Extension:InterwikiRegex
From MediaWiki.org
InterwikiRegex Release status: stable |
|||
---|---|---|---|
Implementation | Link markup | ||
Description | Adds regex capability for interwiki links | ||
Author(s) | Leucosticte | ||
Last version | 1.0.0 | ||
MediaWiki | 1.19+ | ||
License | GPL | ||
Download | No link | ||
|
![]() |
This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net. |
The InterwikiRegex extension adds regex capability for interwiki links. Or something like regex; actually, it's str_replace.
Contents |
[edit] Installation
- Create a folder in the extensions folder named InterwikiRegex
- Move the files to the extensions/InterwikiRegex/ folder
- Edit LocalSettings.php in the root of your MediaWiki installation, and add the following line near the bottom:
require_once("$IP/extensions/InterwikiRegex/InterwikiRegex.php");
[edit] Usage
[edit] Configuration settings
// Array of interwiki prefixes and the string replacements $wgInterwikiRegexString = array ( 'urbandictionary' => array ( ' ' => '+', '_' => '+', ) );
This will cause [[urbandictionary:would of]]
to link to http://www.urbandictionary.com/define.php?term=would+of , once you have added the appropriate interwiki link using Special:Interwiki.
[edit] Files
[edit] InterwikiRegex.php
<? /** * InterwikiRegex MediaWiki extension. * * This extension adds regex capability for interwiki links. * * Written by Leucosticte * https://www.mediawiki.org/wiki/User:Leucosticte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file * @ingroup Extensions */ if( !defined( 'MEDIAWIKI' ) ) { echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); die( 1 ); } $wgExtensionCredits['other'][] = array( 'path' => __FILE__, 'name' => 'InterwikiRegex', 'author' => '[https://mediawiki.org/User:Leucosticte Leucosticte]', 'url' => 'https://mediawiki.org/wiki/Extension:InterwikiRegex', 'description' => 'Adds regex capability for interwiki links', 'version' => '1.0.0' ); // Array of interwiki prefixes and the string replacements $wgInterwikiRegexString = array ( 'urbandictionary' => array ( ' ' => '+', '_' => '+', ) ); $wgHooks['LinkEnd'][] = 'InterwikiRegex::onLinkEnd'; class InterwikiRegex { public static function onLinkEnd( $skin, $target, $options, &$text, &$attribs, &$ret ) { global $wgInterwikiRegexString; if ( !$target->isExternal() ) { return true; } $interwiki = $target->getInterwiki(); if ( isset ( $wgInterwikiRegexString[ $interwiki ] ) ) { foreach ( $wgInterwikiRegexString[ $interwiki ] as $key => $value ) { $attribs[ 'href' ] = str_replace ( $key, $value, $attribs[ 'href' ] ); } } return true; } }