Installing mwlib, mwlib.rl, and Collection on Windows

Introduction

Instructions for installing mwlib on Windows using MinGW and MSYS (part of MinGW). The installation guide is broken into four sections covering the installation of the development, build, and runtime environment for Windows, the mwlib component, the mwlib.rl component, and the Collection extension.

  • These instructions do not use Cygwin.
  • These instructions have been verified on Windows XP and Windows Vista

written by Brion Finlay

Questions, requests, and further information can be posted to the  Google group, or corrections can be made to this wiki page.

Prerequisites

  • You have a working MediaWiki installation, including PHP, a webserver, a database server, and the MediaWiki software.  XAMPP is a very easy way to install a webserver, database, and PHP.
    • your PHP configuration must support CURL. I describe how to enable CURL for XAMPP below.
  • Perl may be needed. I did not verify if is Perl needed to be installed. XAMPP will also install Perl for you, but you may need to add the Perl directory to your path.

Installing the Development/Build/Run-time Environment for Windows

Install Python for Windows

  1. go to  http://www.python.org/download/
  2. Choose Python 2.5.2 Windows installer
  3. Install Python to c:\python25

Install Python for Windows extensions

These extensions are required by twister (win32api).

  1. go to  http://sourceforge.net/project/platformdownload.php?group_id=78018
  2. Download pywin32-212.win32-py2.5.exe
  3. Install

Install Python Imaging Library

  1. go to  http://www.pythonware.com/products/pil/
  2. Download Python Imaging Library 1.1.6 for Python 2.5
  3. The following error messages occur under Windows Vista, but it seems safe to ignore them. They seem related to registry keys. You may be able to prevent them by right clicking on the installer and running it as an administrator.
    • Error messages under windows vista
      • Could not create ... PIL-py2.5
      • Could not set key value... Python 2.5 PIL-1.1.6
      • Could not set key value: "C:\Python25\RemovePIL.exe" -u "C:\Python25\PIL-wininst.log"

Install MinGW

  1. go to  http://sourceforge.net/project/showfiles.php?group_id=2435
  2. Download Automated MinGW Installer
  3. Choose MinGW-5.1.4.exe
  4. run MinGW auto installer
  5. choose "download and install"
  6. Read license and agree
  7. Choose "Current" package
  8. Choose "MinGW base tools"
  9. Choose "g++ compiler"
  10. Choose "mingw make" (maybe not needed)
  11. Install to C:\MinGW
  12. Install to MinGW group.
  13. MinGW will download and install

Install MSYS

  1. download msys 1.0.10
  2. install
  3. agree to license
  4. choose c:\msys\1.0
  5. choose i386
  6. choose group MinGW
  7. post install process pops up
  8. answer yes for mingw
  9. type c:\mingw
  10. hit return
  11. select finish

Setup Paths

  1. Add Python to path: c:\python25\
  2. Add MSYS to path: c:\msys\1.0\bin
  3. add MinGW to path: c:\mingw\bin

Configure Python to use MinGW

Configure Python to work with MinGW, to solve the "visual studio 2003" issue.

Create mingw_setup.py

  1. Copy this file to mingw_setup.py:
    #=== mingw_setup.py by Phillip J. Eby
    """Create pythonNN.def and libpythonNN.a in 'PythonNN/libs' directory
    
    This script makes it possible to use the MinGW compiler tools to
    build C extensions that work with the standard Windows Python
    distribution.
    
    Before running, you should have installed the MinGW compiler toolset,
    and placed its 'bin' directory on your PATH.  An easy way to do this
    is to install Cygwin's "binutils", "gcc", and "mingw-*" packages,
    then run this script from the Cygwin shell.  (Be sure to use *Windows*
    Python, not Cygwin python!)
    
    Once this script has been run, you should be able to build extensions
    using distutils in the standard way, as long as you select the
    'mingw32' compiler, and the required tools are on your PATH.  See
    the "Installing Python Modules" manual for more information on
    selecting a compiler.
    """
    
    
    from distutils.spawn import find_executable
    from distutils.sysconfig import get_config_var
    from distutils import __file__ as distutils_file
    import os, re, sys
    
    if sys.platform=='cygwin':
         print "Please run this script using Windows python,",
         print "not Cygwin python.  E.g, try:"
         print
         print "/cygdrive/c/PythonNN/python", " ".join(sys.argv)
         print
         print "(where NN is the major/minor python version number)"
         sys.exit()
    
    basename = 'python%d%d' % sys.version_info[:2]
    
    libs_dir = os.path.join(get_config_var('prefix'),'libs')
    lib_file = os.path.join(libs_dir,basename+'.lib')
    def_file = os.path.join(libs_dir,basename+'.def')
    ming_lib = os.path.join(libs_dir,'lib%s.a' % basename)
    
    distutils_cfg = os.path.join(os.path.dirname(distutils_file),'distutils.cfg')
    
    export_match = re.compile(r"^_imp__(.*) in python\d+\.dll").match
    
    nm      = find_executable('nm')
    dlltool = find_executable('dlltool')
    
    if not nm or not dlltool:
         print "'nm' and/or 'dlltool' were not found;"
         print "Please make sure they're on your PATH."
         sys.exit()
    
    nm_command = '%s -Cs %s' % (nm, lib_file)
    
    print "Building", def_file, "using", nm_command
    f = open(def_file,'w')
    print >>f, "LIBRARY %s.dll" % basename
    print >>f, "EXPORTS"
    
    
    nm_pipe = os.popen(nm_command)
    for line in nm_pipe.readlines():
         m = export_match(line)
         if m:
             print >>f, m.group(1)
    f.close()
    
    exit = nm_pipe.close()
    if exit:
         print "nm exited with status", exit
         print "Please check that", lib_file, "exists and is valid."
         sys.exit()
    
    
    print "Building",ming_lib,"using",dlltool
    dlltool_pipe = os.popen(
         "%s --dllname %s.dll --def %s --output-lib %s" %
         (dlltool, basename, def_file, ming_lib)
    )
    
    dlltool_pipe.readlines()
    exit = dlltool_pipe.close()
    if exit:
         print "dlltool exited with status", exit
         print "Unable to proceed."
         sys.exit()
    
    print
    print "Installation complete.  You may wish to add the following"
    print "lines to", distutils_cfg, ':'
    print
    print "[build]"
    print "compiler = mingw32"
    print
    print "This will make the distutils use MinGW as the default"
    print "compiler, so that you don't need to configure this for"
    print "every 'setup.py' you run."
    

