24 require_once __DIR__ .
'/Maintenance.php';
38 parent::__construct();
40 'Convert from the old links schema (string->ID) to the new schema (ID->ID). '
41 .
'The wiki should be put into read-only mode while this script executes' );
43 $this->
addArg(
'logperformance',
"Log performance to perfLogFilename.",
false );
46 "Filename where performance is logged if --logperformance was set "
47 .
"(defaults to 'convLinksPerf.txt').",
52 "Don't overwrite the old links table with the new one, leave the new table at links_temp.",
58 "Don't create keys, and so allow duplicates in the new links table.\n"
59 .
"This gives a huge speed improvement for very large links tables which are MyISAM.",
71 $type = $dbw->getType();
72 if (
$type !=
'mysql' ) {
73 $this->
output(
"Link table conversion not necessary for $type\n" );
81 $numBadLinks = $curRowsRead = 0;
83 # total tuples INSERTed into links_temp
84 $totalTuplesInserted = 0;
86 # whether or not to give progress reports while reading IDs from cur table
87 $reportCurReadProgress =
true;
89 # number of rows between progress reports
90 $curReadReportInterval = 1000;
92 # whether or not to give progress reports during conversion
93 $reportLinksConvProgress =
true;
95 # number of rows per INSERT
96 $linksConvInsertInterval = 1000;
98 $initialRowOffset = 0;
100 # not used yet; highest row number from links table to process
101 # $finalRowOffset = 0;
103 $overwriteLinksTable = !$this->
hasOption(
'keep-links-table' );
105 $this->logPerformance = $this->
hasOption(
'logperformance' );
106 $perfLogFilename = $this->
getArg(
'perfLogFilename',
"convLinksPerf.txt" );
108 # --------------------------------------------------------------------
110 list( $cur, $links, $links_temp, $links_backup ) =
111 $dbw->tableNamesN(
'cur',
'links',
'links_temp',
'links_backup' );
113 if ( $dbw->tableExists(
'pagelinks' ) ) {
114 $this->
output(
"...have pagelinks; skipping old links table updates\n" );
119 $res = $dbw->query(
"SELECT l_from FROM $links LIMIT 1" );
120 if ( $dbw->fieldType(
$res, 0 ) ==
"int" ) {
121 $this->
output(
"Schema already converted\n" );
126 $res = $dbw->query(
"SELECT COUNT(*) AS count FROM $links" );
127 $row = $dbw->fetchObject(
$res );
128 $numRows = $row->count;
129 $dbw->freeResult(
$res );
131 if ( $numRows == 0 ) {
132 $this->
output(
"Updating schema (no rows to convert)...\n" );
136 if ( $this->logPerformance ) {
137 $fh = fopen( $perfLogFilename,
"w" );
139 $this->
error(
"Couldn't open $perfLogFilename" );
140 $this->logPerformance =
false;
143 $baseTime = $startTime = microtime(
true );
144 # Create a title -> cur_id map
145 $this->
output(
"Loading IDs from $cur table...\n" );
146 $this->
performanceLog( $fh,
"Reading $numRows rows from cur table...\n" );
149 $dbw->bufferResults(
false );
150 $res = $dbw->query(
"SELECT cur_namespace,cur_title,cur_id FROM $cur" );
153 foreach (
$res as $row ) {
155 if ( $row->cur_namespace ) {
156 $title = $wgContLang->getNsText( $row->cur_namespace ) .
":$title";
158 $ids[
$title] = $row->cur_id;
160 if ( $reportCurReadProgress ) {
161 if ( ( $curRowsRead % $curReadReportInterval ) == 0 ) {
164 $curRowsRead .
" " . ( microtime(
true ) - $baseTime ) .
"\n"
166 $this->
output(
"\t$curRowsRead rows of $cur table read.\n" );
170 $dbw->freeResult(
$res );
171 $dbw->bufferResults(
true );
172 $this->
output(
"Finished loading IDs.\n\n" );
175 "Took " . ( microtime(
true ) - $baseTime ) .
" seconds to load IDs.\n\n"
178 # --------------------------------------------------------------------
180 # Now, step through the links table (in chunks of $linksConvInsertInterval rows),
181 # convert, and write to the new table.
184 $baseTime = microtime(
true );
185 $this->
output(
"Processing $numRows rows from $links table...\n" );
186 $this->
performanceLog( $fh,
"Processing $numRows rows from $links table...\n" );
187 $this->
performanceLog( $fh,
"rows inserted vs seconds elapsed:\n" );
189 for ( $rowOffset = $initialRowOffset; $rowOffset < $numRows;
190 $rowOffset += $linksConvInsertInterval
192 $sqlRead =
"SELECT * FROM $links ";
193 $sqlRead = $dbw->limitResult( $sqlRead, $linksConvInsertInterval, $rowOffset );
194 $res = $dbw->query( $sqlRead );
196 $sqlWrite = [
"INSERT INTO $links_temp (l_from,l_to) VALUES " ];
198 $sqlWrite = [
"INSERT IGNORE INTO $links_temp (l_from,l_to) VALUES " ];
201 $tuplesAdded = 0; # no tuples added to INSERT yet
202 foreach (
$res as $row ) {
203 $fromTitle = $row->l_from;
204 if ( array_key_exists( $fromTitle, $ids ) ) { # valid
title
205 $from = $ids[$fromTitle];
207 if ( $tuplesAdded != 0 ) {
210 $sqlWrite[] =
"($from,$to)";
212 }
else { # invalid
title
216 $dbw->freeResult(
$res );
217 # $this->output( "rowOffset: $rowOffset\ttuplesAdded: "
218 # . "$tuplesAdded\tnumBadLinks: $numBadLinks\n" );
219 if ( $tuplesAdded != 0 ) {
220 if ( $reportLinksConvProgress ) {
221 $this->
output(
"Inserting $tuplesAdded tuples into $links_temp..." );
223 $dbw->query( implode(
"", $sqlWrite ) );
224 $totalTuplesInserted += $tuplesAdded;
225 if ( $reportLinksConvProgress ) {
226 $this->
output(
" done. Total $totalTuplesInserted tuples inserted.\n" );
229 $totalTuplesInserted .
" " . ( microtime(
true ) - $baseTime ) .
"\n"
234 $this->
output(
"$totalTuplesInserted valid titles and "
235 .
"$numBadLinks invalid titles were processed.\n\n" );
238 "$totalTuplesInserted valid titles and $numBadLinks invalid titles were processed.\n"
242 "Total execution time: " . ( microtime(
true ) - $startTime ) .
" seconds.\n"
244 if ( $this->logPerformance ) {
248 # --------------------------------------------------------------------
250 if ( $overwriteLinksTable ) {
251 # Check for existing links_backup, and delete it if it exists.
252 $this->
output(
"Dropping backup links table if it exists..." );
253 $dbw->query(
"DROP TABLE IF EXISTS $links_backup", __METHOD__ );
254 $this->
output(
" done.\n" );
256 # Swap in the new table, and move old links table to links_backup
257 $this->
output(
"Swapping tables '$links' to '$links_backup'; '$links_temp' to '$links'..." );
258 $dbw->query(
"RENAME TABLE links TO $links_backup, $links_temp TO $links", __METHOD__ );
259 $this->
output(
" done.\n\n" );
261 $this->
output(
"Conversion complete. The old table remains at $links_backup;\n" );
262 $this->
output(
"delete at your leisure.\n" );
264 $this->
output(
"Conversion complete. The converted table is at $links_temp;\n" );
265 $this->
output(
"the original links table is unchanged.\n" );
272 if ( !( $dbConn->isOpen() ) ) {
273 $this->
output(
"Opening connection to database failed.\n" );
277 $links_temp = $dbConn->tableName(
'links_temp' );
279 $this->
output(
"Dropping temporary links table if it exists..." );
280 $dbConn->query(
"DROP TABLE IF EXISTS $links_temp" );
281 $this->
output(
" done.\n" );
283 $this->
output(
"Creating temporary links table..." );
285 $dbConn->query(
"CREATE TABLE $links_temp ( " .
286 "l_from int(8) unsigned NOT NULL default '0', " .
287 "l_to int(8) unsigned NOT NULL default '0')" );
289 $dbConn->query(
"CREATE TABLE $links_temp ( " .
290 "l_from int(8) unsigned NOT NULL default '0', " .
291 "l_to int(8) unsigned NOT NULL default '0', " .
292 "UNIQUE KEY l_from(l_from,l_to), " .
295 $this->
output(
" done.\n\n" );
299 if ( $this->logPerformance ) {
300 fwrite( $fh, $text );
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 list
addArg($arg, $description, $required=true)
Add some args that are needed.
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.
require_once RUN_MAINTENANCE_IF_MAIN
when a variable name is used in a it is silently declared as a new local masking the global
namespace and then decline to actually register it file or subcat img or subcat $title
performanceLog($fh, $text)
addDescription($text)
Set the description text.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
output($out, $channel=null)
Throw some output to the user.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Maintenance script to convert from the old links schema (string->ID) to the new schema (ID->ID)...
error($err, $die=0)
Throw an error to the user.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
getArg($argId=0, $default=null)
Get an argument.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type