MediaWiki  master
importImages.php
Go to the documentation of this file.
1 <?php
36 
37 require_once __DIR__ . '/Maintenance.php';
38 
39 class ImportImages extends Maintenance {
40 
41  public function __construct() {
42  parent::__construct();
43 
44  $this->addDescription( 'Imports images and other media files into the wiki' );
45  $this->addArg( 'dir', 'Path to the directory containing images to be imported' );
46 
47  $this->addOption( 'extensions',
48  'Comma-separated list of allowable extensions, defaults to $wgFileExtensions',
49  false,
50  true
51  );
52  $this->addOption( 'overwrite',
53  'Overwrite existing images with the same name (default is to skip them)' );
54  $this->addOption( 'limit',
55  'Limit the number of images to process. Ignored or skipped images are not counted',
56  false,
57  true
58  );
59  $this->addOption( 'from',
60  "Ignore all files until the one with the given name. Useful for resuming aborted "
61  . "imports. The name should be the file's canonical database form.",
62  false,
63  true
64  );
65  $this->addOption( 'skip-dupes',
66  'Skip images that were already uploaded under a different name (check SHA1)' );
67  $this->addOption( 'search-recursively', 'Search recursively for files in subdirectories' );
68  $this->addOption( 'sleep',
69  'Sleep between files. Useful mostly for debugging',
70  false,
71  true
72  );
73  $this->addOption( 'user',
74  "Set username of uploader, default 'Maintenance script'",
75  false,
76  true
77  );
78  // This parameter can optionally have an argument. If none specified, getOption()
79  // returns 1 which is precisely what we need.
80  $this->addOption( 'check-userblock', 'Check if the user got blocked during import' );
81  $this->addOption( 'comment',
82  "Set file description, default 'Importing file'",
83  false,
84  true
85  );
86  $this->addOption( 'comment-file',
87  'Set description to the content of this file',
88  false,
89  true
90  );
91  $this->addOption( 'comment-ext',
92  'Causes the description for each file to be loaded from a file with the same name, but '
93  . 'the extension provided. If a global description is also given, it is appended.',
94  false,
95  true
96  );
97  $this->addOption( 'summary',
98  'Upload summary, description will be used if not provided',
99  false,
100  true
101  );
102  $this->addOption( 'license',
103  'Use an optional license template',
104  false,
105  true
106  );
107  $this->addOption( 'timestamp',
108  'Override upload time/date, all MediaWiki timestamp formats are accepted',
109  false,
110  true
111  );
112  $this->addOption( 'protect',
113  'Specify the protect value (autoconfirmed,sysop)',
114  false,
115  true
116  );
117  $this->addOption( 'unprotect', 'Unprotects all uploaded images' );
118  $this->addOption( 'source-wiki-url',
119  'If specified, take User and Comment data for each imported file from this URL. '
120  . 'For example, --source-wiki-url="http://en.wikipedia.org/',
121  false,
122  true
123  );
124  $this->addOption( 'dry', "Dry run, don't import anything" );
125  }
126 
127  public function execute() {
128  global $wgFileExtensions, $wgUser, $wgRestrictionLevels;
129 
130  $processed = $added = $ignored = $skipped = $overwritten = $failed = 0;
131 
132  $this->output( "Importing Files\n\n" );
133 
134  $dir = $this->getArg( 0 );
135 
136  # Check Protection
137  if ( $this->hasOption( 'protect' ) && $this->hasOption( 'unprotect' ) ) {
138  $this->fatalError( "Cannot specify both protect and unprotect. Only 1 is allowed.\n" );
139  }
140 
141  if ( $this->hasOption( 'protect' ) && trim( $this->getOption( 'protect' ) ) ) {
142  $this->fatalError( "You must specify a protection option.\n" );
143  }
144 
145  # Prepare the list of allowed extensions
146  $extensions = $this->hasOption( 'extensions' )
147  ? explode( ',', strtolower( $this->getOption( 'extensions' ) ) )
149 
150  # Search the path provided for candidates for import
151  $files = $this->findFiles( $dir, $extensions, $this->hasOption( 'search-recursively' ) );
152 
153  # Initialise the user for this operation
154  $user = $this->hasOption( 'user' )
155  ? User::newFromName( $this->getOption( 'user' ) )
156  : User::newSystemUser( 'Maintenance script', [ 'steal' => true ] );
157  if ( !$user instanceof User ) {
158  $user = User::newSystemUser( 'Maintenance script', [ 'steal' => true ] );
159  }
160  $wgUser = $user;
161 
162  # Get block check. If a value is given, this specified how often the check is performed
163  $checkUserBlock = (int)$this->getOption( 'check-userblock' );
164 
165  $from = $this->getOption( 'from' );
166  $sleep = (int)$this->getOption( 'sleep' );
167  $limit = (int)$this->getOption( 'limit' );
168  $timestamp = $this->getOption( 'timestamp', false );
169 
170  # Get the upload comment. Provide a default one in case there's no comment given.
171  $commentFile = $this->getOption( 'comment-file' );
172  if ( $commentFile !== null ) {
173  $comment = file_get_contents( $commentFile );
174  if ( $comment === false || $comment === null ) {
175  $this->fatalError( "failed to read comment file: {$commentFile}\n" );
176  }
177  } else {
178  $comment = $this->getOption( 'comment', 'Importing file' );
179  }
180  $commentExt = $this->getOption( 'comment-ext' );
181  $summary = $this->getOption( 'summary', '' );
182 
183  $license = $this->getOption( 'license', '' );
184 
185  $sourceWikiUrl = $this->getOption( 'source-wiki-url' );
186 
187  # Batch "upload" operation
188  $count = count( $files );
189  if ( $count > 0 ) {
190  foreach ( $files as $file ) {
191  if ( $sleep && ( $processed > 0 ) ) {
192  sleep( $sleep );
193  }
194 
195  $base = UtfNormal\Validator::cleanUp( wfBaseName( $file ) );
196 
197  # Validate a title
199  if ( !is_object( $title ) ) {
200  $this->output(
201  "{$base} could not be imported; a valid title cannot be produced\n" );
202  continue;
203  }
204 
205  if ( $from ) {
206  if ( $from == $title->getDBkey() ) {
207  $from = null;
208  } else {
209  $ignored++;
210  continue;
211  }
212  }
213 
214  if ( $checkUserBlock && ( ( $processed % $checkUserBlock ) == 0 ) ) {
215  $user->clearInstanceCache( 'name' ); // reload from DB!
216  // @TODO Use PermissionManager::isBlockedFrom() instead.
217  if ( $user->getBlock() ) {
218  $this->output( $user->getName() . " was blocked! Aborting.\n" );
219  break;
220  }
221  }
222 
223  # Check existence
224  $image = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
225  ->newFile( $title );
226  if ( $image->exists() ) {
227  if ( $this->hasOption( 'overwrite' ) ) {
228  $this->output( "{$base} exists, overwriting..." );
229  $svar = 'overwritten';
230  } else {
231  $this->output( "{$base} exists, skipping\n" );
232  $skipped++;
233  continue;
234  }
235  } else {
236  if ( $this->hasOption( 'skip-dupes' ) ) {
237  $repo = $image->getRepo();
238  # XXX: we end up calculating this again when actually uploading. that sucks.
239  $sha1 = FSFile::getSha1Base36FromPath( $file );
240 
241  $dupes = $repo->findBySha1( $sha1 );
242 
243  if ( $dupes ) {
244  $this->output(
245  "{$base} already exists as {$dupes[0]->getName()}, skipping\n" );
246  $skipped++;
247  continue;
248  }
249  }
250 
251  $this->output( "Importing {$base}..." );
252  $svar = 'added';
253  }
254 
255  if ( $sourceWikiUrl ) {
256  /* find comment text directly from source wiki, through MW's API */
257  $real_comment = $this->getFileCommentFromSourceWiki( $sourceWikiUrl, $base );
258  if ( $real_comment === false ) {
259  $commentText = $comment;
260  } else {
261  $commentText = $real_comment;
262  }
263 
264  /* find user directly from source wiki, through MW's API */
265  $real_user = $this->getFileUserFromSourceWiki( $sourceWikiUrl, $base );
266  if ( $real_user === false ) {
267  $wgUser = $user;
268  } else {
269  $wgUser = User::newFromName( $real_user );
270  if ( $wgUser === false ) {
271  # user does not exist in target wiki
272  $this->output(
273  "failed: user '$real_user' does not exist in target wiki." );
274  continue;
275  }
276  }
277  } else {
278  # Find comment text
279  $commentText = false;
280 
281  if ( $commentExt ) {
282  $f = $this->findAuxFile( $file, $commentExt );
283  if ( !$f ) {
284  $this->output( " No comment file with extension {$commentExt} found "
285  . "for {$file}, using default comment. " );
286  } else {
287  $commentText = file_get_contents( $f );
288  if ( !$commentText ) {
289  $this->output(
290  " Failed to load comment file {$f}, using default comment. " );
291  }
292  }
293  }
294 
295  if ( !$commentText ) {
296  $commentText = $comment;
297  }
298  }
299 
300  # Import the file
301  if ( $this->hasOption( 'dry' ) ) {
302  $this->output(
303  " publishing {$file} by '{$wgUser->getName()}', comment '$commentText'... "
304  );
305  } else {
306  $mwProps = new MWFileProps( MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() );
307  $props = $mwProps->getPropsFromPath( $file, true );
308  $flags = 0;
309  $publishOptions = [];
310  $handler = MediaHandler::getHandler( $props['mime'] );
311  if ( $handler ) {
312  $metadata = \Wikimedia\AtEase\AtEase::quietCall( 'unserialize', $props['metadata'] );
313 
314  $publishOptions['headers'] = $handler->getContentHeaders( $metadata );
315  } else {
316  $publishOptions['headers'] = [];
317  }
318  $archive = $image->publish( $file, $flags, $publishOptions );
319  if ( !$archive->isGood() ) {
320  $this->output( "failed. (" .
321  $archive->getWikiText( false, false, 'en' ) .
322  ")\n" );
323  $failed++;
324  continue;
325  }
326  }
327 
328  $commentText = SpecialUpload::getInitialPageText( $commentText, $license );
329  if ( !$this->hasOption( 'summary' ) ) {
330  $summary = $commentText;
331  }
332 
333  if ( $this->hasOption( 'dry' ) ) {
334  $this->output( "done.\n" );
335  } elseif ( $image->recordUpload2(
336  $archive->value,
337  $summary,
338  $commentText,
339  $props,
340  $timestamp
341  )->isOK() ) {
342  $this->output( "done.\n" );
343 
344  $doProtect = false;
345 
346  $protectLevel = $this->getOption( 'protect' );
347 
348  if ( $protectLevel && in_array( $protectLevel, $wgRestrictionLevels ) ) {
349  $doProtect = true;
350  }
351  if ( $this->hasOption( 'unprotect' ) ) {
352  $protectLevel = '';
353  $doProtect = true;
354  }
355 
356  if ( $doProtect ) {
357  # Protect the file
358  $this->output( "\nWaiting for replica DBs...\n" );
359  // Wait for replica DBs.
360  sleep( 2.0 ); # Why this sleep?
361  wfWaitForSlaves();
362 
363  $this->output( "\nSetting image restrictions ... " );
364 
365  $cascade = false;
366  $restrictions = [];
367  foreach ( $title->getRestrictionTypes() as $type ) {
368  $restrictions[$type] = $protectLevel;
369  }
370 
371  $page = WikiPage::factory( $title );
372  $status = $page->doUpdateRestrictions( $restrictions, [], $cascade, '', $user );
373  $this->output( ( $status->isOK() ? 'done' : 'failed' ) . "\n" );
374  }
375  } else {
376  $this->output( "failed. (at recordUpload stage)\n" );
377  $svar = 'failed';
378  }
379 
380  $$svar++;
381  $processed++;
382 
383  if ( $limit && $processed >= $limit ) {
384  break;
385  }
386  }
387 
388  # Print out some statistics
389  $this->output( "\n" );
390  foreach (
391  [
392  'count' => 'Found',
393  'limit' => 'Limit',
394  'ignored' => 'Ignored',
395  'added' => 'Added',
396  'skipped' => 'Skipped',
397  'overwritten' => 'Overwritten',
398  'failed' => 'Failed'
399  ] as $var => $desc
400  ) {
401  if ( $$var > 0 ) {
402  $this->output( "{$desc}: {$$var}\n" );
403  }
404  }
405  } else {
406  $this->output( "No suitable files could be found for import.\n" );
407  }
408  }
409 
418  private function findFiles( $dir, $exts, $recurse = false ) {
419  if ( is_dir( $dir ) ) {
420  $dhl = opendir( $dir );
421  if ( $dhl ) {
422  $files = [];
423  while ( ( $file = readdir( $dhl ) ) !== false ) {
424  if ( is_file( $dir . '/' . $file ) ) {
425  $ext = pathinfo( $file, PATHINFO_EXTENSION );
426  if ( array_search( strtolower( $ext ), $exts ) !== false ) {
427  $files[] = $dir . '/' . $file;
428  }
429  } elseif ( $recurse && is_dir( $dir . '/' . $file ) && $file !== '..' && $file !== '.' ) {
430  $files = array_merge( $files, $this->findFiles( $dir . '/' . $file, $exts, true ) );
431  }
432  }
433 
434  return $files;
435  } else {
436  return [];
437  }
438  } else {
439  return [];
440  }
441  }
442 
457  private function findAuxFile( $file, $auxExtension, $maxStrip = 1 ) {
458  if ( strpos( $auxExtension, '.' ) !== 0 ) {
459  $auxExtension = '.' . $auxExtension;
460  }
461 
462  $d = dirname( $file );
463  $n = basename( $file );
464 
465  while ( $maxStrip >= 0 ) {
466  $f = $d . '/' . $n . $auxExtension;
467 
468  if ( file_exists( $f ) ) {
469  return $f;
470  }
471 
472  $idx = strrpos( $n, '.' );
473  if ( !$idx ) {
474  break;
475  }
476 
477  $n = substr( $n, 0, $idx );
478  $maxStrip -= 1;
479  }
480 
481  return false;
482  }
483 
484  # @todo FIXME: Access the api in a saner way and performing just one query
485  # (preferably batching files too).
486  private function getFileCommentFromSourceWiki( $wiki_host, $file ) {
487  $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:'
488  . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=comment';
489  $body = Http::get( $url, [], __METHOD__ );
490  if ( preg_match( '#<ii comment="([^"]*)" />#', $body, $matches ) == 0 ) {
491  return false;
492  }
493 
494  return html_entity_decode( $matches[1] );
495  }
496 
497  private function getFileUserFromSourceWiki( $wiki_host, $file ) {
498  $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:'
499  . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=user';
500  $body = Http::get( $url, [], __METHOD__ );
501  if ( preg_match( '#<ii user="([^"]*)" />#', $body, $matches ) == 0 ) {
502  return false;
503  }
504 
505  return html_entity_decode( $matches[1] );
506  }
507 
508 }
509 
511 require_once RUN_MAINTENANCE_IF_MAIN;
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
wfBaseName( $path, $suffix='')
Return the final portion of a pathname.
getArg( $argId=0, $default=null)
Get an argument.
static getInitialPageText( $comment='', $license='', $copyStatus='', $source='', Config $config=null)
Get the initial image page text based on a comment and optional file status information.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
getOption( $name, $default=null)
Get an option, or return the default.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Definition: router.php:42
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
$wgRestrictionLevels
Rights which can be required for each protection level (via action=protect)
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 MediaWikiServices
Definition: injection.txt:23
hasOption( $name)
Checks to see if a particular option exists.
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
A helper class for throttling authentication attempts.
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:51
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:767
$maintClass
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 '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:1244
getFileCommentFromSourceWiki( $wiki_host, $file)
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
addDescription( $text)
Set the description text.
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:767
addArg( $arg, $description, $required=true)
Add some args that are needed.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
const NS_FILE
Definition: Defines.php:66
output( $out, $channel=null)
Throw some output to the user.
static getSha1Base36FromPath( $path)
Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case encoding, zero padded to 31 digits.
Definition: FSFile.php:218
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
Definition: distributors.txt:9
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:620
$wgFileExtensions
This is the list of preferred extensions for uploading files.
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
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
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:767
if(!is_readable( $file)) $ext
Definition: router.php:48
MimeMagic helper wrapper.
Definition: MWFileProps.php:28
$f
Definition: router.php:79
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
findFiles( $dir, $exts, $recurse=false)
Search a directory for files with one of a set of extensions.
findAuxFile( $file, $auxExtension, $maxStrip=1)
Find an auxilliary file with the given extension, matching the give base file path.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:535
getFileUserFromSourceWiki( $wiki_host, $file)
static getHandler( $type)
Get a MediaHandler for a given MIME type from the instance cache.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.
Definition: User.php:772
static get( $url, array $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( &#39;GET&#39; )
Definition: Http.php:64
$matches