4 * Makes the required database changes for the CheckUser extension
7 define( 'BATCH_SIZE', 100 );
9 require_once 'commandLine.inc';
11 $db =& wfGetDB( DB_MASTER
);
12 if ( !$db->tableExists( 'page_restrictions' ) ) {
13 echo "page_restrictions does not exist\n";
17 migrate_page_restrictions( $db );
19 function migrate_page_restrictions( $db ) {
21 $start = $db->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__
);
22 $end = $db->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__
);
24 $blockEnd = $start + BATCH_SIZE
- 1;
25 $encodedExpiry = Block
::decodeExpiry('');
26 while ( $blockEnd <= $end ) {
27 $cond = "page_id BETWEEN $blockStart AND $blockEnd AND page_rescrictions !=''";
28 $res = $db->select( 'page', array('page_id', 'page_restrictions'), $cond, __FUNCTION__
);
30 while ( $row = $db->fetchObject( $res ) ) {
31 $oldRestrictions = array();
32 foreach( explode( ':', trim( $row->page_restrictions
) ) as $restrict ) {
33 $temp = explode( '=', trim( $restrict ) );
34 if(count($temp) == 1) {
35 // old old format should be treated as edit/move restriction
36 $oldRestrictions["edit"] = explode( ',', trim( $temp[0] ) );
37 $oldRestrictions["move"] = explode( ',', trim( $temp[0] ) );
39 $oldRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) );
42 # Update restrictions table
43 foreach( $oldRestrictions as $action => $restrictions ) {
45 'pr_page' => $row->page_id
,
47 'pr_level' => $restrictions,
49 'pr_expiry' => $encodedExpiry
55 'page_restrictions' => ''
57 'page_id' => $row->page_id
58 ), 'migrate_restrictions'
61 # We use insert() and not replace() as Article.php replaces
62 # page_restrictions with '' when protected in the restrictions table
63 if ( count( $batch ) ) {
64 $db->insert( 'page_restictions', $batch, __FUNCTION__
);
66 $blockStart +
= BATCH_SIZE
;
67 $blockEnd +
= BATCH_SIZE
;