mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 17:59:29 +02:00
Fix page option in maintenance script.
- Fix: Maintenance script would crash if invoked with the --page option. Closes #13.
This commit is contained in:
@ -111,11 +111,16 @@ class Cli extends \Maintenance {
|
|||||||
$pagename = strval($this->getOption('page'));
|
$pagename = strval($this->getOption('page'));
|
||||||
if ($pagename != null)
|
if ($pagename != null)
|
||||||
{
|
{
|
||||||
|
$this->output( 'Processing single page: ' . $pagename);
|
||||||
$curTitle = Title::newFromDBkey( $pagename );
|
$title = \Title::newFromText( $pagename );
|
||||||
LinkTitles::processPage($curTitle,RequestContext::getMain() );
|
$success = Extension::processPage( $title, \RequestContext::getMain() );
|
||||||
|
if ( $success ) {
|
||||||
$this->output( "\nFinished parsing.\n" );
|
$this->output( "\nFinished parsing.\n" );
|
||||||
return;
|
}
|
||||||
|
else {
|
||||||
|
$this->output( "\nError: There is no such page.\n" );
|
||||||
|
}
|
||||||
|
return $success;
|
||||||
}
|
}
|
||||||
// get our Namespaces
|
// get our Namespaces
|
||||||
$namespacesClause = str_replace( '_', ' ','(' . implode( ', ',$wgLinkTitlesNamespaces ) . ')' );
|
$namespacesClause = str_replace( '_', ' ','(' . implode( ', ',$wgLinkTitlesNamespaces ) . ')' );
|
||||||
@ -150,7 +155,7 @@ class Cli extends \Maintenance {
|
|||||||
Extension::processPage($curTitle, $context);
|
Extension::processPage($curTitle, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->output("\nFinished parsing.\n");
|
$this->output("\rFinished parsing. \n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,26 +248,32 @@ class Extension {
|
|||||||
/// Automatically processes a single page, given a $title Title object.
|
/// Automatically processes a single page, given a $title Title object.
|
||||||
/// This function is called by the SpecialLinkTitles class and the
|
/// This function is called by the SpecialLinkTitles class and the
|
||||||
/// LinkTitlesJob class.
|
/// LinkTitlesJob class.
|
||||||
/// @param string $title Page title.
|
/// @param Title $title Title object.
|
||||||
/// @param RequestContext $context Current context.
|
/// @param RequestContext $context Current request context.
|
||||||
/// If in doubt, call MediaWiki's `RequestContext::getMain()`
|
/// If in doubt, call MediaWiki's `RequestContext::getMain()`
|
||||||
/// to obtain such an object.
|
/// to obtain such an object.
|
||||||
/// @returns undefined
|
/// @returns boolean True if the page exists, false if the page does not exist
|
||||||
public static function processPage( $title, \RequestContext $context ) {
|
public static function processPage( \Title $title, \RequestContext $context ) {
|
||||||
$titleObj = \Title::makeTitle(0, $title);
|
self::ltLog('Processing '. $title->getPrefixedText());
|
||||||
self::ltLog('Processing '. $titleObj->getPrefixedText());
|
$page = \WikiPage::factory($title);
|
||||||
$page = \WikiPage::factory($titleObj);
|
|
||||||
$content = $page->getContent();
|
$content = $page->getContent();
|
||||||
|
if ( $content != null ) {
|
||||||
$text = $content->getContentHandler()->serializeContent($content);
|
$text = $content->getContentHandler()->serializeContent($content);
|
||||||
$newText = self::parseContent($titleObj, $text);
|
$newText = self::parseContent($title, $text);
|
||||||
if ( $text != $newText ) {
|
if ( $text != $newText ) {
|
||||||
$content = $content->getContentHandler()->unserializeContent( $newText );
|
$content = $content->getContentHandler()->unserializeContent( $newText );
|
||||||
$page->doQuickEditContent($content,
|
$page->doQuickEditContent(
|
||||||
|
$content,
|
||||||
$context->getUser(),
|
$context->getUser(),
|
||||||
"Links to existing pages added by LinkTitles bot.", // TODO: i18n
|
"Links to existing pages added by LinkTitles bot.", // TODO: i18n
|
||||||
true // minor modification
|
true // minor modification
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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