Last modified: 2012-04-12 13:53:38 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T28285, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 26285 - Automatically append extension if the user entered a filename without extension during upload
Automatically append extension if the user entered a filename without extensi...
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Uploading (Other open bugs)
1.16.x
All All
: Normal enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-12-08 21:56 UTC by Jon
Modified: 2012-04-12 13:53 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Jon 2010-12-08 21:56:52 UTC
I was getting an error about no file extension through the UI since my apache/php config creates temp files in /tmp/ with no file extension.  So I can up with a solution around the issues since it seems that MediaWiki requires a file extension to allow an upload to complete.  This is more of a "I found a bug for me, and I fixed here.  And here's how."  and you can tell me if that was stupid or there was already way around this.

I added $mTempOrigName to the Base class, then set it in FromFile.  Then in getTitle of the Base class if the tempname fails to produce a file extension I test the original name to see if I can get an extension from that.  If so I override the vars and thing continue like normal.

includes/upload/UploadBase.php

        protected $mTempPath, $mTempOrigName;
...
                list( $partname, $ext ) = $this->splitExtensions( $this->mFilteredName );
        if (count($ext) == 0) { // extension was missing from apache temp file, try original name
            list($t_partname,$t_ext) = $this->splitExtensions( $this->mTempOrigName );
            if (count($t_ext) > 1) {
                $partname = $t_partname;
                $ext = $t_ext;
            }
        }

includes/upload/UploadFromFile.php
                if( !$desiredDestName )
                        $desiredDestName = $request->getFileName( 'wpUploadFile' );
        $this->mTempOrigName = $request->getFileName( 'wpUploadFile' );
                return $this->initializePathInfo(



Not sure if this helps anyone else but it fixes my last blocker to upgrading.
Comment 1 Jon 2010-12-09 22:37:29 UTC
I copied an older version of my code.  The (count($t_ext) > 1) should be (count($t_ext) > 0).
Comment 2 Bryan Tong Minh 2010-12-10 20:27:39 UTC
I don't really get this. $mFilteredName is constructed from $mDesiredDestName, which is the filename as sent by the browser, and not the Apache temp file.
Comment 3 Jon 2010-12-14 02:37:45 UTC
in my logging I found that the $mFilteredName isn't the original name, but then random name they put into the text input box on the form.  As a result it doesn't have an extension most of the time.  I needed the original filename to actually get the file extension as a result.
Comment 4 Bryan Tong Minh 2010-12-14 08:01:52 UTC
Well, users should add the extension in the desired name indeed. However if as you say there is a possibility of determining the original filename, then think it would not be unreasonable to guess the extension ourselves.

(changed summary accordingly)
Comment 5 Jon 2010-12-14 20:43:29 UTC
Cool.  Thanks.
Comment 6 Bryan Tong Minh 2010-12-15 08:47:24 UTC
Feature request, so marking as enhancement.
Comment 7 Bryan Tong Minh 2011-01-27 21:18:15 UTC
r81106

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links