コード例 #1
0
 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);
     // Retrieve page names from the database.
     $res = $dbr->select('page', 'page_title', array('page_namespace = 0'), __METHOD__, array('LIMIT' => 999999999, 'OFFSET' => $index));
     $numPages = $res->numRows();
     $context = RequestContext::getMain();
     $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("\rPage #%d (%02.0f%%)", $index, $index / $numPages * 100));
         LinkTitles::processPage($curTitle, $context);
     }
     $this->output("\nFinished parsing.\n");
 }
コード例 #2
0
 private function process(WebRequest &$request, OutputPage &$output)
 {
     global $wgLinkTitlesTimeLimit;
     // Start the stopwatch
     $startTime = microtime(true);
     // Connect to the database
     $dbr = wfGetDB(DB_SLAVE);
     // Fetch the start index and max number of records from the POST
     // request.
     $postValues = $request->getValues();
     // Convert the start index to an integer; this helps preventing
     // SQL injection attacks via forged POST requests.
     $start = intval($postValues['s']);
     // If an end index was given, we don't need to query the database
     if (array_key_exists('e', $postValues)) {
         $end = intval($postValues['e']);
     } else {
         // No end index was given. Therefore, count pages now.
         $end = $this->countPages($dbr);
     }
     array_key_exists('r', $postValues) ? $reloads = $postValues['r'] : ($reloads = 0);
     // Retrieve page names from the database.
     $res = $dbr->select('page', 'page_title', array('page_namespace = 0'), __METHOD__, array('LIMIT' => 999999999, 'OFFSET' => $start));
     // Iterate through the pages; break if a time limit is exceeded.
     foreach ($res as $row) {
         $curTitle = $row->page_title;
         LinkTitles::processPage($curTitle, $this->getContext());
         $start += 1;
         // Check if the time limit is exceeded
         if (microtime(true) - $startTime > $wgLinkTitlesTimeLimit) {
             break;
         }
     }
     $this->addProgressInfo($output, $curTitle, $start, $end);
     // If we have not reached the last page yet, produce code to reload
     // 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(), $start, $end, $reloads));
     } else {
         $this->addCompletedInfo($output, $start, $end, $reloads);
     }
 }