X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FinitStats.php;h=b92d46c575ac875345092ee27eedd93dc96a1096;hb=0320dd57a0a78edd10f71d95f3ad3dc046b750a9;hp=fb5603d331649c317f61ff62e03323a9d6cf8ede;hpb=fff417fb7465cc7aef22de29b904fbb632133276;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/initStats.php b/maintenance/initStats.php index fb5603d331..b92d46c575 100644 --- a/maintenance/initStats.php +++ b/maintenance/initStats.php @@ -3,66 +3,82 @@ /** * Maintenance script to re-initialise or update the site statistics table * - * @package MediaWiki - * @subpackage Maintenance + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @ingroup Maintenance * @author Brion Vibber * @author Rob Church * @licence GNU General Public Licence 2.0 or later */ - -$options = array( 'help', 'update' ); -require_once( 'commandLine.inc' ); -echo( "Refresh Site Statistics\n\n" ); -$dbr =& wfGetDB( DB_SLAVE ); -$fname = 'initStats'; -if( isset( $options['help'] ) { - showHelp(); - exit(); -} +require_once( dirname(__FILE__) . '/Maintenance.php' ); -echo( "Counting total edits..." ); -$edits = $dbr->selectField( 'revision', 'COUNT(*)', '', $fname ); -echo( "{$edits}\nCounting number of articles..." ); +class InitStats extends Maintenance { + public function __construct() { + parent::__construct(); + $this->mDescription = "Re-initialise the site statistics tables"; + $this->addOption( 'update', 'Update the existing statistics (preserves the ss_total_views field)' ); + $this->addOption( 'noviews', "Don't update the page view counter" ); + $this->addOption( 'active', 'Also update active users count' ); + $this->addOption( 'use-master', 'Count using the master database' ); + } -$good = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => 0, 'page_is_redirect' => 0, 'page_len > 0' ), $fname ); -echo( "{$good}\nCounting total pages..." ); + public function execute() { + $this->output( "Refresh Site Statistics\n\n" ); + $counter = new SiteStatsInit( $this->hasOption( 'use-master' ) ); -$pages = $dbr->selectField( 'page', 'COUNT(*)', '', $fname ); -echo( "{$pages}\nCounting number of users..." ); + $this->output( "Counting total edits..." ); + $edits = $counter->edits(); + $this->output( "{$edits}\nCounting number of articles..." ); -$users = $dbr->selectField( 'user', 'COUNT(*)', '', $fname ); -echo( "{$users}\nCounting number of admins..." ); + $good = $counter->articles(); + $this->output( "{$good}\nCounting total pages..." ); -$admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname ); -echo( "{$admin}\nCounting number of images..." ); + $pages = $counter->pages(); + $this->output( "{$pages}\nCounting number of users..." ); -$image = $dbr->selectField( 'image', 'COUNT(*)', '', $fname ); -echo( "{$image}\n\nUpdating site statistics..." ); + $users = $counter->users(); + $this->output( "{$users}\nCounting number of images..." ); -$dbw =& wfGetDB( DB_MASTER ); -$values = array( 'ss_total_edits' => $edits, - 'ss_good_articles' => $good, - 'ss_total_pages' => $pages, - 'ss_users' => $users, - 'ss_admins' => $admin, - 'ss_images' => $image ); -$conds = array( 'ss_row_id' => 1 ); -$views = array( 'ss_total_views' => 0 ); - -if( isset( $options['update'] ) ) { - $dbw->update( 'site_stats', $values, $conds, $fname ); -} else { - $dbw->delete( 'site_stats', $conds, $fname ); - $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), $fname ); -} + $image = $counter->files(); + $this->output( "{$image}\n" ); + + if( !$this->hasOption('noviews') ) { + $this->output( "Counting total page views..." ); + $views = $counter->views(); + $this->output( "{$views}\n" ); + } + + if( $this->hasOption( 'active' ) ) { + $this->output( "Counting active users..." ); + $active = SiteStatsUpdate::cacheUpdate(); + $this->output( "{$active}\n" ); + } + + $this->output( "\nUpdating site statistics..." ); -echo( "done.\n\n" ); + if( $this->hasOption( 'update' ) ) { + $counter->update(); + } else { + $counter->refresh(); + } -function showHelp() { - echo( "Re-initialise the site statistics tables.\n\n" ); - echo( "Usage: php initStats.php [--update]\n\n" ); - echo( "--update : Update the existing statistics (preserves the ss_total_views field)\n\n" ); + $this->output( "done.\n" ); + } } -?> \ No newline at end of file +$maintClass = "InitStats"; +require_once( DO_MAINTENANCE );