ApiParse: don't reparse language link titles
[mediawiki.git] / maintenance / updateArticleCount.php
blobb60f1eb74cbac387088495af8c73171bc74139c1
1 <?php
2 /**
3 * Provide a better count of the number of articles
4 * and update the site statistics table, if desired.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
21 * @file
22 * @ingroup Maintenance
23 * @author Rob Church <robchur@gmail.com>
26 use MediaWiki\SiteStats\SiteStatsInit;
28 // @codeCoverageIgnoreStart
29 require_once __DIR__ . '/Maintenance.php';
30 // @codeCoverageIgnoreEnd
32 /**
33 * Maintenance script to provide a better count of the number of articles
34 * and update the site statistics table, if desired.
36 * @ingroup Maintenance
38 class UpdateArticleCount extends Maintenance {
40 public function __construct() {
41 parent::__construct();
42 $this->addDescription( 'Count of the number of articles and update the site statistics table' );
43 $this->addOption( 'update', 'Update the site_stats table with the new count' );
44 $this->addOption( 'use-master', 'Count using the primary database' );
47 public function execute() {
48 $this->output( "Counting articles..." );
50 if ( $this->hasOption( 'use-master' ) ) {
51 $dbr = $this->getPrimaryDB();
52 } else {
53 $dbr = $this->getDB( DB_REPLICA, 'vslow' );
55 $counter = new SiteStatsInit( $dbr );
56 $result = $counter->articles();
58 $this->output( "found {$result}.\n" );
59 if ( $this->hasOption( 'update' ) ) {
60 $this->output( "Updating site statistics table..." );
61 $dbw = $this->getPrimaryDB();
62 $dbw->newUpdateQueryBuilder()
63 ->update( 'site_stats' )
64 ->set( [ 'ss_good_articles' => $result ] )
65 ->where( [ 'ss_row_id' => 1 ] )
66 ->caller( __METHOD__ )
67 ->execute();
68 $this->output( "done.\n" );
69 } else {
70 $this->output( "To update the site statistics table, run the script "
71 . "with the --update option.\n" );
76 // @codeCoverageIgnoreStart
77 $maintClass = UpdateArticleCount::class;
78 require_once RUN_MAINTENANCE_IF_MAIN;
79 // @codeCoverageIgnoreEnd