Extension:HTTP302Found/Version 2.0

From MediaWiki.org
Jump to navigation Jump to search

HTTP302Found.php[edit]

<?php
if ( ! defined( 'MEDIAWIKI' ) )
        die();
/* MediaWiki extension to force an external HTTP 302 redirect instead of internal redirects
 * Copyright (C) 2009  Ian Weller <ian@ianweller.org>
 * Copyright (C) 2012  Patrick Uiterwijk <puiterwijk@gmail.com>
 *
 * 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 2
 * 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.
 */
$wgHooks['ArticleViewRedirect'][] = 'HTTP302Found::onArticleViewRedirect';

$wgAutoloadClasses['HTTP302Found'] = dirname(__FILE__) . '/HTTP302Found.body.php';

$wgExtensionCredits['parserhook'][] = array(
        'path' => __FILE__,
        'name' => 'HTTP 302 Found',
        'author' => 'Ian Weller, Patrick Uiterwijk',
        'description' => 'Forces an external HTTP 302 redirect instead of internal redirects',
        'url' => 'https://www.mediawiki.org/wiki/Extension:HTTP302Found',
        'version' => '2.0',
);
?>

HTTP302Found.body.php[edit]

<?php
/* MediaWiki extension to force an external HTTP 302 redirect instead of internal redirects
 * Copyright (C) 2009  Ian Weller <ian@ianweller.org>
 * Copyright (C) 2012  Patrick Uiterwijk <puiterwijk@gmail.com>
 *
 * 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 2
 * 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.
 */
class HTTP302Found {
    function onArticleViewRedirect($article)
    {
        header('Location: ' . $article->getTitle()->getFullURL() . '?rd=' . $article->getContext()->getRequest()->getVal('title'));
        print('Redirected to <a href="' . $article->getTitle()->getFullURL() . '?rd=' . $article->getContext()->getRequest()->getVal('title') . '">Here</a>');
        return true;
    }
}
?>

HTTP302Found.i18n.php[edit]

<?php
/* MediaWiki extension to force an external HTTP 302 redirect instead of internal redirects
 * Copyright (C) 2009  Ian Weller <ian@ianweller.org>
 * Copyright (C) 2012  Patrick Uiterwijk <puiterwijk@gmail.com>
 *
 * 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 2
 * 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.
 */
$messages = array();
?>