MediaWiki
REL1_20
|
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 00133 final public function getChangeEntries( $start = null, $limit = 0, &$next = null ) { 00134 $entries = $this->doGetChangeEntries( $start, $limit ? $limit + 1 : 0 ); 00135 if ( $limit && count( $entries ) > $limit ) { 00136 $last = array_pop( $entries ); // remove the extra entry 00137 $next = $last['id']; // update for next call 00138 } else { 00139 $next = null; // end of list 00140 } 00141 return $entries; 00142 } 00143 00148 abstract protected function doGetChangeEntries( $start, $limit ); 00149 00155 final public function purgeOldLogs() { 00156 return $this->doPurgeOldLogs(); 00157 } 00158 00163 abstract protected function doPurgeOldLogs(); 00164 } 00165 00170 class NullFileJournal extends FileJournal { 00177 protected function doLogChangeBatch( array $entries, $batchId ) { 00178 return Status::newGood(); 00179 } 00180 00185 protected function doGetChangeEntries( $start, $limit ) { 00186 return array(); 00187 } 00188 00193 protected function doPurgeOldLogs() { 00194 return Status::newGood(); 00195 } 00196 }