MediaWiki REL1_29
DBFileJournal.php
Go to the documentation of this file.
1<?php
28
35 protected $dbw;
36
37 protected $wiki = false; // string; wiki DB name
38
45 protected function __construct( array $config ) {
46 parent::__construct( $config );
47
48 $this->wiki = $config['wiki'];
49 }
50
57 protected function doLogChangeBatch( array $entries, $batchId ) {
58 $status = StatusValue::newGood();
59
60 try {
61 $dbw = $this->getMasterDB();
62 } catch ( DBError $e ) {
63 $status->fatal( 'filejournal-fail-dbconnect', $this->backend );
64
65 return $status;
66 }
67
68 $now = wfTimestamp( TS_UNIX );
69
70 $data = [];
71 foreach ( $entries as $entry ) {
72 $data[] = [
73 'fj_batch_uuid' => $batchId,
74 'fj_backend' => $this->backend,
75 'fj_op' => $entry['op'],
76 'fj_path' => $entry['path'],
77 'fj_new_sha1' => $entry['newSha1'],
78 'fj_timestamp' => $dbw->timestamp( $now )
79 ];
80 }
81
82 try {
83 $dbw->insert( 'filejournal', $data, __METHOD__ );
84 if ( mt_rand( 0, 99 ) == 0 ) {
85 $this->purgeOldLogs(); // occasionally delete old logs
86 }
87 } catch ( DBError $e ) {
88 $status->fatal( 'filejournal-fail-dbquery', $this->backend );
89
90 return $status;
91 }
92
93 return $status;
94 }
95
100 protected function doGetCurrentPosition() {
101 $dbw = $this->getMasterDB();
102
103 return $dbw->selectField( 'filejournal', 'MAX(fj_id)',
104 [ 'fj_backend' => $this->backend ],
105 __METHOD__
106 );
107 }
108
114 protected function doGetPositionAtTime( $time ) {
115 $dbw = $this->getMasterDB();
116
117 $encTimestamp = $dbw->addQuotes( $dbw->timestamp( $time ) );
118
119 return $dbw->selectField( 'filejournal', 'fj_id',
120 [ 'fj_backend' => $this->backend, "fj_timestamp <= $encTimestamp" ],
121 __METHOD__,
122 [ 'ORDER BY' => 'fj_timestamp DESC' ]
123 );
124 }
125
132 protected function doGetChangeEntries( $start, $limit ) {
133 $dbw = $this->getMasterDB();
134
135 $res = $dbw->select( 'filejournal', '*',
136 [
137 'fj_backend' => $this->backend,
138 'fj_id >= ' . $dbw->addQuotes( (int)$start ) ], // $start may be 0
139 __METHOD__,
140 array_merge( [ 'ORDER BY' => 'fj_id ASC' ],
141 $limit ? [ 'LIMIT' => $limit ] : [] )
142 );
143
144 $entries = [];
145 foreach ( $res as $row ) {
146 $item = [];
147 foreach ( (array)$row as $key => $value ) {
148 $item[substr( $key, 3 )] = $value; // "fj_op" => "op"
149 }
150 $entries[] = $item;
151 }
152
153 return $entries;
154 }
155
161 protected function doPurgeOldLogs() {
162 $status = StatusValue::newGood();
163 if ( $this->ttlDays <= 0 ) {
164 return $status; // nothing to do
165 }
166
167 $dbw = $this->getMasterDB();
168 $dbCutoff = $dbw->timestamp( time() - 86400 * $this->ttlDays );
169
170 $dbw->delete( 'filejournal',
171 [ 'fj_timestamp < ' . $dbw->addQuotes( $dbCutoff ) ],
172 __METHOD__
173 );
174
175 return $status;
176 }
177
184 protected function getMasterDB() {
185 if ( !$this->dbw ) {
186 // Get a separate connection in autocommit mode
187 $lb = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->newMainLB();
188 $this->dbw = $lb->getConnection( DB_MASTER, [], $this->wiki );
189 $this->dbw->clearFlag( DBO_TRX );
190 }
191
192 return $this->dbw;
193 }
194}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Version of FileJournal that logs to a DB table.
doGetChangeEntries( $start, $limit)
getMasterDB()
Get a master connection to the logging DB.
doLogChangeBatch(array $entries, $batchId)
doGetPositionAtTime( $time)
__construct(array $config)
Construct a new instance from configuration.
Class for handling file operation journaling.
purgeOldLogs()
Purge any old log entries.
string $backend
MediaWikiServices is the service locator for the application scope of MediaWiki.
Database error base class.
Definition DBError.php:30
$res
Definition database.txt:21
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
the array() calling protocol came about after MediaWiki 1.4rc1.
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition hooks.txt:1769
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers please use GetContentModels hook to make them known to core if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
Definition hooks.txt:1143
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition hooks.txt:1049
returning false will NOT prevent logging $e
Definition hooks.txt:2127
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:37
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:40
selectField( $table, $var, $cond='', $fname=__METHOD__, $options=[])
A SELECT wrapper which returns a single field from a single result row.
select( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Execute a SELECT query constructed using the various parameters provided.
delete( $table, $conds, $fname=__METHOD__)
DELETE query wrapper.
addQuotes( $s)
Adds quotes and backslashes.
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
insert( $table, $a, $fname=__METHOD__, $options=[])
INSERT wrapper, inserts an array into a table.
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning maintenance scripts have been cleaned up to use a unified class Directory structure How to run a script How to write your own DIRECTORY STRUCTURE The maintenance directory of a MediaWiki installation contains several all of which have unique purposes HOW TO RUN A SCRIPT Ridiculously just call php someScript php that s in the top level maintenance directory if not default wiki
const DB_MASTER
Definition defines.php:26
const DBO_TRX
Definition defines.php:12