diff --git a/includes/Extension.php b/includes/Extension.php index 0edcd70..d2d47d1 100644 --- a/includes/Extension.php +++ b/includes/Extension.php @@ -64,7 +64,7 @@ class Extension { // MW 1.36+ if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) { $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); - $wikiPage = $wikiPageFactory->newFromTitle( $title ); + $wikiPage = $wikiPageFactory->newFromLinkTarget( $title ); } else { $wikiPage = WikiPage::factory( $title ); } @@ -102,11 +102,11 @@ class Extension { * * Entry point for the SpecialLinkTitles class and the LinkTitlesJob class. * - * @param \Title $title Title object. + * @param MediaWiki\Title\Title $title Title object. * @param \RequestContext $context Current request context. If in doubt, call MediaWiki's `RequestContext::getMain()` to obtain such an object. * @return bool True if the page exists, false if the page does not exist */ - public static function processPage( \Title $title, \RequestContext $context ) { + public static function processPage( MediaWiki\Title\Title $title, \RequestContext $context ) { $config = new Config(); $source = Source::createFromTitle( $title, $config ); if ( $source->hasContent() ) { diff --git a/includes/Linker.php b/includes/Linker.php index 13428ff..343e6b3 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -66,7 +66,7 @@ class Linker { * callbacks in the Extension class do not always get a WikiPage object in the * first place. * - * @param \Title &$title Title object for the current page. + * @param MediaWiki\Title\Title &$title Title object for the current page. * @param String $text String that holds the article content * @return String|null Source page text with links to target pages, or null if no links were added */ diff --git a/includes/Source.php b/includes/Source.php index c966987..2aa2e93 100644 --- a/includes/Source.php +++ b/includes/Source.php @@ -46,11 +46,11 @@ class Source { private $content; /** - * Creates a Source object from a \Title. - * @param \Title $title Title object from which to create the Source. + * Creates a Source object from a MediaWiki\Title\Title. + * @param MediaWiki\Title\Title $title Title object from which to create the Source. * @return Source Source object created from the title. */ - public static function createFromTitle( \Title $title, Config $config ) { + public static function createFromTitle( MediaWiki\Title\Title $title, Config $config ) { $source = new Source( $config ); $source->title = $title; return $source; @@ -62,12 +62,12 @@ class Source { * This factory can be called e.g. from a onPageContentSave event handler * which knows both these parameters. * - * @param \Title $title Title of the source page + * @param \MediaWiki\Title\Title $title Title of the source page * @param String $text String representation of the page content * @param Config $config LinkTitles configuration * @return Source Source object created from the title and the text */ - public static function createFromTitleAndText( \Title $title, $text, Config $config ) { + public static function createFromTitleAndText( \MediaWiki\Title\Title $title, $text, Config $config ) { $source = Source::createFromTitle( $title, $config); $source->text = $text; return $source; @@ -158,7 +158,7 @@ class Source { /** * Gets the title. * - * @return \Title Title of the source page. + * @return MediaWiki\Title\Title Title of the source page. */ public function getTitle() { if ( $this->title === null ) { @@ -249,7 +249,7 @@ class Source { /** * Obtain a WikiPage object. * Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory. - * @param \Title $title + * @param MediaWiki\Title\Title $title * @return WikiPage object */ private static function getPageObject( $title ) { diff --git a/includes/Target.php b/includes/Target.php index bcc5fb4..d432f02 100644 --- a/includes/Target.php +++ b/includes/Target.php @@ -25,6 +25,7 @@ namespace LinkTitles; use MediaWiki\MediaWikiServices; +use MediaWiki\Title\Title as MWTitle; /** * Represents a page that is a potential link target. @@ -32,7 +33,7 @@ use MediaWiki\MediaWikiServices; class Target { /** * A Title object for the target page currently being examined. - * @var \Title $title + * @var MediaWiki\Title\Title $title */ private $title; @@ -76,7 +77,7 @@ class Target { * @param String &$title Title of the target page */ public function __construct( $namespace, $title, Config &$config ) { - $this->title = \Title::makeTitleSafe( $namespace, $title ); + $this->title = MWTitle::makeTitleSafe( $namespace, $title ); $this->titleValue = $this->title->getTitleValue(); $this->config = $config; @@ -252,7 +253,7 @@ class Target { /** * Obtain a page's content. * Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory. - * @param \Title $title + * @param MediaWiki\Title\Title $title * @return Content content object of the page */ private static function getPageContents( $title ) { diff --git a/includes/Targets.php b/includes/Targets.php index cf62205..8617fa3 100644 --- a/includes/Targets.php +++ b/includes/Targets.php @@ -24,6 +24,8 @@ */ namespace LinkTitles; +use MediaWiki\Title\Title; + /** * Fetches potential target page titles from the database. */ @@ -41,7 +43,7 @@ class Targets { * @param String $sourceNamespace The namespace of the current page. * @param Config $config LinkTitles configuration. */ - public static function singleton( \Title $title, Config $config ) { + public static function singleton( \MediaWiki\Title\Title $title, Config $config ) { if ( ( self::$instance === null ) || ( self::$instance->sourceNamespace != $title->getNamespace() ) ) { self::$instance = new Targets( $title, $config ); } @@ -83,9 +85,9 @@ class Targets { /** * The constructor is private to enforce using the singleton pattern. - * @param \Title $title + * @param MediaWiki\Title\Title $title */ - private function __construct( \Title $title, Config $config) { + private function __construct( MediaWiki\Title\Title $title, Config $config) { $this->config = $config; $this->sourceNamespace = $title->getNamespace(); $this->fetch(); @@ -135,7 +137,7 @@ class Targets { // shortest to longest. Only titles from 'normal' pages (namespace uid // = 0) are returned. Since the db may be sqlite, we need a try..catch // structure because sqlite does not support the CHAR_LENGTH function. - $dbr = wfGetDB( DB_REPLICA ); + $dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_REPLICA ); $this->queryResult = $dbr->select( 'page', array( 'page_title', 'page_namespace' , "weight" => $weightSelect), diff --git a/linktitles-cli.php b/linktitles-cli.php index e3d7b41..f96170f 100755 --- a/linktitles-cli.php +++ b/linktitles-cli.php @@ -143,7 +143,7 @@ class Cli extends \Maintenance { private function singlePage() { $pageName = strval( $this->getOption( 'page' ) ); $this->output( "Processing single page: '$pageName'\n" ); - $title = \Title::newFromText( $pageName ); + $title = MediaWiki\Title\Title::newFromText( $pageName ); $success = Extension::processPage( $title, \RequestContext::getMain() ); if ( $success ) { $this->output( "Finished.\n" ); @@ -184,7 +184,7 @@ class Cli extends \Maintenance { $numProcessed = 0; foreach ( $res as $row ) { - $title = \Title::makeTitleSafe( $row->page_namespace, $row->page_title ); + $title = MediaWiki\Title\Title::makeTitleSafe( $row->page_namespace, $row->page_title ); $numProcessed += 1; $index += 1; if ( $verbose ) { diff --git a/tests/phpunit/SplitterTest.php b/tests/phpunit/SplitterTest.php index db826df..35d12ff 100644 --- a/tests/phpunit/SplitterTest.php +++ b/tests/phpunit/SplitterTest.php @@ -26,8 +26,8 @@ * * @group bovender */ -class SplitterTest extends \MediaWikiTestCase -{ + +class SplitterTest extends LinkTitles\TestCase { /** * @dataProvider provideSplitData */ diff --git a/tests/phpunit/TargetTest.php b/tests/phpunit/TargetTest.php index b34ec38..36d352d 100644 --- a/tests/phpunit/TargetTest.php +++ b/tests/phpunit/TargetTest.php @@ -24,8 +24,8 @@ /** * @group bovender */ -class TargetTest extends \MediaWikiTestCase -{ + +class TargetTest extends LinkTitles\TestCase { /** * @dataProvider provideStartOnly diff --git a/tests/phpunit/TargetsTest.php b/tests/phpunit/TargetsTest.php index 4502c7a..5232f92 100644 --- a/tests/phpunit/TargetsTest.php +++ b/tests/phpunit/TargetsTest.php @@ -36,7 +36,7 @@ class TargetsTest extends LinkTitles\TestCase { // LinkTitlesLinkerTest::testLinkContentTargetNamespaces() is every changed, // this test will fail. $config->targetNamespaces = [ 4000 ]; - $title = \Title::newFromText( 'link target' ); + $title = MediaWiki\Title\Title::newFromText( 'link target' ); $targets = LinkTitles\Targets::singleton( $title, $config ); // Count number of articles: Inspired by updateArticleCount.php maintenance diff --git a/tests/phpunit/TestCase.php b/tests/phpunit/TestCase.php index 179661c..3f22644 100644 --- a/tests/phpunit/TestCase.php +++ b/tests/phpunit/TestCase.php @@ -21,8 +21,9 @@ * @author Daniel Kraus */ namespace LinkTitles; +use MediaWikiIntegrationTestCase; -abstract class TestCase extends \MediaWikiTestCase { +abstract class TestCase extends MediaWikiIntegrationTestCase { protected function setUp(): void { parent::setUp();