Pretty URLs in mediawiki

August 5th, 2008 No Comments »

The following steps are usually sufficient in order to make “pretty URLs” in mediawiki, e.g.
In Apache configuration:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(skins|stylesheets|images|config)/
RewriteCond %{REQUEST_URI} !^/(redirect|texvc|index).php
RewriteRule ^(.*)$ /index.php?title=$1 [L,QSA]

In LocalSettings.php

$wgScriptPath       = "";
$wgScript           = "$wgScriptPath";
$wgRedirectScript   = "$wgScriptPath/redirect.php";
$wgArticlePath      = "$wgScript/$1";

However, the latest version (1.12.0 at the time of writing) needed the following patch, in order to make all things work. I don’t know whenever this was already reported by someone and/or fixed.

--- includes/Title.php.orig     2008-08-05 22:56:32.000000000 +0300
+++ includes/Title.php  2008-08-05 23:16:22.000000000 +0300
@@ -832,7 +832,12 @@
                                        if ( $query == '-' ) {
                                                $query = '';
-                                       $url = "{$wgScript}?title={$dbkey}&{$query}";
+                                       # Assume "pretty URLs" if wgScript is empty
+                                       if ( $wgScript == '' ) {
+                                               $url = "/{$dbkey}?{$query}";
+                                       } else {
+                                               $url = "{$wgScript}?title={$dbkey}&{$query}";
+                                       }

Upgrading PostgreSQL 8.2 to 8.3 (mediawiki)

August 5th, 2008 2 Comments »

This upgrade was a real pain.
Though there are many resources on the web, which talk about this kind of upgrade (and the best one in my opinion is this one:, all of them fall short of giving a succinct but precise instruction for this upgrade. I tried to follow the aforementioned article, but it still gave some errors.
So I’ve done something similar, but a little bit different, finally importing the 8.2 database without a single error.
First of all, I dumped the original database in two parts – schema and data.
I took the schema part and divided it in two: schema definition and constraints and indexes. From the former I removed all references to tsearch2 functions, in the latter checked that the “search_path” is correct for every bulk of updates. Then I wanted to import the new tsearch2 functions that come with PostgreSQL 8.3.
So I wrote a simple script which I used in order to import the db several times, fixing bugs and eliminated all the problems which were still present:

export PGUSER=postgres
dropdb wikidb
createdb wikidb
psql -q wikidb < /usr/share/pgsql/contrib/tsearch2.sql
echo "Inserting wiki schema"
psql -q wikidb < wiki_schema.sql
echo "Inserting data"
psql -q wikidb < wiki_data.sql
echo "Inserting constraints"
psql -q wikidb < wiki_schema_constraints.sql

At the end all files were imported without a single error.
Then I discovered, that I’ll have to update mediawiki from 1.11.0 to 1.12.0, since the former doesn’t work with PostgreSQL 8.3
The update had only one problem (missing file – it’s mentioned in the link above), which was easy to remedy.
Upon using the mediawiki I found out, that I’ve to grant access to one of the tables.
It was probably due to the fact, that it was added to schema by user other than wikiuser:

GRANT ALL ON TABLE protected_titles TO wikiuser;

Seems to work fine so far.

Apache hacking

July 27th, 2008 No Comments »

When trying to help our engineers to configure Apache 2.2 I found out to my complete astonishment, that Apache doesn’t allow negation of environment, e.g. to perform some action in context of mod_authz_host allow/deny when some environment variable DOESN’T exist, thus the directive below has no effect:

Deny from env=!HAS_SOMEVAR

I opened a bug with a patch, which was accepted, and lately it was backported to 2.2 branch, therefore it will appear in the next version (2.2.10).

Other shortcoming that I’ve found, that it’s impossible to unset a cookie while using mod_rewrite, but checking the code revealed, that the value for the cookie isn’t checked, therefore it’s possible to inject arbitrary string there, and this is exactly what I did:

RewriteRule ^/$ http://myhost.domain/url [CO=JSESSIONID:;comment=Reset:.myhost.domain:0:/,L]

Notice the trick – the value for cookie is “;comment=Reset” and validity period of 0 minutes making the Set-Cookie header look like this:

Set-Cookie: JSESSIONID=;comment=Reset; path=/; domain=.myhost.domain;
  expires=Sun, 27-Jul-2008 12:00:08 GMT

Integrating Rails and dhtmlxTabbar

June 24th, 2008 2 Comments »

The dhtmlxTabbar is a nice tab-bar component from
In order to use the AJAX loading feature I had to make a small change in the dhtmlxcommon.js so it mimics the behavior of Prototype by adding a X-Requested-With HTTP header. Thus, it’s possible to use request.xhr? in Rails.

Hacking wget

February 2nd, 2008 No Comments »

Today was a perfect day for hacking wget.
I wanted to mirror some site, and to my astonishment found out, that wget doesn’t support regular expressions for including the paths to mirror. Only a list of directories for including/excluding could be provided.
This was easily remedied using the excellent pcre library.
The patch is quick and dirty, and if one would like to compile wget with it, -lpcre should be added to LIBS in Makefile.
Patch for wget which adds regular expression matching for urls

Update: Well, it seems that there was a similar patch available for years:

Encryption in wordpress

October 17th, 2007 No Comments »

Since I wanted to write some private posts which ought to be encrypted as well as hidden, I was naturally looking for an encryption plug-in for wordpress. However, to my great disappointment, I couldn’t find one.
Perhaps I’ll write one. The basic idea is that there will be an option to mark the post as encrypted when writing it.
In that case, when the Save or Publish button will be pressed, the javascript will ask to decrypt the key (which is stored on the server in the encrypted form) and then will use the decrypted key to encrypt the content and convert it to base64. The content then will be modified in place and then sent to server.
When watching the post, the javascript will prompt for password for the key, decrypt it, and then use it in order to decrypt the ciphertext in place.
The cryptographic algorithm which can be used is AES-cbc, which is available in javascript.
Quite secure, since the password is not sent via the net.
Now I just have to find some time to implement it … 🙁

Accessing Subversion from Rails in an ActiveRecord way

August 27th, 2007 2 Comments »

I needed to present products and their corresponding branches and tags in Subversion in a Rails app. So I’ve come up with this quite simple solution.

The GenericModel class (attached) is ihnerited by Tag, Branch and Product.
The Product class supports methods find, branches and tags for which it uses ‘svn/client’.

The config.yml (which is read into OpenStruct) is very simple:

  url: http://svn/svn/repos
  user: roman
  password: roman

The Product class tries to provide interface similar to the ActiveRecord (of course I didn’t immitate everything, just the basic stuff). Implementing interfaces in a contract-less language is an adventure 🙂



Still playing with Bugzilla

August 24th, 2007 No Comments »

Today I extended my Bugzilla gateway to support “products” in Bugzilla.

To my surprise, I found out that Bugzilla’s XML-RPC doesn’t return the associated “components” and “versions”.

The fix is quite simple:

--- Bugzilla/WebService/ Fri Aug 24 20:46:07 2007
+++ Bugzilla/WebService/      Fri Aug 24 21:10:47 2007
@@ -60,6 +60,8 @@
                id          => type('int')->value($_->id),
                name        => type('string')->value($_->name),
                description => type('string')->value($_->description),
+               components  => $_->components,
+               versions    => $_->versions
         } @requested_accessible;

I’ll try to submit it to the Bugzilla’s bugzilla 🙂

But what’s really missing, is the ability to change bugs via the XML-RPC API, or for the very least – adding comments.
The current way of doing it via the mail gateway is a little bit ugly.

Update: It turns out that there’s a bug opened already:
And this bug has a patch which allows appending comments to a bug.

Bugzilla plugin for Rails

August 14th, 2007 3 Comments »

I finally posted my Bugzilla plugin on Rubyforge.

The project page is:

The source can be found here:


It is probably not complete, and has some bugs, and surely lacks documentation, but this is better than nothing 🙂

Bugzilla 2.x integration with Subversion

August 12th, 2007 No Comments »

To install Bugzilla on FC6:

yum install perl-DBD-MySQL perl-TimeDate perl-MIME-tools
perl-AppConfig perl-Template-Toolkit


yum install perl-PatchReader perl-GD perl-Chart perl-GDGraph perl-Template-GD

Configuring Subversion to send email upon commit

Copy the /usr/share/doc/subversion-1.4.X/tools/hook-scripts/ to hooks directory and patch it with my changes:

---  2007-02-07 11:57:50.000000000 +0200
+++     2007-08-01 16:31:40.000000000 +0300
@@ -347,6 +347,7 @@
 # $author - declared above for use as a command line parameter in
 #   revprop-change mode.  In commit mode, gets filled in below.
+my @log;
 if ($mode eq 'commit')
@@ -357,7 +358,7 @@
     $author = shift @infolines;
     my $date = shift @infolines;
     shift @infolines;
-    my @log = map { "$_\n" } @infolines;
+    @log = map { "$_\n" } @infolines;
     # Modified directory name collapsing.
@@ -516,6 +517,11 @@
     my $subject         = $subject_base;
     my $diff_wanted     = ($project->{show_diff} and $mode eq 'commit');
+    if (join('', @log) =~ /bug.*?(\d+)/im)
+    {
+           $subject_prefix = "[Bug $1]";
+    }
     if ($subject_prefix =~ /\w/)
         $subject = "$subject_prefix $subject";

Edit the post-commit file under hooks directory in subversion repository:

/home/svn/hooks/ "$REPOS" "$REV" -h --diff n

Configuring sendmail to send the mail to the Bugzilla email gateway

Install perl-MIME-tools package:

yum install perl-MIME-tools

Patch /usr/local/bugzilla/contrib/ :

---       2007-08-01 16:05:01.000000000 +0300
+++        2007-08-02 10:43:53.000000000 +0300
@@ -32,7 +32,7 @@
 use MIME::Parser;
-  chdir "..";        # this script lives in contrib, change to main
+  chdir '/usr/local/bugzilla';
   push @INC, "contrib";
   push @INC, "."; # this script lives in contrib
@@ -91,6 +91,7 @@
 print "The subject is $Subject\n";
 my ($bugid) = ($Subject =~ /\[Bug ([\d]+)\]/);
+exit 0 unless $bugid;
 print "The bugid is $bugid\n";
 # make sure the bug exists
@@ -122,6 +123,11 @@
+# I'll exit at this point, since Bugzilla::BugMail::Send yields:
+# Can't call method "active_names" on an undefined value at line 203.
+# and this make the sendmail filter fail miserably.
+exit 0;
 Bugzilla::BugMail::Send( $found_id, { changer => $SenderShort } );
 sub DealWithError {

Make this script trusted by sendmail:

cd /etc/smrsh; ln -s /usr/local/bugzilla/contrib/ .

Edit /etc/aliases and add:

bugzilla:       |

Then don’t forget to run newaliases.

Change user to the “mail” user (you’ll need to change its shell for this test), and try running the
Change permissions in /usr/local/bugzilla for files and/or directories it complains about (if it does).

That’s it. When there will be commit with ‘Bug 123’ in the comment, the bug will be updated with this information (including the files involved).