MediaWiki  1.23.14
updateRestrictions.php
Go to the documentation of this file.
1 <?php
27 require_once __DIR__ . '/Maintenance.php';
28 
36  public function __construct() {
37  parent::__construct();
38  $this->mDescription = "Updates page_restrictions table from old page_restriction column";
39  $this->setBatchSize( 100 );
40  }
41 
42  public function execute() {
43  $db = wfGetDB( DB_MASTER );
44  if ( !$db->tableExists( 'page_restrictions' ) ) {
45  $this->error( "page_restrictions table does not exist", true );
46  }
47 
48  $start = $db->selectField( 'page', 'MIN(page_id)', false, __METHOD__ );
49  if ( !$start ) {
50  $this->error( "Nothing to do.", true );
51  }
52  $end = $db->selectField( 'page', 'MAX(page_id)', false, __METHOD__ );
53 
54  # Do remaining chunk
55  $end += $this->mBatchSize - 1;
56  $blockStart = $start;
57  $blockEnd = $start + $this->mBatchSize - 1;
58  $encodedExpiry = 'infinity';
59  while ( $blockEnd <= $end ) {
60  $this->output( "...doing page_id from $blockStart to $blockEnd\n" );
61  $cond = "page_id BETWEEN $blockStart AND $blockEnd AND page_restrictions !=''";
62  $res = $db->select( 'page', array( 'page_id', 'page_namespace', 'page_restrictions' ), $cond, __METHOD__ );
63  $batch = array();
64  foreach ( $res as $row ) {
65  $oldRestrictions = array();
66  foreach ( explode( ':', trim( $row->page_restrictions ) ) as $restrict ) {
67  $temp = explode( '=', trim( $restrict ) );
68  // Make sure we are not settings restrictions to ""
69  if ( count( $temp ) == 1 && $temp[0] ) {
70  // old old format should be treated as edit/move restriction
71  $oldRestrictions["edit"] = trim( $temp[0] );
72  $oldRestrictions["move"] = trim( $temp[0] );
73  } elseif ( $temp[1] ) {
74  $oldRestrictions[$temp[0]] = trim( $temp[1] );
75  }
76  }
77  # Clear invalid columns
78  if ( $row->page_namespace == NS_MEDIAWIKI ) {
79  $db->update( 'page', array( 'page_restrictions' => '' ),
80  array( 'page_id' => $row->page_id ), __FUNCTION__ );
81  $this->output( "...removed dead page_restrictions column for page {$row->page_id}\n" );
82  }
83  # Update restrictions table
84  foreach ( $oldRestrictions as $action => $restrictions ) {
85  $batch[] = array(
86  'pr_page' => $row->page_id,
87  'pr_type' => $action,
88  'pr_level' => $restrictions,
89  'pr_cascade' => 0,
90  'pr_expiry' => $encodedExpiry
91  );
92  }
93  }
94  # We use insert() and not replace() as Article.php replaces
95  # page_restrictions with '' when protected in the restrictions table
96  if ( count( $batch ) ) {
97  $ok = $db->deadlockLoop( array( $db, 'insert' ), 'page_restrictions',
98  $batch, __FUNCTION__, array( 'IGNORE' ) );
99  if ( !$ok ) {
100  throw new MWException( "Deadlock loop failed wtf :(" );
101  }
102  }
103  $blockStart += $this->mBatchSize - 1;
104  $blockEnd += $this->mBatchSize - 1;
105  wfWaitForSlaves();
106  }
107  $this->output( "...removing dead rows from page_restrictions\n" );
108  // Kill any broken rows from previous imports
109  $db->delete( 'page_restrictions', array( 'pr_level' => '' ) );
110  // Kill other invalid rows
111  $db->deleteJoin( 'page_restrictions', 'page', 'pr_page', 'page_id', array( 'page_namespace' => NS_MEDIAWIKI ) );
112  $this->output( "...Done!\n" );
113  }
114 }
115 
116 $maintClass = "UpdateRestrictions";
117 require_once RUN_MAINTENANCE_IF_MAIN;
UpdateRestrictions
Maintenance script that updates page_restrictions table from old page_restriction column.
Definition: updateRestrictions.php:35
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
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3714
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
MWException
MediaWiki exception.
Definition: MWException.php:26
$maintClass
$maintClass
Definition: updateRestrictions.php:116
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:3859
UpdateRestrictions\__construct
__construct()
Default constructor.
Definition: updateRestrictions.php:36
$ok
$ok
Definition: UtfNormalTest.php:71
UpdateRestrictions\execute
execute()
Do the actual work.
Definition: updateRestrictions.php:42
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
$batch
$batch
Definition: linkcache.txt:23
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
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:87
$res
$res
Definition: database.txt:21
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:254