* Allow string to be passed to showUploadForm to make porting old extensions easier
[lhc/web/wiklou.git] / includes / specials / SpecialUpload.php
index d3aeeb9..85f2b1a 100644 (file)
@@ -30,10 +30,10 @@ class SpecialUpload extends SpecialPage {
        protected $mUploadClicked;
 
        /** User input variables from the "description" section **/
-       protected $mDesiredDestName;    // The requested target file name
+       public    $mDesiredDestName;    // The requested target file name
        protected $mComment;
        protected $mLicense;
-
+       
        /** User input variables from the root section **/
        protected $mIgnoreWarning;
        protected $mWatchThis;
@@ -41,9 +41,16 @@ class SpecialUpload extends SpecialPage {
        protected $mCopyrightSource;
 
        /** Hidden variables **/
+       protected $mDestWarningAck;
        protected $mForReUpload;                // The user followed an "overwrite this file" link
        protected $mCancelUpload;               // The user clicked "Cancel and return to upload form" button
        protected $mTokenOk;
+       protected $mUploadSuccessful = false;   // Subclasses can use this to determine whether a file was uploaded
+       
+       /** Text injection points for hooks not using HTMLForm **/
+       public $uploadFormTextTop;
+       public $uploadFormTextAfterSummary;
+       
 
        /**
         * Initialize instance variables from request and create an Upload handler
@@ -56,7 +63,9 @@ class SpecialUpload extends SpecialPage {
                $this->mRequest = $request;
                $this->mSourceType        = $request->getVal( 'wpSourceType', 'file' );
                $this->mUpload            = UploadBase::createFromRequest( $request );
-               $this->mUploadClicked     = $request->getCheck( 'wpUpload' ) && $request->wasPosted();
+               $this->mUploadClicked     = $request->wasPosted() 
+                       && ( $request->getCheck( 'wpUpload' ) 
+                               || $request->getCheck( 'wpUploadIgnoreWarning' ) );
 
                // Guess the desired name from the filename if not provided
                $this->mDesiredDestName   = $request->getText( 'wpDestFile' );
@@ -66,8 +75,10 @@ class SpecialUpload extends SpecialPage {
                $this->mLicense           = $request->getText( 'wpLicense' );
 
 
-               $this->mIgnoreWarning     = $request->getCheck( 'wpIgnoreWarning' );
-               $this->mWatchthis         = $request->getBool( 'wpWatchthis' );
+               $this->mDestWarningAck    = $request->getText( 'wpDestFileWarningAck' );
+               $this->mIgnoreWarning     = $request->getCheck( 'wpIgnoreWarning' )
+                       || $request->getCheck( 'wpUploadIgnoreWarning' );
+               $this->mWatchthis         = $request->getBool( 'wpWatchthis' ) && $wgUser->isLoggedIn();
                $this->mCopyrightStatus   = $request->getText( 'wpUploadCopyStatus' );
                $this->mCopyrightSource   = $request->getText( 'wpUploadSource' );
 
@@ -86,6 +97,9 @@ class SpecialUpload extends SpecialPage {
                } else {
                        $this->mTokenOk = $wgUser->matchEditToken( $token );
                }
+               
+               $this->uploadFormTextTop = '';
+               $this->uploadFormTextAfterSummary = '';
        }
 
        /**
@@ -152,6 +166,13 @@ class SpecialUpload extends SpecialPage {
                                && ( $this->mUpload && $this->mUploadClicked ) ) {
                        $this->processUpload();
                } else {
+                       # Backwards compatibility hook
+                       if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
+                       {
+                               wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
+                               return;
+                       }
+                       
                        $this->showUploadForm( $this->getUploadForm() );
                }
 
@@ -161,18 +182,23 @@ class SpecialUpload extends SpecialPage {
        }
 
        /**
-        * Show the main upload form and optionally add the session key to the
-        * output. This hides the source selection.
+        * Show the main upload form 
         *
-        * @param string $message HTML message to be shown at top of form
-        * @param string $sessionKey Session key of the stashed upload
+        * @param mixed $form An HTMLForm instance or HTML string to show
         */
        protected function showUploadForm( $form ) {
                # Add links if file was previously deleted
-               if ( !$this->mDesiredDestName )
+               if ( !$this->mDesiredDestName ) {
                        $this->showViewDeletedLinks();
-
-               $form->show();
+               }
+               
+               if ( $form instanceof HTMLForm ) {
+                       $form->show();
+               } else {
+                       global $wgOut;
+                       $wgOut->addHTML( $form );
+               }
+               
        }
 
        /**
@@ -182,42 +208,65 @@ class SpecialUpload extends SpecialPage {
         * @param string $sessionKey Session key in case this is a stashed upload
         * @return UploadForm
         */
-       protected function getUploadForm( $message = '', $sessionKey = '' ) {
+       protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) {
+               global $wgOut;
+               
                # Initialize form
-               $form = new UploadForm( $this->watchCheck(), $this->mForReUpload, $sessionKey );
+               $form = new UploadForm( array(
+                       'watch' => $this->getWatchCheck(), 
+                       'forreupload' => $this->mForReUpload, 
+                       'sessionkey' => $sessionKey,
+                       'hideignorewarning' => $hideIgnoreWarning,
+                       'destwarningack' => (bool)$this->mDestWarningAck,
+                       
+                       'texttop' => $this->uploadFormTextTop,
+                       'textaftersummary' => $this->uploadFormTextAfterSummary,
+               ) );
                $form->setTitle( $this->getTitle() );
 
                # Check the token, but only if necessary
                if( !$this->mTokenOk && !$this->mCancelUpload
-                               && ( $this->mUpload && $this->mUploadClicked ) )
+                               && ( $this->mUpload && $this->mUploadClicked ) ) {
                        $form->addPreText( wfMsgExt( 'session_fail_preview', 'parseinline' ) );
+               }
 
                # Add text to form
                $form->addPreText( '<div id="uploadtext">' . wfMsgExt( 'uploadtext', 'parse' ) . '</div>');
                # Add upload error message
                $form->addPreText( $message );
+               
+               # Add footer to form
+               $uploadFooter = wfMsgNoTrans( 'uploadfooter' );
+               if ( $uploadFooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadFooter ) ) {
+                       $form->addPostText( '<div id="mw-upload-footer-message">'
+                               . $wgOut->parse( $uploadFooter ) . "</div>\n" );
+               }
+               
+               return $form;           
 
-               return $form;
        }
 
        /**
-        * TODO: DOCUMENT
+        * Shows the "view X deleted revivions link""
         */
        protected function showViewDeletedLinks() {
                global $wgOut, $wgUser;
 
                $title = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
                // Show a subtitle link to deleted revisions (to sysops et al only)
-               if( $title instanceof Title && ( $count = $title->isDeleted() ) > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
-                       $link = wfMsgExt(
-                               $wgUser->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted',
-                               array( 'parse', 'replaceafter' ),
-                               $wgUser->getSkin()->linkKnown(
-                                       SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ),
-                                       wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
-                               )
-                       );
-                       $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
+               if( $title instanceof Title ) {
+                       $count = $title->isDeleted();
+                       if ( $count > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) {
+                               $link = wfMsgExt(
+                                       $wgUser->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted',
+                                       array( 'parse', 'replaceafter' ),
+                                       $wgUser->getSkin()->linkKnown(
+                                               SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ),
+                                               wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count )
+                                       )
+                               );
+                               $wgOut->addHTML( "<div id=\"contentSub2\">{$link}</div>" );
+                       }
                }
 
                // Show the relevant lines from deletion log (for still deleted files only)
