r19037 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19036‎ | r19037 | r19038 >
Date:05:42, 10 January 2007
Author:werdna
Status:old
Tags:
Comment:
Final-ish progress commit -- all that's left is that bloody null-edit problem; which can, frankly, come along in a later commit. I'm going to test the migration stuff on my own wiki, check with Tim/Brion about the schema change, and then I should be ready to merge :-)
Modified paths:
  • /branches/werdna/restrictions-separation/includes/Title.php (modified) (history)
  • /branches/werdna/restrictions-separation/maintenance/tables.sql (modified) (history)
  • /branches/werdna/restrictions-separation/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: branches/werdna/restrictions-separation/maintenance/updaters.inc
@@ -37,6 +37,7 @@
3838 array( 'filearchive', 'patch-filearchive.sql' ),
3939 array( 'redirect', 'patch-redirect.sql' ),
4040 array( 'querycachetwo', 'patch-querycachetwo.sql' ),
 41+# array( 'page_restrictions', 'patch-page_restrictions.sql' ),
4142 );
4243
4344 $wgNewFields = array(
@@ -925,6 +926,68 @@
926927 }
927928 }
928929
 930+function do_restrictions_update() {
 931+ # Adding page_restrictions table, obsoleting page.page_restrictions.
 932+ # Migrating old restrictions to new table
 933+ # -- Andrew Garrett, January 2007.
 934+
 935+ global $wgDatabase;
 936+
 937+ $name = 'page_restrictions';
 938+ $patch = 'patch-page_restrictions.sql';
 939+
 940+ if ( $wgDatabase->tableExists( $name ) ) {
 941+ echo "...$name table already exists.\n";
 942+ } else {
 943+ echo "Creating $name table...";
 944+ dbsource( archive($patch), $wgDatabase );
 945+ echo "ok\n";
 946+
 947+ echo "Migrating old restrictions to new table...";
 948+
 949+ $res = $wgDatabase->select( 'page', array( 'page_id', 'page_restrictions' ), array("page_restrictions!=''", "page_restrictions!='edit=:move='"), __METHOD__ );
 950+
 951+ $count = 0;
 952+
 953+ while ($row = $wgDatabase->fetchObject($res) ) {
 954+ $count = ($count + 1) % 100;
 955+
 956+ if ($count == 0) {
 957+ if ( function_exists( 'wfWaitForSlaves' ) ) {
 958+ wfWaitForSlaves( 10 );
 959+ } else {
 960+ sleep( 1 );
 961+ }
 962+ }
 963+
 964+ # Figure out what the restrictions are..
 965+ $id = $row->page_id;
 966+ $flatterrestrictions = $row->page_restrictions;
 967+
 968+ $flatrestrictions = explode( ':', $flatterrestrictions );
 969+
 970+ $restrictions = array ();
 971+
 972+ foreach( $flatrestrictions as $restriction ) {
 973+ $thisrestriction = explode('=', $restriction);
 974+
 975+ $restriction_type = $thisrestriction[0];
 976+ $restriction_level = $thisrestriction[1];
 977+
 978+ $restrictions[$restriction_type] = $restriction_level;
 979+
 980+ $wgDatabase->insert( 'page_restrictions', array ( 'pr_page' => $id,
 981+ 'pr_type' => $restriction_type,
 982+ 'pr_level' => $restriction_level,
 983+ 'pr_cascade' => 0 ), __METHOD );
 984+ }
 985+
 986+ echo "ok\n";
 987+ }
 988+ }
 989+
 990+}
 991+
929992 function do_postgres_updates() {
930993 global $wgDatabase, $wgVersion, $wgDBmwschema;
931994
Index: branches/werdna/restrictions-separation/maintenance/tables.sql
@@ -1047,7 +1047,7 @@
10481048 -- and deletions may refer to different page records as time
10491049 -- goes by.
10501050 rd_namespace int NOT NULL default '0',
1051 - rd_title varchar(255) binary NOT NULL default '',
 1051+ rd_title varchar(2deleted.55) binary NOT NULL default '',
10521052
10531053 PRIMARY KEY rd_from (rd_from),
10541054 KEY rd_ns_title (rd_namespace,rd_title,rd_from)
@@ -1075,4 +1075,23 @@
10761076
10771077 ) TYPE=InnoDB;
10781078
 1079+--- Used for storing page restrictions (i.e. protection levels)
 1080+CREATE TABLE /*$wgDBprefix*/page_restrictions (
 1081+ -- Page to apply restrictions to (Foreign Key to page).
 1082+ pr_page int(8) NOT NULL,
 1083+ -- The protection type (edit, move, etc)
 1084+ pr_type varchar(255) NOT NULL,
 1085+ -- The protection level (Sysop, autoconfirmed, etc)
 1086+ pr_level varchar(255) NOT NULL,
 1087+ -- Whether or not to cascade the protection down to pages transcluded.
 1088+ pr_cascade tinyint(4) NOT NULL,
 1089+
 1090+ PRIMARY KEY (pr_page,pr_type),
 1091+
 1092+ KEY pr_page (pr_page),
 1093+ KEY pr_typelevel (pr_type,pr_level),
 1094+ KEY pr_level (pr_level),
 1095+ KEY pr_cascade (pr_cascade)
 1096+) TYPE=InnoDB;
 1097+
10791098 -- vim: sw=2 sts=2 et
Index: branches/werdna/restrictions-separation/includes/Title.php
@@ -1349,7 +1349,7 @@
13501350
13511351 function areRestrictionsCascading() {
13521352 if (!$this->mRestrictionsLoaded) {
1353 - $this->getRestrictions();
 1353+ $this->loadRestrictions();
13541354 }
13551355
13561356 return $this->mCascadeRestrictions;