if ( !$like ) {
$this->error( "Not a valid hostname specification: $spec", true );
}
-
- $dbr = wfGetDB( DB_SLAVE );
if ( $this->hasOption('all') ) {
// Clean up spam on all wikis
- $dbr = wfGetDB( DB_SLAVE );
- $this->output( "Finding spam on " . count($wgLocalDatabases) . " wikis\n" );
+ $this->output( "Finding spam on " . count( $wgLocalDatabases ) . " wikis\n" );
$found = false;
- foreach ( $wgLocalDatabases as $db ) {
- $count = $dbr->selectField( "`$db`.externallinks", 'COUNT(*)',
+ foreach ( $wgLocalDatabases as $wikiID ) {
+ $dbr = wfGetDB( DB_SLAVE, array(), $wikiID );
+
+ $count = $dbr->selectField( 'externallinks', 'COUNT(*)',
array( 'el_index LIKE ' . $dbr->addQuotes( $like ) ), __METHOD__ );
if ( $count ) {
$found = true;
- passthru( "php cleanupSpam.php $db $spec | sed s/^/$db: /" );
+ passthru( "php cleanupSpam.php --wiki='$wikiID' $spec | sed 's/^/$wikiID: /'" );
}
}
if ( $found ) {
}
} else {
// Clean up spam on this wiki
+
+ $dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( 'externallinks', array( 'DISTINCT el_from' ),
array( 'el_index LIKE ' . $dbr->addQuotes( $like ) ), __METHOD__ );
$count = $dbr->numRows( $res );
$this->output( "Found $count articles containing $spec\n" );
- while ( $row = $dbr->fetchObject( $res ) ) {
+ foreach ( $res as $row ) {
$this->cleanupArticle( $row->el_from, $spec );
}
if ( $count ) {
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
+ * @todo Make this work on PostgreSQL and maybe other database servers
* @ingroup Maintenance
*/
foreach ( $dbsByMaster as $master => $dbs ) {
$dbConn = wfGetDB( DB_MASTER, array(), $dbs[0] );
$stype = $dbConn->addQuotes($type);
- $jobTable = $dbConn->tableName( 'job' );
+
# Padding row for MySQL bug
$sql = "(SELECT '-------------------------------------------' as db)";
- foreach ( $dbs as $dbName ) {
+ foreach ( $dbs as $wikiId ) {
if ( $sql != '' ) {
$sql .= ' UNION ';
}
- if ($type === false)
- $sql .= "(SELECT '$dbName' as db FROM `$dbName`.$jobTable LIMIT 1)";
+
+ list( $dbName, $tablePrefix ) = wfSplitWikiID( $wikiId );
+ $dbConn->tablePrefix( $tablePrefix );
+ $jobTable = $dbConn->tableName( 'job' );
+
+ if ( $type === false )
+ $sql .= "(SELECT '$wikiId' as db FROM $dbName.$jobTable LIMIT 1)";
else
- $sql .= "(SELECT '$dbName' as db FROM `$dbName`.$jobTable WHERE job_cmd=$stype LIMIT 1)";
+ $sql .= "(SELECT '$wikiId' as db FROM $dbName.$jobTable WHERE job_cmd=$stype LIMIT 1)";
}
$res = $dbConn->query( $sql, __METHOD__ );
$first = true;