MediaWiki REL1_29
SpecialUpload.php
Go to the documentation of this file.
1<?php
27
40 public function __construct( $request = null ) {
41 parent::__construct( 'Upload', 'upload' );
42 }
43
44 public function doesWrites() {
45 return true;
46 }
47
51 public $mRequest;
53
55 public $mUpload;
56
60
65 public $mComment;
66 public $mLicense;
67
74
78
81
84 public $mTokenOk;
85
87 public $mUploadSuccessful = false;
88
92
96 protected function loadRequest() {
97 $this->mRequest = $request = $this->getRequest();
98 $this->mSourceType = $request->getVal( 'wpSourceType', 'file' );
99 $this->mUpload = UploadBase::createFromRequest( $request );
100 $this->mUploadClicked = $request->wasPosted()
101 && ( $request->getCheck( 'wpUpload' )
102 || $request->getCheck( 'wpUploadIgnoreWarning' ) );
103
104 // Guess the desired name from the filename if not provided
105 $this->mDesiredDestName = $request->getText( 'wpDestFile' );
106 if ( !$this->mDesiredDestName && $request->getFileName( 'wpUploadFile' ) !== null ) {
107 $this->mDesiredDestName = $request->getFileName( 'wpUploadFile' );
108 }
109 $this->mLicense = $request->getText( 'wpLicense' );
110
111 $this->mDestWarningAck = $request->getText( 'wpDestFileWarningAck' );
112 $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' )
113 || $request->getCheck( 'wpUploadIgnoreWarning' );
114 $this->mWatchthis = $request->getBool( 'wpWatchthis' ) && $this->getUser()->isLoggedIn();
115 $this->mCopyrightStatus = $request->getText( 'wpUploadCopyStatus' );
116 $this->mCopyrightSource = $request->getText( 'wpUploadSource' );
117
118 $this->mForReUpload = $request->getBool( 'wpForReUpload' ); // updating a file
119
120 $commentDefault = '';
121 $commentMsg = wfMessage( 'upload-default-description' )->inContentLanguage();
122 if ( !$this->mForReUpload && !$commentMsg->isDisabled() ) {
123 $commentDefault = $commentMsg->plain();
124 }
125 $this->mComment = $request->getText( 'wpUploadDescription', $commentDefault );
126
127 $this->mCancelUpload = $request->getCheck( 'wpCancelUpload' )
128 || $request->getCheck( 'wpReUpload' ); // b/w compat
129
130 // If it was posted check for the token (no remote POST'ing with user credentials)
131 $token = $request->getVal( 'wpEditToken' );
132 $this->mTokenOk = $this->getUser()->matchEditToken( $token );
133
134 $this->uploadFormTextTop = '';
135 $this->uploadFormTextAfterSummary = '';
136 }
137
146 public function userCanExecute( User $user ) {
147 return UploadBase::isEnabled() && parent::userCanExecute( $user );
148 }
149
161 public function execute( $par ) {
163
164 $this->setHeaders();
165 $this->outputHeader();
166
167 # Check uploading enabled
168 if ( !UploadBase::isEnabled() ) {
169 throw new ErrorPageError( 'uploaddisabled', 'uploaddisabledtext' );
170 }
171
172 $this->addHelpLink( 'Help:Managing files' );
173
174 # Check permissions
175 $user = $this->getUser();
176 $permissionRequired = UploadBase::isAllowed( $user );
177 if ( $permissionRequired !== true ) {
178 throw new PermissionsError( $permissionRequired );
179 }
180
181 # Check blocks
182 if ( $user->isBlocked() ) {
183 throw new UserBlockedError( $user->getBlock() );
184 }
185
186 // Global blocks
187 if ( $user->isBlockedGlobally() ) {
188 throw new UserBlockedError( $user->getGlobalBlock() );
189 }
190
191 # Check whether we actually want to allow changing stuff
192 $this->checkReadOnly();
193
194 $this->loadRequest();
195
196 # Unsave the temporary file in case this was a cancelled upload
197 if ( $this->mCancelUpload ) {
198 if ( !$this->unsaveUploadedFile() ) {
199 # Something went wrong, so unsaveUploadedFile showed a warning
200 return;
201 }
202 }
203
204 # Process upload or show a form
205 if (
206 $this->mTokenOk && !$this->mCancelUpload &&
207 ( $this->mUpload && $this->mUploadClicked )
208 ) {
209 $this->processUpload();
210 } else {
211 # Backwards compatibility hook
212 // Avoid PHP 7.1 warning of passing $this by reference
213 $upload = $this;
214 if ( !Hooks::run( 'UploadForm:initial', [ &$upload ] ) ) {
215 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form\n" );
216
217 return;
218 }
219 $this->showUploadForm( $this->getUploadForm() );
220 }
221
222 # Cleanup
223 if ( $this->mUpload ) {
224 $this->mUpload->cleanupTempFile();
225 }
226 }
227
233 protected function showUploadForm( $form ) {
234 # Add links if file was previously deleted
235 if ( $this->mDesiredDestName ) {
236 $this->showViewDeletedLinks();
237 }
238
239 if ( $form instanceof HTMLForm ) {
240 $form->show();
241 } else {
242 $this->getOutput()->addHTML( $form );
243 }
244 }
245
254 protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) {
255 # Initialize form
256 $context = new DerivativeContext( $this->getContext() );
257 $context->setTitle( $this->getPageTitle() ); // Remove subpage
258 $form = new UploadForm( [
259 'watch' => $this->getWatchCheck(),
260 'forreupload' => $this->mForReUpload,
261 'sessionkey' => $sessionKey,
262 'hideignorewarning' => $hideIgnoreWarning,
263 'destwarningack' => (bool)$this->mDestWarningAck,
264
265 'description' => $this->mComment,
266 'texttop' => $this->uploadFormTextTop,
267 'textaftersummary' => $this->uploadFormTextAfterSummary,
268 'destfile' => $this->mDesiredDestName,
269 ], $context, $this->getLinkRenderer() );
270
271 # Check the token, but only if necessary
272 if (
273 !$this->mTokenOk && !$this->mCancelUpload &&
274 ( $this->mUpload && $this->mUploadClicked )
275 ) {
276 $form->addPreText( $this->msg( 'session_fail_preview' )->parse() );
277 }
278
279 # Give a notice if the user is uploading a file that has been deleted or moved
280 # Note that this is independent from the message 'filewasdeleted'
281 $desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
282 $delNotice = ''; // empty by default
283 if ( $desiredTitleObj instanceof Title && !$desiredTitleObj->exists() ) {
285
286 LogEventsList::showLogExtract( $delNotice, [ 'delete', 'move' ],
287 $desiredTitleObj,
288 '', [ 'lim' => 10,
289 'conds' => [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ],
290 'showIfEmpty' => false,
291 'msgKey' => [ 'upload-recreate-warning' ] ]
292 );
293 }
294 $form->addPreText( $delNotice );
295
296 # Add text to form
297 $form->addPreText( '<div id="uploadtext">' .
298 $this->msg( 'uploadtext', [ $this->mDesiredDestName ] )->parseAsBlock() .
299 '</div>' );
300 # Add upload error message
301 $form->addPreText( $message );
302
303 # Add footer to form
304 $uploadFooter = $this->msg( 'uploadfooter' );
305 if ( !$uploadFooter->isDisabled() ) {
306 $form->addPostText( '<div id="mw-upload-footer-message">'
307 . $uploadFooter->parseAsBlock() . "</div>\n" );
308 }
309
310 return $form;
311 }
312
316 protected function showViewDeletedLinks() {
317 $title = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
318 $user = $this->getUser();
319 // Show a subtitle link to deleted revisions (to sysops et al only)
320 if ( $title instanceof Title ) {
321 $count = $title->isDeleted();
322 if ( $count > 0 && $user->isAllowed( 'deletedhistory' ) ) {
323 $restorelink = $this->getLinkRenderer()->makeKnownLink(
324 SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ),
325 $this->msg( 'restorelink' )->numParams( $count )->text()
326 );
327 $link = $this->msg( $user->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted' )
328 ->rawParams( $restorelink )->parseAsBlock();
329 $this->getOutput()->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
330 }
331 }
332 }
333
345 protected function showRecoverableUploadError( $message ) {
346 $stashStatus = $this->mUpload->tryStashFile( $this->getUser() );
347 if ( $stashStatus->isGood() ) {
348 $sessionKey = $stashStatus->getValue()->getFileKey();
349 } else {
350 $sessionKey = null;
351 // TODO Add a warning message about the failure to stash here?
352 }
353 $message = '<h2>' . $this->msg( 'uploaderror' )->escaped() . "</h2>\n" .
354 '<div class="error">' . $message . "</div>\n";
355
356 $form = $this->getUploadForm( $message, $sessionKey );
357 $form->setSubmitText( $this->msg( 'upload-tryagain' )->escaped() );
358 $this->showUploadForm( $form );
359 }
360
369 protected function showUploadWarning( $warnings ) {
370 # If there are no warnings, or warnings we can ignore, return early.
371 # mDestWarningAck is set when some javascript has shown the warning
372 # to the user. mForReUpload is set when the user clicks the "upload a
373 # new version" link.
374 if ( !$warnings || ( count( $warnings ) == 1
375 && isset( $warnings['exists'] )
376 && ( $this->mDestWarningAck || $this->mForReUpload ) )
377 ) {
378 return false;
379 }
380
381 $stashStatus = $this->mUpload->tryStashFile( $this->getUser() );
382 if ( $stashStatus->isGood() ) {
383 $sessionKey = $stashStatus->getValue()->getFileKey();
384 } else {
385 $sessionKey = null;
386 // TODO Add a warning message about the failure to stash here?
387 }
388
389 // Add styles for the warning, reused from the live preview
390 $this->getOutput()->addModuleStyles( 'mediawiki.special.upload.styles' );
391
393 $warningHtml = '<h2>' . $this->msg( 'uploadwarning' )->escaped() . "</h2>\n"
394 . '<div class="mw-destfile-warning"><ul>';
395 foreach ( $warnings as $warning => $args ) {
396 if ( $warning == 'badfilename' ) {
397 $this->mDesiredDestName = Title::makeTitle( NS_FILE, $args )->getText();
398 }
399 if ( $warning == 'exists' ) {
400 $msg = "\t<li>" . self::getExistsWarning( $args ) . "</li>\n";
401 } elseif ( $warning == 'no-change' ) {
402 $file = $args;
403 $filename = $file->getTitle()->getPrefixedText();
404 $msg = "\t<li>" . wfMessage( 'fileexists-no-change', $filename )->parse() . "</li>\n";
405 } elseif ( $warning == 'duplicate-version' ) {
406 $file = $args[0];
407 $count = count( $args );
408 $filename = $file->getTitle()->getPrefixedText();
409 $message = wfMessage( 'fileexists-duplicate-version' )
410 ->params( $filename )
411 ->numParams( $count );
412 $msg = "\t<li>" . $message->parse() . "</li>\n";
413 } elseif ( $warning == 'was-deleted' ) {
414 # If the file existed before and was deleted, warn the user of this
415 $ltitle = SpecialPage::getTitleFor( 'Log' );
416 $llink = $linkRenderer->makeKnownLink(
417 $ltitle,
418 wfMessage( 'deletionlog' )->text(),
419 [],
420 [
421 'type' => 'delete',
422 'page' => Title::makeTitle( NS_FILE, $args )->getPrefixedText(),
423 ]
424 );
425 $msg = "\t<li>" . wfMessage( 'filewasdeleted' )->rawParams( $llink )->parse() . "</li>\n";
426 } elseif ( $warning == 'duplicate' ) {
427 $msg = $this->getDupeWarning( $args );
428 } elseif ( $warning == 'duplicate-archive' ) {
429 if ( $args === '' ) {
430 $msg = "\t<li>" . $this->msg( 'file-deleted-duplicate-notitle' )->parse()
431 . "</li>\n";
432 } else {
433 $msg = "\t<li>" . $this->msg( 'file-deleted-duplicate',
434 Title::makeTitle( NS_FILE, $args )->getPrefixedText() )->parse()
435 . "</li>\n";
436 }
437 } else {
438 if ( $args === true ) {
439 $args = [];
440 } elseif ( !is_array( $args ) ) {
441 $args = [ $args ];
442 }
443 $msg = "\t<li>" . $this->msg( $warning, $args )->parse() . "</li>\n";
444 }
445 $warningHtml .= $msg;
446 }
447 $warningHtml .= "</ul></div>\n";
448 $warningHtml .= $this->msg( 'uploadwarning-text' )->parseAsBlock();
449
450 $form = $this->getUploadForm( $warningHtml, $sessionKey, /* $hideIgnoreWarning */ true );
451 $form->setSubmitText( $this->msg( 'upload-tryagain' )->text() );
452 $form->addButton( [
453 'name' => 'wpUploadIgnoreWarning',
454 'value' => $this->msg( 'ignorewarning' )->text()
455 ] );
456 $form->addButton( [
457 'name' => 'wpCancelUpload',
458 'value' => $this->msg( 'reuploaddesc' )->text()
459 ] );
460
461 $this->showUploadForm( $form );
462
463 # Indicate that we showed a form
464 return true;
465 }
466
472 protected function showUploadError( $message ) {
473 $message = '<h2>' . $this->msg( 'uploadwarning' )->escaped() . "</h2>\n" .
474 '<div class="error">' . $message . "</div>\n";
475 $this->showUploadForm( $this->getUploadForm( $message ) );
476 }
477
482 protected function processUpload() {
483 // Fetch the file if required
484 $status = $this->mUpload->fetchFile();
485 if ( !$status->isOK() ) {
486 $this->showUploadError( $this->getOutput()->parse( $status->getWikiText() ) );
487
488 return;
489 }
490 // Avoid PHP 7.1 warning of passing $this by reference
491 $upload = $this;
492 if ( !Hooks::run( 'UploadForm:BeforeProcessing', [ &$upload ] ) ) {
493 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
494 // This code path is deprecated. If you want to break upload processing
495 // do so by hooking into the appropriate hooks in UploadBase::verifyUpload
496 // and UploadBase::verifyFile.
497 // If you use this hook to break uploading, the user will be returned
498 // an empty form with no error message whatsoever.
499 return;
500 }
501
502 // Upload verification
503 $details = $this->mUpload->verifyUpload();
504 if ( $details['status'] != UploadBase::OK ) {
505 $this->processVerificationError( $details );
506
507 return;
508 }
509
510 // Verify permissions for this title
511 $permErrors = $this->mUpload->verifyTitlePermissions( $this->getUser() );
512 if ( $permErrors !== true ) {
513 $code = array_shift( $permErrors[0] );
514 $this->showRecoverableUploadError( $this->msg( $code, $permErrors[0] )->parse() );
515
516 return;
517 }
518
519 $this->mLocalFile = $this->mUpload->getLocalFile();
520
521 // Check warnings if necessary
522 if ( !$this->mIgnoreWarning ) {
523 $warnings = $this->mUpload->checkWarnings();
524 if ( $this->showUploadWarning( $warnings ) ) {
525 return;
526 }
527 }
528
529 // This is as late as we can throttle, after expected issues have been handled
530 if ( UploadBase::isThrottled( $this->getUser() ) ) {
532 $this->msg( 'actionthrottledtext' )->escaped()
533 );
534 return;
535 }
536
537 // Get the page text if this is not a reupload
538 if ( !$this->mForReUpload ) {
539 $pageText = self::getInitialPageText( $this->mComment, $this->mLicense,
540 $this->mCopyrightStatus, $this->mCopyrightSource, $this->getConfig() );
541 } else {
542 $pageText = false;
543 }
544
545 $changeTags = $this->getRequest()->getVal( 'wpChangeTags' );
546 if ( is_null( $changeTags ) || $changeTags === '' ) {
547 $changeTags = [];
548 } else {
549 $changeTags = array_filter( array_map( 'trim', explode( ',', $changeTags ) ) );
550 }
551
552 if ( $changeTags ) {
554 $changeTags, $this->getUser() );
555 if ( !$changeTagsStatus->isOK() ) {
556 $this->showUploadError( $this->getOutput()->parse( $changeTagsStatus->getWikiText() ) );
557
558 return;
559 }
560 }
561
562 $status = $this->mUpload->performUpload(
563 $this->mComment,
564 $pageText,
565 $this->mWatchthis,
566 $this->getUser(),
567 $changeTags
568 );
569
570 if ( !$status->isGood() ) {
571 $this->showRecoverableUploadError( $this->getOutput()->parse( $status->getWikiText() ) );
572
573 return;
574 }
575
576 // Success, redirect to description page
577 $this->mUploadSuccessful = true;
578 // Avoid PHP 7.1 warning of passing $this by reference
579 $upload = $this;
580 Hooks::run( 'SpecialUploadComplete', [ &$upload ] );
581 $this->getOutput()->redirect( $this->mLocalFile->getTitle()->getFullURL() );
582 }
583
593 public static function getInitialPageText( $comment = '', $license = '',
594 $copyStatus = '', $source = '', Config $config = null
595 ) {
596 if ( $config === null ) {
597 wfDebug( __METHOD__ . ' called without a Config instance passed to it' );
598 $config = MediaWikiServices::getInstance()->getMainConfig();
599 }
600
601 $msg = [];
602 $forceUIMsgAsContentMsg = (array)$config->get( 'ForceUIMsgAsContentMsg' );
603 /* These messages are transcluded into the actual text of the description page.
604 * Thus, forcing them as content messages makes the upload to produce an int: template
605 * instead of hardcoding it there in the uploader language.
606 */
607 foreach ( [ 'license-header', 'filedesc', 'filestatus', 'filesource' ] as $msgName ) {
608 if ( in_array( $msgName, $forceUIMsgAsContentMsg ) ) {
609 $msg[$msgName] = "{{int:$msgName}}";
610 } else {
611 $msg[$msgName] = wfMessage( $msgName )->inContentLanguage()->text();
612 }
613 }
614
615 if ( $config->get( 'UseCopyrightUpload' ) ) {
616 $licensetxt = '';
617 if ( $license != '' ) {
618 $licensetxt = '== ' . $msg['license-header'] . " ==\n" . '{{' . $license . '}}' . "\n";
619 }
620 $pageText = '== ' . $msg['filedesc'] . " ==\n" . $comment . "\n" .
621 '== ' . $msg['filestatus'] . " ==\n" . $copyStatus . "\n" .
622 "$licensetxt" .
623 '== ' . $msg['filesource'] . " ==\n" . $source;
624 } else {
625 if ( $license != '' ) {
626 $filedesc = $comment == '' ? '' : '== ' . $msg['filedesc'] . " ==\n" . $comment . "\n";
627 $pageText = $filedesc .
628 '== ' . $msg['license-header'] . " ==\n" . '{{' . $license . '}}' . "\n";
629 } else {
630 $pageText = $comment;
631 }
632 }
633
634 return $pageText;
635 }
636
649 protected function getWatchCheck() {
650 if ( $this->getUser()->getOption( 'watchdefault' ) ) {
651 // Watch all edits!
652 return true;
653 }
654
655 $desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
656 if ( $desiredTitleObj instanceof Title && $this->getUser()->isWatched( $desiredTitleObj ) ) {
657 // Already watched, don't change that
658 return true;
659 }
660
661 $local = wfLocalFile( $this->mDesiredDestName );
662 if ( $local && $local->exists() ) {
663 // We're uploading a new version of an existing file.
664 // No creation, so don't watch it if we're not already.
665 return false;
666 } else {
667 // New page should get watched if that's our option.
668 return $this->getUser()->getOption( 'watchcreations' ) ||
669 $this->getUser()->getOption( 'watchuploads' );
670 }
671 }
672
679 protected function processVerificationError( $details ) {
680 switch ( $details['status'] ) {
681
684 $this->showRecoverableUploadError( $this->msg( 'minlength1' )->escaped() );
685 break;
687 $this->showRecoverableUploadError( $this->msg( 'illegalfilename',
688 $details['filtered'] )->parse() );
689 break;
691 $this->showRecoverableUploadError( $this->msg( 'filename-toolong' )->escaped() );
692 break;
694 $this->showRecoverableUploadError( $this->msg( 'filetype-missing' )->parse() );
695 break;
697 $this->showRecoverableUploadError( $this->msg( 'windows-nonascii-filename' )->parse() );
698 break;
699
702 $this->showUploadError( $this->msg( 'emptyfile' )->escaped() );
703 break;
705 $this->showUploadError( $this->msg( 'largefileserver' )->escaped() );
706 break;
708 $msg = $this->msg( 'filetype-banned-type' );
709 if ( isset( $details['blacklistedExt'] ) ) {
710 $msg->params( $this->getLanguage()->commaList( $details['blacklistedExt'] ) );
711 } else {
712 $msg->params( $details['finalExt'] );
713 }
714 $extensions = array_unique( $this->getConfig()->get( 'FileExtensions' ) );
715 $msg->params( $this->getLanguage()->commaList( $extensions ),
716 count( $extensions ) );
717
718 // Add PLURAL support for the first parameter. This results
719 // in a bit unlogical parameter sequence, but does not break
720 // old translations
721 if ( isset( $details['blacklistedExt'] ) ) {
722 $msg->params( count( $details['blacklistedExt'] ) );
723 } else {
724 $msg->params( 1 );
725 }
726
727 $this->showUploadError( $msg->parse() );
728 break;
730 unset( $details['status'] );
731 $code = array_shift( $details['details'] );
732 $this->showUploadError( $this->msg( $code, $details['details'] )->parse() );
733 break;
735 if ( is_array( $details['error'] ) ) { # allow hooks to return error details in an array
736 $args = $details['error'];
737 $error = array_shift( $args );
738 } else {
739 $error = $details['error'];
740 $args = null;
741 }
742
743 $this->showUploadError( $this->msg( $error, $args )->parse() );
744 break;
745 default:
746 throw new MWException( __METHOD__ . ": Unknown value `{$details['status']}`" );
747 }
748 }
749
755 protected function unsaveUploadedFile() {
756 if ( !( $this->mUpload instanceof UploadFromStash ) ) {
757 return true;
758 }
759 $success = $this->mUpload->unsaveUploadedFile();
760 if ( !$success ) {
761 $this->getOutput()->showFileDeleteError( $this->mUpload->getTempPath() );
762
763 return false;
764 } else {
765 return true;
766 }
767 }
768
769 /*** Functions for formatting warnings ***/
770
778 public static function getExistsWarning( $exists ) {
779 if ( !$exists ) {
780 return '';
781 }
782
783 $file = $exists['file'];
784 $filename = $file->getTitle()->getPrefixedText();
785 $warnMsg = null;
786
787 if ( $exists['warning'] == 'exists' ) {
788 // Exact match
789 $warnMsg = wfMessage( 'fileexists', $filename );
790 } elseif ( $exists['warning'] == 'page-exists' ) {
791 // Page exists but file does not
792 $warnMsg = wfMessage( 'filepageexists', $filename );
793 } elseif ( $exists['warning'] == 'exists-normalized' ) {
794 $warnMsg = wfMessage( 'fileexists-extension', $filename,
795 $exists['normalizedFile']->getTitle()->getPrefixedText() );
796 } elseif ( $exists['warning'] == 'thumb' ) {
797 // Swapped argument order compared with other messages for backwards compatibility
798 $warnMsg = wfMessage( 'fileexists-thumbnail-yes',
799 $exists['thumbFile']->getTitle()->getPrefixedText(), $filename );
800 } elseif ( $exists['warning'] == 'thumb-name' ) {
801 // Image w/o '180px-' does not exists, but we do not like these filenames
802 $name = $file->getName();
803 $badPart = substr( $name, 0, strpos( $name, '-' ) + 1 );
804 $warnMsg = wfMessage( 'file-thumbnail-no', $badPart );
805 } elseif ( $exists['warning'] == 'bad-prefix' ) {
806 $warnMsg = wfMessage( 'filename-bad-prefix', $exists['prefix'] );
807 }
808
809 return $warnMsg ? $warnMsg->title( $file->getTitle() )->parse() : '';
810 }
811
817 public function getDupeWarning( $dupes ) {
818 if ( !$dupes ) {
819 return '';
820 }
821
822 $gallery = ImageGalleryBase::factory( false, $this->getContext() );
823 $gallery->setShowBytes( false );
824 foreach ( $dupes as $file ) {
825 $gallery->add( $file->getTitle() );
826 }
827
828 return '<li>' .
829 $this->msg( 'file-exists-duplicate' )->numParams( count( $dupes ) )->parse() .
830 $gallery->toHTML() . "</li>\n";
831 }
832
833 protected function getGroupName() {
834 return 'media';
835 }
836
844 public static function rotationEnabled() {
845 $bitmapHandler = new BitmapHandler();
846 return $bitmapHandler->autoRotateEnabled();
847 }
848}
849
853class UploadForm extends HTMLForm {
854 protected $mWatch;
855 protected $mForReUpload;
856 protected $mSessionKey;
859 protected $mDestFile;
860
861 protected $mComment;
862 protected $mTextTop;
864
865 protected $mSourceIds;
866
867 protected $mMaxFileSize = [];
868
869 protected $mMaxUploadSize = [];
870
871 public function __construct( array $options = [], IContextSource $context = null,
873 ) {
874 if ( $context instanceof IContextSource ) {
875 $this->setContext( $context );
876 }
877
878 if ( !$linkRenderer ) {
879 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
880 }
881
882 $this->mWatch = !empty( $options['watch'] );
883 $this->mForReUpload = !empty( $options['forreupload'] );
884 $this->mSessionKey = isset( $options['sessionkey'] ) ? $options['sessionkey'] : '';
885 $this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] );
886 $this->mDestWarningAck = !empty( $options['destwarningack'] );
887 $this->mDestFile = isset( $options['destfile'] ) ? $options['destfile'] : '';
888
889 $this->mComment = isset( $options['description'] ) ?
890 $options['description'] : '';
891
892 $this->mTextTop = isset( $options['texttop'] )
893 ? $options['texttop'] : '';
894
895 $this->mTextAfterSummary = isset( $options['textaftersummary'] )
896 ? $options['textaftersummary'] : '';
897
898 $sourceDescriptor = $this->getSourceSection();
899 $descriptor = $sourceDescriptor
900 + $this->getDescriptionSection()
901 + $this->getOptionsSection();
902
903 Hooks::run( 'UploadFormInitDescriptor', [ &$descriptor ] );
904 parent::__construct( $descriptor, $context, 'upload' );
905
906 # Add a link to edit MediaWiki:Licenses
907 if ( $this->getUser()->isAllowed( 'editinterface' ) ) {
908 $this->getOutput()->addModuleStyles( 'mediawiki.special.upload.styles' );
909 $licensesLink = $linkRenderer->makeKnownLink(
910 $this->msg( 'licenses' )->inContentLanguage()->getTitle(),
911 $this->msg( 'licenses-edit' )->text(),
912 [],
913 [ 'action' => 'edit' ]
914 );
915 $editLicenses = '<p class="mw-upload-editlicenses">' . $licensesLink . '</p>';
916 $this->addFooterText( $editLicenses, 'description' );
917 }
918
919 # Set some form properties
920 $this->setSubmitText( $this->msg( 'uploadbtn' )->text() );
921 $this->setSubmitName( 'wpUpload' );
922 # Used message keys: 'accesskey-upload', 'tooltip-upload'
923 $this->setSubmitTooltip( 'upload' );
924 $this->setId( 'mw-upload-form' );
925
926 # Build a list of IDs for javascript insertion
927 $this->mSourceIds = [];
928 foreach ( $sourceDescriptor as $field ) {
929 if ( !empty( $field['id'] ) ) {
930 $this->mSourceIds[] = $field['id'];
931 }
932 }
933 }
934
941 protected function getSourceSection() {
942 if ( $this->mSessionKey ) {
943 return [
944 'SessionKey' => [
945 'type' => 'hidden',
946 'default' => $this->mSessionKey,
947 ],
948 'SourceType' => [
949 'type' => 'hidden',
950 'default' => 'Stash',
951 ],
952 ];
953 }
954
955 $canUploadByUrl = UploadFromUrl::isEnabled()
956 && ( UploadFromUrl::isAllowed( $this->getUser() ) === true )
957 && $this->getConfig()->get( 'CopyUploadsFromSpecialUpload' );
958 $radio = $canUploadByUrl;
959 $selectedSourceType = strtolower( $this->getRequest()->getText( 'wpSourceType', 'File' ) );
960
961 $descriptor = [];
962 if ( $this->mTextTop ) {
963 $descriptor['UploadFormTextTop'] = [
964 'type' => 'info',
965 'section' => 'source',
966 'default' => $this->mTextTop,
967 'raw' => true,
968 ];
969 }
970
971 $this->mMaxUploadSize['file'] = min(
974 );
975
976 $help = $this->msg( 'upload-maxfilesize',
977 $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['file'] )
978 )->parse();
979
980 // If the user can also upload by URL, there are 2 different file size limits.
981 // This extra message helps stress which limit corresponds to what.
982 if ( $canUploadByUrl ) {
983 $help .= $this->msg( 'word-separator' )->escaped();
984 $help .= $this->msg( 'upload_source_file' )->parse();
985 }
986
987 $descriptor['UploadFile'] = [
988 'class' => 'UploadSourceField',
989 'section' => 'source',
990 'type' => 'file',
991 'id' => 'wpUploadFile',
992 'radio-id' => 'wpSourceTypeFile',
993 'label-message' => 'sourcefilename',
994 'upload-type' => 'File',
995 'radio' => &$radio,
996 'help' => $help,
997 'checked' => $selectedSourceType == 'file',
998 ];
999
1000 if ( $canUploadByUrl ) {
1001 $this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize( 'url' );
1002 $descriptor['UploadFileURL'] = [
1003 'class' => 'UploadSourceField',
1004 'section' => 'source',
1005 'id' => 'wpUploadFileURL',
1006 'radio-id' => 'wpSourceTypeurl',
1007 'label-message' => 'sourceurl',
1008 'upload-type' => 'url',
1009 'radio' => &$radio,
1010 'help' => $this->msg( 'upload-maxfilesize',
1011 $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['url'] )
1012 )->parse() .
1013 $this->msg( 'word-separator' )->escaped() .
1014 $this->msg( 'upload_source_url' )->parse(),
1015 'checked' => $selectedSourceType == 'url',
1016 ];
1017 }
1018 Hooks::run( 'UploadFormSourceDescriptors', [ &$descriptor, &$radio, $selectedSourceType ] );
1019
1020 $descriptor['Extensions'] = [
1021 'type' => 'info',
1022 'section' => 'source',
1023 'default' => $this->getExtensionsMessage(),
1024 'raw' => true,
1025 ];
1026
1027 return $descriptor;
1028 }
1029
1035 protected function getExtensionsMessage() {
1036 # Print a list of allowed file extensions, if so configured. We ignore
1037 # MIME type here, it's incomprehensible to most people and too long.
1038 $config = $this->getConfig();
1039
1040 if ( $config->get( 'CheckFileExtensions' ) ) {
1041 $fileExtensions = array_unique( $config->get( 'FileExtensions' ) );
1042 if ( $config->get( 'StrictFileExtensions' ) ) {
1043 # Everything not permitted is banned
1044 $extensionsList =
1045 '<div id="mw-upload-permitted">' .
1046 $this->msg( 'upload-permitted' )
1047 ->params( $this->getLanguage()->commaList( $fileExtensions ) )
1048 ->numParams( count( $fileExtensions ) )
1049 ->parseAsBlock() .
1050 "</div>\n";
1051 } else {
1052 # We have to list both preferred and prohibited
1053 $fileBlacklist = array_unique( $config->get( 'FileBlacklist' ) );
1054 $extensionsList =
1055 '<div id="mw-upload-preferred">' .
1056 $this->msg( 'upload-preferred' )
1057 ->params( $this->getLanguage()->commaList( $fileExtensions ) )
1058 ->numParams( count( $fileExtensions ) )
1059 ->parseAsBlock() .
1060 "</div>\n" .
1061 '<div id="mw-upload-prohibited">' .
1062 $this->msg( 'upload-prohibited' )
1063 ->params( $this->getLanguage()->commaList( $fileBlacklist ) )
1064 ->numParams( count( $fileBlacklist ) )
1065 ->parseAsBlock() .
1066 "</div>\n";
1067 }
1068 } else {
1069 # Everything is permitted.
1070 $extensionsList = '';
1071 }
1072
1073 return $extensionsList;
1074 }
1075
1082 protected function getDescriptionSection() {
1083 $config = $this->getConfig();
1084 if ( $this->mSessionKey ) {
1085 $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $this->getUser() );
1086 try {
1087 $file = $stash->getFile( $this->mSessionKey );
1088 } catch ( Exception $e ) {
1089 $file = null;
1090 }
1091 if ( $file ) {
1093
1094 $mto = $file->transform( [ 'width' => 120 ] );
1095 if ( $mto ) {
1096 $this->addHeaderText(
1097 '<div class="thumb t' . $wgContLang->alignEnd() . '">' .
1098 Html::element( 'img', [
1099 'src' => $mto->getUrl(),
1100 'class' => 'thumbimage',
1101 ] ) . '</div>', 'description' );
1102 }
1103 }
1104 }
1105
1106 $descriptor = [
1107 'DestFile' => [
1108 'type' => 'text',
1109 'section' => 'description',
1110 'id' => 'wpDestFile',
1111 'label-message' => 'destfilename',
1112 'size' => 60,
1113 'default' => $this->mDestFile,
1114 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
1115 'nodata' => strval( $this->mDestFile ) !== '',
1116 ],
1117 'UploadDescription' => [
1118 'type' => 'textarea',
1119 'section' => 'description',
1120 'id' => 'wpUploadDescription',
1121 'label-message' => $this->mForReUpload
1122 ? 'filereuploadsummary'
1123 : 'fileuploadsummary',
1124 'default' => $this->mComment,
1125 'cols' => 80,
1126 'rows' => 8,
1127 ]
1128 ];
1129 if ( $this->mTextAfterSummary ) {
1130 $descriptor['UploadFormTextAfterSummary'] = [
1131 'type' => 'info',
1132 'section' => 'description',
1133 'default' => $this->mTextAfterSummary,
1134 'raw' => true,
1135 ];
1136 }
1137
1138 $descriptor += [
1139 'EditTools' => [
1140 'type' => 'edittools',
1141 'section' => 'description',
1142 'message' => 'edittools-upload',
1143 ]
1144 ];
1145
1146 if ( $this->mForReUpload ) {
1147 $descriptor['DestFile']['readonly'] = true;
1148 } else {
1149 $descriptor['License'] = [
1150 'type' => 'select',
1151 'class' => 'Licenses',
1152 'section' => 'description',
1153 'id' => 'wpLicense',
1154 'label-message' => 'license',
1155 ];
1156 }
1157
1158 if ( $config->get( 'UseCopyrightUpload' ) ) {
1159 $descriptor['UploadCopyStatus'] = [
1160 'type' => 'text',
1161 'section' => 'description',
1162 'id' => 'wpUploadCopyStatus',
1163 'label-message' => 'filestatus',
1164 ];
1165 $descriptor['UploadSource'] = [
1166 'type' => 'text',
1167 'section' => 'description',
1168 'id' => 'wpUploadSource',
1169 'label-message' => 'filesource',
1170 ];
1171 }
1172
1173 return $descriptor;
1174 }
1175
1182 protected function getOptionsSection() {
1183 $user = $this->getUser();
1184 if ( $user->isLoggedIn() ) {
1185 $descriptor = [
1186 'Watchthis' => [
1187 'type' => 'check',
1188 'id' => 'wpWatchthis',
1189 'label-message' => 'watchthisupload',
1190 'section' => 'options',
1191 'default' => $this->mWatch,
1192 ]
1193 ];
1194 }
1195 if ( !$this->mHideIgnoreWarning ) {
1196 $descriptor['IgnoreWarning'] = [
1197 'type' => 'check',
1198 'id' => 'wpIgnoreWarning',
1199 'label-message' => 'ignorewarnings',
1200 'section' => 'options',
1201 ];
1202 }
1203
1204 $descriptor['DestFileWarningAck'] = [
1205 'type' => 'hidden',
1206 'id' => 'wpDestFileWarningAck',
1207 'default' => $this->mDestWarningAck ? '1' : '',
1208 ];
1209
1210 if ( $this->mForReUpload ) {
1211 $descriptor['ForReUpload'] = [
1212 'type' => 'hidden',
1213 'id' => 'wpForReUpload',
1214 'default' => '1',
1215 ];
1216 }
1217
1218 return $descriptor;
1219 }
1220
1224 public function show() {
1225 $this->addUploadJS();
1226 parent::show();
1227 }
1228
1232 protected function addUploadJS() {
1233 $config = $this->getConfig();
1234
1235 $useAjaxDestCheck = $config->get( 'UseAjax' ) && $config->get( 'AjaxUploadDestCheck' );
1236 $useAjaxLicensePreview = $config->get( 'UseAjax' ) &&
1237 $config->get( 'AjaxLicensePreview' ) && $config->get( 'EnableAPI' );
1238 $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize();
1239
1240 $scriptVars = [
1241 'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
1242 'wgAjaxLicensePreview' => $useAjaxLicensePreview,
1243 'wgUploadAutoFill' => !$this->mForReUpload &&
1244 // If we received mDestFile from the request, don't autofill
1245 // the wpDestFile textbox
1246 $this->mDestFile === '',
1247 'wgUploadSourceIds' => $this->mSourceIds,
1248 'wgCheckFileExtensions' => $config->get( 'CheckFileExtensions' ),
1249 'wgStrictFileExtensions' => $config->get( 'StrictFileExtensions' ),
1250 'wgFileExtensions' => array_values( array_unique( $config->get( 'FileExtensions' ) ) ),
1251 'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ),
1252 'wgMaxUploadSize' => $this->mMaxUploadSize,
1253 'wgFileCanRotate' => SpecialUpload::rotationEnabled(),
1254 ];
1255
1256 $out = $this->getOutput();
1257 $out->addJsConfigVars( $scriptVars );
1258
1259 $out->addModules( [
1260 'mediawiki.action.edit', // For <charinsert> support
1261 'mediawiki.special.upload', // Extras for thumbnail and license preview.
1262 ] );
1263 }
1264
1270 function trySubmit() {
1271 return false;
1272 }
1273}
1274
1279
1284 function getLabelHtml( $cellAttributes = [] ) {
1285 $id = $this->mParams['id'];
1286 $label = Html::rawElement( 'label', [ 'for' => $id ], $this->mLabel );
1287
1288 if ( !empty( $this->mParams['radio'] ) ) {
1289 if ( isset( $this->mParams['radio-id'] ) ) {
1290 $radioId = $this->mParams['radio-id'];
1291 } else {
1292 // Old way. For the benefit of extensions that do not define
1293 // the 'radio-id' key.
1294 $radioId = 'wpSourceType' . $this->mParams['upload-type'];
1295 }
1296
1297 $attribs = [
1298 'name' => 'wpSourceType',
1299 'type' => 'radio',
1300 'id' => $radioId,
1301 'value' => $this->mParams['upload-type'],
1302 ];
1303
1304 if ( !empty( $this->mParams['checked'] ) ) {
1305 $attribs['checked'] = 'checked';
1306 }
1307
1308 $label .= Html::element( 'input', $attribs );
1309 }
1310
1311 return Html::rawElement( 'td', [ 'class' => 'mw-label' ] + $cellAttributes, $label );
1312 }
1313
1317 function getSize() {
1318 return isset( $this->mParams['size'] )
1319 ? $this->mParams['size']
1320 : 60;
1321 }
1322}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfLocalFile( $title)
Get an object referring to a locally registered file.
if( $line===false) $args
Definition cdb.php:63
Generic handler for bitmap images.
Definition Bitmap.php:29
static canAddTagsAccompanyingChange(array $tags, User $user=null)
Is it OK to allow the user to apply all the specified tags at the same time as they edit/make the cha...
getUser()
Get the User object.
getRequest()
Get the WebRequest object.
getConfig()
Get the Config object.
msg()
Get a Message object with context set Parameters are the same as wfMessage()
getOutput()
Get the OutputPage object.
IContextSource $context
getLanguage()
Get the Language object.
getContext()
Get the base IContextSource object.
setContext(IContextSource $context)
Set the IContextSource object.
An IContextSource implementation which will inherit context from another source but allow individual ...
An error page which can definitely be safely rendered using the OutputPage.
WebRequest clone which takes values from a provided array.
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition HTMLForm.php:128
setSubmitName( $name)
setId( $id)
addFooterText( $msg, $section=null)
Add footer text, inside the form.
Definition HTMLForm.php:819
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition HTMLForm.php:764
getTitle()
Get the title.
setSubmitTooltip( $name)
setSubmitText( $t)
Set the text for the submit button.
<input> field.
static factory( $mode=false, IContextSource $context=null)
Get a new image gallery.
Class to represent a local file in the wiki's own database.
Definition LocalFile.php:45
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
MediaWiki exception.
Class that generates HTML links for pages.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Show an error when a user tries to do something they do not have the necessary permissions for.
static singleton()
Get a RepoGroup instance.
Definition RepoGroup.php:59
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.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getContext()
Gets the context this SpecialPage is executed in.
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.
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
msg()
Wrapper around wfMessage that sets the current context.
MediaWiki Linker LinkRenderer null $linkRenderer
getTitle( $subpage=false)
Get a self-referential title object.
Form for handling uploads and special page.
processVerificationError( $details)
Provides output to the user for a result of UploadBase::verifyUpload.
UploadBase $mUpload
showViewDeletedLinks()
Shows the "view X deleted revivions link"".
getWatchCheck()
See if we should check the 'watch this page' checkbox on the form based on the user's preferences and...
loadRequest()
Initialize instance variables from request and create an Upload handler.
static getInitialPageText( $comment='', $license='', $copyStatus='', $source='', Config $config=null)
Get the initial image page text based on a comment and optional file status information.
showUploadWarning( $warnings)
Stashes the upload, shows the main form, but adds a "continue anyway button".
$uploadFormTextTop
Text injection points for hooks not using HTMLForm.
bool $mCancelUpload
The user clicked "Cancel and return to upload form" button.
unsaveUploadedFile()
Remove a temporarily kept file stashed by saveTempUploadedFile().
userCanExecute(User $user)
This page can be shown if uploading is enabled.
static getExistsWarning( $exists)
Formats a result of UploadBase::getExistsWarning as HTML This check is static and can be done pre-upl...
string $mDesiredDestName
User input variables from the "description" section.
showRecoverableUploadError( $message)
Stashes the upload and shows the main upload form.
$mDestWarningAck
Hidden variables.
getDupeWarning( $dupes)
Construct a warning and a gallery from an array of duplicate files.
showUploadForm( $form)
Show the main upload form.
__construct( $request=null)
Constructor : initialise object Get data POSTed through the form and assign them to the object.
WebRequest FauxRequest $mRequest
Misc variables.
processUpload()
Do the upload.
bool $mUploadSuccessful
Subclasses can use this to determine whether a file was uploaded.
LocalFile $mLocalFile
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
execute( $par)
Special page entry point.
getUploadForm( $message='', $sessionKey='', $hideIgnoreWarning=false)
Get an UploadForm instance with title and text properly set.
doesWrites()
Indicates whether this special page may perform database writes.
bool $mForReUpload
The user followed an "overwrite this file" link.
$mIgnoreWarning
User input variables from the root section.
showUploadError( $message)
Show the upload form with error message, but do not stash the file.
static rotationEnabled()
Should we rotate images in the preview on Special:Upload.
Represents a title within MediaWiki.
Definition Title.php:39
exists( $flags=0)
Check if page exists.
Definition Title.php:4322
UploadBase and subclasses are the backend of MediaWiki's file uploads.
const EMPTY_FILE
static createFromRequest(&$request, $type=null)
Create a form of UploadBase depending on wpSourceType and initializes it.
const FILETYPE_MISSING
static isEnabled()
Returns true if uploads are enabled.
const HOOK_ABORTED
const VERIFICATION_ERROR
const WINDOWS_NONASCII_FILENAME
const FILETYPE_BADTYPE
static getMaxUploadSize( $forType=null)
Get the MediaWiki maximum uploaded file size for given type of upload, based on $wgMaxUploadSize.
const FILE_TOO_LARGE
static isThrottled( $user)
Returns true if the user has surpassed the upload rate limit, false otherwise.
const ILLEGAL_FILENAME
const MIN_LENGTH_PARTNAME
static isAllowed( $user)
Returns true if the user can use this upload module or else a string identifying the missing permissi...
const FILENAME_TOO_LONG
static getMaxPhpUploadSize()
Get the PHP maximum uploaded file size, based on ini settings.
Sub class of HTMLForm that provides the form section of SpecialUpload.
show()
Add the upload JS and show the form.
trySubmit()
Empty function; submission is handled elsewhere.
__construct(array $options=[], IContextSource $context=null, LinkRenderer $linkRenderer=null)
getDescriptionSection()
Get the descriptor of the fieldset that contains the file description input.
getOptionsSection()
Get the descriptor of the fieldset that contains the upload options, such as "watch this file".
addUploadJS()
Add upload JS to the OutputPage.
getSourceSection()
Get the descriptor of the fieldset that contains the file source selection.
getExtensionsMessage()
Get the messages indicating which extensions are preferred and prohibitted.
Implements uploading from previously stored file.
static isAllowed( $user)
Checks if the user is allowed to use the upload-by-URL feature.
static isEnabled()
Checks if the upload from URL feature is enabled.
A form field that contains a radio box in the label.
getLabelHtml( $cellAttributes=[])
Show an error when the user tries to do something whilst blocked.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:50
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition design.txt:57
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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:18
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:68
the array() calling protocol came about after MediaWiki 1.4rc1.
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:249
error also a ContextSource you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2728
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition hooks.txt:1102
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 modifiable & $code
Definition hooks.txt:865
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
null for the local wiki Added in
Definition hooks.txt:1572
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 true
Definition hooks.txt:1967
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2723
Using a hook running we can avoid having all this option specific stuff in our mainline code Using hooks
Definition hooks.txt:74
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:864
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition hooks.txt:2937
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:304
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:1975
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition hooks.txt:1049
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 after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition hooks.txt:2007
returning false will NOT prevent logging $e
Definition hooks.txt:2127
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
Interface for objects which can provide a MediaWiki context on request.
$help
Definition mcc.php:32
$source
const DB_REPLICA
Definition defines.php:25