MediaWiki  master
tidyUpT39714.php
Go to the documentation of this file.
1 <?php
2 
3 require_once __DIR__ . '/Maintenance.php';
4 
6 
10 class TidyUpT39714 extends Maintenance {
11  public function execute() {
12  // Search for all log entries which are about changing the visability of other log entries.
13  $result = $this->getDB( DB_REPLICA )->select(
14  'logging',
15  [ 'log_id', 'log_params' ],
16  [
17  'log_type' => [ 'suppress', 'delete' ],
18  'log_action' => 'event',
19  'log_namespace' => NS_SPECIAL,
20  'log_title' => SpecialPage::getTitleFor( 'Log' )->getText()
21  ],
22  __METHOD__
23  );
24 
25  $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
26  foreach ( $result as $row ) {
27  $ids = explode( ',', explode( "\n", $row->log_params )[0] );
28  // Work out what log entries were changed here.
29  $result = $this->getDB( DB_REPLICA )->select(
30  'logging',
31  'log_type',
32  [ 'log_id' => $ids ],
33  __METHOD__,
34  'DISTINCT'
35  );
36  if ( $result->numRows() === 1 ) {
37  // If there's only one type, the target title can be set to include it.
38  $logTitle = SpecialPage::getTitleFor( 'Log', $result->current()->log_type )->getText();
39  $this->output( 'Set log_title to "' . $logTitle . '" for log entry ' . $row->log_id . ".\n" );
40  $this->getDB( DB_MASTER )->update(
41  'logging',
42  [ 'log_title' => $logTitle ],
43  [ 'log_id' => $row->log_id ],
44  __METHOD__
45  );
46  $lbFactory->waitForReplication();
47  }
48  }
49  }
50 }
51 
52 $maintClass = TidyUpT39714::class;
53 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:38
TidyUpT39714
Fixes all rows affected by T39714.
Definition: tidyUpT39714.php:10
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:152
TidyUpT39714\execute
execute()
Do the actual work.
Definition: tidyUpT39714.php:11
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:90
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:53
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:58
$maintClass
$maintClass
Definition: tidyUpT39714.php:52
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1350
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:429