From: Matthew Flaschen Date: Wed, 27 Feb 2013 02:32:19 +0000 (-0500) Subject: Change new wgUserRegistration format, put in User: X-Git-Tag: 1.31.0-rc.0~20540^2 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=910ed234e832dc537b9edfc88b0d7c460ed988d7;p=lhc%2Fweb%2Fwiklou.git Change new wgUserRegistration format, put in User: * This is much more useful if it can be passed to new Date. As a side effect, this means straight arithmetic comparisons can be done. * Add a method for this to mediawiki.user (getRegistrationDate). * Improve docs on server User::getRegistration method by documenting possibility that data is null. Change-Id: Id7ae0faa930433876939b73d47fc294975e14fb1 --- diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 525fc24b7a..8a95f04141 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -3029,7 +3029,8 @@ $templates if ( $user->isLoggedIn() ) { $vars['wgUserId'] = $user->getId(); $vars['wgUserEditCount'] = $user->getEditCount(); - $vars['wgUserRegistration'] = $user->getRegistration(); + $userReg = wfTimestampOrNull( TS_UNIX, $user->getRegistration() ); + $vars['wgUserRegistration'] = $userReg !== null ? ( $userReg * 1000 ) : null; } if ( $wgContLang->hasVariants() ) { $vars['wgUserVariant'] = $wgContLang->getPreferredVariant(); diff --git a/includes/User.php b/includes/User.php index de34bfcbb0..7a60d9e158 100644 --- a/includes/User.php +++ b/includes/User.php @@ -3748,8 +3748,9 @@ class User { /** * Get the timestamp of account creation. * - * @return String|Bool Timestamp of account creation, or false for - * non-existent/anonymous user accounts. + * @return String|Bool|Null Timestamp of account creation, false for + * non-existent/anonymous user accounts, or null if existing account + * but information is not in database. */ public function getRegistration() { if ( $this->isAnon() ) { diff --git a/resources/mediawiki/mediawiki.user.js b/resources/mediawiki/mediawiki.user.js index 3b2a59cdbc..308e4add2e 100644 --- a/resources/mediawiki/mediawiki.user.js +++ b/resources/mediawiki/mediawiki.user.js @@ -88,6 +88,25 @@ return this.getName(); }; + /** + * Get date user registered, if available. + * + * @return {Date|false|null} date user registered, or false for anonymous users, or + * null when data is not available + */ + this.getRegistration = function () { + var registration = mw.config.get( 'wgUserRegistration' ); + if ( this.isAnon() ) { + return false; + } else if ( registration === null ) { + // Information may not be available if they signed up before + // MW began storing this. + return null; + } else { + return new Date( registration ); + } + }; + /** * Checks if the current user is anonymous. *