mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 09:49:31 +02:00
Implement InternalParseBeforeLinks hook.
This replaces the ArticleAfterFetchContent hook and enables the extension to parse output produced by templates for links.
This commit is contained in:
@ -53,13 +53,12 @@
|
|||||||
$wgHooks['PageContentSave'][] = 'LinkTitles::onPageContentSave';
|
$wgHooks['PageContentSave'][] = 'LinkTitles::onPageContentSave';
|
||||||
};
|
};
|
||||||
if ( $wgLinkTitlesParseOnRender ) {
|
if ( $wgLinkTitlesParseOnRender ) {
|
||||||
$wgHooks['ArticleAfterFetchContentObject'][] =
|
$wgHooks['InternalParseBeforeLinks'][] = 'LinkTitles::onInternalParseBeforeLinks';
|
||||||
'LinkTitles::onArticleAfterFetchContentObject';
|
|
||||||
};
|
};
|
||||||
$wgHooks['GetDoubleUnderscoreIDs'][] = 'LinkTitles::onGetDoubleUnderscoreIDs';
|
$wgHooks['GetDoubleUnderscoreIDs'][] = 'LinkTitles::onGetDoubleUnderscoreIDs';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Event handler that is hooked to the ArticleSave event.
|
/// Event handler that is hooked to the PageContentSave event.
|
||||||
public static function onPageContentSave( &$wikiPage, &$user, &$content, &$summary,
|
public static function onPageContentSave( &$wikiPage, &$user, &$content, &$summary,
|
||||||
$isMinor, $isWatch, $section, &$flags, &$status ) {
|
$isMinor, $isWatch, $section, &$flags, &$status ) {
|
||||||
|
|
||||||
@ -74,18 +73,12 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Event handler that is hooked to the ArticleAfterFetchContent event.
|
/// Event handler that is hooked to the InternalParseBeforeLinks event.
|
||||||
/// @param $article Article object
|
/// @param Parser $parser Parser that raised the event.
|
||||||
/// @param $content Content object that holds the article content
|
/// @param $text Preprocessed text of the page.
|
||||||
public static function onArticleAfterFetchContentObject( &$article, &$content ) {
|
public static function onInternalParseBeforeLinks( Parser &$parser, &$text ) {
|
||||||
// The ArticleAfterFetchContentObject event is triggered whenever page
|
$title = $parser->getTitle();
|
||||||
// content is retrieved from the database, i.e. also for editing etc.
|
$text = self::parseContent( $title, $text );
|
||||||
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user