Jump to content

User:BDavis (WMF)/Notes/Thumb.php with Vagrant

From mediawiki.org

Enable Use of thumb.php in Vagrant VM

[edit]

Create a Vagrant "role" that enables thumb.php to handle 404 image requests in the wikimedia instance.

Manual Changes

[edit]
  • Add config to LocalSettings.php:
// thumb.php thumbnail generation via 404
$wgThumbnailScriptPath = false;
$wgGenerateThumbnailOnParse = false;
    ### thumb.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /w/thumb.php?f=$1&width=$2 [PT,QSA,B]
    ### ^^^^ this works but doesn't match wiki docs
    ### PT instead of L

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /w/thumb.php?f=$1&width=$2&archived=1 [PT,QSA,B]
    ### end thumb.php


Note that I used the MediaWiki <= 1.19 syntax. I couldn't get thumb_handler.php to work properly. It seems like the PathRouter setup isn't quite right to handle it. I also had to change from L to PT to get the alias for /w to take effect.

With these changes in place my vm instance is generating new thumbs on the fly. They are also saved to disk in /svr/images

Puppet

[edit]

Usage

[edit]
   vagrant enable-role multimedia
   vagrant provision


Once enabled, mediaiwiki instance in vagrant host will no longer generate thumbnails at page render. It will instead automagically generate and cache thumbs that have not been generated yet when HTTP requests are received. This allows a more WMF production matching dev stack as commons uses a similar configuration.


Design

[edit]

Basic idea: create a new role that:

  1. sets needed values in LocalSettings.php
  2. adds rewrites to apache vhost config


Augmenting LocalSettings is we documented and supported.


Messing with the vhost config is a little less easy. There are a couple ways it might be handled.

  1. The mediawiki class could be changed to take more parameters. This could be a simple flag for this feature or a more general system.
  2. The template for the vhost could be altered to read includes from some filesystem location into the <VirtualHost> scope.


I'm leaning towards the vhost reading include files approach. Here's what I think would be reasonable and extensible:

  • new apache::site::include resource type
    • This resource would ensure the availablity of an /etc/apache2/site-conf.d/[sitename]/ directory and manage adding a file to it
  • modify mediawiki-apache-site.erb to include files from the site include dir
  • add a usage of apache::site::include in role::thumb_on_404 to include needed rewrite rules


See gerrit:78260 for proposed solution. --BDavis (WMF) (talk) 18:56, 8 August 2013 (UTC)


See Also

[edit]