mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 01:39:30 +02:00
Merge pull request #73 from paladox/patch-3
Fix Target and Source php files
This commit is contained in:
@ -238,7 +238,7 @@ class Source {
|
|||||||
if ( $this->page === null ) {
|
if ( $this->page === null ) {
|
||||||
// Access the property directly to avoid an infinite loop.
|
// Access the property directly to avoid an infinite loop.
|
||||||
if ( $this->title != null) {
|
if ( $this->title != null) {
|
||||||
$this->page = static::getPage();
|
$this->page = static::getPageObject( $this->title );
|
||||||
} else {
|
} else {
|
||||||
throw new Exception( 'Unable to create Page for this Source because Title is null.' );
|
throw new Exception( 'Unable to create Page for this Source because Title is null.' );
|
||||||
}
|
}
|
||||||
@ -249,14 +249,15 @@ class Source {
|
|||||||
/**
|
/**
|
||||||
* Obtain a WikiPage object.
|
* Obtain a WikiPage object.
|
||||||
* Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory.
|
* Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory.
|
||||||
|
* @param \Title $title
|
||||||
* @return WikiPage object
|
* @return WikiPage object
|
||||||
*/
|
*/
|
||||||
private static function getPage() {
|
private static function getPageObject( $title ) {
|
||||||
if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) {
|
if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) {
|
||||||
$wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
|
$wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
|
||||||
return $wikiPageFactory->newFromTitle( $this->title );
|
return $wikiPageFactory->newFromTitle( $title );
|
||||||
}
|
}
|
||||||
|
|
||||||
return \WikiPage::factory( $this->title );
|
return \WikiPage::factory( $title );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ class Target {
|
|||||||
*/
|
*/
|
||||||
public function getContent() {
|
public function getContent() {
|
||||||
if ( $this->content === null ) {
|
if ( $this->content === null ) {
|
||||||
$this->content = static::getPage();
|
$this->content = static::getPageContents( $this->title );
|
||||||
};
|
};
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
@ -240,7 +240,11 @@ class Target {
|
|||||||
*/
|
*/
|
||||||
public function redirectsTo( $source ) {
|
public function redirectsTo( $source ) {
|
||||||
if ( $this->getContent() ) {
|
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() );
|
return $redirectTitle && $redirectTitle->equals( $source->getTitle() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -248,14 +252,15 @@ class Target {
|
|||||||
/**
|
/**
|
||||||
* Obtain a page's content.
|
* Obtain a page's content.
|
||||||
* Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory.
|
* Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory.
|
||||||
|
* @param \Title $title
|
||||||
* @return Content content object of the page
|
* @return Content content object of the page
|
||||||
*/
|
*/
|
||||||
private static function getPage() {
|
private static function getPageContents( $title ) {
|
||||||
if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) {
|
if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) {
|
||||||
$wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
|
$wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
|
||||||
$page = $wikiPageFactory->newFromTitle( $this->title );
|
$page = $wikiPageFactory->newFromTitle( $title );
|
||||||
} else {
|
} else {
|
||||||
$page = \WikiPage::factory( $this->title );
|
$page = \WikiPage::factory( $title );
|
||||||
}
|
}
|
||||||
return $page->getContent();
|
return $page->getContent();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user