r22437 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22436‎ | r22437 | r22438 >
Date:21:00, 25 May 2007
Author:brion
Status:old
Tags:
Comment:
got a little done on this today at least :P
* some centralauth-admin-level access to account properties (registration age, lock status)
* store a registration timestamp at auto-migration time (this is current time. is that ideal?)
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuthUser.php (modified) (history)
  • /trunk/extensions/CentralAuth/SpecialCentralAuth.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/CentralAuthUser.php
@@ -22,7 +22,6 @@
2323 function __construct( $username ) {
2424 $this->mName = $username;
2525 $this->resetState();
26 - $this->loadState();
2726 }
2827
2928 public static function tableName( $name ) {
@@ -41,10 +40,11 @@
4241 private function resetState() {
4342 $this->mGlobalId = null;
4443 $this->mLocalId = null;
 44+ $this->mProperties = null;
4545 }
4646
4747 /**
48 - * Load up the most commonly required state information
 48+ * Lazy-load up the most commonly required state information
4949 */
5050 private function loadState() {
5151 if( !isset( $this->mGlobalId ) ) {
@@ -104,6 +104,44 @@
105105 return $id != 0;
106106 }
107107
 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+
108146 private function lazyMigrate() {
109147 global $wgCentralAuthAutoMigrate;
110148 if( $wgCentralAuthAutoMigrate ) {
@@ -203,6 +241,7 @@
204242 'gu_password' => $hash,
205243 'gu_email' => $email,
206244 'gu_email_authenticated' => $emailAuth,
 245+ 'gu_registration' => $dbw->timestamp(), // hmmmm
207246 ),
208247 __METHOD__,
209248 array( 'IGNORE' ) );
Index: trunk/extensions/CentralAuth/SpecialCentralAuth.php
@@ -104,6 +104,24 @@
105105 );
106106 }
107107
 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+
108126 function showInfo() {
109127 $globalUser = new CentralAuthUser( $this->mUserName );
110128
@@ -111,9 +129,21 @@
112130 $merged = $globalUser->queryAttached();
113131 $remainder = $globalUser->queryUnattached();
114132
115 - global $wgOut;
 133+ global $wgOut, $wgLang;
116134 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 );
118148
119149 $wgOut->addWikiText( "<h2>Fully merged accounts</h2>" );
120150 $wgOut->addHtml( $this->listMerged( $merged ) );