MediaWiki REL1_32
recompressTracked.php
Go to the documentation of this file.
1<?php
28
30require __DIR__ . '/../commandLine.inc';
31
32if ( count( $args ) < 1 ) {
33 echo "Usage: php recompressTracked.php [options] <cluster> [... <cluster>...]
34Moves blobs indexed by trackBlobs.php to a specified list of destination clusters,
35and recompresses them in the process. Restartable.
36
37Options:
38 --procs <procs> Set the number of child processes (default 1)
39 --copy-only Copy only, do not update the text table. Restart
40 without this option to complete.
41 --debug-log <file> Log debugging data to the specified file
42 --info-log <file> Log progress messages to the specified file
43 --critical-log <file> Log error messages to the specified file
44";
45 exit( 1 );
46}
47
49$job->execute();
50
59 public $batchSize = 1000;
60 public $orphanBatchSize = 1000;
61 public $reportingInterval = 10;
62 public $numProcs = 1;
63 public $numBatches = 0;
66 public $copyOnly = false;
67 public $isChild = false;
68 public $replicaId = false;
69 public $noCount = false;
71 public $store;
72
73 private static $optionsWithArgs = [
74 'procs',
75 'replica-id',
76 'debug-log',
77 'info-log',
78 'critical-log'
79 ];
80
81 private static $cmdLineOptionMap = [
82 'no-count' => 'noCount',
83 'procs' => 'numProcs',
84 'copy-only' => 'copyOnly',
85 'child' => 'isChild',
86 'replica-id' => 'replicaId',
87 'debug-log' => 'debugLog',
88 'info-log' => 'infoLog',
89 'critical-log' => 'criticalLog',
90 ];
91
92 static function getOptionsWithArgs() {
94 }
95
96 static function newFromCommandLine( $args, $options ) {
97 $jobOptions = [ 'destClusters' => $args ];
98 foreach ( self::$cmdLineOptionMap as $cmdOption => $classOption ) {
99 if ( isset( $options[$cmdOption] ) ) {
100 $jobOptions[$classOption] = $options[$cmdOption];
101 }
102 }
103
104 return new self( $jobOptions );
105 }
106
107 function __construct( $options ) {
108 foreach ( $options as $name => $value ) {
109 $this->$name = $value;
110 }
111 $this->store = new ExternalStoreDB;
112 if ( !$this->isChild ) {
113 $GLOBALS['wgDebugLogPrefix'] = "RCT M: ";
114 } elseif ( $this->replicaId !== false ) {
115 $GLOBALS['wgDebugLogPrefix'] = "RCT {$this->replicaId}: ";
116 }
117 $this->pageBlobClass = function_exists( 'xdiff_string_bdiff' ) ?
118 DiffHistoryBlob::class : ConcatenatedGzipHistoryBlob::class;
119 $this->orphanBlobClass = ConcatenatedGzipHistoryBlob::class;
120 }
121
122 function debug( $msg ) {
123 wfDebug( "$msg\n" );
124 if ( $this->debugLog ) {
125 $this->logToFile( $msg, $this->debugLog );
126 }
127 }
128
129 function info( $msg ) {
130 echo "$msg\n";
131 if ( $this->infoLog ) {
132 $this->logToFile( $msg, $this->infoLog );
133 }
134 }
135
136 function critical( $msg ) {
137 echo "$msg\n";
138 if ( $this->criticalLog ) {
139 $this->logToFile( $msg, $this->criticalLog );
140 }
141 }
142
143 function logToFile( $msg, $file ) {
144 $header = '[' . date( 'd\TH:i:s' ) . '] ' . wfHostname() . ' ' . posix_getpid();
145 if ( $this->replicaId !== false ) {
146 $header .= "({$this->replicaId})";
147 }
148 $header .= ' ' . wfWikiID();
149 LegacyLogger::emit( sprintf( "%-50s %s\n", $header, $msg ), $file );
150 }
151
157 function syncDBs() {
158 $dbw = wfGetDB( DB_MASTER );
160 $pos = $dbw->getMasterPos();
161 $dbr->masterPosWait( $pos, 100000 );
162 }
163
167 function execute() {
168 if ( $this->isChild ) {
169 $this->executeChild();
170 } else {
171 $this->executeParent();
172 }
173 }
174
178 function executeParent() {
179 if ( !$this->checkTrackingTable() ) {
180 return;
181 }
182
183 $this->syncDBs();
184 $this->startReplicaProcs();
185 $this->doAllPages();
186 $this->doAllOrphans();
187 $this->killReplicaProcs();
188 }
189
196 if ( !$dbr->tableExists( 'blob_tracking' ) ) {
197 $this->critical( "Error: blob_tracking table does not exist" );
198
199 return false;
200 }
201 $row = $dbr->selectRow( 'blob_tracking', '*', '', __METHOD__ );
202 if ( !$row ) {
203 $this->info( "Warning: blob_tracking table contains no rows, skipping this wiki." );
204
205 return false;
206 }
207
208 return true;
209 }
210
217 function startReplicaProcs() {
218 $cmd = 'php ' . wfEscapeShellArg( __FILE__ );
219 foreach ( self::$cmdLineOptionMap as $cmdOption => $classOption ) {
220 if ( $cmdOption == 'replica-id' ) {
221 continue;
222 } elseif ( in_array( $cmdOption, self::$optionsWithArgs ) && isset( $this->$classOption ) ) {
223 $cmd .= " --$cmdOption " . wfEscapeShellArg( $this->$classOption );
224 } elseif ( $this->$classOption ) {
225 $cmd .= " --$cmdOption";
226 }
227 }
228 $cmd .= ' --child' .
229 ' --wiki ' . wfEscapeShellArg( wfWikiID() ) .
230 ' ' . wfEscapeShellArg( ...$this->destClusters );
231
232 $this->replicaPipes = $this->replicaProcs = [];
233 for ( $i = 0; $i < $this->numProcs; $i++ ) {
234 $pipes = [];
235 $spec = [
236 [ 'pipe', 'r' ],
237 [ 'file', 'php://stdout', 'w' ],
238 [ 'file', 'php://stderr', 'w' ]
239 ];
240 Wikimedia\suppressWarnings();
241 $proc = proc_open( "$cmd --replica-id $i", $spec, $pipes );
242 Wikimedia\restoreWarnings();
243 if ( !$proc ) {
244 $this->critical( "Error opening replica DB process: $cmd" );
245 exit( 1 );
246 }
247 $this->replicaProcs[$i] = $proc;
248 $this->replicaPipes[$i] = $pipes[0];
249 }
250 $this->prevReplicaId = -1;
251 }
252
256 function killReplicaProcs() {
257 $this->info( "Waiting for replica DB processes to finish..." );
258 for ( $i = 0; $i < $this->numProcs; $i++ ) {
259 $this->dispatchToReplica( $i, 'quit' );
260 }
261 for ( $i = 0; $i < $this->numProcs; $i++ ) {
262 $status = proc_close( $this->replicaProcs[$i] );
263 if ( $status ) {
264 $this->critical( "Warning: child #$i exited with status $status" );
265 }
266 }
267 $this->info( "Done." );
268 }
269
274 function dispatch( /*...*/ ) {
275 $args = func_get_args();
276 $pipes = $this->replicaPipes;
277 $numPipes = stream_select( $x = [], $pipes, $y = [], 3600 );
278 if ( !$numPipes ) {
279 $this->critical( "Error waiting to write to replica DBs. Aborting" );
280 exit( 1 );
281 }
282 for ( $i = 0; $i < $this->numProcs; $i++ ) {
283 $replicaId = ( $i + $this->prevReplicaId + 1 ) % $this->numProcs;
284 if ( isset( $pipes[$replicaId] ) ) {
285 $this->prevReplicaId = $replicaId;
286 $this->dispatchToReplica( $replicaId, $args );
287
288 return;
289 }
290 }
291 $this->critical( "Unreachable" );
292 exit( 1 );
293 }
294
301 $args = (array)$args;
302 $cmd = implode( ' ', $args );
303 fwrite( $this->replicaPipes[$replicaId], "$cmd\n" );
304 }
305
309 function doAllPages() {
311 $i = 0;
312 $startId = 0;
313 if ( $this->noCount ) {
314 $numPages = '[unknown]';
315 } else {
316 $numPages = $dbr->selectField( 'blob_tracking',
317 'COUNT(DISTINCT bt_page)',
318 # A condition is required so that this query uses the index
319 [ 'bt_moved' => 0 ],
320 __METHOD__
321 );
322 }
323 if ( $this->copyOnly ) {
324 $this->info( "Copying pages..." );
325 } else {
326 $this->info( "Moving pages..." );
327 }
328 while ( true ) {
329 $res = $dbr->select( 'blob_tracking',
330 [ 'bt_page' ],
331 [
332 'bt_moved' => 0,
333 'bt_page > ' . $dbr->addQuotes( $startId )
334 ],
335 __METHOD__,
336 [
337 'DISTINCT',
338 'ORDER BY' => 'bt_page',
339 'LIMIT' => $this->batchSize,
340 ]
341 );
342 if ( !$res->numRows() ) {
343 break;
344 }
345 foreach ( $res as $row ) {
346 $startId = $row->bt_page;
347 $this->dispatch( 'doPage', $row->bt_page );
348 $i++;
349 }
350 $this->report( 'pages', $i, $numPages );
351 }
352 $this->report( 'pages', $i, $numPages );
353 if ( $this->copyOnly ) {
354 $this->info( "All page copies queued." );
355 } else {
356 $this->info( "All page moves queued." );
357 }
358 }
359
366 function report( $label, $current, $end ) {
367 $this->numBatches++;
368 if ( $current == $end || $this->numBatches >= $this->reportingInterval ) {
369 $this->numBatches = 0;
370 $this->info( "$label: $current / $end" );
371 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
372 }
373 }
374
378 function doAllOrphans() {
380 $startId = 0;
381 $i = 0;
382 if ( $this->noCount ) {
383 $numOrphans = '[unknown]';
384 } else {
385 $numOrphans = $dbr->selectField( 'blob_tracking',
386 'COUNT(DISTINCT bt_text_id)',
387 [ 'bt_moved' => 0, 'bt_page' => 0 ],
388 __METHOD__ );
389 if ( !$numOrphans ) {
390 return;
391 }
392 }
393 if ( $this->copyOnly ) {
394 $this->info( "Copying orphans..." );
395 } else {
396 $this->info( "Moving orphans..." );
397 }
398
399 while ( true ) {
400 $res = $dbr->select( 'blob_tracking',
401 [ 'bt_text_id' ],
402 [
403 'bt_moved' => 0,
404 'bt_page' => 0,
405 'bt_text_id > ' . $dbr->addQuotes( $startId )
406 ],
407 __METHOD__,
408 [
409 'DISTINCT',
410 'ORDER BY' => 'bt_text_id',
411 'LIMIT' => $this->batchSize
412 ]
413 );
414 if ( !$res->numRows() ) {
415 break;
416 }
417 $ids = [];
418 foreach ( $res as $row ) {
419 $startId = $row->bt_text_id;
420 $ids[] = $row->bt_text_id;
421 $i++;
422 }
423 // Need to send enough orphan IDs to the child at a time to fill a blob,
424 // so orphanBatchSize needs to be at least ~100.
425 // batchSize can be smaller or larger.
426 while ( count( $ids ) > $this->orphanBatchSize ) {
427 $args = array_slice( $ids, 0, $this->orphanBatchSize );
428 $ids = array_slice( $ids, $this->orphanBatchSize );
429 array_unshift( $args, 'doOrphanList' );
430 $this->dispatch( ...$args );
431 }
432 if ( count( $ids ) ) {
433 $args = $ids;
434 array_unshift( $args, 'doOrphanList' );
435 $this->dispatch( ...$args );
436 }
437
438 $this->report( 'orphans', $i, $numOrphans );
439 }
440 $this->report( 'orphans', $i, $numOrphans );
441 $this->info( "All orphans queued." );
442 }
443
447 function executeChild() {
448 $this->debug( 'starting' );
449 $this->syncDBs();
450
451 while ( !feof( STDIN ) ) {
452 $line = rtrim( fgets( STDIN ) );
453 if ( $line == '' ) {
454 continue;
455 }
456 $this->debug( $line );
457 $args = explode( ' ', $line );
458 $cmd = array_shift( $args );
459 switch ( $cmd ) {
460 case 'doPage':
461 $this->doPage( intval( $args[0] ) );
462 break;
463 case 'doOrphanList':
464 $this->doOrphanList( array_map( 'intval', $args ) );
465 break;
466 case 'quit':
467 return;
468 }
469 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
470 }
471 }
472
478 function doPage( $pageId ) {
479 $title = Title::newFromID( $pageId );
480 if ( $title ) {
481 $titleText = $title->getPrefixedText();
482 } else {
483 $titleText = '[deleted]';
484 }
486
487 // Finish any incomplete transactions
488 if ( !$this->copyOnly ) {
489 $this->finishIncompleteMoves( [ 'bt_page' => $pageId ] );
490 $this->syncDBs();
491 }
492
493 $startId = 0;
494 $trx = new CgzCopyTransaction( $this, $this->pageBlobClass );
495
496 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
497 while ( true ) {
498 $res = $dbr->select(
499 [ 'blob_tracking', 'text' ],
500 '*',
501 [
502 'bt_page' => $pageId,
503 'bt_text_id > ' . $dbr->addQuotes( $startId ),
504 'bt_moved' => 0,
505 'bt_new_url IS NULL',
506 'bt_text_id=old_id',
507 ],
508 __METHOD__,
509 [
510 'ORDER BY' => 'bt_text_id',
511 'LIMIT' => $this->batchSize
512 ]
513 );
514 if ( !$res->numRows() ) {
515 break;
516 }
517
518 $lastTextId = 0;
519 foreach ( $res as $row ) {
520 $startId = $row->bt_text_id;
521 if ( $lastTextId == $row->bt_text_id ) {
522 // Duplicate (null edit)
523 continue;
524 }
525 $lastTextId = $row->bt_text_id;
526 // Load the text
527 $text = Revision::getRevisionText( $row );
528 if ( $text === false ) {
529 $this->critical( "Error loading {$row->bt_rev_id}/{$row->bt_text_id}" );
530 continue;
531 }
532
533 // Queue it
534 if ( !$trx->addItem( $text, $row->bt_text_id ) ) {
535 $this->debug( "$titleText: committing blob with " . $trx->getSize() . " items" );
536 $trx->commit();
537 $trx = new CgzCopyTransaction( $this, $this->pageBlobClass );
538 $lbFactory->waitForReplication();
539 }
540 }
541 }
542
543 $this->debug( "$titleText: committing blob with " . $trx->getSize() . " items" );
544 $trx->commit();
545 }
546
560 function moveTextRow( $textId, $url ) {
561 if ( $this->copyOnly ) {
562 $this->critical( "Internal error: can't call moveTextRow() in --copy-only mode" );
563 exit( 1 );
564 }
565 $dbw = wfGetDB( DB_MASTER );
566 $dbw->begin( __METHOD__ );
567 $dbw->update( 'text',
568 [ // set
569 'old_text' => $url,
570 'old_flags' => 'external,utf-8',
571 ],
572 [ // where
573 'old_id' => $textId
574 ],
575 __METHOD__
576 );
577 $dbw->update( 'blob_tracking',
578 [ 'bt_moved' => 1 ],
579 [ 'bt_text_id' => $textId ],
580 __METHOD__
581 );
582 $dbw->commit( __METHOD__ );
583 }
584
595 function finishIncompleteMoves( $conds ) {
597 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
598
599 $startId = 0;
600 $conds = array_merge( $conds, [
601 'bt_moved' => 0,
602 'bt_new_url IS NOT NULL'
603 ] );
604 while ( true ) {
605 $res = $dbr->select( 'blob_tracking',
606 '*',
607 array_merge( $conds, [ 'bt_text_id > ' . $dbr->addQuotes( $startId ) ] ),
608 __METHOD__,
609 [
610 'ORDER BY' => 'bt_text_id',
611 'LIMIT' => $this->batchSize,
612 ]
613 );
614 if ( !$res->numRows() ) {
615 break;
616 }
617 $this->debug( 'Incomplete: ' . $res->numRows() . ' rows' );
618 foreach ( $res as $row ) {
619 $startId = $row->bt_text_id;
620 $this->moveTextRow( $row->bt_text_id, $row->bt_new_url );
621 if ( $row->bt_text_id % 10 == 0 ) {
622 $lbFactory->waitForReplication();
623 }
624 }
625 }
626 }
627
632 function getTargetCluster() {
633 $cluster = next( $this->destClusters );
634 if ( $cluster === false ) {
635 $cluster = reset( $this->destClusters );
636 }
637
638 return $cluster;
639 }
640
646 function getExtDB( $cluster ) {
647 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
648 $lb = $lbFactory->getExternalLB( $cluster );
649
650 return $lb->getConnection( DB_MASTER );
651 }
652
658 function doOrphanList( $textIds ) {
659 // Finish incomplete moves
660 if ( !$this->copyOnly ) {
661 $this->finishIncompleteMoves( [ 'bt_text_id' => $textIds ] );
662 $this->syncDBs();
663 }
664
665 $trx = new CgzCopyTransaction( $this, $this->orphanBlobClass );
666
667 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
668 $res = wfGetDB( DB_REPLICA )->select(
669 [ 'text', 'blob_tracking' ],
670 [ 'old_id', 'old_text', 'old_flags' ],
671 [
672 'old_id' => $textIds,
673 'bt_text_id=old_id',
674 'bt_moved' => 0,
675 ],
676 __METHOD__,
677 [ 'DISTINCT' ]
678 );
679
680 foreach ( $res as $row ) {
681 $text = Revision::getRevisionText( $row );
682 if ( $text === false ) {
683 $this->critical( "Error: cannot load revision text for old_id={$row->old_id}" );
684 continue;
685 }
686
687 if ( !$trx->addItem( $text, $row->old_id ) ) {
688 $this->debug( "[orphan]: committing blob with " . $trx->getSize() . " rows" );
689 $trx->commit();
690 $trx = new CgzCopyTransaction( $this, $this->orphanBlobClass );
691 $lbFactory->waitForReplication();
692 }
693 }
694 $this->debug( "[orphan]: committing blob with " . $trx->getSize() . " rows" );
695 $trx->commit();
696 }
697}
698
704 public $parent;
707 public $cgz;
709
716 $this->blobClass = $blobClass;
717 $this->cgz = false;
718 $this->texts = [];
719 $this->parent = $parent;
720 }
721
729 function addItem( $text, $textId ) {
730 if ( !$this->cgz ) {
731 $class = $this->blobClass;
732 $this->cgz = new $class;
733 }
734 $hash = $this->cgz->addItem( $text );
735 $this->referrers[$textId] = $hash;
736 $this->texts[$textId] = $text;
737
738 return $this->cgz->isHappy();
739 }
740
741 function getSize() {
742 return count( $this->texts );
743 }
744
748 function recompress() {
749 $class = $this->blobClass;
750 $this->cgz = new $class;
751 $this->referrers = [];
752 foreach ( $this->texts as $textId => $text ) {
753 $hash = $this->cgz->addItem( $text );
754 $this->referrers[$textId] = $hash;
755 }
756 }
757
763 function commit() {
764 $originalCount = count( $this->texts );
765 if ( !$originalCount ) {
766 return;
767 }
768
769 /* Check to see if the target text_ids have been moved already.
770 *
771 * We originally read from the replica DB, so this can happen when a single
772 * text_id is shared between multiple pages. It's rare, but possible
773 * if a delete/move/undelete cycle splits up a null edit.
774 *
775 * We do a locking read to prevent closer-run race conditions.
776 */
777 $dbw = wfGetDB( DB_MASTER );
778 $dbw->begin( __METHOD__ );
779 $res = $dbw->select( 'blob_tracking',
780 [ 'bt_text_id', 'bt_moved' ],
781 [ 'bt_text_id' => array_keys( $this->referrers ) ],
782 __METHOD__, [ 'FOR UPDATE' ] );
783 $dirty = false;
784 foreach ( $res as $row ) {
785 if ( $row->bt_moved ) {
786 # This row has already been moved, remove it
787 $this->parent->debug( "TRX: conflict detected in old_id={$row->bt_text_id}" );
788 unset( $this->texts[$row->bt_text_id] );
789 $dirty = true;
790 }
791 }
792
793 // Recompress the blob if necessary
794 if ( $dirty ) {
795 if ( !count( $this->texts ) ) {
796 // All have been moved already
797 if ( $originalCount > 1 ) {
798 // This is suspcious, make noise
799 $this->parent->critical(
800 "Warning: concurrent operation detected, are there two conflicting " .
801 "processes running, doing the same job?" );
802 }
803
804 return;
805 }
806 $this->recompress();
807 }
808
809 // Insert the data into the destination cluster
810 $targetCluster = $this->parent->getTargetCluster();
811 $store = $this->parent->store;
812 $targetDB = $store->getMaster( $targetCluster );
813 $targetDB->clearFlag( DBO_TRX ); // we manage the transactions
814 $targetDB->begin( __METHOD__ );
815 $baseUrl = $this->parent->store->store( $targetCluster, serialize( $this->cgz ) );
816
817 // Write the new URLs to the blob_tracking table
818 foreach ( $this->referrers as $textId => $hash ) {
819 $url = $baseUrl . '/' . $hash;
820 $dbw->update( 'blob_tracking',
821 [ 'bt_new_url' => $url ],
822 [
823 'bt_text_id' => $textId,
824 'bt_moved' => 0, # Check for concurrent conflicting update
825 ],
826 __METHOD__
827 );
828 }
829
830 $targetDB->commit( __METHOD__ );
831 // Critical section here: interruption at this point causes blob duplication
832 // Reversing the order of the commits would cause data loss instead
833 $dbw->commit( __METHOD__ );
834
835 // Write the new URLs to the text table and set the moved flag
836 if ( !$this->parent->copyOnly ) {
837 foreach ( $this->referrers as $textId => $hash ) {
838 $url = $baseUrl . '/' . $hash;
839 $this->parent->moveTextRow( $textId, $url );
840 }
841 }
842 }
843}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
serialize()
$GLOBALS['IP']
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfEscapeShellArg(... $args)
Version of escapeshellarg() that works better on Windows.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfHostname()
Fetch server name for use in error reporting etc.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
$line
Definition cdb.php:59
if( $line===false) $args
Definition cdb.php:64
Class to represent a recompression operation for a single CGZ blob.
ConcatenatedGzipHistoryBlob $cgz
RecompressTracked $parent
addItem( $text, $textId)
Add text.
commit()
Commit the blob.
recompress()
Recompress text after some aberrant modification.
__construct( $parent, $blobClass)
Create a transaction from a RecompressTracked object.
Concatenated gzip (CGZ) storage Improves compression ratio by concatenating like objects before gzipp...
DB accessible external objects.
PSR-3 logger that mimics the historic implementation of MediaWiki's former wfErrorLog logging impleme...
MediaWikiServices is the service locator for the application scope of MediaWiki.
Maintenance script that moves blobs indexed by trackBlobs.php to a specified list of destination clus...
executeChild()
Main entry point for worker processes.
moveTextRow( $textId, $url)
Atomic move operation.
dispatch()
Dispatch a command to the next available replica DB.
report( $label, $current, $end)
Display a progress report.
execute()
Execute parent or child depending on the isChild option.
getExtDB( $cluster)
Gets a DB master connection for the given external cluster name.
doOrphanList( $textIds)
Move an orphan text_id to the new cluster.
doAllOrphans()
Move all orphan text to the new clusters.
static newFromCommandLine( $args, $options)
finishIncompleteMoves( $conds)
Moves are done in two phases: bt_new_url and then bt_moved.
doPage( $pageId)
Move tracked text in a given page.
syncDBs()
Wait until the selected replica DB has caught up to the master.
startReplicaProcs()
Start the worker processes.
getTargetCluster()
Returns the name of the next target cluster.
executeParent()
Execute the parent process.
doAllPages()
Move all tracked pages to the new clusters.
killReplicaProcs()
Gracefully terminate the child processes.
dispatchToReplica( $replicaId, $args)
Dispatch a command to a specified replica DB.
checkTrackingTable()
Make sure the tracking table exists and isn't empty.
static getRevisionText( $row, $prefix='old_', $wiki=false)
Get revision text associated with an old or archive row.
$res
Definition database.txt:21
For a write query
Definition database.txt:26
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if that
Definition deferred.txt:13
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
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition hooks.txt:1305
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:2050
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:994
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to and or sell copies of the and to permit persons to whom the Software is furnished to do so
Definition LICENSE.txt:13
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:37
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
This document provides an overview of the usage of PageUpdater and that is
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:26
const DBO_TRX
Definition defines.php:12
$optionsWithArgs
if(count( $args)< 1) $job
MediaWiki s SiteStore can be cached and stored in a flat in a json format If the SiteStore is frequently the file cache may provide a performance benefit over a database store
Definition sitescache.txt:4
$header