MediaWiki  1.23.2
populateRecentChangesSource.php
Go to the documentation of this file.
1 <?php
24 require_once dirname( __FILE__ ) . '/Maintenance.php';
25 
33  public function __construct() {
34  parent::__construct();
35  $this->mDescription = "Populates rc_source field of the recentchanges table with the data in rc_type.";
36  $this->setBatchSize( 100 );
37  }
38 
39  protected function doDBUpdates() {
40  $dbw = $this->getDB( DB_MASTER );
41  if ( !$dbw->fieldExists( 'recentchanges', 'rc_source' ) ) {
42  $this->error( 'rc_source field in recentchanges table does not exist.' );
43  }
44 
45  $start = $dbw->selectField( 'recentchanges', 'MIN(rc_id)', false, __METHOD__ );
46  if ( !$start ) {
47  $this->output( "Nothing to do.\n" );
48  return true;
49  }
50  $end = $dbw->selectField( 'recentchanges', 'MAX(rc_id)', false, __METHOD__ );
51  $end += $this->mBatchSize - 1;
52  $blockStart = $start;
53  $blockEnd = $start + $this->mBatchSize - 1;
54 
55  $updatedValues = $this->buildUpdateCondition( $dbw );
56 
57  while ( $blockEnd <= $end ) {
58  $cond = "rc_id BETWEEN $blockStart AND $blockEnd";
59 
60  $dbw->update(
61  'recentchanges',
62  array( $updatedValues ),
63  array(
64  "rc_source = ''",
65  "rc_id BETWEEN $blockStart AND $blockEnd"
66  ),
67  __METHOD__
68  );
69 
70  $this->output( "." );
72 
73  $blockStart += $this->mBatchSize;
74  $blockEnd += $this->mBatchSize;
75  }
76 
77  $this->output( "\nDone.\n" );
78  }
79 
80  protected function getUpdateKey() {
81  return __CLASS__;
82  }
83 
84  protected function buildUpdateCondition( DatabaseBase $dbw ) {
85  $rcNew = $dbw->addQuotes( RC_NEW );
86  $rcSrcNew = $dbw->addQuotes( RecentChange::SRC_NEW );
87  $rcEdit = $dbw->addQuotes( RC_EDIT );
88  $rcSrcEdit = $dbw->addQuotes( RecentChange::SRC_EDIT );
89  $rcLog = $dbw->addQuotes( RC_LOG );
90  $rcSrcLog = $dbw->addQuotes( RecentChange::SRC_LOG );
91  $rcExternal = $dbw->addQuotes( RC_EXTERNAL );
92  $rcSrcExternal = $dbw->addQuotes( RecentChange::SRC_EXTERNAL );
93 
94  return "rc_source = CASE
95  WHEN rc_type = $rcNew THEN $rcSrcNew
96  WHEN rc_type = $rcEdit THEN $rcSrcEdit
97  WHEN rc_type = $rcLog THEN $rcSrcLog
98  WHEN rc_type = $rcExternal THEN $rcSrcExternal
99  ELSE ''
100  END";
101  }
102 }
103 
104 $maintClass = "PopulateRecentChangesSource";
105 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\$mBatchSize
int $mBatchSize
Batch size.
Definition: Maintenance.php:97
RC_EXTERNAL
const RC_EXTERNAL
Definition: Defines.php:183
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
PopulateRecentChangesSource\__construct
__construct()
Default constructor.
Definition: populateRecentChangesSource.php:33
RC_LOG
const RC_LOG
Definition: Defines.php:181
PopulateRecentChangesSource
Maintenance script to populate the rc_source field.
Definition: populateRecentChangesSource.php:32
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
RC_EDIT
const RC_EDIT
Definition: Defines.php:178
RecentChange\SRC_LOG
const SRC_LOG
Definition: RecentChange.php:68
Maintenance\getDB
& getDB( $db, $groups=array(), $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1007
DatabaseBase\addQuotes
addQuotes( $s)
Adds quotes and backslashes.
Definition: Database.php:2477
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: Maintenance.php:1209
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
RecentChange\SRC_EDIT
const SRC_EDIT
Definition: RecentChange.php:66
PopulateRecentChangesSource\buildUpdateCondition
buildUpdateCondition(DatabaseBase $dbw)
Definition: populateRecentChangesSource.php:84
RecentChange\SRC_NEW
const SRC_NEW
Definition: RecentChange.php:67
wfWaitForSlaves
wfWaitForSlaves( $maxLag=false, $wiki=false, $cluster=false)
Modern version of wfWaitForSlaves().
Definition: GlobalFunctions.php:3795
PopulateRecentChangesSource\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: populateRecentChangesSource.php:39
DatabaseBase
Database abstraction object.
Definition: Database.php:219
RC_NEW
const RC_NEW
Definition: Defines.php:179
$maintClass
$maintClass
Definition: populateRecentChangesSource.php:104
PopulateRecentChangesSource\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: populateRecentChangesSource.php:80
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:254
RecentChange\SRC_EXTERNAL
const SRC_EXTERNAL
Definition: RecentChange.php:69