From: Alexandre Emsenhuber Date: Sun, 16 Aug 2009 19:23:34 +0000 (+0000) Subject: * Update nextJobDB.php and cleanupSpam.php to work with wikis using a prefix for... X-Git-Tag: 1.31.0-rc.0~40274 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=commitdiff_plain;h=ea9db3b303da8b5da4dce73c34b218124f757946;p=lhc%2Fweb%2Fwiklou.git * Update nextJobDB.php and cleanupSpam.php to work with wikis using a prefix for database tables * Adding a note that nextJobDB.php doesn't work with PostgreSQL * Pass the wiki through the --wiki option in cleanupSpam.php to not be Wikimedia-only and quote the sed regex to avoid errors due to spaces --- diff --git a/maintenance/cleanupSpam.php b/maintenance/cleanupSpam.php index 7da4a24a1f..f9e897eadf 100644 --- a/maintenance/cleanupSpam.php +++ b/maintenance/cleanupSpam.php @@ -44,20 +44,19 @@ class CleanupSpam extends Maintenance { 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 ) { @@ -67,11 +66,13 @@ class CleanupSpam extends Maintenance { } } 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 ) { diff --git a/maintenance/nextJobDB.php b/maintenance/nextJobDB.php index 6e634b2027..2244532bae 100644 --- a/maintenance/nextJobDB.php +++ b/maintenance/nextJobDB.php @@ -17,6 +17,7 @@ * 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 */ @@ -65,18 +66,23 @@ class nextJobDB extends 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;