MediaWiki  REL1_22
TitleArray.php
Go to the documentation of this file.
00001 <?php
00031 abstract class TitleArray implements Iterator {
00038     static function newFromResult( $res ) {
00039         $array = null;
00040         if ( !wfRunHooks( 'TitleArrayFromResult', array( &$array, $res ) ) ) {
00041             return null;
00042         }
00043         if ( $array === null ) {
00044             $array = self::newFromResult_internal( $res );
00045         }
00046         return $array;
00047     }
00048 
00053     protected static function newFromResult_internal( $res ) {
00054         $array = new TitleArrayFromResult( $res );
00055         return $array;
00056     }
00057 }
00058 
00059 class TitleArrayFromResult extends TitleArray {
00060 
00064     var $res;
00065     var $key, $current;
00066 
00067     function __construct( $res ) {
00068         $this->res = $res;
00069         $this->key = 0;
00070         $this->setCurrent( $this->res->current() );
00071     }
00072 
00077     protected function setCurrent( $row ) {
00078         if ( $row === false ) {
00079             $this->current = false;
00080         } else {
00081             $this->current = Title::newFromRow( $row );
00082         }
00083     }
00084 
00088     public function count() {
00089         return $this->res->numRows();
00090     }
00091 
00092     function current() {
00093         return $this->current;
00094     }
00095 
00096     function key() {
00097         return $this->key;
00098     }
00099 
00100     function next() {
00101         $row = $this->res->next();
00102         $this->setCurrent( $row );
00103         $this->key++;
00104     }
00105 
00106     function rewind() {
00107         $this->res->rewind();
00108         $this->key = 0;
00109         $this->setCurrent( $this->res->current() );
00110     }
00111 
00115     function valid() {
00116         return $this->current !== false;
00117     }
00118 }