3 * This script will refresh the cat_pages, cat_subcats and cat_files fields of
4 * the category table, which may be incorrect if the wiki ran the corrupted
5 * version of Article::doDeleteArticle (r40912 --> r47326); see explanation at
6 * [https://bugzilla.wikimedia.org/show_bug.cgi?id=17155]. It will print out
7 * progress indicators every 1000 categories it updates. You may want to use the
8 * throttling options if it's causing too much load; they will not affect
11 * If the script is stopped and later resumed, you can use the --start option
12 * with the last printed progress indicator to pick up where you left off.
13 * This is safe, because any newly-added categories will be added at the end of
17 * @ingroup Maintenance
18 * @author Happy-melon, Max Semenik
19 * Based on /maintenance/populateCategory.php by Simetrical.
22 require_once( dirname( __FILE__
) . '/Maintenance.php' );
24 class RefreshCategoryCounts
extends Maintenance
{
25 const REPORTING_INTERVAL
= 1000;
27 public function __construct() {
28 $this->mDescription
= 'Refreshes category counts';
29 $this->addOption( 'start', 'Start from this category ID', false, true );
30 $this->addOption( 'maxlag', 'Maximum database slave lag in seconds (5 by default)', false, true );
31 $this->addOption( 'throttle', 'Optional delay after every processed category in milliseconds',
35 public function execute() {
36 $start = intval( $this->getOption( 'start', 0 ) );
37 $maxlag = intval( $this->getOption( 'maxlag', 5 ) );
38 $throttle = intval( $this->getOption( 'throttle', 0 ) );
40 $this->doRefresh( $start, $maxlag, $throttle );
43 protected function doRefresh( $start, $maxlag, $throttle ) {
44 $dbw = wfGetDB( DB_MASTER
);
46 $maxlag = intval( $maxlag );
47 $throttle = intval( $throttle );
52 # Find which category to update
53 $row = $dbw->selectRow(
55 array( 'cat_id', 'cat_title' ),
56 'cat_id > ' . $dbw->addQuotes( $id ),
58 array( 'ORDER BY' => 'cat_id' )
65 $name = $row->cat_title
;
67 # Use the row to update the category count
68 $cat = Category
::newFromName( $name );
69 if ( !is_object( $cat ) ) {
70 $this->output( "Invalid category name '$name'\n" );
72 $cat->refreshCounts();
76 if ( !( $i % self
::REPORTING_INTERVAL
) ) {
77 $this->output( "$id\n" );
78 wfWaitForSlaves( $maxlag );
80 usleep( $throttle * 1000 );
85 array( 'ul_key' => 'refresh catgory counts' ),
90 $this->output( "Category count refresh complete.\n" );
93 $this->output( "Could not insert category population row.\n" );
96 $this->output( "Category count refresh complete.\n" );
100 $maintClass = "RefreshCategoryCounts";
101 require_once( DO_MAINTENANCE
);