r95600 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95599‎ | r95600 | r95601 >
Date:15:00, 27 August 2011
Author:ashley
Status:deferred
Tags:
Comment:
new social extension, shows the avatars of newly registered users
Modified paths:
  • /trunk/extensions/NewUsersList (added) (history)
  • /trunk/extensions/NewUsersList/NewUsersList.php (added) (history)

Diff [purge]

Index: trunk/extensions/NewUsersList/NewUsersList.php
@@ -0,0 +1,137 @@
 2+<?php
 3+/**
 4+ * NewUsersList parser hook extension -- adds <newusers> parser tag to retrieve
 5+ * the list of new users and their avatars.
 6+ * Requires SocialProfile extension in order to work correctly.
 7+ * Works with NewSignupPage extension, i.e. if the user_register_track DB table
 8+ * is present, this extension queries that table, but if it's not, then the
 9+ * core logging table is used instead.
 10+ *
 11+ * @file
 12+ * @ingroup Extensions
 13+ * @version 1.0
 14+ * @author Aaron Wright <aaron.wright@gmail.com>
 15+ * @author David Pean <david.pean@gmail.com>
 16+ * @author Jack Phoenix <jack@countervandalism.net>
 17+ * @link http://www.mediawiki.org/wiki/Extension:NewUsersList Documentation
 18+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 19+ */
 20+
 21+if ( !defined( 'MEDIAWIKI' ) ) {
 22+ die( "This is not a valid entry point.\n" );
 23+}
 24+
 25+// Extension credits that will show up on Special:Version
 26+$wgExtensionCredits['parserhook'][] = array(
 27+ 'name' => 'NewUsersList',
 28+ 'version' => '1.0',
 29+ 'author' => array( 'Aaron Wright', 'David Pean', 'Jack Phoenix' ),
 30+ 'description' => 'Adds <tt>&lt;newusers&gt;</tt> parser tag to retrieve the list of new users and their avatars',
 31+ 'url' => 'http://www.mediawiki.org/wiki/Extension:NewUsersList'
 32+);
 33+
 34+$wgHooks['ParserFirstCallInit'][] = 'wfGetNewUsers';
 35+
 36+/**
 37+ * Register the <newusers> tag with MediaWiki's Parser.
 38+ *
 39+ * @param $parser Object: instance of Parser (not necessarily $wgParser)
 40+ * @return Boolean: true
 41+ */
 42+function wfGetNewUsers( &$parser ) {
 43+ $parser->setHook( 'newusers', 'getNewUsers' );
 44+ return true;
 45+}
 46+
 47+/**
 48+ * Callback function for the <newusers> tag.
 49+ * Queries the user_register_track database table for new users and renders
 50+ * the list of newest users and their avatars, wrapped in a div with the class
 51+ * "new-users".
 52+ * Disables parser cache and caches the database query results in memcached.
 53+ */
 54+function getNewUsers( $input, $args, $parser ) {
 55+ global $wgMemc;
 56+
 57+ $parser->disableCache();
 58+
 59+ $count = 10;
 60+ $per_row = 5;
 61+
 62+ if ( isset( $args['count'] ) && is_numeric( $args['count'] ) ) {
 63+ $count = intval( $args['count'] );
 64+ }
 65+
 66+ if ( isset( $args['row'] ) && is_numeric( $args['row'] ) ) {
 67+ $per_row = intval( $args['row'] );
 68+ }
 69+
 70+ // Try cache
 71+ $key = wfMemcKey( 'users', 'new', $count );
 72+ $data = $wgMemc->get( $key );
 73+
 74+ if( !$data ) {
 75+ $dbr = wfGetDB( DB_SLAVE );
 76+
 77+ if ( $dbr->tableExists( 'user_register_track' ) ) {
 78+ $res = $dbr->select(
 79+ 'user_register_track',
 80+ array( 'ur_user_id', 'ur_user_name' ),
 81+ array(),
 82+ __METHOD__,
 83+ array( 'ORDER BY' => 'ur_date', 'LIMIT' => $count )
 84+ );
 85+ } else {
 86+ // If user_register_track table doesn't exist, use the core logging
 87+ // table
 88+ $res = $dbr->select(
 89+ 'logging',
 90+ array(
 91+ 'log_user AS ur_user_id',
 92+ 'log_user_text AS ur_user_name'
 93+ ),
 94+ array( 'log_type' => 'newusers' ),
 95+ __METHOD__,
 96+ // DESC to get the *newest* $count users instead of the oldest
 97+ array( 'ORDER BY' => 'log_timestamp DESC', 'LIMIT' => $count )
 98+ );
 99+ }
 100+
 101+ $list = array();
 102+ foreach( $res as $row ) {
 103+ $list[] = array(
 104+ 'user_id' => $row->ur_user_id,
 105+ 'user_name' => $row->ur_user_name
 106+ );
 107+ }
 108+
 109+ // Cache in memcached for 10 minutes
 110+ $wgMemc->set( $key, $list, 60 * 10 );
 111+ } else {
 112+ wfDebugLog( 'NewUsersList', 'Got new users from cache' );
 113+ $list = $data;
 114+ }
 115+
 116+ $output = '<div class="new-users">';
 117+
 118+ if ( !empty( $list ) ) {
 119+ $x = 1;
 120+ foreach( $list as $user ) {
 121+ $avatar = new wAvatar( $user['user_id'], 'ml' );
 122+ $userLink = Title::makeTitle( NS_USER, $user['user_name'] );
 123+
 124+ $output .= '<a href="' . $userLink->escapeFullURL() .
 125+ '" rel="nofollow">' . $avatar->getAvatarURL() . '</a>';
 126+
 127+ if ( ( $x == $count ) || ( $x != 1 ) && ( $x % $per_row == 0 ) ) {
 128+ $output .= '<div class="cleared"></div>';
 129+ }
 130+
 131+ $x++;
 132+ }
 133+ }
 134+
 135+ $output .= '<div class="cleared"></div></div>';
 136+
 137+ return $output;
 138+}
\ No newline at end of file
Property changes on: trunk/extensions/NewUsersList/NewUsersList.php
___________________________________________________________________
Added: svn:eol-style
1139 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r95738Add new extension (r95600) to translatewiki.net...raymond08:28, 30 August 2011

Status & tagging log