MediaWiki  REL1_19
TitleArray.php
Go to the documentation of this file.
00001 <?php
00012 abstract class TitleArray implements Iterator {
00019         static function newFromResult( $res ) {
00020                 $array = null;
00021                 if ( !wfRunHooks( 'TitleArrayFromResult', array( &$array, $res ) ) ) {
00022                         return null;
00023                 }
00024                 if ( $array === null ) {
00025                         $array = self::newFromResult_internal( $res );
00026                 }
00027                 return $array;
00028         }
00029 
00034         protected static function newFromResult_internal( $res ) {
00035                 $array = new TitleArrayFromResult( $res );
00036                 return $array;
00037         }
00038 }
00039 
00040 class TitleArrayFromResult extends TitleArray {
00041 
00045         var $res;
00046         var $key, $current;
00047 
00048         function __construct( $res ) {
00049                 $this->res = $res;
00050                 $this->key = 0;
00051                 $this->setCurrent( $this->res->current() );
00052         }
00053 
00058         protected function setCurrent( $row ) {
00059                 if ( $row === false ) {
00060                         $this->current = false;
00061                 } else {
00062                         $this->current = Title::newFromRow( $row );
00063                 }
00064         }
00065 
00069         public function count() {
00070                 return $this->res->numRows();
00071         }
00072 
00073         function current() {
00074                 return $this->current;
00075         }
00076 
00077         function key() {
00078                 return $this->key;
00079         }
00080 
00081         function next() {
00082                 $row = $this->res->next();
00083                 $this->setCurrent( $row );
00084                 $this->key++;
00085         }
00086 
00087         function rewind() {
00088                 $this->res->rewind();
00089                 $this->key = 0;
00090                 $this->setCurrent( $this->res->current() );
00091         }
00092 
00096         function valid() {
00097                 return $this->current !== false;
00098         }
00099 }