[Mediawiki-l] power point upload?

Lane, Ryan Ryan.Lane at ocean.navo.navy.mil
Fri Apr 24 15:25:24 UTC 2009


> I attempted to load a MS Power Point 2007 file (.pptx) to my 
> wiki this afternoon, and I got the message that the file was 
> corrupt or the wrong file type.
> 
> I *did* set $wgFileExtensions array in LocalSettings.php to 
> allow .ppt/.pptx files; any ideas?
> 
> Oh, and thanks for all the answers to my first question about 
> a root installation! :)
> 

Office 2007 formats get detected as zip files. It is possible to upload
these without turning off MIME detection, but I'll tell you ahead of
time, this is a dirty, dirty hack:

--- MimeMagic.php.old   2009-04-24 10:20:58.000000000 -0500
+++ MimeMagic.php       2009-04-24 10:20:06.000000000 -0500
@@ -334,6 +334,14 @@
                $m = trim( $m );
                $m = preg_replace( '/\s.*$/', '', $m );
 
+               //BEGIN CUSTOMIZATION
+               if ( $ext == 'ppt' ) {
+                       $m = 'application/vnd.ms-powerpoint';
+               } else if ( $ext == 'xls' ) {
+                       $m = 'application/vnd.ms-excel';
+               }
+               //END CUSTOMIZATION
+
                return $m;
        }
 
@@ -547,6 +555,9 @@
                // Check for ZIP (before getimagesize)
                if ( strpos( $tail, "PK\x05\x06" ) !== false ) {
                        wfDebug( __METHOD__.": ZIP header present at end
of $file\n" );
+                       if ( $ext == 'docx' || $ext === false ) {
+                               return 'application/msword';
+                       }
                        return $this->detectZipType( $head );
                }

Note that the list or my email client probably slaughtered the diff.
You'll probably want to do this by hand. Notice that this only fixes
docx, so you'll need to do the rest, but this is a way to do it.

That said... Don't use Office 2007 formats. Either use Office 2003
formats, or use ODT.

If you want to fix the issues with the older office formats, see my blog
entry on it:

http://ryandlane.com/wprdl/2009/04/21/allowing-docpptxls-uploads-to-medi
awiki-and-getting-proper-mime-types-back/

V/r,

Ryan Lane



More information about the MediaWiki-l mailing list