Merge pull request #72 from paladox/patch-2

Fix "Call to undefined method WikiPage::factory()"
This commit is contained in:
Daniel Kraus
2023-12-27 18:11:07 +01:00
committed by GitHub
2 changed files with 33 additions and 2 deletions

View File

@ -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 );
}
}

View File

@ -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();
}
}