public $minTs = false;
function execute() {
- $this->dbw = wfGetDB( DB_MASTER );
+ $this->dbw = $this->getDB( DB_MASTER );
$logging = $this->dbw->tableName( 'logging' );
$logging_1_10 = $this->dbw->tableName( 'logging_1_10' );
$logging_pre_1_10 = $this->dbw->tableName( 'logging_pre_1_10' );
public function execute() {
$this->output( "Looking for pages with page_latest set to 0...\n" );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$conds = array( 'page_latest' => 0 );
if ( $this->hasOption( 'regenerate-all' ) ) {
$conds = '';
}
public function execute() {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$test = $dbw->tableName( 'test' );
$dbw->query( "CREATE TABLE IF NOT EXISTS /*_*/$test (
* @return bool|string Revision ID, or false if not found or error
*/
function getRevIdForTime( Title $title, $timestamp ) {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$id = $dbr->selectField(
array( 'revision', 'page' ),
public function execute() {
$this->output( "Fetching redirects...\n" );
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$result = $dbr->select(
array( 'page' ),
array( 'page_namespace', 'page_title', 'page_latest' ),
public function execute() {
$start = '';
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$numImages = 0;
$numGood = 0;
}
function execute() {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$maxUserId = 0;
do {
);
}
- $db = wfGetDB( DB_MASTER );
+ $db = $this->getDB( DB_MASTER );
$ancientTables = array(
'blobs', // 1.4
'brokenlinks', // 1.4
}
public function execute() {
- $db = wfGetDB( DB_MASTER );
+ $db = $this->getDB( DB_MASTER );
$max = $db->selectField( 'ipblocks', 'MAX(ipb_user)' );
$this->output( "DRY RUN: would delete bogus row '$name'\n" );
} else {
$this->output( "deleting bogus row '$name'\n" );
- $db = wfGetDB( DB_MASTER );
+ $db = $this->getDB( DB_MASTER );
$db->delete( 'image',
array( 'img_name' => $name ),
__METHOD__ );
return;
}
- $db = wfGetDB( DB_MASTER );
+ $db = $this->getDB( DB_MASTER );
/*
* To prevent key collisions in the update() statements below,
}
public function execute() {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$rl = new ResourceLoader( ConfigFactory::getDefaultInstance()->makeConfig( 'main' ) );
$moduleNames = $rl->getModuleNames();
$moduleList = implode( ', ', array_map( array( $dbw, 'addQuotes' ), $moduleNames ) );
$this->output( "Finding spam on " . count( $wgLocalDatabases ) . " wikis\n" );
$found = false;
foreach ( $wgLocalDatabases as $wikiID ) {
- $dbr = wfGetDB( DB_SLAVE, array(), $wikiID );
+ $dbr = $this->getDB( DB_SLAVE, array(), $wikiID );
$count = $dbr->selectField( 'externallinks', 'COUNT(*)',
array( 'el_index' . $dbr->buildLike( $like ) ), __METHOD__ );
} else {
// Clean up spam on this wiki
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$res = $dbr->select( 'externallinks', array( 'DISTINCT el_from' ),
array( 'el_index' . $dbr->buildLike( $like ) ), __METHOD__ );
$count = $dbr->numRows( $res );
// This happens e.g. when a link comes from a template rather than the page itself
$this->output( "False match\n" );
} else {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$this->beginTransaction( $dbw, __METHOD__ );
$page = WikiPage::factory( $title );
if ( $rev ) {
* @throws MWException
*/
public function runTable( $params ) {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
if ( array_diff( array_keys( $params ),
array( 'table', 'conds', 'index', 'callback' ) )
protected function fileExists( $name ) {
// XXX: Doesn't actually check for file existence, just presence of image record.
// This is reasonable, since cleanupImages.php only iterates over the image table.
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$row = $dbr->selectRow( 'image', array( 'img_name' ), array( 'img_name' => $name ), __METHOD__ );
return $row !== false;
} else {
$this->output( "renaming $row->page_id ($row->page_namespace," .
"'$row->page_title') to ($row->page_namespace,'$dest')\n" );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$dbw->update( 'page',
array( 'page_title' => $dest ),
array( 'page_id' => $row->page_id ),
} else {
$this->output( "renaming $row->page_id ($row->page_namespace," .
"'$row->page_title') to ($ns,'$dest')\n" );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$dbw->update( 'page',
array(
'page_namespace' => $ns,
private function removeWatch( $row ) {
if ( !$this->dryrun && $this->hasOption( 'fix' ) ) {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$dbw->delete(
'watchlist', array(
'wl_user' => $row->wl_user,
public function execute() {
global $wgLocalDatabases, $wgMemc;
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$res = $dbr->select( 'interwiki', array( 'iw_prefix' ), false );
$prefixes = array();
foreach ( $res as $row ) {
}
public function execute() {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$type = $dbw->getType();
if ( $type != 'mysql' ) {
}
private function createTempTable() {
- $dbConn = wfGetDB( DB_MASTER );
+ $dbConn = $this->getDB( DB_MASTER );
if ( !( $dbConn->isOpen() ) ) {
$this->output( "Opening connection to database failed.\n" );
public function execute() {
$this->output( "...batch conversion of user_options: " );
$id = 0;
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
if ( !$dbw->fieldExists( 'user', 'user_options', __METHOD__ ) ) {
$this->output( "nothing to migrate. " );
$this->error( "Unable to read file, exiting", true );
}
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
# Handle each entry
// @codingStandardsIgnoreStart Ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
global $wgUser;
$this->output( "Checking existence of old default messages..." );
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$res = $dbr->select( array( 'page', 'revision' ),
array( 'page_namespace', 'page_title' ),
array(
# Handle deletion
$this->output( "\n...deleting old default messages (this may take a long time!)...", 'msg' );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
foreach ( $res as $row ) {
wfWaitForSlaves();
// Handle deletion
$this->output( "\n...deleting equal messages (this may take a long time!)..." );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
foreach ( $messageInfo['results'] as $result ) {
wfWaitForSlaves();
$dbw->ping();
function doDelete( $delete = false, $args = array() ) {
# Data should come off the master, wrapped in a transaction
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$this->beginTransaction( $dbw, __METHOD__ );
$pageConds = array();
$report = $this->hasOption( 'report' );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$this->beginTransaction( $dbw, __METHOD__ );
list( $page, $revision ) = $dbw->tableNamesN( 'page', 'revision' );
$this->output( "Deleting revision(s) " . implode( ',', $this->mArgs ) .
" from " . wfWikiID() . "...\n" );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$affected = 0;
foreach ( $this->mArgs as $revID ) {
public function execute() {
global $wgServer;
$this->output( "Deleting self externals from $wgServer\n" );
- $db = wfGetDB( DB_MASTER );
+ $db = $this->getDB( DB_MASTER );
while ( 1 ) {
wfWaitForSlaves();
$this->commitTransaction( $db, __METHOD__ );
}
public function execute() {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$result = $dbr->select( array( 'pagelinks', 'page' ),
array(
'page_id',
* @param bool $shared True to pass shared-dir settings to hash func
*/
function fetchUsed( $shared ) {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$image = $dbr->tableName( 'image' );
$imagelinks = $dbr->tableName( 'imagelinks' );
* @param bool $shared True to pass shared-dir settings to hash func
*/
function fetchLocal( $shared ) {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$result = $dbr->select( 'image',
array( 'img_name' ),
'',
}
$afile = false;
} else { // specified version
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$row = $dbw->selectRow( 'filearchive', '*',
array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $filekey ),
__METHOD__ );
}
protected function scrubAllVersions( $name ) {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$res = $dbw->select( 'filearchive', '*',
array( 'fa_name' => $name, 'fa_storage_group' => 'deleted' ),
__METHOD__ );
* note that the text string itself is *not* followed by newline
*/
public function execute() {
- $db = wfGetDB( DB_SLAVE );
+ $db = $this->getDB( DB_SLAVE );
$stdin = $this->getStdin();
while ( !feof( $stdin ) ) {
$line = fgets( $stdin );
return true;
}
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$namespaces = array(
NS_MEDIAWIKI => $dbr->buildLike( $dbr->anyString(), '.json' ),
NS_USER => $dbr->buildLike( $dbr->anyString(), '/', $dbr->anyString(), '.json' ),
$this->output( "Processing {$title} ({$row->page_id})...\n" );
$rev = Revision::newFromTitle( $title );
$content = $rev->getContent( Revision::RAW );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
if ( $content instanceof JsonContent ) {
if ( $content->isValid() ) {
// Yay, actually JSON. We need to just change the
$title = null;
}
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
// See also SpecialDoubleRedirects
$tables = array(
}
protected function doDBUpdates() {
- $db = wfGetDB( DB_MASTER );
+ $db = $this->getDB( DB_MASTER );
if ( !$db->tableExists( 'externallinks' ) ) {
$this->error( "externallinks table does not exist" );
$grace = 60; // maximum normal clock offset
# Find bounding revision IDs
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$revisionTable = $dbw->tableName( 'revision' );
$res = $dbw->query( "SELECT MIN(rev_id) as minrev, MAX(rev_id) as maxrev FROM $revisionTable " .
"WHERE rev_timestamp BETWEEN '{$start}' AND '{$end}'", __METHOD__ );
}
public function execute() {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$lastId = 0;
do {
$this->identifier = $this->getOption( 'identifier', wfWikiID() );
$this->compress = $this->getOption( 'compress', 'yes' ) !== 'no';
$this->skipRedirects = $this->getOption( 'skip-redirects', false ) !== false;
- $this->dbr = wfGetDB( DB_SLAVE );
+ $this->dbr = $this->getDB( DB_SLAVE );
$this->generateNamespaces();
$this->timestamp = wfTimestamp( TS_ISO_8601, wfTimestampNow() );
$this->findex = fopen( "{$this->fspath}sitemap-index-{$this->identifier}.xml", 'wb' );
if ( $wgAllDBsAreLocalhost ) {
$host = 'localhost';
} elseif ( $this->hasOption( 'group' ) ) {
- $db = wfGetDB( DB_SLAVE, $this->getOption( 'group' ) );
+ $db = $this->getDB( DB_SLAVE, $this->getOption( 'group' ) );
$host = $db->getServer();
} else {
$lb = wfGetLB();
}
public function execute() {
- $this->db = wfGetDB( DB_SLAVE );
-
$titleText = $this->getArg( 0 );
$title = Title::newFromText( $titleText );
if ( !$title ) {
if ( !$this->dryRun ) {
// bluuuh hack
// call_user_func( $this->uploadCallback, $revision );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
return $dbw->deadlockLoop( array( $revision, 'importUpload' ) );
}
}
public function execute() {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$user = $dbw->tableName( 'user' );
$revision = $dbw->tableName( 'revision' );
if ( $backgroundMode ) {
$this->output( "Using replication-friendly background mode...\n" );
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$chunkSize = 100;
$lastUser = $dbr->selectField( 'user', 'MAX(user_id)', '', __METHOD__ );
if ( $this->hasOption( 'active' ) ) {
$this->output( "\nCounting and updating active users..." );
- $active = SiteStatsUpdate::cacheUpdate( wfGetDB( DB_MASTER ) );
+ $active = SiteStatsUpdate::cacheUpdate( $this->getDB( DB_MASTER ) );
$this->output( "{$active}\n" );
}
$count = 0;
$oldGroup = $this->getArg( 0 );
$newGroup = $this->getArg( 1 );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$start = $dbw->selectField( 'user_groups', 'MIN(ug_user)',
array( 'ug_group' => $oldGroup ), __FUNCTION__ );
$end = $dbw->selectField( 'user_groups', 'MAX(ug_user)',
}
# Setup complete, now start
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
// @codingStandardsIgnoreStart Ignore avoid function calls in a FOR loop test part warning
for ( $linenum = 1; !feof( $file ); $linenum++ ) {
// @codingStandardsIgnoreEnd
}
public function execute() {
- $this->db = wfGetDB( DB_MASTER );
+ $this->db = $this->getDB( DB_MASTER );
$options = array(
'fix' => $this->hasOption( 'fix' ),
$ns = $this->getOption( 'ns', NS_MEDIAWIKI );
$delete = $this->getOption( 'delete', false );
$all = $this->getOption( 'all', false );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$this->beginTransaction( $dbw, __METHOD__ );
$tbl_pag = $dbw->tableName( 'page' );
$name = $this->getArg();
$delete = $this->getOption( 'delete', false );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$this->beginTransaction( $dbw, __METHOD__ );
$tbl_pag = $dbw->tableName( 'page' );
}
public function deleteRevisions( $ids ) {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$this->beginTransaction( $dbw, __METHOD__ );
$tbl_rev = $dbw->tableName( 'revision' );
return;
}
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
foreach ( $wgSharedTables as $table ) {
$stable = $dbw->tableNameInternal( $table );
if ( $wgSharedPrefix != null ) {
* @param bool $fix Whether to fix broken revisions when found
*/
private function checkOrphans( $fix ) {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$page = $dbw->tableName( 'page' );
$revision = $dbw->tableName( 'revision' );
* but valid revisions do exist)
*/
private function checkWidows( $fix ) {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$page = $dbw->tableName( 'page' );
$revision = $dbw->tableName( 'revision' );
* @param bool $fix Whether to fix broken entries
*/
private function checkSeparation( $fix ) {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$page = $dbw->tableName( 'page' );
$revision = $dbw->tableName( 'revision' );
}
public function execute() {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
foreach ( $this->mArgs as $arg ) {
$files = array(
$arg,
$throttle = $this->getOption( 'throttle', 0 );
$force = $this->getOption( 'force', false );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
if ( !$force ) {
$row = $dbw->selectRow(
}
public function execute() {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$ns = $this->getOption( 'ns' );
if ( !ctype_digit( $ns ) && $ns !== 'all' ) {
$this->error( 'Invalid namespace', 1 );
public function doDBUpdates() {
$startTime = microtime( true );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$table = 'filearchive';
$conds = array( 'fa_sha1' => '', 'fa_storage_key IS NOT NULL' );
$isRegen = ( $force || $file != '' ); // forced recalculation?
$t = -microtime( true );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
if ( $file != '' ) {
$res = $dbw->select(
'image',
}
protected function doDBUpdates() {
- $db = wfGetDB( DB_MASTER );
+ $db = $this->getDB( DB_MASTER );
if ( !$db->tableExists( 'revision' ) ) {
$this->error( "revision table does not exist" );
* @param int|bool $namespace
*/
private function purgeNamespace( $namespace = false ) {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$startId = 0;
if ( $namespace === false ) {
$conds = array();
* @return int Number of entries changed, or that would be changed
*/
private function doReassignEdits( &$from, &$to, $rc = false, $report = false ) {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$this->beginTransaction( $dbw, __METHOD__ );
# Count things
$this->output( "Building content page file cache from page {$start}!\n" );
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$overwrite = $this->getOption( 'overwrite', false );
$start = ( $start > 0 )
? $start
$blockStart = $start;
$blockEnd = $start + $this->mBatchSize - 1;
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
// Go through each page and save the output
while ( $blockEnd <= $end ) {
// Get the pages
}
public function execute() {
- $this->dbw = wfGetDB( DB_MASTER );
+ $this->dbw = $this->getDB( DB_MASTER );
$this->dryrun = $this->hasOption( 'dry-run' );
if ( $this->dryrun ) {
$GLOBALS['wgReadOnly'] = 'Dry run mode, image upgrades are suppressed';
$this->init( $count, $table );
$this->output( "Processing $table...\n" );
- $result = wfGetDB( DB_SLAVE )->select( $table, '*', array(), __METHOD__ );
+ $result = $this->getDB( DB_SLAVE )->select( $table, '*', array(), __METHOD__ );
foreach ( $result as $row ) {
$update = call_user_func( $callback, $row, null );
public function execute() {
// Rebuild the text index
- if ( wfGetDB( DB_SLAVE )->getType() != 'postgres' ) {
+ if ( $this->getDB( DB_SLAVE )->getType() != 'postgres' ) {
$this->output( "** Rebuilding fulltext search index (if you abort "
. "this will break searching; run this script again to fix):\n" );
$rebuildText = $this->runChild( 'RebuildTextIndex', 'rebuildtextindex.php' );
* Rebuild pass 1: Insert `recentchanges` entries for page revisions.
*/
private function rebuildRecentChangesTablePass1() {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$dbw->delete( 'recentchanges', '*' );
* (rc_last_oldid, rc_new etc.) and size differences (rc_old_len, rc_new_len).
*/
private function rebuildRecentChangesTablePass2() {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
list( $recentchanges, $revision ) = $dbw->tableNamesN( 'recentchanges', 'revision' );
$this->output( "Updating links and size differences...\n" );
* Rebuild pass 3: Insert `recentchanges` entries for action logs.
*/
private function rebuildRecentChangesTablePass3() {
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$this->output( "Loading from user, page, and logging tables...\n" );
private function rebuildRecentChangesTablePass4() {
global $wgUseRCPatrol;
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
list( $recentchanges, $usergroups, $user ) =
$dbw->tableNamesN( 'recentchanges', 'user_groups', 'user' );
public function execute() {
// Shouldn't be needed for Postgres
- $this->db = wfGetDB( DB_MASTER );
+ $this->db = $this->getDB( DB_MASTER );
if ( $this->db->getType() == 'postgres' ) {
$this->error( "This script is not needed when using Postgres.\n", true );
}
- $this->db = wfGetDB( DB_MASTER );
if ( $this->db->getType() == 'sqlite' ) {
if ( !DatabaseSqlite::getFulltextSearchModule() ) {
$this->error( "Your version of SQLite module for PHP doesn't "
$end = str_replace( ' ', '_', $this->getOption( 'end', '' ) ); // page on img_name
$count = 0;
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
do {
$conds = array( "img_name > {$dbr->addQuotes( $start )}" );
if ( strlen( $end ) ) {
$leftAlone = 0;
$error = 0;
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
if ( $this->mBatchSize <= 0 ) {
$this->error( "Batch size is too low...", 12 );
}
global $wgParser;
$reportingInterval = 100;
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
if ( $start === null ) {
$start = 1;
*/
private function fixRedirect( $id ) {
$page = WikiPage::newFromID( $id );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
if ( $page === null ) {
// This page doesn't exist (any more)
) {
wfWaitForSlaves();
$this->output( "Deleting illegal entries from the links tables...\n" );
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
do {
// Find the start of the next chunk. This is based only
// on existent page_ids.
* @param int $batchSize The size of deletion batches
*/
private function dfnCheckInterval( $start = null, $end = null, $batchSize = 100 ) {
- $dbw = wfGetDB( DB_MASTER );
- $dbr = wfGetDB( DB_SLAVE );
+ $dbw = $this->getDB( DB_MASTER );
+ $dbr = $this->getDB( DB_SLAVE );
$linksTables = array( // table name => page_id field
'pagelinks' => 'pl_from',
# Do an initial scan for inactive accounts and report the result
$this->output( "Checking for unused user accounts...\n" );
$del = array();
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$res = $dbr->select( 'user', array( 'user_id', 'user_name', 'user_touched' ), '', __METHOD__ );
if ( $this->hasOption( 'ignore-groups' ) ) {
$excludedGroups = explode( ',', $this->getOption( 'ignore-groups' ) );
# If required, go back and delete each marked account
if ( $count > 0 && $this->hasOption( 'delete' ) ) {
$this->output( "\nDeleting unused accounts..." );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$dbw->delete( 'user', array( 'user_id' => $del ), __METHOD__ );
$dbw->delete( 'user_groups', array( 'ug_user' => $del ), __METHOD__ );
$dbw->delete( 'user_former_groups', array( 'ufg_user' => $del ), __METHOD__ );
* @return bool
*/
private function isInactiveAccount( $id, $master = false ) {
- $dbo = wfGetDB( $master ? DB_MASTER : DB_SLAVE );
+ $dbo = $this->getDB( $master ? DB_MASTER : DB_SLAVE );
$checks = array(
'revision' => 'rev',
'archive' => 'ar',
$this->output( "Renaming DB prefix for tables of $wgDBname from '$old' to '$new'\n" );
$count = 0;
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$res = $dbw->query( "SHOW TABLES " . $dbw->buildLike( $old, $dbw->anyString() ) );
foreach ( $res as $row ) {
// XXX: odd syntax. MySQL outputs an oddly cased "Tables of X"
}
// We list user by user_id from one of the slave database
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$where = array();
if ( $this->nullsOnly ) {
* @return array
*/
private function getRollbackTitles( $user ) {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$titles = array();
$results = $dbr->select(
array( 'page', 'revision' ),
$query = $this->getArg();
$n = 1;
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
do {
$this->output( "Batch $n: " );
$n++;
);
// Get cached stats from slave database
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$stats = $dbr->selectRow( 'site_stats', '*', '', __METHOD__ );
// Get maximum size for each column
return;
}
- $this->db = wfGetDB( DB_MASTER );
+ $this->db = $this->getDB( DB_MASTER );
if ( $this->db->getType() != 'sqlite' ) {
$this->error( "This maintenance script requires a SQLite database.\n" );
private function compressOldPages( $start = 0, $extdb = '' ) {
$chunksize = 50;
$this->output( "Starting from old_id $start...\n" );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
do {
$res = $dbw->select(
'text',
# print "Already compressed row {$row->old_id}\n";
return false;
}
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$flags = $row->old_flags ? "{$row->old_flags},gzip" : "gzip";
$compress = gzdeflate( $row->old_text );
) {
$loadStyle = self::LS_CHUNKED;
- $dbr = wfGetDB( DB_SLAVE );
- $dbw = wfGetDB( DB_MASTER );
+ $dbr = $this->getDB( DB_SLAVE );
+ $dbw = $this->getDB( DB_MASTER );
# Set up external storage
if ( $extdb != '' ) {
}
public function execute() {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$row = $dbr->selectRow(
array( 'text', 'revision' ),
array( 'old_flags', 'old_text' ),
}
function execute() {
- $dbr = wfGetDB( DB_SLAVE );
- $dbw = wfGetDB( DB_MASTER );
+ $dbr = $this->getDB( DB_SLAVE );
+ $dbw = $this->getDB( DB_MASTER );
$dryRun = $this->getOption( 'dry-run' );
if ( $dryRun ) {
unset( $this->mapCache[$key] );
}
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$map = array();
$res = $dbr->select( 'revision',
array( 'rev_id', 'rev_text_id' ),
}
public function execute() {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
if ( !$dbr->tableExists( 'blob_orphans' ) ) {
$this->error( "blob_orphans doesn't seem to exist, need to run trackBlobs.php first", true );
}
class StorageTypeStats extends Maintenance {
function execute() {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
$endId = $dbr->selectField( 'text', 'MAX(old_id)', false, __METHOD__ );
if ( !$endId ) {
}
$type = isset( $options['type'] ) ? $options['type'] : 'ConcatenatedGzipHistoryBlob';
-$dbr = wfGetDB( DB_SLAVE );
+$dbr = $this->getDB( DB_SLAVE );
$res = $dbr->select(
array( 'page', 'revision', 'text' ),
'*',
class TidyUpBug37714 extends Maintenance {
public function execute() {
// Search for all log entries which are about changing the visability of other log entries.
- $result = wfGetDB( DB_SLAVE )->select(
+ $result = $this->getDB( DB_SLAVE )->select(
'logging',
array( 'log_id', 'log_params' ),
array(
foreach ( $result as $row ) {
$paramLines = explode( "\n", $row->log_params );
$ids = explode( ',', $paramLines[0] ); // Array dereferencing is PHP >= 5.4 :(
- $result = wfGetDB( DB_SLAVE )->select( // Work out what log entries were changed here.
+ $result = $this->getDB( DB_SLAVE )->select( // Work out what log entries were changed here.
'logging',
'log_type',
array( 'log_id' => $ids ),
// If there's only one type, the target title can be set to include it.
$logTitle = SpecialPage::getTitleFor( 'Log', $result->current()->log_type )->getText();
$this->output( 'Set log_title to "' . $logTitle . '" for log entry ' . $row->log_id . ".\n" );
- wfGetDB( DB_MASTER )->update(
+ $this->getDB( DB_MASTER )->update(
'logging',
array( 'log_title' => $logTitle ),
array( 'log_id' => $row->log_id ),
# Attempt to connect to the database as a privileged user
# This will vomit up an error if there are permissions problems
- $db = wfGetDB( DB_MASTER );
+ $db = $this->getDB( DB_MASTER );
$this->output( "Going to run database updates for " . wfWikiID() . "\n" );
if ( $db->getType() === 'sqlite' ) {
$this->output( "Counting articles..." );
if ( $this->hasOption( 'use-master' ) ) {
- $dbr = wfGetDB( DB_MASTER );
+ $dbr = $this->getDB( DB_MASTER );
} else {
- $dbr = wfGetDB( DB_SLAVE, 'vslow' );
+ $dbr = $this->getDB( DB_SLAVE, 'vslow' );
}
$counter = new SiteStatsInit( $dbr );
$result = $counter->articles();
$this->output( "found {$result}.\n" );
if ( $this->hasOption( 'update' ) ) {
$this->output( "Updating site statistics table... " );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$dbw->update(
'site_stats',
array( 'ss_good_articles' => $result ),
public function execute() {
$maxLockTime = $this->getOption( 'l', 20 );
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
if ( $dbw->getType() !== 'mysql' ) {
$this->error( "This change is only needed on MySQL, quitting.\n", true );
}
}
public function execute() {
- $db = wfGetDB( DB_MASTER );
+ $db = $this->getDB( DB_MASTER );
if ( !$db->tableExists( 'page_restrictions' ) ) {
$this->error( "page_restrictions table does not exist", true );
}
$wgDisableSearchUpdate = false;
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$recentchanges = $dbw->tableName( 'recentchanges' );
$this->output( "Updating searchindex between $start and $end\n" );
public function execute() {
global $wgQueryCacheLimit, $wgDisableQueryPageUpdate;
- $dbw = wfGetDB( DB_MASTER );
+ $dbw = $this->getDB( DB_MASTER );
$this->doSpecialPageCacheUpdates( $dbw );