2006-07-02 21:35:25 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-09-03 18:10:09 +00:00
|
|
|
* Provide a better count of the number of articles
|
|
|
|
|
* and update the site statistics table, if desired.
|
2006-07-02 21:35:25 +00:00
|
|
|
*
|
2009-08-02 19:35:17 +00:00
|
|
|
* 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
|
|
|
|
|
*
|
2010-09-01 19:36:18 +00:00
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
2006-07-02 21:35:25 +00:00
|
|
|
* @author Rob Church <robchur@gmail.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2023-04-26 23:16:29 +00:00
|
|
|
use MediaWiki\SiteStats\SiteStatsInit;
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2006-07-02 21:35:25 +00:00
|
|
|
|
2012-09-03 18:10:09 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to provide a better count of the number of articles
|
|
|
|
|
* and update the site statistics table, if desired.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class UpdateArticleCount extends Maintenance {
|
|
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Count of the number of articles and update the site statistics table' );
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->addOption( 'update', 'Update the site_stats table with the new count' );
|
2021-05-14 20:04:02 +00:00
|
|
|
$this->addOption( 'use-master', 'Count using the primary database' );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
$this->output( "Counting articles..." );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2014-12-09 14:50:56 +00:00
|
|
|
if ( $this->hasOption( 'use-master' ) ) {
|
2024-01-17 18:53:40 +00:00
|
|
|
$dbr = $this->getPrimaryDB();
|
2014-12-09 14:50:56 +00:00
|
|
|
} else {
|
2016-09-05 19:55:19 +00:00
|
|
|
$dbr = $this->getDB( DB_REPLICA, 'vslow' );
|
2014-12-09 14:50:56 +00:00
|
|
|
}
|
|
|
|
|
$counter = new SiteStatsInit( $dbr );
|
2011-04-20 11:58:00 +00:00
|
|
|
$result = $counter->articles();
|
|
|
|
|
|
|
|
|
|
$this->output( "found {$result}.\n" );
|
|
|
|
|
if ( $this->hasOption( 'update' ) ) {
|
2021-07-21 16:34:05 +00:00
|
|
|
$this->output( "Updating site statistics table..." );
|
2024-01-17 18:53:40 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2024-04-14 18:36:13 +00:00
|
|
|
$dbw->newUpdateQueryBuilder()
|
|
|
|
|
->update( 'site_stats' )
|
|
|
|
|
->set( [ 'ss_good_articles' => $result ] )
|
|
|
|
|
->where( [ 'ss_row_id' => 1 ] )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->execute();
|
2011-04-20 11:58:00 +00:00
|
|
|
$this->output( "done.\n" );
|
2009-08-02 19:35:17 +00:00
|
|
|
} else {
|
2014-04-22 20:55:25 +00:00
|
|
|
$this->output( "To update the site statistics table, run the script "
|
|
|
|
|
. "with the --update option.\n" );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-07-02 21:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = UpdateArticleCount::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|