Index: trunk/phase3/maintenance/fixPageRestrictions.php |
— | — | @@ -1,103 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Maintenance script to fix the page restrictions which were added using an |
5 | | - * older version of MediaWiki. |
6 | | - * |
7 | | - * Background |
8 | | - * |
9 | | - * Before page_restrictions table was introduced in version 1.10 |
10 | | - * (r19095�r19703), page protection was handled by modifying the value of |
11 | | - * page_restrictions field of the page table. Initially, this field either was |
12 | | - * left empty (ie page was not protected) or filled with the value "sysop" or |
13 | | - * "autoconfirmed". Later, it was decided that edit protection and move |
14 | | - * protection should be handled separately, so again, either the field was |
15 | | - * left empty, or filled with something like "edit=x:move=y" where x and y were |
16 | | - * either "sysop" or "autoconfirmed" (without quotes) themselves. Often, |
17 | | - * the order of the two parts were reversed (ie "move=x:edit=y"). |
18 | | - * |
19 | | - * When page_restrictions table was introduced, the code was touched in a way |
20 | | - * that if a page's protection level was changed, the old values in the page |
21 | | - * table were wiped out. The problem is, this part of code only runs when the |
22 | | - * protection level of the page *is changed*, and unfortunately, if an admin |
23 | | - * tries to unprotect the page, the code doesn't *sense* a change in protection |
24 | | - * level (because it compares the new value -- ie, nothing -- against the value |
25 | | - * of the page_restrictions table -- which is again nothing. This is reported on |
26 | | - * bugzilla as bug 13132. |
27 | | - * |
28 | | - * This maintenance script deals with the problem, by moving the protection data |
29 | | - * from page table to page_restrictions table. |
30 | | - * |
31 | | - * @addtogroup Maintenance |
32 | | - * @author Hojjat (aka Huji) <huji.huji@gmail.com> |
33 | | - */ |
34 | | - |
35 | | -require_once( 'commandLine.inc' ); |
36 | | - |
37 | | -$fname = 'fixPageRestrictions.php'; |
38 | | - |
39 | | -$dbw = wfGetDB( DB_MASTER ); |
40 | | - |
41 | | -// Get user IDs which need fixing |
42 | | -$res = $dbw->select( 'page', 'page_id, page_restrictions', 'page_restrictions <>\'\'', $fname ); |
43 | | - |
44 | | -while ( $row = $dbw->fetchObject( $res ) ) { |
45 | | - $id = $row->page_id; |
46 | | - $old_restrictions = $row->page_restrictions; |
47 | | - $edit_restriction = ''; |
48 | | - $move_restriction = ''; |
49 | | - if ( strpos( $old_restrictions, '=' ) !== false ) { |
50 | | - if ( strpos( $old_restrictions, ':' ) !== false ) { |
51 | | - # either "edit=x:move=y" or "move=x:edit=y" |
52 | | - if ( strpos( $old_restrictions, 'edit' ) == 0 ){ |
53 | | - # "edit=x:move=y" |
54 | | - $edit_restriction = substr( $old_restrictions, 5, strlen( $old_restrictions) - strpos( $old_restrictions, ':') - 6); |
55 | | - $move_restriction = substr( $old_restrictions, 5, strlen( $old_restrictions) - strpos( $old_restrictions, ':') - 6); |
56 | | - } else { |
57 | | - # "move=x:edit=y" |
58 | | - $move_restriction = substr( $old_restrictions, 5, strlen( $old_restrictions) - strpos( $old_restrictions, ':') - 6); |
59 | | - $edit_restriction = substr( $old_restrictions, 5, strlen( $old_restrictions) - strpos( $old_restrictions, ':') - 6); |
60 | | - } |
61 | | - } else { |
62 | | - # either "edit=x" or "move=x" |
63 | | - if ( strpos( $old_restrictions, 'edit') !== false ) { |
64 | | - $edit_restriction = substr( $old_restrictions, 5); |
65 | | - } else { |
66 | | - $move_restriction = substr( $old_restrictions, 5); |
67 | | - } |
68 | | - } |
69 | | - } else { |
70 | | - # either "sysop" or "autoconfirmed" -- or an unexpected value |
71 | | - if ( $old_restrictions == 'sysop' ) { |
72 | | - $edit_restriction = 'sysop'; |
73 | | - $move_restriction = 'sysop'; |
74 | | - } elseif ( $old_restrictions == 'autoconfirmed' ) { |
75 | | - $edit_restriction = 'autoconfirmed'; |
76 | | - $move_restriction = 'autoconfirmed'; |
77 | | - } else { |
78 | | - #Shouldn't happen |
79 | | - print "WARNING: I found a record with old restriction set to '$old_restrictions' and I can't handle it!\n"; |
80 | | - } |
81 | | - } |
82 | | - |
83 | | - if ( $edit_restriction <> '' ) { |
84 | | - $dbw->replace( 'page_restrictions', |
85 | | - array(array('pr_page', 'pr_type')), |
86 | | - array( 'pr_page' => $id, 'pr_type' => 'edit' |
87 | | - , 'pr_level' => $edit_restriction, 'pr_cascade' => 0 |
88 | | - , 'pr_expiry' => 'infinity' ), |
89 | | - $fname ); |
90 | | - } |
91 | | - if ( $move_restriction <> '' ) { |
92 | | - $dbw->replace( 'page_restrictions', |
93 | | - array(array('pr_page', 'pr_type')), |
94 | | - array( 'pr_page' => $id, 'pr_type' => 'move' |
95 | | - , 'pr_level' => $move_restriction, 'pr_cascade' => 0 |
96 | | - , 'pr_expiry' => 'infinity' ), |
97 | | - $fname ); |
98 | | - } |
99 | | - |
100 | | - $dbw->update( 'page', array( 'page_restrictions' => ''), array( 'page_id' => $id), $fname); |
101 | | - |
102 | | - print "Fixed restrictions for page_id=$id\n from '$old_restrictions'\n to 'edit=$edit_restriction, move=$move_restriction'\n"; |
103 | | -} |
104 | | -print "\n"; |
\ No newline at end of file |