* Update nextJobDB.php and cleanupSpam.php to work with wikis using a prefix for...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 16 Aug 2009 19:23:34 +0000 (19:23 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 16 Aug 2009 19:23:34 +0000 (19:23 +0000)
* 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

maintenance/cleanupSpam.php
maintenance/nextJobDB.php

index 7da4a24..f9e897e 100644 (file)
@@ -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 ) {
index 6e634b2..2244532 100644 (file)
@@ -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;