@@ -237,20 +286,32 @@ class SpecialUpload extends SpecialPage {
         *
         * @param string $message HTML message to be passed to mainUploadForm
         */
-       protected function recoverableUploadError( $message ) {
+       protected function showRecoverableUploadError( $message ) {
                $sessionKey = $this->mUpload->stashSession();
                $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
                        '<div class="error">' . $message . "</div>\n";
-               $this->showUploadForm( $this->getUploadForm( $message, $sessionKey ) );
+               
+               $form = $this->getUploadForm( $message, $sessionKey );
+               $form->setSubmitText( wfMsg( 'upload-tryagain' ) );
+               $this->showUploadForm( $form );
        }
        /**
-        * Stashes the upload, shows the main form, but adds an "continue anyway button"
+        * Stashes the upload, shows the main form, but adds an "continue anyway button".
+        * Also checks whether there are actually warnings to display.
         *
         * @param array $warnings
+        * @return boolean true if warnings were displayed, false if there are no 
+        *      warnings and the should continue processing like there was no warning
         */
-       protected function uploadWarning( $warnings ) {
+       protected function showUploadWarning( $warnings ) {
                global $wgUser;
 
+               # If there are no warnings, or warnings we can ignore, return early
+               if ( !$warnings || ( count( $warnings ) == 1 && 
+                                isset( $warnings['exists']) && $this->mDestWarningAck ) ) {
+                       return false;                                   
+               }
+
                $sessionKey = $this->mUpload->stashSession();
 
                $sk = $wgUser->getSkin();
@@ -260,7 +321,7 @@ class SpecialUpload extends SpecialPage {
                foreach( $warnings as $warning => $args ) {
                                $msg = '';
                                if( $warning == 'exists' ) {
-                                       $msg = self::getExistsWarning( $args );
+                                       $msg = "\t<li>" . self::getExistsWarning( $args ) . "</li>\n";
                                } elseif( $warning == 'duplicate' ) {
                                        $msg = self::getDupeWarning( $args );
                                } elseif( $warning == 'duplicate-archive' ) {
@@ -268,7 +329,7 @@ class SpecialUpload extends SpecialPage {
                                                        array( Title::makeTitle( NS_FILE, $args )->getPrefixedText() ) )
                                                . "</li>\n";
                                } else {
-                                       if ( is_bool( $args ) )
+                                       if ( $args === true )
                                                $args = array();
                                        elseif ( !is_array( $args ) )
                                                $args = array( $args );
@@ -276,13 +337,18 @@ class SpecialUpload extends SpecialPage {
                                }
                                $warningHtml .= $msg;
                }
-               $warningHtml .= '</ul>';
+               $warningHtml .= "</ul>\n";
+               $warningHtml .= wfMsgExt( 'uploadwarning-text', 'parse' );
 
-               $form = $this->getUploadForm( $warningHtml, $sessionKey );
-               $form->setSubmitText( wfMsg( 'ignorewarning' ) );
+               $form = $this->getUploadForm( $warningHtml, $sessionKey, /* $hideIgnoreWarning */ true );
+               $form->setSubmitText( wfMsg( 'upload-tryagain' ) );
+               $form->addButton( 'wpUploadIgnoreWarning', wfMsg( 'ignorewarning' ) );
                $form->addButton( 'wpCancelUpload', wfMsg( 'reuploaddesc' ) );
 
                $this->showUploadForm( $form );
+               
+               # Indicate that we showed a form
+               return true;
        }
 
        /**
@@ -290,7 +356,7 @@ class SpecialUpload extends SpecialPage {
         *
         * @param string $message
         */
-       protected function uploadError( $message ) {
+       protected function showUploadError( $message ) {
                $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
                        '<div class="error">' . $message . "</div>\n";
                $this->showUploadForm( $this->getUploadForm( $message ) );
@@ -305,26 +371,41 @@ class SpecialUpload extends SpecialPage {
 
                // Verify permissions
                $permErrors = $this->mUpload->verifyPermissions( $wgUser );
-               if( $permErrors !== true )
-                       return $wgOut->showPermissionsErrorPage( $permErrors );
+               if( $permErrors !== true ) {
+                       $wgOut->showPermissionsErrorPage( $permErrors );
+                       return;
+               }
 
                // Fetch the file if required
                $status = $this->mUpload->fetchFile();
-               if( !$status->isOK() )
-                       return $this->mainUploadForm( $wgOut->parse( $status->getWikiText() ) );
+               if( !$status->isOK() ) {
+                       $this->showUploadForm( $this->getUploadForm( $wgOut->parse( $status->getWikiText() ) ) );
+                       return;
+               }
+
+               // Deprecated backwards compatibility hook
+               if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
+               {
+                       wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
+                       return array( 'status' => UploadBase::BEFORE_PROCESSING );
+               }
+
 
                // Upload verification
                $details = $this->mUpload->verifyUpload();
-               if ( $details['status'] != UploadBase::OK )
-                       return $this->processVerificationError( $details );
+               if ( $details['status'] != UploadBase::OK ) {
+                       $this->processVerificationError( $details );
+                       return;
+               }
 
                $this->mLocalFile = $this->mUpload->getLocalFile();
 
                // Check warnings if necessary
                if( !$this->mIgnoreWarning ) {
                        $warnings = $this->mUpload->checkWarnings();
-                       if( count( $warnings ) )
-                               return $this->uploadWarning( $warnings );
+                       if( $this->showUploadWarning( $warnings ) ) {
+                               return;
+                       }
                }
 
                // Get the page text if this is not a reupload
@@ -335,10 +416,13 @@ class SpecialUpload extends SpecialPage {
                        $pageText = false;
                }
                $status = $this->mUpload->performUpload( $this->mComment, $pageText, $this->mWatchthis, $wgUser );
-               if ( !$status->isGood() )
-                       return $this->uploadError( $wgOut->parse( $status->getWikiText() ) );
+               if ( !$status->isGood() ) {
+                       $this->showUploadError( $wgOut->parse( $status->getWikiText() ) );
+                       return;
+               }
 
                // Success, redirect to description page
+               $this->mUploadSuccessful = true;
                wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
                $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
 
@@ -381,7 +465,7 @@ class SpecialUpload extends SpecialPage {
         * Note that the page target can be changed *on the form*, so our check
         * state can get out of sync.
         */
-       protected function watchCheck() {
+       protected function getWatchCheck() {
                global $wgUser;
                if( $wgUser->getOption( 'watchdefault' ) ) {
                        // Watch all edits!
@@ -412,28 +496,28 @@ class SpecialUpload extends SpecialPage {
 
                        /** Statuses that only require name changing **/
                        case UploadBase::MIN_LENGTH_PARTNAME:
-                               $this->recoverableUploadError( wfMsgHtml( 'minlength1' ) );
+                               $this->showRecoverableUploadError( wfMsgHtml( 'minlength1' ) );
                                break;
                        case UploadBase::ILLEGAL_FILENAME:
-                               $this->recoverableUploadError( wfMsgExt( 'illegalfilename',
+                               $this->showRecoverableUploadError( wfMsgExt( 'illegalfilename',
                                        'parseinline', $details['filtered'] ) );
                                break;
                        case UploadBase::OVERWRITE_EXISTING_FILE:
-                               $this->recoverableUploadError( wfMsgExt( $details['overwrite'],
+                               $this->showRecoverableUploadError( wfMsgExt( $details['overwrite'],
                                        'parseinline' ) );
                                break;
                        case UploadBase::FILETYPE_MISSING:
-                               $this->recoverableUploadError( wfMsgExt( 'filetype-missing',
+                               $this->showRecoverableUploadError( wfMsgExt( 'filetype-missing',
                                        'parseinline' ) );
                                break;
 
                        /** Statuses that require reuploading **/
                        case UploadBase::EMPTY_FILE:
-                               $this->mainUploadForm( wfMsgHtml( 'emptyfile' ) );
+                               $this->showUploadForm( $this->getUploadForm( wfMsgHtml( 'emptyfile' ) ) );
                                break;
                        case UploadBase::FILETYPE_BADTYPE:
                                $finalExt = $details['finalExt'];
-                               $this->uploadError(
+                               $this->showUploadError(
                                        wfMsgExt( 'filetype-banned-type',
                                                array( 'parseinline' ),
                                                htmlspecialchars( $finalExt ),
@@ -448,11 +532,18 @@ class SpecialUpload extends SpecialPage {
                        case UploadBase::VERIFICATION_ERROR:
                                unset( $details['status'] );
                                $code = array_shift( $details['details'] );
-                               $this->uploadError( wfMsgExt( $code, 'parseinline', $details['details'] ) );
+                               $this->showUploadError( wfMsgExt( $code, 'parseinline', $details['details'] ) );
                                break;
                        case UploadBase::HOOK_ABORTED:
-                               $error = $details['error'];
-                               $this->uploadError( wfMsgExt( $error, 'parseinline' ) );
+                               if ( is_array( $details['error'] ) ) { # allow hooks to return error details in an array
+                                       $args = $details['error'];
+                                       $error = array_shift( $args );
+                               } else {
+                                       $error = $details['error'];
+                                       $args = null;
+                               }
+
+                               $this->showUploadError( wfMsgExt( $error, 'parseinline', $args ) );
                                break;
                        default:
                                throw new MWException( __METHOD__ . ": Unknown value `{$details['status']}`" );
@@ -485,7 +576,6 @@ class SpecialUpload extends SpecialPage {
         *
         * @param array $exists The result of UploadBase::getExistsWarning
         * @return string Empty string if there is no warning or an HTML fragment
-        * consisting of one or more <li> elements if there is a warning.
         */
        public static function getExistsWarning( $exists ) {
                global $wgUser, $wgContLang;
@@ -495,30 +585,30 @@ class SpecialUpload extends SpecialPage {
 
                $file = $exists['file'];
                $filename = $file->getTitle()->getPrefixedText();
-               $warning = array();
+               $warning = '';
 
                $sk = $wgUser->getSkin();
 
                if( $exists['warning'] == 'exists' ) {
                        // Exact match
-                       $warning[] = '<li>' . wfMsgExt( 'fileexists', 'parseinline', $filename ) . '</li>';
+                       $warning = wfMsgExt( 'fileexists', 'parseinline', $filename );
                } elseif( $exists['warning'] == 'page-exists' ) {
                        // Page exists but file does not
-                       $warning[] = '<li>' . wfMsgExt( 'filepageexists', 'parseinline', $filename ) . '</li>';
+                       $warning = wfMsgExt( 'filepageexists', 'parseinline', $filename );
                } elseif ( $exists['warning'] == 'exists-normalized' ) {
-                       $warning[] = '<li>' . wfMsgExt( 'fileexists-extension', 'parseinline', $filename,
-                               $exists['normalizedFile']->getTitle()->getPrefixedText() ) . '</li>';
+                       $warning = wfMsgExt( 'fileexists-extension', 'parseinline', $filename,
+                               $exists['normalizedFile']->getTitle()->getPrefixedText() );
                } elseif ( $exists['warning'] == 'thumb' ) {
                        // Swapped argument order compared with other messages for backwards compatibility
-                       $warning[] = '<li>' . wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline',
-                               $exists['thumbFile']->getTitle()->getPrefixedText(), $filename ) . '</li>';
+                       $warning = wfMsgExt( 'fileexists-thumbnail-yes', 'parseinline',
+                               $exists['thumbFile']->getTitle()->getPrefixedText(), $filename );
                } elseif ( $exists['warning'] == 'thumb-name' ) {
                        // Image w/o '180px-' does not exists, but we do not like these filenames
                        $name = $file->getName();
                        $badPart = substr( $name, 0, strpos( $name, '-' ) + 1 );
-                       $warning[] = '<li>' . wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart ) . '</li>';
+                       $warning = wfMsgExt( 'file-thumbnail-no', 'parseinline', $badPart );
                } elseif ( $exists['warning'] == 'bad-prefix' ) {
-                       $warning[] = '<li>' . wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] ) . '</li>';
+                       $warning = wfMsgExt( 'filename-bad-prefix', 'parseinline', $exists['prefix'] );
                } elseif ( $exists['warning'] == 'was-deleted' ) {
                        # If the file existed before and was deleted, warn the user of this
                        $ltitle = SpecialPage::getTitleFor( 'Log' );
@@ -531,10 +621,10 @@ class SpecialUpload extends SpecialPage {
                                        'page' => $filename
                                )
                        );
-                       $warning[] = '<li>' . wfMsgWikiHtml( 'filewasdeleted', $llink ) . '</li>';
+                       $warning = wfMsgWikiHtml( 'filewasdeleted', $llink );
                }
 
-               return implode( "\n", $warning );
+               return $warning;
        }
 
        /**
@@ -555,31 +645,12 @@ class SpecialUpload extends SpecialPage {
                        $exists = UploadBase::getExistsWarning( $file );
                        $warning = self::getExistsWarning( $exists );
                        if ( $warning !== '' ) {
-                               $s = "<ul>$warning</ul>";
+                               $s = "<div>$warning</div>";
                        }
                }
                return $s;
        }
 
-       /**
-        * Render a preview of a given license for the AJAX preview on upload
-        *
-        * @param string $license
-        * @return string
-        */
-       public static function ajaxGetLicensePreview( $license ) {
-               global $wgParser, $wgUser;
-               $text = '{{' . $license . '}}';
-               $title = Title::makeTitle( NS_FILE, 'Sample.jpg' );
-               $options = ParserOptions::newFromUser( $wgUser );
-
-               // Expand subst: first, then live templates...
-               $text = $wgParser->preSaveTransform( $text, $title, $wgUser, $options );
-               $output = $wgParser->parse( $text, $title, $options );
-
-               return $output->getText();
-       }
-
        /**
         * Construct a warning and a gallery from an array of duplicate files.
         */
@@ -611,21 +682,33 @@ class UploadForm extends HTMLForm {
        protected $mWatch;
        protected $mForReUpload;
        protected $mSessionKey;
+       protected $mHideIgnoreWarning;
+       protected $mDestWarningAck;
+       
+       protected $mTextTop;
+       protected $mTextAfterSummary;
+       
        protected $mSourceIds;
 
-       public function __construct( $watch, $forReUpload = false, $sessionKey = '' ) {
+       public function __construct( $options = array() ) {
                global $wgLang;
 
-               $this->mWatch = $watch;
-               $this->mForReUpload = $forReUpload;
-               $this->mSessionKey = $sessionKey;
+               $this->mWatch = !empty( $options['watch'] );
+               $this->mForReUpload = !empty( $options['forreupload'] );
+               $this->mSessionKey = isset( $options['sessionkey'] ) 
+                               ? $options['sessionkey'] : '';
+               $this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] );
+               $this->mDestWarningAck = !empty( $options['destwarningack'] );
+               
+               $this->mTextTop = $options['texttop'];
+               $this->mTextAfterSummary = $options['textaftersummary'];
 
                $sourceDescriptor = $this->getSourceSection();
                $descriptor = $sourceDescriptor
                        + $this->getDescriptionSection()
                        + $this->getOptionsSection();
 
-               wfRunHooks( 'UploadFormInitDescriptor', array( $descriptor ) );
+               wfRunHooks( 'UploadFormInitDescriptor', array( &$descriptor ) );
                parent::__construct( $descriptor, 'upload' );
 
                # Set some form properties
@@ -644,7 +727,10 @@ class UploadForm extends HTMLForm {
        }
 
        /**
-        *
+        * Get the descriptor of the fieldset that contains the file source 
+        * selection. The section is 'source'
+        * 
+        * @return array Descriptor array
         */
        protected function getSourceSection() {
                global $wgLang, $wgUser, $wgRequest;
@@ -667,6 +753,15 @@ class UploadForm extends HTMLForm {
                $selectedSourceType = strtolower( $wgRequest->getText( 'wpSourceType', 'File' ) );
 
                $descriptor = array();
+               if ( $this->mTextTop ) {
+                       $descriptor['UploadFormTextTop'] = array(
+                               'type' => 'info',
+                               'section' => 'source',
+                               'default' => $this->mTextTop,
+                               'raw' => true,
+                       );
+               }
+               
                $descriptor['UploadFile'] = array(
                                'class' => 'UploadSourceField',
                                'section' => 'source',
@@ -690,7 +785,7 @@ class UploadForm extends HTMLForm {
                                'section' => 'source',
                                'id' => 'wpUploadFileURL',
                                'label-message' => 'sourceurl',
-                               'upload-type' => 'Url',
+                               'upload-type' => 'url',
                                'radio' => &$radio,
                                'help' => wfMsgExt( 'upload-maxfilesize',
                                                array( 'parseinline', 'escapenoentities' ),
@@ -699,7 +794,7 @@ class UploadForm extends HTMLForm {
                                'checked' => $selectedSourceType == 'url',
                        );
                }
-               wfRunHooks( 'UploadFormSourceDescriptors', array( $descriptor, &$radio, $selectedSourceType ) );
+               wfRunHooks( 'UploadFormSourceDescriptors', array( &$descriptor, &$radio, $selectedSourceType ) );
 
                $descriptor['Extensions'] = array(
                        'type' => 'info',
@@ -710,8 +805,11 @@ class UploadForm extends HTMLForm {
                return $descriptor;
        }
 
+
        /**
-        *
+        * Get the messages indicating which extensions are preferred and prohibitted.
+        * 
+        * @return string HTML string containing the message
         */
        protected function getExtensionsMessage() {
                # Print a list of allowed file extensions, if so configured.  We ignore
@@ -745,7 +843,10 @@ class UploadForm extends HTMLForm {
        }
 
        /**
-        *
+        * Get the descriptor of the fieldset that contains the file description
+        * input. The section is 'description'
+        * 
+        * @return array Descriptor array
         */
        protected function getDescriptionSection() {
                global $wgUser, $wgOut;
@@ -772,6 +873,21 @@ class UploadForm extends HTMLForm {
                                        : 'fileuploadsummary',
                                'cols' => $cols,
                                'rows' => 8,
+                       )
+               );
+               if ( $this->mTextAfterSummary ) {
+                       $descriptor['UploadFormTextAfterSummary'] = array(
+                               'type' => 'info',
+                               'section' => 'description',
+                               'default' => $this->mTextAfterSummary,
+                               'raw' => true,
+                       );
+               }
+               
+               $descriptor += array(
+                       'EditTools' => array(
+                               'type' => 'edittools',
+                               'section' => 'description',
                        ),
                        'License' => array(
                                'type' => 'select',
@@ -784,13 +900,6 @@ class UploadForm extends HTMLForm {
                if ( $this->mForReUpload )
                        $descriptor['DestFile']['readonly'] = true;
 
-               global $wgUseAjax, $wgAjaxLicensePreview;
-               if ( $wgUseAjax && $wgAjaxLicensePreview )
-                       $descriptor['AjaxLicensePreview'] = array(
-                               'class' => 'UploadAjaxLicensePreview',
-                               'section' => 'description'
-                       );
-
                global $wgUseCopyrightUpload;
                if ( $wgUseCopyrightUpload ) {
                        $descriptor['UploadCopyStatus'] = array(
@@ -811,44 +920,45 @@ class UploadForm extends HTMLForm {
        }
 
        /**
-        *
+        * Get the descriptor of the fieldset that contains the upload options, 
+        * such as "watch this file". The section is 'options'
+        * 
+        * @return array Descriptor array
         */
        protected function getOptionsSection() {
-               global $wgOut;
+               global $wgUser, $wgOut;
 
-               $descriptor = array(
-                       'Watchthis' => array(
-                               'type' => 'check',
-                               'id' => 'wpWatchthis',
-                               'label-message' => 'watchthisupload',
-                               'section' => 'options',
-                       ),
-                       'IgnoreWarning' => array(
+               if( $wgUser->isLoggedIn() ) {
+                       $descriptor = array(
+                               'Watchthis' => array(
+                                       'type' => 'check',
+                                       'id' => 'wpWatchthis',
+                                       'label-message' => 'watchthisupload',
+                                       'section' => 'options',
+                               )
+                       );
+               }
+               if( !$this->mHideIgnoreWarning ) {
+                       $descriptor['IgnoreWarning'] = array(
                                'type' => 'check',
                                'id' => 'wpIgnoreWarning',
                                'label-message' => 'ignorewarnings',
                                'section' => 'options',
-                       ),
-                       'EditTools' => array(
-                               'type' => 'edittools',
-                               'section' => 'options',
-                       ),
-               );
-
-               $uploadFooter = wfMsgNoTrans( 'uploadfooter' );
-               if ( $uploadFooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadFooter ) )
-                       $descriptor['UploadFooter'] = array(
-                               'type' => 'info',
-                               'id' => 'mw-upload-footer-message',
-                               'default' => $wgOut->parse( $uploadFooter ),
                        );
+               }
+
+               $descriptor['wpDestFileWarningAck'] = array(
+                       'type' => 'hidden',
+                       'id' => 'wpDestFileWarningAck',
+                       'default' => $this->mDestWarningAck ? '1' : '',
+               );
 
                return $descriptor;
 
        }
 
        /**
-        *
+        * Add the upload JS and show the form.
         */
        public function show() {
                $this->addUploadJS();
@@ -856,36 +966,37 @@ class UploadForm extends HTMLForm {
        }
 
        /**
-        *
+        * Add upload JS to $wgOut
+        * 
+        * @param bool $autofill Whether or not to autofill the destination
+        *      filename text box
         */
-       protected function addUploadJS( $autofill = true ) {
-               global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
-               global $wgEnableFirefogg, $wgEnableJS2system;
+       protected function addUploadJS( ) {
+               global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI;
                global $wgOut;
 
                $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
-               $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
+               $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview && $wgEnableAPI;
 
                $scriptVars = array(
-                       'wgAjaxUploadDestCheck' => $wgUseAjax && $wgAjaxUploadDestCheck,
-                       'wgAjaxLicensePreview' => $wgUseAjax && $wgAjaxLicensePreview,
-                       'wgEnableFirefogg' => (bool)$wgEnableFirefogg,
-                       'wgUploadAutoFill' => (bool)$autofill,
+                       'wgAjaxUploadDestCheck' => $useAjaxDestCheck,
+                       'wgAjaxLicensePreview' => $useAjaxLicensePreview,
+                       'wgUploadAutoFill' => !$this->mForReUpload,
                        'wgUploadSourceIds' => $this->mSourceIds,
                );
 
                $wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) );
-
-               if ( $wgEnableJS2system ) {
-                       //js2version of upload page:
-                       $wgOut->addScriptClass( 'uploadPage' );
-               } else {
-                       //legacy upload code:
-                       $wgOut->addScriptFile( 'upload.js' );
-                       $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
-               }
+               
+               // For <charinsert> support
+               $wgOut->addScriptFile( 'edit.js' );
+               $wgOut->addScriptFile( 'upload.js' );
        }
 
+       /**
+        * Empty function; submission is handled elsewhere.
+        * 
+        * @return bool false
+        */
        function trySubmit() {
                return false;
        }
@@ -893,7 +1004,7 @@ class UploadForm extends HTMLForm {
 }
 
 /**
- * TODO: DOCUMENT
+ * A form field that contains a radio box in the label
  */
 class UploadSourceField extends HTMLTextField {
        function getLabelHtml() {
@@ -921,15 +1032,3 @@ class UploadSourceField extends HTMLTextField {
        }
 }
 
-/**
- * TODO: Document
- * TODO: This can be migrated to JS only
- */
-class UploadAjaxLicensePreview extends HTMLFormField {
-       public function getTableRow( $value ) {
-               return "<tr><td></td><td id=\"mw-license-preview\"></td></tr>\n";
-       }
-       public function getInputHTML( $value ) {
-               return '';
-       }
-}
\ No newline at end of file