Skip to content

Commit

Permalink
Merge pull request #100 from Sheep-y/MW1_42_compat
Browse files Browse the repository at this point in the history
MW 1.42 compatibility fix
  • Loading branch information
Nikerabbit authored Aug 3, 2024
2 parents 3d2c73e + ecafebe commit 65fd7df
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/AnnotatedLanguageParserFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SIL;

use MediaWiki\MediaWikiServices;
use Title;
use Language;

Expand Down Expand Up @@ -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 . '}}';

Expand Down
22 changes: 11 additions & 11 deletions src/HookRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace SIL;

use MediaWiki\MediaWikiServices;
use Onoi\Cache\Cache;
use SMW\Store;
use SMW\ApplicationFactory;
use SMW\InMemoryPoolCache;
use SIL\Search\SearchResultModifier;
use SIL\Search\LanguageResultMatchFinder;
use SIL\Category\LanguageFilterCategoryPage;
use Hooks;
use Language;

/**
Expand Down Expand Up @@ -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 );
}

/**
Expand All @@ -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 );
}
}

Expand Down Expand Up @@ -99,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 ) {

Expand Down Expand Up @@ -164,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 ) {

Expand All @@ -175,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 ) {

Expand Down Expand Up @@ -230,14 +231,13 @@ 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(
$contentLang = $pageContentLanguageOnTheFlyModifier->getPageContentLanguage(
$title,
$pageLang
) );
);
$pageLang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $contentLang );

return true;
};
Expand Down
2 changes: 1 addition & 1 deletion src/InterlanguageLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
3 changes: 2 additions & 1 deletion src/InterlanguageLinkParserFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SIL;

use Onoi\Cache\CacheFactory;
use MediaWiki\MediaWikiServices;
use Title;
use Language;

Expand Down Expand Up @@ -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 = '' ) {
Expand Down
4 changes: 3 additions & 1 deletion src/InterlanguageListParserFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SIL;

use MediaWiki\MediaWikiServices;
use Title;
use Language;

Expand Down Expand Up @@ -86,6 +87,7 @@ private function createTemplateInclusionCode( array $languageTargetLinks, $templ
$result = '';
$templateText = '';
$i = 0;
$langUtils = MediaWikiServices::getInstance()->getLanguageNameUtils();

foreach ( $languageTargetLinks as $languageCode => $targetLink ) {

Expand All @@ -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 . '}}';
}
Expand Down
2 changes: 1 addition & 1 deletion src/PageContentLanguageOnTheFlyModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/Search/SearchResultModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function addLanguageFilterToPowerBox( $request, &$showSections ) {
*/
public function createHtmlLanguageFilterSelector( $defaultLanguagefilter ) {

$languages = Language::fetchLanguageNames();
$languages = MediaWikiServices::getInstance()->getLanguageNameUtils()->getLanguageNames();

ksort( $languages );

Expand Down
3 changes: 2 additions & 1 deletion src/SiteLanguageLinkModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SIL;

use MediaWiki\MediaWikiServices;
use Title;
use Language;

Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion tests/phpunit/Unit/HookRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SIL\Tests;

use Language;
use MediaWiki\MediaWikiServices;
use SIL\HookRegistry;
use SMW\Tests\PHPUnitCompat;
use Title;
Expand Down Expand Up @@ -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__ );

Expand Down

0 comments on commit 65fd7df

Please sign in to comment.