http://www.mediawiki.org/wiki/Special:Code/MediaWiki/71854
Revision: 71854
Author: ialex
Date: 2010-08-28 12:27:29 +0000 (Sat, 28 Aug 2010)
Log Message:
-----------
Reuse code from updateRestrictions.php in do_restrictions_update() instead of
having its own code
Modified Paths:
--------------
trunk/phase3/maintenance/updaters.inc
Modified: trunk/phase3/maintenance/updaters.inc
===================================================================
--- trunk/phase3/maintenance/updaters.inc 2010-08-28 12:13:09 UTC (rev
71853)
+++ trunk/phase3/maintenance/updaters.inc 2010-08-28 12:27:29 UTC (rev
71854)
@@ -777,78 +777,26 @@
wfOut( "done.\n" );
}
+/**
+ * Adding page_restrictions table, obsoleting page.page_restrictions.
+ * Migrating old restrictions to new table
+ * -- Andrew Garrett, January 2007.
+ */
function do_restrictions_update() {
- # Adding page_restrictions table, obsoleting page.page_restrictions.
- # Migrating old restrictions to new table
- # -- Andrew Garrett, January 2007.
-
global $wgDatabase;
- $name = 'page_restrictions';
- $patch = 'patch-page_restrictions.sql';
- $patch2 = 'patch-page_restrictions_sortkey.sql';
-
- if ( $wgDatabase->tableExists( $name ) ) {
- wfOut( "...$name table already exists.\n" );
+ if ( $wgDatabase->tableExists( 'page_restrictions' ) ) {
+ wfOut( "...page_restrictions table already exists.\n" );
} else {
- wfOut( "Creating $name table..." );
- $wgDatabase->sourceFile( archive( $patch ) );
- $wgDatabase->sourceFile( archive( $patch2 ) );
+ wfOut( "Creating page_restrictions table..." );
+ $wgDatabase->sourceFile( archive( 'patch-page_restrictions.sql'
) );
+ $wgDatabase->sourceFile( archive(
'patch-page_restrictions_sortkey.sql' ) );
wfOut( "ok\n" );
- wfOut( "Migrating old restrictions to new table..." );
-
- $res = $wgDatabase->select( 'page', array( 'page_id',
'page_restrictions' ), array( "page_restrictions!=''",
"page_restrictions!='edit=:move='" ), __METHOD__ );
-
- $count = 0;
-
- while ( $row = $wgDatabase->fetchObject( $res ) ) {
- $count = ( $count + 1 ) % 100;
-
- if ( $count == 0 ) {
- if ( function_exists( 'wfWaitForSlaves' ) ) {
- wfWaitForSlaves( 10 );
- } else {
- sleep( 1 );
- }
- }
-
- # Figure out what the restrictions are..
- $id = $row->page_id;
- $flatrestrictions = explode( ':',
$row->page_restrictions );
-
- $restrictions = array ();
- foreach ( $flatrestrictions as $restriction ) {
- $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;
- }
- }
-
- $wgDatabase->update( 'page', array (
'page_restrictions' => '' ), array( 'page_id' => $id ), __METHOD__ );
-
- }
-
- foreach ( $restrictions as $type => $level ) {
- $wgDatabase->insert( 'page_restrictions', array
( 'pr_page' => $id,
-
'pr_type' => $type,
-
'pr_level' => $level,
-
'pr_cascade' => 0,
-
'pr_expiry' => 'infinity' ),
-
__METHOD__ );
- }
- }
- wfOut( "ok\n" );
+ wfOut( "Migrating old restrictions to new table...\n" );
+ require_once( 'updateRestrictions.php' );
+ $task = new UpdateRestrictions();
+ $task->execute();
}
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs