r55152 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55151‎ | r55152 | r55153 >
Date:19:23, 16 August 2009
Author:ialex
Status:ok
Tags:
Comment:
* 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
Modified paths:
  • /trunk/phase3/maintenance/cleanupSpam.php (modified) (history)
  • /trunk/phase3/maintenance/nextJobDB.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/nextJobDB.php
@@ -17,6 +17,7 @@
1818 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919 * http://www.gnu.org/copyleft/gpl.html
2020 *
 21+ * @todo Make this work on PostgreSQL and maybe other database servers
2122 * @ingroup Maintenance
2223 */
2324
@@ -65,18 +66,23 @@
6667 foreach ( $dbsByMaster as $master => $dbs ) {
6768 $dbConn = wfGetDB( DB_MASTER, array(), $dbs[0] );
6869 $stype = $dbConn->addQuotes($type);
69 - $jobTable = $dbConn->tableName( 'job' );
 70+
7071
7172 # Padding row for MySQL bug
7273 $sql = "(SELECT '-------------------------------------------' as db)";
73 - foreach ( $dbs as $dbName ) {
 74+ foreach ( $dbs as $wikiId ) {
7475 if ( $sql != '' ) {
7576 $sql .= ' UNION ';
7677 }
77 - if ($type === false)
78 - $sql .= "(SELECT '$dbName' as db FROM `$dbName`.$jobTable LIMIT 1)";
 78+
 79+ list( $dbName, $tablePrefix ) = wfSplitWikiID( $wikiId );
 80+ $dbConn->tablePrefix( $tablePrefix );
 81+ $jobTable = $dbConn->tableName( 'job' );
 82+
 83+ if ( $type === false )
 84+ $sql .= "(SELECT '$wikiId' as db FROM $dbName.$jobTable LIMIT 1)";
7985 else
80 - $sql .= "(SELECT '$dbName' as db FROM `$dbName`.$jobTable WHERE job_cmd=$stype LIMIT 1)";
 86+ $sql .= "(SELECT '$wikiId' as db FROM $dbName.$jobTable WHERE job_cmd=$stype LIMIT 1)";
8187 }
8288 $res = $dbConn->query( $sql, __METHOD__ );
8389 $first = true;
Index: trunk/phase3/maintenance/cleanupSpam.php
@@ -44,20 +44,19 @@
4545 if ( !$like ) {
4646 $this->error( "Not a valid hostname specification: $spec", true );
4747 }
48 -
49 - $dbr = wfGetDB( DB_SLAVE );
5048
5149 if ( $this->hasOption('all') ) {
5250 // Clean up spam on all wikis
53 - $dbr = wfGetDB( DB_SLAVE );
54 - $this->output( "Finding spam on " . count($wgLocalDatabases) . " wikis\n" );
 51+ $this->output( "Finding spam on " . count( $wgLocalDatabases ) . " wikis\n" );
5552 $found = false;
56 - foreach ( $wgLocalDatabases as $db ) {
57 - $count = $dbr->selectField( "`$db`.externallinks", 'COUNT(*)',
 53+ foreach ( $wgLocalDatabases as $wikiID ) {
 54+ $dbr = wfGetDB( DB_SLAVE, array(), $wikiID );
 55+
 56+ $count = $dbr->selectField( 'externallinks', 'COUNT(*)',
5857 array( 'el_index LIKE ' . $dbr->addQuotes( $like ) ), __METHOD__ );
5958 if ( $count ) {
6059 $found = true;
61 - passthru( "php cleanupSpam.php $db $spec | sed s/^/$db: /" );
 60+ passthru( "php cleanupSpam.php --wiki='$wikiID' $spec | sed 's/^/$wikiID: /'" );
6261 }
6362 }
6463 if ( $found ) {
@@ -67,11 +66,13 @@
6867 }
6968 } else {
7069 // Clean up spam on this wiki
 70+
 71+ $dbr = wfGetDB( DB_SLAVE );
7172 $res = $dbr->select( 'externallinks', array( 'DISTINCT el_from' ),
7273 array( 'el_index LIKE ' . $dbr->addQuotes( $like ) ), __METHOD__ );
7374 $count = $dbr->numRows( $res );
7475 $this->output( "Found $count articles containing $spec\n" );
75 - while ( $row = $dbr->fetchObject( $res ) ) {
 76+ foreach ( $res as $row ) {
7677 $this->cleanupArticle( $row->el_from, $spec );
7778 }
7879 if ( $count ) {

Status & tagging log