From def78d1992c48c78dc7dbb77d90f729b6a866bbb Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 11 Jan 2007 01:53:48 +0000 Subject: [PATCH] fix migration of page_restrictions fields from old versions of mw that didn't have move-protection option (field values like 'sysop') --- maintenance/updaters.inc | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 2f9ed54cbc..1beffc585e 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -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"; } -- 2.20.1