Index: branches/maintenance-work/maintenance/rebuildFileCache.php |
— | — | @@ -13,6 +13,7 @@ |
14 | 14 | parent::__construct(); |
15 | 15 | $this->mDescription = "Build file cache for content pages"; |
16 | 16 | $this->addArgs( array( 'start', 'overwrite' ) ); |
| 17 | + $this->setBatchSize( 100 ); |
17 | 18 | } |
18 | 19 | |
19 | 20 | public function execute() { |
— | — | @@ -24,22 +25,21 @@ |
25 | 26 | $start = intval( $this->getArg( 0, 0 ) ); |
26 | 27 | $overwrite = $this->hasArg(1) && $this->getArg(1) === 'overwrite'; |
27 | 28 | $this->output( "Building content page file cache from page {$start}!\n" ); |
28 | | - |
| 29 | + |
29 | 30 | $dbr = wfGetDB( DB_SLAVE ); |
30 | 31 | $start = $start > 0 ? $start : $dbr->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ ); |
31 | 32 | $end = $dbr->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ ); |
32 | 33 | if( !$start ) { |
33 | 34 | $this->error( "Nothing to do.\n", true ); |
34 | 35 | } |
35 | | - |
| 36 | + |
36 | 37 | $_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip'; // hack, no real client |
37 | 38 | OutputPage::setEncodings(); # Not really used yet |
38 | | - |
39 | | - $BATCH_SIZE = 100; |
| 39 | + |
40 | 40 | # Do remaining chunk |
41 | | - $end += $BATCH_SIZE - 1; |
| 41 | + $end += $this->mBatchSize - 1; |
42 | 42 | $blockStart = $start; |
43 | | - $blockEnd = $start + $BATCH_SIZE - 1; |
| 43 | + $blockEnd = $start + $this->mBatchSize - 1; |
44 | 44 | |
45 | 45 | $dbw = wfGetDB( DB_MASTER ); |
46 | 46 | // Go through each page and save the output |
— | — | @@ -85,8 +85,8 @@ |
86 | 86 | } |
87 | 87 | $dbw->commit(); // commit any changes |
88 | 88 | } |
89 | | - $blockStart += $BATCH_SIZE; |
90 | | - $blockEnd += $BATCH_SIZE; |
| 89 | + $blockStart += $this->mBatchSize; |
| 90 | + $blockEnd += $this->mBatchSize; |
91 | 91 | wfWaitForSlaves( 5 ); |
92 | 92 | } |
93 | 93 | $this->output( "Done!\n" ); |
Index: branches/maintenance-work/maintenance/changePassword.php |
— | — | @@ -21,9 +21,6 @@ |
22 | 22 | } |
23 | 23 | |
24 | 24 | public function execute() { |
25 | | - if( !$this->hasOption('user') || !$this->hasOption('password') ) { |
26 | | - $this->error( "Username or password not provided, halting.", true ); |
27 | | - } |
28 | 25 | $user = User::newFromName( $this->getOption('user') ); |
29 | 26 | if( !$user->getId() ) { |
30 | 27 | $this->error( "No such user: " . $this->getOption('user') . "\n", true ); |
Index: branches/maintenance-work/maintenance/checkImages.php |
— | — | @@ -9,10 +9,10 @@ |
10 | 10 | public function __construct() { |
11 | 11 | parent::__construct(); |
12 | 12 | $this->mDescription = "Check images to see if they exist, are readable, etc"; |
| 13 | + $this->setBatchSize( 1000 ); |
13 | 14 | } |
14 | 15 | |
15 | 16 | public function execute() { |
16 | | - $batchSize = 1000; |
17 | 17 | $start = ''; |
18 | 18 | $dbr = wfGetDB( DB_SLAVE ); |
19 | 19 | |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | |
23 | 23 | do { |
24 | 24 | $res = $dbr->select( 'image', '*', array( 'img_name > ' . $dbr->addQuotes( $start ) ), |
25 | | - __METHOD__, array( 'LIMIT' => $batchSize ) ); |
| 25 | + __METHOD__, array( 'LIMIT' => $this->mBatchSize ) ); |
26 | 26 | foreach ( $res as $row ) { |
27 | 27 | $numImages++; |
28 | 28 | $start = $row->img_name; |
Index: branches/maintenance-work/maintenance/populateParentId.php |
— | — | @@ -8,13 +8,10 @@ |
9 | 9 | require_once( "Maintenance.php" ); |
10 | 10 | |
11 | 11 | class PopulateParentId extends Maintenance { |
12 | | - |
13 | | - // Batch size |
14 | | - const BATCH_SIZE = 200; |
15 | | - |
16 | 12 | public function __construct() { |
17 | 13 | parent::__construct(); |
18 | 14 | $this->mDescription = "Populates rev_parent_id"; |
| 15 | + $this->setBatchSize( 200 ); |
19 | 16 | } |
20 | 17 | |
21 | 18 | public function execute() { |
— | — | @@ -29,14 +26,14 @@ |
30 | 27 | $this->output( "...revision table seems to be empty.\n" ); |
31 | 28 | $db->insert( 'updatelog', |
32 | 29 | array( 'ul_key' => 'populate rev_parent_id' ), |
33 | | - __FUNCTION__, |
| 30 | + __METHOD__, |
34 | 31 | 'IGNORE' ); |
35 | 32 | return; |
36 | 33 | } |
37 | 34 | # Do remaining chunk |
38 | | - $end += self::BATCH_SIZE - 1; |
| 35 | + $end += $this->mBatchSize - 1; |
39 | 36 | $blockStart = intval( $start ); |
40 | | - $blockEnd = intval( $start ) + self::BATCH_SIZE - 1; |
| 37 | + $blockEnd = intval( $start ) + $this->mBatchSize - 1; |
41 | 38 | $count = 0; |
42 | 39 | $changed = 0; |
43 | 40 | while( $blockEnd <= $end ) { |
— | — | @@ -44,7 +41,7 @@ |
45 | 42 | $cond = "rev_id BETWEEN $blockStart AND $blockEnd"; |
46 | 43 | $res = $db->select( 'revision', |
47 | 44 | array('rev_id','rev_page','rev_timestamp','rev_parent_id'), |
48 | | - $cond, __FUNCTION__ ); |
| 45 | + $cond, __METHOD__ ); |
49 | 46 | # Go through and update rev_parent_id from these rows. |
50 | 47 | # Assume that the previous revision of the title was |
51 | 48 | # the original previous revision of the title when the |
— | — | @@ -56,20 +53,20 @@ |
57 | 54 | $previousID = $db->selectField( 'revision', 'rev_id', |
58 | 55 | array( 'rev_page' => $row->rev_page, 'rev_timestamp' => $row->rev_timestamp, |
59 | 56 | "rev_id < " . intval( $row->rev_id ) ), |
60 | | - __FUNCTION__, |
| 57 | + __METHOD__, |
61 | 58 | array( 'ORDER BY' => 'rev_id DESC' ) ); |
62 | 59 | # If there are none, check the the highest ID with a lower timestamp |
63 | 60 | if( !$previousID ) { |
64 | 61 | # Get the highest older timestamp |
65 | 62 | $lastTimestamp = $db->selectField( 'revision', 'rev_timestamp', |
66 | 63 | array( 'rev_page' => $row->rev_page, "rev_timestamp < " . $db->addQuotes( $row->rev_timestamp ) ), |
67 | | - __FUNCTION__, |
| 64 | + __METHOD__, |
68 | 65 | array( 'ORDER BY' => 'rev_timestamp DESC' ) ); |
69 | 66 | # If there is one, let the highest rev ID win |
70 | 67 | if( $lastTimestamp ) { |
71 | 68 | $previousID = $db->selectField( 'revision', 'rev_id', |
72 | 69 | array( 'rev_page' => $row->rev_page, 'rev_timestamp' => $lastTimestamp ), |
73 | | - __FUNCTION__, |
| 70 | + __METHOD__, |
74 | 71 | array( 'ORDER BY' => 'rev_id DESC' ) ); |
75 | 72 | } |
76 | 73 | } |
— | — | @@ -80,16 +77,16 @@ |
81 | 78 | $db->update( 'revision', |
82 | 79 | array( 'rev_parent_id' => $previousID ), |
83 | 80 | array( 'rev_id' => $row->rev_id ), |
84 | | - __FUNCTION__ ); |
| 81 | + __METHOD__ ); |
85 | 82 | $count++; |
86 | 83 | } |
87 | | - $blockStart += self::BATCH_SIZE - 1; |
88 | | - $blockEnd += self::BATCH_SIZE - 1; |
| 84 | + $blockStart += $this->mBatchSize - 1; |
| 85 | + $blockEnd += $this->mBatchSize - 1; |
89 | 86 | wfWaitForSlaves( 5 ); |
90 | 87 | } |
91 | 88 | $logged = $db->insert( 'updatelog', |
92 | 89 | array( 'ul_key' => 'populate rev_parent_id' ), |
93 | | - __FUNCTION__, |
| 90 | + __METHOD__, |
94 | 91 | 'IGNORE' ); |
95 | 92 | if( $logged ) { |
96 | 93 | $this->output( "rev_parent_id population complete ... {$count} rows [{$changed} changed]\n" ); |
Index: branches/maintenance-work/maintenance/Maintenance.php |
— | — | @@ -313,6 +313,7 @@ |
314 | 314 | |
315 | 315 | $this->loadParamsAndArgs(); |
316 | 316 | $this->maybeHelp(); |
| 317 | + $this->validateParamsAndArgs(); |
317 | 318 | } |
318 | 319 | |
319 | 320 | /** |
— | — | @@ -410,22 +411,27 @@ |
411 | 412 | } |
412 | 413 | } |
413 | 414 | |
| 415 | + $this->mOptions = $options; |
| 416 | + $this->mArgs = $args; |
| 417 | + $this->loadSpecialVars(); |
| 418 | + $this->inputLoaded = true; |
| 419 | + } |
| 420 | + |
| 421 | + /** |
| 422 | + * Run some validation checks on the params, etc |
| 423 | + */ |
| 424 | + private function validateParamsAndArgs() { |
414 | 425 | # Check to make sure we've got all the required ones |
415 | 426 | foreach( $this->mParams as $opt => $info ) { |
416 | 427 | if( $info['require'] && !$this->hasOption($opt) ) { |
417 | 428 | $this->error( "Param $opt required.\n", true ); |
418 | 429 | } |
419 | 430 | } |
420 | | - |
| 431 | + |
421 | 432 | # Also make sure we've got enough arguments |
422 | | - if ( count( $args ) < count( $this->mArgList ) ) { |
| 433 | + if ( count( $this->mArgs ) < count( $this->mArgList ) ) { |
423 | 434 | $this->error( "Not enough arguments passed", true ); |
424 | 435 | } |
425 | | - |
426 | | - $this->mOptions = $options; |
427 | | - $this->mArgs = $args; |
428 | | - $this->loadSpecialVars(); |
429 | | - $this->inputLoaded = true; |
430 | 436 | } |
431 | 437 | |
432 | 438 | /** |
Index: branches/maintenance-work/maintenance/updateRestrictions.php |
— | — | @@ -9,84 +9,88 @@ |
10 | 10 | * @ingroup Maintenance |
11 | 11 | */ |
12 | 12 | |
13 | | -define( 'BATCH_SIZE', 100 ); |
| 13 | +require_once( "Maintenance.php" ); |
14 | 14 | |
15 | | -require_once 'commandLine.inc'; |
16 | | - |
17 | | -$db =& wfGetDB( DB_MASTER ); |
18 | | -if ( !$db->tableExists( 'page_restrictions' ) ) { |
19 | | - echo "page_restrictions does not exist\n"; |
20 | | - exit( 1 ); |
21 | | -} |
| 15 | +class UpdateRestrictions extends Maintenance { |
| 16 | + public function __construct() { |
| 17 | + parent::__construct(); |
| 18 | + $this->mDescription = ""; |
| 19 | + $this->setBatchSize( 100 ); |
| 20 | + } |
22 | 21 | |
23 | | -migrate_page_restrictions( $db ); |
| 22 | + private function execute() { |
| 23 | + $db = wfGetDB( DB_MASTER ); |
| 24 | + if( !$db->tableExists( 'page_restrictions' ) ) { |
| 25 | + $this->error( "page_restrictions table does not exist\n", true ); |
| 26 | + } |
24 | 27 | |
25 | | -function migrate_page_restrictions( $db ) { |
26 | | - $start = $db->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ ); |
27 | | - if( !$start ) { |
28 | | - die("Nothing to do.\n"); |
29 | | - } |
30 | | - $end = $db->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ ); |
| 28 | + $start = $db->selectField( 'page', 'MIN(page_id)', false, __METHOD__ ); |
| 29 | + if( !$start ) { |
| 30 | + $this->error( "Nothing to do.\n", true ); |
| 31 | + } |
| 32 | + $end = $db->selectField( 'page', 'MAX(page_id)', false, __METHOD__ ); |
31 | 33 | |
32 | | - # Do remaining chunk |
33 | | - $end += BATCH_SIZE - 1; |
34 | | - $blockStart = $start; |
35 | | - $blockEnd = $start + BATCH_SIZE - 1; |
36 | | - $encodedExpiry = 'infinity'; |
37 | | - while( $blockEnd <= $end ) { |
38 | | - echo "...doing page_id from $blockStart to $blockEnd\n"; |
39 | | - $cond = "page_id BETWEEN $blockStart AND $blockEnd AND page_restrictions !=''"; |
40 | | - $res = $db->select( 'page', array('page_id','page_namespace','page_restrictions'), $cond, __FUNCTION__ ); |
41 | | - $batch = array(); |
42 | | - while( $row = $db->fetchObject( $res ) ) { |
43 | | - $oldRestrictions = array(); |
44 | | - foreach( explode( ':', trim( $row->page_restrictions ) ) as $restrict ) { |
45 | | - $temp = explode( '=', trim( $restrict ) ); |
46 | | - // Make sure we are not settings restrictions to "" |
47 | | - if( count($temp) == 1 && $temp[0] ) { |
48 | | - // old old format should be treated as edit/move restriction |
49 | | - $oldRestrictions["edit"] = trim( $temp[0] ); |
50 | | - $oldRestrictions["move"] = trim( $temp[0] ); |
51 | | - } else if( $temp[1] ) { |
52 | | - $oldRestrictions[$temp[0]] = trim( $temp[1] ); |
| 34 | + # Do remaining chunk |
| 35 | + $end += $this->mBatchSize - 1; |
| 36 | + $blockStart = $start; |
| 37 | + $blockEnd = $start + $this->mBatchSize - 1; |
| 38 | + $encodedExpiry = 'infinity'; |
| 39 | + while( $blockEnd <= $end ) { |
| 40 | + $this->output( "...doing page_id from $blockStart to $blockEnd\n" ); |
| 41 | + $cond = "page_id BETWEEN $blockStart AND $blockEnd AND page_restrictions !=''"; |
| 42 | + $res = $db->select( 'page', array('page_id','page_namespace','page_restrictions'), $cond, __METHOD__ ); |
| 43 | + $batch = array(); |
| 44 | + while( $row = $db->fetchObject( $res ) ) { |
| 45 | + $oldRestrictions = array(); |
| 46 | + foreach( explode( ':', trim( $row->page_restrictions ) ) as $restrict ) { |
| 47 | + $temp = explode( '=', trim( $restrict ) ); |
| 48 | + // Make sure we are not settings restrictions to "" |
| 49 | + if( count($temp) == 1 && $temp[0] ) { |
| 50 | + // old old format should be treated as edit/move restriction |
| 51 | + $oldRestrictions["edit"] = trim( $temp[0] ); |
| 52 | + $oldRestrictions["move"] = trim( $temp[0] ); |
| 53 | + } else if( $temp[1] ) { |
| 54 | + $oldRestrictions[$temp[0]] = trim( $temp[1] ); |
| 55 | + } |
53 | 56 | } |
| 57 | + # Clear invalid columns |
| 58 | + if( $row->page_namespace == NS_MEDIAWIKI ) { |
| 59 | + $db->update( 'page', array( 'page_restrictions' => '' ), |
| 60 | + array( 'page_id' => $row->page_id ), __FUNCTION__ ); |
| 61 | + $this->output( "...removed dead page_restrictions column for page {$row->page_id}\n" ); |
| 62 | + } |
| 63 | + # Update restrictions table |
| 64 | + foreach( $oldRestrictions as $action => $restrictions ) { |
| 65 | + $batch[] = array( |
| 66 | + 'pr_page' => $row->page_id, |
| 67 | + 'pr_type' => $action, |
| 68 | + 'pr_level' => $restrictions, |
| 69 | + 'pr_cascade' => 0, |
| 70 | + 'pr_expiry' => $encodedExpiry |
| 71 | + ); |
| 72 | + } |
54 | 73 | } |
55 | | - # Clear invalid columns |
56 | | - if( $row->page_namespace == NS_MEDIAWIKI ) { |
57 | | - $db->update( 'page', array( 'page_restrictions' => '' ), |
58 | | - array( 'page_id' => $row->page_id ), __FUNCTION__ ); |
59 | | - echo "...removed dead page_restrictions column for page {$row->page_id}\n"; |
| 74 | + # We use insert() and not replace() as Article.php replaces |
| 75 | + # page_restrictions with '' when protected in the restrictions table |
| 76 | + if ( count( $batch ) ) { |
| 77 | + $ok = $db->deadlockLoop( array( $db, 'insert' ), 'page_restrictions', |
| 78 | + $batch, __FUNCTION__, array( 'IGNORE' ) ); |
| 79 | + if( !$ok ) { |
| 80 | + throw new MWException( "Deadlock loop failed wtf :(" ); |
| 81 | + } |
60 | 82 | } |
61 | | - # Update restrictions table |
62 | | - foreach( $oldRestrictions as $action => $restrictions ) { |
63 | | - $batch[] = array( |
64 | | - 'pr_page' => $row->page_id, |
65 | | - 'pr_type' => $action, |
66 | | - 'pr_level' => $restrictions, |
67 | | - 'pr_cascade' => 0, |
68 | | - 'pr_expiry' => $encodedExpiry |
69 | | - ); |
70 | | - } |
| 83 | + $blockStart += $this->mBatchSize - 1; |
| 84 | + $blockEnd += $this->mBatchSize - 1; |
| 85 | + wfWaitForSlaves( 5 ); |
71 | 86 | } |
72 | | - # We use insert() and not replace() as Article.php replaces |
73 | | - # page_restrictions with '' when protected in the restrictions table |
74 | | - if ( count( $batch ) ) { |
75 | | - $ok = $db->deadlockLoop( array( $db, 'insert' ), 'page_restrictions', |
76 | | - $batch, __FUNCTION__, array( 'IGNORE' ) ); |
77 | | - if( !$ok ) { |
78 | | - throw new MWException( "Deadlock loop failed wtf :(" ); |
79 | | - } |
80 | | - } |
81 | | - $blockStart += BATCH_SIZE - 1; |
82 | | - $blockEnd += BATCH_SIZE - 1; |
83 | | - wfWaitForSlaves( 5 ); |
| 87 | + $this->output( "...removing dead rows from page_restrictions\n" ); |
| 88 | + // Kill any broken rows from previous imports |
| 89 | + $db->delete( 'page_restrictions', array( 'pr_level' => '' ) ); |
| 90 | + // Kill other invalid rows |
| 91 | + $db->deleteJoin( 'page_restrictions', 'page', 'pr_page', 'page_id', array('page_namespace' => NS_MEDIAWIKI) ); |
| 92 | + $this->output( "...Done!\n" ); |
84 | 93 | } |
85 | | - echo "...removing dead rows from page_restrictions\n"; |
86 | | - // Kill any broken rows from previous imports |
87 | | - $db->delete( 'page_restrictions', array( 'pr_level' => '' ) ); |
88 | | - // Kill other invalid rows |
89 | | - $db->deleteJoin( 'page_restrictions', 'page', 'pr_page', 'page_id', array('page_namespace' => NS_MEDIAWIKI) ); |
90 | | - echo "...Done!\n"; |
91 | 94 | } |
92 | 95 | |
93 | | - |
| 96 | +$maintClass = "UpdateRestrictions"; |
| 97 | +require_once( DO_MAINTENANCE ); |