Lazy initialisation of wgProxyList, no flip required
[lhc/web/wiklou.git] / includes / SpecialUpload.php
index 185700f..9f8b63f 100644 (file)
@@ -55,7 +55,9 @@ class UploadForm {
                $this->mUploadDescription = $request->getText( 'wpUploadDescription' );
                $this->mLicense           = $request->getText( 'wpLicense' );
                $this->mUploadCopyStatus  = $request->getText( 'wpUploadCopyStatus' );
-               $this->mUploadSource      = $request->getText( 'wpUploadSource');
+               $this->mUploadSource      = $request->getText( 'wpUploadSource' );
+               $this->mWatchthis         = $request->getBool( 'wpWatchthis' );
+               wfDebug( "UploadForm: watchthis is: '$this->mWatchthis'\n" );
 
                $this->mAction            = $request->getVal( 'action' );
 
@@ -139,9 +141,7 @@ class UploadForm {
         * @access private
         */
        function processUpload() {
-               global $wgUser, $wgOut, $wgLang, $wgContLang;
-               global $wgUploadDirectory;
-               global $wgUseCopyrightUpload, $wgCheckCopyrightUpload;
+               global $wgUser, $wgOut, $wgUploadDirectory;
 
                /* Check for PHP error if any, requires php 4.2 or newer */
                if ( $this->mUploadError == 1/*UPLOAD_ERR_INI_SIZE*/ ) {
@@ -232,13 +232,27 @@ class UploadForm {
                                return $this->uploadError( $veri->toString() );
                        }
                }
+               
+               /**
+                * Provide an opportunity for extensions to add futher checks
+                */
+               $error = '';
+               if( !wfRunHooks( 'UploadVerification',
+                               array( $this->mUploadSaveName, $this->mUploadTempName, &$error ) ) ) {
+                       return $this->uploadError( $error );
+               }
 
                /**
                 * Check for non-fatal conditions
                 */
                if ( ! $this->mIgnoreWarning ) {
                        $warning = '';
-                       if( $this->mUploadSaveName != ucfirst( $filtered ) ) {
+                       
+                       global $wgCapitalLinks;
+                       if( $wgCapitalLinks ) {
+                               $filtered = ucfirst( $filtered );
+                       }
+                       if( $this->mUploadSaveName != $filtered ) {
                                $warning .=  '<li>'.wfMsgHtml( 'badfilename', htmlspecialchars( $this->mUploadSaveName ) ).'</li>';
                        }
 
@@ -292,7 +306,8 @@ class UploadForm {
                                                        $this->mUploadDescription,
                                                        $this->mLicense,
                                                        $this->mUploadCopyStatus,
-                                                       $this->mUploadSource );
+                                                       $this->mUploadSource,
+                                                       $this->mWatchthis );
 
                        if ( $success ) {
                                $this->showSuccess();
@@ -466,7 +481,7 @@ class UploadForm {
         * @access private
         */
        function uploadWarning( $warning ) {
-               global $wgOut, $wgUser, $wgLang, $wgUploadDirectory, $wgRequest;
+               global $wgOut, $wgUser, $wgUploadDirectory, $wgRequest;
                global $wgUseCopyrightUpload;
 
                $this->mSessionKey = $this->stashSession();
@@ -502,6 +517,7 @@ class UploadForm {
                <input type='hidden' name='wpUploadDescription' value=\"" . htmlspecialchars( $this->mUploadDescription ) . "\" />
                <input type='hidden' name='wpLicense' value=\"" . htmlspecialchars( $this->mLicense ) . "\" />
                <input type='hidden' name='wpDestFile' value=\"" . htmlspecialchars( $this->mDestFile ) . "\" />
+               <input type='hidden' name='wpWatchthis' value=\"" . htmlspecialchars( intval( $this->mWatchthis ) ) . "\" />
        {$copyright}
        <table border='0'>
                <tr>
@@ -529,7 +545,7 @@ class UploadForm {
         * @access private
         */
        function mainUploadForm( $msg='' ) {
-               global $wgOut, $wgUser, $wgLang, $wgUploadDirectory, $wgRequest;
+               global $wgOut, $wgUser, $wgUploadDirectory, $wgRequest;
                global $wgUseCopyrightUpload;
 
                $cols = intval($wgUser->getOption( 'cols' ));
@@ -542,7 +558,9 @@ class UploadForm {
                        $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
                          "<span class='error'>{$msg}</span>\n" );
                }
+               $wgOut->addHTML( '<div id="uploadtext">' );
                $wgOut->addWikiText( wfMsg( 'uploadtext' ) );
+               $wgOut->addHTML( '</div>' );
                $sk = $wgUser->getSkin();
 
 
@@ -562,55 +580,95 @@ class UploadForm {
                $action = $titleObj->escapeLocalURL();
 
                $encDestFile = htmlspecialchars( $this->mDestFile );
-               $source = null;
-
-               if ( $wgUseCopyrightUpload )
-                 {
-                       $source = "
-       <td align='right' nowrap='nowrap'>" . wfMsg ( 'filestatus' ) . ":</td>
-       <td><input tabindex='3' type='text' name=\"wpUploadCopyStatus\" value=\"" .
-       htmlspecialchars($this->mUploadCopyStatus). "\" size='40' /></td>
-       </tr><tr>
-       <td align='right'>". wfMsg ( 'filesource' ) . ":</td>
-       <td><input tabindex='4' type='text' name='wpUploadSource' value=\"" .
-       htmlspecialchars($this->mUploadSource). "\" size='40' /></td>
-       " ;
-                 }
 
+               $watchChecked = $wgUser->getOption( 'watchdefault' )
+                       ? 'checked="checked"'
+                       : '';
+               
                $wgOut->addHTML( "
        <form id='upload' method='post' enctype='multipart/form-data' action=\"$action\">
-       <table border='0'><tr>
-
-       <td align='right'>{$sourcefilename}:</td><td align='left'>
-       <input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " . ($this->mDestFile?"":"onchange='fillDestFilename()' ") . "size='40' />
-       </td></tr><tr>
-
-       <td align='right'>{$destfilename}:</td><td align='left'>
-       <input tabindex='1' type='text' name='wpDestFile' id='wpDestFile' size='40' value=\"$encDestFile\" />
-       </td></tr><tr>
-
-       <td align='right'>{$summary}</td><td align='left'>
-       <textarea tabindex='2' name='wpUploadDescription' rows='6' cols='{$cols}'{$ew}>"        
-         . htmlspecialchars( $this->mUploadDescription ) .
-       "</textarea>
-       </td></tr><tr>" );
+               <table border='0'>
+               <tr>
+                       <td align='right'><label for='wpUploadFile'>{$sourcefilename}:</label></td>
+                       <td align='left'>
+                               <input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " . ($this->mDestFile?"":"onchange='fillDestFilename()' ") . "size='40' />
+                       </td>
+               </tr>
+               <tr>
+                       <td align='right'><label for='wpDestFile'>{$destfilename}:</label></td>
+                       <td align='left'>
+                               <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40' value=\"$encDestFile\" />
+                       </td>
+               </tr>
+               <tr>
+                       <td align='right'><label for='wpUploadDescription'>{$summary}</label></td>
+                       <td align='left'>
+                               <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6' cols='{$cols}'{$ew}>" . htmlspecialchars( $this->mUploadDescription ) . "</textarea>
+                       </td>
+               </tr>
+               <tr>" );
        
        if ( $licenseshtml != '' ) {
                $wgOut->addHTML( "
-       <td align='right'>$license:</td>
-       <td align='left'>
-               <select name='wpLicense'>
-                       <option value=''>$nolicense</option>
-                       $licenseshtml
-               </select>
-       </td></tr><tr>
+                       <td align='right'><label for='wpLicense'>$license:</label></td>
+                       <td align='left'>
+                               <select name='wpLicense' id='wpLicense' tabindex='4'>
+                                       <option value=''>$nolicense</option>
+                                       $licenseshtml
+                               </select>
+                       </td>
+                       </tr>
+                       <tr>
                ");
        }
-       $wgOut->addHtml( "{$source}
+
+       if ( $wgUseCopyrightUpload ) {
+               $filestatus = wfMsgHtml ( 'filestatus' );
+               $copystatus =  htmlspecialchars( $this->mUploadCopyStatus );
+               $filesource = wfMsgHtml ( 'filesource' );
+               $uploadsource = htmlspecialchars( $this->mUploadSource );
+               
+               $wgOut->addHTML( "
+                               <td align='right' nowrap='nowrap'><label for='wpUploadCopyStatus'>$filestatus:</label></td>
+                               <td><input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus' value=\"$copystatus\" size='40' /></td>
+                       </tr>
+                       <tr>
+                               <td align='right'><label for='wpUploadCopyStatus'>$filesource:</label></td>
+                               <td><input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus' value=\"$uploadsource\" size='40' /></td>
+                       </tr>
+                       <tr>
+               ");
+       }
+       
+       
+       $wgOut->addHtml( "
+               <td></td>
+               <td>
+                       <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
+                       <label for='wpWatchthis'>" . wfMsgHtml( 'watchthis' ) . "</label>
+                       <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' />
+                       <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
+               </td>
+       </tr>
+       <tr>
+
+       </tr>
+       <tr>
+               <td></td>
+               <td align='left'><input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\" /></td>
        </tr>
-       <tr><td></td><td align='left'>
-       <input tabindex='5' type='submit' name='wpUpload' value=\"{$ulb}\" />
-       </td></tr></table></form>\n" );
+       
+       <tr>
+               <td></td>
+               <td align='left'>
+               " );
+       $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
+       $wgOut->addHTML( "
+               </td>
+       </tr>
+               
+       </table>
+       </form>" );
        }
 
        /* -------------------------------------------------------------- */
@@ -716,12 +774,16 @@ class UploadForm {
        function verifyExtension( $mime, $extension ) {
                $fname = 'SpecialUpload::verifyExtension';
 
-               if (!$mime || $mime=="unknown" || $mime=="unknown/unknown") {
-                       wfDebug( "$fname: passing file with unknown mime type\n" );
-                       return true;
-               }
+               $magic =& wfGetMimeMagic();
 
-               $magic=& wfGetMimeMagic();
+               if ( ! $mime || $mime == 'unknown' || $mime == 'unknown/unknown' )
+                       if ( ! $magic->isRecognizableExtension( $extension ) ) {
+                               wfDebug( "$fname: passing file with unknown detected mime type; unrecognized extension '$extension', can't verify\n" );
+                               return true;
+                       } else {
+                               wfDebug( "$fname: rejecting file with unknown detected mime type; recognized extension '$extension', so probably invalid file\n" );
+                               return false;
+                       }
 
                $match= $magic->isMatchingExtension($extension,$mime);