24require_once __DIR__ .
'/Maintenance.php';
40 parent::__construct();
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
46updates the category
table accordingly.
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->
fatalError(
'Please specify a valid mode: one of "pages", "subcats" or "files".' );
85 while ( ( $result = $this->
doWork() ) !==
false ) {
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->getBatchSize()} drifted rows " .
101 "greater than 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)"
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} != " . (
int)( $row->count ),
162 $affectedRows += $dbw->affectedRows();
165 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
getBatchSize()
Returns batch size.
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.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
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 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
namespace being checked & $result
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
script(document.cookie)%253c/script%253e</pre ></div > !! end !! test XSS is escaped(inline) !!input< source lang
require_once RUN_MAINTENANCE_IF_MAIN