Wednesday, February 24, 2010

Adding mime types for Microsoft Office 2007 file types in Apache

When opening uploaded documents from Microsoft Office 2007 applications in MediaWiki (and some other web applications as well) they might turn up as zip-files or doesn't start the appropriate office application. This is due to the fact that Office Open XML (OOXML) is a zip based file format and Apache 1 and 2 doesn't yet come with updated mime type definitions (or IANA haven't registered them).

You can add these missing definitions yourself without much trouble. First locate the Apache mime types table (mime.types) and then just add the following and restart your apache server.

application/vnd.ms-word.document.macroEnabled.12 docm
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
application/vnd.ms-powerpoint.template.macroEnabled.12 potm
application/vnd.openxmlformats-officedocument.presentationml.template potx
application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam
application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm
application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
application/vnd.ms-excel.addin.macroEnabled.12 xlam
application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
application/vnd.ms-excel.template.macroEnabled.12 xltm
application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx

For MediaWiki to identify the correct mime type (during upload) you can also add the above unmodified to includes/mime.types.

The MediaWiki file includes/mime.info has no practical use currently but you could add the following to it for completeness:

application/vnd.ms-word.document.macroEnabled.12 [OFFICE]
application/vnd.openxmlformats-officedocument.wordprocessingml.document [OFFICE]
application/vnd.openxmlformats-officedocument.wordprocessingml.template [OFFICE]
application/vnd.ms-powerpoint.template.macroEnabled.12 [OFFICE]
application/vnd.openxmlformats-officedocument.presentationml.template [OFFICE]
application/vnd.ms-powerpoint.addin.macroEnabled.12 [OFFICE]
application/vnd.ms-powerpoint.slideshow.macroEnabled.12 [OFFICE]
application/vnd.openxmlformats-officedocument.presentationml.slideshow [OFFICE]
application/vnd.ms-powerpoint.presentation.macroEnabled.12 [OFFICE]
application/vnd.openxmlformats-officedocument.presentationml.presentation [OFFICE]
application/vnd.ms-excel.addin.macroEnabled.12 [OFFICE]
application/vnd.ms-excel.sheet.binary.macroEnabled.12 [OFFICE]
application/vnd.ms-excel.sheet.macroEnabled.12 [OFFICE]
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet [OFFICE]
application/vnd.ms-excel.template.macroEnabled.12 [OFFICE]
application/vnd.openxmlformats-officedocument.spreadsheetml.template [OFFICE]

Finally remember to add the file types to the variable $wgFileExtensions in LocalSettings.php.

Tuesday, February 23, 2010

Duplex in LaTeX revisited

Back in the 90'ies when I studied at the university I wrote all my documents in LaTeX and I was really fond of it. I still think that it is the best layout system / engine ever invented. Back then I actually wrote some styles myself that were used at the university quite a lot. One of them were a duplex for PostScript functionality so you could enable duplex printing easilly via dvips.

Now my indepth knowledge of LaTeX is long gone but as a homage to it I will post the style right here on this blog for now - it should still be fully working though not tested:

% Definitions for enabling duplex print on PostScript printers (dvips)
% (c) Copyright 1998 Kasper Løvschall

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{psduplex}[1998/03/23 v1.1 Duplex print on PostScript device (KL)]

% Defining duplex options

\DeclareOption{longedge}{\special{!userdict begin /start-hook{
  1 dict dup /Duplex true put setpagedevice
  1 dict dup /Tumble false put setpagedevice
  }def end}\PackageInfo{psduplex}{Duplex Long Edge Binding is active}}
\DeclareOption{shortedge}{\special{!userdict begin /start-hook{
  1 dict dup /Duplex true put setpagedevice
  1 dict dup /Tumble true put setpagedevice
  }def end}\PackageInfo{psduplex}{Duplex Short Edge Binding is active}}
\DeclareOption{none}{\special{!userdict begin /start-hook{
  1 dict dup /Duplex false put setpagedevice
  1 dict dup /Tumble false put setpagedevice
  }def end}\PackageInfo{psduplex}{Duplex None is active}}

% Defining media position

\DeclareOption{tray2}{\special{!userdict begin /start-hook{
  1 dict dup /DeferredMediaSelection true put setpagedevice
  1 dict dup /MediaPosition 0 put setpagedevice
  }def end}\PackageInfo{psduplex}{Tray 2 media selected}}
\DeclareOption{tray3}{\special{!userdict begin /start-hook{
  1 dict dup /DeferredMediaSelection true put setpagedevice
  1 dict dup /MediaPosition 1 put setpagedevice
  }def end}\PackageInfo{psduplex}{Tray 3 media selected}}
\DeclareOption{envelope}{\special{!userdict begin /start-hook{
  1 dict dup /DeferredMediaSelection true put setpagedevice
  1 dict dup /MediaPosition 2 put setpagedevice
  }def end}\PackageInfo{psduplex}{Envelope media selected}}
\DeclareOption{tray1}{\special{!userdict begin /start-hook{
  1 dict dup /DeferredMediaSelection true put setpagedevice
  1 dict dup /MediaPosition 3 put setpagedevice
  }def end}\PackageInfo{psduplex}{Tray 1 media selected}}
\DeclareOption{tray4}{\special{!userdict begin /start-hook{
  1 dict dup /DeferredMediaSelection true put setpagedevice
  1 dict dup /MediaPosition 4 put setpagedevice
  }def end}\PackageInfo{psduplex}{Tray 4 media selected}}

% Beginning-Of-Page hooks

\DeclareOption{kopi}{\special{!userdict begin /bop-hook{gsave 200 30
  translate 65 rotate /Courier-Bold findfont 300 scalefont setfont
  50 -10 moveto 0.8 setgray (KOPI) show grestore}def end}}
\DeclareOption{kladde}{\special{!userdict begin /bop-hook{gsave 200 30
  translate 65 rotate /Courier-Bold findfont 200 scalefont setfont
  50 20 moveto 0.8 setgray (KLADDE) show grestore}def end}}
\DeclareOption{udkast}{\special{!userdict begin /bop-hook{gsave 200 30
  translate 65 rotate /Courier-Bold findfont 200 scalefont setfont
  40 20 moveto 0.8 setgray (UDKAST) show grestore}def end}}
\DeclareOption{hemmeligt}{\special{!userdict begin /bop-hook{gsave 200 30
  translate 65 rotate /Courier-Bold findfont 135 scalefont setfont
  40 40 moveto 0.8 setgray (HEMMELIGT) show grestore}def end}}

% Error message if invalid argument

\DeclareOption*{%
  \PackageWarning{psduplex}{Unknown argument "\CurrentOption"}}
\ProcessOptions*\relax

\endinput %EOF

In you preamble you can now add:

\usepackage[longedge]{psduplex}

to enable duplex on the long edge. Other options include: shortedge, tray1, tray2, tray3, tray4, envelope and none. They should be self explanatory. Also some backdrop text usually now provided by the printer driver are included (and needs to be translated, if you like): kopi (copy), kladde (draft), udkast (outline) as well as hemmeligt (secret).

If I will have some spare time I will take a look at the LyX project: http://www.lyx.org which looks rather interesting.