diff --git a/includes/Source.php b/includes/Source.php index a119cae..9be3f6b 100644 --- a/includes/Source.php +++ b/includes/Source.php @@ -238,7 +238,7 @@ class Source { if ( $this->page === null ) { // Access the property directly to avoid an infinite loop. if ( $this->title != null) { - $this->page = static::getPage(); + $this->page = static::getPageObject( $this->title ); } else { throw new Exception( 'Unable to create Page for this Source because Title is null.' ); } @@ -249,14 +249,15 @@ class Source { /** * Obtain a WikiPage object. * Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory. + * @param \Title $title * @return WikiPage object */ - private static function getPage() { + private static function getPageObject( $title ) { if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) { $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); - return $wikiPageFactory->newFromTitle( $this->title ); + return $wikiPageFactory->newFromTitle( $title ); } - return \WikiPage::factory( $this->title ); + return \WikiPage::factory( $title ); } } diff --git a/includes/Target.php b/includes/Target.php index f9afcd5..e203959 100644 --- a/includes/Target.php +++ b/includes/Target.php @@ -191,7 +191,7 @@ class Target { */ public function getContent() { if ( $this->content === null ) { - $this->content = static::getPage(); + $this->content = static::getPageContents( $this->title ); }; return $this->content; } @@ -240,7 +240,11 @@ class Target { */ public function redirectsTo( $source ) { if ( $this->getContent() ) { - $redirectTitle = $this->getContent()->getUltimateRedirectTarget(); + if ( version_compare( MW_VERSION, '1.38', '>=' ) ) { + $redirectTitle = $this->getContent()->getRedirectTarget(); + } else { + $redirectTitle = $this->getContent()->getUltimateRedirectTarget(); + } return $redirectTitle && $redirectTitle->equals( $source->getTitle() ); } } @@ -248,14 +252,15 @@ class Target { /** * Obtain a page's content. * Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory. + * @param \Title $title * @return Content content object of the page */ - private static function getPage() { + private static function getPageContents( $title ) { if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) { $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); - $page = $wikiPageFactory->newFromTitle( $this->title ); + $page = $wikiPageFactory->newFromTitle( $title ); } else { - $page = \WikiPage::factory( $this->title ); + $page = \WikiPage::factory( $title ); } return $page->getContent(); }