*/
private function getHooksFromOnlineDoc() {
// All hooks
- $allhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&cmlimit=500&format=php' );
+ $allhookdata = Http::get(
+ 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&'
+ . 'cmtitle=Category:MediaWiki_hooks&cmlimit=500&format=php'
+ );
$allhookdata = unserialize( $allhookdata );
$allhooks = array();
foreach ( $allhookdata['query']['categorymembers'] as $page ) {
}
}
// Removed hooks
- $oldhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Removed_hooks&cmlimit=500&format=php' );
+ $oldhookdata = Http::get(
+ 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&'
+ . 'cmtitle=Category:Removed_hooks&cmlimit=500&format=php'
+ );
$oldhookdata = unserialize( $oldhookdata );
$removed = array();
foreach ( $oldhookdata['query']['categorymembers'] as $page ) {
private function getHooksFromFile( $file ) {
$content = file_get_contents( $file );
$m = array();
- preg_match_all( '/(?:wfRunHooks|Hooks\:\:run|ContentHandler\:\:runLegacyHooks)\(\s*([\'"])(.*?)\1/', $content, $m );
+ preg_match_all(
+ '/(?:wfRunHooks|Hooks\:\:run|ContentHandler\:\:runLegacyHooks)\(\s*([\'"])(.*?)\1/',
+ $content,
+ $m
+ );
+
return $m[2];
}
if ( !$async ) {
$success = ( $dryrun ? true : $job->run() );
if ( !$success ) {
- $this->error( "Error fixing " . $titleA->getPrefixedText() . ": " . $job->getLastError() . "\n" );
+ $this->error( "Error fixing " . $titleA->getPrefixedText()
+ . ": " . $job->getLastError() . "\n" );
}
} else {
$jobs[] = $job;
class FixExtLinksProtocolRelative extends LoggedUpdateMaintenance {
public function __construct() {
parent::__construct();
- $this->mDescription = "Fixes any entries in the externallinks table containing protocol-relative URLs";
+ $this->mDescription =
+ "Fixes any entries in the externallinks table containing protocol-relative URLs";
}
protected function getUpdateKey() {
)
), __METHOD__, array( 'IGNORE' )
);
- $db->delete( 'externallinks', array( 'el_index' => $row->el_index, 'el_from' => $row->el_from, 'el_to' => $row->el_to ), __METHOD__ );
+ $db->delete(
+ 'externallinks',
+ array(
+ 'el_index' => $row->el_index,
+ 'el_from' => $row->el_from,
+ 'el_to' => $row->el_to
+ ),
+ __METHOD__
+ );
}
$this->output( "Done, $count rows updated.\n" );
return true;
* @ingroup Maintenance
*/
class FixSlaveDesync extends Maintenance {
+ /** @var array */
+ private $slaveIndexes;
+
public function __construct() {
parent::__construct();
$this->mDescription = "";
public function execute() {
$this->slaveIndexes = array();
- for ( $i = 1; $i < wfGetLB()->getServerCount(); $i++ ) {
+ $serverCount = wfGetLB()->getServerCount();
+ for ( $i = 1; $i < $serverCount; $i++ ) {
if ( wfGetLB()->isNonZeroLoad( $i ) ) {
$this->slaveIndexes[] = $i;
}
$n = 0;
$dbw = wfGetDB( DB_MASTER );
$masterIDs = array();
- $res = $dbw->select( 'page', array( 'page_id', 'page_latest' ), array( 'page_id<6054123' ), __METHOD__ );
+ $res = $dbw->select(
+ 'page',
+ array( 'page_id', 'page_latest' ),
+ array( 'page_id<6054123' ),
+ __METHOD__
+ );
$this->output( "Number of pages: " . $res->numRows() . "\n" );
foreach ( $res as $row ) {
$masterIDs[$row->page_id] = $row->page_latest;
foreach ( $this->slaveIndexes as $i ) {
$db = wfGetDB( $i );
- $res = $db->select( 'page', array( 'page_id', 'page_latest' ), array( 'page_id<6054123' ), __METHOD__ );
+ $res = $db->select(
+ 'page',
+ array( 'page_id', 'page_latest' ),
+ array( 'page_id<6054123' ),
+ __METHOD__
+ );
foreach ( $res as $row ) {
if ( isset( $masterIDs[$row->page_id] ) && $masterIDs[$row->page_id] != $row->page_latest ) {
$desync[$row->page_id] = true;
if ( count( $masterIDs ) < count( $slaveIDs ) ) {
$missingIDs = array_diff( $slaveIDs, $masterIDs );
if ( count( $missingIDs ) ) {
- $this->output( "Found " . count( $missingIDs ) . " lost in master, copying from slave... " );
+ $this->output( "Found " . count( $missingIDs )
+ . " lost in master, copying from slave... " );
$dbFrom = $dbw;
$found = true;
$toMaster = true;
} else {
$missingIDs = array_diff( $masterIDs, $slaveIDs );
if ( count( $missingIDs ) ) {
- $this->output( "Found " . count( $missingIDs ) . " missing revision(s), copying from master... " );
+ $this->output( "Found " . count( $missingIDs )
+ . " missing revision(s), copying from master... " );
$dbFrom = $dbw;
$found = true;
$toMaster = false;
if ( $found ) {
$this->output( "Fixing page_latest... " );
if ( $toMaster ) {
- # $dbw->update( 'page', array( 'page_latest' => $realLatest ), array( 'page_id' => $pageID ), __METHOD__ );
+ /*
+ $dbw->update(
+ 'page',
+ array( 'page_latest' => $realLatest ),
+ array( 'page_id' => $pageID ),
+ __METHOD__
+ );
+ */
} else {
foreach ( $this->slaveIndexes as $i ) {
$db = wfGetDB( $i );
- $db->update( 'page', array( 'page_latest' => $realLatest ), array( 'page_id' => $pageID ), __METHOD__ );
+ $db->update(
+ 'page',
+ array( 'page_latest' => $realLatest ),
+ array( 'page_id' => $pageID ),
+ __METHOD__
+ );
}
}
$this->output( "done\n" );
$fixup = -$offset;
$sql = "UPDATE $revisionTable " .
- "SET rev_timestamp=DATE_FORMAT(DATE_ADD(rev_timestamp, INTERVAL $fixup SECOND), '%Y%m%d%H%i%s') " .
+ "SET rev_timestamp="
+ . "DATE_FORMAT(DATE_ADD(rev_timestamp, INTERVAL $fixup SECOND), '%Y%m%d%H%i%s') " .
"WHERE rev_id IN (" . $dbw->makeList( $badRevs ) . ')';
$dbw->query( $sql, __METHOD__ );
$this->output( "Done\n" );
foreach ( $res as $row ) {
$id = $row->user_id;
// Get first edit time
- $timestamp = $dbr->selectField( 'revision', 'MIN(rev_timestamp)', array( 'rev_user' => $id ), __METHOD__ );
+ $timestamp = $dbr->selectField(
+ 'revision',
+ 'MIN(rev_timestamp)',
+ array( 'rev_user' => $id ),
+ __METHOD__
+ );
// Update
if ( !empty( $timestamp ) ) {
- $dbw->update( 'user', array( 'user_registration' => $timestamp ), array( 'user_id' => $id ), __METHOD__ );
+ $dbw->update(
+ 'user',
+ array( 'user_registration' => $timestamp ),
+ array( 'user_id' => $id ),
+ __METHOD__
+ );
$this->output( "$id $timestamp\n" );
} else {
$this->output( "$id NULL\n" );
public $fspath;
/**
- * The URL path to prepend to filenames in the index; should resolve to the same directory as $fspath
+ * The URL path to prepend to filenames in the index;
+ * should resolve to the same directory as $fspath.
*
* @var string
*/
public function __construct() {
parent::__construct();
$this->mDescription = "Creates a sitemap for the site";
- $this->addOption( 'fspath', 'The file system path to save to, e.g. /tmp/sitemap; defaults to current directory', false, true );
- $this->addOption( 'urlpath', 'The URL path corresponding to --fspath, prepended to filenames in the index; defaults to an empty string', false, true );
- $this->addOption( 'compress', 'Compress the sitemap files, can take value yes|no, default yes', false, true );
+ $this->addOption(
+ 'fspath',
+ 'The file system path to save to, e.g. /tmp/sitemap; defaults to current directory',
+ false,
+ true
+ );
+ $this->addOption(
+ 'urlpath',
+ 'The URL path corresponding to --fspath, prepended to filenames in the index; '
+ . 'defaults to an empty string',
+ false,
+ true
+ );
+ $this->addOption(
+ 'compress',
+ 'Compress the sitemap files, can take value yes|no, default yes',
+ false,
+ true
+ );
$this->addOption( 'skip-redirects', 'Do not include redirecting articles in the sitemap' );
- $this->addOption( 'identifier', 'What site identifier to use for the wiki, defaults to $wgDBname', false, true );
+ $this->addOption(
+ 'identifier',
+ 'What site identifier to use for the wiki, defaults to $wgDBname',
+ false,
+ true
+ );
}
/**
* @return string
*/
function priority( $namespace ) {
- return isset( $this->priorities[$namespace] ) ? $this->priorities[$namespace] : $this->guessPriority( $namespace );
+ return isset( $this->priorities[$namespace] )
+ ? $this->priorities[$namespace]
+ : $this->guessPriority( $namespace );
}
/**
* @return string
*/
function guessPriority( $namespace ) {
- return MWNamespace::isSubject( $namespace ) ? $this->priorities[self::GS_MAIN] : $this->priorities[self::GS_TALK];
+ return MWNamespace::isSubject( $namespace )
+ ? $this->priorities[self::GS_MAIN]
+ : $this->priorities[self::GS_TALK];
}
/**
continue;
}
- if ( $i++ === 0 || $i === $this->url_limit + 1 || $length + $this->limit[1] + $this->limit[2] > $this->size_limit ) {
+ if ( $i++ === 0
+ || $i === $this->url_limit + 1
+ || $length + $this->limit[1] + $this->limit[2] > $this->size_limit
+ ) {
if ( $this->file !== false ) {
$this->write( $this->file, $this->closeFile() );
$this->close( $this->file );
if ( $vCode == $wgContLang->getCode() ) {
continue; // we don't want default variant
}
- $entry = $this->fileEntry( $title->getCanonicalURL( '', $vCode ), $date, $this->priority( $namespace ) );
+ $entry = $this->fileEntry(
+ $title->getCanonicalURL( '', $vCode ),
+ $date,
+ $this->priority( $namespace )
+ );
$length += strlen( $entry );
$this->write( $this->file, $entry );
}
function open( $file, $flags ) {
$resource = $this->compress ? gzopen( $file, $flags ) : fopen( $file, $flags );
if ( $resource === false ) {
- throw new MWException( __METHOD__ . " error opening file $file with flags $flags. Check permissions?" );
+ throw new MWException( __METHOD__
+ . " error opening file $file with flags $flags. Check permissions?" );
}
return $resource;
}
$this->limit = array(
strlen( $this->openFile() ),
- strlen( $this->fileEntry( $title->getCanonicalURL(), wfTimestamp( TS_ISO_8601, wfTimestamp() ), $this->priority( $namespace ) ) ),
+ strlen( $this->fileEntry(
+ $title->getCanonicalURL(),
+ wfTimestamp( TS_ISO_8601, wfTimestamp() ),
+ $this->priority( $namespace )
+ ) ),
strlen( $this->closeFile() )
);
}
$titleText = $title->getPrefixedText();
$this->error( "Page $titleText does not exist.\n", true );
}
- $content = $rev->getContent( $this->hasOption( 'show-private' ) ? Revision::RAW : Revision::FOR_PUBLIC );
+ $content = $rev->getContent( $this->hasOption( 'show-private' )
+ ? Revision::RAW
+ : Revision::FOR_PUBLIC );
+
if ( $content === false ) {
$titleText = $title->getPrefixedText();
$this->error( "Couldn't extract the text from $titleText.\n", true );
function __construct() {
parent::__construct();
- $gz = in_array( 'compress.zlib', stream_get_wrappers() ) ? 'ok' : '(disabled; requires PHP zlib module)';
- $bz2 = in_array( 'compress.bzip2', stream_get_wrappers() ) ? 'ok' : '(disabled; requires PHP bzip2 module)';
+ $gz = in_array( 'compress.zlib', stream_get_wrappers() )
+ ? 'ok'
+ : '(disabled; requires PHP zlib module)';
+ $bz2 = in_array( 'compress.bzip2', stream_get_wrappers() )
+ ? 'ok'
+ : '(disabled; requires PHP bzip2 module)';
$this->mDescription = <<<TEXT
This script reads pages from an XML file as produced from Special:Export or
$this->addOption( 'dry-run', 'Parse dump without actually importing pages' );
$this->addOption( 'debug', 'Output extra verbose debug information' );
$this->addOption( 'uploads', 'Process file upload data if included (experimental)' );
- $this->addOption( 'no-updates', 'Disable link table updates. Is faster but leaves the wiki in an inconsistent state' );
+ $this->addOption(
+ 'no-updates',
+ 'Disable link table updates. Is faster but leaves the wiki in an inconsistent state'
+ );
$this->addOption( 'image-base-path', 'Import files from a specified path', false, true );
$this->addArg( 'file', 'Dump file to import [else use stdin]', false );
}
return false;
}
-# FIXME: Access the api in a saner way and performing just one query (preferably batching files too).
+# @todo FIXME: Access the api in a saner way and performing just one query
+# (preferably batching files too).
function getFileCommentFromSourceWiki( $wiki_host, $file ) {
- $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=comment';
+ $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:'
+ . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=comment';
$body = Http::get( $url );
if ( preg_match( '#<ii comment="([^"]*)" />#', $body, $matches ) == 0 ) {
return false;
}
function getFileUserFromSourceWiki( $wiki_host, $file ) {
- $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=user';
+ $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:'
+ . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=user';
$body = Http::get( $url );
if ( preg_match( '#<ii user="([^"]*)" />#', $body, $matches ) == 0 ) {
return false;