Index: trunk/phase3/includes/TitleArray.php |
— | — | @@ -0,0 +1,77 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Note: this entire file is a byte-for-byte copy of UserArray.php with |
| 5 | + * s/User/Title/. If anyone can figure out how to do this nicely with inheri- |
| 6 | + * tance or something, please do so. |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * The TitleArray class only exists to provide the newFromResult method at pre- |
| 11 | + * sent. |
| 12 | + */ |
| 13 | +abstract class TitleArray implements Iterator { |
| 14 | + /** |
| 15 | + * @param $res result A MySQL result including at least page_namespace and |
| 16 | + * page_title -- also can have page_id, page_len, page_is_redirect, |
| 17 | + * page_latest (if those will be used). See Title::newFromRow. |
| 18 | + * @return TitleArray |
| 19 | + */ |
| 20 | + static function newFromResult( $res ) { |
| 21 | + $array = null; |
| 22 | + if ( !wfRunHooks( 'TitleArrayFromResult', array( &$array, $res ) ) ) { |
| 23 | + return null; |
| 24 | + } |
| 25 | + if ( $array === null ) { |
| 26 | + $array = self::newFromResult_internal( $res ); |
| 27 | + } |
| 28 | + return $array; |
| 29 | + } |
| 30 | + |
| 31 | + protected static function newFromResult_internal( $res ) { |
| 32 | + $array = new TitleArrayFromResult( $res ); |
| 33 | + return $array; |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +class TitleArrayFromResult extends TitleArray { |
| 38 | + var $res; |
| 39 | + var $key, $current; |
| 40 | + |
| 41 | + function __construct( $res ) { |
| 42 | + $this->res = $res; |
| 43 | + $this->key = 0; |
| 44 | + $this->setCurrent( $this->res->current() ); |
| 45 | + } |
| 46 | + |
| 47 | + protected function setCurrent( $row ) { |
| 48 | + if ( $row === false ) { |
| 49 | + $this->current = false; |
| 50 | + } else { |
| 51 | + $this->current = Title::newFromRow( $row ); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + function current() { |
| 56 | + return $this->current; |
| 57 | + } |
| 58 | + |
| 59 | + function key() { |
| 60 | + return $this->key; |
| 61 | + } |
| 62 | + |
| 63 | + function next() { |
| 64 | + $row = $this->res->next(); |
| 65 | + $this->setCurrent( $row ); |
| 66 | + $this->key++; |
| 67 | + } |
| 68 | + |
| 69 | + function rewind() { |
| 70 | + $this->res->rewind(); |
| 71 | + $this->key = 0; |
| 72 | + $this->setCurrent( $this->res->current() ); |
| 73 | + } |
| 74 | + |
| 75 | + function valid() { |
| 76 | + return $this->current !== false; |
| 77 | + } |
| 78 | +} |
Property changes on: trunk/phase3/includes/TitleArray.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 79 | + native |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -191,6 +191,7 @@ |
192 | 192 | 'ThumbnailImage' => 'includes/MediaTransformOutput.php', |
193 | 193 | 'TitleDependency' => 'includes/CacheDependency.php', |
194 | 194 | 'Title' => 'includes/Title.php', |
| 195 | + 'TitleArray' => 'includes/TitleArray.php', |
195 | 196 | 'TitleListDependency' => 'includes/CacheDependency.php', |
196 | 197 | 'TransformParameterError' => 'includes/MediaTransformOutput.php', |
197 | 198 | 'TurckBagOStuff' => 'includes/BagOStuff.php', |