mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 09:49:31 +02:00
Merge branch 'release-4.0.5'
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2012-2016 Daniel Kraus <bovender@bovender.de> ('bovender')
|
||||
* Copyright 2012-2016 Daniel Kraus <bovender@bovender.de> @bovender
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -65,21 +65,21 @@ class Cli extends \Maintenance {
|
||||
true, // requires argument
|
||||
"s"
|
||||
);
|
||||
$this->addOption(
|
||||
$this->addOption(
|
||||
"page",
|
||||
"page to process",
|
||||
"page name to process",
|
||||
false, // not required
|
||||
true, // requires argument
|
||||
"p"
|
||||
);
|
||||
$this->addOption(
|
||||
$this->addOption(
|
||||
"log",
|
||||
"enables logging to console",
|
||||
false, // not required
|
||||
false, // requires no argument
|
||||
"l"
|
||||
);
|
||||
$this->addOption(
|
||||
$this->addOption(
|
||||
"debug",
|
||||
"enables debug logging to console",
|
||||
false, // not required
|
||||
@ -92,41 +92,54 @@ class Cli extends \Maintenance {
|
||||
/// if the `--start` option is given) and call LinkTitles::processPage() for
|
||||
/// each page.
|
||||
public function execute() {
|
||||
global $wgLinkTitlesNamespaces;
|
||||
if ($this->hasOption('log'))
|
||||
{
|
||||
Extension::$ltConsoleOutput = true;
|
||||
}
|
||||
if ($this->hasOption('debug'))
|
||||
{
|
||||
Extension::$ltConsoleOutputDebug = true;
|
||||
}
|
||||
if ( $this->hasOption('page') ) {
|
||||
if ( !$this->hasOption( 'start' ) ) {
|
||||
$this->singlePage();
|
||||
}
|
||||
else {
|
||||
$this->error( 'FATAL: Must not use --start option with --page option.', 2 );
|
||||
}
|
||||
}
|
||||
else {
|
||||
$startIndex = intval( $this->getOption( 'start', 0 ) );
|
||||
if ( $startIndex < 0 ) {
|
||||
$this->error( 'FATAL: Start index must be 0 or greater.', 1 );
|
||||
};
|
||||
$this->allPages( $startIndex);
|
||||
}
|
||||
}
|
||||
|
||||
$index = intval($this->getOption('start', 0));
|
||||
if ( $index < 0 ) {
|
||||
$this->error('FATAL: Start index must be 0 or greater.', 1);
|
||||
};
|
||||
private function singlePage() {
|
||||
$pageName = strval( $this->getOption( 'page' ) );
|
||||
$this->output( "Processing single page: '$pageName'\n" );
|
||||
$title = \Title::newFromText( $pageName );
|
||||
$success = Extension::processPage( $title, \RequestContext::getMain() );
|
||||
if ( $success ) {
|
||||
$this->output( "Finished.\n" );
|
||||
}
|
||||
else {
|
||||
$this->error( 'FATAL: There is no such page.', 3 );
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
if ($this->hasOption('log'))
|
||||
{
|
||||
Extension::$ltConsoleOutput = true;
|
||||
}
|
||||
if ($this->hasOption('debug'))
|
||||
{
|
||||
Extension::$ltConsoleOutputDebug = true;
|
||||
}
|
||||
|
||||
$pagename = strval($this->getOption('page'));
|
||||
if ($pagename != null)
|
||||
{
|
||||
|
||||
$curTitle = Title::newFromDBkey( $pagename );
|
||||
LinkTitles::processPage($curTitle,RequestContext::getMain() );
|
||||
$this->output("\nFinished parsing.\n");
|
||||
return;
|
||||
}
|
||||
// get our Namespaces
|
||||
$namespacesClause = str_replace( '_', ' ','(' . implode( ', ',$wgLinkTitlesNamespaces ) . ')' );
|
||||
|
||||
// Connect to the database
|
||||
$dbr = $this->getDB( DB_SLAVE );
|
||||
private function allPages( $index = 0 ) {
|
||||
global $wgLinkTitlesNamespaces;
|
||||
|
||||
// Retrieve page names from the database.
|
||||
$dbr = $this->getDB( DB_SLAVE );
|
||||
$namespacesClause = str_replace( '_', ' ','(' . implode( ', ', $wgLinkTitlesNamespaces ) . ')' );
|
||||
$res = $dbr->select(
|
||||
'page',
|
||||
array('page_title', 'page_namespace'),
|
||||
array( 'page_title', 'page_namespace' ),
|
||||
array(
|
||||
'page_namespace IN ' . $namespacesClause,
|
||||
),
|
||||
@ -138,19 +151,16 @@ class Cli extends \Maintenance {
|
||||
);
|
||||
$numPages = $res->numRows();
|
||||
$context = \RequestContext::getMain();
|
||||
$this->output("Processing ${numPages} pages, starting at index ${index}...\n");
|
||||
$this->output( "Processing ${numPages} pages, starting at index ${index}...\n" );
|
||||
|
||||
// Iterate through the pages; break if a time limit is exceeded.
|
||||
foreach ( $res as $row ) {
|
||||
$index += 1;
|
||||
$curTitle = \Title::makeTitleSafe( $row->page_namespace, $row->page_title);
|
||||
$this->output(
|
||||
sprintf("\rPage #%d (%02.0f%%) ", $index, $index / $numPages * 100)
|
||||
);
|
||||
Extension::processPage($curTitle, $context);
|
||||
$index += 1; // at this point, $index is only needed for reporting to user
|
||||
$title = \Title::makeTitleSafe( $row->page_namespace, $row->page_title );
|
||||
$this->output( sprintf( "\rPage #%d (%02.0f%%) ", $index, $index / $numPages * 100 ) );
|
||||
Extension::processPage( $title, $context );
|
||||
}
|
||||
|
||||
$this->output("\nFinished parsing.\n");
|
||||
$this->output( "\rFinished. \n" );
|
||||
}
|
||||
}
|
||||
|
||||
|
10
NEWS
10
NEWS
@ -1,3 +1,13 @@
|
||||
Version 4.0.5 (2016-12-14)
|
||||
------------------------------------------------------------------------
|
||||
|
||||
- Fix: Maintenance script would crash if invoked with the --page option.
|
||||
- Fix: Remove leftover error log call.
|
||||
- Improvement: Refactored maintenance script, improving user interaction.
|
||||
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
|
||||
|
||||
Version 4.0.4 (2016-11-30)
|
||||
------------------------------------------------------------------------
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
],
|
||||
"type": "parserhook",
|
||||
"url": "https://www.mediawiki.org/wiki/Extension:LinkTitles",
|
||||
"version": "4.0.4",
|
||||
"version": "4.0.5",
|
||||
"license-name": "GPL-2.0+",
|
||||
"descriptionmsg": "linktitles-desc",
|
||||
"requires": {
|
||||
|
2
gh-pages
2
gh-pages
Submodule gh-pages updated: 28e9c0416e...fe99cf4e03
@ -124,7 +124,6 @@ class Extension {
|
||||
( $wgLinkTitlesPreferShortTitles ) ? $sort_order = 'ASC' : $sort_order = 'DESC';
|
||||
( $wgLinkTitlesFirstOnly ) ? $limit = 1 : $limit = -1;
|
||||
$limitReached = false;
|
||||
error_log($wgLinkTitlesFirstOnly);
|
||||
|
||||
self::$currentTitle = $title;
|
||||
$newText = $text;
|
||||
@ -248,26 +247,32 @@ class Extension {
|
||||
/// Automatically processes a single page, given a $title Title object.
|
||||
/// This function is called by the SpecialLinkTitles class and the
|
||||
/// LinkTitlesJob class.
|
||||
/// @param string $title Page title.
|
||||
/// @param RequestContext $context Current context.
|
||||
/// @param Title $title Title object.
|
||||
/// @param RequestContext $context Current request context.
|
||||
/// If in doubt, call MediaWiki's `RequestContext::getMain()`
|
||||
/// to obtain such an object.
|
||||
/// @returns undefined
|
||||
public static function processPage( $title, \RequestContext $context ) {
|
||||
$titleObj = \Title::makeTitle(0, $title);
|
||||
self::ltLog('Processing '. $titleObj->getPrefixedText());
|
||||
$page = \WikiPage::factory($titleObj);
|
||||
/// @returns boolean True if the page exists, false if the page does not exist
|
||||
public static function processPage( \Title $title, \RequestContext $context ) {
|
||||
self::ltLog('Processing '. $title->getPrefixedText());
|
||||
$page = \WikiPage::factory($title);
|
||||
$content = $page->getContent();
|
||||
$text = $content->getContentHandler()->serializeContent($content);
|
||||
$newText = self::parseContent($titleObj, $text);
|
||||
if ( $text != $newText ) {
|
||||
$content = $content->getContentHandler()->unserializeContent( $newText );
|
||||
$page->doQuickEditContent($content,
|
||||
$context->getUser(),
|
||||
"Links to existing pages added by LinkTitles bot.", // TODO: i18n
|
||||
true // minor modification
|
||||
);
|
||||
};
|
||||
if ( $content != null ) {
|
||||
$text = $content->getContentHandler()->serializeContent($content);
|
||||
$newText = self::parseContent($title, $text);
|
||||
if ( $text != $newText ) {
|
||||
$content = $content->getContentHandler()->unserializeContent( $newText );
|
||||
$page->doQuickEditContent(
|
||||
$content,
|
||||
$context->getUser(),
|
||||
"Links to existing pages added by LinkTitles bot.", // TODO: i18n
|
||||
true // minor modification
|
||||
);
|
||||
};
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds the two magic words defined by this extension to the list of
|
||||
|
Reference in New Issue
Block a user