MediaWiki r40279 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r40278‎ | r40279 (on ViewVC)‎ | r40280 >
Date:19:29, 31 August 2008
Author:aaron
Status:old
Tags:
Comment:
* Maintain active user count for Special:Statistics (bug 13585)
* Add a global to add update functions to updateSpecialPages.php
Modified paths:

Diff [purge]

Index: trunk/phase3/maintenance/archives/patch-ss_active_users.sql
===================================================================
--- trunk/phase3/maintenance/archives/patch-ss_active_users.sql	(revision 0)
+++ trunk/phase3/maintenance/archives/patch-ss_active_users.sql	(revision 40279)
@@ -0,0 +1,6 @@
+-- More statistics, for version 1.14
+
+ALTER TABLE /*$wgDBprefix*/site_stats ADD ss_active_users bigint default '-1';
+SELECT @activeusers := COUNT( DISTINCT rc_user_text ) FROM /*$wgDBprefix*/recentchanges 
+WHERE rc_user != 0 AND rc_bot = 0 AND rc_log_type != 'newusers';
+UPDATE /*$wgDBprefix*/site_stats SET ss_active_users=@activeusers;

Property changes on: trunk/phase3/maintenance/archives/patch-ss_active_users.sql
___________________________________________________________________
Added: svn:eol-style
   + native

Index: trunk/phase3/maintenance/postgres/tables.sql
===================================================================
--- trunk/phase3/maintenance/postgres/tables.sql	(revision 40278)
+++ trunk/phase3/maintenance/postgres/tables.sql	(revision 40279)
@@ -213,6 +213,7 @@
   ss_good_articles  INTEGER             DEFAULT 0,
   ss_total_pages    INTEGER            DEFAULT -1,
   ss_users          INTEGER            DEFAULT -1,
+  ss_active_users   INTEGER            DEFAULT -1,
   ss_admins         INTEGER            DEFAULT -1,
   ss_images         INTEGER            DEFAULT 0
 );
Index: trunk/phase3/maintenance/updateSpecialPages.php
===================================================================
--- trunk/phase3/maintenance/updateSpecialPages.php	(revision 40278)
+++ trunk/phase3/maintenance/updateSpecialPages.php	(revision 40279)
@@ -25,7 +25,31 @@
 $wgOut->disable();
 $dbw = wfGetDB( DB_MASTER );
 
-foreach ( $wgQueryPages as $page ) {
+foreach( $wgSpecialPageCacheUpdates as $special => $call ) {
+	if( !is_callable($call) ) {
+		print "Uncallable function $call!\n";
+		continue;
+	}
+	$t1 = explode( ' ', microtime() );
+	call_user_func( $call, $dbw );
+	$t2 = explode( ' ', microtime() );
+	printf( '%-30s ', $special );
+	$elapsed = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]);
+	$hours = intval( $elapsed / 3600 );
+	$minutes = intval( $elapsed % 3600 / 60 );
+	$seconds = $elapsed - $hours * 3600 - $minutes * 60;
+	if ( $hours ) {
+		print $hours . 'h ';
+	}
+	if ( $minutes ) {
+		print $minutes . 'm ';
+	}
+	printf( "completed in %.2fs\n", $seconds );
+	# Wait for the slave to catch up
+	wfWaitForSlaves( 5 );
+}
+
+foreach( $wgQueryPages as $page ) {
 	@list( $class, $special, $limit ) = $page;
 
 	# --list : just show the name of pages
@@ -50,33 +74,30 @@
 	}
 	$queryPage = new $class;
 
