MediaWiki  1.28.0
SpecialImport.php
Go to the documentation of this file.
1 <?php
32 class SpecialImport extends SpecialPage {
33  private $sourceName = false;
34  private $interwiki = false;
35  private $subproject;
37  private $mapping = 'default';
38  private $namespace;
39  private $rootpage = '';
40  private $frompage = '';
41  private $logcomment = false;
42  private $history = true;
43  private $includeTemplates = false;
44  private $pageLinkDepth;
45  private $importSources;
46 
50  public function __construct() {
51  parent::__construct( 'Import', 'import' );
52  }
53 
54  public function doesWrites() {
55  return true;
56  }
57 
64  function execute( $par ) {
66 
67  $this->setHeaders();
68  $this->outputHeader();
69 
70  $this->namespace = $this->getConfig()->get( 'ImportTargetNamespace' );
71 
72  $this->getOutput()->addModules( 'mediawiki.special.import' );
73 
74  $this->importSources = $this->getConfig()->get( 'ImportSources' );
75  Hooks::run( 'ImportSources', [ &$this->importSources ] );
76 
77  $user = $this->getUser();
78  if ( !$user->isAllowedAny( 'import', 'importupload' ) ) {
79  throw new PermissionsError( 'import' );
80  }
81 
82  # @todo Allow Title::getUserPermissionsErrors() to take an array
83  # @todo FIXME: Title::checkSpecialsAndNSPermissions() has a very wierd expectation of what
84  # getUserPermissionsErrors() might actually be used for, hence the 'ns-specialprotected'
85  $errors = wfMergeErrorArrays(
86  $this->getPageTitle()->getUserPermissionsErrors(
87  'import', $user, true,
88  [ 'ns-specialprotected', 'badaccess-group0', 'badaccess-groups' ]
89  ),
90  $this->getPageTitle()->getUserPermissionsErrors(
91  'importupload', $user, true,
92  [ 'ns-specialprotected', 'badaccess-group0', 'badaccess-groups' ]
93  )
94  );
95 
96  if ( $errors ) {
97  throw new PermissionsError( 'import', $errors );
98  }
99 
100  $this->checkReadOnly();
101 
102  $request = $this->getRequest();
103  if ( $request->wasPosted() && $request->getVal( 'action' ) == 'submit' ) {
104  $this->doImport();
105  }
106  $this->showForm();
107  }
108 
112  private function doImport() {
113  $isUpload = false;
114  $request = $this->getRequest();
115  $this->sourceName = $request->getVal( "source" );
116 
117  $this->logcomment = $request->getText( 'log-comment' );
118  $this->pageLinkDepth = $this->getConfig()->get( 'ExportMaxLinkDepth' ) == 0
119  ? 0
120  : $request->getIntOrNull( 'pagelink-depth' );
121 
122  $this->mapping = $request->getVal( 'mapping' );
123  if ( $this->mapping === 'namespace' ) {
124  $this->namespace = $request->getIntOrNull( 'namespace' );
125  } elseif ( $this->mapping === 'subpage' ) {
126  $this->rootpage = $request->getText( 'rootpage' );
127  } else {
128  $this->mapping = 'default';
129  }
130 
131  $user = $this->getUser();
132  if ( !$user->matchEditToken( $request->getVal( 'editToken' ) ) ) {
133  $source = Status::newFatal( 'import-token-mismatch' );
134  } elseif ( $this->sourceName === 'upload' ) {
135  $isUpload = true;
136  if ( $user->isAllowed( 'importupload' ) ) {
138  } else {
139  throw new PermissionsError( 'importupload' );
140  }
141  } elseif ( $this->sourceName === 'interwiki' ) {
142  if ( !$user->isAllowed( 'import' ) ) {
143  throw new PermissionsError( 'import' );
144  }
145  $this->interwiki = $this->fullInterwikiPrefix = $request->getVal( 'interwiki' );
146  // does this interwiki have subprojects?
147  $hasSubprojects = array_key_exists( $this->interwiki, $this->importSources );
148  if ( !$hasSubprojects && !in_array( $this->interwiki, $this->importSources ) ) {
149  $source = Status::newFatal( "import-invalid-interwiki" );
150  } else {
151  if ( $hasSubprojects ) {
152  $this->subproject = $request->getVal( 'subproject' );
153  $this->fullInterwikiPrefix .= ':' . $request->getVal( 'subproject' );
154  }
155  if ( $hasSubprojects &&
156  !in_array( $this->subproject, $this->importSources[$this->interwiki] )
157  ) {
158  $source = Status::newFatal( "import-invalid-interwiki" );
159  } else {
160  $this->history = $request->getCheck( 'interwikiHistory' );
161  $this->frompage = $request->getText( "frompage" );
162  $this->includeTemplates = $request->getCheck( 'interwikiTemplates' );
164  $this->fullInterwikiPrefix,
165  $this->frompage,
166  $this->history,
167  $this->includeTemplates,
168  $this->pageLinkDepth );
169  }
170  }
171  } else {
172  $source = Status::newFatal( "importunknownsource" );
173  }
174 
175  $out = $this->getOutput();
176  if ( !$source->isGood() ) {
177  $out->wrapWikiMsg(
178  "<p class=\"error\">\n$1\n</p>",
179  [ 'importfailed', $source->getWikiText() ]
180  );
181  } else {
182  $importer = new WikiImporter( $source->value, $this->getConfig() );
183  if ( !is_null( $this->namespace ) ) {
184  $importer->setTargetNamespace( $this->namespace );
185  } elseif ( !is_null( $this->rootpage ) ) {
186  $statusRootPage = $importer->setTargetRootPage( $this->rootpage );
187  if ( !$statusRootPage->isGood() ) {
188  $out->wrapWikiMsg(
189  "<p class=\"error\">\n$1\n</p>",
190  [
191  'import-options-wrong',
192  $statusRootPage->getWikiText(),
193  count( $statusRootPage->getErrorsArray() )
194  ]
195  );
196 
197  return;
198  }
199  }
200 
201  $out->addWikiMsg( "importstart" );
202 
203  $reporter = new ImportReporter(
204  $importer,
205  $isUpload,
206  $this->fullInterwikiPrefix,
207  $this->logcomment
208  );
209  $reporter->setContext( $this->getContext() );
210  $exception = false;
211 
212  $reporter->open();
213  try {
214  $importer->doImport();
215  } catch ( Exception $e ) {
216  $exception = $e;
217  }
218  $result = $reporter->close();
219 
220  if ( $exception ) {
221  # No source or XML parse error
222  $out->wrapWikiMsg(
223  "<p class=\"error\">\n$1\n</p>",
224  [ 'importfailed', $exception->getMessage() ]
225  );
226  } elseif ( !$result->isGood() ) {
227  # Zero revisions
228  $out->wrapWikiMsg(
229  "<p class=\"error\">\n$1\n</p>",
230  [ 'importfailed', $result->getWikiText() ]
231  );
232  } else {
233  # Success!
234  $out->addWikiMsg( 'importsuccess' );
235  }
236  $out->addHTML( '<hr />' );
237  }
238  }
239 
240  private function getMappingFormPart( $sourceName ) {
241  $isSameSourceAsBefore = ( $this->sourceName === $sourceName );
242  $defaultNamespace = $this->getConfig()->get( 'ImportTargetNamespace' );
243  return "<tr>
244  <td>
245  </td>
246  <td class='mw-input'>" .
248  $this->msg( 'import-mapping-default' )->text(),
249  'mapping',
250  'default',
251  // mw-import-mapping-interwiki-default, mw-import-mapping-upload-default
252  "mw-import-mapping-$sourceName-default",
253  ( $isSameSourceAsBefore ?
254  ( $this->mapping === 'default' ) :
255  is_null( $defaultNamespace ) )
256  ) .
257  "</td>
258  </tr>
259  <tr>
260  <td>
261  </td>
262  <td class='mw-input'>" .
264  $this->msg( 'import-mapping-namespace' )->text(),
265  'mapping',
266  'namespace',
267  // mw-import-mapping-interwiki-namespace, mw-import-mapping-upload-namespace
268  "mw-import-mapping-$sourceName-namespace",
269  ( $isSameSourceAsBefore ?
270  ( $this->mapping === 'namespace' ) :
271  !is_null( $defaultNamespace ) )
272  ) . ' ' .
274  [
275  'selected' => ( $isSameSourceAsBefore ?
276  $this->namespace :
277  ( $defaultNamespace || '' ) ),
278  ], [
279  'name' => "namespace",
280  // mw-import-namespace-interwiki, mw-import-namespace-upload
281  'id' => "mw-import-namespace-$sourceName",
282  'class' => 'namespaceselector',
283  ]
284  ) .
285  "</td>
286  </tr>
287  <tr>
288  <td>
289  </td>
290  <td class='mw-input'>" .
292  $this->msg( 'import-mapping-subpage' )->text(),
293  'mapping',
294  'subpage',
295  // mw-import-mapping-interwiki-subpage, mw-import-mapping-upload-subpage
296  "mw-import-mapping-$sourceName-subpage",
297  ( $isSameSourceAsBefore ? ( $this->mapping === 'subpage' ) : '' )
298  ) . ' ' .
299  Xml::input( 'rootpage', 50,
300  ( $isSameSourceAsBefore ? $this->rootpage : '' ),
301  [
302  // Should be "mw-import-rootpage-...", but we keep this inaccurate
303  // ID for legacy reasons
304  // mw-interwiki-rootpage-interwiki, mw-interwiki-rootpage-upload
305  'id' => "mw-interwiki-rootpage-$sourceName",
306  'type' => 'text'
307  ]
308  ) . ' ' .
309  "</td>
310  </tr>";
311  }
312 
313  private function showForm() {
314  $action = $this->getPageTitle()->getLocalURL( [ 'action' => 'submit' ] );
315  $user = $this->getUser();
316  $out = $this->getOutput();
317  $this->addHelpLink( '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Import', true );
318 
319  if ( $user->isAllowed( 'importupload' ) ) {
320  $mappingSelection = $this->getMappingFormPart( 'upload' );
321  $out->addHTML(
322  Xml::fieldset( $this->msg( 'import-upload' )->text() ) .
324  'form',
325  [
326  'enctype' => 'multipart/form-data',
327  'method' => 'post',
328  'action' => $action,
329  'id' => 'mw-import-upload-form'
330  ]
331  ) .
332  $this->msg( 'importtext' )->parseAsBlock() .
333  Html::hidden( 'action', 'submit' ) .
334  Html::hidden( 'source', 'upload' ) .
335  Xml::openElement( 'table', [ 'id' => 'mw-import-table-upload' ] ) .
336  "<tr>
337  <td class='mw-label'>" .
338  Xml::label( $this->msg( 'import-upload-filename' )->text(), 'xmlimport' ) .
339  "</td>
340  <td class='mw-input'>" .
341  Html::input( 'xmlimport', '', 'file', [ 'id' => 'xmlimport' ] ) . ' ' .
342  "</td>
343  </tr>
344  <tr>
345  <td class='mw-label'>" .
346  Xml::label( $this->msg( 'import-comment' )->text(), 'mw-import-comment' ) .
347  "</td>
348  <td class='mw-input'>" .
349  Xml::input( 'log-comment', 50,
350  ( $this->sourceName === 'upload' ? $this->logcomment : '' ),
351  [ 'id' => 'mw-import-comment', 'type' => 'text' ] ) . ' ' .
352  "</td>
353  </tr>
354  $mappingSelection
355  <tr>
356  <td></td>
357  <td class='mw-submit'>" .
358  Xml::submitButton( $this->msg( 'uploadbtn' )->text() ) .
359  "</td>
360  </tr>" .
361  Xml::closeElement( 'table' ) .
362  Html::hidden( 'editToken', $user->getEditToken() ) .
363  Xml::closeElement( 'form' ) .
364  Xml::closeElement( 'fieldset' )
365  );
366  } else {
367  if ( empty( $this->importSources ) ) {
368  $out->addWikiMsg( 'importnosources' );
369  }
370  }
371 
372  if ( $user->isAllowed( 'import' ) && !empty( $this->importSources ) ) {
373  # Show input field for import depth only if $wgExportMaxLinkDepth > 0
374  $importDepth = '';
375  if ( $this->getConfig()->get( 'ExportMaxLinkDepth' ) > 0 ) {
376  $importDepth = "<tr>
377  <td class='mw-label'>" .
378  $this->msg( 'export-pagelinks' )->parse() .
379  "</td>
380  <td class='mw-input'>" .
381  Xml::input( 'pagelink-depth', 3, 0 ) .
382  "</td>
383  </tr>";
384  }
385  $mappingSelection = $this->getMappingFormPart( 'interwiki' );
386 
387  $out->addHTML(
388  Xml::fieldset( $this->msg( 'importinterwiki' )->text() ) .
390  'form',
391  [
392  'method' => 'post',
393  'action' => $action,
394  'id' => 'mw-import-interwiki-form'
395  ]
396  ) .
397  $this->msg( 'import-interwiki-text' )->parseAsBlock() .
398  Html::hidden( 'action', 'submit' ) .
399  Html::hidden( 'source', 'interwiki' ) .
400  Html::hidden( 'editToken', $user->getEditToken() ) .
401  Xml::openElement( 'table', [ 'id' => 'mw-import-table-interwiki' ] ) .
402  "<tr>
403  <td class='mw-label'>" .
404  Xml::label( $this->msg( 'import-interwiki-sourcewiki' )->text(), 'interwiki' ) .
405  "</td>
406  <td class='mw-input'>" .
408  'select',
409  [ 'name' => 'interwiki', 'id' => 'interwiki' ]
410  )
411  );
412 
413  $needSubprojectField = false;
414  foreach ( $this->importSources as $key => $value ) {
415  if ( is_int( $key ) ) {
416  $key = $value;
417  } elseif ( $value !== $key ) {
418  $needSubprojectField = true;
419  }
420 
421  $attribs = [
422  'value' => $key,
423  ];
424  if ( is_array( $value ) ) {
425  $attribs['data-subprojects'] = implode( ' ', $value );
426  }
427  if ( $this->interwiki === $key ) {
428  $attribs['selected'] = 'selected';
429  }
430  $out->addHTML( Html::element( 'option', $attribs, $key ) );
431  }
432 
433  $out->addHTML(
434  Xml::closeElement( 'select' )
435  );
436 
437  if ( $needSubprojectField ) {
438  $out->addHTML(
440  'select',
441  [ 'name' => 'subproject', 'id' => 'subproject' ]
442  )
443  );
444 
445  $subprojectsToAdd = [];
446  foreach ( $this->importSources as $key => $value ) {
447  if ( is_array( $value ) ) {
448  $subprojectsToAdd = array_merge( $subprojectsToAdd, $value );
449  }
450  }
451  $subprojectsToAdd = array_unique( $subprojectsToAdd );
452  sort( $subprojectsToAdd );
453  foreach ( $subprojectsToAdd as $subproject ) {
454  $out->addHTML( Xml::option( $subproject, $subproject, $this->subproject === $subproject ) );
455  }
456 
457  $out->addHTML(
458  Xml::closeElement( 'select' )
459  );
460  }
461 
462  $out->addHTML(
463  "</td>
464  </tr>
465  <tr>
466  <td class='mw-label'>" .
467  Xml::label( $this->msg( 'import-interwiki-sourcepage' )->text(), 'frompage' ) .
468  "</td>
469  <td class='mw-input'>" .
470  Xml::input( 'frompage', 50, $this->frompage, [ 'id' => 'frompage' ] ) .
471  "</td>
472  </tr>
473  <tr>
474  <td>
475  </td>
476  <td class='mw-input'>" .
478  $this->msg( 'import-interwiki-history' )->text(),
479  'interwikiHistory',
480  'interwikiHistory',
481  $this->history
482  ) .
483  "</td>
484  </tr>
485  <tr>
486  <td>
487  </td>
488  <td class='mw-input'>" .
490  $this->msg( 'import-interwiki-templates' )->text(),
491  'interwikiTemplates',
492  'interwikiTemplates',
493  $this->includeTemplates
494  ) .
495  "</td>
496  </tr>
497  $importDepth
498  <tr>
499  <td class='mw-label'>" .
500  Xml::label( $this->msg( 'import-comment' )->text(), 'mw-interwiki-comment' ) .
501  "</td>
502  <td class='mw-input'>" .
503  Xml::input( 'log-comment', 50,
504  ( $this->sourceName === 'interwiki' ? $this->logcomment : '' ),
505  [ 'id' => 'mw-interwiki-comment', 'type' => 'text' ] ) . ' ' .
506  "</td>
507  </tr>
508  $mappingSelection
509  <tr>
510  <td>
511  </td>
512  <td class='mw-submit'>" .
514  $this->msg( 'import-interwiki-submit' )->text(),
516  ) .
517  "</td>
518  </tr>" .
519  Xml::closeElement( 'table' ) .
520  Xml::closeElement( 'form' ) .
521  Xml::closeElement( 'fieldset' )
522  );
523  }
524  }
525 
526  protected function getGroupName() {
527  return 'pagetools';
528  }
529 }
530 
536  private $reason = false;
537  private $mOriginalLogCallback = null;
539  private $mLogItemCount = 0;
540 
547  function __construct( $importer, $upload, $interwiki, $reason = false ) {
548  $this->mOriginalPageOutCallback =
549  $importer->setPageOutCallback( [ $this, 'reportPage' ] );
550  $this->mOriginalLogCallback =
551  $importer->setLogItemCallback( [ $this, 'reportLogItem' ] );
552  $importer->setNoticeCallback( [ $this, 'reportNotice' ] );
553  $this->mPageCount = 0;
554  $this->mIsUpload = $upload;
555  $this->mInterwiki = $interwiki;
556  $this->reason = $reason;
557  }
558 
559  function open() {
560  $this->getOutput()->addHTML( "<ul>\n" );
561  }
562 
563  function reportNotice( $msg, array $params ) {
564  $this->getOutput()->addHTML(
565  Html::element( 'li', [], $this->msg( $msg, $params )->text() )
566  );
567  }
568 
569  function reportLogItem( /* ... */ ) {
570  $this->mLogItemCount++;
571  if ( is_callable( $this->mOriginalLogCallback ) ) {
572  call_user_func_array( $this->mOriginalLogCallback, func_get_args() );
573  }
574  }
575 
584  public function reportPage( $title, $foreignTitle, $revisionCount,
585  $successCount, $pageInfo ) {
586  $args = func_get_args();
587  call_user_func_array( $this->mOriginalPageOutCallback, $args );
588 
589  if ( $title === null ) {
590  # Invalid or non-importable title; a notice is already displayed
591  return;
592  }
593 
594  $this->mPageCount++;
595 
596  if ( $successCount > 0 ) {
597  // <bdi> prevents jumbling of the versions count
598  // in RTL wikis in case the page title is LTR
599  $this->getOutput()->addHTML(
600  "<li>" . Linker::linkKnown( $title ) . " " .
601  "<bdi>" .
602  $this->msg( 'import-revision-count' )->numParams( $successCount )->escaped() .
603  "</bdi>" .
604  "</li>\n"
605  );
606 
607  $logParams = [ '4:number:count' => $successCount ];
608  if ( $this->mIsUpload ) {
609  $detail = $this->msg( 'import-logentry-upload-detail' )->numParams(
610  $successCount )->inContentLanguage()->text();
611  $action = 'upload';
612  } else {
613  $pageTitle = $foreignTitle->getFullText();
614  $fullInterwikiPrefix = $this->mInterwiki;
615  Hooks::run( 'ImportLogInterwikiLink', [ &$fullInterwikiPrefix, &$pageTitle ] );
616 
617  $interwikiTitleStr = $fullInterwikiPrefix . ':' . $pageTitle;
618  $interwiki = '[[:' . $interwikiTitleStr . ']]';
619  $detail = $this->msg( 'import-logentry-interwiki-detail' )->numParams(
620  $successCount )->params( $interwiki )->inContentLanguage()->text();
621  $action = 'interwiki';
622  $logParams['5:title-link:interwiki'] = $interwikiTitleStr;
623  }
624  if ( $this->reason ) {
625  $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text()
626  . $this->reason;
627  }
628 
629  $logEntry = new ManualLogEntry( 'import', $action );
630  $logEntry->setTarget( $title );
631  $logEntry->setComment( $this->reason );
632  $logEntry->setPerformer( $this->getUser() );
633  $logEntry->setParameters( $logParams );
634  $logid = $logEntry->insert();
635  $logEntry->publish( $logid );
636 
637  $comment = $detail; // quick
638  $dbw = wfGetDB( DB_MASTER );
639  $latest = $title->getLatestRevID();
640  $nullRevision = Revision::newNullRevision(
641  $dbw,
642  $title->getArticleID(),
643  $comment,
644  true,
645  $this->getUser()
646  );
647 
648  if ( !is_null( $nullRevision ) ) {
649  $nullRevision->insertOn( $dbw );
651  # Update page record
652  $page->updateRevisionOn( $dbw, $nullRevision );
653  Hooks::run(
654  'NewRevisionFromEditComplete',
655  [ $page, $nullRevision, $latest, $this->getUser() ]
656  );
657  }
658  } else {
659  $this->getOutput()->addHTML( "<li>" . Linker::linkKnown( $title ) . " " .
660  $this->msg( 'import-nonewrevisions' )->escaped() . "</li>\n" );
661  }
662  }
663 
664  function close() {
665  $out = $this->getOutput();
666  if ( $this->mLogItemCount > 0 ) {
667  $msg = $this->msg( 'imported-log-entries' )->numParams( $this->mLogItemCount )->parse();
668  $out->addHTML( Xml::tags( 'li', null, $msg ) );
669  } elseif ( $this->mPageCount == 0 && $this->mLogItemCount == 0 ) {
670  $out->addHTML( "</ul>\n" );
671 
672  return Status::newFatal( 'importnopages' );
673  }
674  $out->addHTML( "</ul>\n" );
675 
676  return Status::newGood( $this->mPageCount );
677  }
678 }
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:115
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
doImport()
Do the actual import.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub 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 $out
Definition: hooks.txt:802
the array() calling protocol came about after MediaWiki 1.4rc1.
getContext()
Gets the context this SpecialPage is executed in.
execute($par)
Execute.
MediaWiki page data importer.
XML file reader for the page data importer.
static radioLabel($label, $name, $value, $id, $checked=false, $attribs=[])
Convenience function to build an HTML radio button with a label.
Definition: Xml.php:445
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
Definition: hooks.txt:2102
static newFatal($message)
Factory function for fatal errors.
Definition: StatusValue.php:63
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
__construct($importer, $upload, $interwiki, $reason=false)
static hidden($name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:758
reportNotice($msg, array $params)
$comment
$source
$value
static input($name, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field.
Definition: Xml.php:275
msg()
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
const DB_MASTER
Definition: defines.php:23
static tooltipAndAccesskeyAttribs($name, array $msgParams=[])
Returns the attributes for the tooltip and access key.
Definition: Linker.php:2182
static submitButton($value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:460
addHelpLink($to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
setTargetNamespace($namespace)
Set a target namespace to override the defaults.
static label($label, $id, $attribs=[])
Convenience function to build an HTML form label.
Definition: Xml.php:359
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1934
outputHeader($summaryMessageKey= '')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
if($line===false) $args
Definition: cdb.php:64
static fieldset($legend=false, $content=false, $attribs=[])
Shortcut for creating fieldsets.
Definition: Xml.php:578
static closeElement($element)
Shortcut to close an XML element.
Definition: Xml.php:118
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Parent class for all special pages.
Definition: SpecialPage.php:36
wfMergeErrorArrays()
Merge arrays in the style of getUserPermissionsErrors, with duplicate removal e.g.
getMappingFormPart($sourceName)
static option($text, $value=null, $selected=false, $attribs=[])
Convenience function to build an HTML drop-down list item.
Definition: Xml.php:485
static newNullRevision($dbw, $pageId, $summary, $minor, $user=null)
Create a new null-revision for insertion into a page's history.
Definition: Revision.php:1678
static openElement($element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
$params
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1936
static newFromInterwiki($interwiki, $page, $history=false, $templates=false, $pageLinkDepth=0)
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:953
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:255
__construct()
Constructor.
static newGood($value=null)
Factory function for good results.
Definition: StatusValue.php:76
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
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
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
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
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc next in line in page history
Definition: hooks.txt:1721
static tags($element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:131
reportPage($title, $foreignTitle, $revisionCount, $successCount, $pageInfo)
Class for creating log entries manually, to inject them into the database.
Definition: LogEntry.php:394
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2573
static input($name, $value= '', $type= 'text', array $attribs=[])
Convenience function to produce an "" element.
Definition: Html.php:675
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
getUser()
Shortcut to get the User executing this instance.
getConfig()
Shortcut to get main config object.
Show an error when a user tries to do something they do not have the necessary permissions for...
Reporting callback.
static checkLabel($label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:420
static newFromUpload($fieldname="xmlimport")
getRequest()
Get the WebRequest being used for this instance.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:229
getUser()
Get the User object.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2491
getPageTitle($subpage=false)
Get a self-referential title object.
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition: Html.php:846
getOutput()
Get the OutputPage object.