mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 17:59:29 +02:00
Add start index option to CLI script.
This commit is contained in:
@ -28,7 +28,24 @@ require_once( "/home/daniel/Documents/Kommunikation/Wiki/maintenance/Maintenance
|
|||||||
require_once( dirname( __FILE__ ) . "/LinkTitles.body.php" );
|
require_once( dirname( __FILE__ ) . "/LinkTitles.body.php" );
|
||||||
|
|
||||||
class LinkTitlesCli extends Maintenance {
|
class LinkTitlesCli extends Maintenance {
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct();
|
||||||
|
$this->addDescription("Iterates over wiki pages and automatically adds links to other pages.");
|
||||||
|
$this->addOption(
|
||||||
|
"start",
|
||||||
|
"Set start index.",
|
||||||
|
false, // not required
|
||||||
|
true, // requires argument
|
||||||
|
"s"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function execute() {
|
public function execute() {
|
||||||
|
$index = intval($this->getOption('start', 0));
|
||||||
|
if ( $index < 0 ) {
|
||||||
|
$this->error('FATAL: Start index must be 0 or greater.', 1);
|
||||||
|
};
|
||||||
|
|
||||||
// Connect to the database
|
// Connect to the database
|
||||||
$dbr = $this->getDB( DB_SLAVE );
|
$dbr = $this->getDB( DB_SLAVE );
|
||||||
|
|
||||||
@ -39,20 +56,27 @@ class LinkTitlesCli extends Maintenance {
|
|||||||
array(
|
array(
|
||||||
'page_namespace = 0',
|
'page_namespace = 0',
|
||||||
),
|
),
|
||||||
__METHOD__
|
__METHOD__,
|
||||||
|
array(
|
||||||
|
'LIMIT' => 999999999,
|
||||||
|
'OFFSET' => $index
|
||||||
|
)
|
||||||
);
|
);
|
||||||
$index = 0;
|
|
||||||
$numPages = $res->numRows();
|
$numPages = $res->numRows();
|
||||||
$context = RequestContext::getMain();
|
$context = RequestContext::getMain();
|
||||||
$this->output("Processing ${numPages} pages...\n");
|
$this->output("Processing ${numPages} pages, starting at index ${index}...\n");
|
||||||
|
|
||||||
// Iterate through the pages; break if a time limit is exceeded.
|
// Iterate through the pages; break if a time limit is exceeded.
|
||||||
foreach ( $res as $row ) {
|
foreach ( $res as $row ) {
|
||||||
$index += 1;
|
$index += 1;
|
||||||
$curTitle = $row->page_title;
|
$curTitle = $row->page_title;
|
||||||
$this->output( sprintf("\r%02.0f%%", $index / $numPages * 100) );
|
$this->output(
|
||||||
|
sprintf("\rPage #%d (%02.0f%%)", $index, $index / $numPages * 100)
|
||||||
|
);
|
||||||
LinkTitles::processPage($curTitle, $context);
|
LinkTitles::processPage($curTitle, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->output("Finished parsing.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,8 +111,8 @@ class SpecialLinkTitles extends SpecialPage {
|
|||||||
),
|
),
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
array(
|
array(
|
||||||
'OFFSET' => $start,
|
'LIMIT' => 999999999,
|
||||||
'LIMIT' => '1'
|
'OFFSET' => $start
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -125,7 +125,6 @@ class SpecialLinkTitles extends SpecialPage {
|
|||||||
// Check if the time limit is exceeded
|
// Check if the time limit is exceeded
|
||||||
if ( microtime(true)-$startTime > $wgLinkTitlesTimeLimit )
|
if ( microtime(true)-$startTime > $wgLinkTitlesTimeLimit )
|
||||||
{
|
{
|
||||||
$reloads += 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,6 +135,7 @@ class SpecialLinkTitles extends SpecialPage {
|
|||||||
// the extension's special page.
|
// the extension's special page.
|
||||||
if ( $start < $end )
|
if ( $start < $end )
|
||||||
{
|
{
|
||||||
|
$reloads += 1;
|
||||||
// Build a form with hidden values and output JavaScript code that
|
// Build a form with hidden values and output JavaScript code that
|
||||||
// immediately submits the form in order to continue the process.
|
// immediately submits the form in order to continue the process.
|
||||||
$output->addHTML($this->getReloaderForm($request->getRequestURL(),
|
$output->addHTML($this->getReloaderForm($request->getRequestURL(),
|
||||||
|
Reference in New Issue
Block a user