MediaWiki
master
updateArticleCount.php
Go to the documentation of this file.
1
<?php
12
use
MediaWiki\Maintenance\Maintenance
;
13
use
MediaWiki\SiteStats\SiteStatsInit
;
14
15
// @codeCoverageIgnoreStart
16
require_once __DIR__ .
'/Maintenance.php'
;
17
// @codeCoverageIgnoreEnd
18
25
class
UpdateArticleCount
extends
Maintenance
{
26
27
public
function
__construct
() {
28
parent::__construct();
29
$this->
addDescription
(
'Count of the number of articles and update the site statistics table'
);
30
$this->
addOption
(
'update'
,
'Update the site_stats table with the new count'
);
31
$this->
addOption
(
'use-master'
,
'Count using the primary database'
);
32
}
33
34
public
function
execute
() {
35
$this->
output
(
"Counting articles..."
);
36
37
if
( $this->
hasOption
(
'use-master'
) ) {
38
$dbr = $this->
getPrimaryDB
();
39
}
else
{
40
$dbr = $this->
getDB
(
DB_REPLICA
,
'vslow'
);
41
}
42
$counter =
new
SiteStatsInit
( $dbr );
43
$result = $counter->articles();
44
45
$this->
output
(
"found {$result}.\n"
);
46
if
( $this->
hasOption
(
'update'
) ) {
47
$this->
output
(
"Updating site statistics table..."
);
48
$dbw = $this->
getPrimaryDB
();
49
$dbw->newUpdateQueryBuilder()
50
->update(
'site_stats'
)
51
->set( [
'ss_good_articles'
=> $result ] )
52
->where( [
'ss_row_id'
=> 1 ] )
53
->caller( __METHOD__ )
54
->execute();
55
$this->
output
(
"done.\n"
);
56
}
else
{
57
$this->
output
(
"To update the site statistics table, run the script "
58
.
"with the --update option.\n"
);
59
}
60
}
61
}
62
63
// @codeCoverageIgnoreStart
64
$maintClass
= UpdateArticleCount::class;
65
require_once RUN_MAINTENANCE_IF_MAIN;
66
// @codeCoverageIgnoreEnd
DB_REPLICA
const DB_REPLICA
Definition
defines.php:26
MediaWiki\Maintenance\Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition
Maintenance.php:65
MediaWiki\Maintenance\Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:486
MediaWiki\Maintenance\Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition
Maintenance.php:266
MediaWiki\Maintenance\Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition
Maintenance.php:1117
MediaWiki\Maintenance\Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option was set.
Definition
Maintenance.php:285
MediaWiki\Maintenance\Maintenance\getPrimaryDB
getPrimaryDB(string|false $virtualDomain=false)
Definition
Maintenance.php:1151
MediaWiki\Maintenance\Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:336
MediaWiki\SiteStats\SiteStatsInit
Class designed for counting of stats.
Definition
SiteStatsInit.php:19
UpdateArticleCount
Maintenance script to provide a better count of the number of articles and update the site statistics...
Definition
updateArticleCount.php:25
UpdateArticleCount\__construct
__construct()
Default constructor.
Definition
updateArticleCount.php:27
UpdateArticleCount\execute
execute()
Do the actual work.
Definition
updateArticleCount.php:34
$maintClass
$maintClass
Definition
updateArticleCount.php:64
maintenance
updateArticleCount.php
Generated on Wed Feb 18 2026 00:28:44 for MediaWiki by
1.10.0