MediaWiki  1.23.2
populateLogSearch.php
Go to the documentation of this file.
1 <?php
25 require_once __DIR__ . '/Maintenance.php';
26 
34  static $tableMap = array( 'rev' => 'revision', 'fa' => 'filearchive', 'oi' => 'oldimage', 'ar' => 'archive' );
35 
36  public function __construct() {
37  parent::__construct();
38  $this->mDescription = "Migrate log params to new table and index for searching";
39  $this->setBatchSize( 100 );
40  }
41 
42  protected function getUpdateKey() {
43  return 'populate log_search';
44  }
45 
46  protected function updateSkippedMessage() {
47  return 'log_search table already populated.';
48  }
49 
50  protected function doDBUpdates() {
51  $db = $this->getDB( DB_MASTER );
52  if ( !$db->tableExists( 'log_search' ) ) {
53  $this->error( "log_search does not exist" );
54  return false;
55  }
56  $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
57  if ( !$start ) {
58  $this->output( "Nothing to do.\n" );
59  return true;
60  }
61  $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ );
62 
63  # Do remaining chunk
64  $end += $this->mBatchSize - 1;
65  $blockStart = $start;
66  $blockEnd = $start + $this->mBatchSize - 1;
67 
68  $delTypes = array( 'delete', 'suppress' ); // revisiondelete types
69  while ( $blockEnd <= $end ) {
70  $this->output( "...doing log_id from $blockStart to $blockEnd\n" );
71  $cond = "log_id BETWEEN $blockStart AND $blockEnd";
72  $res = $db->select( 'logging', '*', $cond, __FUNCTION__ );
73  foreach ( $res as $row ) {
74  // RevisionDelete logs - revisions
75  if ( LogEventsList::typeAction( $row, $delTypes, 'revision' ) ) {
76  $params = LogPage::extractParams( $row->log_params );
77  // Param format: <urlparam> <item CSV> [<ofield> <nfield>]
78  if ( count( $params ) < 2 ) {
79  continue; // bad row?
80  }
82  // B/C, the params may start with a title key (<title> <urlparam> <CSV>)
83  if ( $field == null ) {
84  array_shift( $params ); // remove title param
86  if ( $field == null ) {
87  $this->output( "Invalid param type for {$row->log_id}\n" );
88  continue; // skip this row
89  } else {
90  // Clean up the row...
91  $db->update( 'logging',
92  array( 'log_params' => implode( ',', $params ) ),
93  array( 'log_id' => $row->log_id ) );
94  }
95  }
96  $items = explode( ',', $params[1] );
97  $log = new LogPage( $row->log_type );
98  // Add item relations...
99  $log->addRelations( $field, $items, $row->log_id );
100  // Determine what table to query...
101  $prefix = substr( $field, 0, strpos( $field, '_' ) ); // db prefix
102  if ( !isset( self::$tableMap[$prefix] ) ) {
103  continue; // bad row?
104  }
105  $table = self::$tableMap[$prefix];
106  $userField = $prefix . '_user';
107  $userTextField = $prefix . '_user_text';
108  // Add item author relations...
109  $userIds = $userIPs = array();
110  $sres = $db->select( $table,
111  array( $userField, $userTextField ),
112  array( $field => $items )
113  );
114  foreach ( $sres as $srow ) {
115  if ( $srow->$userField > 0 ) {
116  $userIds[] = intval( $srow->$userField );
117  } elseif ( $srow->$userTextField != '' ) {
118  $userIPs[] = $srow->$userTextField;
119  }
120  }
121  // Add item author relations...
122  $log->addRelations( 'target_author_id', $userIds, $row->log_id );
123  $log->addRelations( 'target_author_ip', $userIPs, $row->log_id );
124  // RevisionDelete logs - log events
125  } elseif ( LogEventsList::typeAction( $row, $delTypes, 'event' ) ) {
126  $params = LogPage::extractParams( $row->log_params );
127  // Param format: <item CSV> [<ofield> <nfield>]
128  if ( count( $params ) < 1 ) {
129  continue; // bad row
130  }
131  $items = explode( ',', $params[0] );
132  $log = new LogPage( $row->log_type );
133  // Add item relations...
134  $log->addRelations( 'log_id', $items, $row->log_id );
135  // Add item author relations...
136  $userIds = $userIPs = array();
137  $sres = $db->select( 'logging',
138  array( 'log_user', 'log_user_text' ),
139  array( 'log_id' => $items )
140  );
141  foreach ( $sres as $srow ) {
142  if ( $srow->log_user > 0 ) {
143  $userIds[] = intval( $srow->log_user );
144  } elseif ( IP::isIPAddress( $srow->log_user_text ) ) {
145  $userIPs[] = $srow->log_user_text;
146  }
147  }
148  $log->addRelations( 'target_author_id', $userIds, $row->log_id );
149  $log->addRelations( 'target_author_ip', $userIPs, $row->log_id );
150  }
151  }
152  $blockStart += $this->mBatchSize;
153  $blockEnd += $this->mBatchSize;
154  wfWaitForSlaves();
155  }
156  $this->output( "Done populating log_search table.\n" );
157  return true;
158  }
159 }
160 
161 $maintClass = "PopulateLogSearch";
162 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\$mBatchSize
int $mBatchSize
Batch size.
Definition: Maintenance.php:97
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
LogPage\extractParams
static extractParams( $blob)
Extract a parameter array from a blob.
Definition: LogPage.php:533
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$params
$params
Definition: styleTest.css.php:40
PopulateLogSearch\__construct
__construct()
Default constructor.
Definition: populateLogSearch.php:36
Maintenance\getDB
& getDB( $db, $groups=array(), $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1007
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: Maintenance.php:1209
$maintClass
$maintClass
Definition: populateLogSearch.php:161
LogEventsList\typeAction
static typeAction( $row, $type, $action, $right='')
Definition: LogEventsList.php:419
LogPage
Class to simplify the use of log pages.
Definition: LogPage.php:32
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
wfWaitForSlaves
wfWaitForSlaves( $maxLag=false, $wiki=false, $cluster=false)
Modern version of wfWaitForSlaves().
Definition: GlobalFunctions.php:3795
PopulateLogSearch\updateSkippedMessage
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
Definition: populateLogSearch.php:46
PopulateLogSearch
Maintenance script that makes the required database updates for populating the log_search table retro...
Definition: populateLogSearch.php:33
RevisionDeleter\getRelationType
static getRelationType( $typeName)
Get DB field name for URL param...
Definition: RevisionDeleter.php:152
PopulateLogSearch\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: populateLogSearch.php:50
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
PopulateLogSearch\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: populateLogSearch.php:42
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
$res
$res
Definition: database.txt:21
IP\isIPAddress
static isIPAddress( $ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition: IP.php:74
PopulateLogSearch\$tableMap
static $tableMap
Definition: populateLogSearch.php:34
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:254