Add 'whatlinkshere-filters'
[lhc/web/wiklou.git] / maintenance / updateRestrictions.php
1 <?php
2
3 /*
4 * Makes the required database updates for Special:ProtectedPages
5 * to show all protected pages, even ones before the page restrictions
6 * schema change. All remaining page_restriction column values are moved
7 * to the new table.
8 */
9
10 define( 'BATCH_SIZE', 100 );
11
12 require_once 'commandLine.inc';
13
14 $db =& wfGetDB( DB_MASTER );
15 if ( !$db->tableExists( 'page_restrictions' ) ) {
16 echo "page_restrictions does not exist\n";
17 exit( 1 );
18 }
19
20 migrate_page_restrictions( $db );
21
22 function migrate_page_restrictions( $db ) {
23
24 $start = $db->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ );
25 $end = $db->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ );
26 # Do remaining chunk
27 $end += BATCH_SIZE - 1;
28 $blockStart = $start;
29 $blockEnd = $start + BATCH_SIZE - 1;
30 $encodedExpiry = 'infinity';
31 while ( $blockEnd <= $end ) {
32 echo "...doing page_id from $blockStart to $blockEnd\n";
33 $cond = "page_id BETWEEN $blockStart AND $blockEnd AND page_restrictions !='' AND page_restrictions !='edit=:move='";
34 $res = $db->select( 'page', array('page_id', 'page_restrictions'), $cond, __FUNCTION__ );
35 $batch = array();
36 while ( $row = $db->fetchObject( $res ) ) {
37 $oldRestrictions = array();
38 foreach( explode( ':', trim( $row->page_restrictions ) ) as $restrict ) {
39 $temp = explode( '=', trim( $restrict ) );
40 if(count($temp) == 1) {
41 // old old format should be treated as edit/move restriction
42 $oldRestrictions["edit"] = trim( $temp[0] );
43 $oldRestrictions["move"] = trim( $temp[0] );
44 } else {
45 $oldRestrictions[$temp[0]] = trim( $temp[1] );
46 }
47 }
48 # Update restrictions table
49 foreach( $oldRestrictions as $action => $restrictions ) {
50 $batch[] = array(
51 'pr_page' => $row->page_id,
52 'pr_type' => $action,
53 'pr_level' => $restrictions,
54 'pr_cascade' => 0,
55 'pr_expiry' => $encodedExpiry
56 );
57 }
58 }
59 # We use insert() and not replace() as Article.php replaces
60 # page_restrictions with '' when protected in the restrictions table
61 if ( count( $batch ) ) {
62 $db->insert( 'page_restrictions', $batch, __FUNCTION__, array( 'IGNORE' ) );
63 }
64 $blockStart += BATCH_SIZE - 1;
65 $blockEnd += BATCH_SIZE - 1;
66 wfWaitForSlaves( 5 );
67 }
68 }
69
70