24require_once __DIR__ .
'/Maintenance.php';
37 [
'redirect',
'rd',
'idField' =>
'rd_from' ],
40 [
'protected_titles',
'pt',
'idField' => 0 ],
41 [
'category',
'cat',
'nsField' => 14 ],
42 [
'recentchanges',
'rc' ],
43 [
'watchlist',
'wl' ],
48 [
'pagelinks',
'pl',
'idField' =>
'pl_from' ],
49 [
'templatelinks',
'tl',
'idField' =>
'tl_from' ],
50 [
'categorylinks',
'cl',
'idField' =>
'cl_from',
'nsField' => 14,
'titleField' =>
'cl_to' ],
54 parent::__construct();
56This script cleans up the title fields in various tables to
remove entries that
57will be rejected by the constructor of
TitleValue. This constructor
throws an
58exception when invalid data is encountered, which will not normally
occur on
59regular page views, but can happen on query special
pages.
61The script targets titles matching the regular expression /^_|[ \r\n\t]|_$/.
62Because any foreign
key relationships involving these titles will already be
63broken, the titles are corrected to a valid
version or the rows are deleted
66The script
runs with the expectation that STDOUT is redirected to a file.
69 $this->
addOption(
'fix',
'Actually clean up invalid titles. If this parameter is ' .
70 'not specified, the script will report invalid titles but not clean them up.',
72 $this->
addOption(
'table',
'The table(s) to process. This option can be specified ' .
73 'more than once (e.g. -t category -t watchlist). If not specified, all available ' .
74 'tables will be processed. Available tables are: ' .
75 implode(
', ', array_column( static::$tables, 0 ) ),
false,
true,
't',
true );
81 $tablesToProcess = $this->
getOption(
'table' );
82 foreach ( static::$tables as $tableParams ) {
83 if ( !$tablesToProcess || in_array( $tableParams[0], $tablesToProcess ) ) {
103 if ( trim( $str ) ) {
104 fwrite( STDOUT,
'*** ' . trim( $str ) .
"\n" );
106 fwrite( STDERR, $str );
115 fwrite( STDOUT, $str );
124 $table = $tableParams[0];
125 $prefix = $tableParams[1];
126 $idField = isset( $tableParams[
'idField'] ) ?
127 $tableParams[
'idField'] :
129 $nsField = isset( $tableParams[
'nsField'] ) ?
130 $tableParams[
'nsField'] :
131 "{$prefix}_namespace";
132 $titleField = isset( $tableParams[
'titleField'] ) ?
133 $tableParams[
'titleField'] :
136 $this->
outputStatus(
"Looking for invalid $titleField entries in $table...\n" );
146 $percent =
$dbr->anyString();
152 'title' => $titleField,
156 $titleField .
$dbr->buildLike( $percent,
' ', $percent ),
157 $titleField .
$dbr->buildLike( $percent,
"\r", $percent ),
158 $titleField .
$dbr->buildLike( $percent,
"\n", $percent ),
159 $titleField .
$dbr->buildLike( $percent,
"\t", $percent ),
160 $titleField .
$dbr->buildLike(
'_', $percent ),
161 $titleField .
$dbr->buildLike( $percent,
'_' ),
164 [
'LIMIT' => $this->mBatchSize ]
168 if ( !
$res->numRows() ) {
175 $this->
writeToReport( sprintf(
"%10s | ns | dbkey\n", $idField ) );
177 foreach (
$res as $row ) {
178 $this->
writeToReport( sprintf(
"%10d | %3d | %s\n", $row->id, $row->ns, $row->title ) );
185 if ( $table ===
'logging' || $table ===
'archive' ) {
186 $this->
writeToReport(
"The following updates would be run with the --fix flag:\n" );
187 foreach (
$res as $row ) {
190 "$idField={$row->id}: update '{$row->title}' to '$newTitle'\n" );
194 if ( $table !==
'page' && $table !==
'redirect' ) {
195 $this->
outputStatus(
"Run with --fix to clean up these rows\n" );
210IMPORTANT: This script does not fix invalid entries in the $table
table.
211Consider repairing these rows, and rows in related tables, by hand.
212You may like to
run, or borrow logic
from, the cleanupTitles.php script.
225 "Updating these rows, setting $titleField to the closest valid DB key...\n" );
226 $affectedRowCount = 0;
227 foreach (
$res as $row ) {
230 "$idField={$row->id}: updating '{$row->title}' to '$newTitle'\n" );
232 $dbw->update( $table,
233 [ $titleField => $newTitle ],
234 [ $idField => $row->id ],
236 $affectedRowCount += $dbw->affectedRows();
239 $this->
outputStatus(
"Updated $affectedRowCount rows on $table.\n" );
243 case 'recentchanges':
249 $this->
outputStatus(
"Deleting invalid $table rows...\n" );
250 $dbw->delete( $table, [ $idField => $ids ], __METHOD__ );
252 $this->
outputStatus(
'Deleted ' . $dbw->affectedRows() .
" rows from $table.\n" );
255 case 'protected_titles':
259 $this->
outputStatus(
"Deleting invalid $table rows...\n" );
260 $affectedRowCount = 0;
261 foreach (
$res as $row ) {
262 $dbw->delete( $table,
263 [ $nsField => $row->ns, $titleField => $row->title ],
265 $affectedRowCount += $dbw->affectedRows();
268 $this->
outputStatus(
"Deleted $affectedRowCount rows from $table.\n" );
272 case 'templatelinks':
273 case 'categorylinks':
277 $this->
outputStatus(
"Queueing link update jobs for the pages in $idField...\n" );
278 foreach (
$res as $row ) {
284 $dbw->delete( $table,
285 [ $idField => $row->id, $nsField => $row->ns, $titleField => $row->title ],
290 $this->
outputStatus(
"Link update jobs have been added to the job queue.\n" );
305 return strtr( trim( $invalidTitle,
'_' ),
306 [
' ' =>
'_',
"\r" =>
'',
"\n" =>
'',
"\t" =>
'_' ] );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable from
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special exception
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Program or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section provided that you also meet all of these that in whole or in part contains or is derived from the Program or any part to be licensed as a whole at no charge to all third parties under the terms of this License c If the modified program normally reads commands interactively when run
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable runs
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Maintenance script that cleans up invalid titles in various tables.
static makeValidTitle( $invalidTitle)
Fix possible validation issues in the given title (DB key).
cleanupTable( $tableParams)
Identifies, and optionally cleans up, invalid titles.
outputStatus( $str, $channel=null)
Prints text to STDOUT, and STDERR if STDOUT was redirected to a file.
writeToReport( $str)
Prints text to STDOUT.
static array $tables
List of tables to clean up, and the field prefix for that table.
__construct()
Default constructor.
execute()
Do the actual work.
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.
hasOption( $name)
Checks to see if a particular param exists.
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.
static fixLinksFromArticle( $id, $ns=false)
Run LinksUpdate for all links on a given page_id.
Represents a page (or page fragment) title within MediaWiki.
static newFromID( $id, $from='fromdb')
Constructor from a page id.
The ContentHandler facility adds support for arbitrary content types on wiki pages
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 but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped broken
return true to allow those checks to occur
globals will be eliminated from MediaWiki entirely
require_once RUN_MAINTENANCE_IF_MAIN