Use $this->getLang() per Nikerabbit on r91648.
[lhc/web/wiklou.git] / includes / UserArray.php
1 <?php
2
3 abstract class UserArray implements Iterator {
4 /**
5 * @param $res ResultWrapper
6 * @return UserArrayFromResult
7 */
8 static function newFromResult( $res ) {
9 $userArray = null;
10 if ( !wfRunHooks( 'UserArrayFromResult', array( &$userArray, $res ) ) ) {
11 return null;
12 }
13 if ( $userArray === null ) {
14 $userArray = self::newFromResult_internal( $res );
15 }
16 return $userArray;
17 }
18
19 /**
20 * @param $ids array
21 * @return UserArrayFromResult
22 */
23 static function newFromIDs( $ids ) {
24 $ids = array_map( 'intval', (array)$ids ); // paranoia
25 if ( !$ids ) {
26 // Database::select() doesn't like empty arrays
27 return new ArrayIterator(array());
28 }
29 $dbr = wfGetDB( DB_SLAVE );
30 $res = $dbr->select( 'user', '*', array( 'user_id' => $ids ),
31 __METHOD__ );
32 return self::newFromResult( $res );
33 }
34
35 /**
36 * @param $res
37 * @return UserArrayFromResult
38 */
39 protected static function newFromResult_internal( $res ) {
40 return new UserArrayFromResult( $res );
41 }
42 }
43
44 class UserArrayFromResult extends UserArray {
45
46 /**
47 * @var ResultWrapper
48 */
49 var $res;
50 var $key, $current;
51
52 /**
53 * @param $res ResultWrapper
54 */
55 function __construct( $res ) {
56 $this->res = $res;
57 $this->key = 0;
58 $this->setCurrent( $this->res->current() );
59 }
60
61 /**
62 * @param $row
63 * @return void
64 */
65 protected function setCurrent( $row ) {
66 if ( $row === false ) {
67 $this->current = false;
68 } else {
69 $this->current = User::newFromRow( $row );
70 }
71 }
72
73 /**
74 * @return int
75 */
76 public function count() {
77 return $this->res->numRows();
78 }
79
80 function current() {
81 return $this->current;
82 }
83
84 function key() {
85 return $this->key;
86 }
87
88 function next() {
89 $row = $this->res->next();
90 $this->setCurrent( $row );
91 $this->key++;
92 }
93
94 function rewind() {
95 $this->res->rewind();
96 $this->key = 0;
97 $this->setCurrent( $this->res->current() );
98 }
99
100 /**
101 * @return bool
102 */
103 function valid() {
104 return $this->current !== false;
105 }
106 }