MediaWiki REL1_33
populateCategory.php
Go to the documentation of this file.
1<?php
25require_once __DIR__ . '/Maintenance.php';
26
33
34 const REPORTING_INTERVAL = 1000;
35
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription(
39 <<<TEXT
40This script will populate the category table, added in MediaWiki 1.13. It will
41print out progress indicators every 1000 categories it adds to the table. The
42script is perfectly safe to run on large, live wikis, and running it multiple
43times is harmless. You may want to use the throttling options if it's causing
44too much load; they will not affect correctness.
45
46If the script is stopped and later resumed, you can use the --begin option with
47the last printed progress indicator to pick up where you left off. This is
48safe, because any newly-added categories before this cutoff will have been
49added after the software update and so will be populated anyway.
50
51When the script has finished, it will make a note of this in the database, and
52will not run again without the --force option.
53TEXT
54 );
55
56 $this->addOption(
57 'begin',
58 'Only do categories whose names are alphabetically after the provided name',
59 false,
60 true
61 );
62 $this->addOption(
63 'throttle',
64 'Wait this many milliseconds after each category. Default: 0',
65 false,
66 true
67 );
68 $this->addOption( 'force', 'Run regardless of whether the database says it\'s been run already' );
69 }
70
71 public function execute() {
72 $begin = $this->getOption( 'begin', '' );
73 $throttle = $this->getOption( 'throttle', 0 );
74 $force = $this->hasOption( 'force' );
75
76 $dbw = $this->getDB( DB_MASTER );
77
78 if ( !$force ) {
79 $row = $dbw->selectRow(
80 'updatelog',
81 '1',
82 [ 'ul_key' => 'populate category' ],
83 __METHOD__
84 );
85 if ( $row ) {
86 $this->output( "Category table already populated. Use php " .
87 "maintenance/populateCategory.php\n--force from the command line " .
88 "to override.\n" );
89
90 return true;
91 }
92 }
93
94 $throttle = intval( $throttle );
95 if ( $begin !== '' ) {
96 $where = [ 'cl_to > ' . $dbw->addQuotes( $begin ) ];
97 } else {
98 $where = [ '1 = 1' ];
99 }
100 $i = 0;
101
102 while ( true ) {
103 # Find which category to update
104 $row = $dbw->selectRow(
105 'categorylinks',
106 'cl_to',
107 $where,
108 __METHOD__,
109 [
110 'ORDER BY' => 'cl_to'
111 ]
112 );
113 if ( !$row ) {
114 # Done, hopefully.
115 break;
116 }
117 $name = $row->cl_to;
118 $where = 'cl_to > ' . $dbw->addQuotes( $name );
119
120 # Use the row to update the category count
121 $cat = Category::newFromName( $name );
122 if ( !is_object( $cat ) ) {
123 $this->output( "The category named $name is not valid?!\n" );
124 } else {
125 $cat->refreshCounts();
126 }
127
128 ++$i;
129 if ( !( $i % self::REPORTING_INTERVAL ) ) {
130 $this->output( "$name\n" );
132 }
133 usleep( $throttle * 1000 );
134 }
135
136 $dbw->insert(
137 'updatelog',
138 [ 'ul_key' => 'populate category' ],
139 __METHOD__,
140 'IGNORE'
141 );
142
143 return true;
144 }
145}
146
147$maintClass = PopulateCategory::class;
148require_once RUN_MAINTENANCE_IF_MAIN;
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
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
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.
hasOption( $name)
Checks to see if a particular option exists.
addDescription( $text)
Set the description text.
getOption( $name, $default=null)
Get an option, or return the default.
Maintenance script to populate the category table.
execute()
Do the actual work.
__construct()
Default constructor.
$dbw begin(__METHOD__)
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
Definition deferred.txt:16
> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) name
Definition hooks.txt:1850
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing options(say) and put it in one place. Instead of having little title-reversing if-blocks spread all over the codebase in showAnArticle
while(( $__line=Maintenance::readconsole()) !==false) print
Definition eval.php:64
script(document.cookie)%253c/script%253e</pre ></div > !! end !! test XSS is escaped(inline) !!input< source lang
require_once RUN_MAINTENANCE_IF_MAIN
A helper class for throttling authentication attempts.
const DB_MASTER
Definition defines.php:26