mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 01:39:30 +02:00
Fix parsing on page viewing only
This commit is contained in:
@ -29,6 +29,18 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
class LinkTitles {
|
class LinkTitles {
|
||||||
|
/// Setup function, hooks the extension's functions to MediaWiki events.
|
||||||
|
public static function setup() {
|
||||||
|
global $wgLinkTitlesParseOnEdit;
|
||||||
|
global $wgLinkTitlesParseOnRender;
|
||||||
|
global $wgHooks;
|
||||||
|
if ( $wgLinkTitlesParseOnEdit ) {
|
||||||
|
$wgHooks['ArticleSave'][] = 'LinkTitles::onArticleSave';
|
||||||
|
};
|
||||||
|
if ( $wgLinkTitlesParseOnRender ) {
|
||||||
|
$wgHooks['ArticleAfterFetchContent'][] = 'LinkTitles::onArticleAfterFetchContent';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// This function is hooked to the ArticleSave event.
|
/// This function is hooked to the ArticleSave event.
|
||||||
/// It will be called whenever a page is about to be
|
/// It will be called whenever a page is about to be
|
||||||
@ -39,19 +51,25 @@
|
|||||||
// To prevent time-consuming parsing of the page whenever
|
// To prevent time-consuming parsing of the page whenever
|
||||||
// it is edited and saved, we only parse it if the flag
|
// it is edited and saved, we only parse it if the flag
|
||||||
// 'minor edits' is not set.
|
// 'minor edits' is not set.
|
||||||
if ( !$minor ) {
|
return $minor or self::parseContent( $article, $content );
|
||||||
return parseContent( $article, $content );
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called when an ArticleAfterFetchContent event occurs; this requires the
|
/// Called when an ArticleAfterFetchContent event occurs; this requires the
|
||||||
/// $wgLinkTitlesParseOnRender option to be set to 'true'
|
/// $wgLinkTitlesParseOnRender option to be set to 'true'
|
||||||
public static function onArticleAfterFetchContent( &$article, &$content ) {
|
public static function onArticleAfterFetchContent( &$article, &$content ) {
|
||||||
return parseContent( $article, $content );
|
// The ArticleAfterFetchContent event is triggered whenever page content
|
||||||
|
// is retrieved from the database, i.e. also for editing etc.
|
||||||
|
// Therefore we access the global $action variabl to only parse the
|
||||||
|
// content when the page is viewed.
|
||||||
|
global $action;
|
||||||
|
if ( in_array( $action, array('view', 'render', 'purge') ) ) {
|
||||||
|
self::parseContent( $article, $content );
|
||||||
|
};
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function performs the actual parsing of the content.
|
/// This function performs the actual parsing of the content.
|
||||||
static function parseContent( &$article, &$content ) {
|
static function parseContent( &$article, &$text ) {
|
||||||
// Configuration variables need to be defined here as globals.
|
// Configuration variables need to be defined here as globals.
|
||||||
global $wgLinkTitlesPreferShortTitles;
|
global $wgLinkTitlesPreferShortTitles;
|
||||||
global $wgLinkTitlesMinimumTitleLength;
|
global $wgLinkTitlesMinimumTitleLength;
|
||||||
@ -98,6 +116,7 @@
|
|||||||
if ( $newText != '' ) {
|
if ( $newText != '' ) {
|
||||||
$text = $newText;
|
$text = $newText;
|
||||||
};
|
};
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -23,17 +23,16 @@
|
|||||||
die( 'Not an entry point.' );
|
die( 'Not an entry point.' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
ini_set('display_errors', 'Off');
|
ini_set('display_errors', 'Off');
|
||||||
ini_set('error_log', 'php://stderr');
|
ini_set('error_log', 'php://stderr');
|
||||||
$wgMainCacheType = CACHE_NONE;
|
$wgMainCacheType = CACHE_NONE;
|
||||||
$wgCacheDirectory = false;
|
$wgCacheDirectory = false;
|
||||||
*/
|
|
||||||
|
|
||||||
// Configuration variables
|
// Configuration variables
|
||||||
$wgLinkTitlesPreferShortTitles = false;
|
$wgLinkTitlesPreferShortTitles = false;
|
||||||
$wgLinkTitlesMinimumTitleLength = 3;
|
$wgLinkTitlesMinimumTitleLength = 3;
|
||||||
|
$wgLinkTitlesParseHeadings = false;
|
||||||
$wgLinkTitlesParseOnEdit = true;
|
$wgLinkTitlesParseOnEdit = true;
|
||||||
$wgLinkTitlesParseOnRender = false;
|
$wgLinkTitlesParseOnRender = false;
|
||||||
|
|
||||||
@ -48,14 +47,7 @@
|
|||||||
|
|
||||||
$wgExtensionMessagesFiles['LinkTitles'] = dirname( __FILE__ ) . '/LinkTitles.i18n.php';
|
$wgExtensionMessagesFiles['LinkTitles'] = dirname( __FILE__ ) . '/LinkTitles.i18n.php';
|
||||||
$wgAutoloadClasses['LinkTitles'] = dirname(__FILE__) . '/LinkTitles.body.php';
|
$wgAutoloadClasses['LinkTitles'] = dirname(__FILE__) . '/LinkTitles.body.php';
|
||||||
|
$wgExtensionFunctions[] = 'LinkTitles::setup';
|
||||||
|
|
||||||
// Hook up our custom function to the ArticleSave event.
|
|
||||||
if ( $wgLinkTitlesParseOnEdit ) {
|
|
||||||
$wgHooks['ArticleSave'][] = 'LinkTitles::onArticleSave';
|
|
||||||
};
|
|
||||||
if ( $wgLinkTitlesParseOnRender ) {
|
|
||||||
$wgHooks['ArticleAfterFetchContent'][] = 'LinkTitles::onArticleAfterFetchContent';
|
|
||||||
};
|
|
||||||
|
|
||||||
// vim: ts=2:sw=2:noet
|
// vim: ts=2:sw=2:noet
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user