aboutsummaryrefslogtreecommitdiffstats
path: root/maintenance/initEditCount.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@users.mediawiki.org>2006-12-14 13:22:52 +0000
committerBrion Vibber <brion@users.mediawiki.org>2006-12-14 13:22:52 +0000
commit288a7eb7f18ebc1f98f6ad65ede01c9ea39d9e9b (patch)
treef0a2905d1a7688fb6f5f1dd09194e0f2bd1fc86b /maintenance/initEditCount.php
parentfc39e18f0ebec16df7482441a3e250934b82a356 (diff)
downloadmediawikicore-288a7eb7f18ebc1f98f6ad65ede01c9ea39d9e9b.tar.gz
mediawikicore-288a7eb7f18ebc1f98f6ad65ede01c9ea39d9e9b.zip
Going ahead and adding this field while other DB updates are pending.
Interfaces to use it can be added shortly. * Add user_editcount field to provide data for heuristics on account use. Incremented on edit, with lazy initialization from past revision data. Can batch-initialize with maintenance/initEditCount.php (not yet friendly to replication environments, this will do all accounts in one query). * Allow raw SQL subsections in Database::update() SET portion as well as for WHERE portion. Handy for increments and such.
Notes
Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/18325
Diffstat (limited to 'maintenance/initEditCount.php')
-rw-r--r--maintenance/initEditCount.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/maintenance/initEditCount.php b/maintenance/initEditCount.php
new file mode 100644
index 000000000000..a975f356162d
--- /dev/null
+++ b/maintenance/initEditCount.php
@@ -0,0 +1,40 @@
+<?php
+
+require_once "commandLine.inc";
+
+// @fixme: add replication-friendly batch mode
+
+$dbw = wfGetDB( DB_MASTER );
+$user = $dbw->tableName( 'user' );
+$revision = $dbw->tableName( 'revision' );
+
+$dbver = $dbw->getServerVersion();
+if( ($dbw instanceof DatabaseMySql && version_compare( $dbver, '4.1' ) < 0)
+ || isset( $options['force-mysql4'] ) ) {
+
+ echo "Warning: MySQL $dbver; using hacky MySQL 4.0 compatibility query...\n";
+ $sql = "CREATE TEMPORARY TABLE temp_editcount (
+ temp_user_id INT,
+ temp_user_editcount INT
+ )";
+ $dbw->query( $sql );
+
+ $sql = "INSERT INTO temp_editcount
+ (temp_user_id, temp_user_editcount)
+ SELECT rev_user, COUNT(rev_user)
+ FROM $revision GROUP BY rev_user";
+ $dbw->query( $sql );
+
+ $sql = "UPDATE $user
+ LEFT OUTER JOIN temp_editcount ON user_id=temp_user_id
+ SET user_editcount=IF(temp_user_editcount IS NULL,0,temp_user_editcount)";
+ $dbw->query( $sql );
+} else {
+ // Subselect should work on modern MySQLs etc
+ $sql = "UPDATE $user SET user_editcount=(SELECT COUNT(*) FROM $revision WHERE rev_user=user_id)";
+ $dbw->query( $sql );
+}
+
+echo "Done!\n";
+
+?>