(bug 18488) Added maintenance script refreshCategoryCounts.php. Based on Happy-Mellon...
authorMax Semenik <maxsem@users.mediawiki.org>
Mon, 10 May 2010 15:47:45 +0000 (15:47 +0000)
committerMax Semenik <maxsem@users.mediawiki.org>
Mon, 10 May 2010 15:47:45 +0000 (15:47 +0000)
RELEASE-NOTES
maintenance/refreshCategoryCounts.php [new file with mode: 0644]

index 03b9392..f3b92d6 100644 (file)
@@ -71,6 +71,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 20976) "searchmenu-new-nocreate" message now displayed when when there
   is no title match in search and the user has no rights to create pages.
 * (bug 23429) Added new hook WatchlistEditorBuildRemoveLine
+* (bug 18488) Added maintenance script refreshCategoryCounts.php
 
 === Bug fixes in 1.17 ===
 * (bug 17560) Half-broken deletion moved image files to deletion archive
diff --git a/maintenance/refreshCategoryCounts.php b/maintenance/refreshCategoryCounts.php
new file mode 100644 (file)
index 0000000..5116302
--- /dev/null
@@ -0,0 +1,102 @@
+<?php
+/**
+ * This script will refresh the cat_pages, cat_subcats and cat_files fields of
+ * the category table, which may be incorrect if the wiki ran the corrupted
+ * version of Article::doDeleteArticle (r40912 --> r47326); see explanation at
+ * [https://bugzilla.wikimedia.org/show_bug.cgi?id=17155].  It will print out 
+ * progress indicators every 1000 categories it updates. You may want to use the
+ * throttling options if it's causing too much load; they will not affect 
+ * correctness.
+ *
+ * If the script is stopped and later resumed, you can use the --start option 
+ * with the last printed progress indicator to pick up where you left off. 
+ * This is safe, because any newly-added categories will  be added at the end of
+ * the table.
+ *
+ * @file 
+ * @ingroup Maintenance
+ * @author Happy-melon, Max Semenik
+ * Based on /maintenance/populateCategory.php by Simetrical.
+ */
+
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+
+class RefreshCategoryCounts extends Maintenance {
+       const REPORTING_INTERVAL = 1000;
+
+       public function __construct() {
+               $this->mDescription = 'Refreshes category counts';
+               $this->addOption( 'start', 'Start from this category ID', false, true );
+               $this->addOption( 'maxlag', 'Maximum database slave lag in seconds (5 by default)', false, true );
+               $this->addOption( 'throttle', 'Optional delay after every processed category in milliseconds',
+                       false, true );
+       }
+       
+       public function execute() {
+               $start = intval( $this->getOption( 'start', 0 ) );
+               $maxlag = intval( $this->getOption( 'maxlag', 5 ) );
+               $throttle = intval( $this->getOption( 'throttle', 0 ) );
+
+               $this->doRefresh( $start, $maxlag, $throttle );
+       }
+
+       protected function doRefresh( $start, $maxlag, $throttle ) {
+               $dbw = wfGetDB( DB_MASTER );
+
+               $maxlag = intval( $maxlag );
+               $throttle = intval( $throttle );
+               $id = $start;
+
+               $i = 0;
+               while ( true ) {
+                       # Find which category to update
+                       $row = $dbw->selectRow(
+                               'category',
+                               array( 'cat_id', 'cat_title' ),
+                               'cat_id > ' . $dbw->addQuotes( $id ),
+                               __METHOD__,
+                               array( 'ORDER BY' => 'cat_id' )
+                       );
+                       if ( !$row ) {
+                               # Done, hopefully.
+                               break;
+                       }
+                       $id    = $row->cat_id;
+                       $name  = $row->cat_title;
+
+                       # Use the row to update the category count
+                       $cat = Category::newFromName( $name );
+                       if ( !is_object( $cat ) ) {
+                               $this->output( "Invalid category name '$name'\n" );
+                       } else {
+                               $cat->refreshCounts();
+                       }
+
+                       $i++;
+                       if ( !( $i % self::REPORTING_INTERVAL ) ) {
+                               $this->output( "$id\n" );
+                               wfWaitForSlaves( $maxlag );
+                       }
+                       usleep( $throttle * 1000 );
+               }
+
+               /*if ( $dbw->insert(
+                               'updatelog',
+                               array( 'ul_key' => 'refresh catgory counts' ),
+                               __METHOD__,
+                               'IGNORE'
+                       )
+               ) {
+                       $this->output( "Category count refresh complete.\n" );
+                       return true;
+               } else {
+                       $this->output( "Could not insert category population row.\n" );
+                       return false;
+               }*/
+               $this->output( "Category count refresh complete.\n" );
+       }
+}
+
+$maintClass = "RefreshCategoryCounts";
+require_once( DO_MAINTENANCE );
+