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 00030 protected static function newFromResult_internal( $res ) { 00031 $array = new TitleArrayFromResult( $res ); 00032 return $array; 00033 } 00034 } 00035 00036 class TitleArrayFromResult extends TitleArray { 00037 var $res; 00038 var $key, $current; 00039 00040 function __construct( $res ) { 00041 $this->res = $res; 00042 $this->key = 0; 00043 $this->setCurrent( $this->res->current() ); 00044 } 00045 00046 protected function setCurrent( $row ) { 00047 if ( $row === false ) { 00048 $this->current = false; 00049 } else { 00050 $this->current = Title::newFromRow( $row ); 00051 } 00052 } 00053 00054 public function count() { 00055 return $this->res->numRows(); 00056 } 00057 00058 function current() { 00059 return $this->current; 00060 } 00061 00062 function key() { 00063 return $this->key; 00064 } 00065 00066 function next() { 00067 $row = $this->res->next(); 00068 $this->setCurrent( $row ); 00069 $this->key++; 00070 } 00071 00072 function rewind() { 00073 $this->res->rewind(); 00074 $this->key = 0; 00075 $this->setCurrent( $this->res->current() ); 00076 } 00077 00078 function valid() { 00079 return $this->current !== false; 00080 } 00081 }