Extension:Redirect302
From Linux Web Expert
<translate> This extension stores its source code on a wiki page.</translate> <translate> Please be aware that this code may be unreviewed or maliciously altered.</translate> <translate> They may contain security holes, outdated interfaces that are no longer compatible etc.</translate> <translate> Note:</translate> <translate> No [[<tvar name=localisation>Special:MyLanguage/Localisation#Translation resources</tvar>|localisation]] updates are provided for this extension by <tvar name=twn>translatewiki.net </tvar>.</translate> |
<translate> This extension is currently not actively maintained!</translate> <translate> Although it may still work, any bug reports or feature requests will more than likely be ignored.</translate> |
Redirect302 Release status: unmaintained |
|
---|---|
Implementation | Hook |
Description | Adds a hook to create 302 style redirects |
Author(s) | Joshua Gay (Joshuagaytalk) |
Latest version | 0.2 (2012-11-07) |
MediaWiki | 1.17+ |
Database changes | No |
License | GNU General Public License 2.0 or later |
Download | see below |
Example | The Free Software Directory |
Quarterly downloads | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
Public wikis using | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
The Redirect302 extension changes the redirect hook so that an http 302 error is issued and the redirect is done on the client side.
Installation
- <translate> <tvar name=1>Copy the code into files</tvar> and place the file(s) in a directory called <tvar name=name>
Redirect302
</tvar> in your <tvar name=ext>extensions/
</tvar> folder.</translate> - <translate> Add the following code at the bottom of your <tvar name=1>LocalSettings.php </tvar> file:</translate>
require_once "$IP/extensions/Redirect302/Redirect302.php";
- File:OOjs UI icon check-constructive.svg <translate> Done</translate> – <translate> Navigate to <tvar name=special>Special:Version</tvar> on your wiki to verify that the extension is successfully installed.</translate>
Code
Redirect302.php
<?php
/**
* This extension changes the redirect hook so that an http 302 error is issued and the redirect is done on the client side.
*
* @file
* @ingroup Extensions
* license: GPL-2.0-or-later
*/
if ( !defined( 'MEDIAWIKI' ) ) die();
// credits
define('Redirect302_VERSION', '0.2' );
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'Redirect302',
'version' => Redirect302_VERSION,
'author' => array( 'Joshua Gay' ),
'url' => 'https://www.mediawiki.org/wiki/Extension:Redirect302',
'descriptionmsg' => 'redirect302-desc',
);
// messages i18n
$dir = dirname(__FILE__) . '/';
$wgExtensionMessagesFiles['Redirect302'] = $dir . 'Redirect302.i18n.php';
// Register hook
$wgHooks['InitializeArticleMaybeRedirect'][] = 'redirect302_hook';
// Redirect with 302
function redirect302_hook($title, $request, &$ignoreRedirect, &$target, &$article) {
if (!$ignoreRedirect && $article->isRedirect()) {
if(($target = $article->followRedirect()) instanceof Title) {
$target = $target->getFullURL();
}
}
return true;
}
Redirect302.i18n.php
<?php
/**
* Internationalisation file for extension Redirect302.
*
* @file
* @ingroup Extensions
*/
$messages = array();
/** English
* @author Joshua Gay
*/
$messages['en'] = array(
'redirect302-desc' => 'Adds a hook to create 302 style redirects',
);
/** German (Deutsch)
* @author Kghbln
*/
$messages['de'] = array(
'redirect302-desc' => 'Ermöglicht Umleitungen mit HTTP-Statuscode 302',
);
On-wiki translation
/** English (English)
* @author ?
*/
$messages['en'] = array(
'redirect302-desc' => 'Adds a hook to create 302 style redirects',
);
Categories:
- Pages with script errors
- Pages with broken file links
- Extensions which host their code in-wiki
- Unmaintained extensions
- Extensions without an image
- Hook extensions
- Extensions without a compatibility policy
- Extensions with manual MediaWiki version
- GPL licensed extensions
- InitializeArticleMaybeRedirect extensions
- All extensions
- Extensions not in ExtensionJson
- Extensions not using extension registration