Harden test for redirects.

- Fix: Do not crash when testing redirect target on empty page.
This commit is contained in:
Daniel Kraus
2017-09-03 09:35:11 +02:00
parent 95bd9e0cbc
commit d34b2090c0

View File

@ -73,7 +73,6 @@ class Target {
* @param String &$title Title of the target page * @param String &$title Title of the target page
*/ */
public function __construct( $namespace, $title, Config &$config ) { public function __construct( $namespace, $title, Config &$config ) {
// print "\n>>>namespace=$namespace;title=$title<<<\n";
$this->title = \Title::makeTitleSafe( $namespace, $title ); $this->title = \Title::makeTitleSafe( $namespace, $title );
$this->titleValue = $this->title->getTitleValue(); $this->titleValue = $this->title->getTitleValue();
$this->config = $config; $this->config = $config;
@ -95,7 +94,7 @@ class Target {
} }
public function getPrefixedTitleText() { public function getPrefixedTitleText() {
return $this->getNsPrefix() . $this->getTitleText(); return $this->title->getPrefixedText();
} }
/** /**
@ -204,11 +203,8 @@ class Target {
// If checking for redirects is enabled and the target page does // If checking for redirects is enabled and the target page does
// indeed redirect to the current page, return the page title as-is // indeed redirect to the current page, return the page title as-is
// (unlinked). // (unlinked).
if ( $this->config->checkRedirect ) { if ( $this->config->checkRedirect && $this->redirectsTo( $source ) ) {
$redirectTitle = $this->getContent()->getUltimateRedirectTarget(); return false;
if ( $redirectTitle && $redirectTitle->equals( $source->getTitle() ) ) {
return false;
}
}; };
// If the magic word __NOAUTOLINKTARGET__ is enabled and the target // If the magic word __NOAUTOLINKTARGET__ is enabled and the target
// page does indeed contain this magic word, return the page title // page does indeed contain this magic word, return the page title
@ -229,4 +225,16 @@ class Target {
public function isSameTitle( Source $source) { public function isSameTitle( Source $source) {
return $this->title->equals( $source->getTitle() ); return $this->title->equals( $source->getTitle() );
} }
/**
* Checks whether this target redirects to the source.
* @param Source $source Source page.
* @return bool True if the target redirects to the source.
*/
public function redirectsTo( $source ) {
if ( $this->getContent() ) {
$redirectTitle = $this->getContent()->getUltimateRedirectTarget();
return $redirectTitle && $redirectTitle->equals( $source->getTitle() );
}
}
} }