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 @@ |
26 | 26 | self::$users[$username] = $propObj; |
27 | 27 | return $propObj; |
28 | 28 | } |
| 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 | + } |
29 | 47 | |
30 | 48 | function __construct( $name = null ) { |
31 | 49 | $this->name = $name; |
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssUser.php |
— | — | @@ -1,6 +1,8 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class NssUser { |
| 5 | + static $passwdFields = array( 'pwd_uid', 'pwd_gid', 'pwd_home', 'pwd_active', 'pwd_email' ); |
| 6 | + |
5 | 7 | function __construct( $name ) { |
6 | 8 | $this->name = $name; |
7 | 9 | |
— | — | @@ -23,7 +25,7 @@ |
24 | 26 | |
25 | 27 | // Load the user existence from passwd |
26 | 28 | $result = $dbr->select( 'passwd', |
27 | | - array( 'pwd_uid', 'pwd_gid', 'pwd_home', 'pwd_active', 'pwd_email' ), |
| 29 | + self::$passwdFields, |
28 | 30 | array( 'pwd_name' => $this->name ), |
29 | 31 | __METHOD__ |
30 | 32 | ); |
— | — | @@ -117,5 +119,18 @@ |
118 | 120 | $names[] = $row->pwd_name; |
119 | 121 | return $names; |
120 | 122 | } |
| 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 | + } |
121 | 136 | } |
122 | 137 | |
\ No newline at end of file |
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/SpecialAccountManager.php |
— | — | @@ -64,6 +64,13 @@ |
65 | 65 | return $this->displayRestrictionError(); |
66 | 66 | $this->setHeaders(); |
67 | 67 | |
| 68 | + $export = $wgRequest->getVal( 'export' ); |
| 69 | + if ( $export ) { |
| 70 | + $exporter = new AmExport(); |
| 71 | + if ( $exporter->execute( $export ) === true ) |
| 72 | + return; |
| 73 | + } |
| 74 | + |
68 | 75 | $username = $wgRequest->getVal( 'user' ); |
69 | 76 | |
70 | 77 | $result = $this->processData(); |
— | — | @@ -74,12 +81,11 @@ |
75 | 82 | wfMsg( $this->error ) ) . "\n" ); |
76 | 83 | } |
77 | 84 | |
| 85 | + $userView = new AmUserView( $username ); |
| 86 | + $userView->execute(); |
| 87 | + |
78 | 88 | $list = new AmUserListView(); |
79 | 89 | $list->execute(); |
80 | | - |
81 | | - $userView = new AmUserView( $username ); |
82 | | - $userView->execute(); |
83 | | - |
84 | 90 | } |
85 | 91 | |
86 | 92 | |