MediaWiki REL1_27
SpecialUpload.php
Go to the documentation of this file.
1<?php
37 public function __construct( $request = null ) {
38 parent::__construct( 'Upload', 'upload' );
39 }
40
41 public function doesWrites() {
42 return true;
43 }
44
48 public $mRequest;
50
52 public $mUpload;
53
57
62 public $mComment;
63 public $mLicense;
64
71
75
78
81 public $mTokenOk;
82
84 public $mUploadSuccessful = false;
85
89
93 protected function loadRequest() {
94 $this->mRequest = $request = $this->getRequest();
95 $this->mSourceType = $request->getVal( 'wpSourceType', 'file' );
96 $this->mUpload = UploadBase::createFromRequest( $request );
97 $this->mUploadClicked = $request->wasPosted()
98 && ( $request->getCheck( 'wpUpload' )
99 || $request->getCheck( 'wpUploadIgnoreWarning' ) );
100
101 // Guess the desired name from the filename if not provided
102 $this->mDesiredDestName = $request->getText( 'wpDestFile' );
103 if ( !$this->mDesiredDestName && $request->getFileName( 'wpUploadFile' ) !== null ) {
104 $this->mDesiredDestName = $request->getFileName( 'wpUploadFile' );
105 }
106 $this->mLicense = $request->getText( 'wpLicense' );
107
108 $this->mDestWarningAck = $request->getText( 'wpDestFileWarningAck' );
109 $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' )
110 || $request->getCheck( 'wpUploadIgnoreWarning' );
111 $this->mWatchthis = $request->getBool( 'wpWatchthis' ) && $this->getUser()->isLoggedIn();
112 $this->mCopyrightStatus = $request->getText( 'wpUploadCopyStatus' );
113 $this->mCopyrightSource = $request->getText( 'wpUploadSource' );
114
115 $this->mForReUpload = $request->getBool( 'wpForReUpload' ); // updating a file
116
117 $commentDefault = '';
118 $commentMsg = wfMessage( 'upload-default-description' )->inContentLanguage();
119 if ( !$this->mForReUpload && !$commentMsg->isDisabled() ) {
120 $commentDefault = $commentMsg->plain();
121 }
122 $this->mComment = $request->getText( 'wpUploadDescription', $commentDefault );
123
124 $this->mCancelUpload = $request->getCheck( 'wpCancelUpload' )
125 || $request->getCheck( 'wpReUpload' ); // b/w compat
126
127 // If it was posted check for the token (no remote POST'ing with user credentials)
128 $token = $request->getVal( 'wpEditToken' );
129 $this->mTokenOk = $this->getUser()->matchEditToken( $token );
130
131 $this->uploadFormTextTop = '';
132 $this->uploadFormTextAfterSummary = '';
133 }
134
143 public function userCanExecute( User $user ) {
144 return UploadBase::isEnabled() && parent::userCanExecute( $user );
145 }
146
158 public function execute( $par ) {
160
161 $this->setHeaders();
162 $this->outputHeader();
163
164 # Check uploading enabled
165 if ( !UploadBase::isEnabled() ) {
166 throw new ErrorPageError( 'uploaddisabled', 'uploaddisabledtext' );
167 }
168
169 $this->addHelpLink( 'Help:Managing files' );
170
171 # Check permissions
172 $user = $this->getUser();
173 $permissionRequired = UploadBase::isAllowed( $user );
174 if ( $permissionRequired !== true ) {
175 throw new PermissionsError( $permissionRequired );
176 }
177
178 # Check blocks
179 if ( $user->isBlocked() ) {
180 throw new UserBlockedError( $user->getBlock() );
181 }
182
183 // Global blocks
184 if ( $user->isBlockedGlobally() ) {
185 throw new UserBlockedError( $user->getGlobalBlock() );
186 }
187
188 # Check whether we actually want to allow changing stuff
189 $this->checkReadOnly();
190
191 $this->loadRequest();
192
193 # Unsave the temporary file in case this was a cancelled upload
194 if ( $this->mCancelUpload ) {
195 if ( !$this->unsaveUploadedFile() ) {
196 # Something went wrong, so unsaveUploadedFile showed a warning
197 return;
198 }
199 }
200
201 # Process upload or show a form
202 if (
203 $this->mTokenOk && !$this->mCancelUpload &&
204 ( $this->mUpload && $this->mUploadClicked )
205 ) {
206 $this->processUpload();
207 } else {
208 # Backwards compatibility hook
209 // Avoid PHP 7.1 warning of passing $this by reference
210 $upload = $this;
211 if ( !Hooks::run( 'UploadForm:initial', [ &$upload ] ) ) {
212 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form\n" );
213
214 return;
215 }
216 $this->showUploadForm( $this->getUploadForm() );
217 }
218
219 # Cleanup
220 if ( $this->mUpload ) {
221 $this->mUpload->cleanupTempFile();
222 }
223 }
224
230 protected function showUploadForm( $form ) {
231 # Add links if file was previously deleted
232 if ( $this->mDesiredDestName ) {
233 $this->showViewDeletedLinks();
234 }
235
236 if ( $form instanceof HTMLForm ) {
237 $form->show();
238 } else {
239 $this->getOutput()->addHTML( $form );
240 }
241 }
242
251 protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) {
252 # Initialize form
253 $context = new DerivativeContext( $this->getContext() );
254 $context->setTitle( $this->getPageTitle() ); // Remove subpage
255 $form = new UploadForm( [
256 'watch' => $this->getWatchCheck(),
257 'forreupload' => $this->mForReUpload,
258 'sessionkey' => $sessionKey,
259 'hideignorewarning' => $hideIgnoreWarning,
260 'destwarningack' => (bool)$this->mDestWarningAck,
261
262 'description' => $this->mComment,
263 'texttop' => $this->uploadFormTextTop,
264 'textaftersummary' => $this->uploadFormTextAfterSummary,
265 'destfile' => $this->mDesiredDestName,
266 ], $context );
267
268 # Check the token, but only if necessary
269 if (
270 !$this->mTokenOk && !$this->mCancelUpload &&
271 ( $this->mUpload && $this->mUploadClicked )
272 ) {
273 $form->addPreText( $this->msg( 'session_fail_preview' )->parse() );
274 }
275
276 # Give a notice if the user is uploading a file that has been deleted or moved
277 # Note that this is independent from the message 'filewasdeleted'
278 $desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
279 $delNotice = ''; // empty by default
280 if ( $desiredTitleObj instanceof Title && !$desiredTitleObj->exists() ) {
281 LogEventsList::showLogExtract( $delNotice, [ 'delete', 'move' ],
282 $desiredTitleObj,
283 '', [ 'lim' => 10,
284 'conds' => [ "log_action != 'revision'" ],
285 'showIfEmpty' => false,
286 'msgKey' => [ 'upload-recreate-warning' ] ]
287 );
288 }
289 $form->addPreText( $delNotice );
290
291 # Add text to form
292 $form->addPreText( '<div id="uploadtext">' .
293 $this->msg( 'uploadtext', [ $this->mDesiredDestName ] )->parseAsBlock() .
294 '</div>' );
295 # Add upload error message
296 $form->addPreText( $message );
297
298 # Add footer to form
299 $uploadFooter = $this->msg( 'uploadfooter' );
300 if ( !$uploadFooter->isDisabled() ) {
301 $form->addPostText( '<div id="mw-upload-footer-message">'
302 . $uploadFooter->parseAsBlock() . "</div>\n" );
303 }
304
305 return $form;
306 }
307
311 protected function showViewDeletedLinks() {
312 $title = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
313 $user = $this->getUser();
314 // Show a subtitle link to deleted revisions (to sysops et al only)
315 if ( $title instanceof Title ) {
316 $count = $title->isDeleted();
317 if ( $count > 0 && $user->isAllowed( 'deletedhistory' ) ) {
318 $restorelink = Linker::linkKnown(
319 SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ),
320 $this->msg( 'restorelink' )->numParams( $count )->escaped()
321 );
322 $link = $this->msg( $user->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted' )
323 ->rawParams( $restorelink )->parseAsBlock();
324 $this->getOutput()->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
325 }
326 }
327 }
328
340 protected function showRecoverableUploadError( $message ) {
341 $sessionKey = $this->mUpload->stashSession();
342 $message = '<h2>' . $this->msg( 'uploaderror' )->escaped() . "</h2>\n" .
343 '<div class="error">' . $message . "</div>\n";
344
345 $form = $this->getUploadForm( $message, $sessionKey );
346 $form->setSubmitText( $this->msg( 'upload-tryagain' )->escaped() );
347 $this->showUploadForm( $form );
348 }
349
358 protected function showUploadWarning( $warnings ) {
359 # If there are no warnings, or warnings we can ignore, return early.
360 # mDestWarningAck is set when some javascript has shown the warning
361 # to the user. mForReUpload is set when the user clicks the "upload a
362 # new version" link.
363 if ( !$warnings || ( count( $warnings ) == 1
364 && isset( $warnings['exists'] )
365 && ( $this->mDestWarningAck || $this->mForReUpload ) )
366 ) {
367 return false;
368 }
369
370 $sessionKey = $this->mUpload->stashSession();
371
372 // Add styles for the warning, reused from the live preview
373 $this->getOutput()->addModuleStyles( 'mediawiki.special.upload' );
374
375 $warningHtml = '<h2>' . $this->msg( 'uploadwarning' )->escaped() . "</h2>\n"
376 . '<div class="mw-destfile-warning"><ul>';
377 foreach ( $warnings as $warning => $args ) {
378 if ( $warning == 'badfilename' ) {
379 $this->mDesiredDestName = Title::makeTitle( NS_FILE, $args )->getText();
380 }
381 if ( $warning == 'exists' ) {
382 $msg = "\t<li>" . self::getExistsWarning( $args ) . "</li>\n";
383 } elseif ( $warning == 'was-deleted' ) {
384 # If the file existed before and was deleted, warn the user of this
385 $ltitle = SpecialPage::getTitleFor( 'Log' );
386 $llink = Linker::linkKnown(
387 $ltitle,
388 wfMessage( 'deletionlog' )->escaped(),
389 [],
390 [
391 'type' => 'delete',
392 'page' => Title::makeTitle( NS_FILE, $args )->getPrefixedText(),
393 ]
394 );
395 $msg = "\t<li>" . wfMessage( 'filewasdeleted' )->rawParams( $llink )->parse() . "</li>\n";
396 } elseif ( $warning == 'duplicate' ) {
397 $msg = $this->getDupeWarning( $args );
398 } elseif ( $warning == 'duplicate-archive' ) {
399 if ( $args === '' ) {
400 $msg = "\t<li>" . $this->msg( 'file-deleted-duplicate-notitle' )->parse()
401 . "</li>\n";
402 } else {
403 $msg = "\t<li>" . $this->msg( 'file-deleted-duplicate',
404 Title::makeTitle( NS_FILE, $args )->getPrefixedText() )->parse()
405 . "</li>\n";
406 }
407 } else {
408 if ( $args === true ) {
409 $args = [];
410 } elseif ( !is_array( $args ) ) {
411 $args = [ $args ];
412 }
413 $msg = "\t<li>" . $this->msg( $warning, $args )->parse() . "</li>\n";
414 }
415 $warningHtml .= $msg;
416 }
417 $warningHtml .= "</ul></div>\n";
418 $warningHtml .= $this->msg( 'uploadwarning-text' )->parseAsBlock();
419
420 $form = $this->getUploadForm( $warningHtml, $sessionKey, /* $hideIgnoreWarning */ true );
421 $form->setSubmitText( $this->msg( 'upload-tryagain' )->text() );
422 $form->addButton( [
423 'name' => 'wpUploadIgnoreWarning',
424 'value' => $this->msg( 'ignorewarning' )->text()
425 ] );
426 $form->addButton( [
427 'name' => 'wpCancelUpload',
428 'value' => $this->msg( 'reuploaddesc' )->text()
429 ] );
430
431 $this->showUploadForm( $form );
432
433 # Indicate that we showed a form
434 return true;
435 }
436
442 protected function showUploadError( $message ) {
443 $message = '<h2>' . $this->msg( 'uploadwarning' )->escaped() . "</h2>\n" .
444 '<div class="error">' . $message . "</div>\n";
445 $this->showUploadForm( $this->getUploadForm( $message ) );
446 }
447
452 protected function processUpload() {
453 // Fetch the file if required
454 $status = $this->mUpload->fetchFile();
455 if ( !$status->isOK() ) {
456 $this->showUploadError( $this->getOutput()->parse( $status->getWikiText() ) );
457
458 return;
459 }
460 // Avoid PHP 7.1 warning of passing $this by reference
461 $upload = $this;
462 if ( !Hooks::run( 'UploadForm:BeforeProcessing', [ &$upload ] ) ) {
463 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
464 // This code path is deprecated. If you want to break upload processing
465 // do so by hooking into the appropriate hooks in UploadBase::verifyUpload
466 // and UploadBase::verifyFile.
467 // If you use this hook to break uploading, the user will be returned
468 // an empty form with no error message whatsoever.
469 return;
470 }
471
472 // Upload verification
473 $details = $this->mUpload->verifyUpload();
474 if ( $details['status'] != UploadBase::OK ) {
475 $this->processVerificationError( $details );
476
477 return;
478 }
479
480 // Verify permissions for this title
481 $permErrors = $this->mUpload->verifyTitlePermissions( $this->getUser() );
482 if ( $permErrors !== true ) {
483 $code = array_shift( $permErrors[0] );
484 $this->showRecoverableUploadError( $this->msg( $code, $permErrors[0] )->parse() );
485
486 return;
487 }
488
489 $this->mLocalFile = $this->mUpload->getLocalFile();
490
491 // Check warnings if necessary
492 if ( !$this->mIgnoreWarning ) {
493 $warnings = $this->mUpload->checkWarnings();
494 if ( $this->showUploadWarning( $warnings ) ) {
495 return;
496 }
497 }
498
499 // This is as late as we can throttle, after expected issues have been handled
500 if ( UploadBase::isThrottled( $this->getUser() ) ) {
502 $this->msg( 'actionthrottledtext' )->escaped()
503 );
504 return;
505 }
506
507 // Get the page text if this is not a reupload
508 if ( !$this->mForReUpload ) {
509 $pageText = self::getInitialPageText( $this->mComment, $this->mLicense,
510 $this->mCopyrightStatus, $this->mCopyrightSource, $this->getConfig() );
511 } else {
512 $pageText = false;
513 }
514
515 $changeTags = $this->getRequest()->getVal( 'wpChangeTags' );
516 if ( is_null( $changeTags ) || $changeTags === '' ) {
517 $changeTags = [];
518 } else {
519 $changeTags = array_filter( array_map( 'trim', explode( ',', $changeTags ) ) );
520 }
521
522 if ( $changeTags ) {
524 $changeTags, $this->getUser() );
525 if ( !$changeTagsStatus->isOK() ) {
526 $this->showUploadError( $this->getOutput()->parse( $changeTagsStatus->getWikiText() ) );
527
528 return;
529 }
530 }
531
532 $status = $this->mUpload->performUpload(
533 $this->mComment,
534 $pageText,
535 $this->mWatchthis,
536 $this->getUser(),
537 $changeTags
538 );
539
540 if ( !$status->isGood() ) {
541 $this->showUploadError( $this->getOutput()->parse( $status->getWikiText() ) );
542
543 return;
544 }
545
546 // Success, redirect to description page
547 $this->mUploadSuccessful = true;
548 // Avoid PHP 7.1 warning of passing $this by reference
549 $upload = $this;
550 Hooks::run( 'SpecialUploadComplete', [ &$upload ] );
551 $this->getOutput()->redirect( $this->mLocalFile->getTitle()->getFullURL() );
552 }
553
563 public static function getInitialPageText( $comment = '', $license = '',
564 $copyStatus = '', $source = '', Config $config = null
565 ) {
566 if ( $config === null ) {
567 wfDebug( __METHOD__ . ' called without a Config instance passed to it' );
568 $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
569 }
570
571 $msg = [];
572 $forceUIMsgAsContentMsg = (array)$config->get( 'ForceUIMsgAsContentMsg' );
573 /* These messages are transcluded into the actual text of the description page.
574 * Thus, forcing them as content messages makes the upload to produce an int: template
575 * instead of hardcoding it there in the uploader language.
576 */
577 foreach ( [ 'license-header', 'filedesc', 'filestatus', 'filesource' ] as $msgName ) {
578 if ( in_array( $msgName, $forceUIMsgAsContentMsg ) ) {
579 $msg[$msgName] = "{{int:$msgName}}";
580 } else {
581 $msg[$msgName] = wfMessage( $msgName )->inContentLanguage()->text();
582 }
583 }
584
585 if ( $config->get( 'UseCopyrightUpload' ) ) {
586 $licensetxt = '';
587 if ( $license != '' ) {
588 $licensetxt = '== ' . $msg['license-header'] . " ==\n" . '{{' . $license . '}}' . "\n";
589 }
590 $pageText = '== ' . $msg['filedesc'] . " ==\n" . $comment . "\n" .
591 '== ' . $msg['filestatus'] . " ==\n" . $copyStatus . "\n" .
592 "$licensetxt" .
593 '== ' . $msg['filesource'] . " ==\n" . $source;
594 } else {
595 if ( $license != '' ) {
596 $filedesc = $comment == '' ? '' : '== ' . $msg['filedesc'] . " ==\n" . $comment . "\n";
597 $pageText = $filedesc .
598 '== ' . $msg['license-header'] . " ==\n" . '{{' . $license . '}}' . "\n";
599 } else {
600 $pageText = $comment;
601 }
602 }
603
604 return $pageText;
605 }
606
619 protected function getWatchCheck() {
620 if ( $this->getUser()->getOption( 'watchdefault' ) ) {
621 // Watch all edits!
622 return true;
623 }
624
625 $desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
626 if ( $desiredTitleObj instanceof Title && $this->getUser()->isWatched( $desiredTitleObj ) ) {
627 // Already watched, don't change that
628 return true;
629 }
630
631 $local = wfLocalFile( $this->mDesiredDestName );
632 if ( $local && $local->exists() ) {
633 // We're uploading a new version of an existing file.
634 // No creation, so don't watch it if we're not already.
635 return false;
636 } else {
637 // New page should get watched if that's our option.
638 return $this->getUser()->getOption( 'watchcreations' ) ||
639 $this->getUser()->getOption( 'watchuploads' );
640 }
641 }
642
649 protected function processVerificationError( $details ) {
650 switch ( $details['status'] ) {
651
654 $this->showRecoverableUploadError( $this->msg( 'minlength1' )->escaped() );
655 break;
657 $this->showRecoverableUploadError( $this->msg( 'illegalfilename',
658 $details['filtered'] )->parse() );
659 break;
661 $this->showRecoverableUploadError( $this->msg( 'filename-toolong' )->escaped() );
662 break;
664 $this->showRecoverableUploadError( $this->msg( 'filetype-missing' )->parse() );
665 break;
667 $this->showRecoverableUploadError( $this->msg( 'windows-nonascii-filename' )->parse() );
668 break;
669
672 $this->showUploadError( $this->msg( 'emptyfile' )->escaped() );
673 break;
675 $this->showUploadError( $this->msg( 'largefileserver' )->escaped() );
676 break;
678 $msg = $this->msg( 'filetype-banned-type' );
679 if ( isset( $details['blacklistedExt'] ) ) {
680 $msg->params( $this->getLanguage()->commaList( $details['blacklistedExt'] ) );
681 } else {
682 $msg->params( $details['finalExt'] );
683 }
684 $extensions = array_unique( $this->getConfig()->get( 'FileExtensions' ) );
685 $msg->params( $this->getLanguage()->commaList( $extensions ),
686 count( $extensions ) );
687
688 // Add PLURAL support for the first parameter. This results
689 // in a bit unlogical parameter sequence, but does not break
690 // old translations
691 if ( isset( $details['blacklistedExt'] ) ) {
692 $msg->params( count( $details['blacklistedExt'] ) );
693 } else {
694 $msg->params( 1 );
695 }
696
697 $this->showUploadError( $msg->parse() );
698 break;
700 unset( $details['status'] );
701 $code = array_shift( $details['details'] );
702 $this->showUploadError( $this->msg( $code, $details['details'] )->parse() );
703 break;
705 if ( is_array( $details['error'] ) ) { # allow hooks to return error details in an array
706 $args = $details['error'];
707 $error = array_shift( $args );
708 } else {
709 $error = $details['error'];
710 $args = null;
711 }
712
713 $this->showUploadError( $this->msg( $error, $args )->parse() );
714 break;
715 default:
716 throw new MWException( __METHOD__ . ": Unknown value `{$details['status']}`" );
717 }
718 }
719
725 protected function unsaveUploadedFile() {
726 if ( !( $this->mUpload instanceof UploadFromStash ) ) {
727 return true;
728 }
729 $success = $this->mUpload->unsaveUploadedFile();
730 if ( !$success ) {
731 $this->getOutput()->showFileDeleteError( $this->mUpload->getTempPath() );
732
733 return false;
734 } else {
735 return true;
736 }
737 }
738
739 /*** Functions for formatting warnings ***/
740
748 public static function getExistsWarning( $exists ) {
749 if ( !$exists ) {
750 return '';
751 }
752
753 $file = $exists['file'];
754 $filename = $file->getTitle()->getPrefixedText();
755 $warning = '';
756
757 if ( $exists['warning'] == 'exists' ) {
758 // Exact match
759 $warning = wfMessage( 'fileexists', $filename )->parse();
760 } elseif ( $exists['warning'] == 'page-exists' ) {
761 // Page exists but file does not
762 $warning = wfMessage( 'filepageexists', $filename )->parse();
763 } elseif ( $exists['warning'] == 'exists-normalized' ) {
764 $warning = wfMessage( 'fileexists-extension', $filename,
765 $exists['normalizedFile']->getTitle()->getPrefixedText() )->parse();
766 } elseif ( $exists['warning'] == 'thumb' ) {
767 // Swapped argument order compared with other messages for backwards compatibility
768 $warning = wfMessage( 'fileexists-thumbnail-yes',
769 $exists['thumbFile']->getTitle()->getPrefixedText(), $filename )->parse();
770 } elseif ( $exists['warning'] == 'thumb-name' ) {
771 // Image w/o '180px-' does not exists, but we do not like these filenames
772 $name = $file->getName();
773 $badPart = substr( $name, 0, strpos( $name, '-' ) + 1 );
774 $warning = wfMessage( 'file-thumbnail-no', $badPart )->parse();
775 } elseif ( $exists['warning'] == 'bad-prefix' ) {
776 $warning = wfMessage( 'filename-bad-prefix', $exists['prefix'] )->parse();
777 }
778
779 return $warning;
780 }
781
787 public function getDupeWarning( $dupes ) {
788 if ( !$dupes ) {
789 return '';
790 }
791
792 $gallery = ImageGalleryBase::factory( false, $this->getContext() );
793 $gallery->setShowBytes( false );
794 foreach ( $dupes as $file ) {
795 $gallery->add( $file->getTitle() );
796 }
797
798 return '<li>' .
799 $this->msg( 'file-exists-duplicate' )->numParams( count( $dupes ) )->parse() .
800 $gallery->toHTML() . "</li>\n";
801 }
802
803 protected function getGroupName() {
804 return 'media';
805 }
806
814 public static function rotationEnabled() {
815 $bitmapHandler = new BitmapHandler();
816 return $bitmapHandler->autoRotateEnabled();
817 }
818}
819
823class UploadForm extends HTMLForm {
824 protected $mWatch;
825 protected $mForReUpload;
826 protected $mSessionKey;
829 protected $mDestFile;
830
831 protected $mComment;
832 protected $mTextTop;
834
835 protected $mSourceIds;
836
837 protected $mMaxFileSize = [];
838
839 protected $mMaxUploadSize = [];
840
841 public function __construct( array $options = [], IContextSource $context = null ) {
842 if ( $context instanceof IContextSource ) {
843 $this->setContext( $context );
844 }
845
846 $this->mWatch = !empty( $options['watch'] );
847 $this->mForReUpload = !empty( $options['forreupload'] );
848 $this->mSessionKey = isset( $options['sessionkey'] ) ? $options['sessionkey'] : '';
849 $this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] );
850 $this->mDestWarningAck = !empty( $options['destwarningack'] );
851 $this->mDestFile = isset( $options['destfile'] ) ? $options['destfile'] : '';
852
853 $this->mComment = isset( $options['description'] ) ?
854 $options['description'] : '';
855
856 $this->mTextTop = isset( $options['texttop'] )
857 ? $options['texttop'] : '';
858
859 $this->mTextAfterSummary = isset( $options['textaftersummary'] )
860 ? $options['textaftersummary'] : '';
861
862 $sourceDescriptor = $this->getSourceSection();
863 $descriptor = $sourceDescriptor
864 + $this->getDescriptionSection()
865 + $this->getOptionsSection();
866
867 Hooks::run( 'UploadFormInitDescriptor', [ &$descriptor ] );
868 parent::__construct( $descriptor, $context, 'upload' );
869
870 # Add a link to edit MediaWik:Licenses
871 if ( $this->getUser()->isAllowed( 'editinterface' ) ) {
872 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
873 $licensesLink = Linker::linkKnown(
874 $this->msg( 'licenses' )->inContentLanguage()->getTitle(),
875 $this->msg( 'licenses-edit' )->escaped(),
876 [],
877 [ 'action' => 'edit' ]
878 );
879 $editLicenses = '<p class="mw-upload-editlicenses">' . $licensesLink . '</p>';
880 $this->addFooterText( $editLicenses, 'description' );
881 }
882
883 # Set some form properties
884 $this->setSubmitText( $this->msg( 'uploadbtn' )->text() );
885 $this->setSubmitName( 'wpUpload' );
886 # Used message keys: 'accesskey-upload', 'tooltip-upload'
887 $this->setSubmitTooltip( 'upload' );
888 $this->setId( 'mw-upload-form' );
889
890 # Build a list of IDs for javascript insertion
891 $this->mSourceIds = [];
892 foreach ( $sourceDescriptor as $field ) {
893 if ( !empty( $field['id'] ) ) {
894 $this->mSourceIds[] = $field['id'];
895 }
896 }
897 }
898
905 protected function getSourceSection() {
906 if ( $this->mSessionKey ) {
907 return [
908 'SessionKey' => [
909 'type' => 'hidden',
910 'default' => $this->mSessionKey,
911 ],
912 'SourceType' => [
913 'type' => 'hidden',
914 'default' => 'Stash',
915 ],
916 ];
917 }
918
919 $canUploadByUrl = UploadFromUrl::isEnabled()
920 && ( UploadFromUrl::isAllowed( $this->getUser() ) === true )
921 && $this->getConfig()->get( 'CopyUploadsFromSpecialUpload' );
922 $radio = $canUploadByUrl;
923 $selectedSourceType = strtolower( $this->getRequest()->getText( 'wpSourceType', 'File' ) );
924
925 $descriptor = [];
926 if ( $this->mTextTop ) {
927 $descriptor['UploadFormTextTop'] = [
928 'type' => 'info',
929 'section' => 'source',
930 'default' => $this->mTextTop,
931 'raw' => true,
932 ];
933 }
934
935 $this->mMaxUploadSize['file'] = min(
938 );
939
940 $help = $this->msg( 'upload-maxfilesize',
941 $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['file'] )
942 )->parse();
943
944 // If the user can also upload by URL, there are 2 different file size limits.
945 // This extra message helps stress which limit corresponds to what.
946 if ( $canUploadByUrl ) {
947 $help .= $this->msg( 'word-separator' )->escaped();
948 $help .= $this->msg( 'upload_source_file' )->parse();
949 }
950
951 $descriptor['UploadFile'] = [
952 'class' => 'UploadSourceField',
953 'section' => 'source',
954 'type' => 'file',
955 'id' => 'wpUploadFile',
956 'radio-id' => 'wpSourceTypeFile',
957 'label-message' => 'sourcefilename',
958 'upload-type' => 'File',
959 'radio' => &$radio,
960 'help' => $help,
961 'checked' => $selectedSourceType == 'file',
962 ];
963
964 if ( $canUploadByUrl ) {
965 $this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize( 'url' );
966 $descriptor['UploadFileURL'] = [
967 'class' => 'UploadSourceField',
968 'section' => 'source',
969 'id' => 'wpUploadFileURL',
970 'radio-id' => 'wpSourceTypeurl',
971 'label-message' => 'sourceurl',
972 'upload-type' => 'url',
973 'radio' => &$radio,
974 'help' => $this->msg( 'upload-maxfilesize',
975 $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['url'] )
976 )->parse() .
977 $this->msg( 'word-separator' )->escaped() .
978 $this->msg( 'upload_source_url' )->parse(),
979 'checked' => $selectedSourceType == 'url',
980 ];
981 }
982 Hooks::run( 'UploadFormSourceDescriptors', [ &$descriptor, &$radio, $selectedSourceType ] );
983
984 $descriptor['Extensions'] = [
985 'type' => 'info',
986 'section' => 'source',
987 'default' => $this->getExtensionsMessage(),
988 'raw' => true,
989 ];
990
991 return $descriptor;
992 }
993
999 protected function getExtensionsMessage() {
1000 # Print a list of allowed file extensions, if so configured. We ignore
1001 # MIME type here, it's incomprehensible to most people and too long.
1002 $config = $this->getConfig();
1003
1004 if ( $config->get( 'CheckFileExtensions' ) ) {
1005 $fileExtensions = array_unique( $config->get( 'FileExtensions' ) );
1006 if ( $config->get( 'StrictFileExtensions' ) ) {
1007 # Everything not permitted is banned
1008 $extensionsList =
1009 '<div id="mw-upload-permitted">' .
1010 $this->msg( 'upload-permitted' )
1011 ->params( $this->getLanguage()->commaList( $fileExtensions ) )
1012 ->numParams( count( $fileExtensions ) )
1013 ->parseAsBlock() .
1014 "</div>\n";
1015 } else {
1016 # We have to list both preferred and prohibited
1017 $fileBlacklist = array_unique( $config->get( 'FileBlacklist' ) );
1018 $extensionsList =
1019 '<div id="mw-upload-preferred">' .
1020 $this->msg( 'upload-preferred' )
1021 ->params( $this->getLanguage()->commaList( $fileExtensions ) )
1022 ->numParams( count( $fileExtensions ) )
1023 ->parseAsBlock() .
1024 "</div>\n" .
1025 '<div id="mw-upload-prohibited">' .
1026 $this->msg( 'upload-prohibited' )
1027 ->params( $this->getLanguage()->commaList( $fileBlacklist ) )
1028 ->numParams( count( $fileBlacklist ) )
1029 ->parseAsBlock() .
1030 "</div>\n";
1031 }
1032 } else {
1033 # Everything is permitted.
1034 $extensionsList = '';
1035 }
1036
1037 return $extensionsList;
1038 }
1039
1046 protected function getDescriptionSection() {
1047 $config = $this->getConfig();
1048 if ( $this->mSessionKey ) {
1049 $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $this->getUser() );
1050 try {
1051 $file = $stash->getFile( $this->mSessionKey );
1052 } catch ( Exception $e ) {
1053 $file = null;
1054 }
1055 if ( $file ) {
1057
1058 $mto = $file->transform( [ 'width' => 120 ] );
1059 if ( $mto ) {
1060 $this->addHeaderText(
1061 '<div class="thumb t' . $wgContLang->alignEnd() . '">' .
1062 Html::element( 'img', [
1063 'src' => $mto->getUrl(),
1064 'class' => 'thumbimage',
1065 ] ) . '</div>', 'description' );
1066 }
1067 }
1068 }
1069
1070 $descriptor = [
1071 'DestFile' => [
1072 'type' => 'text',
1073 'section' => 'description',
1074 'id' => 'wpDestFile',
1075 'label-message' => 'destfilename',
1076 'size' => 60,
1077 'default' => $this->mDestFile,
1078 # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
1079 'nodata' => strval( $this->mDestFile ) !== '',
1080 ],
1081 'UploadDescription' => [
1082 'type' => 'textarea',
1083 'section' => 'description',
1084 'id' => 'wpUploadDescription',
1085 'label-message' => $this->mForReUpload
1086 ? 'filereuploadsummary'
1087 : 'fileuploadsummary',
1088 'default' => $this->mComment,
1089 'cols' => $this->getUser()->getIntOption( 'cols' ),
1090 'rows' => 8,
1091 ]
1092 ];
1093 if ( $this->mTextAfterSummary ) {
1094 $descriptor['UploadFormTextAfterSummary'] = [
1095 'type' => 'info',
1096 'section' => 'description',
1097 'default' => $this->mTextAfterSummary,
1098 'raw' => true,
1099 ];
1100 }
1101
1102 $descriptor += [
1103 'EditTools' => [
1104 'type' => 'edittools',
1105 'section' => 'description',
1106 'message' => 'edittools-upload',
1107 ]
1108 ];
1109
1110 if ( $this->mForReUpload ) {
1111 $descriptor['DestFile']['readonly'] = true;
1112 } else {
1113 $descriptor['License'] = [
1114 'type' => 'select',
1115 'class' => 'Licenses',
1116 'section' => 'description',
1117 'id' => 'wpLicense',
1118 'label-message' => 'license',
1119 ];
1120 }
1121
1122 if ( $config->get( 'UseCopyrightUpload' ) ) {
1123 $descriptor['UploadCopyStatus'] = [
1124 'type' => 'text',
1125 'section' => 'description',
1126 'id' => 'wpUploadCopyStatus',
1127 'label-message' => 'filestatus',
1128 ];
1129 $descriptor['UploadSource'] = [
1130 'type' => 'text',
1131 'section' => 'description',
1132 'id' => 'wpUploadSource',
1133 'label-message' => 'filesource',
1134 ];
1135 }
1136
1137 return $descriptor;
1138 }
1139
1146 protected function getOptionsSection() {
1147 $user = $this->getUser();
1148 if ( $user->isLoggedIn() ) {
1149 $descriptor = [
1150 'Watchthis' => [
1151 'type' => 'check',
1152 'id' => 'wpWatchthis',
1153 'label-message' => 'watchthisupload',
1154 'section' => 'options',
1155 'default' => $this->mWatch,
1156 ]
1157 ];
1158 }
1159 if ( !$this->mHideIgnoreWarning ) {
1160 $descriptor['IgnoreWarning'] = [
1161 'type' => 'check',
1162 'id' => 'wpIgnoreWarning',
1163 'label-message' => 'ignorewarnings',
1164 'section' => 'options',
1165 ];
1166 }
1167
1168 $descriptor['DestFileWarningAck'] = [
1169 'type' => 'hidden',
1170 'id' => 'wpDestFileWarningAck',
1171 'default' => $this->mDestWarningAck ? '1' : '',
1172 ];
1173
1174 if ( $this->mForReUpload ) {
1175 $descriptor['ForReUpload'] = [
1176 'type' => 'hidden',
1177 'id' => 'wpForReUpload',
1178 'default' => '1',
1179 ];
1180 }
1181
1182 return $descriptor;
1183 }
1184
1188 public function show() {
1189 $this->addUploadJS();
1190 parent::show();
1191 }
1192
1196 protected function addUploadJS() {
1197 $config = $this->getConfig();
1198
1199 $useAjaxDestCheck = $config->get( 'UseAjax' ) && $config->get( 'AjaxUploadDestCheck' );
1200 $useAjaxLicensePreview = $config->get( 'UseAjax' ) &&
1201 $config->get( 'AjaxLicensePreview' ) && $config->get( 'EnableAPI' );
1202 $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize();
1203
1204 $scriptVars = [
1205 'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
1206 'wgAjaxLicensePreview' => $useAjaxLicensePreview,
1207 'wgUploadAutoFill' => !$this->mForReUpload &&
1208 // If we received mDestFile from the request, don't autofill
1209 // the wpDestFile textbox
1210 $this->mDestFile === '',
1211 'wgUploadSourceIds' => $this->mSourceIds,
1212 'wgCheckFileExtensions' => $config->get( 'CheckFileExtensions' ),
1213 'wgStrictFileExtensions' => $config->get( 'StrictFileExtensions' ),
1214 'wgFileExtensions' => array_values( array_unique( $config->get( 'FileExtensions' ) ) ),
1215 'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ),
1216 'wgMaxUploadSize' => $this->mMaxUploadSize,
1217 'wgFileCanRotate' => SpecialUpload::rotationEnabled(),
1218 ];
1219
1220 $out = $this->getOutput();
1221 $out->addJsConfigVars( $scriptVars );
1222
1223 $out->addModules( [
1224 'mediawiki.action.edit', // For <charinsert> support
1225 'mediawiki.special.upload', // Extras for thumbnail and license preview.
1226 ] );
1227 }
1228
1234 function trySubmit() {
1235 return false;
1236 }
1237}
1238
1243
1248 function getLabelHtml( $cellAttributes = [] ) {
1249 $id = $this->mParams['id'];
1250 $label = Html::rawElement( 'label', [ 'for' => $id ], $this->mLabel );
1251
1252 if ( !empty( $this->mParams['radio'] ) ) {
1253 if ( isset( $this->mParams['radio-id'] ) ) {
1254 $radioId = $this->mParams['radio-id'];
1255 } else {
1256 // Old way. For the benefit of extensions that do not define
1257 // the 'radio-id' key.
1258 $radioId = 'wpSourceType' . $this->mParams['upload-type'];
1259 }
1260
1261 $attribs = [
1262 'name' => 'wpSourceType',
1263 'type' => 'radio',
1264 'id' => $radioId,
1265 'value' => $this->mParams['upload-type'],
1266 ];
1267
1268 if ( !empty( $this->mParams['checked'] ) ) {
1269 $attribs['checked'] = 'checked';
1270 }
1271
1272 $label .= Html::element( 'input', $attribs );
1273 }
1274
1275 return Html::rawElement( 'td', [ 'class' => 'mw-label' ] + $cellAttributes, $label );
1276 }
1277
1281 function getSize() {
1282 return isset( $this->mParams['size'] )
1283 ? $this->mParams['size']
1284 : 60;
1285 }
1286}
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfLocalFile( $title)
Get an object referring to a locally registered file.
if( $line===false) $args
Definition cdb.php:64
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:123
setSubmitName( $name)
setId( $id)
addFooterText( $msg, $section=null)
Add footer text, inside the form.
Definition HTMLForm.php:769
addHeaderText( $msg, $section=null)
Add HTML to the header, inside the form.
Definition HTMLForm.php:714
getTitle()
Get the title.
setSubmitTooltip( $name)
setSubmitText( $t)
Set the text for the submit button.
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition Html.php:230
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition Html.php:210
static factory( $mode=false, IContextSource $context=null)
Get a new image gallery.
static linkKnown( $target, $html=null, $customAttribs=[], $query=[], $options=[ 'known', 'noclasses'])
Identical to link(), except $options defaults to 'known'.
Definition Linker.php:264
Class to represent a local file in the wiki's own database.
Definition LocalFile.php:46
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
MediaWiki exception.
static isCapitalized( $index)
Is the namespace first-letter capitalized?
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.
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.
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:34
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition Title.php:524
exists( $flags=0)
Check if page exists.
Definition Title.php:4287
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition Title.php:548
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)
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:47
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:76
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist 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:1007
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
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:1819
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 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
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist 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:1042
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:944
null for the local wiki Added in
Definition hooks.txt:1421
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:1811
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2530
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:846
the value to return A Title object or null for latest to be modified or replaced by the hook handler or if authentication is not possible after cache objects are set for highlighting & $link
Definition hooks.txt:2692
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:314
returning false will NOT prevent logging $e
Definition hooks.txt:1940
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:847
$comment
$license
$extensions
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 configuration instances.
Definition Config.php:28
Interface for objects which can provide a MediaWiki context on request.
$context
Definition load.php:44
$help
Definition mcc.php:32
$source