31require_once __DIR__ .
'/Maintenance.php';
60 parent::__construct();
63 $this->
addOption(
'table',
'revision or archive table, or `all` to populate both',
false,
66 'Reuse content table rows when the address and model are the same. '
67 .
'This will increase the script\'s time and memory usage, perhaps significantly.',
69 $this->
addOption(
'start-revision',
'The rev_id to start at',
false,
true );
70 $this->
addOption(
'start-archive',
'The ar_rev_id to start at',
false,
true );
76 $this->contentModelStore = MediaWikiServices::getInstance()->getContentModelStore();
77 $this->slotRoleStore = MediaWikiServices::getInstance()->getSlotRoleStore();
78 $this->blobStore = MediaWikiServices::getInstance()->getBlobStore();
82 $this->contentModelStore->reloadMap();
83 $this->slotRoleStore->reloadMap();
84 $this->mainRoleId = $this->slotRoleStore->acquireId( SlotRecord::MAIN );
94 '...cannot update while \$wgMultiContentRevisionSchemaMigrationStage '
95 .
'does not have the SCHEMA_COMPAT_WRITE_NEW bit set.'
102 if ( $this->
getOption(
'reuse-content',
false ) ) {
106 foreach ( $this->
getTables() as $table ) {
111 $this->
writeln(
"Done. Processed $this->totalCount rows in $elapsed seconds" );
119 $table = $this->
getOption(
'table',
'all' );
120 $validTableOptions = [
'all',
'revision',
'archive' ];
122 if ( !
in_array( $table, $validTableOptions ) ) {
123 $this->
fatalError(
'Invalid table. Must be either `revision` or `archive` or `all`' );
126 if ( $table ===
'all' ) {
127 $tables = [
'revision',
'archive' ];
137 $this->
writeln(
"Loading existing content table rows..." );
138 $this->contentRowMap = [];
144 [
'content_id',
'content_address',
'content_model' ],
145 $from ?
"content_id > $from" :
'',
147 [
'ORDER BY' =>
'content_id',
'LIMIT' => $this->
getBatchSize() ]
152 foreach (
$res as $row ) {
153 $from = $row->content_id;
154 $this->contentRowMap[
"{$row->content_model}:{$row->content_address}"] = $row->content_id;
158 $this->
writeln(
"Loaded " . count( $this->contentRowMap ) .
" rows in $elapsed seconds" );
167 $this->
writeln(
"Populating $table..." );
169 if ( $table ===
'revision' ) {
171 $tables = [
'revision',
'slots',
'page' ];
175 'sha1' =>
'rev_sha1',
176 'text_id' =>
'rev_text_id',
177 'content_model' =>
'rev_content_model',
178 'namespace' =>
'page_namespace',
179 'title' =>
'page_title',
182 'slots' => [
'LEFT JOIN',
'rev_id=slot_revision_id' ],
183 'page' => [
'LEFT JOIN',
'rev_page=page_id' ],
185 $startOption =
'start-revision';
187 $idField =
'ar_rev_id';
188 $tables = [
'archive',
'slots' ];
190 'rev_id' =>
'ar_rev_id',
193 'text_id' =>
'ar_text_id',
194 'content_model' =>
'ar_content_model',
195 'namespace' =>
'ar_namespace',
196 'title' =>
'ar_title',
199 'slots' => [
'LEFT JOIN',
'ar_rev_id=slot_revision_id' ],
201 $startOption =
'start-archive';
204 if ( !$this->dbw->fieldExists( $table, $fields[
'text_id'], __METHOD__ ) ) {
205 $this->
writeln(
"No need to populate, $table.{$fields['text_id']} field does not exist" );
209 $minmax = $this->dbw->selectRow(
211 [
'min' =>
"MIN( $idField )",
'max' =>
"MAX( $idField )" ],
215 if ( $this->
hasOption( $startOption ) ) {
220 $minmax = (
object)[
'min' => 1,
'max' => 0 ];
225 for ( $startId = $minmax->min; $startId <= $minmax->max; $startId += $batchSize ) {
226 $endId = min( $startId + $batchSize - 1, $minmax->max );
227 $rows = $this->dbw->select(
231 "$idField >= $startId",
232 "$idField <= $endId",
233 'slot_revision_id IS NULL',
236 [
'ORDER BY' =>
'rev_id' ],
239 if (
$rows->numRows() !== 0 ) {
245 "... $table processed up to revision id $endId of {$minmax->max}"
246 .
" ($this->count rows in $elapsed seconds)"
251 $this->
writeln(
"Done populating $table table. Processed $this->count rows in $elapsed seconds" );
263 if ( $this->contentRowMap ===
null ) {
273 foreach (
$rows as $row ) {
274 $revisionId = $row->rev_id;
276 Assert::invariant( $revisionId !==
null,
'rev_id must not be null' );
279 $modelId = $this->contentModelStore->acquireId( $model );
280 $address = SqlBlobStore::makeAddressFromTextId( $row->text_id );
282 $key =
"{$modelId}:{$address}";
285 if ( !
isset( $map[$key] ) ) {
290 'content_size' => (
int)$row->len,
291 'content_sha1' => $row->sha1,
292 'content_model' => $modelId,
293 'content_address' => $address,
299 if ( $contentRows ) {
300 $id = $this->dbw->selectField(
'content',
'MAX(content_id)',
'', __METHOD__ );
301 $this->dbw->insert(
'content', $contentRows, __METHOD__ );
302 $res = $this->dbw->select(
304 [
'content_id',
'content_model',
'content_address' ],
305 'content_id > ' . (
int)$id,
308 foreach (
$res as $row ) {
309 $key = $row->content_model .
':' . $row->content_address;
310 $map[$key] = $row->content_id;
316 foreach (
$rows as $row ) {
317 $revisionId = $row->rev_id;
318 $contentId = $map[$contentKeys[
$revisionId]] ??
false;
319 if ( $contentId ===
false ) {
332 $this->dbw->insert(
'slots', $slotRows, __METHOD__ );
333 $this->count += count( $slotRows );
334 $this->totalCount += count( $slotRows );
335 }
catch ( \Exception
$e ) {
337 $this->
fatalError(
"Failed to populate content table $table row batch starting at $startId "
338 .
"due to exception: " . $e->__toString() );
349 if (
isset( $row->content_model ) ) {
350 return $row->content_model;
353 $title = Title::makeTitle( $row->namespace, $row->title );
355 return ContentHandler::getDefaultModelFor( $title );
362 $this->
output(
"$msg\n" );
374 if ( !
isset( $row->content_model ) ) {
376 $row->content_model = $model;
379 if (
isset( $row->len ) && isset( $row->sha1 ) && $row->sha1 !==
'' ) {
384 $blob = $this->blobStore->getBlob( $address );
386 if ( !
isset( $row->len ) ) {
388 $handler = ContentHandler::getForModelID( $model );
394 if ( !
isset( $row->sha1 ) || $row->sha1 ===
'' ) {
395 $row->sha1 = SlotRecord::base36Sha1(
$blob );
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
int $wgMultiContentRevisionSchemaMigrationStage
RevisionStore table schema migration stage (content, slots, content_models & slot_roles tables).
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular option exists.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
rollbackTransaction(IDatabase $dbw, $fname)
Rollback the transcation on a DB handle.
setBatchSize( $s=0)
Set the batch size.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Populate the content and slot tables.
array null $contentRowMap
Map "{$modelId}:{$address}" to content_id.
NameTableStore $slotRoleStore
__construct()
Default constructor.
execute()
Do the actual work.
fillMissingFields( $row, $model, $address)
Compute any missing fields in $row.
populateContentTablesForRowBatch(ResultWrapper $rows, $startId, $table)
NameTableStore $contentModelStore
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
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 it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
this hook is for auditing only 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 & $tables
returning false will NOT prevent logging $e
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
const SCHEMA_COMPAT_WRITE_NEW
require_once RUN_MAINTENANCE_IF_MAIN
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))