Merge pull request #73 from paladox/patch-3

Fix Target and Source php files
This commit is contained in:
Daniel Kraus
2023-12-28 07:14:44 +01:00
committed by GitHub
2 changed files with 15 additions and 9 deletions

View File

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

View File

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