Fix for bug 29274 - Message class ignores $wgForceUIMsgAsContentMsg
[mediawiki.git] / includes / UserArray.php
blob6cce48c04f3d46492ca69a403747f81da2f50487
1 <?php
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;
13 if ( $userArray === null ) {
14 $userArray = self::newFromResult_internal( $res );
16 return $userArray;
19 /**
20 * @param $ids array
21 * @return UserArrayFromResult
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());
29 $dbr = wfGetDB( DB_SLAVE );
30 $res = $dbr->select( 'user', '*', array( 'user_id' => $ids ),
31 __METHOD__ );
32 return self::newFromResult( $res );
35 /**
36 * @param $res
37 * @return UserArrayFromResult
39 protected static function newFromResult_internal( $res ) {
40 return new UserArrayFromResult( $res );
44 class UserArrayFromResult extends UserArray {
46 /**
47 * @var ResultWrapper
49 var $res;
50 var $key, $current;
52 /**
53 * @param $res ResultWrapper
55 function __construct( $res ) {
56 $this->res = $res;
57 $this->key = 0;
58 $this->setCurrent( $this->res->current() );
61 /**
62 * @param $row
63 * @return void
65 protected function setCurrent( $row ) {
66 if ( $row === false ) {
67 $this->current = false;
68 } else {
69 $this->current = User::newFromRow( $row );
73 /**
74 * @return int
76 public function count() {
77 return $this->res->numRows();
80 function current() {
81 return $this->current;
84 function key() {
85 return $this->key;
88 function next() {
89 $row = $this->res->next();
90 $this->setCurrent( $row );
91 $this->key++;
94 function rewind() {
95 $this->res->rewind();
96 $this->key = 0;
97 $this->setCurrent( $this->res->current() );
101 * @return bool
103 function valid() {
104 return $this->current !== false;