3 * Makes the required database updates for Special:ProtectedPages
4 * to show all protected pages, even ones before the page restrictions
5 * schema change. All remaining page_restriction column values are moved
12 define( 'BATCH_SIZE', 100 );
14 require_once 'commandLine.inc';
16 $db =& wfGetDB( DB_MASTER
);
17 if ( !$db->tableExists( 'page_restrictions' ) ) {
18 echo "page_restrictions does not exist\n";
22 migrate_page_restrictions( $db );
24 function migrate_page_restrictions( $db ) {
26 $start = $db->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__
);
27 $end = $db->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__
);
30 die("Nothing to do.\n");
34 $end +
= BATCH_SIZE
- 1;
36 $blockEnd = $start + BATCH_SIZE
- 1;
37 $encodedExpiry = 'infinity';
38 while ( $blockEnd <= $end ) {
39 echo "...doing page_id from $blockStart to $blockEnd\n";
40 $cond = "page_id BETWEEN $blockStart AND $blockEnd AND page_restrictions !='' AND page_restrictions !='edit=:move='";
41 $res = $db->select( 'page', array('page_id', 'page_restrictions'), $cond, __FUNCTION__
);
43 while ( $row = $db->fetchObject( $res ) ) {
44 $oldRestrictions = array();
45 foreach( explode( ':', trim( $row->page_restrictions
) ) as $restrict ) {
46 $temp = explode( '=', trim( $restrict ) );
47 if(count($temp) == 1) {
48 // old old format should be treated as edit/move restriction
49 $oldRestrictions["edit"] = trim( $temp[0] );
50 $oldRestrictions["move"] = trim( $temp[0] );
52 $oldRestrictions[$temp[0]] = trim( $temp[1] );
55 # Update restrictions table
56 foreach( $oldRestrictions as $action => $restrictions ) {
58 'pr_page' => $row->page_id
,
60 'pr_level' => $restrictions,
62 'pr_expiry' => $encodedExpiry
66 # We use insert() and not replace() as Article.php replaces
67 # page_restrictions with '' when protected in the restrictions table
68 if ( count( $batch ) ) {
69 $ok = $db->deadlockLoop(
70 array( $db, 'insert' ),
71 'page_restrictions', $batch, __FUNCTION__
, array( 'IGNORE' ) );
73 throw new MWException( "Deadlock loop failed wtf :(" );
76 $blockStart +
= BATCH_SIZE
- 1;
77 $blockEnd +
= BATCH_SIZE
- 1;