Expose additional user attributes as JS vars
authorOri Livneh <ori@wikimedia.org>
Tue, 22 Jan 2013 22:44:22 +0000 (14:44 -0800)
committerOri Livneh <ori@wikimedia.org>
Wed, 27 Feb 2013 01:56:21 +0000 (17:56 -0800)
This change adds user ID, registration time, and edit count to the
default set of JavaScript configuration variables.

These values are all included in $mCacheVars and so require no additional
database lookups.

Change-Id: Id0adb795567d4ba932104938f2793cdb4084883c

includes/OutputPage.php

index f719421..525fc24 100644 (file)
@@ -3002,6 +3002,8 @@ $templates
                        implode( "\t", $digitTransTable ),
                );
 
+               $user = $this->getUser();
+
                $vars = array(
                        'wgCanonicalNamespace' => $nsname,
                        'wgCanonicalSpecialPageName' => $canonicalName,
@@ -3012,8 +3014,8 @@ $templates
                        'wgArticleId' => $pageID,
                        'wgIsArticle' => $this->isArticle(),
                        'wgAction' => Action::getActionName( $this->getContext() ),
-                       'wgUserName' => $this->getUser()->isAnon() ? null : $this->getUser()->getName(),
-                       'wgUserGroups' => $this->getUser()->getEffectiveGroups(),
+                       'wgUserName' => $user->isAnon() ? null : $user->getName(),
+                       'wgUserGroups' => $user->getEffectiveGroups(),
                        'wgCategories' => $this->getCategories(),
                        'wgBreakFrames' => $this->getFrameOptions() == 'DENY',
                        'wgPageContentLanguage' => $lang->getCode(),
@@ -3024,6 +3026,11 @@ $templates
                        'wgMonthNamesShort' => $lang->getMonthAbbreviationsArray(),
                        'wgRelevantPageName' => $relevantTitle->getPrefixedDBKey(),
                );
+               if ( $user->isLoggedIn() ) {
+                       $vars['wgUserId'] = $user->getId();
+                       $vars['wgUserEditCount'] = $user->getEditCount();
+                       $vars['wgUserRegistration'] = $user->getRegistration();
+               }
                if ( $wgContLang->hasVariants() ) {
                        $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
                }