Index: trunk/extensions/FlaggedRevs/maintenance/reviewAllPages.inc |
— | — | @@ -1,55 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -function autoreview_current( $user, $db ) { |
5 | | - global $wgFlaggedRevsNamespaces; |
6 | | - echo "Auto-reviewing all current page versions...\n"; |
7 | | - if( !$user->getID() ) { |
8 | | - echo( "Invalid user specified!" ); |
9 | | - exit(0); |
10 | | - } |
11 | | - echo "Reviewer username: ".$user->getName()."\n"; |
12 | | - $BATCH_SIZE = 50; |
13 | | - $start = $db->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ ); |
14 | | - $end = $db->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ ); |
15 | | - if( is_null( $start ) || is_null( $end ) ){ |
16 | | - echo "...page table seems to be empty.\n"; |
17 | | - return; |
18 | | - } |
19 | | - # Do remaining chunk |
20 | | - $end += $BATCH_SIZE - 1; |
21 | | - $blockStart = $start; |
22 | | - $blockEnd = $start + $BATCH_SIZE - 1; |
23 | | - $count = 0; |
24 | | - $changed = 0; |
25 | | - $flags = FlaggedRevs::quickTags( FR_CHECKED ); // Assume basic level |
26 | | - while( $blockEnd <= $end ) { |
27 | | - echo "...doing page_id from $blockStart to $blockEnd\n"; |
28 | | - $cond = "page_id BETWEEN $blockStart AND $blockEnd"; |
29 | | - $res = $db->select( 'page', array('page_id','page_latest','page_namespace','page_title'), |
30 | | - array( $cond, 'page_namespace' => $wgFlaggedRevsNamespaces ), |
31 | | - __FUNCTION__ ); |
32 | | - # Go through and autoreview the current version of every page... |
33 | | - foreach( $res as $row ) { |
34 | | - $title = Title::makeTitle( $row->page_namespace, $row->page_title ); |
35 | | - $rev = Revision::newFromId( $row->page_latest ); |
36 | | - # Is it already reviewed? |
37 | | - $frev = FlaggedRevision::newFromTitle( $title, $row->page_latest, FR_MASTER ); |
38 | | - # Should exist, but to be safe... |
39 | | - if( !$frev && $rev && FlaggedRevs::inReviewNamespace( $title ) ) { |
40 | | - $article = new Article( $title ); |
41 | | - $db->begin(); |
42 | | - FlaggedRevs::autoReviewEdit( $article, $user, $rev, $flags, true ); |
43 | | - FlaggedRevs::HTMLCacheUpdates( $article->getTitle() ); |
44 | | - $db->commit(); |
45 | | - $changed++; |
46 | | - } |
47 | | - $count++; |
48 | | - } |
49 | | - $db->freeResult( $res ); |
50 | | - $blockStart += $BATCH_SIZE - 1; |
51 | | - $blockEnd += $BATCH_SIZE - 1; |
52 | | - wfWaitForSlaves( 5 ); |
53 | | - } |
54 | | - echo "Auto-reviewing of all pages complete ... {$count} rows [{$changed} changed]\n"; |
55 | | -} |
56 | | - |
Index: trunk/extensions/FlaggedRevs/maintenance/reviewAllPages.php |
— | — | @@ -1,29 +1,99 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | +/** |
| 4 | + * @ingroup Maintenance |
| 5 | + */ |
4 | 6 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
5 | | - $IP = getenv( 'MW_INSTALL_PATH' ); |
| 7 | + $IP = getenv( 'MW_INSTALL_PATH' ); |
6 | 8 | } else { |
7 | | - $IP = dirname(__FILE__).'/../../..'; |
| 9 | + $IP = dirname(__FILE__).'/../../..'; |
8 | 10 | } |
9 | | -require "$IP/maintenance/commandLine.inc"; |
10 | | -require dirname(__FILE__) . '/reviewAllPages.inc'; |
11 | 11 | |
12 | | -if( isset($options['help']) || !isset($args[0]) || !$args[0] ) { |
13 | | - echo <<<TEXT |
14 | | -Usage: |
15 | | - php reviewAllPages.php --help |
16 | | - php reviewAllPages.php <user ID> |
| 12 | +require_once( "$IP/maintenance/Maintenance.php" ); |
17 | 13 | |
18 | | - --help : This help message |
19 | | - --<userid> : The ID of the existing user to use as the "reviewer" (you can find your ID at Special:Preferences) |
| 14 | +class ReviewAllPages extends Maintenance { |
20 | 15 | |
21 | | -TEXT; |
22 | | - exit(0); |
23 | | -} |
| 16 | + public function __construct() { |
| 17 | + parent::__construct(); |
| 18 | + $this->mDescription = "Review all pages in reviewable namespaces. " . |
| 19 | + "A user ID must be given to specifiy the \"reviewer\" who accepted the pages."; |
| 20 | + $this->addOption( 'username', |
| 21 | + 'The user name of the existing user to use as the "reviewer"', true, true ); |
| 22 | + $this->setBatchSize( 100 ); |
| 23 | + } |
24 | 24 | |
25 | | -error_reporting( E_ALL ); |
| 25 | + public function execute() { |
| 26 | + $user = User::newFromName( $this->getOption( 'username' ) ); |
| 27 | + $this->autoreview_current( $user ); |
| 28 | + } |
26 | 29 | |
27 | | -$db = wfGetDB( DB_MASTER ); |
28 | | -$user = User::newFromId( intval($args[0]) ); |
| 30 | + protected function autoreview_current( User $user ) { |
| 31 | + $this->output( "Auto-reviewing all current page versions...\n" ); |
| 32 | + if ( !$user->getID() ) { |
| 33 | + $this->output( "Invalid user specified." ); |
| 34 | + return; |
| 35 | + } elseif ( !$user->isAllowed( 'review' ) ) { |
| 36 | + $this->output( "User specified does not have \"review\" rights." ); |
| 37 | + return; |
| 38 | + } |
29 | 39 | |
30 | | -autoreview_current( $user, $db ); |
| 40 | + $db = wfGetDB( DB_MASTER ); |
| 41 | + |
| 42 | + $this->output( "Reviewer username: " . $user->getName() . "\n" ); |
| 43 | + |
| 44 | + $start = $db->selectField( 'page', 'MIN(page_id)', false, __METHOD__ ); |
| 45 | + $end = $db->selectField( 'page', 'MAX(page_id)', false, __METHOD__ ); |
| 46 | + if ( is_null( $start ) || is_null( $end ) ) { |
| 47 | + $this->output( "...page table seems to be empty.\n" ); |
| 48 | + return; |
| 49 | + } |
| 50 | + # Do remaining chunk |
| 51 | + $end += $this->mBatchSize - 1; |
| 52 | + $blockStart = $start; |
| 53 | + $blockEnd = $start + $this->mBatchSize - 1; |
| 54 | + $count = 0; |
| 55 | + $changed = 0; |
| 56 | + $flags = FlaggedRevs::quickTags( FR_CHECKED ); // Assume basic level |
| 57 | + |
| 58 | + while ( $blockEnd <= $end ) { |
| 59 | + $this->output( "...doing page_id from $blockStart to $blockEnd\n" ); |
| 60 | + $res = $db->select( array( 'page', 'revision' ), |
| 61 | + '*', |
| 62 | + array( "page_id BETWEEN $blockStart AND $blockEnd", |
| 63 | + 'page_namespace' => FlaggedRevs::getReviewNamespaces(), |
| 64 | + 'rev_id = page_latest' ), |
| 65 | + __METHOD__ |
| 66 | + ); |
| 67 | + # Go through and autoreview the current version of every page... |
| 68 | + foreach ( $res as $row ) { |
| 69 | + $title = Title::newFromRow( $row ); |
| 70 | + $rev = Revision::newFromRow( $row ); |
| 71 | + # Is it already reviewed? |
| 72 | + $frev = FlaggedRevision::newFromTitle( $title, $row->page_latest, FR_MASTER ); |
| 73 | + # Rev should exist, but to be safe... |
| 74 | + if ( !$frev && $rev ) { |
| 75 | + $article = new Article( $title ); |
| 76 | + $db->begin(); |
| 77 | + FlaggedRevs::autoReviewEdit( $article, $user, $rev, $flags, true ); |
| 78 | + FlaggedRevs::HTMLCacheUpdates( $article->getTitle() ); |
| 79 | + $db->commit(); |
| 80 | + $changed++; |
| 81 | + } |
| 82 | + $count++; |
| 83 | + } |
| 84 | + $db->freeResult( $res ); |
| 85 | + $blockStart += $this->mBatchSize - 1; |
| 86 | + $blockEnd += $this->mBatchSize - 1; |
| 87 | + |
| 88 | + // XXX: Don't let deferred jobs array get absurdly large (bug 24375) |
| 89 | + DeferredUpdates::doUpdates( 'commit' ); |
| 90 | + |
| 91 | + wfWaitForSlaves( 5 ); |
| 92 | + } |
| 93 | + |
| 94 | + $this->output( "Auto-reviewing of all pages complete ..." . |
| 95 | + "{$count} rows [{$changed} changed]\n" ); |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +$maintClass = "ReviewAllPages"; |
| 100 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |