http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96012
Revision: 96012
Author: catrope
Date: 2011-09-01 16:55:00 +0000 (Thu, 01 Sep 2011)
Log Message:
-----------
RL2: Add maintenace script for populating the gadgetpagelist table
Added Paths:
-----------
branches/RL2/extensions/Gadgets/populateGadgetPageList.php
Added: branches/RL2/extensions/Gadgets/populateGadgetPageList.php
===================================================================
--- branches/RL2/extensions/Gadgets/populateGadgetPageList.php
(rev 0)
+++ branches/RL2/extensions/Gadgets/populateGadgetPageList.php 2011-09-01
16:55:00 UTC (rev 96012)
@@ -0,0 +1,62 @@
+<?php
+
+$IP = getenv( 'MW_INSTALL_PATH' );
+if ( $IP === false ) {
+ $IP = dirname( __FILE__ ) . '/../..';
+}
+require( "$IP/maintenance/Maintenance.php" );
+
+class PopulateGadgetPageList extends Maintenance {
+ const BATCH_SIZE = 100;
+
+ public function __construct() {
+ parent::__construct();
+ $this->mDescription = "Populates the gadgetpagelist table";
+ }
+
+ public function execute() {
+ $dbr = wfGetDB( DB_SLAVE );
+ $dbw = wfGetDB( DB_MASTER );
+
+ $this->output( "Populating gadgetpagelist table ...\n" );
+
+ $lastPageID = 0;
+ $processed = 0;
+ $written = 0;
+ while ( true ) {
+ // Grab a batch of pages from the page table
+ $res = $dbr->select( 'page',
+ array( 'page_id', 'page_namespace',
'page_title', 'page_is_redirect' ),
+ "page_id > $lastPageID", __METHOD__,
+ array( 'LIMIT' => self::BATCH_SIZE, 'ORDER BY'
=> 'page_id' )
+ );
+ if ( $dbr->numRows( $res ) == 0 ) {
+ // We've reached the end
+ break;
+ }
+ $processed += $dbr->numRows( $res );
+
+ // Build gadgetpagelist rows
+ $gplRows = array();
+ foreach ( $res as $row ) {
+ $title = Title::newFromRow( $row );
+ if ( GadgetPageList::isGadgetPage( $title ) ) {
+ $gplRows[] =
GadgetPageList::getRowForTitle( $title );
+ }
+ $lastPageID = intval( $row->page_id );
+ }
+ $dbr->freeResult( $res );
+
+ // Insert the new rows
+ $dbw->insert( 'gadgetpagelist', $gplRows, __METHOD__,
array( 'IGNORE' ) );
+ $written += count( $gplRows );
+
+ $this->output( "... $processed pages processed,
$written rows written, page_id $lastPageID\n" );
+ }
+
+ $this->output( "Done\n" );
+ }
+}
+
+$maintClass = "PopulateGadgetPageList";
+require_once( DO_MAINTENANCE );
\ No newline at end of file
Property changes on: branches/RL2/extensions/Gadgets/populateGadgetPageList.php
___________________________________________________________________
Added: svn:eol-style
+ native
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs