Index: trunk/extensions/CentralAuth/CentralAuthUser.php |
— | — | @@ -22,7 +22,6 @@ |
23 | 23 | function __construct( $username ) { |
24 | 24 | $this->mName = $username; |
25 | 25 | $this->resetState(); |
26 | | - $this->loadState(); |
27 | 26 | } |
28 | 27 | |
29 | 28 | public static function tableName( $name ) { |
— | — | @@ -41,10 +40,11 @@ |
42 | 41 | private function resetState() { |
43 | 42 | $this->mGlobalId = null; |
44 | 43 | $this->mLocalId = null; |
| 44 | + $this->mProperties = null; |
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | | - * Load up the most commonly required state information |
| 48 | + * Lazy-load up the most commonly required state information |
49 | 49 | */ |
50 | 50 | private function loadState() { |
51 | 51 | if( !isset( $this->mGlobalId ) ) { |
— | — | @@ -104,6 +104,44 @@ |
105 | 105 | return $id != 0; |
106 | 106 | } |
107 | 107 | |
| 108 | + /** |
| 109 | + * Lazy-load misc properties that may be used at times |
| 110 | + */ |
| 111 | + private function loadProperties() { |
| 112 | + if( !isset( $this->mProperties ) ) { |
| 113 | + $dbw = wfGetDB( DB_MASTER, 'CentralAuth' ); |
| 114 | + $row = $dbw->selectRow( self::tableName( 'globaluser' ), |
| 115 | + array( 'gu_locked', 'gu_hidden', 'gu_registration' ), |
| 116 | + array( 'gu_id' => $this->getId() ), |
| 117 | + __METHOD__ ); |
| 118 | + $this->mProperties = $row; |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * @return bool |
| 124 | + */ |
| 125 | + public function isLocked() { |
| 126 | + $this->loadProperties(); |
| 127 | + return (bool)$this->mProperties->gu_locked; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * @return bool |
| 132 | + */ |
| 133 | + public function isHidden() { |
| 134 | + $this->loadProperties(); |
| 135 | + return (bool)$this->mProperties->gu_hidden; |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * @return string timestamp |
| 140 | + */ |
| 141 | + public function getRegistration() { |
| 142 | + $this->loadProperties(); |
| 143 | + return wfTimestamp( TS_MW, $this->mProperties->gu_registration ); |
| 144 | + } |
| 145 | + |
108 | 146 | private function lazyMigrate() { |
109 | 147 | global $wgCentralAuthAutoMigrate; |
110 | 148 | if( $wgCentralAuthAutoMigrate ) { |
— | — | @@ -203,6 +241,7 @@ |
204 | 242 | 'gu_password' => $hash, |
205 | 243 | 'gu_email' => $email, |
206 | 244 | 'gu_email_authenticated' => $emailAuth, |
| 245 | + 'gu_registration' => $dbw->timestamp(), // hmmmm |
207 | 246 | ), |
208 | 247 | __METHOD__, |
209 | 248 | array( 'IGNORE' ) ); |
Index: trunk/extensions/CentralAuth/SpecialCentralAuth.php |
— | — | @@ -104,6 +104,24 @@ |
105 | 105 | ); |
106 | 106 | } |
107 | 107 | |
| 108 | + function prettyTimespan( $span ) { |
| 109 | + $units = array( |
| 110 | + 'seconds' => 60, |
| 111 | + 'minutes' => 60, |
| 112 | + 'hours' => 24, |
| 113 | + 'days' => 30.417, |
| 114 | + 'months' => 12, |
| 115 | + 'years' => 1 ); |
| 116 | + foreach( $units as $unit => $chunk ) { |
| 117 | + if( $span < 2*$chunk ) { |
| 118 | + return "$span $unit"; |
| 119 | + } |
| 120 | + $span = intval( $span / $chunk ); |
| 121 | + } |
| 122 | + return "$span $unit"; |
| 123 | + } |
| 124 | + |
| 125 | + |
108 | 126 | function showInfo() { |
109 | 127 | $globalUser = new CentralAuthUser( $this->mUserName ); |
110 | 128 | |
— | — | @@ -111,9 +129,21 @@ |
112 | 130 | $merged = $globalUser->queryAttached(); |
113 | 131 | $remainder = $globalUser->queryUnattached(); |
114 | 132 | |
115 | | - global $wgOut; |
| 133 | + global $wgOut, $wgLang; |
116 | 134 | if( $globalUser->exists() ) { |
117 | | - $wgOut->addWikiText( "User id: $id" ); |
| 135 | + $reg = $globalUser->getRegistration(); |
| 136 | + $age = $this->prettyTimespan( wfTimestamp( TS_UNIX ) - wfTimestamp( TS_UNIX, $reg ) ); |
| 137 | + $attribs = array( |
| 138 | + 'User id:' => $globalUser->getId(), |
| 139 | + 'Registered:' => $wgLang->timeanddate( $reg ) . " ($age ago)", |
| 140 | + 'Locked:' => $globalUser->isLocked() ? 'yes' : 'no', |
| 141 | + 'Hidden:' => $globalUser->isHidden() ? 'yes' : 'no' ); |
| 142 | + $out = '<ul>'; |
| 143 | + foreach( $attribs as $tag => $data ) { |
| 144 | + $out .= Xml::element( 'li', array(), $tag . ' ' . $data ); |
| 145 | + } |
| 146 | + $out .= '</ul>'; |
| 147 | + $wgOut->addHtml( $out ); |
118 | 148 | |
119 | 149 | $wgOut->addWikiText( "<h2>Fully merged accounts</h2>" ); |
120 | 150 | $wgOut->addHtml( $this->listMerged( $merged ) ); |