mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 01:39:30 +02:00
Implement config for check-redirect and magic word.
Added two new configuration variables, $wgLinkTitlesCheckRedirect and $wgLinkTitlesEnableNoTargetMagicWord, that can be used to increase performance. If both are overridden to be false, the target page content will not be fetched from the database to check for redirect or the occurrence of a magic word, which saves a lot of time.
This commit is contained in:
@ -91,9 +91,10 @@
|
|||||||
global $wgLinkTitlesFirstOnly;
|
global $wgLinkTitlesFirstOnly;
|
||||||
global $wgLinkTitlesWordStartOnly;
|
global $wgLinkTitlesWordStartOnly;
|
||||||
global $wgLinkTitlesWordEndOnly;
|
global $wgLinkTitlesWordEndOnly;
|
||||||
// global $wgLinkTitlesIgnoreCase;
|
|
||||||
global $wgLinkTitlesSmartMode;
|
global $wgLinkTitlesSmartMode;
|
||||||
global $wgCapitalLinks;
|
global $wgCapitalLinks;
|
||||||
|
global $wgLinkTitlesEnableNoTargetMagicWord;
|
||||||
|
global $wgLinkTitlesCheckRedirect;
|
||||||
|
|
||||||
( $wgLinkTitlesWordStartOnly ) ? $wordStartDelim = '\b' : $wordStartDelim = '';
|
( $wgLinkTitlesWordStartOnly ) ? $wordStartDelim = '\b' : $wordStartDelim = '';
|
||||||
( $wgLinkTitlesWordEndOnly ) ? $wordEndDelim = '\b' : $wordEndDelim = '';
|
( $wgLinkTitlesWordEndOnly ) ? $wordEndDelim = '\b' : $wordEndDelim = '';
|
||||||
@ -180,28 +181,47 @@
|
|||||||
|
|
||||||
// Iterate through the page titles
|
// Iterate through the page titles
|
||||||
foreach( $res as $row ) {
|
foreach( $res as $row ) {
|
||||||
// Obtain an instance of a Title class for the current database
|
// Obtain an instance of a Title class for the current database row.
|
||||||
// row.
|
|
||||||
$targetTitle = Title::makeTitle(NS_MAIN, $row->page_title);
|
$targetTitle = Title::makeTitle(NS_MAIN, $row->page_title);
|
||||||
$targetTitleText = $targetTitle->getText();
|
|
||||||
|
|
||||||
// Obtain a page object for the current title, so we can check for
|
if ( $wgLinkTitlesCheckRedirect || $wgLinkTitlesEnableNoTargetMagicWord ) {
|
||||||
// the presence of the __NOAUTOLINKTARGET__ magic keyword.
|
// Obtain a page object for the current title, so we can check for
|
||||||
$targetPage = WikiPage::factory($targetTitle);
|
// the presence of the __NOAUTOLINKTARGET__ magic keyword.
|
||||||
$targetText = $targetPage->getText();
|
$targetPageContent = WikiPage::factory($targetTitle)->getContent();
|
||||||
|
|
||||||
// To prevent linking to pages that redirect to the current page,
|
// To prevent linking to pages that redirect to the current page,
|
||||||
// obtain the title that the target page redirects to. Will be null
|
// obtain the title that the target page redirects to. Will be null
|
||||||
// if there is no redirect.
|
// if there is no redirect.
|
||||||
$redirectTitle = $targetPage->getContent()->getUltimateRedirectTarget();
|
if ( $wgLinkTitlesCheckRedirect ) {
|
||||||
|
$redirectTitle = $targetPageContent->getUltimateRedirectTarget();
|
||||||
|
$redirectCheck = !( $redirectTitle && $redirectTitle->equals($myTitle) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$redirectCheck = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
if ( $wgLinkTitlesEnableNoTargetMagicWord ) {
|
||||||
|
$magicWordCheck = ! $targetPageContent->matchMagicWord(
|
||||||
|
MagicWord::get('MAG_LINKTITLES_NOTARGET') );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$magicWordCheck = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$redirectCheck = true;
|
||||||
|
$magicWordCheck = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Proceed only if the currently examined page does not redirect to
|
// Proceed only if the currently examined page does not redirect to
|
||||||
// our page and does not contain the no-target magic word
|
// our page and does not contain the no-target magic word.
|
||||||
if (
|
// If the corresponding configuration variables are set to false,
|
||||||
!( $redirectTitle && $redirectTitle->equals($myTitle) ) &&
|
// both 'check' variables below will be set to true by the code
|
||||||
!( $targetPage->getContent()->matchMagicWord(
|
// above.
|
||||||
MagicWord::get('MAG_LINKTITLES_NOTARGET') ) ) ) {
|
if ( $redirectCheck && $magicWordCheck ) {
|
||||||
|
|
||||||
// split the page content by [[...]] groups
|
// split the page content 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
|
||||||
@ -209,6 +229,7 @@
|
|||||||
|
|
||||||
// Escape certain special characters in the page title to prevent
|
// Escape certain special characters in the page title to prevent
|
||||||
// regexp compilation errors
|
// regexp compilation errors
|
||||||
|
$targetTitleText = $targetTitle->getText();
|
||||||
$quotedTitle = preg_quote($targetTitleText, '/');
|
$quotedTitle = preg_quote($targetTitleText, '/');
|
||||||
|
|
||||||
// Depending on the global configuration setting $wgCapitalLinks,
|
// Depending on the global configuration setting $wgCapitalLinks,
|
||||||
|
@ -143,6 +143,38 @@
|
|||||||
/// @ingroup config
|
/// @ingroup config
|
||||||
$wgLinkTitlesSmartMode = true;
|
$wgLinkTitlesSmartMode = true;
|
||||||
|
|
||||||
|
/// Determines whether or not to check if a page redirects to the current
|
||||||
|
/// page. Normally one would want to have the default behavior (true), but
|
||||||
|
/// this check requires a time-consuming database query for every page in
|
||||||
|
/// the wiki.
|
||||||
|
/// @note For maximum performance, set both $wgLinkTitlesCheckRedirect and
|
||||||
|
/// $wgLinkTitlesEnableNoTargetMagicWord to false in LocalSettings.php.
|
||||||
|
/// On the developer's machine, fetching the target page content increased
|
||||||
|
/// the run time from about 50 ms to about 500 ms on a wiki with 90 pages
|
||||||
|
/// (Intel Core i5-3320M, 2x 2.6 GHz, 16 GB RAM, PHP 5.5.9, Apache 2.4.7,
|
||||||
|
/// MySQL 5.5.37, MediaWiki 1.23.0). If any of the two mentioned variables
|
||||||
|
/// is set to true, a page content request will be performed for every
|
||||||
|
/// page in the wiki whenever a single page is edited or parsed in batch
|
||||||
|
/// mode.
|
||||||
|
/// @ingroup config
|
||||||
|
$wgLinkTitlesCheckRedirect = true;
|
||||||
|
|
||||||
|
/// Determines whether or not the magic word __NOAUTOLINKTARGET__ is
|
||||||
|
/// enabled or not. If __NOAUTOLINKTARGET__ is included in a page, this
|
||||||
|
/// page will never be linked to by the extension. The default is enabled
|
||||||
|
/// (true), but it comes at the cost of performance.
|
||||||
|
/// @note For maximum performance, set both $wgLinkTitlesCheckRedirect and
|
||||||
|
/// $wgLinkTitlesEnableNoTargetMagicWord to false in LocalSettings.php.
|
||||||
|
/// On the developer's machine, fetching the target page content increased
|
||||||
|
/// the run time from about 50 ms to about 500 ms on a wiki with 90 pages
|
||||||
|
/// (Intel Core i5-3320M, 2x 2.6 GHz, 16 GB RAM, PHP 5.5.9, Apache 2.4.7,
|
||||||
|
/// MySQL 5.5.37, MediaWiki 1.23.0). If any of the two mentioned variables
|
||||||
|
/// is set to true, a page content request will be performed for every
|
||||||
|
/// page in the wiki whenever a single page is edited or parsed in batch
|
||||||
|
/// mode.
|
||||||
|
/// @ingroup config
|
||||||
|
$wgLinkTitlesEnableNoTargetMagicWord = true;
|
||||||
|
|
||||||
/// Time limit for online batch processing. This determines the maximum
|
/// Time limit for online batch processing. This determines the maximum
|
||||||
/// amount of time in seconds that page processing will take before a
|
/// amount of time in seconds that page processing will take before a
|
||||||
/// refresh of the special page is issued.
|
/// refresh of the special page is issued.
|
||||||
|
Reference in New Issue
Block a user