* Introduce updateArticleCount maintenance script which uses a better check that...
authorRob Church <robchurch@users.mediawiki.org>
Sun, 2 Jul 2006 21:35:25 +0000 (21:35 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Sun, 2 Jul 2006 21:35:25 +0000 (21:35 +0000)
RELEASE-NOTES
maintenance/updateArticleCount.inc.php [new file with mode: 0644]
maintenance/updateArticleCount.php [new file with mode: 0644]

index d9a94bd..809e00b 100644 (file)
@@ -630,6 +630,8 @@ Some default configuration options have changed:
 * (bug 6516) Update to Russian translation
 * New 'allpagesbadtitle' message for Special:Allpages, based on 'badtitletext'.
 * Rename "searchquery" to "searchsubtitle" and support wiki text in it
+* Introduce updateArticleCount maintenance script which uses a better check that
+  reflects what Article::isCountable() tests for
 
 == Compatibility ==
 
diff --git a/maintenance/updateArticleCount.inc.php b/maintenance/updateArticleCount.inc.php
new file mode 100644 (file)
index 0000000..20546a7
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ * Support class for the updateArticleCount.php maintenance script
+ *
+ * @package MediaWiki
+ * @subpackage Maintenance
+ * @author Rob Church <robchur@gmail.com>
+ */
+
+class ArticleCounter {
+
+       var $dbr;
+       var $namespaces;
+       
+       function ArticleCounter() {
+               global $wgContentNamespaces;
+               $this->namespaces = $wgContentNamespaces;
+               $this->dbr =& wfGetDB( DB_SLAVE );
+       }
+       
+       /**
+        * Produce a comma-delimited set of namespaces
+        * Includes paranoia
+        *
+        * @return string
+        */
+       function makeNsSet() {
+               foreach( $this->namespaces as $namespace )
+                       $namespaces[] = intval( $namespace );
+               return implode( ', ', $namespaces );
+       }
+       
+       /**
+        * Produce SQL for the query
+        *
+        * @return string
+        */
+       function makeSql() {
+               extract( $this->dbr->tableNames( 'page', 'pagelinks' ) );
+               $nsset = $this->makeNsSet();
+               return "SELECT COUNT(*) AS count FROM {$page}
+                               LEFT JOIN {$pagelinks} ON pl_from = page_id
+                               WHERE page_namespace IN ( $nsset )
+                               AND page_is_redirect = 0
+                               AND page_len > 0
+                               AND pl_namespace IS NOT NULL";
+       }
+       
+       /**
+        * Count the number of valid content pages in the wiki
+        *
+        * @return mixed Integer, or false if there's a problem
+        */
+       function count() {
+               $res = $this->dbr->query( $this->makeSql(), __METHOD__ );
+               if( $res ) {
+                       $row = $this->dbr->fetchObject( $res );
+                       $this->dbr->freeResult( $res );
+                       return (int)$row->count;
+               } else {
+                       return false; # Look out for this when handling the result
+               }
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/maintenance/updateArticleCount.php b/maintenance/updateArticleCount.php
new file mode 100644 (file)
index 0000000..112274d
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * Maintenance script to provide a better count of the number of articles
+ * and update the site statistics table, if desired
+ *
+ * @package MediaWiki
+ * @subpackage Maintenance
+ * @author Rob Church <robchur@gmail.com>
+ */
+
+$options = array( 'update', 'help' );
+require_once( 'commandLine.inc' );
+require_once( 'updateArticleCount.inc.php' );
+echo( "Update Article Count\n\n" );
+
+if( isset( $options['help'] ) && $options['help'] ) {
+       echo( "Usage: php updateArticleCount.php [--update]\n\n" );
+       echo( "--update : Update site statistics table\n" );
+       exit( 0 );
+}
+
+echo( "Counting articles..." );
+$counter = new ArticleCounter();
+$result = $counter->count();
+
+if( $result !== false ) {
+       echo( "found {$result}.\n" );
+       if( isset( $options['update'] ) && $options['update'] ) {
+               echo( "Updating site statistics table... " );
+               $dbw =& wfGetDB( DB_MASTER );
+               $dbw->update( 'site_stats', array( 'ss_good_articles' => $result ), array( 'ss_row_id' => 1 ), __METHOD__ );
+               echo( "done.\n" );
+       } else {
+               echo( "To update the site statistics table, run the script with the --update option.\n" );
+       }
+} else {
+       echo( "failed.\n" );
+}
+echo( "\n" );
+
+?>
\ No newline at end of file