(bug 19441) Updated date formatting for Lithuanian
[mediawiki.git] / includes / UserArray.php
blobd48a4440bf9fdc4633ceee23ffeea4507f650037
1 <?php
3 abstract class UserArray implements Iterator {
4 static function newFromResult( $res ) {
5 $userArray = null;
6 if ( !wfRunHooks( 'UserArrayFromResult', array( &$userArray, $res ) ) ) {
7 return null;
9 if ( $userArray === null ) {
10 $userArray = self::newFromResult_internal( $res );
12 return $userArray;
15 static function newFromIDs( $ids ) {
16 $ids = array_map( 'intval', (array)$ids ); // paranoia
17 if ( !$ids )
18 // Database::select() doesn't like empty arrays
19 return new ArrayIterator(array());
20 $dbr = wfGetDB( DB_SLAVE );
21 $res = $dbr->select( 'user', '*', array( 'user_id' => $ids ),
22 __METHOD__ );
23 return self::newFromResult( $res );
26 protected static function newFromResult_internal( $res ) {
27 $userArray = new UserArrayFromResult( $res );
28 return $userArray;
32 class UserArrayFromResult extends UserArray {
33 var $res;
34 var $key, $current;
36 function __construct( $res ) {
37 $this->res = $res;
38 $this->key = 0;
39 $this->setCurrent( $this->res->current() );
42 protected function setCurrent( $row ) {
43 if ( $row === false ) {
44 $this->current = false;
45 } else {
46 $this->current = User::newFromRow( $row );
50 public function count() {
51 return $this->res->numRows();
54 function current() {
55 return $this->current;
58 function key() {
59 return $this->key;
62 function next() {
63 $row = $this->res->next();
64 $this->setCurrent( $row );
65 $this->key++;
68 function rewind() {
69 $this->res->rewind();
70 $this->key = 0;
71 $this->setCurrent( $this->res->current() );
74 function valid() {
75 return $this->current !== false;