Beispiel #1
0
 /**
  * There is no need to stash the image twice
  */
 public function stashSession($key = null)
 {
     if (!empty($this->mSessionKey)) {
         return $this->mSessionKey;
     }
     return parent::stashSession();
 }
Beispiel #2
0
 /**
  * Stashes the upload, shows the main form, but adds a "continue anyway button".
  * Also checks whether there are actually warnings to display.
  *
  * @param array $warnings
  * @return bool True if warnings were displayed, false if there are no
  *   warnings and it should continue processing
  */
 protected function showUploadWarning($warnings)
 {
     # If there are no warnings, or warnings we can ignore, return early.
     # mDestWarningAck is set when some javascript has shown the warning
     # to the user. mForReUpload is set when the user clicks the "upload a
     # new version" link.
     if (!$warnings || count($warnings) == 1 && isset($warnings['exists']) && ($this->mDestWarningAck || $this->mForReUpload)) {
         return false;
     }
     $sessionKey = $this->mUpload->stashSession();
     // Add styles for the warning, reused from the live preview
     $this->getOutput()->addModuleStyles('mediawiki.special.upload');
     $warningHtml = '<h2>' . $this->msg('uploadwarning')->escaped() . "</h2>\n" . '<div class="mw-destfile-warning"><ul>';
     foreach ($warnings as $warning => $args) {
         if ($warning == 'badfilename') {
             $this->mDesiredDestName = Title::makeTitle(NS_FILE, $args)->getText();
         }
         if ($warning == 'exists') {
             $msg = "\t<li>" . self::getExistsWarning($args) . "</li>\n";
         } elseif ($warning == 'was-deleted') {
             # If the file existed before and was deleted, warn the user of this
             $ltitle = SpecialPage::getTitleFor('Log');
             $llink = Linker::linkKnown($ltitle, wfMessage('deletionlog')->escaped(), [], ['type' => 'delete', 'page' => Title::makeTitle(NS_FILE, $args)->getPrefixedText()]);
             $msg = "\t<li>" . wfMessage('filewasdeleted')->rawParams($llink)->parse() . "</li>\n";
         } elseif ($warning == 'duplicate') {
             $msg = $this->getDupeWarning($args);
         } elseif ($warning == 'duplicate-archive') {
             if ($args === '') {
                 $msg = "\t<li>" . $this->msg('file-deleted-duplicate-notitle')->parse() . "</li>\n";
             } else {
                 $msg = "\t<li>" . $this->msg('file-deleted-duplicate', Title::makeTitle(NS_FILE, $args)->getPrefixedText())->parse() . "</li>\n";
             }
         } else {
             if ($args === true) {
                 $args = [];
             } elseif (!is_array($args)) {
                 $args = [$args];
             }
             $msg = "\t<li>" . $this->msg($warning, $args)->parse() . "</li>\n";
         }
         $warningHtml .= $msg;
     }
     $warningHtml .= "</ul></div>\n";
     $warningHtml .= $this->msg('uploadwarning-text')->parseAsBlock();
     $form = $this->getUploadForm($warningHtml, $sessionKey, true);
     $form->setSubmitText($this->msg('upload-tryagain')->text());
     $form->addButton(['name' => 'wpUploadIgnoreWarning', 'value' => $this->msg('ignorewarning')->text()]);
     $form->addButton(['name' => 'wpCancelUpload', 'value' => $this->msg('reuploaddesc')->text()]);
     $this->showUploadForm($form);
     # Indicate that we showed a form
     return true;
 }
Beispiel #3
0
	/**
	 * Stashes the upload, shows the main form, but adds a "continue anyway button".
	 * Also checks whether there are actually warnings to display.
	 *
	 * @param $warnings Array
	 * @return boolean true if warnings were displayed, false if there are no
	 *         warnings and it should continue processing
	 */
	protected function showUploadWarning( $warnings ) {
		# If there are no warnings, or warnings we can ignore, return early.
		# mDestWarningAck is set when some javascript has shown the warning
		# to the user. mForReUpload is set when the user clicks the "upload a
		# new version" link.
		if ( !$warnings || ( count( $warnings ) == 1 &&
			isset( $warnings['exists'] ) &&
			( $this->mDestWarningAck || $this->mForReUpload ) ) )
		{
			return false;
		}

		$sessionKey = $this->mUpload->stashSession();

		$warningHtml = '<h2>' . $this->msg( 'uploadwarning' )->escaped() . "</h2>\n"
			. '<ul class="warning">';
		foreach ( $warnings as $warning => $args ) {
			if ( $warning == 'badfilename' ) {
				$this->mDesiredDestName = Title::makeTitle( NS_FILE, $args )->getText();
			}
			if ( $warning == 'exists' ) {
				$msg = "\t<li>" . self::getExistsWarning( $args ) . "</li>\n";
			} elseif ( $warning == 'duplicate' ) {
				$msg = $this->getDupeWarning( $args );
			} elseif ( $warning == 'duplicate-archive' ) {
				$msg = "\t<li>" . $this->msg( 'file-deleted-duplicate',
						Title::makeTitle( NS_FILE, $args )->getPrefixedText() )->parse()
					. "</li>\n";
			} else {
				if ( $args === true ) {
					$args = array();
				} elseif ( !is_array( $args ) ) {
					$args = array( $args );
				}
				$msg = "\t<li>" . $this->msg( $warning, $args )->parse() . "</li>\n";
			}
			$warningHtml .= $msg;
		}
		$warningHtml .= "</ul>\n";
		$warningHtml .= $this->msg( 'uploadwarning-text' )->parseAsBlock();

		$form = $this->getUploadForm( $warningHtml, $sessionKey, /* $hideIgnoreWarning */ true );
		$form->setSubmitText( $this->msg( 'upload-tryagain' )->text() );
		$form->addButton( 'wpUploadIgnoreWarning', $this->msg( 'ignorewarning' )->text() );
		$form->addButton( 'wpCancelUpload', $this->msg( 'reuploaddesc' )->text() );

		$this->showUploadForm( $form );

		# Indicate that we showed a form
		return true;
	}