mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 09:49:31 +02:00
Refactor Extension class.
This commit is contained in:
@ -31,26 +31,23 @@ class Extension {
|
|||||||
/// Event handler that is hooked to the PageContentSave 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 ) {
|
||||||
global $wgLinkTitlesParseOnEdit;
|
|
||||||
global $wgLinkTitlesNamespaces;
|
|
||||||
if ( !$wgLinkTitlesParseOnEdit ) return true; // TODO: refactor with following if
|
|
||||||
|
|
||||||
if ( !$isMinor ) {
|
$config = new Config();
|
||||||
|
if ( !$config->parseOnEdit || $isMinor ) return true;
|
||||||
|
|
||||||
$title = $wikiPage->getTitle();
|
$title = $wikiPage->getTitle();
|
||||||
|
|
||||||
// Only process if page is in one of our namespaces we want to link
|
// Only process if page is in one of our namespaces we want to link
|
||||||
// Fixes ugly autolinking of sidebar pages
|
// Fixes ugly autolinking of sidebar pages
|
||||||
if ( in_array( $title->getNamespace(), $wgLinkTitlesNamespaces )) {
|
if ( in_array( $title->getNamespace(), $config->nameSpaces )) {
|
||||||
$text = $content->getContentHandler()->serializeContent( $content );
|
$text = $content->getContentHandler()->serializeContent( $content );
|
||||||
if ( !\MagicWord::get( 'MAG_LINKTITLES_NOAUTOLINKS' )->match( $text ) ) {
|
if ( !\MagicWord::get( 'MAG_LINKTITLES_NOAUTOLINKS' )->match( $text ) ) {
|
||||||
$config = new Config();
|
|
||||||
$linker = new Linker( $config );
|
$linker = new Linker( $config );
|
||||||
$newText = $linker->linkContent( $title, $text );
|
$newText = $linker->linkContent( $title, $text );
|
||||||
if ( $newText != $text ) {
|
if ( $newText != $text ) {
|
||||||
$content = $content->getContentHandler()->unserializeContent( $newText );
|
$content = $content->getContentHandler()->unserializeContent( $newText );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user