MediaWiki
REL1_22
|
00001 <?php 00025 define( 'REPORTING_INTERVAL', 100 ); 00026 00027 if ( !defined( 'MEDIAWIKI' ) ) { 00028 $optionsWithArgs = array( 'm' ); 00029 00030 require_once __DIR__ . '/../commandLine.inc'; 00031 00032 resolveStubs(); 00033 } 00034 00039 function resolveStubs() { 00040 $fname = 'resolveStubs'; 00041 00042 $dbr = wfGetDB( DB_SLAVE ); 00043 $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname ); 00044 $blockSize = 10000; 00045 $numBlocks = intval( $maxID / $blockSize ) + 1; 00046 00047 for ( $b = 0; $b < $numBlocks; $b++ ) { 00048 wfWaitForSlaves(); 00049 00050 printf( "%5.2f%%\n", $b / $numBlocks * 100 ); 00051 $start = intval( $maxID / $numBlocks ) * $b + 1; 00052 $end = intval( $maxID / $numBlocks ) * ( $b + 1 ); 00053 00054 $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ), 00055 "old_id>=$start AND old_id<=$end " . 00056 "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " . 00057 'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'', 00058 $fname ); 00059 foreach ( $res as $row ) { 00060 resolveStub( $row->old_id, $row->old_text, $row->old_flags ); 00061 } 00062 } 00063 print "100%\n"; 00064 } 00065 00069 function resolveStub( $id, $stubText, $flags ) { 00070 $fname = 'resolveStub'; 00071 00072 $stub = unserialize( $stubText ); 00073 $flags = explode( ',', $flags ); 00074 00075 $dbr = wfGetDB( DB_SLAVE ); 00076 $dbw = wfGetDB( DB_MASTER ); 00077 00078 if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) { 00079 print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n"; 00080 return; 00081 } 00082 00083 # Get the (maybe) external row 00084 $externalRow = $dbr->selectRow( 'text', array( 'old_text' ), 00085 array( 'old_id' => $stub->mOldId, 'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ) ), 00086 $fname 00087 ); 00088 00089 if ( !$externalRow ) { 00090 # Object wasn't external 00091 return; 00092 } 00093 00094 # Preserve the legacy encoding flag, but switch from object to external 00095 if ( in_array( 'utf-8', $flags ) ) { 00096 $newFlags = 'external,utf-8'; 00097 } else { 00098 $newFlags = 'external'; 00099 } 00100 00101 # Update the row 00102 # print "oldid=$id\n"; 00103 $dbw->update( 'text', 00104 array( /* SET */ 00105 'old_flags' => $newFlags, 00106 'old_text' => $externalRow->old_text . '/' . $stub->mHash 00107 ), 00108 array( /* WHERE */ 00109 'old_id' => $id 00110 ), $fname 00111 ); 00112 }