MediaWiki
REL1_24
|
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 00072 function resolveStub( $id, $stubText, $flags ) { 00073 $fname = 'resolveStub'; 00074 00075 $stub = unserialize( $stubText ); 00076 $flags = explode( ',', $flags ); 00077 00078 $dbr = wfGetDB( DB_SLAVE ); 00079 $dbw = wfGetDB( DB_MASTER ); 00080 00081 if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) { 00082 print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n"; 00083 00084 return; 00085 } 00086 00087 # Get the (maybe) external row 00088 $externalRow = $dbr->selectRow( 00089 'text', 00090 array( 'old_text' ), 00091 array( 00092 'old_id' => $stub->mOldId, 00093 'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ) 00094 ), 00095 $fname 00096 ); 00097 00098 if ( !$externalRow ) { 00099 # Object wasn't external 00100 return; 00101 } 00102 00103 # Preserve the legacy encoding flag, but switch from object to external 00104 if ( in_array( 'utf-8', $flags ) ) { 00105 $newFlags = 'external,utf-8'; 00106 } else { 00107 $newFlags = 'external'; 00108 } 00109 00110 # Update the row 00111 # print "oldid=$id\n"; 00112 $dbw->update( 'text', 00113 array( /* SET */ 00114 'old_flags' => $newFlags, 00115 'old_text' => $externalRow->old_text . '/' . $stub->mHash 00116 ), 00117 array( /* WHERE */ 00118 'old_id' => $id 00119 ), $fname 00120 ); 00121 }