mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 17:59:29 +02:00
Change signature of parseContent function.
To be able to use the InternalParseBeforeLinks hook (to be implemented), a different signature was needed. This entailed subsequent changes to calling functions.
This commit is contained in:
@ -63,10 +63,15 @@
|
|||||||
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 ) {
|
||||||
|
|
||||||
// To prevent time-consuming parsing of the page whenever
|
if ( ! $isMinor ) {
|
||||||
// it is edited and saved, we only parse it if the flag
|
$title = $wikiPage->getTitle();
|
||||||
// 'minor edits' is not set.
|
$text = $content->getContentHandler()->serializeContent($content);
|
||||||
return $isMinor or self::parseContent( $wikiPage, $content );
|
$newText = self::parseContent( $title, $text );
|
||||||
|
if ( $newText != $text ) {
|
||||||
|
$content = $content->getContentHandler()->unserializeContent( $newText );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Event handler that is hooked to the ArticleAfterFetchContent event.
|
/// Event handler that is hooked to the ArticleAfterFetchContent event.
|
||||||
@ -85,14 +90,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Core function of the extension, performs the actual parsing of the content.
|
/// Core function of the extension, performs the actual parsing of the content.
|
||||||
/// @param $article Article object
|
/// @param Title $title Title of the page being parsed
|
||||||
/// @param $content Content object that holds the article content
|
/// @param $text String that holds the article content
|
||||||
/// @returns true
|
/// @returns string: parsed text with links added if needed
|
||||||
static function parseContent( WikiPage &$wikiPage, Content &$content ) {
|
private static function parseContent( Title &$title, &$text ) {
|
||||||
// If the page contains the magic word '__NOAUTOLINKS__', do not parse
|
// If the page contains the magic word '__NOAUTOLINKS__', do not parse it.
|
||||||
// the content.
|
if ( MagicWord::get('MAG_LINKTITLES_NOAUTOLINKS')->match( $text ) ) {
|
||||||
if ( $content->matchMagicWord(
|
|
||||||
MagicWord::get('MAG_LINKTITLES_NOAUTOLINKS') ) ) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,8 +124,7 @@
|
|||||||
$templatesDelimiter = '{{[^|]+?}}|{{.+\||';
|
$templatesDelimiter = '{{[^|]+?}}|{{.+\||';
|
||||||
};
|
};
|
||||||
|
|
||||||
LinkTitles::$currentTitle = $wikiPage->getTitle();
|
LinkTitles::$currentTitle = $title;
|
||||||
$text = $content->getContentHandler()->serializeContent($content);
|
|
||||||
$newText = $text;
|
$newText = $text;
|
||||||
|
|
||||||
// Build a regular expression that will capture existing wiki links ("[[...]]"),
|
// Build a regular expression that will capture existing wiki links ("[[...]]"),
|
||||||
@ -241,10 +243,7 @@
|
|||||||
$newText = implode( '', $arr );
|
$newText = implode( '', $arr );
|
||||||
} // $wgLinkTitlesSmartMode
|
} // $wgLinkTitlesSmartMode
|
||||||
}; // foreach $res as $row
|
}; // foreach $res as $row
|
||||||
if ( $newText != $text ) {
|
return $newText;
|
||||||
$content = $content->getContentHandler()->unserializeContent( $newText );
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Automatically processes a single page, given a $title Title object.
|
/// Automatically processes a single page, given a $title Title object.
|
||||||
@ -260,12 +259,16 @@
|
|||||||
$titleObj = Title::makeTitle(0, $title);
|
$titleObj = Title::makeTitle(0, $title);
|
||||||
$page = WikiPage::factory($titleObj);
|
$page = WikiPage::factory($titleObj);
|
||||||
$content = $page->getContent();
|
$content = $page->getContent();
|
||||||
LinkTitles::parseContent($page, $content);
|
$text = $content->getContentHandler()->serializeContent($content);
|
||||||
$page->doQuickEditContent($content,
|
$newText = LinkTitles::parseContent($titleObj, $text);
|
||||||
$context->getUser(),
|
if ( $text != $newText ) {
|
||||||
"Links to existing pages added by LinkTitles bot.",
|
$content = $content->getContentHandler()->unserializeContent( $newText );
|
||||||
true // minor modification
|
$page->doQuickEditContent($content,
|
||||||
);
|
$context->getUser(),
|
||||||
|
"Links to existing pages added by LinkTitles bot.",
|
||||||
|
true // minor modification
|
||||||
|
);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds the two magic words defined by this extension to the list of
|
/// Adds the two magic words defined by this extension to the list of
|
||||||
|
Reference in New Issue
Block a user