fix migration of page_restrictions fields from old versions of mw that didn't have...
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 11 Jan 2007 01:53:48 +0000 (01:53 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 11 Jan 2007 01:53:48 +0000 (01:53 +0000)
maintenance/updaters.inc

index 2f9ed54..1beffc5 100644 (file)
@@ -963,28 +963,34 @@ function do_restrictions_update() {
 
                        # Figure out what the restrictions are..
                        $id = $row->page_id;
-                       $flatterrestrictions = $row->page_restrictions;
-
-                       $flatrestrictions = explode( ':', $flatterrestrictions );
+                       $flatrestrictions = explode( ':', $row->page_restrictions );
 
                        $restrictions = array ();
-
                        foreach( $flatrestrictions as $restriction ) {
-                               $thisrestriction = explode('=', $restriction);
-
-                               $restriction_type = $thisrestriction[0];
-                               $restriction_level = $thisrestriction[1];
-
-                               $restrictions[$restriction_type] = $restriction_level;
-
-                               if ($restriction_level != '') {
-
-                                       $wgDatabase->insert( 'page_restrictions', array ( 'pr_page' => $id,
-                                                                                               'pr_type' => $restriction_type,
-                                                                                               'pr_level' => $restriction_level,
-                                                                                               'pr_cascade' => 0 ), __METHOD__ );
+                               $thisrestriction = explode( '=', $restriction, 2 );
+                               if( count( $thisrestriction ) == 1 ) {
+                                       // Compatibility with old protections from before
+                                       // separate move protection was added.
+                                       list( $level ) = $thisrestriction;
+                                       if( $level ) {
+                                               $restrictions['edit'] = $level;
+                                               $restrictions['move'] = $level;
+                                       }
+                               } else {
+                                       list( $type, $level ) = $thisrestriction;
+                                       if( $level ) {
+                                               $restrictions[$type] = $level;
+                                       }
                                }
                        }
+                       
+                       foreach( $restrictions as $type => $level ) {
+                               $wgDatabase->insert( 'page_restrictions', array ( 'pr_page' => $id,
+                                                                                       'pr_type' => $type,
+                                                                                       'pr_level' => $level,
+                                                                                       'pr_cascade' => 0 ),
+                                                                                       __METHOD__ );
+                       }
                }
                print "ok\n";
        }