50 parent::__construct(
'Import',
'import' );
69 $this->
namespace = $this->
getConfig()->get( 'ImportTargetNamespace' );
71 $this->
getOutput()->addModules(
'mediawiki.special.import' );
73 $this->importSources = $this->
getConfig()->get(
'ImportSources' );
74 Hooks::run(
'ImportSources', [ &$this->importSources ] );
77 if ( !
$user->isAllowedAny(
'import',
'importupload' ) ) {
81 # @todo Allow Title::getUserPermissionsErrors() to take an array
82 # @todo FIXME: Title::checkSpecialsAndNSPermissions() has a very weird expectation of what
83 # getUserPermissionsErrors() might actually be used for, hence the 'ns-specialprotected'
86 'import',
$user,
true,
87 [
'ns-specialprotected',
'badaccess-group0',
'badaccess-groups' ]
90 'importupload',
$user,
true,
91 [
'ns-specialprotected',
'badaccess-group0',
'badaccess-groups' ]
114 $this->sourceName =
$request->getVal(
"source" );
115 $this->assignKnownUsers =
$request->getCheck(
'assignKnownUsers' );
117 $this->logcomment =
$request->getText(
'log-comment' );
118 $this->pageLinkDepth = $this->
getConfig()->get(
'ExportMaxLinkDepth' ) == 0
120 :
$request->getIntOrNull(
'pagelink-depth' );
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' );
128 $this->mapping =
'default';
132 if ( !
$user->matchEditToken(
$request->getVal(
'editToken' ) ) ) {
133 $source = Status::newFatal(
'import-token-mismatch' );
134 } elseif ( $this->sourceName ===
'upload' ) {
136 $this->usernamePrefix = $this->fullInterwikiPrefix =
$request->getVal(
'usernamePrefix' );
137 if (
$user->isAllowed(
'importupload' ) ) {
142 } elseif ( $this->sourceName ===
'interwiki' ) {
143 if ( !
$user->isAllowed(
'import' ) ) {
146 $this->interwiki = $this->fullInterwikiPrefix =
$request->getVal(
'interwiki' );
148 $hasSubprojects = array_key_exists( $this->interwiki, $this->importSources );
149 if ( !$hasSubprojects && !in_array( $this->interwiki, $this->importSources ) ) {
150 $source = Status::newFatal(
"import-invalid-interwiki" );
152 if ( $hasSubprojects ) {
153 $this->subproject =
$request->getVal(
'subproject' );
154 $this->fullInterwikiPrefix .=
':' .
$request->getVal(
'subproject' );
156 if ( $hasSubprojects &&
157 !in_array( $this->subproject, $this->importSources[$this->interwiki] )
159 $source = Status::newFatal(
"import-invalid-interwiki" );
162 $this->frompage =
$request->getText(
"frompage" );
163 $this->includeTemplates =
$request->getCheck(
'interwikiTemplates' );
165 $this->fullInterwikiPrefix,
168 $this->includeTemplates,
169 $this->pageLinkDepth );
173 $source = Status::newFatal(
"importunknownsource" );
176 if ( (
string)$this->fullInterwikiPrefix ===
'' ) {
177 $source->fatal(
'importnoprefix' );
182 $out->addWikiText(
"<div class=\"error\">\n" .
183 $this->
msg(
'importfailed',
$source->getWikiText() )->parse() .
"\n</div>" );
186 if ( !is_null( $this->
namespace ) ) {
187 $importer->setTargetNamespace( $this->
namespace );
188 } elseif ( !is_null( $this->rootpage ) ) {
189 $statusRootPage = $importer->setTargetRootPage( $this->rootpage );
190 if ( !$statusRootPage->isGood() ) {
192 "<div class=\"error\">\n$1\n</div>",
194 'import-options-wrong',
195 $statusRootPage->getWikiText(),
196 count( $statusRootPage->getErrorsArray() )
203 $importer->setUsernamePrefix( $this->fullInterwikiPrefix, $this->assignKnownUsers );
205 $out->addWikiMsg(
"importstart" );
210 $this->fullInterwikiPrefix,
218 $importer->doImport();
219 }
catch ( Exception
$e ) {
225 # No source or XML parse error
227 "<div class=\"error\">\n$1\n</div>",
228 [
'importfailed', $exception->getMessage() ]
230 } elseif ( !
$result->isGood() ) {
233 "<div class=\"error\">\n$1\n</div>",
234 [
'importfailed',
$result->getWikiText() ]
238 $out->addWikiMsg(
'importsuccess' );
240 $out->addHTML(
'<hr />' );
245 $isSameSourceAsBefore = ( $this->sourceName ===
$sourceName );
246 $defaultNamespace = $this->
getConfig()->get(
'ImportTargetNamespace' );
250 <td class='mw-input'>" .
252 $this->
msg(
'import-mapping-default' )->
text(),
256 "mw-import-mapping-$sourceName-default",
257 ( $isSameSourceAsBefore ?
258 ( $this->mapping ===
'default' ) :
259 is_null( $defaultNamespace ) )
266 <td class='mw-input'>" .
268 $this->
msg(
'import-mapping-namespace' )->
text(),
272 "mw-import-mapping-$sourceName-namespace",
273 ( $isSameSourceAsBefore ?
274 ( $this->mapping ===
'namespace' ) :
275 !is_null( $defaultNamespace ) )
277 Html::namespaceSelector(
279 'selected' => ( $isSameSourceAsBefore ?
281 ( $defaultNamespace ||
'' ) ),
283 'name' =>
"namespace",
285 'id' =>
"mw-import-namespace-$sourceName",
286 'class' =>
'namespaceselector',
294 <td class='mw-input'>" .
296 $this->
msg(
'import-mapping-subpage' )->text(),
300 "mw-import-mapping-$sourceName-subpage",
301 ( $isSameSourceAsBefore ? ( $this->mapping ===
'subpage' ) :
'' )
303 Xml::input(
'rootpage', 50,
304 ( $isSameSourceAsBefore ? $this->rootpage :
'' ),
309 'id' =>
"mw-interwiki-rootpage-$sourceName",
318 $action = $this->
getPageTitle()->getLocalURL( [
'action' =>
'submit' ] );
321 $this->
addHelpLink(
'//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Import',
true );
323 if (
$user->isAllowed(
'importupload' ) ) {
326 Xml::fieldset( $this->
msg(
'import-upload' )->
text() ) .
330 'enctype' =>
'multipart/form-data',
333 'id' =>
'mw-import-upload-form'
336 $this->
msg(
'importtext' )->parseAsBlock() .
337 Html::hidden(
'action',
'submit' ) .
338 Html::hidden(
'source',
'upload' ) .
339 Xml::openElement(
'table', [
'id' =>
'mw-import-table-upload' ] ) .
341 <td class='mw-label'>" .
342 Xml::label( $this->
msg(
'import-upload-filename' )->
text(),
'xmlimport' ) .
344 <td class='mw-input'>" .
345 Html::input(
'xmlimport',
'',
'file', [
'id' =>
'xmlimport' ] ) .
' ' .
349 <td class='mw-label'>" .
350 Xml::label( $this->
msg(
'import-upload-username-prefix' )->
text(),
351 'mw-import-usernamePrefix' ) .
353 <td class='mw-input'>" .
354 Xml::input(
'usernamePrefix', 50,
355 $this->usernamePrefix,
356 [
'id' =>
'usernamePrefix',
'type' =>
'text' ] ) .
' ' .
361 <td class='mw-input'>" .
363 $this->
msg(
'import-assign-known-users' )->
text(),
366 $this->assignKnownUsers
371 <td class='mw-label'>" .
372 Xml::label( $this->
msg(
'import-comment' )->
text(),
'mw-import-comment' ) .
374 <td class='mw-input'>" .
375 Xml::input(
'log-comment', 50,
376 ( $this->sourceName ===
'upload' ? $this->logcomment :
'' ),
377 [
'id' =>
'mw-import-comment',
'type' =>
'text' ] ) .
' ' .
383 <td class='mw-submit'>" .
384 Xml::submitButton( $this->
msg(
'uploadbtn' )->
text() ) .
387 Xml::closeElement(
'table' ) .
388 Html::hidden(
'editToken',
$user->getEditToken() ) .
389 Xml::closeElement(
'form' ) .
390 Xml::closeElement(
'fieldset' )
393 if ( empty( $this->importSources ) ) {
394 $out->addWikiMsg(
'importnosources' );
398 if (
$user->isAllowed(
'import' ) && !empty( $this->importSources ) ) {
399 # Show input field for import depth only if $wgExportMaxLinkDepth > 0
401 if ( $this->
getConfig()->get(
'ExportMaxLinkDepth' ) > 0 ) {
403 <td class='mw-label'>" .
404 $this->
msg(
'export-pagelinks' )->parse() .
406 <td class='mw-input'>" .
407 Xml::input(
'pagelink-depth', 3, 0 ) .
414 Xml::fieldset( $this->
msg(
'importinterwiki' )->
text() ) .
420 'id' =>
'mw-import-interwiki-form'
423 $this->
msg(
'import-interwiki-text' )->parseAsBlock() .
424 Html::hidden(
'action',
'submit' ) .
425 Html::hidden(
'source',
'interwiki' ) .
426 Html::hidden(
'editToken',
$user->getEditToken() ) .
427 Xml::openElement(
'table', [
'id' =>
'mw-import-table-interwiki' ] ) .
429 <td class='mw-label'>" .
430 Xml::label( $this->msg(
'import-interwiki-sourcewiki' )->text(),
'interwiki' ) .
432 <td class='mw-input'>" .
435 [
'name' =>
'interwiki',
'id' =>
'interwiki' ]
439 $needSubprojectField =
false;
440 foreach ( $this->importSources
as $key =>
$value ) {
441 if ( is_int( $key ) ) {
443 } elseif (
$value !== $key ) {
444 $needSubprojectField =
true;
450 if ( is_array(
$value ) ) {
453 if ( $this->interwiki === $key ) {
456 $out->addHTML( Html::element(
'option',
$attribs, $key ) );
460 Xml::closeElement(
'select' )
463 if ( $needSubprojectField ) {
467 [
'name' =>
'subproject',
'id' =>
'subproject' ]
471 $subprojectsToAdd = [];
472 foreach ( $this->importSources
as $key =>
$value ) {
473 if ( is_array(
$value ) ) {
474 $subprojectsToAdd = array_merge( $subprojectsToAdd,
$value );
477 $subprojectsToAdd = array_unique( $subprojectsToAdd );
478 sort( $subprojectsToAdd );
484 Xml::closeElement(
'select' )
492 <td class='mw-label'>" .
493 Xml::label( $this->
msg(
'import-interwiki-sourcepage' )->
text(),
'frompage' ) .
495 <td class='mw-input'>" .
496 Xml::input(
'frompage', 50, $this->frompage, [
'id' =>
'frompage' ] ) .
502 <td class='mw-input'>" .
504 $this->
msg(
'import-interwiki-history' )->
text(),
514 <td class='mw-input'>" .
516 $this->
msg(
'import-interwiki-templates' )->
text(),
517 'interwikiTemplates',
518 'interwikiTemplates',
519 $this->includeTemplates
525 <td class='mw-input'>" .
527 $this->
msg(
'import-assign-known-users' )->
text(),
529 'interwikiAssignKnownUsers',
530 $this->assignKnownUsers
536 <td class='mw-label'>" .
537 Xml::label( $this->
msg(
'import-comment' )->
text(),
'mw-interwiki-comment' ) .
539 <td class='mw-input'>" .
540 Xml::input(
'log-comment', 50,
541 ( $this->sourceName ===
'interwiki' ? $this->logcomment :
'' ),
542 [
'id' =>
'mw-interwiki-comment',
'type' =>
'text' ] ) .
' ' .
549 <td class='mw-submit'>" .
551 $this->
msg(
'import-interwiki-submit' )->
text(),
556 Xml::closeElement(
'table' ) .
557 Xml::closeElement(
'form' ) .
558 Xml::closeElement(
'fieldset' )
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
wfMergeErrorArrays(... $args)
Merge arrays in the style of getUserPermissionsErrors, with duplicate removal e.g.
static newFromInterwiki( $interwiki, $page, $history=false, $templates=false, $pageLinkDepth=0)
static newFromUpload( $fieldname="xmlimport")
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Show an error when a user tries to do something they do not have the necessary permissions for.
MediaWiki page data importer.
doesWrites()
Indicates whether this special page may perform database writes.
getMappingFormPart( $sourceName)
doImport()
Do the actual import.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
getPageTitle( $subpage=false)
Get a self-referential title object.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
XML file reader for the page data importer.
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
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
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. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. '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 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name '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 since 1.16! 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:Array with elements of the form "language:title" in the order that they will be output. & $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 since 1.28! 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
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
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
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
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
returning false will NOT prevent logging $e
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