Index: trunk/extensions/WikimediaMaintenance/cleanupBug31576.php |
— | — | @@ -0,0 +1,64 @@ |
| 2 | +<?php |
| 3 | +$IP = getenv( 'MW_INSTALL_PATH' ); |
| 4 | +if ( $IP === false ) { |
| 5 | + $IP = dirname( __FILE__ ) . '/../..'; |
| 6 | +} |
| 7 | +require( "$IP/maintenance/Maintenance.php" ); |
| 8 | + |
| 9 | +class CleanupBug31576 extends Maintenance { |
| 10 | + public function __construct() { |
| 11 | + parent::__construct(); |
| 12 | + $this->mDescription = "Cleans up templatelinks corruption caused by https://bugzilla.wikimedia.org/show_bug.cgi?id=31576"; |
| 13 | + $this->addOption( 'batchsize', 'Number of rows to process in one batch. Default: 50', false, true ); |
| 14 | + } |
| 15 | + |
| 16 | + public function execute() { |
| 17 | + $this->batchsize = $this->getOption( 'batchsize', 50 ); |
| 18 | + $variableIDs = MagicWord::getVariableIDs(); |
| 19 | + foreach ( $variableIDs as $id ) { |
| 20 | + $magic = MagicWord::get( $id ); |
| 21 | + foreach ( $magic->getSynonyms() as $synonym ) { |
| 22 | + $this->processSynonym( $synonym ); |
| 23 | + } |
| 24 | + } |
| 25 | + $this->output( "All done\n" ); |
| 26 | + } |
| 27 | + |
| 28 | + public function processSynonym( $synonym ) { |
| 29 | + $dbr = wfGetDB( DB_SLAVE ); |
| 30 | + $pCount = 0; |
| 31 | + $vCount = 0; |
| 32 | + $this->output( "Fixing pages with template links to $synonym ...\n" ); |
| 33 | + while ( true ) { |
| 34 | + $res = $dbr->select( 'templatelinks', array( 'tl_title', 'tl_from' ), |
| 35 | + array( |
| 36 | + 'tl_namespace' => NS_TEMPLATE, |
| 37 | + 'tl_title ' . $dbr->buildLike( $synonym, $dbr->anyString() ) |
| 38 | + ), __METHOD__, |
| 39 | + array( 'ORDER BY' => array( 'tl_title', 'tl_from' ), 'LIMIT' => $this->batchsize ) |
| 40 | + ); |
| 41 | + if ( $dbr->numRows( $res ) == 0 ) { |
| 42 | + // No more rows, we're done |
| 43 | + break; |
| 44 | + } |
| 45 | + |
| 46 | + $processed = array(); |
| 47 | + foreach ( $res as $row ) { |
| 48 | + $vCount++; |
| 49 | + if ( isset( $processed[$row->tl_from] ) ) { |
| 50 | + // We've already processed this page, skip it |
| 51 | + continue; |
| 52 | + } |
| 53 | + RefreshLinks::fixLinksFromArticle( $row->tl_from ); |
| 54 | + $processed[$row->tl_from] = true; |
| 55 | + $pCount++; |
| 56 | + } |
| 57 | + $this->output( "{$pCount}/{$vCount} pages processed\n" ); |
| 58 | + wfWaitForSlaves(); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | +} |
| 63 | + |
| 64 | +$maintClass = "CleanupBug31576"; |
| 65 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
\ No newline at end of file |
Property changes on: trunk/extensions/WikimediaMaintenance/cleanupBug31576.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 66 | + native |