MediaWiki
REL1_24
|
00001 <?php 00038 abstract class FileJournal { 00040 protected $backend; 00041 00043 protected $ttlDays; 00044 00051 protected function __construct( array $config ) { 00052 $this->ttlDays = isset( $config['ttlDays'] ) ? $config['ttlDays'] : false; 00053 } 00054 00063 final public static function factory( array $config, $backend ) { 00064 $class = $config['class']; 00065 $jrn = new $class( $config ); 00066 if ( !$jrn instanceof self ) { 00067 throw new MWException( "Class given is not an instance of FileJournal." ); 00068 } 00069 $jrn->backend = $backend; 00070 00071 return $jrn; 00072 } 00073 00079 final public function getTimestampedUUID() { 00080 $s = ''; 00081 for ( $i = 0; $i < 5; $i++ ) { 00082 $s .= mt_rand( 0, 2147483647 ); 00083 } 00084 $s = wfBaseConvert( sha1( $s ), 16, 36, 31 ); 00085 00086 return substr( wfBaseConvert( wfTimestamp( TS_MW ), 10, 36, 9 ) . $s, 0, 31 ); 00087 } 00088 00100 final public function logChangeBatch( array $entries, $batchId ) { 00101 if ( !count( $entries ) ) { 00102 return Status::newGood(); 00103 } 00104 00105 return $this->doLogChangeBatch( $entries, $batchId ); 00106 } 00107 00115 abstract protected function doLogChangeBatch( array $entries, $batchId ); 00116 00122 final public function getCurrentPosition() { 00123 return $this->doGetCurrentPosition(); 00124 } 00125 00130 abstract protected function doGetCurrentPosition(); 00131 00138 final public function getPositionAtTime( $time ) { 00139 return $this->doGetPositionAtTime( $time ); 00140 } 00141 00147 abstract protected function doGetPositionAtTime( $time ); 00148 00166 final public function getChangeEntries( $start = null, $limit = 0, &$next = null ) { 00167 $entries = $this->doGetChangeEntries( $start, $limit ? $limit + 1 : 0 ); 00168 if ( $limit && count( $entries ) > $limit ) { 00169 $last = array_pop( $entries ); // remove the extra entry 00170 $next = $last['id']; // update for next call 00171 } else { 00172 $next = null; // end of list 00173 } 00174 00175 return $entries; 00176 } 00177 00184 abstract protected function doGetChangeEntries( $start, $limit ); 00185 00191 final public function purgeOldLogs() { 00192 return $this->doPurgeOldLogs(); 00193 } 00194 00199 abstract protected function doPurgeOldLogs(); 00200 } 00201 00206 class NullFileJournal extends FileJournal { 00213 protected function doLogChangeBatch( array $entries, $batchId ) { 00214 return Status::newGood(); 00215 } 00216 00221 protected function doGetCurrentPosition() { 00222 return false; 00223 } 00224 00230 protected function doGetPositionAtTime( $time ) { 00231 return false; 00232 } 00233 00240 protected function doGetChangeEntries( $start, $limit ) { 00241 return array(); 00242 } 00243 00248 protected function doPurgeOldLogs() { 00249 return Status::newGood(); 00250 } 00251 }