MediaWiki  1.23.8
resolveStubs.php
Go to the documentation of this file.
1 <?php
25 define( 'REPORTING_INTERVAL', 100 );
26 
27 if ( !defined( 'MEDIAWIKI' ) ) {
28  $optionsWithArgs = array( 'm' );
29 
30  require_once __DIR__ . '/../commandLine.inc';
31 
32  resolveStubs();
33 }
34 
39 function resolveStubs() {
40  $fname = 'resolveStubs';
41 
42  $dbr = wfGetDB( DB_SLAVE );
43  $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
44  $blockSize = 10000;
45  $numBlocks = intval( $maxID / $blockSize ) + 1;
46 
47  for ( $b = 0; $b < $numBlocks; $b++ ) {
49 
50  printf( "%5.2f%%\n", $b / $numBlocks * 100 );
51  $start = intval( $maxID / $numBlocks ) * $b + 1;
52  $end = intval( $maxID / $numBlocks ) * ( $b + 1 );
53 
54  $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ),
55  "old_id>=$start AND old_id<=$end " .
56  "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " .
57  'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'',
58  $fname );
59  foreach ( $res as $row ) {
60  resolveStub( $row->old_id, $row->old_text, $row->old_flags );
61  }
62  }
63  print "100%\n";
64 }
65 
69 function resolveStub( $id, $stubText, $flags ) {
70  $fname = 'resolveStub';
71 
72  $stub = unserialize( $stubText );
73  $flags = explode( ',', $flags );
74 
75  $dbr = wfGetDB( DB_SLAVE );
76  $dbw = wfGetDB( DB_MASTER );
77 
78  if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
79  print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
80  return;
81  }
82 
83  # Get the (maybe) external row
84  $externalRow = $dbr->selectRow( 'text', array( 'old_text' ),
85  array( 'old_id' => $stub->mOldId, 'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ) ),
86  $fname
87  );
88 
89  if ( !$externalRow ) {
90  # Object wasn't external
91  return;
92  }
93 
94  # Preserve the legacy encoding flag, but switch from object to external
95  if ( in_array( 'utf-8', $flags ) ) {
96  $newFlags = 'external,utf-8';
97  } else {
98  $newFlags = 'external';
99  }
100 
101  # Update the row
102  # print "oldid=$id\n";
103  $dbw->update( 'text',
104  array( /* SET */
105  'old_flags' => $newFlags,
106  'old_text' => $externalRow->old_text . '/' . $stub->mHash
107  ),
108  array( /* WHERE */
109  'old_id' => $id
110  ), $fname
111  );
112 }
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
$optionsWithArgs
global $optionsWithArgs
Definition: commandLine.inc:24
resolveStubs
if(!defined( 'MEDIAWIKI')) resolveStubs()
Convert history stubs that point to an external row to direct external pointers.
Definition: resolveStubs.php:39
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3659
$fname
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition: Setup.php:35
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2113
$dbr
$dbr
Definition: testCompression.php:48
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
wfWaitForSlaves
wfWaitForSlaves( $maxLag=false, $wiki=false, $cluster=false)
Modern version of wfWaitForSlaves().
Definition: GlobalFunctions.php:3804
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$res
$res
Definition: database.txt:21
resolveStub
resolveStub( $id, $stubText, $flags)
Resolve a history stub.
Definition: resolveStubs.php:69