MediaWiki REL1_28
populateRecentChangesSource.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
33 public function __construct() {
34 parent::__construct();
35 $this->addDescription(
36 'Populates rc_source field of the recentchanges table with the data in rc_type.' );
37 $this->setBatchSize( 100 );
38 }
39
40 protected function doDBUpdates() {
41 $dbw = $this->getDB( DB_MASTER );
42 if ( !$dbw->fieldExists( 'recentchanges', 'rc_source' ) ) {
43 $this->error( 'rc_source field in recentchanges table does not exist.' );
44 }
45
46 $start = $dbw->selectField( 'recentchanges', 'MIN(rc_id)', false, __METHOD__ );
47 if ( !$start ) {
48 $this->output( "Nothing to do.\n" );
49
50 return true;
51 }
52 $end = $dbw->selectField( 'recentchanges', 'MAX(rc_id)', false, __METHOD__ );
53 $end += $this->mBatchSize - 1;
54 $blockStart = $start;
55 $blockEnd = $start + $this->mBatchSize - 1;
56
57 $updatedValues = $this->buildUpdateCondition( $dbw );
58
59 while ( $blockEnd <= $end ) {
60 $cond = "rc_id BETWEEN $blockStart AND $blockEnd";
61
62 $dbw->update(
63 'recentchanges',
64 [ $updatedValues ],
65 [
66 "rc_source = ''",
67 "rc_id BETWEEN $blockStart AND $blockEnd"
68 ],
69 __METHOD__
70 );
71
72 $this->output( "." );
74
75 $blockStart += $this->mBatchSize;
76 $blockEnd += $this->mBatchSize;
77 }
78
79 $this->output( "\nDone.\n" );
80 }
81
82 protected function getUpdateKey() {
83 return __CLASS__;
84 }
85
86 protected function buildUpdateCondition( Database $dbw ) {
87 $rcNew = $dbw->addQuotes( RC_NEW );
88 $rcSrcNew = $dbw->addQuotes( RecentChange::SRC_NEW );
89 $rcEdit = $dbw->addQuotes( RC_EDIT );
90 $rcSrcEdit = $dbw->addQuotes( RecentChange::SRC_EDIT );
91 $rcLog = $dbw->addQuotes( RC_LOG );
92 $rcSrcLog = $dbw->addQuotes( RecentChange::SRC_LOG );
93 $rcExternal = $dbw->addQuotes( RC_EXTERNAL );
94 $rcSrcExternal = $dbw->addQuotes( RecentChange::SRC_EXTERNAL );
95
96 return "rc_source = CASE
97 WHEN rc_type = $rcNew THEN $rcSrcNew
98 WHEN rc_type = $rcEdit THEN $rcSrcEdit
99 WHEN rc_type = $rcLog THEN $rcSrcLog
100 WHEN rc_type = $rcExternal THEN $rcSrcExternal
101 ELSE ''
102 END";
103 }
104}
105
106$maintClass = "PopulateRecentChangesSource";
107require_once RUN_MAINTENANCE_IF_MAIN;
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Relational database abstraction object.
Definition Database.php:36
addQuotes( $s)
Adds quotes and backslashes.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
error( $err, $die=0)
Throw an error to the user.
int $mBatchSize
Batch size.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
Set the batch size.
Maintenance script to populate the rc_source field.
getUpdateKey()
Get the update key name to go in the update log table.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
const RC_NEW
Definition Defines.php:137
const RC_LOG
Definition Defines.php:138
const RC_EXTERNAL
Definition Defines.php:139
const RC_EDIT
Definition Defines.php:136
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
require_once RUN_MAINTENANCE_IF_MAIN
const DB_MASTER
Definition defines.php:23