-	if( !(isset($options['only'])) or ($options['only'] == $queryPage->getName()) ) {
-	printf( '%-30s ',  $special );
+	if( !isset($options['only']) or $options['only'] == $queryPage->getName() ) {
+		printf( '%-30s ',  $special );
+		if ( $queryPage->isExpensive() ) {
+			$t1 = explode( ' ', microtime() );
+			# Do the query
+			$num = $queryPage->recache( $limit === null ? $wgQueryCacheLimit : $limit );
+			$t2 = explode( ' ', microtime() );
+			if ( $num === false ) {
+				print "FAILED: database error\n";
+			} else {
+				print "got $num rows in ";
 
-	if ( $queryPage->isExpensive() ) {
-		$t1 = explode( ' ', microtime() );
-		# Do the query
-		$num = $queryPage->recache( $limit === null ? $wgQueryCacheLimit : $limit );
-		$t2 = explode( ' ', microtime() );
-
-		if ( $num === false ) {
-			print "FAILED: database error\n";
-		} else {
-			print "got $num rows in ";
-
-			$elapsed = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]);
-			$hours = intval( $elapsed / 3600 );
-			$minutes = intval( $elapsed % 3600 / 60 );
-			$seconds = $elapsed - $hours * 3600 - $minutes * 60;
-			if ( $hours ) {
-				print $hours . 'h ';
-			}
-			if ( $minutes ) {
-				print $minutes . 'm ';
-			}
-			printf( "%.2fs\n", $seconds );
+				$elapsed = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]);
+				$hours = intval( $elapsed / 3600 );
+				$minutes = intval( $elapsed % 3600 / 60 );
+				$seconds = $elapsed - $hours * 3600 - $minutes * 60;
+				if ( $hours ) {
+					print $hours . 'h ';
+				}
+				if ( $minutes ) {
+					print $minutes . 'm ';
+				}
+				printf( "%.2fs\n", $seconds );
 		}
-
 		# Reopen any connections that have closed
 		if ( !wfGetLB()->pingAll())  {
 			print "\n";
@@ -89,22 +110,10 @@
 			# Commit the results
 			$dbw->immediateCommit();
 		}
-
 		# Wait for the slave to catch up
-		/*
-		$slaveDB = wfGetDB( DB_SLAVE, array('QueryPage::recache', 'vslow' ) );
-		while( $slaveDB->getLag() > 600 ) {
-			print "Slave lagged, waiting...\n";
-			sleep(30);
-
+		wfWaitForSlaves( 5 );
+		} else {
+			print "cheap, skipped\n";
 		}
-		*/
-		wfWaitForSlaves( 5 );
-
-	} else {
-		print "cheap, skipped\n";
 	}
-	}
 }
-
-
Index: trunk/phase3/maintenance/updaters.inc
===================================================================
--- trunk/phase3/maintenance/updaters.inc	(revision 40278)
+++ trunk/phase3/maintenance/updaters.inc	(revision 40279)
@@ -143,6 +143,9 @@
 	array( 'maybe_do_profiling_memory_update' ),
 	array( 'do_filearchive_indices_update' ),
 	array( 'update_password_format' ),
+	
+	// 1.14
+	array( 'add_field', 'site_stats',     'ss_active_users',  'patch-ss_active_users.sql' ),
 );
 
 
@@ -1463,6 +1466,7 @@
 		array("revision",      "rev_len",              "INTEGER"),
 		array("revision",      "rev_deleted",          "SMALLINT NOT NULL DEFAULT 0"),
 		array("user_newtalk",  "user_last_timestamp",  "TIMESTAMPTZ"),
+		array("site_stats",    "ss_active_users",      "INTERGER DEFAULT '-1'"),
 	);
 
 
Index: trunk/phase3/maintenance/tables.sql
===================================================================
--- trunk/phase3/maintenance/tables.sql	(revision 40278)
+++ trunk/phase3/maintenance/tables.sql	(revision 40279)
@@ -596,6 +596,9 @@
 
   -- Number of users, theoretically equal to SELECT COUNT(*) FROM user;
   ss_users bigint default '-1',
+  
+  -- Number of users that still edit
+  ss_active_users bigint default '-1',
 
   -- Deprecated, no longer updated as of 1.5
   ss_admins int default '-1',
Index: trunk/phase3/includes/SiteStats.php
===================================================================
--- trunk/phase3/includes/SiteStats.php	(revision 40278)
+++ trunk/phase3/includes/SiteStats.php	(revision 40279)
@@ -93,6 +93,11 @@
 		self::load();
 		return self::$row->ss_users;
 	}
+	
+	static function activeUsers() {
+		self::load();
+		return self::$row->ss_active_users;
+	}
 
 	static function images() {
 		self::load();
@@ -248,13 +253,20 @@
 			$dbw->query( $sql, $fname );
 			$dbw->commit();
 		}
-
-		/*
-		global $wgDBname, $wgTitle;
-		if ( $this->mGood && $wgDBname == 'enwiki' ) {
-			$good = $dbw->selectField( 'site_stats', 'ss_good_articles', '', $fname );
-			error_log( $good . ' ' . $wgTitle->getPrefixedDBkey() . "\n", 3, '/home/wikipedia/logs/million.log' );
-		}
-		*/
 	}
