]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/UserArray.php
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.git] / includes / UserArray.php
1 <?php
2
3 abstract class UserArray implements Iterator {
4         static function newFromResult( $res ) {
5                 $userArray = null;
6                 if ( !wfRunHooks( 'UserArrayFromResult', array( &$userArray, $res ) ) ) {
7                         return null;
8                 }
9                 if ( $userArray === null ) {
10                         $userArray = self::newFromResult_internal( $res );
11                 }
12                 return $userArray;
13         }
14
15         protected static function newFromResult_internal( $res ) {
16                 $userArray = new UserArrayFromResult( $res );
17                 return $userArray;
18         }
19 }
20
21 class UserArrayFromResult extends UserArray {
22         var $res;
23         var $key, $current;
24
25         function __construct( $res ) {
26                 $this->res = $res;
27                 $this->key = 0;
28                 $this->setCurrent( $this->res->current() );
29         }
30
31         protected function setCurrent( $row ) {
32                 if ( $row === false ) {
33                         $this->current = false;
34                 } else {
35                         $this->current = User::newFromRow( $row );
36                 }
37         }
38
39         public function count() {
40                 return $this->res->numRows();
41         }
42
43         function current() {
44                 return $this->current;
45         }
46
47         function key() {
48                 return $this->key;
49         }
50
51         function next() {
52                 $row = $this->res->next();
53                 $this->setCurrent( $row );
54                 $this->key++;
55         }
56
57         function rewind() {
58                 $this->res->rewind();
59                 $this->key = 0;
60                 $this->setCurrent( $this->res->current() );
61         }
62
63         function valid() {
64                 return $this->current !== false;
65         }
66 }