Kill "* @return void"
[lhc/web/wiklou.git] / includes / TitleArray.php
1 <?php
2 /**
3 * Note: this entire file is a byte-for-byte copy of UserArray.php with
4 * s/User/Title/. If anyone can figure out how to do this nicely with inheri-
5 * tance or something, please do so.
6 */
7
8 /**
9 * The TitleArray class only exists to provide the newFromResult method at pre-
10 * sent.
11 */
12 abstract class TitleArray implements Iterator {
13 /**
14 * @param $res ResultWrapper A SQL result including at least page_namespace and
15 * page_title -- also can have page_id, page_len, page_is_redirect,
16 * page_latest (if those will be used). See Title::newFromRow.
17 * @return TitleArrayFromResult
18 */
19 static function newFromResult( $res ) {
20 $array = null;
21 if ( !wfRunHooks( 'TitleArrayFromResult', array( &$array, $res ) ) ) {
22 return null;
23 }
24 if ( $array === null ) {
25 $array = self::newFromResult_internal( $res );
26 }
27 return $array;
28 }
29
30 /**
31 * @param $res ResultWrapper
32 * @return TitleArrayFromResult
33 */
34 protected static function newFromResult_internal( $res ) {
35 $array = new TitleArrayFromResult( $res );
36 return $array;
37 }
38 }
39
40 class TitleArrayFromResult extends TitleArray {
41
42 /**
43 * @var ResultWrapper
44 */
45 var $res;
46 var $key, $current;
47
48 function __construct( $res ) {
49 $this->res = $res;
50 $this->key = 0;
51 $this->setCurrent( $this->res->current() );
52 }
53
54 /**
55 * @param $row ResultWrapper
56 */
57 protected function setCurrent( $row ) {
58 if ( $row === false ) {
59 $this->current = false;
60 } else {
61 $this->current = Title::newFromRow( $row );
62 }
63 }
64
65 /**
66 * @return int
67 */
68 public function count() {
69 return $this->res->numRows();
70 }
71
72 function current() {
73 return $this->current;
74 }
75
76 function key() {
77 return $this->key;
78 }
79
80 function next() {
81 $row = $this->res->next();
82 $this->setCurrent( $row );
83 $this->key++;
84 }
85
86 function rewind() {
87 $this->res->rewind();
88 $this->key = 0;
89 $this->setCurrent( $this->res->current() );
90 }
91
92 /**
93 * @return bool
94 */
95 function valid() {
96 return $this->current !== false;
97 }
98 }