[Mediawiki-l] Interwiki links with spaces not underscores.

Thad Kerosky thadk at alltel.net
Mon Mar 28 03:55:15 UTC 2005


Hey everyone,
I've been happily running my mediawiki for a while now and I implemented a
little 5 line fix so that I could do interwiki links for Google and a few
other things effectively. The catch with Google and many other services is
that they don't like to interpret underscores as spaces. My hack was to
leave all $1 interwiki links alone but add a $2 symbol for use when you
actually want real spaces (or %20) in your URL.

It is getting a little tedious editing my change into the main each update
and I'd imagine this might be a decent feature or fix if implemented
correctly.

I didn't know much about the innards and figured out only enough to make
it work, so here goes:
I changed the function getFullURLs() in ./includes/Title.php by switching
this:
                        $url = str_replace( '$1', $namespace .
$this->mUrlform, $baseUrl );
                        if ( '' != $this->mFragment ) {
                               $url .= '#' . $this->mFragment;
                        }
                        return $url;
with this:
                        $urlPre = str_replace( "$1", $namespace .
$this->mUrlform, $baseUrl );
                        if ( '' != $this->mFragment ) {
                                $url .= '#' . $this->mFragment;
                        }
                        $url = str_replace( "$2", $namespace .
str_replace("_", "%20", $this->mUrlform),
$urlPre);
                        return $url;

I then changed all of the bits of the URLs in the database entries of the
Interwiki table which should have spaces from $1 to $2.

What do you think?

Thad



More information about the MediaWiki-l mailing list