r52686 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52685‎ | r52686 | r52687 >
Date:11:39, 2 July 2009
Author:btongminh
Status:deferred
Tags:
Comment:
* Add Excel export
* Group usernames by activity state
Modified paths:
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmExport.php (modified) (history)
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmUserListView.php (modified) (history)
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssUser.php (modified) (history)

Diff [purge]

Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmExport.php
@@ -14,14 +14,16 @@
1515 global $wgOut;
1616 $wgOut->disable();
1717 wfResetOutputBuffers();
18 - header( 'Content-Type: application/octet-stream' );
1918 echo $result;
2019 return true;
2120 }
2221
23 - static $formats = array('csv');
 22+ static $formats = array('csv', 'csvexcel' );
2423
25 - function formatCsv( $data ) {
 24+ function formatCsvexcel( $data ) {
 25+ return $this->formatCsv( $data, ';' );
 26+ }
 27+ function formatCsv( $data, $separator = ',' ) {
2628 $props = NssProperties::getAll();
2729 $users = NssUser::fetchAll();
2830
@@ -32,6 +34,8 @@
3335 $field = isset( $line[$name] ) ? $line[$name] : '';
3436
3537 if ( !$field && in_array( $name, array( 'username', 'home', 'active', 'email' ) ) ) {
 38+ if ( !isset( $users[$username] ) )
 39+ continue;
3640 $field = $users[$username]->get( $name );
3741 }
3842
@@ -50,8 +54,10 @@
5155 else
5256 $dataline[] = $field;
5357 }
54 - $result .= implode( ',', $dataline )."\r\n";
 58+ $result .= implode( $separator, $dataline )."\r\n";
5559 }
 60+
 61+ header( "Content-Disposition: inline;filename*=utf-8'en'export.csv" );
5662 return $result;
5763 }
5864 }
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssUser.php
@@ -1,7 +1,7 @@
22 <?php
33
44 class NssUser {
5 - static $passwdFields = array( 'pwd_uid', 'pwd_gid', 'pwd_home', 'pwd_active', 'pwd_email' );
 5+ static $passwdFields = array( 'pwd_name', 'pwd_uid', 'pwd_gid', 'pwd_home', 'pwd_active', 'pwd_email' );
66
77 function __construct( $name ) {
88 $this->name = $name;
@@ -119,6 +119,21 @@
120120 $names[] = $row->pwd_name;
121121 return $names;
122122 }
 123+ public static function fetchByActive() {
 124+ global $wgAuth;
 125+ $dbr = $wgAuth->getDB( DB_READ );
 126+
 127+ $res = $dbr->select( 'passwd', array( 'pwd_name', 'pwd_active' ), array(), __METHOD__ );
 128+
 129+ $actives = array();
 130+ while ( $row = $res->fetchObject() ) {
 131+ if ( !isset( $actives[$row->pwd_active] ) )
 132+ $actives[$row->pwd_active] = array();
 133+
 134+ $actives[$row->pwd_active] = $row->pwd_name;
 135+ }
 136+ return $actives;
 137+ }
123138
124139 public static function fetchAll() {
125140 global $wgAuth;
@@ -129,6 +144,7 @@
130145 while ( $row = $res->fetchObject() ) {
131146 $user = new self( $row->pwd_name );
132147 $user->loadFromRow( $row );
 148+ $users[$row->pwd_name] = $user;
133149 }
134150 return $users;
135151 }
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmUserListView.php
@@ -4,21 +4,25 @@
55 function execute() {
66 global $wgOut, $wgUser;
77
8 - $users = NssUser::fetchNames();
 8+ $actives = NssUser::fetchByActive();
 9+
910 $title = SpecialPage::getTitleFor( 'AccountManager' );
1011 $sk = $wgUser->getSkin();
1112
12 - $wgOut->addHtml( Xml::element( 'ul', array(
13 - 'id' => 'nss-user-listview'
14 - ) ) . "\n" );
15 -
16 - foreach ( $users as $name ) {
17 - $wgOut->addHtml( "\t<li>" .
18 - $sk->link( $title, $name, /* html attribs */ array(),
19 - array( 'user' => $name ), 'known'
20 - ) . "</li>\n" );
 13+ foreach ( $actives as $active => $users ) {
 14+ $wgOut->addHtml( Xml::element( 'h2', null, $active ).
 15+ Xml::openElement( 'ul', array(
 16+ 'id' => 'nss-user-listview'
 17+ ) ) . "\n" );
 18+
 19+ foreach ( $users as $name ) {
 20+ $wgOut->addHtml( "\t<li>" .
 21+ $sk->link( $title, $name, /* html attribs */ array(),
 22+ array( 'user' => $name ), 'known'
 23+ ) . "</li>\n" );
 24+ }
 25+
 26+ $wgOut->addHtml( "</ul>\n" );
2127 }
22 -
23 - $wgOut->addHtml( "</ul>\n" );
2428 }
2529 }
\ No newline at end of file

Status & tagging log