mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 01:39:30 +02:00
Fix inadvertent page deletions; prevent self references
This commit is contained in:
9
HISTORY
Normal file
9
HISTORY
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Extension:LinkTitles
|
||||||
|
|
||||||
|
0.0.2: 2012-05-20
|
||||||
|
* Prevent generation of self-references.
|
||||||
|
* Escape slashes in page titles before using them in a regexp.
|
||||||
|
|
||||||
|
0.0.1: 2012-05-20
|
||||||
|
* Initial release.
|
||||||
|
|
@ -41,6 +41,10 @@
|
|||||||
// 'minor edits' is not set.
|
// 'minor edits' is not set.
|
||||||
|
|
||||||
if ( !$minor ) {
|
if ( !$minor ) {
|
||||||
|
// To prevent adding self-references, we now
|
||||||
|
// extract the current page's title.
|
||||||
|
$my_title = $article->getTitle()->getText();
|
||||||
|
|
||||||
// Build an SQL query and fetch all page titles ordered
|
// Build an SQL query and fetch all page titles ordered
|
||||||
// by length from shortest to longest.
|
// by length from shortest to longest.
|
||||||
$dbr = wfGetDB( DB_SLAVE );
|
$dbr = wfGetDB( DB_SLAVE );
|
||||||
@ -52,22 +56,32 @@
|
|||||||
array( 'ORDER BY' => 'length(page_title)' ));
|
array( 'ORDER BY' => 'length(page_title)' ));
|
||||||
|
|
||||||
// Iterate through the page titles
|
// Iterate through the page titles
|
||||||
|
$new_text = $text;
|
||||||
foreach( $res as $row ) {
|
foreach( $res as $row ) {
|
||||||
// Page titles are stored in the database with spaces
|
// Page titles are stored in the database with spaces
|
||||||
// replaced by underscores. Therefore we now convert
|
// replaced by underscores. Therefore we now convert
|
||||||
// the underscores back to spaces.
|
// the underscores back to spaces.
|
||||||
$title = str_replace('_', ' ', $row->page_title);
|
$title = str_replace('_', ' ', $row->page_title);
|
||||||
|
|
||||||
// Now look for every occurrence of $title in the
|
if ( $title != $my_title ) {
|
||||||
// page $text and enclose it in double square brackets,
|
|
||||||
// unless it is already enclosed in brackets (directly
|
// Now look for every occurrence of $title in the
|
||||||
// adjacent or remotely, see http://stackoverflow.com/questions/10672286
|
// page $text and enclose it in double square brackets,
|
||||||
// Regex built with the help from Eugene @ Stackoverflow
|
// unless it is already enclosed in brackets (directly
|
||||||
// http://stackoverflow.com/a/10672440/270712
|
// adjacent or remotely, see http://stackoverflow.com/questions/10672286
|
||||||
$text = preg_replace(
|
// Regex built with the help from Eugene @ Stackoverflow
|
||||||
'/(' . $title . ')([^\]]+(\[|$))/i',
|
// http://stackoverflow.com/a/10672440/270712
|
||||||
'[[$1]]$2',
|
$new_text = preg_replace(
|
||||||
$text );
|
'/(\b' . str_replace('/', '\/', $title) . '\b)([^\]]+(\[|$))/i',
|
||||||
|
'[[$1]]$2',
|
||||||
|
$new_text );
|
||||||
|
if ( $new_text == '' ) {
|
||||||
|
throw new Exception( 'new text was deleted! - title: ' . $title );
|
||||||
|
};
|
||||||
|
}; // if $title != $my_title
|
||||||
|
}; // foreach $res as $row
|
||||||
|
if ( $new_text != '' ) {
|
||||||
|
$text = $new_text;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return true;
|
return true;
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
'name' => 'LinkTitles',
|
'name' => 'LinkTitles',
|
||||||
'author' => '[http://www.mediawiki.org/wiki/User:Bovender Daniel Kraus]',
|
'author' => '[http://www.mediawiki.org/wiki/User:Bovender Daniel Kraus]',
|
||||||
'url' => 'http://www.mediawiki.org/wiki/Extension:LinkTitles',
|
'url' => 'http://www.mediawiki.org/wiki/Extension:LinkTitles',
|
||||||
'version' => '0.0.1',
|
'version' => '0.0.2',
|
||||||
'descriptionmsg' => 'linktitles-desc'
|
'descriptionmsg' => 'linktitles-desc'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -4,4 +4,4 @@
|
|||||||
# extension into two archive files that contain the current
|
# extension into two archive files that contain the current
|
||||||
# git tag as the version number.
|
# git tag as the version number.
|
||||||
|
|
||||||
tar cvzf release/LinkTitles-`git describe --tags`.tar.gz gpl-*.txt LinkTitles.* --exclude '*~' --transform 's,^,LinkTitles/,'
|
tar cvzf release/LinkTitles-`git describe --tags`.tar.gz gpl-*.txt HISTORY LinkTitles.* --exclude '*~' --transform 's,^,LinkTitles/,'
|
||||||
|
Reference in New Issue
Block a user