MediaWiki
REL1_22
|
00001 <?php 00038 abstract class FileJournal { 00039 protected $backend; // string 00040 protected $ttlDays; // integer 00041 00049 protected function __construct( array $config ) { 00050 $this->ttlDays = isset( $config['ttlDays'] ) ? $config['ttlDays'] : false; 00051 } 00052 00061 final public static function factory( array $config, $backend ) { 00062 $class = $config['class']; 00063 $jrn = new $class( $config ); 00064 if ( !$jrn instanceof self ) { 00065 throw new MWException( "Class given is not an instance of FileJournal." ); 00066 } 00067 $jrn->backend = $backend; 00068 return $jrn; 00069 } 00070 00076 final public function getTimestampedUUID() { 00077 $s = ''; 00078 for ( $i = 0; $i < 5; $i++ ) { 00079 $s .= mt_rand( 0, 2147483647 ); 00080 } 00081 $s = wfBaseConvert( sha1( $s ), 16, 36, 31 ); 00082 return substr( wfBaseConvert( wfTimestamp( TS_MW ), 10, 36, 9 ) . $s, 0, 31 ); 00083 } 00084 00097 final public function logChangeBatch( array $entries, $batchId ) { 00098 if ( !count( $entries ) ) { 00099 return Status::newGood(); 00100 } 00101 return $this->doLogChangeBatch( $entries, $batchId ); 00102 } 00103 00111 abstract protected function doLogChangeBatch( array $entries, $batchId ); 00112 00118 final public function getCurrentPosition() { 00119 return $this->doGetCurrentPosition(); 00120 } 00121 00126 abstract protected function doGetCurrentPosition(); 00127 00134 final public function getPositionAtTime( $time ) { 00135 return $this->doGetPositionAtTime( $time ); 00136 } 00137 00143 abstract protected function doGetPositionAtTime( $time ); 00144 00165 final public function getChangeEntries( $start = null, $limit = 0, &$next = null ) { 00166 $entries = $this->doGetChangeEntries( $start, $limit ? $limit + 1 : 0 ); 00167 if ( $limit && count( $entries ) > $limit ) { 00168 $last = array_pop( $entries ); // remove the extra entry 00169 $next = $last['id']; // update for next call 00170 } else { 00171 $next = null; // end of list 00172 } 00173 return $entries; 00174 } 00175 00180 abstract protected function doGetChangeEntries( $start, $limit ); 00181 00187 final public function purgeOldLogs() { 00188 return $this->doPurgeOldLogs(); 00189 } 00190 00195 abstract protected function doPurgeOldLogs(); 00196 } 00197 00202 class NullFileJournal extends FileJournal { 00209 protected function doLogChangeBatch( array $entries, $batchId ) { 00210 return Status::newGood(); 00211 } 00212 00217 protected function doGetCurrentPosition() { 00218 return false; 00219 } 00220 00226 protected function doGetPositionAtTime( $time ) { 00227 return false; 00228 } 00229 00234 protected function doGetChangeEntries( $start, $limit ) { 00235 return array(); 00236 } 00237 00242 protected function doPurgeOldLogs() { 00243 return Status::newGood(); 00244 } 00245 }