* @ingroup Maintenance
*/
abstract class Maintenance {
-
/**
* Constants for DB access type
* @see Maintenance::getDbType()
* @param bool $withArg Is an argument required with this option?
* @param string $shortName Character to use as short name
*/
- protected function addOption( $name, $description, $required = false, $withArg = false, $shortName = false ) {
- $this->mParams[$name] = array( 'desc' => $description, 'require' => $required, 'withArg' => $withArg, 'shortName' => $shortName );
+ protected function addOption( $name, $description, $required = false,
+ $withArg = false, $shortName = false
+ ) {
+ $this->mParams[$name] = array(
+ 'desc' => $description,
+ 'require' => $required,
+ 'withArg' => $withArg,
+ 'shortName' => $shortName
+ );
+
if ( $shortName !== false ) {
$this->mShortParamsMap[$shortName] = $name;
}
$this->addOption( 'conf', 'Location of LocalSettings.php, if not default', false, true );
$this->addOption( 'wiki', 'For specifying the wiki ID', false, true );
$this->addOption( 'globals', 'Output globals at the end of processing for debugging' );
- $this->addOption( 'memory-limit', 'Set a specific memory limit for the script, "max" for no limit or "default" to avoid changing it' );
+ $this->addOption(
+ 'memory-limit',
+ 'Set a specific memory limit for the script, '
+ . '"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 );
}
} elseif ( substr( $arg, 0, 1 ) == '-' ) {
# Short options
- for ( $p = 1; $p < strlen( $arg ); $p++ ) {
+ $argLength = strlen( $arg );
+ for ( $p = 1; $p < $argLength; $p++ ) {
$option = $arg { $p };
if ( !isset( $this->mParams[$option] ) && isset( $this->mShortParamsMap[$option] ) ) {
$option = $this->mShortParamsMap[$option];
$this->afterFinalSetup();
$wgShowSQLErrors = true;
+
+ // @codingStandardsIgnoreStart Allow error supppression. wfSuppressWarnings()
+ // is not avaiable.
@set_time_limit( 0 );
+ // @codingStandardsIgnoreStart
+
$this->adjustMemoryLimit();
// Per-script profiling; useful for debugging
* @ingroup Maintenance
*/
class AttachLatest extends Maintenance {
-
public function __construct() {
parent::__construct();
$this->addOption( "fix", "Actually fix the entries, will dry run otherwise" );
$revision = Revision::loadFromTimestamp( $dbw, $title, $latestTime );
if ( is_null( $revision ) ) {
- $this->output( wfWikiID() . " $pageId [[$name]] latest time $latestTime, can't find revision id\n" );
+ $this->output( wfWikiID()
+ . " $pageId [[$name]] latest time $latestTime, can't find revision id\n" );
continue;
}
$id = $revision->getId();
* @ingroup Dump Maintenance
*/
class BackupDumper {
- var $reportingInterval = 100;
- var $reporting = true;
- var $pageCount = 0;
- var $revCount = 0;
- var $server = null; // use default
- var $pages = null; // all pages
- var $skipHeader = false; // don't output <mediawiki> and <siteinfo>
- var $skipFooter = false; // don't output </mediawiki>
- var $startId = 0;
- var $endId = 0;
- var $revStartId = 0;
- var $revEndId = 0;
- var $sink = null; // Output filters
- var $stubText = false; // include rev_text_id instead of text; for 2-pass dump
- var $dumpUploads = false;
- var $dumpUploadFileContents = false;
- var $lastTime = 0;
- var $pageCountLast = 0;
- var $revCountLast = 0;
- var $ID = 0;
-
- var $outputTypes = array(), $filterTypes = array();
+ public $reporting = true;
+ public $pages = null; // all pages
+ public $skipHeader = false; // don't output <mediawiki> and <siteinfo>
+ public $skipFooter = false; // don't output </mediawiki>
+ public $startId = 0;
+ public $endId = 0;
+ public $revStartId = 0;
+ public $revEndId = 0;
+ public $dumpUploads = false;
+ public $dumpUploadFileContents = false;
+
+ protected $reportingInterval = 100;
+ protected $pageCount = 0;
+ protected $revCount = 0;
+ protected $server = null; // use default
+ protected $sink = null; // Output filters
+ protected $lastTime = 0;
+ protected $pageCountLast = 0;
+ protected $revCountLast = 0;
+
+ protected $outputTypes = array();
+ protected $filterTypes = array();
+
+ protected $ID = 0;
/**
* The dependency-injected database to use.
*/
protected $forcedDb = null;
- /**
- * @var LoadBalancer
- */
+ /** @var LoadBalancer */
protected $lb;
+ // @todo Unused?
+ private $stubText = false; // include rev_text_id instead of text; for 2-pass dump
+
function __construct( $args ) {
$this->stderr = fopen( "php://stderr", "wt" );
foreach ( $args as $arg ) {
$matches = array();
if ( preg_match( '/^--(.+?)(?:=(.+?)(?::(.+?))?)?$/', $arg, $matches ) ) {
- @list( /* $full */ , $opt, $val, $param ) = $matches;
+ wfSuppressWarnings();
+ list( /* $full */ , $opt, $val, $param ) = $matches;
+ wfRestoreWarnings();
+
switch ( $opt ) {
case "plugin":
$this->loadPlugin( $val, $param );
$pageRatePart = '-';
$revRatePart = '-';
}
- $this->progress( sprintf( "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), %d revs (%0.1f|%0.1f/sec all|curr), ETA %s [max %d]",
- $now, wfWikiID(), $this->ID, $this->pageCount, $pageRate, $pageRatePart, $this->revCount, $revRate, $revRatePart, $etats, $this->maxCount ) );
+ $this->progress( sprintf(
+ "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), "
+ . "%d revs (%0.1f|%0.1f/sec all|curr), ETA %s [max %d]",
+ $now, wfWikiID(), $this->ID, $this->pageCount, $pageRate,
+ $pageRatePart, $this->revCount, $revRate, $revRatePart, $etats,
+ $this->maxCount
+ ) );
$this->lastTime = $nowts;
$this->revCountLast = $this->revCount;
}
* @ingroup Maintenance
*/
class BaseDump {
- var $reader = null;
- var $atEnd = false;
- var $atPageEnd = false;
- var $lastPage = 0;
- var $lastRev = 0;
- var $infiles = null;
+ protected $reader = null;
+ protected $atEnd = false;
+ protected $atPageEnd = false;
+ protected $lastPage = 0;
+ protected $lastRev = 0;
+ protected $infiles = null;
- function BaseDump( $infile ) {
+ public function __construct( $infile ) {
$this->infiles = explode( ';', $infile );
$this->reader = new XMLReader();
$infile = array_shift( $this->infiles );
$this->nextPage();
}
if ( $this->lastPage > $page || $this->atEnd ) {
- $this->debug( "BaseDump::prefetch already past page $page looking for rev $rev [$this->lastPage, $this->lastRev]" );
+ $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 ) {
- $this->debug( "BaseDump::prefetch at page $this->lastPage, rev $this->lastRev, looking for $page, $rev" );
+ $this->debug( "BaseDump::prefetch at page $this->lastPage, rev $this->lastRev, "
+ . "looking for $page, $rev" );
$this->nextRev();
}
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]" );
+ $this->debug( "BaseDump::prefetch already past rev $rev on page $page "
+ . "[$this->lastPage, $this->lastRev]" );
return null;
}
}
* @ingroup Maintenance
*/
class TextPassDumper extends BackupDumper {
- var $prefetch = null;
- var $input = "php://stdin";
- var $history = WikiExporter::FULL;
- var $fetchCount = 0;
- var $prefetchCount = 0;
- var $prefetchCountLast = 0;
- var $fetchCountLast = 0;
+ public $prefetch = null;
+ protected $input = "php://stdin";
+ protected $history = WikiExporter::FULL;
+ protected $fetchCount = 0;
+ protected $prefetchCount = 0;
+ protected $prefetchCountLast = 0;
+ protected $fetchCountLast = 0;
- var $maxFailures = 5;
- var $maxConsecutiveFailedTextRetrievals = 200;
- var $failureTimeout = 5; // Seconds to sleep after db failure
+ protected $maxFailures = 5;
+ protected $maxConsecutiveFailedTextRetrievals = 200;
+ protected $failureTimeout = 5; // Seconds to sleep after db failure
- var $php = "php";
- var $spawn = false;
+ protected $php = "php";
+ protected $spawn = false;
/**
* @var bool|resource
*/
- var $spawnProc = false;
+ protected $spawnProc = false;
/**
* @var bool|resource
*/
- var $spawnWrite = false;
+ protected $spawnWrite = false;
/**
* @var bool|resource
*/
- var $spawnRead = false;
+ protected $spawnRead = false;
/**
* @var bool|resource
*/
- var $spawnErr = false;
+ protected $spawnErr = false;
- var $xmlwriterobj = false;
+ protected $xmlwriterobj = false;
// 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)
- var $maxTimeAllowed = 0; // 0 = no limit
- var $timeExceeded = false;
- var $firstPageWritten = false;
- var $lastPageWritten = false;
- var $checkpointJustWritten = false;
- var $checkpointFiles = array();
+ protected $maxTimeAllowed = 0; // 0 = no limit
+ protected $timeExceeded = false;
+ protected $firstPageWritten = false;
+ protected $lastPageWritten = false;
+ protected $checkpointJustWritten = false;
+ protected $checkpointFiles = array();
/**
* @var DatabaseBase
try {
$this->lb = wfGetLBFactory()->newMainLB();
} catch ( Exception $e ) {
- throw new MWException( __METHOD__ . " rotating DB failed to obtain new load balancer (" . $e->getMessage() . ")" );
+ throw new MWException( __METHOD__
+ . " rotating DB failed to obtain new load balancer (" . $e->getMessage() . ")" );
}
// 2. The Connection, through the load balancer.
try {
$this->db = $this->lb->getConnection( DB_SLAVE, 'dump' );
} catch ( Exception $e ) {
- throw new MWException( __METHOD__ . " rotating DB failed to obtain new database (" . $e->getMessage() . ")" );
+ throw new MWException( __METHOD__
+ . " rotating DB failed to obtain new database (" . $e->getMessage() . ")" );
}
}
$pageRatePart = '-';
$revRatePart = '-';
}
- $this->progress( sprintf( "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), %d revs (%0.1f|%0.1f/sec all|curr), %0.1f%%|%0.1f%% prefetched (all|curr), ETA %s [max %d]",
- $now, wfWikiID(), $this->ID, $this->pageCount, $pageRate, $pageRatePart, $this->revCount, $revRate, $revRatePart, $fetchRate, $fetchRatePart, $etats, $this->maxCount ) );
+ $this->progress( sprintf(
+ "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), "
+ . "%d revs (%0.1f|%0.1f/sec all|curr), %0.1f%%|%0.1f%% "
+ . "prefetched (all|curr), ETA %s [max %d]",
+ $now, wfWikiID(), $this->ID, $this->pageCount, $pageRate,
+ $pageRatePart, $this->revCount, $revRate, $revRatePart,
+ $fetchRate, $fetchRatePart, $etats, $this->maxCount
+ ) );
$this->lastTime = $nowts;
$this->revCountLast = $this->revCount;
$this->prefetchCountLast = $this->prefetchCount;
}
function checkIfTimeExceeded() {
- if ( $this->maxTimeAllowed && ( $this->lastTime - $this->timeOfCheckpoint > $this->maxTimeAllowed ) ) {
+ if ( $this->maxTimeAllowed
+ && ( $this->lastTime - $this->timeOfCheckpoint > $this->maxTimeAllowed )
+ ) {
return true;
}
+
return false;
}
foreach ( $this->checkpointFiles as $checkpointFile ) {
$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, file is $checkpointFile.\n" );
+ throw new MWException( "Option checkpointfile must contain two '%s' "
+ . "for substitution of first and last pageids, count is $count instead, "
+ . "file is $checkpointFile.\n" );
}
}
if ( $this->checkpointFiles ) {
$filenameList = (array)$this->egress->getFilenames();
if ( count( $filenameList ) != count( $this->checkpointFiles ) ) {
- throw new MWException( "One checkpointfile must be specified for each output option, if maxtime is used.\n" );
+ throw new MWException( "One checkpointfile must be specified "
+ . "for each output option, if maxtime is used.\n" );
}
}
}
$parser = xml_parser_create( "UTF-8" );
xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, false );
- xml_set_element_handler( $parser, array( &$this, 'startElement' ), array( &$this, 'endElement' ) );
+ xml_set_element_handler(
+ $parser,
+ array( &$this, 'startElement' ),
+ array( &$this, 'endElement' )
+ );
xml_set_character_data_handler( $parser, array( &$this, 'characterData' ) );
$offset = 0; // for context extraction on error reporting
if ( ! $this->firstPageWritten ) {
$firstPageID = str_pad( 0, 9, "0", STR_PAD_LEFT );
$lastPageID = str_pad( 0, 9, "0", STR_PAD_LEFT );
- }
- else {
+ } else {
$firstPageID = str_pad( $this->firstPageWritten, 9, "0", STR_PAD_LEFT );
$lastPageID = str_pad( $this->lastPageWritten, 9, "0", STR_PAD_LEFT );
}
- for ( $i = 0; $i < count( $filenameList ); $i++ ) {
+
+ $filenameCount = count( $filenameList );
+ for ( $i = 0; $i < $filenameCount; $i++ ) {
$checkpointNameFilledIn = sprintf( $this->checkpointFiles[$i], $firstPageID, $lastPageID );
$fileinfo = pathinfo( $filenameList[$i] );
$newFilenames[] = $fileinfo['dirname'] . '/' . $checkpointNameFilledIn;
$newFilenames = array();
$firstPageID = str_pad( $this->firstPageWritten, 9, "0", STR_PAD_LEFT );
$lastPageID = str_pad( $this->lastPageWritten, 9, "0", STR_PAD_LEFT );
- for ( $i = 0; $i < count( $filenameList ); $i++ ) {
+ $filenamesCount = count( $filenameList );
+ for ( $i = 0; $i < $filenamesCount; $i++ ) {
$checkpointNameFilledIn = sprintf( $this->checkpointFiles[$i], $firstPageID, $lastPageID );
$fileinfo = pathinfo( $filenameList[$i] );
$newFilenames[] = $fileinfo['dirname'] . '/' . $checkpointNameFilledIn;
$this->timeOfCheckpoint = $this->lastTime;
$this->firstPageWritten = false;
$this->checkpointJustWritten = true;
- }
- else {
+ } else {
$this->egress->writeClosePage( $this->buffer );
$this->buffer = "";
$this->thisPage = "";