MediaWiki REL1_33
importImages.php
Go to the documentation of this file.
1<?php
35require_once __DIR__ . '/Maintenance.php';
36
38
39 public function __construct() {
40 parent::__construct();
41
42 $this->addDescription( 'Imports images and other media files into the wiki' );
43 $this->addArg( 'dir', 'Path to the directory containing images to be imported' );
44
45 $this->addOption( 'extensions',
46 'Comma-separated list of allowable extensions, defaults to $wgFileExtensions',
47 false,
48 true
49 );
50 $this->addOption( 'overwrite',
51 'Overwrite existing images with the same name (default is to skip them)' );
52 $this->addOption( 'limit',
53 'Limit the number of images to process. Ignored or skipped images are not counted',
54 false,
55 true
56 );
57 $this->addOption( 'from',
58 "Ignore all files until the one with the given name. Useful for resuming aborted "
59 . "imports. The name should be the file's canonical database form.",
60 false,
61 true
62 );
63 $this->addOption( 'skip-dupes',
64 'Skip images that were already uploaded under a different name (check SHA1)' );
65 $this->addOption( 'search-recursively', 'Search recursively for files in subdirectories' );
66 $this->addOption( 'sleep',
67 'Sleep between files. Useful mostly for debugging',
68 false,
69 true
70 );
71 $this->addOption( 'user',
72 "Set username of uploader, default 'Maintenance script'",
73 false,
74 true
75 );
76 // This parameter can optionally have an argument. If none specified, getOption()
77 // returns 1 which is precisely what we need.
78 $this->addOption( 'check-userblock', 'Check if the user got blocked during import' );
79 $this->addOption( 'comment',
80 "Set file description, default 'Importing file'",
81 false,
82 true
83 );
84 $this->addOption( 'comment-file',
85 'Set description to the content of this file',
86 false,
87 true
88 );
89 $this->addOption( 'comment-ext',
90 'Causes the description for each file to be loaded from a file with the same name, but '
91 . 'the extension provided. If a global description is also given, it is appended.',
92 false,
93 true
94 );
95 $this->addOption( 'summary',
96 'Upload summary, description will be used if not provided',
97 false,
98 true
99 );
100 $this->addOption( 'license',
101 'Use an optional license template',
102 false,
103 true
104 );
105 $this->addOption( 'timestamp',
106 'Override upload time/date, all MediaWiki timestamp formats are accepted',
107 false,
108 true
109 );
110 $this->addOption( 'protect',
111 'Specify the protect value (autoconfirmed,sysop)',
112 false,
113 true
114 );
115 $this->addOption( 'unprotect', 'Unprotects all uploaded images' );
116 $this->addOption( 'source-wiki-url',
117 'If specified, take User and Comment data for each imported file from this URL. '
118 . 'For example, --source-wiki-url="http://en.wikipedia.org/',
119 false,
120 true
121 );
122 $this->addOption( 'dry', "Dry run, don't import anything" );
123 }
124
125 public function execute() {
127
128 $processed = $added = $ignored = $skipped = $overwritten = $failed = 0;
129
130 $this->output( "Import Images\n\n" );
131
132 $dir = $this->getArg( 0 );
133
134 # Check Protection
135 if ( $this->hasOption( 'protect' ) && $this->hasOption( 'unprotect' ) ) {
136 $this->fatalError( "Cannot specify both protect and unprotect. Only 1 is allowed.\n" );
137 }
138
139 if ( $this->hasOption( 'protect' ) && trim( $this->getOption( 'protect' ) ) ) {
140 $this->fatalError( "You must specify a protection option.\n" );
141 }
142
143 # Prepare the list of allowed extensions
144 $extensions = $this->hasOption( 'extensions' )
145 ? explode( ',', strtolower( $this->getOption( 'extensions' ) ) )
147
148 # Search the path provided for candidates for import
149 $files = $this->findFiles( $dir, $extensions, $this->hasOption( 'search-recursively' ) );
150
151 # Initialise the user for this operation
152 $user = $this->hasOption( 'user' )
153 ? User::newFromName( $this->getOption( 'user' ) )
154 : User::newSystemUser( 'Maintenance script', [ 'steal' => true ] );
155 if ( !$user instanceof User ) {
156 $user = User::newSystemUser( 'Maintenance script', [ 'steal' => true ] );
157 }
158 $wgUser = $user;
159
160 # Get block check. If a value is given, this specified how often the check is performed
161 $checkUserBlock = (int)$this->getOption( 'check-userblock' );
162
163 $from = $this->getOption( 'from' );
164 $sleep = (int)$this->getOption( 'sleep' );
165 $limit = (int)$this->getOption( 'limit' );
166 $timestamp = $this->getOption( 'timestamp', false );
167
168 # Get the upload comment. Provide a default one in case there's no comment given.
169 $commentFile = $this->getOption( 'comment-file' );
170 if ( $commentFile !== null ) {
171 $comment = file_get_contents( $commentFile );
172 if ( $comment === false || $comment === null ) {
173 $this->fatalError( "failed to read comment file: {$commentFile}\n" );
174 }
175 } else {
176 $comment = $this->getOption( 'comment', 'Importing file' );
177 }
178 $commentExt = $this->getOption( 'comment-ext' );
179 $summary = $this->getOption( 'summary', '' );
180
181 $license = $this->getOption( 'license', '' );
182
183 $sourceWikiUrl = $this->getOption( 'source-wiki-url' );
184
185 # Batch "upload" operation
186 $count = count( $files );
187 if ( $count > 0 ) {
188 foreach ( $files as $file ) {
189 if ( $sleep && ( $processed > 0 ) ) {
190 sleep( $sleep );
191 }
192
193 $base = UtfNormal\Validator::cleanUp( wfBaseName( $file ) );
194
195 # Validate a title
196 $title = Title::makeTitleSafe( NS_FILE, $base );
197 if ( !is_object( $title ) ) {
198 $this->output(
199 "{$base} could not be imported; a valid title cannot be produced\n" );
200 continue;
201 }
202
203 if ( $from ) {
204 if ( $from == $title->getDBkey() ) {
205 $from = null;
206 } else {
207 $ignored++;
208 continue;
209 }
210 }
211
212 if ( $checkUserBlock && ( ( $processed % $checkUserBlock ) == 0 ) ) {
213 $user->clearInstanceCache( 'name' ); // reload from DB!
214 if ( $user->isBlocked() ) {
215 $this->output( $user->getName() . " was blocked! Aborting.\n" );
216 break;
217 }
218 }
219
220 # Check existence
222 if ( $image->exists() ) {
223 if ( $this->hasOption( 'overwrite' ) ) {
224 $this->output( "{$base} exists, overwriting..." );
225 $svar = 'overwritten';
226 } else {
227 $this->output( "{$base} exists, skipping\n" );
228 $skipped++;
229 continue;
230 }
231 } else {
232 if ( $this->hasOption( 'skip-dupes' ) ) {
233 $repo = $image->getRepo();
234 # XXX: we end up calculating this again when actually uploading. that sucks.
236
237 $dupes = $repo->findBySha1( $sha1 );
238
239 if ( $dupes ) {
240 $this->output(
241 "{$base} already exists as {$dupes[0]->getName()}, skipping\n" );
242 $skipped++;
243 continue;
244 }
245 }
246
247 $this->output( "Importing {$base}..." );
248 $svar = 'added';
249 }
250
251 if ( $sourceWikiUrl ) {
252 /* find comment text directly from source wiki, through MW's API */
253 $real_comment = $this->getFileCommentFromSourceWiki( $sourceWikiUrl, $base );
254 if ( $real_comment === false ) {
255 $commentText = $comment;
256 } else {
257 $commentText = $real_comment;
258 }
259
260 /* find user directly from source wiki, through MW's API */
261 $real_user = $this->getFileUserFromSourceWiki( $sourceWikiUrl, $base );
262 if ( $real_user === false ) {
263 $wgUser = $user;
264 } else {
265 $wgUser = User::newFromName( $real_user );
266 if ( $wgUser === false ) {
267 # user does not exist in target wiki
268 $this->output(
269 "failed: user '$real_user' does not exist in target wiki." );
270 continue;
271 }
272 }
273 } else {
274 # Find comment text
275 $commentText = false;
276
277 if ( $commentExt ) {
278 $f = $this->findAuxFile( $file, $commentExt );
279 if ( !$f ) {
280 $this->output( " No comment file with extension {$commentExt} found "
281 . "for {$file}, using default comment. " );
282 } else {
283 $commentText = file_get_contents( $f );
284 if ( !$commentText ) {
285 $this->output(
286 " Failed to load comment file {$f}, using default comment. " );
287 }
288 }
289 }
290
291 if ( !$commentText ) {
292 $commentText = $comment;
293 }
294 }
295
296 # Import the file
297 if ( $this->hasOption( 'dry' ) ) {
298 $this->output(
299 " publishing {$file} by '{$wgUser->getName()}', comment '$commentText'... "
300 );
301 } else {
302 $mwProps = new MWFileProps( MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() );
303 $props = $mwProps->getPropsFromPath( $file, true );
304 $flags = 0;
305 $publishOptions = [];
306 $handler = MediaHandler::getHandler( $props['mime'] );
307 if ( $handler ) {
308 $metadata = Wikimedia\quietCall( 'unserialize', $props['metadata'] );
309
310 $publishOptions['headers'] = $handler->getContentHeaders( $metadata );
311 } else {
312 $publishOptions['headers'] = [];
313 }
314 $archive = $image->publish( $file, $flags, $publishOptions );
315 if ( !$archive->isGood() ) {
316 $this->output( "failed. (" .
317 $archive->getWikiText( false, false, 'en' ) .
318 ")\n" );
319 $failed++;
320 continue;
321 }
322 }
323
324 $commentText = SpecialUpload::getInitialPageText( $commentText, $license );
325 if ( !$this->hasOption( 'summary' ) ) {
326 $summary = $commentText;
327 }
328
329 if ( $this->hasOption( 'dry' ) ) {
330 $this->output( "done.\n" );
331 } elseif ( $image->recordUpload2(
332 $archive->value,
333 $summary,
334 $commentText,
335 $props,
336 $timestamp
337 )->isOK() ) {
338 $this->output( "done.\n" );
339
340 $doProtect = false;
341
342 $protectLevel = $this->getOption( 'protect' );
343
344 if ( $protectLevel && in_array( $protectLevel, $wgRestrictionLevels ) ) {
345 $doProtect = true;
346 }
347 if ( $this->hasOption( 'unprotect' ) ) {
348 $protectLevel = '';
349 $doProtect = true;
350 }
351
352 if ( $doProtect ) {
353 # Protect the file
354 $this->output( "\nWaiting for replica DBs...\n" );
355 // Wait for replica DBs.
356 sleep( 2.0 ); # Why this sleep?
358
359 $this->output( "\nSetting image restrictions ... " );
360
361 $cascade = false;
362 $restrictions = [];
363 foreach ( $title->getRestrictionTypes() as $type ) {
364 $restrictions[$type] = $protectLevel;
365 }
366
367 $page = WikiPage::factory( $title );
368 $status = $page->doUpdateRestrictions( $restrictions, [], $cascade, '', $user );
369 $this->output( ( $status->isOK() ? 'done' : 'failed' ) . "\n" );
370 }
371 } else {
372 $this->output( "failed. (at recordUpload stage)\n" );
373 $svar = 'failed';
374 }
375
376 $$svar++;
377 $processed++;
378
379 if ( $limit && $processed >= $limit ) {
380 break;
381 }
382 }
383
384 # Print out some statistics
385 $this->output( "\n" );
386 foreach (
387 [
388 'count' => 'Found',
389 'limit' => 'Limit',
390 'ignored' => 'Ignored',
391 'added' => 'Added',
392 'skipped' => 'Skipped',
393 'overwritten' => 'Overwritten',
394 'failed' => 'Failed'
395 ] as $var => $desc
396 ) {
397 if ( $$var > 0 ) {
398 $this->output( "{$desc}: {$$var}\n" );
399 }
400 }
401 } else {
402 $this->output( "No suitable files could be found for import.\n" );
403 }
404 }
405
414 private function findFiles( $dir, $exts, $recurse = false ) {
415 if ( is_dir( $dir ) ) {
416 $dhl = opendir( $dir );
417 if ( $dhl ) {
418 $files = [];
419 while ( ( $file = readdir( $dhl ) ) !== false ) {
420 if ( is_file( $dir . '/' . $file ) ) {
421 $ext = pathinfo( $file, PATHINFO_EXTENSION );
422 if ( array_search( strtolower( $ext ), $exts ) !== false ) {
423 $files[] = $dir . '/' . $file;
424 }
425 } elseif ( $recurse && is_dir( $dir . '/' . $file ) && $file !== '..' && $file !== '.' ) {
426 $files = array_merge( $files, $this->findFiles( $dir . '/' . $file, $exts, true ) );
427 }
428 }
429
430 return $files;
431 } else {
432 return [];
433 }
434 } else {
435 return [];
436 }
437 }
438
453 private function findAuxFile( $file, $auxExtension, $maxStrip = 1 ) {
454 if ( strpos( $auxExtension, '.' ) !== 0 ) {
455 $auxExtension = '.' . $auxExtension;
456 }
457
458 $d = dirname( $file );
459 $n = basename( $file );
460
461 while ( $maxStrip >= 0 ) {
462 $f = $d . '/' . $n . $auxExtension;
463
464 if ( file_exists( $f ) ) {
465 return $f;
466 }
467
468 $idx = strrpos( $n, '.' );
469 if ( !$idx ) {
470 break;
471 }
472
473 $n = substr( $n, 0, $idx );
474 $maxStrip -= 1;
475 }
476
477 return false;
478 }
479
480 # @todo FIXME: Access the api in a saner way and performing just one query
481 # (preferably batching files too).
482 private function getFileCommentFromSourceWiki( $wiki_host, $file ) {
483 $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:'
484 . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=comment';
485 $body = Http::get( $url, [], __METHOD__ );
486 if ( preg_match( '#<ii comment="([^"]*)" />#', $body, $matches ) == 0 ) {
487 return false;
488 }
489
490 return html_entity_decode( $matches[1] );
491 }
492
493 private function getFileUserFromSourceWiki( $wiki_host, $file ) {
494 $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:'
495 . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=user';
496 $body = Http::get( $url, [], __METHOD__ );
497 if ( preg_match( '#<ii user="([^"]*)" />#', $body, $matches ) == 0 ) {
498 return false;
499 }
500
501 return html_entity_decode( $matches[1] );
502 }
503
504}
505
506$maintClass = ImportImages::class;
507require_once RUN_MAINTENANCE_IF_MAIN;
$wgRestrictionLevels
Rights which can be required for each protection level (via action=protect)
$wgFileExtensions
This is the list of preferred extensions for uploading files.
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
wfBaseName( $path, $suffix='')
Return the final portion of a pathname.
wfLocalFile( $title)
Get an object referring to a locally registered file.
static getSha1Base36FromPath( $path)
Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case encoding,...
Definition FSFile.php:218
static get( $url, array $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'GET' )
Definition Http.php:98
execute()
Do the actual work.
getFileCommentFromSourceWiki( $wiki_host, $file)
findFiles( $dir, $exts, $recurse=false)
Search a directory for files with one of a set of extensions.
__construct()
Default constructor.
findAuxFile( $file, $auxExtension, $maxStrip=1)
Find an auxilliary file with the given extension, matching the give base file path.
getFileUserFromSourceWiki( $wiki_host, $file)
MimeMagic helper wrapper.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option exists.
getArg( $argId=0, $default=null)
Get an argument.
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.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
static getHandler( $type)
Get a MediaHandler for a given MIME type from the instance cache.
static getInitialPageText( $comment='', $license='', $copyStatus='', $source='', Config $config=null)
Get the initial image page text based on a comment and optional file status information.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:48
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:585
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.
Definition User.php:813
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
const NS_FILE
Definition Defines.php:79
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 $image
Definition hooks.txt:886
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
Definition hooks.txt:894
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, 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. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition hooks.txt:1266
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
return true to allow those checks to and false if checking is done & $user
Definition hooks.txt:1510
$maintClass
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
require_once RUN_MAINTENANCE_IF_MAIN
A helper class for throttling authentication attempts.
$f
Definition router.php:79
if(!is_readable( $file)) $ext
Definition router.php:48
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Definition router.php:42