MediaWiki  1.27.2
SpecialUpload.php
Go to the documentation of this file.
1 <?php
31 class SpecialUpload extends SpecialPage {
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;
49  public $mSourceType;
50 
52  public $mUpload;
53 
55  public $mLocalFile;
57 
62  public $mComment;
63  public $mLicense;
64 
68  public $mWatchthis;
71 
75 
77  public $mForReUpload;
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 ) {
159  $this->useTransactionalTimeLimit();
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  if ( !Hooks::run( 'UploadForm:initial', [ &$this ] ) ) {
210  wfDebug( "Hook 'UploadForm:initial' broke output of the upload form\n" );
211 
212  return;
213  }
214  $this->showUploadForm( $this->getUploadForm() );
215  }
216 
217  # Cleanup
218  if ( $this->mUpload ) {
219  $this->mUpload->cleanupTempFile();
220  }
221  }
222 
228  protected function showUploadForm( $form ) {
229  # Add links if file was previously deleted
230  if ( $this->mDesiredDestName ) {
231  $this->showViewDeletedLinks();
232  }
233 
234  if ( $form instanceof HTMLForm ) {
235  $form->show();
236  } else {
237  $this->getOutput()->addHTML( $form );
238  }
239  }
240 
249  protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) {
250  # Initialize form
251  $context = new DerivativeContext( $this->getContext() );
252  $context->setTitle( $this->getPageTitle() ); // Remove subpage
253  $form = new UploadForm( [
254  'watch' => $this->getWatchCheck(),
255  'forreupload' => $this->mForReUpload,
256  'sessionkey' => $sessionKey,
257  'hideignorewarning' => $hideIgnoreWarning,
258  'destwarningack' => (bool)$this->mDestWarningAck,
259 
260  'description' => $this->mComment,
261  'texttop' => $this->uploadFormTextTop,
262  'textaftersummary' => $this->uploadFormTextAfterSummary,
263  'destfile' => $this->mDesiredDestName,
264  ], $context );
265 
266  # Check the token, but only if necessary
267  if (
268  !$this->mTokenOk && !$this->mCancelUpload &&
269  ( $this->mUpload && $this->mUploadClicked )
270  ) {
271  $form->addPreText( $this->msg( 'session_fail_preview' )->parse() );
272  }
273 
274  # Give a notice if the user is uploading a file that has been deleted or moved
275  # Note that this is independent from the message 'filewasdeleted'
276  $desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
277  $delNotice = ''; // empty by default
278  if ( $desiredTitleObj instanceof Title && !$desiredTitleObj->exists() ) {
279  LogEventsList::showLogExtract( $delNotice, [ 'delete', 'move' ],
280  $desiredTitleObj,
281  '', [ 'lim' => 10,
282  'conds' => [ "log_action != 'revision'" ],
283  'showIfEmpty' => false,
284  'msgKey' => [ 'upload-recreate-warning' ] ]
285  );
286  }
287  $form->addPreText( $delNotice );
288 
289  # Add text to form
290  $form->addPreText( '<div id="uploadtext">' .
291  $this->msg( 'uploadtext', [ $this->mDesiredDestName ] )->parseAsBlock() .
292  '</div>' );
293  # Add upload error message
294  $form->addPreText( $message );
295 
296  # Add footer to form
297  $uploadFooter = $this->msg( 'uploadfooter' );
298  if ( !$uploadFooter->isDisabled() ) {
299  $form->addPostText( '<div id="mw-upload-footer-message">'
300  . $uploadFooter->parseAsBlock() . "</div>\n" );
301  }
302 
303  return $form;
304  }
305 
309  protected function showViewDeletedLinks() {
310  $title = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
311  $user = $this->getUser();
312  // Show a subtitle link to deleted revisions (to sysops et al only)
313  if ( $title instanceof Title ) {
314  $count = $title->isDeleted();
315  if ( $count > 0 && $user->isAllowed( 'deletedhistory' ) ) {
316  $restorelink = Linker::linkKnown(
317  SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ),
318  $this->msg( 'restorelink' )->numParams( $count )->escaped()
319  );
320  $link = $this->msg( $user->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted' )
321  ->rawParams( $restorelink )->parseAsBlock();
322  $this->getOutput()->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
323  }
324  }
325  }
326 
338  protected function showRecoverableUploadError( $message ) {
339  $sessionKey = $this->mUpload->stashSession();
340  $message = '<h2>' . $this->msg( 'uploaderror' )->escaped() . "</h2>\n" .
341  '<div class="error">' . $message . "</div>\n";
342 
343  $form = $this->getUploadForm( $message, $sessionKey );
344  $form->setSubmitText( $this->msg( 'upload-tryagain' )->escaped() );
345  $this->showUploadForm( $form );
346  }
347 
356  protected function showUploadWarning( $warnings ) {
357  # If there are no warnings, or warnings we can ignore, return early.
358  # mDestWarningAck is set when some javascript has shown the warning
359  # to the user. mForReUpload is set when the user clicks the "upload a
360  # new version" link.
361  if ( !$warnings || ( count( $warnings ) == 1
362  && isset( $warnings['exists'] )
363  && ( $this->mDestWarningAck || $this->mForReUpload ) )
364  ) {
365  return false;
366  }
367 
368  $sessionKey = $this->mUpload->stashSession();
369 
370  // Add styles for the warning, reused from the live preview
371  $this->getOutput()->addModuleStyles( 'mediawiki.special.upload' );
372 
373  $warningHtml = '<h2>' . $this->msg( 'uploadwarning' )->escaped() . "</h2>\n"
374  . '<div class="mw-destfile-warning"><ul>';
375  foreach ( $warnings as $warning => $args ) {
376  if ( $warning == 'badfilename' ) {
377  $this->mDesiredDestName = Title::makeTitle( NS_FILE, $args )->getText();
378  }
379  if ( $warning == 'exists' ) {
380  $msg = "\t<li>" . self::getExistsWarning( $args ) . "</li>\n";
381  } elseif ( $warning == 'was-deleted' ) {
382  # If the file existed before and was deleted, warn the user of this
383  $ltitle = SpecialPage::getTitleFor( 'Log' );
384  $llink = Linker::linkKnown(
385  $ltitle,
386  wfMessage( 'deletionlog' )->escaped(),
387  [],
388  [
389  'type' => 'delete',
390  'page' => Title::makeTitle( NS_FILE, $args )->getPrefixedText(),
391  ]
392  );
393  $msg = "\t<li>" . wfMessage( 'filewasdeleted' )->rawParams( $llink )->parse() . "</li>\n";
394  } elseif ( $warning == 'duplicate' ) {
395  $msg = $this->getDupeWarning( $args );
396  } elseif ( $warning == 'duplicate-archive' ) {
397  if ( $args === '' ) {
398  $msg = "\t<li>" . $this->msg( 'file-deleted-duplicate-notitle' )->parse()
399  . "</li>\n";
400  } else {
401  $msg = "\t<li>" . $this->msg( 'file-deleted-duplicate',
402  Title::makeTitle( NS_FILE, $args )->getPrefixedText() )->parse()
403  . "</li>\n";
404  }
405  } else {
406  if ( $args === true ) {
407  $args = [];
408  } elseif ( !is_array( $args ) ) {
409  $args = [ $args ];
410  }
411  $msg = "\t<li>" . $this->msg( $warning, $args )->parse() . "</li>\n";
412  }
413  $warningHtml .= $msg;
414  }
415  $warningHtml .= "</ul></div>\n";
416  $warningHtml .= $this->msg( 'uploadwarning-text' )->parseAsBlock();
417 
418  $form = $this->getUploadForm( $warningHtml, $sessionKey, /* $hideIgnoreWarning */ true );
419  $form->setSubmitText( $this->msg( 'upload-tryagain' )->text() );
420  $form->addButton( [
421  'name' => 'wpUploadIgnoreWarning',
422  'value' => $this->msg( 'ignorewarning' )->text()
423  ] );
424  $form->addButton( [
425  'name' => 'wpCancelUpload',
426  'value' => $this->msg( 'reuploaddesc' )->text()
427  ] );
428 
429  $this->showUploadForm( $form );
430 
431  # Indicate that we showed a form
432  return true;
433  }
434 
440  protected function showUploadError( $message ) {
441  $message = '<h2>' . $this->msg( 'uploadwarning' )->escaped() . "</h2>\n" .
442  '<div class="error">' . $message . "</div>\n";
443  $this->showUploadForm( $this->getUploadForm( $message ) );
444  }
445 
450  protected function processUpload() {
451  // Fetch the file if required
452  $status = $this->mUpload->fetchFile();
453  if ( !$status->isOK() ) {
454  $this->showUploadError( $this->getOutput()->parse( $status->getWikiText() ) );
455 
456  return;
457  }
458 
459  if ( !Hooks::run( 'UploadForm:BeforeProcessing', [ &$this ] ) ) {
460  wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
461  // This code path is deprecated. If you want to break upload processing
462  // do so by hooking into the appropriate hooks in UploadBase::verifyUpload
463  // and UploadBase::verifyFile.
464  // If you use this hook to break uploading, the user will be returned
465  // an empty form with no error message whatsoever.
466  return;
467  }
468 
469  // Upload verification
470  $details = $this->mUpload->verifyUpload();
471  if ( $details['status'] != UploadBase::OK ) {
472  $this->processVerificationError( $details );
473 
474  return;
475  }
476 
477  // Verify permissions for this title
478  $permErrors = $this->mUpload->verifyTitlePermissions( $this->getUser() );
479  if ( $permErrors !== true ) {
480  $code = array_shift( $permErrors[0] );
481  $this->showRecoverableUploadError( $this->msg( $code, $permErrors[0] )->parse() );
482 
483  return;
484  }
485 
486  $this->mLocalFile = $this->mUpload->getLocalFile();
487 
488  // Check warnings if necessary
489  if ( !$this->mIgnoreWarning ) {
490  $warnings = $this->mUpload->checkWarnings();
491  if ( $this->showUploadWarning( $warnings ) ) {
492  return;
493  }
494  }
495 
496  // This is as late as we can throttle, after expected issues have been handled
497  if ( UploadBase::isThrottled( $this->getUser() ) ) {
499  $this->msg( 'actionthrottledtext' )->escaped()
500  );
501  return;
502  }
503 
504  // Get the page text if this is not a reupload
505  if ( !$this->mForReUpload ) {
506  $pageText = self::getInitialPageText( $this->mComment, $this->mLicense,
507  $this->mCopyrightStatus, $this->mCopyrightSource, $this->getConfig() );
508  } else {
509  $pageText = false;
510  }
511 
512  $changeTags = $this->getRequest()->getVal( 'wpChangeTags' );
513  if ( is_null( $changeTags ) || $changeTags === '' ) {
514  $changeTags = [];
515  } else {
516  $changeTags = array_filter( array_map( 'trim', explode( ',', $changeTags ) ) );
517  }
518 
519  if ( $changeTags ) {
520  $changeTagsStatus = ChangeTags::canAddTagsAccompanyingChange(
521  $changeTags, $this->getUser() );
522  if ( !$changeTagsStatus->isOK() ) {
523  $this->showUploadError( $this->getOutput()->parse( $changeTagsStatus->getWikiText() ) );
524 
525  return;
526  }
527  }
528 
529  $status = $this->mUpload->performUpload(
530  $this->mComment,
531  $pageText,
532  $this->mWatchthis,
533  $this->getUser(),
534  $changeTags
535  );
536 
537  if ( !$status->isGood() ) {
538  $this->showUploadError( $this->getOutput()->parse( $status->getWikiText() ) );
539 
540  return;
541  }
542 
543  // Success, redirect to description page
544  $this->mUploadSuccessful = true;
545  Hooks::run( 'SpecialUploadComplete', [ &$this ] );
546  $this->getOutput()->redirect( $this->mLocalFile->getTitle()->getFullURL() );
547  }
548 
558  public static function getInitialPageText( $comment = '', $license = '',
559  $copyStatus = '', $source = '', Config $config = null
560  ) {
561  if ( $config === null ) {
562  wfDebug( __METHOD__ . ' called without a Config instance passed to it' );
563  $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
564  }
565 
566  $msg = [];
567  $forceUIMsgAsContentMsg = (array)$config->get( 'ForceUIMsgAsContentMsg' );
568  /* These messages are transcluded into the actual text of the description page.
569  * Thus, forcing them as content messages makes the upload to produce an int: template
570  * instead of hardcoding it there in the uploader language.
571  */
572  foreach ( [ 'license-header', 'filedesc', 'filestatus', 'filesource' ] as $msgName ) {
573  if ( in_array( $msgName, $forceUIMsgAsContentMsg ) ) {
574  $msg[$msgName] = "{{int:$msgName}}";
575  } else {
576  $msg[$msgName] = wfMessage( $msgName )->inContentLanguage()->text();
577  }
578  }
579 
580  if ( $config->get( 'UseCopyrightUpload' ) ) {
581  $licensetxt = '';
582  if ( $license != '' ) {
583  $licensetxt = '== ' . $msg['license-header'] . " ==\n" . '{{' . $license . '}}' . "\n";
584  }
585  $pageText = '== ' . $msg['filedesc'] . " ==\n" . $comment . "\n" .
586  '== ' . $msg['filestatus'] . " ==\n" . $copyStatus . "\n" .
587  "$licensetxt" .
588  '== ' . $msg['filesource'] . " ==\n" . $source;
589  } else {
590  if ( $license != '' ) {
591  $filedesc = $comment == '' ? '' : '== ' . $msg['filedesc'] . " ==\n" . $comment . "\n";
592  $pageText = $filedesc .
593  '== ' . $msg['license-header'] . " ==\n" . '{{' . $license . '}}' . "\n";
594  } else {
595  $pageText = $comment;
596  }
597  }
598 
599  return $pageText;
600  }
601 
614  protected function getWatchCheck() {
615  if ( $this->getUser()->getOption( 'watchdefault' ) ) {
616  // Watch all edits!
617  return true;
618  }
619 
620  $desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
621  if ( $desiredTitleObj instanceof Title && $this->getUser()->isWatched( $desiredTitleObj ) ) {
622  // Already watched, don't change that
623  return true;
624  }
625 
626  $local = wfLocalFile( $this->mDesiredDestName );
627  if ( $local && $local->exists() ) {
628  // We're uploading a new version of an existing file.
629  // No creation, so don't watch it if we're not already.
630  return false;
631  } else {
632  // New page should get watched if that's our option.
633  return $this->getUser()->getOption( 'watchcreations' ) ||
634  $this->getUser()->getOption( 'watchuploads' );
635  }
636  }
637 
644  protected function processVerificationError( $details ) {
645  switch ( $details['status'] ) {
646 
649  $this->showRecoverableUploadError( $this->msg( 'minlength1' )->escaped() );
650  break;
652  $this->showRecoverableUploadError( $this->msg( 'illegalfilename',
653  $details['filtered'] )->parse() );
654  break;
656  $this->showRecoverableUploadError( $this->msg( 'filename-toolong' )->escaped() );
657  break;
659  $this->showRecoverableUploadError( $this->msg( 'filetype-missing' )->parse() );
660  break;
662  $this->showRecoverableUploadError( $this->msg( 'windows-nonascii-filename' )->parse() );
663  break;
664 
667  $this->showUploadError( $this->msg( 'emptyfile' )->escaped() );
668  break;
670  $this->showUploadError( $this->msg( 'largefileserver' )->escaped() );
671  break;
673  $msg = $this->msg( 'filetype-banned-type' );
674  if ( isset( $details['blacklistedExt'] ) ) {
675  $msg->params( $this->getLanguage()->commaList( $details['blacklistedExt'] ) );
676  } else {
677  $msg->params( $details['finalExt'] );
678  }
679  $extensions = array_unique( $this->getConfig()->get( 'FileExtensions' ) );
680  $msg->params( $this->getLanguage()->commaList( $extensions ),
681  count( $extensions ) );
682 
683  // Add PLURAL support for the first parameter. This results
684  // in a bit unlogical parameter sequence, but does not break
685  // old translations
686  if ( isset( $details['blacklistedExt'] ) ) {
687  $msg->params( count( $details['blacklistedExt'] ) );
688  } else {
689  $msg->params( 1 );
690  }
691 
692  $this->showUploadError( $msg->parse() );
693  break;
695  unset( $details['status'] );
696  $code = array_shift( $details['details'] );
697  $this->showUploadError( $this->msg( $code, $details['details'] )->parse() );
698  break;
700  if ( is_array( $details['error'] ) ) { # allow hooks to return error details in an array
701  $args = $details['error'];
702  $error = array_shift( $args );
703  } else {
704  $error = $details['error'];
705  $args = null;
706  }
707 
708  $this->showUploadError( $this->msg( $error, $args )->parse() );
709  break;
710  default:
711  throw new MWException( __METHOD__ . ": Unknown value `{$details['status']}`" );
712  }
713  }
714 
720  protected function unsaveUploadedFile() {
721  if ( !( $this->mUpload instanceof UploadFromStash ) ) {
722  return true;
723  }
724  $success = $this->mUpload->unsaveUploadedFile();
725  if ( !$success ) {
726  $this->getOutput()->showFileDeleteError( $this->mUpload->getTempPath() );
727 
728  return false;
729  } else {
730  return true;
731  }
732  }
733 
734  /*** Functions for formatting warnings ***/
735 
743  public static function getExistsWarning( $exists ) {
744  if ( !$exists ) {
745  return '';
746  }
747 
748  $file = $exists['file'];
749  $filename = $file->getTitle()->getPrefixedText();
750  $warning = '';
751 
752  if ( $exists['warning'] == 'exists' ) {
753  // Exact match
754  $warning = wfMessage( 'fileexists', $filename )->parse();
755  } elseif ( $exists['warning'] == 'page-exists' ) {
756  // Page exists but file does not
757  $warning = wfMessage( 'filepageexists', $filename )->parse();
758  } elseif ( $exists['warning'] == 'exists-normalized' ) {
759  $warning = wfMessage( 'fileexists-extension', $filename,
760  $exists['normalizedFile']->getTitle()->getPrefixedText() )->parse();
761  } elseif ( $exists['warning'] == 'thumb' ) {
762  // Swapped argument order compared with other messages for backwards compatibility
763  $warning = wfMessage( 'fileexists-thumbnail-yes',
764  $exists['thumbFile']->getTitle()->getPrefixedText(), $filename )->parse();
765  } elseif ( $exists['warning'] == 'thumb-name' ) {
766  // Image w/o '180px-' does not exists, but we do not like these filenames
767  $name = $file->getName();
768  $badPart = substr( $name, 0, strpos( $name, '-' ) + 1 );
769  $warning = wfMessage( 'file-thumbnail-no', $badPart )->parse();
770  } elseif ( $exists['warning'] == 'bad-prefix' ) {
771  $warning = wfMessage( 'filename-bad-prefix', $exists['prefix'] )->parse();
772  }
773 
774  return $warning;
775  }
776 
782  public function getDupeWarning( $dupes ) {
783  if ( !$dupes ) {
784  return '';
785  }
786 
787  $gallery = ImageGalleryBase::factory( false, $this->getContext() );
788  $gallery->setShowBytes( false );
789  foreach ( $dupes as $file ) {
790  $gallery->add( $file->getTitle() );
791  }
792 
793  return '<li>' .
794  $this->msg( 'file-exists-duplicate' )->numParams( count( $dupes ) )->parse() .
795  $gallery->toHTML() . "</li>\n";
796  }
797 
798  protected function getGroupName() {
799  return 'media';
800  }
801 
809  public static function rotationEnabled() {
810  $bitmapHandler = new BitmapHandler();
811  return $bitmapHandler->autoRotateEnabled();
812  }
813 }
814 
818 class UploadForm extends HTMLForm {
819  protected $mWatch;
820  protected $mForReUpload;
821  protected $mSessionKey;
823  protected $mDestWarningAck;
824  protected $mDestFile;
825 
826  protected $mComment;
827  protected $mTextTop;
829 
830  protected $mSourceIds;
831 
832  protected $mMaxFileSize = [];
833 
834  protected $mMaxUploadSize = [];
835 
836  public function __construct( array $options = [], IContextSource $context = null ) {
837  if ( $context instanceof IContextSource ) {
838  $this->setContext( $context );
839  }
840 
841  $this->mWatch = !empty( $options['watch'] );
842  $this->mForReUpload = !empty( $options['forreupload'] );
843  $this->mSessionKey = isset( $options['sessionkey'] ) ? $options['sessionkey'] : '';
844  $this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] );
845  $this->mDestWarningAck = !empty( $options['destwarningack'] );
846  $this->mDestFile = isset( $options['destfile'] ) ? $options['destfile'] : '';
847 
848  $this->mComment = isset( $options['description'] ) ?
849  $options['description'] : '';
850 
851  $this->mTextTop = isset( $options['texttop'] )
852  ? $options['texttop'] : '';
853 
854  $this->mTextAfterSummary = isset( $options['textaftersummary'] )
855  ? $options['textaftersummary'] : '';
856 
857  $sourceDescriptor = $this->getSourceSection();
858  $descriptor = $sourceDescriptor
859  + $this->getDescriptionSection()
860  + $this->getOptionsSection();
861 
862  Hooks::run( 'UploadFormInitDescriptor', [ &$descriptor ] );
863  parent::__construct( $descriptor, $context, 'upload' );
864 
865  # Add a link to edit MediaWik:Licenses
866  if ( $this->getUser()->isAllowed( 'editinterface' ) ) {
867  $this->getOutput()->addModuleStyles( 'mediawiki.special' );
868  $licensesLink = Linker::linkKnown(
869  $this->msg( 'licenses' )->inContentLanguage()->getTitle(),
870  $this->msg( 'licenses-edit' )->escaped(),
871  [],
872  [ 'action' => 'edit' ]
873  );
874  $editLicenses = '<p class="mw-upload-editlicenses">' . $licensesLink . '</p>';
875  $this->addFooterText( $editLicenses, 'description' );
876  }
877 
878  # Set some form properties
879  $this->setSubmitText( $this->msg( 'uploadbtn' )->text() );
880  $this->setSubmitName( 'wpUpload' );
881  # Used message keys: 'accesskey-upload', 'tooltip-upload'
882  $this->setSubmitTooltip( 'upload' );
883  $this->setId( 'mw-upload-form' );
884 
885  # Build a list of IDs for javascript insertion
886  $this->mSourceIds = [];
887  foreach ( $sourceDescriptor as $field ) {
888  if ( !empty( $field['id'] ) ) {
889  $this->mSourceIds[] = $field['id'];
890  }
891  }
892  }
893 
900  protected function getSourceSection() {
901  if ( $this->mSessionKey ) {
902  return [
903  'SessionKey' => [
904  'type' => 'hidden',
905  'default' => $this->mSessionKey,
906  ],
907  'SourceType' => [
908  'type' => 'hidden',
909  'default' => 'Stash',
910  ],
911  ];
912  }
913 
914  $canUploadByUrl = UploadFromUrl::isEnabled()
915  && ( UploadFromUrl::isAllowed( $this->getUser() ) === true )
916  && $this->getConfig()->get( 'CopyUploadsFromSpecialUpload' );
917  $radio = $canUploadByUrl;
918  $selectedSourceType = strtolower( $this->getRequest()->getText( 'wpSourceType', 'File' ) );
919 
920  $descriptor = [];
921  if ( $this->mTextTop ) {
922  $descriptor['UploadFormTextTop'] = [
923  'type' => 'info',
924  'section' => 'source',
925  'default' => $this->mTextTop,
926  'raw' => true,
927  ];
928  }
929 
930  $this->mMaxUploadSize['file'] = min(
933  );
934 
935  $help = $this->msg( 'upload-maxfilesize',
936  $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['file'] )
937  )->parse();
938 
939  // If the user can also upload by URL, there are 2 different file size limits.
940  // This extra message helps stress which limit corresponds to what.
941  if ( $canUploadByUrl ) {
942  $help .= $this->msg( 'word-separator' )->escaped();
943  $help .= $this->msg( 'upload_source_file' )->parse();
944  }
945 
946  $descriptor['UploadFile'] = [
947  'class' => 'UploadSourceField',
948  'section' => 'source',
949  'type' => 'file',
950  'id' => 'wpUploadFile',
951  'radio-id' => 'wpSourceTypeFile',
952  'label-message' => 'sourcefilename',
953  'upload-type' => 'File',
954  'radio' => &$radio,
955  'help' => $help,
956  'checked' => $selectedSourceType == 'file',
957  ];
958 
959  if ( $canUploadByUrl ) {
960  $this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize( 'url' );
961  $descriptor['UploadFileURL'] = [
962  'class' => 'UploadSourceField',
963  'section' => 'source',
964  'id' => 'wpUploadFileURL',
965  'radio-id' => 'wpSourceTypeurl',
966  'label-message' => 'sourceurl',
967  'upload-type' => 'url',
968  'radio' => &$radio,
969  'help' => $this->msg( 'upload-maxfilesize',
970  $this->getContext()->getLanguage()->formatSize( $this->mMaxUploadSize['url'] )
971  )->parse() .
972  $this->msg( 'word-separator' )->escaped() .
973  $this->msg( 'upload_source_url' )->parse(),
974  'checked' => $selectedSourceType == 'url',
975  ];
976  }
977  Hooks::run( 'UploadFormSourceDescriptors', [ &$descriptor, &$radio, $selectedSourceType ] );
978 
979  $descriptor['Extensions'] = [
980  'type' => 'info',
981  'section' => 'source',
982  'default' => $this->getExtensionsMessage(),
983  'raw' => true,
984  ];
985 
986  return $descriptor;
987  }
988 
994  protected function getExtensionsMessage() {
995  # Print a list of allowed file extensions, if so configured. We ignore
996  # MIME type here, it's incomprehensible to most people and too long.
997  $config = $this->getConfig();
998 
999  if ( $config->get( 'CheckFileExtensions' ) ) {
1000  $fileExtensions = array_unique( $config->get( 'FileExtensions' ) );
1001  if ( $config->get( 'StrictFileExtensions' ) ) {
1002  # Everything not permitted is banned
1003  $extensionsList =
1004  '<div id="mw-upload-permitted">' .
1005  $this->msg( 'upload-permitted' )
1006  ->params( $this->getLanguage()->commaList( $fileExtensions ) )
1007  ->numParams( count( $fileExtensions ) )
1008  ->parseAsBlock() .
1009  "</div>\n";
1010  } else {
1011  # We have to list both preferred and prohibited
1012  $fileBlacklist = array_unique( $config->get( 'FileBlacklist' ) );
1013  $extensionsList =
1014  '<div id="mw-upload-preferred">' .
1015  $this->msg( 'upload-preferred' )
1016  ->params( $this->getLanguage()->commaList( $fileExtensions ) )
1017  ->numParams( count( $fileExtensions ) )
1018  ->parseAsBlock() .
1019  "</div>\n" .
1020  '<div id="mw-upload-prohibited">' .
1021  $this->msg( 'upload-prohibited' )
1022  ->params( $this->getLanguage()->commaList( $fileBlacklist ) )
1023  ->numParams( count( $fileBlacklist ) )
1024  ->parseAsBlock() .
1025  "</div>\n";
1026  }
1027  } else {
1028  # Everything is permitted.
1029  $extensionsList = '';
1030  }
1031 
1032  return $extensionsList;
1033  }
1034 
1041  protected function getDescriptionSection() {
1042  $config = $this->getConfig();
1043  if ( $this->mSessionKey ) {
1044  $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $this->getUser() );
1045  try {
1046  $file = $stash->getFile( $this->mSessionKey );
1047  } catch ( Exception $e ) {
1048  $file = null;
1049  }
1050  if ( $file ) {
1052 
1053  $mto = $file->transform( [ 'width' => 120 ] );
1054  if ( $mto ) {
1055  $this->addHeaderText(
1056  '<div class="thumb t' . $wgContLang->alignEnd() . '">' .
1057  Html::element( 'img', [
1058  'src' => $mto->getUrl(),
1059  'class' => 'thumbimage',
1060  ] ) . '</div>', 'description' );
1061  }
1062  }
1063  }
1064 
1065  $descriptor = [
1066  'DestFile' => [
1067  'type' => 'text',
1068  'section' => 'description',
1069  'id' => 'wpDestFile',
1070  'label-message' => 'destfilename',
1071  'size' => 60,
1072  'default' => $this->mDestFile,
1073  # @todo FIXME: Hack to work around poor handling of the 'default' option in HTMLForm
1074  'nodata' => strval( $this->mDestFile ) !== '',
1075  ],
1076  'UploadDescription' => [
1077  'type' => 'textarea',
1078  'section' => 'description',
1079  'id' => 'wpUploadDescription',
1080  'label-message' => $this->mForReUpload
1081  ? 'filereuploadsummary'
1082  : 'fileuploadsummary',
1083  'default' => $this->mComment,
1084  'cols' => $this->getUser()->getIntOption( 'cols' ),
1085  'rows' => 8,
1086  ]
1087  ];
1088  if ( $this->mTextAfterSummary ) {
1089  $descriptor['UploadFormTextAfterSummary'] = [
1090  'type' => 'info',
1091  'section' => 'description',
1092  'default' => $this->mTextAfterSummary,
1093  'raw' => true,
1094  ];
1095  }
1096 
1097  $descriptor += [
1098  'EditTools' => [
1099  'type' => 'edittools',
1100  'section' => 'description',
1101  'message' => 'edittools-upload',
1102  ]
1103  ];
1104 
1105  if ( $this->mForReUpload ) {
1106  $descriptor['DestFile']['readonly'] = true;
1107  } else {
1108  $descriptor['License'] = [
1109  'type' => 'select',
1110  'class' => 'Licenses',
1111  'section' => 'description',
1112  'id' => 'wpLicense',
1113  'label-message' => 'license',
1114  ];
1115  }
1116 
1117  if ( $config->get( 'UseCopyrightUpload' ) ) {
1118  $descriptor['UploadCopyStatus'] = [
1119  'type' => 'text',
1120  'section' => 'description',
1121  'id' => 'wpUploadCopyStatus',
1122  'label-message' => 'filestatus',
1123  ];
1124  $descriptor['UploadSource'] = [
1125  'type' => 'text',
1126  'section' => 'description',
1127  'id' => 'wpUploadSource',
1128  'label-message' => 'filesource',
1129  ];
1130  }
1131 
1132  return $descriptor;
1133  }
1134 
1141  protected function getOptionsSection() {
1142  $user = $this->getUser();
1143  if ( $user->isLoggedIn() ) {
1144  $descriptor = [
1145  'Watchthis' => [
1146  'type' => 'check',
1147  'id' => 'wpWatchthis',
1148  'label-message' => 'watchthisupload',
1149  'section' => 'options',
1150  'default' => $this->mWatch,
1151  ]
1152  ];
1153  }
1154  if ( !$this->mHideIgnoreWarning ) {
1155  $descriptor['IgnoreWarning'] = [
1156  'type' => 'check',
1157  'id' => 'wpIgnoreWarning',
1158  'label-message' => 'ignorewarnings',
1159  'section' => 'options',
1160  ];
1161  }
1162 
1163  $descriptor['DestFileWarningAck'] = [
1164  'type' => 'hidden',
1165  'id' => 'wpDestFileWarningAck',
1166  'default' => $this->mDestWarningAck ? '1' : '',
1167  ];
1168 
1169  if ( $this->mForReUpload ) {
1170  $descriptor['ForReUpload'] = [
1171  'type' => 'hidden',
1172  'id' => 'wpForReUpload',
1173  'default' => '1',
1174  ];
1175  }
1176 
1177  return $descriptor;
1178  }
1179 
1183  public function show() {
1184  $this->addUploadJS();
1185  parent::show();
1186  }
1187 
1191  protected function addUploadJS() {
1192  $config = $this->getConfig();
1193 
1194  $useAjaxDestCheck = $config->get( 'UseAjax' ) && $config->get( 'AjaxUploadDestCheck' );
1195  $useAjaxLicensePreview = $config->get( 'UseAjax' ) &&
1196  $config->get( 'AjaxLicensePreview' ) && $config->get( 'EnableAPI' );
1197  $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize();
1198 
1199  $scriptVars = [
1200  'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
1201  'wgAjaxLicensePreview' => $useAjaxLicensePreview,
1202  'wgUploadAutoFill' => !$this->mForReUpload &&
1203  // If we received mDestFile from the request, don't autofill
1204  // the wpDestFile textbox
1205  $this->mDestFile === '',
1206  'wgUploadSourceIds' => $this->mSourceIds,
1207  'wgCheckFileExtensions' => $config->get( 'CheckFileExtensions' ),
1208  'wgStrictFileExtensions' => $config->get( 'StrictFileExtensions' ),
1209  'wgFileExtensions' => array_values( array_unique( $config->get( 'FileExtensions' ) ) ),
1210  'wgCapitalizeUploads' => MWNamespace::isCapitalized( NS_FILE ),
1211  'wgMaxUploadSize' => $this->mMaxUploadSize,
1212  'wgFileCanRotate' => SpecialUpload::rotationEnabled(),
1213  ];
1214 
1215  $out = $this->getOutput();
1216  $out->addJsConfigVars( $scriptVars );
1217 
1218  $out->addModules( [
1219  'mediawiki.action.edit', // For <charinsert> support
1220  'mediawiki.special.upload', // Extras for thumbnail and license preview.
1221  ] );
1222  }
1223 
1229  function trySubmit() {
1230  return false;
1231  }
1232 }
1233 
1238 
1243  function getLabelHtml( $cellAttributes = [] ) {
1244  $id = $this->mParams['id'];
1245  $label = Html::rawElement( 'label', [ 'for' => $id ], $this->mLabel );
1246 
1247  if ( !empty( $this->mParams['radio'] ) ) {
1248  if ( isset( $this->mParams['radio-id'] ) ) {
1249  $radioId = $this->mParams['radio-id'];
1250  } else {
1251  // Old way. For the benefit of extensions that do not define
1252  // the 'radio-id' key.
1253  $radioId = 'wpSourceType' . $this->mParams['upload-type'];
1254  }
1255 
1256  $attribs = [
1257  'name' => 'wpSourceType',
1258  'type' => 'radio',
1259  'id' => $radioId,
1260  'value' => $this->mParams['upload-type'],
1261  ];
1262 
1263  if ( !empty( $this->mParams['checked'] ) ) {
1264  $attribs['checked'] = 'checked';
1265  }
1266 
1267  $label .= Html::element( 'input', $attribs );
1268  }
1269 
1270  return Html::rawElement( 'td', [ 'class' => 'mw-label' ] + $cellAttributes, $label );
1271  }
1272 
1276  function getSize() {
1277  return isset( $this->mParams['size'] )
1278  ? $this->mParams['size']
1279  : 60;
1280  }
1281 }
setContext(IContextSource $context)
Set the IContextSource object.
static getExistsWarning($exists)
Formats a result of UploadBase::getExistsWarning as HTML This check is static and can be done pre-upl...
getExtensionsMessage()
Get the messages indicating which extensions are preferred and prohibitted.
getDupeWarning($dupes)
Construct a warning and a gallery from an array of duplicate files.
static rotationEnabled()
Should we rotate images in the preview on Special:Upload.
Interface for objects which can provide a MediaWiki context on request.
exists($flags=0)
Check if page exists.
Definition: Title.php:4270
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:762
getOptionsSection()
Get the descriptor of the fieldset that contains the upload options, such as "watch this file"...
const FILENAME_TOO_LONG
Definition: UploadBase.php:71
the array() calling protocol came about after MediaWiki 1.4rc1.
getLanguage()
Get the Language object.
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known', 'noclasses'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
$context
Definition: load.php:44
getContext()
Gets the context this SpecialPage is executed in.
Implements uploading from previously stored file.
getWatchCheck()
See if we should check the 'watch this page' checkbox on the form based on the user's preferences and...
$success
static createFromRequest(&$request, $type=null)
Create a form of UploadBase depending on wpSourceType and initializes it.
Definition: UploadBase.php:152
static isAllowed($user)
Returns true if the user can use this upload module or else a string identifying the missing permissi...
Definition: UploadBase.php:122
UploadBase $mUpload
static getTitleFor($name, $subpage=false, $fragment= '')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:75
setId($id)
Definition: HTMLForm.php:1339
showUploadForm($form)
Show the main upload form.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
Definition: hooks.txt:1932
setSubmitName($name)
Definition: HTMLForm.php:1272
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:210
setSubmitTooltip($name)
Definition: HTMLForm.php:1283
An IContextSource implementation which will inherit context from another source but allow individual ...
LocalFile $mLocalFile
$comment
addHeaderText($msg, $section=null)
Add HTML to the header, inside the form.
Definition: HTMLForm.php:714
null for the local wiki Added in
Definition: hooks.txt:1418
$source
execute($par)
Special page entry point.
A form field that contains a radio box in the label.
bool $mForReUpload
The user followed an "overwrite this file" link.
showViewDeletedLinks()
Shows the "view X deleted revivions link"".
msg()
Wrapper around wfMessage that sets the current context.
unsaveUploadedFile()
Remove a temporarily kept file stashed by saveTempUploadedFile().
getOutput()
Get the OutputPage being used for this instance.
const ILLEGAL_FILENAME
Definition: UploadBase.php:63
Represents a title within MediaWiki.
Definition: Title.php:34
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
IContextSource $context
wfLocalFile($title)
Get an object referring to a locally registered file.
bool $mUploadSuccessful
Subclasses can use this to determine whether a file was uploaded.
addHelpLink($to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
static getMaxUploadSize($forType=null)
Get the MediaWiki maximum uploaded file size for given type of upload, based on $wgMaxUploadSize.
static showLogExtract(&$out, $types=[], $page= '', $user= '', $param=[])
Show log extract.
outputHeader($summaryMessageKey= '')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
if($line===false) $args
Definition: cdb.php:64
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:2581
__construct($request=null)
Constructor : initialise object Get data POSTed through the form and assign them to the object...
userCanExecute(User $user)
This page can be shown if uploading is enabled.
static isCapitalized($index)
Is the namespace first-letter capitalized?
getRequest()
Get the WebRequest object.
static factory($mode=false, IContextSource $context=null)
Get a new image gallery.
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:1798
getLabelHtml($cellAttributes=[])
static isThrottled($user)
Returns true if the user has surpassed the upload rate limit, false otherwise.
Definition: UploadBase.php:138
setSubmitText($t)
Set the text for the submit button.
Definition: HTMLForm.php:1220
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Parent class for all special pages.
Definition: SpecialPage.php:36
static isEnabled()
Checks if the upload from URL feature is enabled.
string $mDesiredDestName
User input variables from the "description" section.
addUploadJS()
Add upload JS to the OutputPage.
An error page which can definitely be safely rendered using the OutputPage.
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:1004
processVerificationError($details)
Provides output to the user for a result of UploadBase::verifyUpload.
getSourceSection()
Get the descriptor of the fieldset that contains the file source selection.
static singleton()
Get a RepoGroup instance.
Definition: RepoGroup.php:59
Form for handling uploads and special page.
$uploadFormTextTop
Text injection points for hooks not using HTMLForm.
getTitle()
Get the title.
Definition: HTMLForm.php:1422
getConfig()
Get the Config object.
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 unsetoffset-wrap String Wrap the message in html(usually something like"&lt
getContext()
Get the base IContextSource object.
getTitle($subpage=false)
Get a self-referential title object.
static getInitialPageText($comment= '', $license= '', $copyStatus= '', $source= '', Config $config=null)
Get the initial image page text based on a comment and optional file status information.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
Object handling generic submission, CSRF protection, layout and other logic for UI forms...
Definition: HTMLForm.php:123
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:548
WebRequest FauxRequest $mRequest
Misc variables.
const FILE_TOO_LARGE
Definition: UploadBase.php:69
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
Using a hook running we can avoid having all this option specific stuff in our mainline code Using hooks
Definition: hooks.txt:73
const MIN_LENGTH_PARTNAME
Definition: UploadBase.php:62
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
$help
Definition: mcc.php:32
const NS_FILE
Definition: Defines.php:75
Show an error when the user tries to do something whilst blocked.
const VERIFICATION_ERROR
Definition: UploadBase.php:67
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
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:762
static isEnabled()
Returns true if uploads are enabled.
Definition: UploadBase.php:103
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
showUploadError($message)
Show the upload form with error message, but do not stash the file.
const FILETYPE_BADTYPE
Definition: UploadBase.php:66
const FILETYPE_MISSING
Definition: UploadBase.php:65
__construct(array $options=[], IContextSource $context=null)
static getDefaultInstance()
static isAllowed($user)
Checks if the user is allowed to use the upload-by-URL feature.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$mIgnoreWarning
User input variables from the root section.
loadRequest()
Initialize instance variables from request and create an Upload handler.
getDescriptionSection()
Get the descriptor of the fieldset that contains the file description input.
const HOOK_ABORTED
Definition: UploadBase.php:68
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2418
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
getUser()
Shortcut to get the User executing this instance.
getConfig()
Shortcut to get main config object.
$license
Show an error when a user tries to do something they do not have the necessary permissions for...
const WINDOWS_NONASCII_FILENAME
Definition: UploadBase.php:70
getLanguage()
Shortcut to get user's language.
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:56
Generic handler for bitmap images.
Definition: Bitmap.php:29
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:1004
$count
static getMaxPhpUploadSize()
Get the PHP maximum uploaded file size, based on ini settings.
showRecoverableUploadError($message)
Stashes the upload and shows the main upload form.
bool $mCancelUpload
The user clicked "Cancel and return to upload form" button.
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...
Definition: ChangeTags.php:378
addFooterText($msg, $section=null)
Add footer text, inside the form.
Definition: HTMLForm.php:769
processUpload()
Do the upload.
$extensions
getRequest()
Get the WebRequest being used for this instance.
const OK
Definition: UploadBase.php:60
$mDestWarningAck
Hidden variables.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:230
showUploadWarning($warnings)
Stashes the upload, shows the main form, but adds a "continue anyway button".
Sub class of HTMLForm that provides the form section of SpecialUpload.
getUser()
Get the User object.
const EMPTY_FILE
Definition: UploadBase.php:61
static & makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:524
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:1798
trySubmit()
Empty function; submission is handled elsewhere.
show()
Add the upload JS and show the form.
getUploadForm($message= '', $sessionKey= '', $hideIgnoreWarning=false)
Get an UploadForm instance with title and text properly set.
getPageTitle($subpage=false)
Get a self-referential title object.
getOutput()
Get the OutputPage object.
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310