* Handle fallbacks too in extension aliases
[lhc/web/wiklou.git] / maintenance / initStats.php
index 9c1e1fa..d206c20 100644 (file)
@@ -1,34 +1,31 @@
 <?php
 
+/**
+ * Maintenance script to re-initialise or update the site statistics table
+ *
+ * @file
+ * @ingroup Maintenance
+ * @author Brion Vibber
+ * @author Rob Church <robchur@gmail.com>
+ * @licence GNU General Public Licence 2.0 or later
+ */
+$options = array( 'help', 'update', 'noviews' );
 require_once( 'commandLine.inc' );
+echo( "Refresh Site Statistics\n\n" );
 
-$dbr =& wfGetDB( DB_SLAVE );
-
-$edits = $dbr->selectField( 'revision', 'COUNT(rev_id)', '' );
-$pages = $dbr->selectField( 'page', 'COUNT(page_id)',
-       array(
-               'page_namespace' => 0,
-               'page_is_redirect' => 0,
-               'page_len > 0',
-       )
-); // HACK APPROXIMATION
+if( isset( $options['help'] ) ) {
+       showHelp();
+       exit();
+}
 
-echo "$wgDBname: setting edits $edits, pages $pages\n";
+require "$IP/maintenance/initStats.inc";
+wfInitStats( $options );
 
-$dbw =& wfGetDB( DB_MASTER );
-if( isset( $options['update'] ) ) {
-       echo "(updating...)\n";
-       $dbw->update( 'site_stats',
-               array( 'ss_total_edits'   => $edits,
-                      'ss_good_articles' => $pages ),
-               array( 'ss_row_id' => 1 ) );
-} else {
-       $dbw->delete( 'site_stats', array( 'ss_row_id' => 1 ) );
-       $dbw->insert( 'site_stats',
-               array( 'ss_row_id'=> 1,
-                      'ss_total_views'   => 0,
-                      'ss_total_edits'   => $edits,
-                      'ss_good_articles' => $pages ) );
+function showHelp() {
+       echo( "Re-initialise the site statistics tables.\n\n" );
+       echo( "Usage: php initStats.php [--update|--noviews]\n\n" );
+       echo( " --update : Update the existing statistics (preserves the ss_total_views field)\n" );
+       echo( "--noviews : Don't update the page view counter\n\n" );
 }
 
-?>
\ No newline at end of file