From 42c6ba8ba74fca19770f2b21533ce0d6911d7bc8 Mon Sep 17 00:00:00 2001 From: Huji Date: Sun, 24 Feb 2008 20:11:43 +0000 Subject: [PATCH] Adding fixPageRestrcionts.php, a maintenance script which deals with bug 13132. --- maintenance/fixPageRestrictions.php | 103 ++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 maintenance/fixPageRestrictions.php diff --git a/maintenance/fixPageRestrictions.php b/maintenance/fixPageRestrictions.php new file mode 100644 index 0000000000..dbdc61800e --- /dev/null +++ b/maintenance/fixPageRestrictions.php @@ -0,0 +1,103 @@ + + */ + +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"; \ No newline at end of file -- 2.20.1