MediaWiki REL1_30
populateRecentChangesSource.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
27
35 public function __construct() {
36 parent::__construct();
37 $this->addDescription(
38 'Populates rc_source field of the recentchanges table with the data in rc_type.' );
39 $this->setBatchSize( 100 );
40 }
41
42 protected function doDBUpdates() {
43 $dbw = $this->getDB( DB_MASTER );
44 if ( !$dbw->fieldExists( 'recentchanges', 'rc_source' ) ) {
45 $this->error( 'rc_source field in recentchanges table does not exist.' );
46 }
47
48 $start = $dbw->selectField( 'recentchanges', 'MIN(rc_id)', false, __METHOD__ );
49 if ( !$start ) {
50 $this->output( "Nothing to do.\n" );
51
52 return true;
53 }
54 $end = $dbw->selectField( 'recentchanges', 'MAX(rc_id)', false, __METHOD__ );
55 $end += $this->mBatchSize - 1;
56 $blockStart = $start;
57 $blockEnd = $start + $this->mBatchSize - 1;
58
59 $updatedValues = $this->buildUpdateCondition( $dbw );
60
61 while ( $blockEnd <= $end ) {
62 $cond = "rc_id BETWEEN $blockStart AND $blockEnd";
63
64 $dbw->update(
65 'recentchanges',
66 [ $updatedValues ],
67 [
68 "rc_source = ''",
69 "rc_id BETWEEN $blockStart AND $blockEnd"
70 ],
71 __METHOD__
72 );
73
74 $this->output( "." );
76
77 $blockStart += $this->mBatchSize;
78 $blockEnd += $this->mBatchSize;
79 }
80
81 $this->output( "\nDone.\n" );
82 }
83
84 protected function getUpdateKey() {
85 return __CLASS__;
86 }
87
88 protected function buildUpdateCondition( IDatabase $dbw ) {
89 $rcNew = $dbw->addQuotes( RC_NEW );
90 $rcSrcNew = $dbw->addQuotes( RecentChange::SRC_NEW );
91 $rcEdit = $dbw->addQuotes( RC_EDIT );
92 $rcSrcEdit = $dbw->addQuotes( RecentChange::SRC_EDIT );
93 $rcLog = $dbw->addQuotes( RC_LOG );
94 $rcSrcLog = $dbw->addQuotes( RecentChange::SRC_LOG );
95 $rcExternal = $dbw->addQuotes( RC_EXTERNAL );
96 $rcSrcExternal = $dbw->addQuotes( RecentChange::SRC_EXTERNAL );
97
98 return "rc_source = CASE
99 WHEN rc_type = $rcNew THEN $rcSrcNew
100 WHEN rc_type = $rcEdit THEN $rcSrcEdit
101 WHEN rc_type = $rcLog THEN $rcSrcLog
102 WHEN rc_type = $rcExternal THEN $rcSrcExternal
103 ELSE ''
104 END";
105 }
106}
107
108$maintClass = "PopulateRecentChangesSource";
109require_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.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
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
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
Definition hooks.txt:2581
const RC_NEW
Definition Defines.php:144
const RC_LOG
Definition Defines.php:145
const RC_EXTERNAL
Definition Defines.php:146
const RC_EDIT
Definition Defines.php:143
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:40
addQuotes( $s)
Adds quotes and backslashes.
require_once RUN_MAINTENANCE_IF_MAIN
const DB_MASTER
Definition defines.php:26