+	
+	public static function cacheUpdate( $dbw ) {
+		$dbr = wfGetDB( DB_SLAVE, array( 'SpecialStatistics', 'vslow') );
+		# Get non-bot users than did some recent action other than making accounts.
+		# If account creation is included, the number gets inflated ~20+ fold on enwiki.
+		$activeUsers = $dbr->selectField( 'recentchanges', 'COUNT( DISTINCT rc_user_text )',
+			array( 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ),
+			__METHOD__ );
+		$dbw->begin();
+		$dbw->update( 'site_stats', 
+			array( 'ss_active_users' => intval($activeUsers) ),
+				array('1 = 1'), __METHOD__, array( 'LIMIT' => 1 )
+		);
+		$dbw->commit();
+	}
 }
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 40278)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 40279)
@@ -1617,6 +1617,14 @@
 );
 
 /**
+ * Additional functions to be performed with updateSpecialPages.
+ * Expensive Querypages are already updated.
+ */
+$wgSpecialPageCacheUpdates = array(
+	'Statistics' => 'SiteStatsUpdate::cacheUpdate'
+);
+
+/**
  * To use inline TeX, you need to compile 'texvc' (in the 'math' subdirectory of
  * the MediaWiki package and have latex, dvips, gs (ghostscript), andconvert
  * (ImageMagick) installed and available in the PATH.
Index: trunk/phase3/includes/specials/SpecialStatistics.php
===================================================================
--- trunk/phase3/includes/specials/SpecialStatistics.php	(revision 40278)
+++ trunk/phase3/includes/specials/SpecialStatistics.php	(revision 40279)
@@ -23,13 +23,15 @@
 	$images = SiteStats::images();
 	$total = SiteStats::pages();
 	$users = SiteStats::users();
+	$activeUsers = SiteStats::activeUsers();
 	$admins = SiteStats::numberingroup('sysop');
 	$numJobs = SiteStats::jobs();
 
 	if( $wgRequest->getVal( 'action' ) == 'raw' ) {
 		$wgOut->disable();
 		header( 'Pragma: nocache' );
-		echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;admins=$admins;images=$images;jobs=$numJobs\n";
+		echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;";
+		echo "activeusers=$activeusers;admins=$admins;images=$images;jobs=$numJobs\n";
 		return;
 	} else {
 		$text = "__NOTOC__\n";
@@ -51,7 +53,8 @@
 			$wgLang->formatNum( $admins ),
 			'[[' . wfMsgForContent( 'grouppage-sysop' ) . ']]', # TODO somehow remove, kept for backwards compatibility
 			$wgLang->formatNum( @sprintf( '%.2f', $admins / $users * 100 ) ),
-			User::makeGroupLinkWiki( 'sysop' )
+			User::makeGroupLinkWiki( 'sysop' ),
+			$wgLang->formatNum( $activeUsers )
 		)."\n";
 
 		global $wgDisableCounters, $wgMiserMode, $wgUser, $wgLang, $wgContLang;
Index: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php	(revision 40278)
+++ trunk/phase3/languages/messages/MessagesEn.php	(revision 40279)
@@ -1926,7 +1926,8 @@
 That comes to '''\$5''' average edits per page, and '''\$6''' views per edit.
 
 The [http://www.mediawiki.org/wiki/Manual:Job_queue job queue] length is '''\$7'''.",
-'userstatstext'          => "There {{PLURAL:$1|is '''1''' registered [[Special:ListUsers|user]]|are '''$1''' registered [[Special:ListUsers|users]]}}, of which '''$2''' (or '''$4%''') {{PLURAL:$2|has|have}} $5 rights.",
+'userstatstext'          => "There {{PLURAL:$1|is '''1''' registered [[Special:ListUsers|user]]|are '''$1''' registered [[Special:ListUsers|users]]}}, of which '''$2''' (or '''$4%''') {{PLURAL:$2|has|have}} $5 rights.
+There {{PLURAL:$6|is|are}} currently about '''$6''' active registered user {{PLURAL:$6|account|accounts}}.",
 'statistics-mostpopular' => 'Most viewed pages',
 'statistics-footer'      => '', # do not translate or duplicate this message to other languages
 
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox