mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 17:59:29 +02:00
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:
@ -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
|
||||||
|
Reference in New Issue
Block a user