*/ require_once( 'commandLine.inc' ); $fname = 'fixPageRestrictions.php'; $dbw = wfGetDB( DB_MASTER ); // Get user IDs which need fixing $res = $dbw->select( 'page', 'page_id, page_restrictions', 'page_restrictions <>\'\'', $fname ); while ( $row = $dbw->fetchObject( $res ) ) { $id = $row->page_id; $old_restrictions = $row->page_restrictions; $edit_restriction = ''; $move_restriction = ''; if ( strpos( $old_restrictions, '=' ) !== false ) { if ( strpos( $old_restrictions, ':' ) !== false ) { # either "edit=x:move=y" or "move=x:edit=y" if ( strpos( $old_restrictions, 'edit' ) == 0 ){ # "edit=x:move=y" $edit_restriction = substr( $old_restrictions, 5, strlen( $old_restrictions) - strpos( $old_restrictions, ':') - 6); $move_restriction = substr( $old_restrictions, 5, strlen( $old_restrictions) - strpos( $old_restrictions, ':') - 6); } else { # "move=x:edit=y" $move_restriction = substr( $old_restrictions, 5, strlen( $old_restrictions) - strpos( $old_restrictions, ':') - 6); $edit_restriction = substr( $old_restrictions, 5, strlen( $old_restrictions) - strpos( $old_restrictions, ':') - 6); } } else { # either "edit=x" or "move=x" if ( strpos( $old_restrictions, 'edit') !== false ) { $edit_restriction = substr( $old_restrictions, 5); } else { $move_restriction = substr( $old_restrictions, 5); } } } else { # either "sysop" or "autoconfirmed" -- or an unexpected value if ( $old_restrictions == 'sysop' ) { $edit_restriction = 'sysop'; $move_restriction = 'sysop'; } elseif ( $old_restrictions == 'autoconfirmed' ) { $edit_restriction = 'autoconfirmed'; $move_restriction = 'autoconfirmed'; } else { #Shouldn't happen print "WARNING: I found a record with old restriction set to '$old_restrictions' and I can't handle it!\n"; } } if ( $edit_restriction <> '' ) { $dbw->replace( 'page_restrictions', array(array('pr_page', 'pr_type')), array( 'pr_page' => $id, 'pr_type' => 'edit' , 'pr_level' => $edit_restriction, 'pr_cascade' => 0 , 'pr_expiry' => 'infinity' ), $fname ); } if ( $move_restriction <> '' ) { $dbw->replace( 'page_restrictions', array(array('pr_page', 'pr_type')), array( 'pr_page' => $id, 'pr_type' => 'move' , 'pr_level' => $move_restriction, 'pr_cascade' => 0 , 'pr_expiry' => 'infinity' ), $fname ); } $dbw->update( 'page', array( 'page_restrictions' => ''), array( 'page_id' => $id), $fname); print "Fixed restrictions for page_id=$id\n from '$old_restrictions'\n to 'edit=$edit_restriction, move=$move_restriction'\n"; } print "\n";