* to allow sysadmins to explicitly set one if they'd prefer to override
* defaults (or for people using Suhosin which yells at you for trying
* to disable the limits)
+ * @return string
*/
public function memoryLimit() {
$limit = $this->getOption( 'memory-limit', 'max' );
$wgDBpassword = $wgDBadminpassword;
if ( $wgDBservers ) {
+ /**
+ * @var $wgDBservers array
+ */
foreach ( $wgDBservers as $i => $server ) {
$wgDBservers[$i]['user'] = $wgDBuser;
$wgDBservers[$i]['password'] = $wgDBpassword;
/**
* Get the maintenance directory.
+ * @return string
*/
protected function getDir() {
return dirname( __FILE__ );
* Update the searchindex table for a given pageid
* @param $dbw Database: a database write handle
* @param $pageId Integer: the page ID to update.
+ * @return null|string
*/
public function updateSearchIndexForPage( $dbw, $pageId ) {
// Get current revision
* @todo Fixme: the --server parameter is currently not respected, as it
* doesn't seem terribly easy to ask the load balancer for a particular
* connection by name.
+ * @return DatabaseBase
*/
function backupDb() {
$this->lb = wfGetLBFactory()->newMainLB();
/**
* @access private
+ * @return string
*/
function nextText() {
$this->skipTo( 'text' );
/**
* @access private
+ * @param $name string
+ * @param $parent string
+ * @return bool|null
*/
function skipTo( $name, $parent = 'page' ) {
if ( $this->atEnd ) {
/**
* @access private
+ * @return null
*/
function close() {
$this->reader->close();
* to benchmark Squid response times.
* @param $urls array A bunch of URLs to purge
* @param $trials int How many times to run the test?
+ * @return string
*/
private function benchSquid( $urls, $trials = 1 ) {
$start = wfTime();
/**
* Get an array of randomUrl()'s.
* @param $length int How many urls to add to the array
+ * @return array
*/
private function randomUrlList( $length ) {
$list = array();
/**
* Return a random URL of the wiki. Not necessarily an actual title in the
* database, but at least a URL that looks like one.
+ * @return string
*/
private function randomUrl() {
global $wgServer, $wgArticlePath;
/**
* Create a random title string (not necessarily a Title object).
* For use with randomUrl().
+ * @return string
*/
private function randomTitle() {
$str = '';
/**
* Returns true if $file is of a type we can check
+ * @param $file string
+ * @return bool
*/
private function isSuitableFile( $file ) {
$file = str_replace( '\\', '/', $file );
/**
* Add given path to file list, searching it in include path if needed
+ * @param $path string
+ * @return bool
*/
private function addPath( $path ) {
global $IP;
}
/**
- * Add given file to file list, or, if it's a directory, add its content
- */
+ * Add given file to file list, or, if it's a directory, add its content
+ * @param $path string
+ * @return bool
+ */
private function addFileOrDir( $path ) {
if ( is_dir( $path ) ) {
$this->addDirectoryContent( $path );
return $this->processRow( $row );
}
}
- } else {
- $this->progress( 0 );
}
+ return $this->progress( 0 );
}
}
if ( is_null( $title ) ) {
$this->output( "page $source ($cleaned) is illegal.\n" );
$safe = $this->buildSafeTitle( $cleaned );
- if ( $safe === false )
+ if ( $safe === false ) {
return $this->progress( 0 );
+ }
$this->pokeFile( $source, $safe );
return $this->progress( 1 );
}
return $this->progress( 1 );
}
- $this->progress( 0 );
+ return $this->progress( 0 );
}
/**
$path = $this->filePath( $orig );
if ( !file_exists( $path ) ) {
$this->output( "missing file: $path\n" );
- return $this->killRow( $orig );
+ $this->killRow( $orig );
+ return;
}
$db = wfGetDB( DB_MASTER );
$version = 0;
$final = $new;
$conflict = ( $this->imageExists( $final, $db ) ||
- ( $this->pageExists( $orig, $db ) && $this->pageExists( $final, $db ) ) );
+ ( $this->pageExists( $orig, $db ) && $this->pageExists( $final, $db ) ) );
while ( $conflict ) {
$this->output( "Rename conflicts with '$final'...\n" );
$dir = dirname( $finalPath );
if ( !file_exists( $dir ) ) {
if ( !wfMkdirParents( $dir, null, __METHOD__ ) ) {
- $this->log( "RENAME FAILED, COULD NOT CREATE $dir" );
+ $this->output( "RENAME FAILED, COULD NOT CREATE $dir" );
$db->rollback();
return;
}
public function execute() {
$repo = RepoGroup::singleton()->getLocalRepo();
-
+
$dbr = $repo->getSlaveDb();
// how far back should this look for files to delete?
global $wgUploadStashMaxAge;
-
+
$this->output( "Getting list of files to clean up...\n" );
$res = $dbr->select(
'uploadstash',
'us_timestamp < ' . $dbr->timestamp( time() - $wgUploadStashMaxAge ),
__METHOD__
);
-
+
if( !is_object( $res ) || $res->numRows() == 0 ) {
+ $this->output( 'No files to cleanup!' );
// nothing to do.
- return false;
+ return;
}
// finish the read before starting writes.
foreach($res as $row) {
array_push( $keys, $row->us_key );
}
-
+
$this->output( 'Removing ' . count($keys) . " file(s)...\n" );
// this could be done some other, more direct/efficient way, but using
// UploadStash's own methods means it's less likely to fall accidentally
// out-of-date someday
$stash = new UploadStash( $repo );
-
+
foreach( $keys as $key ) {
$stash->getFile( $key, true );
$stash->removeFileNoAuth( $key );
}
$maintClass = "UploadStashCleanup";
-require_once( RUN_MAINTENANCE_IF_MAIN );
\ No newline at end of file
+require_once( RUN_MAINTENANCE_IF_MAIN );
var $checkpointJustWritten = false;
var $checkpointFiles = array();
+ /**
+ * @var DatabaseBase
+ */
+ protected $db;
+
function initProgress( $history ) {
parent::initProgress();
$this->timeOfCheckpoint = $this->startTime;
*/
function showReport() {
if ( !$this->prefetch ) {
- return parent::showReport();
+ parent::showReport();
+ return;
}
if ( $this->reporting ) {
$etats = wfTimestamp( TS_DB, intval( $eta ) );
if ( $this->fetchCount ) {
$fetchRate = 100.0 * $this->prefetchCount / $this->fetchCount;
- }
- else {
+ } else {
$fetchRate = '-';
}
$pageRate = $this->pageCount / $deltaAll;
if ( $deltaPart ) {
if ( $this->fetchCountLast ) {
$fetchRatePart = 100.0 * $this->prefetchCountLast / $this->fetchCountLast;
- }
- else {
+ } else {
$fetchRatePart = '-';
}
$pageRatePart = $this->pageCountPart / $deltaPart;
function checkIfTimeExceeded() {
if ( $this->maxTimeAllowed && ( $this->lastTime - $this->timeOfCheckpoint > $this->maxTimeAllowed ) ) {
- return True;
+ return true;
}
- return False;
+ return false;
}
function finalOptionCheck() {
// we wrote some stuff after last checkpoint that needs renamed
if (file_exists($filenameList[0])) {
$newFilenames = array();
- # we might have just written the header and footer and had no
+ # we might have just written the header and footer and had no
# pages or revisions written... perhaps they were all deleted
# there's no pageID 0 so we use that. the caller is responsible
# for deciding what to do with a file containing only the
}
private function doGetText( $id ) {
-
$id = intval( $id );
$this->failures = 0;
$ex = new MWException( "Graceful storage failure" );
$this->closeSpawn();
$this->openSpawn();
}
- $text = $this->getTextSpawned( $id );
+ $text = $this->getTextSpawned( $id );
} else {
- $text = $this->getTextDbSafe( $id );
+ $text = $this->getTextDbSafe( $id );
}
if ( $text === false ) {
$this->failures++;
$this->failedTextRetrievals++;
if ($this->failedTextRetrievals > $this->maxConsecutiveFailedTextRetrievals) {
throw $ex;
- }
- else {
+ } else {
// would be nice to return something better to the caller someday,
// log what we know about the failure and about the revision
- return("");
+ return "";
}
} else {
$this->progress( "Error $this->failures " .
}
} else {
$this->failedTextRetrievals= 0;
- return( $text );
+ return $text;
}
}
-
+ return '';
}
/**
* Fetch a text revision from the database, retrying in case of failure.
* This may survive some transitory errors by reconnecting, but
* may not survive a long-term server outage.
+ *
+ * FIXME: WTF? Why is it using a loop and then returning unconditionally?
*/
private function getTextDbSafe( $id ) {
while ( true ) {
/**
* May throw a database error if, say, the server dies during query.
+ * @param $id
+ * @return bool|string
*/
private function getTextDb( $id ) {
global $wgContLang;
$this->egress->writeClosePage( $this->buffer );
// nasty hack, we can't just write the chardata after the
// page tag, it will include leading blanks from the next line
- $this->egress->sink->write("\n");
-
+ $this->egress->sink->write("\n");
+
$this->buffer = $this->xmlwriterobj->closeStream();
$this->egress->writeCloseStream( $this->buffer );
$this->buffer = "";
$this->thisPage = "";
// this could be more than one file if we had more than one output arg
- $checkpointFilenames = array();
+
$filenameList = (array)$this->egress->getFilenames();
$newFilenames = array();
$firstPageID = str_pad($this->firstPageWritten,9,"0",STR_PAD_LEFT);
pressure on the database.
(Requires the XMLReader extension)
--maxtime=<minutes> Write out checkpoint file after this many minutes (writing
- out complete page, closing xml file properly, and opening new one
+ out complete page, closing xml file properly, and opening new one
with header). This option requires the checkpointfile option.
--checkpointfile=<filenamepattern> Use this string for checkpoint filenames,
- substituting first pageid written for the first %s (required) and the
+ substituting first pageid written for the first %s (required) and the
last pageid written for the second %s if it exists.
--quiet Don't dump status reports to stderr.
--report=n Report position and speed after every n pages processed.
static private $maxparams = 10;
/**
- ** Returns random number between finish and start.
+ * Returns random number between finish and start.
+ * @param $finish
+ * @param $start int
+ * @return int
*/
static public function randnum( $finish, $start = 0 ) {
return mt_rand( $start, $finish );
}
/**
- ** Returns a mix of random text and random wiki syntax.
+ * Returns a mix of random text and random wiki syntax.
+ * @return string
*/
static private function randstring() {
$thestring = "";
}
/**
- ** Returns either random text, or random wiki syntax, or random data from "ints",
- ** or random data from "other".
+ * Returns either random text, or random wiki syntax, or random data from "ints",
+ * or random data from "other".
+ * @return string
*/
static private function makestring() {
$what = wikiFuzz::randnum( 2 );
if ( $what == 0 ) {
return wikiFuzz::randstring();
- }
- elseif ( $what == 1 ) {
+ } elseif ( $what == 1 ) {
return wikiFuzz::$ints[wikiFuzz::randnum( count( wikiFuzz::$ints ) - 1 )];
- }
- else {
+ } else {
return wikiFuzz::$other[wikiFuzz::randnum( count( wikiFuzz::$other ) - 1 )];
}
}
/**
* Returns the matched character slash-escaped as in a C string
* Helper for makeTitleSafe callback
+ * @param $matches
+ * @return atring
*/
static private function stringEscape( $matches ) {
return sprintf( "\\x%02x", ord( $matches[1] ) );
/**
** Strips out the stuff that Mediawiki balks at in a page's title.
** Implementation copied/pasted from cleanupTable.inc & cleanupImages.php
+ * @param $str string
+ * @return string
*/
static public function makeTitleSafe( $str ) {
$legalTitleChars = " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF";
/**
** Returns a string of fuzz text.
+ * @return string
*/
static private function loop() {
switch ( wikiFuzz::randnum( 3 ) ) {
}
/**
- ** Returns one of the three styles of random quote: ', ", and nothing.
+ * Returns one of the three styles of random quote: ', ", and nothing.
+ * @return string
*/
static private function getRandQuote() {
switch ( wikiFuzz::randnum( 3 ) ) {
/**
** Returns fuzz text, with the parameter indicating approximately how many lines of text you want.
+ * @param $maxtypes int
+ * @return string
*/
static public function makeFuzz( $maxtypes = 2 ) {
$page = "";
}
}
-
/**
** selects a page test to run.
+ * @param $count
+ * @return \api|\confirmEmail|\contributionsTest|\editPageTest|\imagelistTest|\imagepageTest|\ipblocklistTest|\listusersTest|\mimeSearchTest|\newImagesTest|\pageDeletion|\pageHistoryTest|\pageProtectionForm|\prefixindexTest|\profileInfo|\recentchangesTest|\redirectTest|\searchTest|\specialAllmessagesTest|\specialAllpagesTest|\specialBlockip|\specialBlockmeTest|\specialBooksourcesTest|\specialCategoryTree|\specialChemicalsourcesTest|\specialCitePageTest|\specialExportTest|\specialFilepathPageTest|\specialImportPageTest|\specialLinksearch|\specialLockdbPageTest|\specialLogTest|\specialMovePage|\specialNewpagesPageTest|\specialRenameuserPageTest|\specialRevisionDeletePageTest|\specialUndeletePageTest|\specialUnlockdbPageTest|\specialUserrights|\successfulUserLoginTest|\thumbTest|\trackbackTest|\userLoginTest|\viewPageTest|\watchlistTest
*/
function selectPageTest( $count ) {
file_put_contents( $name, $data );
}
-
/**
** Returns a test as an experimental GET-to-POST URL.
** This doesn't seem to always work though, and sometimes the output is too long
** to be a valid GET URL, so we also save in other formats.
+ * @param $test pageTest
+ * @return string
*/
function getAsURL( pageTest $test ) {
$used_question_mark = ( strpos( $test->getPagePath(), "?" ) !== false );
saveFile( $str, $filename );
}
-
/**
- ** Escapes a value so that it can be used on the command line by Curl.
- ** Specifically, "<" and "@" need to be escaped if they are the first character,
- ** otherwise curl interprets these as meaning that we want to insert a file.
+ * Escapes a value so that it can be used on the command line by Curl.
+ * Specifically, "<" and "@" need to be escaped if they are the first character,
+ * otherwise curl interprets these as meaning that we want to insert a file.
+ * @param $input_params array
+ * @return array
*/
function escapeForCurl( array $input_params ) {
$output_params = array();
saveTestData ( $test, $base_name . DATA_FILE );
}
-
// ////////////////// MEDIAWIKI OUTPUT /////////////////////////
/**
- ** Asks MediaWiki for the HTML output of a test.
+ * Asks MediaWiki for the HTML output of a test.
+ * @param $test pageTest
+ * @return string
*/
function wikiTestOutput( pageTest $test ) {
$ch = curl_init();
// specify the cookie, if required.
- if ( $test->getCookie() ) curl_setopt( $ch, CURLOPT_COOKIE, $test->getCookie() );
+ if ( $test->getCookie() ) {
+ curl_setopt( $ch, CURLOPT_COOKIE, $test->getCookie() );
+ }
curl_setopt( $ch, CURLOPT_POST, 1 ); // save form using a POST
$params = escapeForCurl( $test->getParams() );
/**
* Asks the validator whether this is valid HTML, or not.
+ * @param $text string
+ * @return array
*/
function validateHTML( $text ) {
return array( $valid, $result );
}
-
/**
- ** Get tidy to check for no HTML errors in the output file (e.g. unescaped strings).
+ * Get tidy to check for no HTML errors in the output file (e.g. unescaped strings).
+ * @param $name
+ * @return bool
*/
function tidyCheckFile( $name ) {
$file = DIRECTORY . "/" . $name;
}
}
-
/**
** Returns whether or not an database error log file has changed in size since
** the last time this was run. This is used to tell if a test caused a DB error.
+ * @return bool
*/
function dbErrorLogged() {
static $filesize;
// //////////////// TOP-LEVEL PROBLEM-FINDING FUNCTION ////////////////////////
/**
- ** takes a page test, and runs it and tests it for problems in the output.
- ** Returns: False on finding a problem, or True on no problems being found.
+ * takes a page test, and runs it and tests it for problems in the output.
+ * Returns: False on finding a problem, or True on no problems being found.
+ * @param $test pageTest
+ * @param $testname
+ * @param $can_overwrite bool
+ * @return bool
*/
function runWikiTest( pageTest $test, &$testname, $can_overwrite = false ) {
// Custom priorities
if ( $wgSitemapNamespacesPriorities !== false ) {
+ /**
+ * @var $wgSitemapNamespacesPriorities array
+ */
foreach ( $wgSitemapNamespacesPriorities as $namespace => $priority ) {
$float = floatval( $priority );
if ( $float > 1.0 ) {
/**
* Create directory if it does not exist and return pathname with a trailing slash
+ * @param $fspath string
+ * @return null|string
*/
private static function init_path( $fspath ) {
if ( !isset( $fspath ) ) {
$this->stderr = fopen( "php://stderr", "wt" );
$this->addOption( 'report',
'Report position and speed after every n pages processed', false, true );
- $this->addOption( 'namespaces',
+ $this->addOption( 'namespaces',
'Import only the pages from namespaces belonging to the list of ' .
'pipe-separated namespace names or namespace indexes', false, true );
$this->addOption( 'dry-run', 'Parse dump without actually importing pages' );
}
}
+ /**
+ * @param $revision Revision
+ * @return bool
+ */
function handleUpload( $revision ) {
if ( $this->uploads ) {
if ( $this->skippedNamespace( $revision ) ) {
- return;
+ return ;
}
$this->uploadCount++;
// $this->report();
}
public function execute() {
- $iterations = $this->getOption( 'i', 100 );
if ( $this->hasArg() ) {
$files = $this->mArgs;
} else {
/**
* Read a line from the shell
* @param $prompt String
+ * @return string
*/
function readaline( $prompt = '' ) {
print $prompt;
* @param $exclude String: Additionals path regex to exclude
* @param $exclude_patterns String: Additionals path regex to exclude
* (LocalSettings.php, AdminSettings.php, .svn and .git directories are always excluded)
+ * @return string
*/
function generateConfigFile( $doxygenTemplate, $outputDirectory, $stripFromPath, $currentVersion, $svnstat, $input, $exclude, $exclude_patterns ) {