MediaWiki  master
FileJournal.php
Go to the documentation of this file.
1 <?php
30 
39 abstract class FileJournal {
41  protected $backend;
43  protected $ttlDays;
44 
51  protected function __construct( array $config ) {
52  $this->ttlDays = $config['ttlDays'] ?? false;
53  }
54 
63  final public static function factory( array $config, $backend ) {
64  $class = $config['class'];
65  $jrn = new $class( $config );
66  if ( !$jrn instanceof self ) {
67  throw new InvalidArgumentException( "$class is not an instance of " . __CLASS__ );
68  }
69  $jrn->backend = $backend;
70 
71  return $jrn;
72  }
73 
79  final public function getTimestampedUUID() {
80  $s = '';
81  for ( $i = 0; $i < 5; $i++ ) {
82  $s .= mt_rand( 0, 2147483647 );
83  }
84  $s = Wikimedia\base_convert( sha1( $s ), 16, 36, 31 );
85 
86  $timestamp = ConvertibleTimestamp::convert( TS_MW, time() );
87 
88  return substr( Wikimedia\base_convert( $timestamp, 10, 36, 9 ) . $s, 0, 31 );
89  }
90 
102  final public function logChangeBatch( array $entries, $batchId ) {
103  if ( $entries === [] ) {
104  return StatusValue::newGood();
105  }
106 
107  return $this->doLogChangeBatch( $entries, $batchId );
108  }
109 
117  abstract protected function doLogChangeBatch( array $entries, $batchId );
118 
124  final public function getCurrentPosition() {
125  return $this->doGetCurrentPosition();
126  }
127 
132  abstract protected function doGetCurrentPosition();
133 
140  final public function getPositionAtTime( $time ) {
141  return $this->doGetPositionAtTime( $time );
142  }
143 
149  abstract protected function doGetPositionAtTime( $time );
150 
168  final public function getChangeEntries( $start = null, $limit = 0, &$next = null ) {
169  $entries = $this->doGetChangeEntries( $start, $limit ? $limit + 1 : 0 );
170  if ( $limit && count( $entries ) > $limit ) {
171  $last = array_pop( $entries ); // remove the extra entry
172  $next = $last['id']; // update for next call
173  } else {
174  $next = null; // end of list
175  }
176 
177  return $entries;
178  }
179 
186  abstract protected function doGetChangeEntries( $start, $limit );
187 
193  final public function purgeOldLogs() {
194  return $this->doPurgeOldLogs();
195  }
196 
201  abstract protected function doPurgeOldLogs();
202 }
string $backend
Definition: FileJournal.php:41
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
doGetChangeEntries( $start, $limit)
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1792
getPositionAtTime( $time)
Get the position ID of the latest journal entry at some point in time.
doGetCurrentPosition()
__construct(array $config)
Construct a new instance from configuration.
Definition: FileJournal.php:51
$last
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
getCurrentPosition()
Get the position ID of the latest journal entry.
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:773
logChangeBatch(array $entries, $batchId)
Log changes made by a batch file operation.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
getChangeEntries( $start=null, $limit=0, &$next=null)
Get an array of file change log entries.
doLogChangeBatch(array $entries, $batchId)
getTimestampedUUID()
Get a statistically unique ID string.
Definition: FileJournal.php:79
purgeOldLogs()
Purge any old log entries.
doGetPositionAtTime( $time)
static factory(array $config, $backend)
Create an appropriate FileJournal object from config.
Definition: FileJournal.php:63
Class for handling file operation journaling.
Definition: FileJournal.php:39