r51853 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51852‎ | r51853 | r51854 >
Date:18:48, 14 June 2009
Author:btongminh
Status:deferred
Tags:
Comment:
Initial commit of export function.
Modified paths:
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmExport.php (added) (history)
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssProperties.php (modified) (history)
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssUser.php (modified) (history)
  • /branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/SpecialAccountManager.php (modified) (history)

Diff [purge]

Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmExport.php
@@ -0,0 +1,51 @@
 2+<?php
 3+
 4+class AmExport {
 5+ function execute( $format ) {
 6+ if ( !in_array( strtolower( $format ), self::$formats ) )
 7+ return false;
 8+
 9+ $data = NssProperties::getAllUsers();
 10+ $result = call_user_func( $this, array(
 11+ 'format'.ucfirst( strtolower( $format ) )
 12+ ) );
 13+
 14+ global $wgOut;
 15+ $wgOut->disable();
 16+ wfResetOutputBuffers();
 17+ header( 'Content-Type: application/octet-stream' );
 18+ echo $result;
 19+ return true;
 20+ }
 21+
 22+ static $formats = array('csv');
 23+
 24+ function formatCsv( $data ) {
 25+ $props = NssProperties::getAll();
 26+
 27+ $result = '';
 28+ foreach ( $data as $line ) {
 29+ $dataline = array();
 30+ foreach ( $props as $name ) {
 31+ $field = isset( $props[$name] ) ? $props[$name] : '';
 32+
 33+ $escape = false;
 34+ if ( strpos( $field, '"' ) !== false ) {
 35+ $field = str_replace( '"', '""' , $field );
 36+ $escape = true;
 37+ }
 38+ if ( strpos( $field, ',') !== false )
 39+ $escape = true;
 40+ if ( !$field )
 41+ $escape = true;
 42+
 43+ if ( $escape )
 44+ $dataline[] = '"'.$field.'"';
 45+ else
 46+ $dataline[] = $field;
 47+ }
 48+ $result .= implode( ',', $dataline )."\r\n";
 49+ }
 50+ return $result;
 51+ }
 52+}
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssProperties.php
@@ -25,6 +25,24 @@
2626 self::$users[$username] = $propObj;
2727 return $propObj;
2828 }
 29+ public static function getAllUsers() {
 30+ global $wgAuth;
 31+ $dbr = $wgAuth->getDB( DB_READ );
 32+ $res = $dbr->select( 'user_props',
 33+ array( 'up_user', 'up_name', 'up_value' ),
 34+ array(),
 35+ __METHOD__,
 36+ array( 'ORDER BY' => 'up_timestamp ASC' )
 37+ );
 38+
 39+ $users = array();
 40+ while ( $row = $res->fetchObject() ) {
 41+ if ( !isset( $users[$row->up_user] ) )
 42+ $users[$row->up_user] = array();
 43+ $users[$row->up_user][$row->up_name] = $row->up_value;
 44+ }
 45+ return $users;
 46+ }
2947
3048 function __construct( $name = null ) {
3149 $this->name = $name;
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssUser.php
@@ -1,6 +1,8 @@
22 <?php
33
44 class NssUser {
 5+ static $passwdFields = array( 'pwd_uid', 'pwd_gid', 'pwd_home', 'pwd_active', 'pwd_email' );
 6+
57 function __construct( $name ) {
68 $this->name = $name;
79
@@ -23,7 +25,7 @@
2426
2527 // Load the user existence from passwd
2628 $result = $dbr->select( 'passwd',
27 - array( 'pwd_uid', 'pwd_gid', 'pwd_home', 'pwd_active', 'pwd_email' ),
 29+ self::$passwdFields,
2830 array( 'pwd_name' => $this->name ),
2931 __METHOD__
3032 );
@@ -117,5 +119,18 @@
118120 $names[] = $row->pwd_name;
119121 return $names;
120122 }
 123+
 124+ public static function fetchAll() {
 125+ global $wgAuth;
 126+ $dbr = $wgAuth->getDB( DB_READ );
 127+
 128+ $res = $dbr->select( 'passwd', self::$passwdFields, array(), __METHOD__ );
 129+ $users = array();
 130+ while ( $row = $res->fetchObject() ) {
 131+ $user = new self( $row->pwd_name );
 132+ $user->loadFromRow( $row );
 133+ }
 134+ return $users;
 135+ }
121136 }
122137
\ No newline at end of file
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/SpecialAccountManager.php
@@ -64,6 +64,13 @@
6565 return $this->displayRestrictionError();
6666 $this->setHeaders();
6767
 68+ $export = $wgRequest->getVal( 'export' );
 69+ if ( $export ) {
 70+ $exporter = new AmExport();
 71+ if ( $exporter->execute( $export ) === true )
 72+ return;
 73+ }
 74+
6875 $username = $wgRequest->getVal( 'user' );
6976
7077 $result = $this->processData();
@@ -74,12 +81,11 @@
7582 wfMsg( $this->error ) ) . "\n" );
7683 }
7784
 85+ $userView = new AmUserView( $username );
 86+ $userView->execute();
 87+
7888 $list = new AmUserListView();
7989 $list->execute();
80 -
81 - $userView = new AmUserView( $username );
82 - $userView->execute();
83 -
8490 }
8591
8692

Status & tagging log