private function stripPath( $path ) {
$prefix = 'mediawiki.compress.7z://';
+
return substr( $path, strlen( $prefix ) );
}
return fseek( $this->stream, $offset, $whence );
}
}
+
stream_wrapper_register( 'mediawiki.compress.7z', 'SevenZipStream' );
return false; // previous calls should all be "requires"
}
}
+
return true;
}
} else {
// Set it so we don't have to provide the default again
$this->mOptions[$name] = $default;
+
return $this->mOptions[$name];
}
}
}
$input = fgets( $f, $len );
fclose( $f );
+
return rtrim( $input );
}
public function outputChanneled( $msg, $channel = null ) {
if ( $msg === false ) {
$this->cleanupChanneled();
+
return;
}
. '"max" for no limit or "default" to avoid changing it'
);
$this->addOption( 'server', "The protocol and server name to use in URLs, e.g. " .
- "http://en.wikipedia.org. This is sometimes necessary because " .
- "server name detection may fail in command line scripts.", false, true );
+ "http://en.wikipedia.org. This is sometimes necessary because " .
+ "server name detection may fail in command line scripts.", false, true );
$this->addOption( 'profiler', 'Set to "text" or "trace" to show profiling output', false, true );
# Save generic options to display them separately in help
if ( !is_null( $this->mDb ) ) {
$child->setDB( $this->mDb );
}
+
return $child;
}
# it's run again and again
if ( $this->mInputLoaded ) {
$this->loadSpecialVars();
+
return;
}
# Short options
$argLength = strlen( $arg );
for ( $p = 1; $p < $argLength; $p++ ) {
- $option = $arg { $p };
+ $option = $arg[$p];
if ( !isset( $this->mParams[$option] ) && isset( $this->mShortParamsMap[$option] ) ) {
$option = $this->mShortParamsMap[$option];
}
}
$this->output(
wordwrap( "$tab--$par: " . $info['desc'], $descWidth,
- "\n$tab$tab" ) . "\n"
+ "\n$tab$tab" ) . "\n"
);
}
$this->output( "\n" );
}
$this->output(
wordwrap( "$tab--$par: " . $info['desc'], $descWidth,
- "\n$tab$tab" ) . "\n"
+ "\n$tab$tab" ) . "\n"
);
}
$this->output( "\n" );
}
$this->output(
wordwrap( "$tab--$par: " . $info['desc'], $descWidth,
- "\n$tab$tab" ) . "\n"
+ "\n$tab$tab" ) . "\n"
);
}
$this->output( "\n" );
if ( !is_readable( $settingsFile ) ) {
$this->error( "A copy of your installation's LocalSettings.php\n" .
- "must exist and be readable in the source directory.\n" .
- "Use --conf to specify it.", true );
+ "must exist and be readable in the source directory.\n" .
+ "Use --conf to specify it.", true );
}
$wgCommandLineMode = true;
+
return $settingsFile;
}
$this->unlockSearchindex( $dbw );
$this->output( "\n" );
}
-
}
/**
$u->doUpdate();
$this->output( "\n" );
}
+
return $title;
}
return false;
}
$resp = trim( $st );
+
return $resp;
}
}
return false;
}
print $prompt;
+
return fgets( STDIN, 1024 );
}
}
*/
class FakeMaintenance extends Maintenance {
protected $mSelf = "FakeMaintenanceScript";
+
public function execute() {
return;
}
&& $db->selectRow( 'updatelog', '1', array( 'ul_key' => $key ), __METHOD__ )
) {
$this->output( "..." . $this->updateSkippedMessage() . "\n" );
+
return true;
}
return true;
} else {
$this->output( $this->updatelogFailedMessage() . "\n" );
+
return false;
}
}
*/
protected function updateSkippedMessage() {
$key = $this->getUpdateKey();
+
return "Update '{$key}' already logged as completed.";
}
*/
protected function updatelogFailedMessage() {
$key = $this->getUpdateKey();
+
return "Unable to log update '{$key}' as completed.";
}
if ( $this->dbw->tableExists( 'logging_pre_1_10' ) ) {
echo "This script has already been run to completion\n";
+
return;
}
$srcRes = $this->dbw->select( $srcTable, '*', $conds, __METHOD__,
array( 'LIMIT' => $batchSize, 'ORDER BY' => 'log_timestamp' ) );
- if ( ! $srcRes->numRows() ) {
+ if ( !$srcRes->numRows() ) {
# All done
break;
}
}
}
}
+
return $numRowsCopied;
}
}
$matches = array();
if ( preg_match( '/^--(.+?)(?:=(.+?)(?::(.+?))?)?$/', $arg, $matches ) ) {
wfSuppressWarnings();
- list( /* $full */ , $opt, $val, $param ) = $matches;
+ list( /* $full */, $opt, $val, $param ) = $matches;
wfRestoreWarnings();
switch ( $opt ) {
- case "plugin":
- $this->loadPlugin( $val, $param );
- break;
- case "output":
- if ( !is_null( $sink ) ) {
- $sinks[] = $sink;
- }
- if ( !isset( $this->outputTypes[$val] ) ) {
- $this->fatalError( "Unrecognized output sink type '$val'" );
- }
- $type = $this->outputTypes[$val];
- $sink = new $type( $param );
- break;
- case "filter":
- if ( is_null( $sink ) ) {
- $sink = new DumpOutput();
- }
- if ( !isset( $this->filterTypes[$val] ) ) {
- $this->fatalError( "Unrecognized filter type '$val'" );
- }
- $type = $this->filterTypes[$val];
- $filter = new $type( $sink, $param );
-
- // references are lame in php...
- unset( $sink );
- $sink = $filter;
-
- break;
- case "report":
- $this->reportingInterval = intval( $val );
- break;
- case "server":
- $this->server = $val;
- break;
- case "force-normal":
- if ( !function_exists( 'utf8_normalize' ) ) {
- $this->fatalError( "UTF-8 normalization extension not loaded. " .
- "Install or remove --force-normal parameter to use slower code." );
- }
- break;
- default:
- $this->processOption( $opt, $val, $param );
+ case "plugin":
+ $this->loadPlugin( $val, $param );
+ break;
+ case "output":
+ if ( !is_null( $sink ) ) {
+ $sinks[] = $sink;
+ }
+ if ( !isset( $this->outputTypes[$val] ) ) {
+ $this->fatalError( "Unrecognized output sink type '$val'" );
+ }
+ $type = $this->outputTypes[$val];
+ $sink = new $type( $param );
+ break;
+ case "filter":
+ if ( is_null( $sink ) ) {
+ $sink = new DumpOutput();
+ }
+ if ( !isset( $this->filterTypes[$val] ) ) {
+ $this->fatalError( "Unrecognized filter type '$val'" );
+ }
+ $type = $this->filterTypes[$val];
+ $filter = new $type( $sink, $param );
+
+ // references are lame in php...
+ unset( $sink );
+ $sink = $filter;
+
+ break;
+ case "report":
+ $this->reportingInterval = intval( $val );
+ break;
+ case "server":
+ $this->server = $val;
+ break;
+ case "force-normal":
+ if ( !function_exists( 'utf8_normalize' ) ) {
+ $this->fatalError( "UTF-8 normalization extension not loaded. " .
+ "Install or remove --force-normal parameter to use slower code." );
+ }
+ break;
+ default:
+ $this->processOption( $opt, $val, $param );
}
}
}
} else {
$exporter->allLogs();
}
- # Page dumps: all or by page ID range
} elseif ( is_null( $this->pages ) ) {
+ # Page dumps: all or by page ID range
if ( $this->startId || $this->endId ) {
$exporter->pagesByRange( $this->startId, $this->endId );
} elseif ( $this->revStartId || $this->revEndId ) {
} else {
$exporter->allPages();
}
- # Dump of specific pages
} else {
+ # Dump of specific pages
$exporter->pagesByName( $this->pages );
}
function backupServer() {
global $wgDBserver;
+
return $this->server
? $this->server
: $wgDBserver;
$infile = array_shift( $this->infiles );
if ( defined( 'LIBXML_PARSEHUGE' ) ) {
$this->reader->open( $infile, null, LIBXML_PARSEHUGE );
- }
- else {
+ } else {
$this->reader->open( $infile );
}
}
if ( $this->lastPage > $page || $this->atEnd ) {
$this->debug( "BaseDump::prefetch already past page $page "
. "looking for rev $rev [$this->lastPage, $this->lastRev]" );
+
return null;
}
while ( $this->lastRev < $rev && !$this->atEnd && !$this->atPageEnd ) {
}
if ( $this->lastRev == $rev && !$this->atEnd ) {
$this->debug( "BaseDump::prefetch hit on $page, $rev [$this->lastPage, $this->lastRev]" );
+
return $this->nextText();
} else {
$this->debug( "BaseDump::prefetch already past rev $rev on page $page "
. "[$this->lastPage, $this->lastRev]" );
+
return null;
}
}
*/
function nextText() {
$this->skipTo( 'text' );
+
return strval( $this->nodeContents() );
}
return false;
}
while ( $this->reader->read() ) {
- if ( $this->reader->nodeType == XMLReader::ELEMENT &&
- $this->reader->name == $name ) {
+ if ( $this->reader->nodeType == XMLReader::ELEMENT
+ && $this->reader->name == $name
+ ) {
return true;
}
- if ( $this->reader->nodeType == XMLReader::END_ELEMENT &&
- $this->reader->name == $parent ) {
+ if ( $this->reader->nodeType == XMLReader::END_ELEMENT
+ && $this->reader->name == $parent
+ ) {
$this->debug( "BaseDump::skipTo found </$parent> searching for <$name>" );
+
return false;
}
}
+
return $this->close();
}
$buffer = "";
while ( $this->reader->read() ) {
switch ( $this->reader->nodeType ) {
- case XMLReader::TEXT:
-// case XMLReader::WHITESPACE:
- case XMLReader::SIGNIFICANT_WHITESPACE:
- $buffer .= $this->reader->value;
- break;
- case XMLReader::END_ELEMENT:
- return $buffer;
+ case XMLReader::TEXT:
+ //case XMLReader::WHITESPACE:
+ case XMLReader::SIGNIFICANT_WHITESPACE:
+ $buffer .= $this->reader->value;
+ break;
+ case XMLReader::END_ELEMENT:
+ return $buffer;
}
}
+
return $this->close();
}
function close() {
$this->reader->close();
$this->atEnd = true;
+
return null;
}
}
// when we spend more than maxTimeAllowed seconds on this run, we continue
// processing until we write out the next complete page, then save output file(s),
// rename it/them and open new one(s)
- protected $maxTimeAllowed = 0; // 0 = no limit
+ protected $maxTimeAllowed = 0; // 0 = no limit
protected $timeExceeded = false;
protected $firstPageWritten = false;
protected $lastPageWritten = false;
if ( $this->forcedDb !== null ) {
$this->db = $this->forcedDb;
+
return;
}
$url = $this->processFileOpt( $val, $param );
switch ( $opt ) {
- case 'prefetch':
- require_once "$IP/maintenance/backupPrefetch.inc";
- $this->prefetch = new BaseDump( $url );
- break;
- case 'stub':
- $this->input = $url;
- break;
- case 'maxtime':
- $this->maxTimeAllowed = intval( $val ) * 60;
- break;
- case 'checkpointfile':
- $this->checkpointFiles[] = $val;
- break;
- case 'current':
- $this->history = WikiExporter::CURRENT;
- break;
- case 'full':
- $this->history = WikiExporter::FULL;
- break;
- case 'spawn':
- $this->spawn = true;
- if ( $val ) {
- $this->php = $val;
- }
- break;
+ case 'prefetch':
+ require_once "$IP/maintenance/backupPrefetch.inc";
+ $this->prefetch = new BaseDump( $url );
+ break;
+ case 'stub':
+ $this->input = $url;
+ break;
+ case 'maxtime':
+ $this->maxTimeAllowed = intval( $val ) * 60;
+ break;
+ case 'checkpointfile':
+ $this->checkpointFiles[] = $val;
+ break;
+ case 'current':
+ $this->history = WikiExporter::CURRENT;
+ break;
+ case 'full':
+ $this->history = WikiExporter::FULL;
+ break;
+ case 'spawn':
+ $this->spawn = true;
+ if ( $val ) {
+ $this->php = $val;
+ }
+ break;
}
}
$newFileURIs[] = $newURI;
}
$val = implode( ';', $newFileURIs );
+
return $val;
}
function showReport() {
if ( !$this->prefetch ) {
parent::showReport();
+
return;
}
}
$pageRatePart = $this->pageCountPart / $deltaPart;
$revRatePart = $this->revCountPart / $deltaPart;
-
} else {
$fetchRatePart = '-';
$pageRatePart = '-';
}
function finalOptionCheck() {
- if ( ( $this->checkpointFiles && ! $this->maxTimeAllowed ) ||
- ( $this->maxTimeAllowed && !$this->checkpointFiles ) ) {
+ if ( ( $this->checkpointFiles && !$this->maxTimeAllowed )
+ || ( $this->maxTimeAllowed && !$this->checkpointFiles )
+ ) {
throw new MWException( "Options checkpointfile and maxtime must be specified together.\n" );
}
foreach ( $this->checkpointFiles as $checkpointFile ) {
- $count = substr_count ( $checkpointFile, "%s" );
+ $count = substr_count( $checkpointFile, "%s" );
if ( $count != 2 ) {
throw new MWException( "Option checkpointfile must contain two '%s' "
. "for substitution of first and last pageids, count is $count instead, "
'XML import parse failure',
xml_get_current_line_number( $parser ),
xml_get_current_column_number( $parser ),
- $byte . ( is_null( $chunk ) ? null : ( '; "' . substr( $chunk, $byte -$offset, 16 ) . '"' ) ),
+ $byte . ( is_null( $chunk ) ? null : ( '; "' . substr( $chunk, $byte - $offset, 16 ) . '"' ) ),
xml_error_string( xml_get_error_code( $parser ) ) )->escaped();
xml_parser_free( $parser );
# there's no pageID 0 so we use that. the caller is responsible
# for deciding what to do with a file containing only the
# siteinfo information and the mw tags.
- if ( ! $this->firstPageWritten ) {
+ if ( !$this->firstPageWritten ) {
$firstPageID = str_pad( 0, 9, "0", STR_PAD_LEFT );
$lastPageID = str_pad( 0, 9, "0", STR_PAD_LEFT );
} else {
// Step 2: Checking for plausibility and return the text if it is
// plausible
$revID = intval( $this->thisRev );
- if ( ! isset( $this->db ) ) {
+ if ( !isset( $this->db ) ) {
throw new MWException( "No database available" );
}
$revLength = $row->rev_len;
}
}
-
- }
- else {
+ } else {
$revLength = $this->db->selectField( 'revision', 'rev_len', array( 'rev_id' => $revID ) );
}
if ( $tryIsPrefetch ) {
$this->prefetchCount++;
}
+
return $text;
}
$text = false;
throw new MWException( "Received text is unplausible for id " . $id );
-
} catch ( Exception $e ) {
$msg = "getting/checking text " . $id . " failed (" . $e->getMessage() . ")";
if ( $failures + 1 < $this->maxFailures ) {
$failures++;
// A failure in a prefetch hit does not warrant resetting db connection etc.
- if ( ! $tryIsPrefetch ) {
+ if ( !$tryIsPrefetch ) {
// After backing off for some time, we try to reboot the whole process as
// much as possible to not carry over failures from one part to the other
// parts
*/
private function getTextDb( $id ) {
global $wgContLang;
- if ( ! isset( $this->db ) ) {
+ if ( !isset( $this->db ) ) {
throw new MWException( __METHOD__ . "No database available" );
}
$row = $this->db->selectRow( 'text',
}
$stripped = str_replace( "\r", "", $text );
$normalized = $wgContLang->normalize( $stripped );
+
return $normalized;
}
}
$text = $this->getTextSpawnedOnce( $id );
wfRestoreWarnings();
+
return $text;
}
"$IP/../multiversion/MWScript.php",
"fetchText.php",
'--wiki', wfWikiID() ) ) );
- }
- else {
+ } else {
$cmd = implode( " ",
array_map( 'wfEscapeShellArg',
array(
if ( !$this->spawnProc ) {
// shit
$this->progress( "Subprocess spawn failed." );
+
return false;
}
list(
$this->spawnWrite, // -> stdin
- $this->spawnRead, // <- stdout
+ $this->spawnRead, // <- stdout
) = $pipes;
return true;
$gotbytes = strlen( $text );
if ( $gotbytes != $nbytes ) {
$this->progress( "Expected $nbytes bytes from database subprocess, got $gotbytes " );
+
return false;
}
// Do normalization in the dump thread...
$stripped = str_replace( "\r", "", $text );
$normalized = $wgContLang->normalize( $stripped );
+
return $normalized;
}
$this->buffer = "";
$this->thisRev = "";
} elseif ( $name == 'page' ) {
- if ( ! $this->firstPageWritten ) {
+ if ( !$this->firstPageWritten ) {
$this->firstPageWritten = trim( $this->thisPage );
}
$this->lastPageWritten = trim( $this->thisPage );
$this->buffer = "";
$this->thisPage = "";
}
-
} elseif ( $name == 'mediawiki' ) {
$this->egress->writeCloseStream( $this->buffer );
$this->buffer = "";
$bench_number = 0;
$count = $this->getOption( 'count', 100 );
- foreach( $benchs as $bench ) {
+ foreach ( $benchs as $bench ) {
// handle empty args
- if( !array_key_exists( 'args', $bench ) ) {
+ if ( !array_key_exists( 'args', $bench ) ) {
$bench['args'] = array();
}
$bench_number++;
$start = microtime( true );
- for( $i = 0; $i < $count; $i++ ) {
+ for ( $i = 0; $i < $count; $i++ ) {
call_user_func_array( $bench['function'], $bench['args'] );
}
$delta = microtime( true ) - $start;
// function passed as a callback
- if( is_array( $bench['function'] ) ) {
+ if ( is_array( $bench['function'] ) ) {
$ret = get_class( $bench['function'][0] ) . '->' . $bench['function'][1];
$bench['function'] = $ret;
}
$this->results[$bench_number] = array(
- 'function' => $bench['function'],
+ 'function' => $bench['function'],
'arguments' => $bench['args'],
- 'count' => $count,
- 'delta' => $delta,
- 'average' => $delta / $count,
- );
+ 'count' => $count,
+ 'delta' => $delta,
+ 'average' => $delta / $count,
+ );
}
}
public function getFormattedResults() {
$ret = '';
- foreach( $this->results as $res ) {
+ foreach ( $this->results as $res ) {
// show function with args
$ret .= sprintf( "%s times: function %s(%s) :\n",
$res['count'],
$res['average'] * 1000
);
}
+
return $ret;
}
}