From c67060820a2fe75c942eef0dc28c6213c33228af Mon Sep 17 00:00:00 2001 From: Sheepy Date: Mon, 15 Jul 2024 12:11:53 +0800 Subject: [PATCH 1/9] Fix compatibility with MediaWiki 1.42 and up, which removed Hooks class. --- src/HookRegistry.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/HookRegistry.php b/src/HookRegistry.php index 5b12843..1e0078d 100644 --- a/src/HookRegistry.php +++ b/src/HookRegistry.php @@ -2,6 +2,7 @@ namespace SIL; +use MediaWiki\MediaWikiServices; use Onoi\Cache\Cache; use SMW\Store; use SMW\ApplicationFactory; @@ -9,7 +10,6 @@ use SIL\Search\SearchResultModifier; use SIL\Search\LanguageResultMatchFinder; use SIL\Category\LanguageFilterCategoryPage; -use Hooks; use Language; /** @@ -44,7 +44,7 @@ public function __construct( Store $store, Cache $cache, CacheKeyProvider $cache * @return boolean */ public function isRegistered( $name ) { - return Hooks::isRegistered( $name ); + return MediaWikiServices::getInstance()->getHookContainer()->isRegistered( $name ); } /** @@ -62,8 +62,9 @@ public function getHandlerFor( $name ) { * @since 1.0 */ public function register() { + $hooks = MediaWikiServices::getInstance()->getHookContainer(); foreach ( $this->handlers as $name => $callback ) { - Hooks::register( $name, $callback ); + $hooks->register( $name, $callback ); } } From a694c548031480c6b1e6ef77bffb882736519266 Mon Sep 17 00:00:00 2001 From: Sheepy Date: Mon, 15 Jul 2024 12:32:36 +0800 Subject: [PATCH 2/9] Replace deprecated Language::factory, available since 1.35. --- src/HookRegistry.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/HookRegistry.php b/src/HookRegistry.php index 1e0078d..2b408e8 100644 --- a/src/HookRegistry.php +++ b/src/HookRegistry.php @@ -231,11 +231,9 @@ private function registerInterlanguageParserHooks( InterlanguageLinksLookup $int /** * @see https://www.mediawiki.org/wiki/Manual:Hooks/PageContentLanguage */ - $this->handlers['PageContentLanguage'] = function ( $title, Language &$pageLang ) use ( $pageContentLanguageOnTheFlyModifier ) { + $this->handlers['PageContentLanguage'] = function ( $title, &$pageLang ) use ( $pageContentLanguageOnTheFlyModifier ) { - // PageContentLanguage now requires pageLang of type Language - // https://phabricator.wikimedia.org/T214358 - $pageLang = Language::factory( $pageContentLanguageOnTheFlyModifier->getPageContentLanguage( + $pageLang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $pageContentLanguageOnTheFlyModifier->getPageContentLanguage( $title, $pageLang ) ); From 458b2f728b8a9eca07965f200393a155f40e4659 Mon Sep 17 00:00:00 2001 From: Sheepy Date: Mon, 15 Jul 2024 12:36:50 +0800 Subject: [PATCH 3/9] Update hook documentation links. --- src/HookRegistry.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/HookRegistry.php b/src/HookRegistry.php index 2b408e8..1230201 100644 --- a/src/HookRegistry.php +++ b/src/HookRegistry.php @@ -100,7 +100,7 @@ private function addCallbackHandlers( $store, $cache, $cacheKeyProvider ) { $interlanguageLinksLookup->setStore( $store ); /** - * @see https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/docs/technical/hooks.md + * @see https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/docs/technical/hooks/hook.property.initproperties.md */ $this->handlers['SMW::Property::initProperties'] = function ( $baseRegistry ) { @@ -165,7 +165,7 @@ private function registerInterlanguageParserHooks( InterlanguageLinksLookup $int }; /** - * https://www.mediawiki.org/wiki/Manual:Hooks/ArticleDelete + * https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/docs/technical/hooks/hook.sqlstore.beforedeletesubjectcomplete.md */ $this->handlers['SMW::SQLStore::BeforeDeleteSubjectComplete'] = function ( $store, $title ) use ( $interlanguageLinksLookup ) { @@ -176,7 +176,7 @@ private function registerInterlanguageParserHooks( InterlanguageLinksLookup $int }; /** - * https://www.mediawiki.org/wiki/Manual:Hooks/TitleMoveComplete + * https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/docs/technical/hooks/hook.sqlstore.beforechangetitlecomplete.md */ $this->handlers['SMW::SQLStore::BeforeChangeTitleComplete'] = function ( $store, $oldTitle, $newTitle, $pageid, $redirid ) use ( $interlanguageLinksLookup ) { From 7c54ebfcb66f3ca77abb3f273b4aa1898c979502 Mon Sep 17 00:00:00 2001 From: Sheepy Date: Mon, 15 Jul 2024 12:42:21 +0800 Subject: [PATCH 4/9] Update composer require to be compatible with SMW 4.0; no backward compatibility issue noted in SMW changelog. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0c9fdfd..4a74c6f 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "php": ">=7.1.0", "composer/installers": "1.*,>=1.0.1", "onoi/cache": "~1.2", - "mediawiki/semantic-media-wiki": "~3.0|@dev" + "mediawiki/semantic-media-wiki": ">=3.0|@dev" }, "require-dev": { "mediawiki/semantic-media-wiki": "@dev" From ccd126b22b87a5fe8b6e757cbc8c7fa8f609692b Mon Sep 17 00:00:00 2001 From: Sheepy Date: Mon, 15 Jul 2024 16:48:58 +0800 Subject: [PATCH 5/9] Minor refactor to keep line short. --- src/HookRegistry.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/HookRegistry.php b/src/HookRegistry.php index 1230201..899eba7 100644 --- a/src/HookRegistry.php +++ b/src/HookRegistry.php @@ -233,7 +233,8 @@ private function registerInterlanguageParserHooks( InterlanguageLinksLookup $int */ $this->handlers['PageContentLanguage'] = function ( $title, &$pageLang ) use ( $pageContentLanguageOnTheFlyModifier ) { - $pageLang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $pageContentLanguageOnTheFlyModifier->getPageContentLanguage( + $langFactory = MediaWikiServices::getInstance()->getLanguageFactory(); + $pageLang = $langFactory->getLanguage( $pageContentLanguageOnTheFlyModifier->getPageContentLanguage( $title, $pageLang ) ); From 8f75879de6542011c9f8cdf8fe22bd7fdee9f61a Mon Sep 17 00:00:00 2001 From: Sheepy Date: Thu, 18 Jul 2024 01:38:19 +0800 Subject: [PATCH 6/9] Migrate fetchLanguageName, fetchLanguageNames, and isSupportedLanguage to LanguageNameUtils. --- src/AnnotatedLanguageParserFunction.php | 3 ++- src/InterlanguageLinkParserFunction.php | 3 ++- src/InterlanguageListParserFunction.php | 4 +++- src/PageContentLanguageOnTheFlyModifier.php | 2 +- src/Search/SearchResultModifier.php | 2 +- src/SiteLanguageLinkModifier.php | 3 ++- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/AnnotatedLanguageParserFunction.php b/src/AnnotatedLanguageParserFunction.php index c24267a..a1bcb74 100644 --- a/src/AnnotatedLanguageParserFunction.php +++ b/src/AnnotatedLanguageParserFunction.php @@ -2,6 +2,7 @@ namespace SIL; +use MediaWiki\MediaWikiServices; use Title; use Language; @@ -72,7 +73,7 @@ private function createTemplateInclusionCode( $source, $languageCode, $template $wikitext .= "|target-link=" . $this->modifyTargetLink( $source ); $wikitext .= "|lang-code=" . Localizer::asBCP47FormattedLanguageCode( $languageCode ); - $wikitext .= "|lang-name=" . Language::fetchLanguageName( $languageCode ); + $wikitext .= "|lang-name=" . MediaWikiServices::getInstance()->getLanguageNameUtils()->getLanguageName( $languageCode ); $templateText .= '{{' . $template . $wikitext . '}}'; diff --git a/src/InterlanguageLinkParserFunction.php b/src/InterlanguageLinkParserFunction.php index 61efab3..fb820d6 100644 --- a/src/InterlanguageLinkParserFunction.php +++ b/src/InterlanguageLinkParserFunction.php @@ -3,6 +3,7 @@ namespace SIL; use Onoi\Cache\CacheFactory; +use MediaWiki\MediaWikiServices; use Title; use Language; @@ -181,7 +182,7 @@ private function isSupportedLanguage( $languageCode ) { return false; } - return Language::isSupportedLanguage( $languageCode ); + return MediaWikiServices::getInstance()->getLanguageNameUtils()->isSupportedLanguage( $languageCode ); } private function createErrorMessageFor( $messageKey, $arg1 = '', $arg2 = '', $arg3 = '',$arg4 = '' ) { diff --git a/src/InterlanguageListParserFunction.php b/src/InterlanguageListParserFunction.php index f1b34d0..c1c018b 100644 --- a/src/InterlanguageListParserFunction.php +++ b/src/InterlanguageListParserFunction.php @@ -2,6 +2,7 @@ namespace SIL; +use MediaWiki\MediaWikiServices; use Title; use Language; @@ -86,6 +87,7 @@ private function createTemplateInclusionCode( array $languageTargetLinks, $templ $result = ''; $templateText = ''; $i = 0; + $langUtils = MediaWikiServices::getInstance()->getLanguageNameUtils(); foreach ( $languageTargetLinks as $languageCode => $targetLink ) { @@ -94,7 +96,7 @@ private function createTemplateInclusionCode( array $languageTargetLinks, $templ $wikitext .= "|#=" . $i++; $wikitext .= "|target-link=" . $this->modifyTargetLink( $targetLink ); $wikitext .= "|lang-code=" . Localizer::asBCP47FormattedLanguageCode( $languageCode ); - $wikitext .= "|lang-name=" . Language::fetchLanguageName( $languageCode ); + $wikitext .= "|lang-name=" . $langUtils->getLanguageName( $languageCode ); $templateText .= '{{' . $template . $wikitext . '}}'; } diff --git a/src/PageContentLanguageOnTheFlyModifier.php b/src/PageContentLanguageOnTheFlyModifier.php index 4310c2f..8b5d152 100644 --- a/src/PageContentLanguageOnTheFlyModifier.php +++ b/src/PageContentLanguageOnTheFlyModifier.php @@ -66,7 +66,7 @@ public function getPageContentLanguage( Title $title, $pageLanguage ) { $hash = $this->getHashFrom( $title ); // Convert language codes from BCP 47 to lowercase to ensure that codes - // are matchable against `Language::fetchLanguageNames` for languages like + // are matchable against `LanguageNameUtils->getLanguageNames` for languages like // zh-Hans etc. if ( ( $cachedLanguageCode = $this->intermediaryCache->fetch( $hash ) ) ) { return strtolower( $cachedLanguageCode ); diff --git a/src/Search/SearchResultModifier.php b/src/Search/SearchResultModifier.php index 0d02fed..356d9c6 100644 --- a/src/Search/SearchResultModifier.php +++ b/src/Search/SearchResultModifier.php @@ -116,7 +116,7 @@ public function addLanguageFilterToPowerBox( $request, &$showSections ) { */ public function createHtmlLanguageFilterSelector( $defaultLanguagefilter ) { - $languages = Language::fetchLanguageNames(); + $languages = MediaWikiServices::getInstance()->getLanguageNameUtils()->getLanguageNames(); ksort( $languages ); diff --git a/src/SiteLanguageLinkModifier.php b/src/SiteLanguageLinkModifier.php index ebdf4a6..19bc5a5 100644 --- a/src/SiteLanguageLinkModifier.php +++ b/src/SiteLanguageLinkModifier.php @@ -2,6 +2,7 @@ namespace SIL; +use MediaWiki\MediaWikiServices; use Title; use Language; @@ -53,7 +54,7 @@ public function modifyLanguageLink( &$languageLink ) { return false; } - $languageName = Language::fetchLanguageName( $languageCode ); + $languageName = MediaWikiServices::getInstance()->getLanguageNameUtils()->getLanguageName( $languageCode ); $languageLink = [ 'href' => Title::newFromText( $target )->getFullURL(), From 462fc73ce5c079378227b1f7d43299a6391065dc Mon Sep 17 00:00:00 2001 From: Sheepy Date: Thu, 18 Jul 2024 01:40:50 +0800 Subject: [PATCH 7/9] Minor refactor for readability. --- src/HookRegistry.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/HookRegistry.php b/src/HookRegistry.php index 899eba7..062fa02 100644 --- a/src/HookRegistry.php +++ b/src/HookRegistry.php @@ -233,11 +233,11 @@ private function registerInterlanguageParserHooks( InterlanguageLinksLookup $int */ $this->handlers['PageContentLanguage'] = function ( $title, &$pageLang ) use ( $pageContentLanguageOnTheFlyModifier ) { - $langFactory = MediaWikiServices::getInstance()->getLanguageFactory(); - $pageLang = $langFactory->getLanguage( $pageContentLanguageOnTheFlyModifier->getPageContentLanguage( + $contentLang = $pageContentLanguageOnTheFlyModifier->getPageContentLanguage( $title, $pageLang - ) ); + ); + $pageLang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $contentLang ); return true; }; From 9b718d9d1070169dd79742df8da3a91afa8526b8 Mon Sep 17 00:00:00 2001 From: Sheepy Date: Thu, 18 Jul 2024 01:43:10 +0800 Subject: [PATCH 8/9] Fix "Deprecated: Optional parameter $languageCode declared before required parameter $linkReference is implicitly treated as a required parameter". --- src/InterlanguageLink.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/InterlanguageLink.php b/src/InterlanguageLink.php index 0edd240..643bd59 100644 --- a/src/InterlanguageLink.php +++ b/src/InterlanguageLink.php @@ -34,7 +34,7 @@ class InterlanguageLink { * @param string|null $languageCode * @param Title|string $linkReference */ - public function __construct( $languageCode = null, $linkReference ) { + public function __construct( $languageCode = null, $linkReference = null ) { $this->languageCode = $languageCode; $this->linkReference = $linkReference instanceOf Title ? $linkReference : Title::newFromText( $linkReference ); } From ecafebec77e661049296815b3765a2d0cccdaf4d Mon Sep 17 00:00:00 2001 From: Sheepy Date: Thu, 18 Jul 2024 02:04:17 +0800 Subject: [PATCH 9/9] Fix Language static method in unit test. --- tests/phpunit/Unit/HookRegistryTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/Unit/HookRegistryTest.php b/tests/phpunit/Unit/HookRegistryTest.php index f77a805..2cfde7c 100644 --- a/tests/phpunit/Unit/HookRegistryTest.php +++ b/tests/phpunit/Unit/HookRegistryTest.php @@ -3,6 +3,7 @@ namespace SIL\Tests; use Language; +use MediaWiki\MediaWikiServices; use SIL\HookRegistry; use SMW\Tests\PHPUnitCompat; use Title; @@ -187,7 +188,7 @@ public function doTestSkinTemplateGetLanguageLink( $instance ) { public function doTestPageContentLanguage( $instance ) { $handler = 'PageContentLanguage'; - $pageLang = Language::factory( 'en' ); + $pageLang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' ); $title = Title::newFromText( __METHOD__ );