Run mingw_setup.py

  1. run "python mingw_setup.py"
  2. create distutils as directed by script:
	Installation complete.  You may wish to add the following
	lines to C:\Python25\lib\distutils\distutils.cfg :

	[build]
	compiler = mingw32

Install easy_install

  1. download  http://peak.telecommunity.com/dist/ez_setup.py
  2. run 'python ez_setup.py'
    • this will install setuptools

Windows Vista: administrator CMD

In Vista, open cmd window as administrator. Remaining components should be installed from the administrator shell.

  1. open start menu
  2. search for cmd
  3. right click cmd and choose "run as administrator"

Installing mwlib on Windows

  • mwlib is the component that processes wikitext in MediaWiki articles.

Install mwlib

  1. cd \python25\scripts
  2. easy_install mwlib

Build latest mwlib

Step 1: Download and install re2c

  1.  http://downloads.sourceforge.net/re2c/re2c-0.13.5-bin.zip
  2. extract re2c – I put it in c:\python25. It probably belongs somewhere better, like its own path. You could put it in MSYS or MinGW directories but then if you upgrade MSYS or MinGW you have to remember to upgrade re2c. Its own path is probably best.

Step 2: Get latest mwlib version

  1. download mwlib source
  2. extract mwlib source
  3. cd to mwlib source
  4. run 'sh'
  5. type 'make'
  6. type 'python setup.py install'

Installing mwlib.rl on Windows

  • mwlibrl mwlib.rl is the component used by mwlib to write PDF output.

Install mwlib.rl

  1. cd \python25\scripts
  2. easy_install mwlib.rl

Install ReportLab? (SVN)

  1. download ReportLab? from SVN
  2. extract source
  3. (Windows Vista: use administrator shell)
  4. cd reportlab-full-xxx\reportlab
  5. run 'sh'
  6. run 'python setup.py install'

Installing the MediaWiki Collection Extension on Windows

  • The  MediaWiki Collection extension makes it possible to organize personal selections of pages in a collection, and adds a Download as PDF link in the toolbox on mediawiki.

Install Collection Extension

  1. download latest Collection extension:
  2. extract to MediaWiki extensions/Collection
  3. Add the following to LocalSettings.php
    	# Extension: Collection
    	require_once("$IP/extensions/Collection/Collection.php");
    	$wgCollectionMWServeURL = 'http://localhost/cgi-bin/mwlib.cgi';
    	$wgHTTPTimeout = 30;
    	$wgEnableAPI=true;
    	// uncomment the next line if you need login
            // domain is optional.  Can be set to "local" for authentication against wiki database.
    	//$wgCollectionMWServeCredentials = "user:password:domain";
    
  4. Create "MediaWiki:PDF Template Blacklist" page
    • enter "none" and save the page.

Enable CURL in PHP

  1. For XAMPP, modify XAMPP\apache\bin\php.ini, and uncomment the line "extension=php_curl.dll".
  2. Restart Apache.

Install mwlib.cgi

  1. copy mwlib.cgi from the mwlib source download (in the cgi-bin directory) to the cgi-bin directory on your server.
  2. edit mwlib.cgi:
    1. modify first line, change to "#! c:\python25\python"
      • your webserver must be setup properly to execute cgi-bin files, especially processing the path behind the shebang. An easy way to do this is to install XAMPP.
    2. modify MWRENDER: MWRENDER = 'c:/python25/scripts/mw-render.exe'
    3. modify MWZIP: MWZIP = 'c:/python25/scripts/mw-zip.exe'
    4. modify MWPOST: MWPOST = 'c:/python25/scripts/mw-post.exe'
    5. update locations for log files and cache directory. Remember to use forward slashes "/" for the python strings.

Add Collection portlet to MediaWiki

  • see  README.txt:
  • Add a portlet to the skin of your MediaWiki installation: Just before the line:
        <div class="portlet" id="p-tb">
    
    in the file skins/MonoBook.php or skins/Modern.php insert the following code:
        <?php
          if(isset($GLOBALS['wgSpecialPages']['Collection'])) {
             Collection::printPortlet();
          }
        ?>
    

Troubleshooting

Could not write status file

2009-05-19T14:57:33 mwlib.status.ERROR >> Could not write status file 'd:/var/cache/mwlib/d\\dc\\dcb8144c2bd9a2c1\\status.rl': [Error 183] Cannot create a file when that file already exists

See: http://code.pediapress.com/wiki/ticket/613

"invalid image url" and no images in PDF output

2009-05-19T15:33:08 rlwriter.warning >> invalid image url (obj.target:u'Image:Hand.pen.jpg') 

See:  http://groups.google.com/group/mwlib/browse_thread/thread/9ee31f1a9dfa3f5b

Further Configuration

  • more options are availble to configure for the Collection extension. See the  README.txt file for more information.