diff --git a/LinkTitles.cli.php b/LinkTitles.cli.php index 383cdae..baaa43d 100755 --- a/LinkTitles.cli.php +++ b/LinkTitles.cli.php @@ -28,7 +28,24 @@ require_once( "/home/daniel/Documents/Kommunikation/Wiki/maintenance/Maintenance require_once( dirname( __FILE__ ) . "/LinkTitles.body.php" ); 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() { + $index = intval($this->getOption('start', 0)); + if ( $index < 0 ) { + $this->error('FATAL: Start index must be 0 or greater.', 1); + }; + // Connect to the database $dbr = $this->getDB( DB_SLAVE ); @@ -39,20 +56,27 @@ class LinkTitlesCli extends Maintenance { array( 'page_namespace = 0', ), - __METHOD__ + __METHOD__, + array( + 'LIMIT' => 999999999, + 'OFFSET' => $index + ) ); - $index = 0; $numPages = $res->numRows(); $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. foreach ( $res as $row ) { $index += 1; $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); } + + $this->output("Finished parsing."); } } diff --git a/SpecialLinkTitles.php b/SpecialLinkTitles.php index 5689076..0b0af2a 100644 --- a/SpecialLinkTitles.php +++ b/SpecialLinkTitles.php @@ -111,8 +111,8 @@ class SpecialLinkTitles extends SpecialPage { ), __METHOD__, array( - 'OFFSET' => $start, - 'LIMIT' => '1' + 'LIMIT' => 999999999, + 'OFFSET' => $start ) ); @@ -125,7 +125,6 @@ class SpecialLinkTitles extends SpecialPage { // Check if the time limit is exceeded if ( microtime(true)-$startTime > $wgLinkTitlesTimeLimit ) { - $reloads += 1; break; } } @@ -136,6 +135,7 @@ class SpecialLinkTitles extends SpecialPage { // the extension's special page. if ( $start < $end ) { + $reloads += 1; // Build a form with hidden values and output JavaScript code that // immediately submits the form in order to continue the process. $output->addHTML($this->getReloaderForm($request->getRequestURL(),