Index: branches/RL2/extensions/Gadgets/populateGadgetPageList.php |
— | — | @@ -0,0 +1,62 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +$IP = getenv( 'MW_INSTALL_PATH' ); |
| 5 | +if ( $IP === false ) { |
| 6 | + $IP = dirname( __FILE__ ) . '/../..'; |
| 7 | +} |
| 8 | +require( "$IP/maintenance/Maintenance.php" ); |
| 9 | + |
| 10 | +class PopulateGadgetPageList extends Maintenance { |
| 11 | + const BATCH_SIZE = 100; |
| 12 | + |
| 13 | + public function __construct() { |
| 14 | + parent::__construct(); |
| 15 | + $this->mDescription = "Populates the gadgetpagelist table"; |
| 16 | + } |
| 17 | + |
| 18 | + public function execute() { |
| 19 | + $dbr = wfGetDB( DB_SLAVE ); |
| 20 | + $dbw = wfGetDB( DB_MASTER ); |
| 21 | + |
| 22 | + $this->output( "Populating gadgetpagelist table ...\n" ); |
| 23 | + |
| 24 | + $lastPageID = 0; |
| 25 | + $processed = 0; |
| 26 | + $written = 0; |
| 27 | + while ( true ) { |
| 28 | + // Grab a batch of pages from the page table |
| 29 | + $res = $dbr->select( 'page', |
| 30 | + array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ), |
| 31 | + "page_id > $lastPageID", __METHOD__, |
| 32 | + array( 'LIMIT' => self::BATCH_SIZE, 'ORDER BY' => 'page_id' ) |
| 33 | + ); |
| 34 | + if ( $dbr->numRows( $res ) == 0 ) { |
| 35 | + // We've reached the end |
| 36 | + break; |
| 37 | + } |
| 38 | + $processed += $dbr->numRows( $res ); |
| 39 | + |
| 40 | + // Build gadgetpagelist rows |
| 41 | + $gplRows = array(); |
| 42 | + foreach ( $res as $row ) { |
| 43 | + $title = Title::newFromRow( $row ); |
| 44 | + if ( GadgetPageList::isGadgetPage( $title ) ) { |
| 45 | + $gplRows[] = GadgetPageList::getRowForTitle( $title ); |
| 46 | + } |
| 47 | + $lastPageID = intval( $row->page_id ); |
| 48 | + } |
| 49 | + $dbr->freeResult( $res ); |
| 50 | + |
| 51 | + // Insert the new rows |
| 52 | + $dbw->insert( 'gadgetpagelist', $gplRows, __METHOD__, array( 'IGNORE' ) ); |
| 53 | + $written += count( $gplRows ); |
| 54 | + |
| 55 | + $this->output( "... $processed pages processed, $written rows written, page_id $lastPageID\n" ); |
| 56 | + } |
| 57 | + |
| 58 | + $this->output( "Done\n" ); |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +$maintClass = "PopulateGadgetPageList"; |
| 63 | +require_once( DO_MAINTENANCE ); |
\ No newline at end of file |
Property changes on: branches/RL2/extensions/Gadgets/populateGadgetPageList.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 64 | + native |