Update Target.php

This commit is contained in:
paladox
2023-12-22 17:04:58 +00:00
committed by GitHub
parent 2a1e3a05e9
commit 4fc414be8b

View File

@ -191,13 +191,7 @@ class Target {
*/ */
public function getContent() { public function getContent() {
if ( $this->content === null ) { if ( $this->content === null ) {
// MW 1.36+ $this->content = static::getPage();
if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) {
$wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
$this->content = $wikiPageFactory->newFromTitle( $this->title )->getContent();
} else {
$this->content = \WikiPage::factory( $this->title )->getContent();
}
}; };
return $this->content; return $this->content;
} }
@ -250,4 +244,19 @@ class Target {
return $redirectTitle && $redirectTitle->equals( $source->getTitle() ); 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();
}
} }