Prevent creating indirect links to self.

Added code to check if a target page redirects to the current page, and
prevents linking to that target page. Note that this does not catch
situations where a page title exists twice, once with first capital letter
and once with first lowercase letter (should happen on test systems only).
This commit is contained in:
Daniel Kraus
2014-06-02 18:55:02 +02:00
parent 821d6d6b34
commit cf792072dd

View File

@ -183,10 +183,26 @@
$targetPage = WikiPage::factory($targetTitle); $targetPage = WikiPage::factory($targetTitle);
$targetText = $targetPage->getText(); $targetText = $targetPage->getText();
// Only proceed if we're not operating on the very same page // To prevent linking to pages that redirect to the current page,
if ( ! ( $myTitle->equals($targetTitle) || // obtain the title that the target page redirects to. Will be null
$noAutoLinkTarget->match($targetText) ) ) { // if there is no redirect.
$redirectTitle = $targetPage->getRedirectTarget();
if ( $redirectTitle ) {
// If the target page redirects to the current page, exit the
// function.
if ( $redirectTitle->equals($myTitle) ) {
continue;
}
}
if ( $noAutoLinkTarget->match($targetText) ) {
continue;
}
// Only proceed if we're not operating on the very same page, if the
// target page does not have the __NOAUTOLINKTARGET__ magic word in
// it, and if the target page does not redirect to the current page.
if ( ! $myTitle->equals($targetTitle) ) {
// split the string by [[...]] groups // split the string by [[...]] groups
// credits to inhan @ StackOverflow for suggesting preg_split // credits to inhan @ StackOverflow for suggesting preg_split
// see http://stackoverflow.com/questions/10672286 // see http://stackoverflow.com/questions/10672286