Refactor Extension class.

This commit is contained in:
Daniel Kraus
2017-08-27 23:09:38 +02:00
parent 2c0eb6839b
commit 0d9e74d7e9

View File

@ -31,26 +31,23 @@ class Extension {
/// Event handler that is hooked to the PageContentSave event.
public static function onPageContentSave( &$wikiPage, &$user, &$content, &$summary,
$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();
// Only process if page is in one of our namespaces we want to link
// Fixes ugly autolinking of sidebar pages
if ( in_array( $title->getNamespace(), $wgLinkTitlesNamespaces )) {
if ( in_array( $title->getNamespace(), $config->nameSpaces )) {
$text = $content->getContentHandler()->serializeContent( $content );
if ( !\MagicWord::get( 'MAG_LINKTITLES_NOAUTOLINKS' )->match( $text ) ) {
$config = new Config();
$linker = new Linker( $config );
$newText = $linker->linkContent( $title, $text );
if ( $newText != $text ) {
$content = $content->getContentHandler()->unserializeContent( $newText );
}
}
}
};
return true;
}