diff --git a/includes/Source.php b/includes/Source.php index ee8d1c4..a119cae 100644 --- a/includes/Source.php +++ b/includes/Source.php @@ -238,11 +238,25 @@ class Source { if ( $this->page === null ) { // Access the property directly to avoid an infinite loop. if ( $this->title != null) { - $this->page = \WikiPage::factory( $this->title ); + $this->page = static::getPage(); } else { throw new Exception( 'Unable to create Page for this Source because Title is null.' ); } } return $this->page; } + + /** + * Obtain a WikiPage object. + * Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory. + * @return WikiPage object + */ + private static function getPage() { + if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) { + $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); + return $wikiPageFactory->newFromTitle( $this->title ); + } + + return \WikiPage::factory( $this->title ); + } } diff --git a/includes/Target.php b/includes/Target.php index 8fa99b5..f9afcd5 100644 --- a/includes/Target.php +++ b/includes/Target.php @@ -24,6 +24,8 @@ */ namespace LinkTitles; +use MediaWiki\MediaWikiServices; + /** * Represents a page that is a potential link target. */ @@ -189,7 +191,7 @@ class Target { */ public function getContent() { if ( $this->content === null ) { - $this->content = \WikiPage::factory( $this->title )->getContent(); + $this->content = static::getPage(); }; return $this->content; } @@ -242,4 +244,19 @@ class Target { return $redirectTitle && $redirectTitle->equals( $source->getTitle() ); } } + + /** + * Obtain a page's content. + * Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory. + * @return Content content object of the page + */ + private static function getPage() { + if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) { + $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); + $page = $wikiPageFactory->newFromTitle( $this->title ); + } else { + $page = \WikiPage::factory( $this->title ); + } + return $page->getContent(); + } }