00001 <?php
00007 define( 'REPORTING_INTERVAL', 100 );
00008
00009 if ( !defined( 'MEDIAWIKI' ) ) {
00010 $optionsWithArgs = array( 'm' );
00011
00012 require_once( dirname(__FILE__) . '/../commandLine.inc' );
00013
00014 resolveStubs();
00015 }
00016
00021 function resolveStubs() {
00022 $fname = 'resolveStubs';
00023
00024 $dbr = wfGetDB( DB_SLAVE );
00025 $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
00026 $blockSize = 10000;
00027 $numBlocks = intval( $maxID / $blockSize ) + 1;
00028
00029 for ( $b = 0; $b < $numBlocks; $b++ ) {
00030 wfWaitForSlaves( 2 );
00031
00032 printf( "%5.2f%%\n", $b / $numBlocks * 100 );
00033 $start = intval($maxID / $numBlocks) * $b + 1;
00034 $end = intval($maxID / $numBlocks) * ($b + 1);
00035
00036 $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ),
00037 "old_id>=$start AND old_id<=$end " .
00038 "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' ".
00039 'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'',
00040 $fname );
00041 while ( $row = $dbr->fetchObject( $res ) ) {
00042 resolveStub( $row->old_id, $row->old_text, $row->old_flags );
00043 }
00044 $dbr->freeResult( $res );
00045
00046
00047 }
00048 print "100%\n";
00049 }
00050
00054 function resolveStub( $id, $stubText, $flags ) {
00055 $fname = 'resolveStub';
00056
00057 $stub = unserialize( $stubText );
00058 $flags = explode( ',', $flags );
00059
00060 $dbr = wfGetDB( DB_SLAVE );
00061 $dbw = wfGetDB( DB_MASTER );
00062
00063 if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
00064 print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
00065 return;
00066 }
00067
00068 # Get the (maybe) external row
00069 $externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
00070 array( 'old_id' => $stub->mOldId, 'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ) ),
00071 $fname
00072 );
00073
00074 if ( !$externalRow ) {
00075 # Object wasn't external
00076 return;
00077 }
00078
00079 # Preserve the legacy encoding flag, but switch from object to external
00080 if ( in_array( 'utf-8', $flags ) ) {
00081 $newFlags = 'external,utf-8';
00082 } else {
00083 $newFlags = 'external';
00084 }
00085
00086 # Update the row
00087 #print "oldid=$id\n";
00088 $dbw->update( 'text',
00089 array(
00090 'old_flags' => $newFlags,
00091 'old_text' => $externalRow->old_text . '/' . $stub->mHash
00092 ),
00093 array(
00094 'old_id' => $id
00095 ), $fname
00096 );
00097 }
00098