MediaWiki  1.29.2
resolveStubs.php
Go to the documentation of this file.
1 <?php
25 if ( !defined( 'MEDIAWIKI' ) ) {
26  $optionsWithArgs = [ 'm' ];
27 
28  require_once __DIR__ . '/../commandLine.inc';
29 
30  resolveStubs();
31 }
32 
37 function resolveStubs() {
38  $fname = 'resolveStubs';
39 
40  $dbr = wfGetDB( DB_REPLICA );
41  $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
42  $blockSize = 10000;
43  $numBlocks = intval( $maxID / $blockSize ) + 1;
44 
45  for ( $b = 0; $b < $numBlocks; $b++ ) {
47 
48  printf( "%5.2f%%\n", $b / $numBlocks * 100 );
49  $start = intval( $maxID / $numBlocks ) * $b + 1;
50  $end = intval( $maxID / $numBlocks ) * ( $b + 1 );
51 
52  $res = $dbr->select( 'text', [ 'old_id', 'old_text', 'old_flags' ],
53  "old_id>=$start AND old_id<=$end " .
54  "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " .
55  'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'',
56  $fname );
57  foreach ( $res as $row ) {
58  resolveStub( $row->old_id, $row->old_text, $row->old_flags );
59  }
60  }
61  print "100%\n";
62 }
63 
70 function resolveStub( $id, $stubText, $flags ) {
71  $fname = 'resolveStub';
72 
73  $stub = unserialize( $stubText );
74  $flags = explode( ',', $flags );
75 
76  $dbr = wfGetDB( DB_REPLICA );
77  $dbw = wfGetDB( DB_MASTER );
78 
79  if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
80  print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
81 
82  return;
83  }
84 
85  # Get the (maybe) external row
86  $externalRow = $dbr->selectRow(
87  'text',
88  [ 'old_text' ],
89  [
90  'old_id' => $stub->mOldId,
91  'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() )
92  ],
93  $fname
94  );
95 
96  if ( !$externalRow ) {
97  # Object wasn't external
98  return;
99  }
100 
101  # Preserve the legacy encoding flag, but switch from object to external
102  if ( in_array( 'utf-8', $flags ) ) {
103  $newFlags = 'external,utf-8';
104  } else {
105  $newFlags = 'external';
106  }
107 
108  # Update the row
109  # print "oldid=$id\n";
110  $dbw->update( 'text',
111  [ /* SET */
112  'old_flags' => $newFlags,
113  'old_text' => $externalRow->old_text . '/' . $stub->mHash
114  ],
115  [ /* WHERE */
116  'old_id' => $id
117  ], $fname
118  );
119 }
$optionsWithArgs
global $optionsWithArgs
Definition: commandLine.inc:24
$maxID
$maxID
Definition: cleanup.php:95
resolveStubs
if(!defined( 'MEDIAWIKI')) resolveStubs()
Convert history stubs that point to an external row to direct external pointers.
Definition: resolveStubs.php:37
$fname
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition: Setup.php:36
unserialize
unserialize( $serialized)
Definition: ApiMessage.php:185
$res
$res
Definition: database.txt:21
wfWaitForSlaves
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Definition: GlobalFunctions.php:3214
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
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
resolveStub
resolveStub( $id, $stubText, $flags)
Resolve a history stub.
Definition: resolveStubs.php:70
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2749