MediaWiki
master
updateArticleCount.php
Go to the documentation of this file.
1
<?php
26
use
MediaWiki\Maintenance\Maintenance
;
27
use
MediaWiki\SiteStats\SiteStatsInit
;
28
29
// @codeCoverageIgnoreStart
30
require_once __DIR__ .
'/Maintenance.php'
;
31
// @codeCoverageIgnoreEnd
32
39
class
UpdateArticleCount
extends
Maintenance
{
40
41
public
function
__construct
() {
42
parent::__construct();
43
$this->
addDescription
(
'Count of the number of articles and update the site statistics table'
);
44
$this->
addOption
(
'update'
,
'Update the site_stats table with the new count'
);
45
$this->
addOption
(
'use-master'
,
'Count using the primary database'
);
46
}
47
48
public
function
execute
() {
49
$this->
output
(
"Counting articles..."
);
50
51
if
( $this->
hasOption
(
'use-master'
) ) {
52
$dbr = $this->
getPrimaryDB
();
53
}
else
{
54
$dbr = $this->
getDB
(
DB_REPLICA
,
'vslow'
);
55
}
56
$counter =
new
SiteStatsInit
( $dbr );
57
$result = $counter->articles();
58
59
$this->
output
(
"found {$result}.\n"
);
60
if
( $this->
hasOption
(
'update'
) ) {
61
$this->
output
(
"Updating site statistics table..."
);
62
$dbw = $this->
getPrimaryDB
();
63
$dbw->newUpdateQueryBuilder()
64
->update(
'site_stats'
)
65
->set( [
'ss_good_articles'
=> $result ] )
66
->where( [
'ss_row_id'
=> 1 ] )
67
->caller( __METHOD__ )
68
->execute();
69
$this->
output
(
"done.\n"
);
70
}
else
{
71
$this->
output
(
"To update the site statistics table, run the script "
72
.
"with the --update option.\n"
);
73
}
74
}
75
}
76
77
// @codeCoverageIgnoreStart
78
$maintClass
= UpdateArticleCount::class;
79
require_once RUN_MAINTENANCE_IF_MAIN;
80
// @codeCoverageIgnoreEnd
MediaWiki\Maintenance\Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition
Maintenance.php:78
MediaWiki\Maintenance\Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:493
MediaWiki\Maintenance\Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition
Maintenance.php:273
MediaWiki\Maintenance\Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition
Maintenance.php:1132
MediaWiki\Maintenance\Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option was set.
Definition
Maintenance.php:292
MediaWiki\Maintenance\Maintenance\getPrimaryDB
getPrimaryDB()
Definition
Maintenance.php:1165
MediaWiki\Maintenance\Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:343
MediaWiki\SiteStats\SiteStatsInit
Class designed for counting of stats.
Definition
SiteStatsInit.php:32
UpdateArticleCount
Maintenance script to provide a better count of the number of articles and update the site statistics...
Definition
updateArticleCount.php:39
UpdateArticleCount\__construct
__construct()
Default constructor.
Definition
updateArticleCount.php:41
UpdateArticleCount\execute
execute()
Do the actual work.
Definition
updateArticleCount.php:48
DB_REPLICA
const DB_REPLICA
Definition
defines.php:26
$maintClass
$maintClass
Definition
updateArticleCount.php:78
maintenance
updateArticleCount.php
Generated on Tue Feb 11 2025 18:27:41 for MediaWiki by
1.10.0