Extension:InterwikiRegex
Appearance
From mediawiki.org
This extension is currently not actively maintained! Although it may still work, any bug reports or feature requests will more than likely be ignored.
This extension stores its source code on a editable wiki page rather than in a code repository. As a result, this code may be maliciously altered.
It may contain security vulnerabilities, and will not receive localisation updates from translatewiki.net . Developers are strongly encouraged to host their code in a code repository rather than a wiki page so that the extension can be properly maintained, reviewed, and kept secure.
It may contain security vulnerabilities, and will not receive localisation updates from translatewiki.net . Developers are strongly encouraged to host their code in a code repository rather than a wiki page so that the extension can be properly maintained, reviewed, and kept secure.
Release status: unmaintained |
|
|---|---|
| Implementation | Link markup |
| Description | Adds regex capability for interwiki links |
| Author(s) | Leucosticte |
| Latest version | 1.0.0 |
| MediaWiki | 1.19+ |
| Licence | GNU General Public License 3.0 or later |
| Download | No link |
The InterwikiRegex extension adds regex capability for interwiki links. Or something like regex; actually, it's str_replace.
Installation
- Create a folder in the extensions folder named InterwikiRegex
- Move the files to the
extensions/InterwikiRegex/folder - Edit
LocalSettings.phpin the root of your MediaWiki installation, and add the following line near the bottom:
require_once("$IP/extensions/InterwikiRegex/InterwikiRegex.php");
Usage
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.
Files
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; } }