mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 09:49:31 +02:00
Merge branch 'namespaces' of https://github.com/c0nnex/LinkTitles into c0nnex-namespaces
This commit is contained in:
@ -65,6 +65,26 @@ class Cli extends \Maintenance {
|
||||
true, // requires argument
|
||||
"s"
|
||||
);
|
||||
$this->addOption(
|
||||
"page",
|
||||
"page to process",
|
||||
false, // not required
|
||||
true, // requires argument
|
||||
"p"
|
||||
);
|
||||
$this->addOption(
|
||||
"log",
|
||||
"enables logging to console",
|
||||
false, // not required
|
||||
false, // requires no argument
|
||||
"l"
|
||||
);
|
||||
$this->addOption(
|
||||
"debug",
|
||||
"enables debug logging to console",
|
||||
false, // not required
|
||||
false // requires no argument
|
||||
);
|
||||
}
|
||||
|
||||
/// Main function of the maintenance script.
|
||||
@ -72,20 +92,43 @@ class Cli extends \Maintenance {
|
||||
/// if the `--start` option is given) and call LinkTitles::processPage() for
|
||||
/// each page.
|
||||
public function execute() {
|
||||
global $wgLinkTitlesNamespaces;
|
||||
|
||||
$index = intval($this->getOption('start', 0));
|
||||
if ( $index < 0 ) {
|
||||
$this->error('FATAL: Start index must be 0 or greater.', 1);
|
||||
};
|
||||
|
||||
if ($this->hasOption('log'))
|
||||
{
|
||||
LinkTitles::$ltConsoleOutput = true;
|
||||
}
|
||||
if ($this->hasOption('debug'))
|
||||
{
|
||||
LinkTitles::$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 );
|
||||
|
||||
// Retrieve page names from the database.
|
||||
$res = $dbr->select(
|
||||
'page',
|
||||
'page_title',
|
||||
array('page_title', 'page_namespace'),
|
||||
array(
|
||||
'page_namespace = 0',
|
||||
'page_namespace IN ' . $namespacesClause,
|
||||
),
|
||||
__METHOD__,
|
||||
array(
|
||||
@ -100,7 +143,7 @@ class Cli extends \Maintenance {
|
||||
// Iterate through the pages; break if a time limit is exceeded.
|
||||
foreach ( $res as $row ) {
|
||||
$index += 1;
|
||||
$curTitle = $row->page_title;
|
||||
$curTitle = Title::makeTitleSafe( $row->page_namespace, $row->page_title);
|
||||
$this->output(
|
||||
sprintf("\rPage #%d (%02.0f%%)", $index, $index / $numPages * 100)
|
||||
);
|
||||
|
Reference in New Issue
Block a user