24require_once __DIR__ .
'/Maintenance.php';
40 parent::__construct();
42This script refreshes the category membership
counts stored in the category
43table. As time passes, these
counts often drift from the actual number of
44category members. The script identifies rows where the value in the category
45table does not match the number of categorylinks rows
for that category, and
48To fully refresh the data in the category
table, you need to run
this script
49three times: once in each mode.
Alternatively, just one mode can be run
if
55 '(REQUIRED) Which category count column to recompute: "pages", "subcats" or "files".',
61 'Only recount categories with cat_id greater than the given value',
67 'Wait this many milliseconds after each batch. Default: 0',
77 if ( !in_array( $this->mode, [
'pages',
'subcats',
'files' ] ) ) {
78 $this->
error(
'Please specify a valid mode: one of "pages", "subcats" or "files".', 1 );
81 $this->minimumId = intval( $this->
getOption(
'begin', 0 ) );
85 while ( ( $result = $this->
doWork() ) !==
false ) {
87 usleep( $this->
getOption(
'throttle', 0 ) * 1000 );
90 $this->
output(
"Done! Updated the {$this->mode} counts of $affectedRows categories.\n" .
91 "Now run the script using the other --mode options if you haven't already.\n" );
92 if ( $this->mode ===
'pages' ) {
94 "Also run 'php cleanupEmptyCategories.php --mode remove' to remove empty,\n" .
95 "nonexistent categories from the category table.\n\n" );
100 $this->
output(
"Finding up to {$this->mBatchSize} drifted rows " .
101 "starting at cat_id {$this->minimumId}...\n" );
103 $countingConds = [
'cl_to = cat_title' ];
104 if ( $this->mode ===
'subcats' ) {
105 $countingConds[
'cl_type'] =
'subcat';
106 } elseif ( $this->mode ===
'files' ) {
107 $countingConds[
'cl_type'] =
'file';
111 $countingSubquery =
$dbr->selectSQLText(
'categorylinks',
120 $idsToUpdate =
$dbr->selectFieldValues(
'category',
123 'cat_id > ' . $this->minimumId,
124 "cat_{$this->mode} != ($countingSubquery)"
127 [
'LIMIT' => $this->mBatchSize ]
129 if ( !$idsToUpdate ) {
132 $this->
output(
"Updating cat_{$this->mode} field on " .
133 count( $idsToUpdate ) .
" rows...\n" );
139 $this->minimumId = end( $idsToUpdate );
143 $res = $dbw->select(
'category',
144 [
'cat_id',
'count' =>
"($countingSubquery)" ],
145 [
'cat_id' => $idsToUpdate ],
154 foreach (
$res as $row ) {
155 $dbw->update(
'category',
156 [
"cat_{$this->mode}" => $row->count ],
158 'cat_id' => $row->cat_id,
159 "cat_{$this->mode} != {$row->count}",
162 $affectedRows += $dbw->affectedRows();
165 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
167 return $affectedRows;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
setBatchSize( $s=0)
Set the batch size.
Maintenance script that refreshes category membership counts in the category table.
__construct()
Default constructor.
execute()
Do the actual work.
The ContentHandler facility adds support for arbitrary content types on wiki instead of relying on wikitext for everything It was introduced in MediaWiki Each kind of stored
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view counts
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these updates(as a Java servelet could)
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if so it s not worth the trouble Since there is a job queue in the jobs table
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
namespace being checked & $result
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
passed in as a query string parameter to the various URLs constructed here(i.e. $prevlink) $ldel you ll need to handle error etc yourself Alternatively
require_once RUN_MAINTENANCE_IF_MAIN