Extension:ShowRedirectPageText

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
ShowRedirectPageText

Release status: beta

Implementation Page action
Description
Author(s) user:jldupont
MediaWiki 1.10 but probably works < 1.10
License No license specified
Download [1]
Check usage and version matrix

Contents

What can this extension do? [edit]

Show the wikitext included in a 'redirect' page.

Why is this useful? [edit]

If one wishes to document the redirect. I personally use this feature to document my cluster of Mediawiki installations.

Installation [edit]

  1. Get 'ExtensionClass' extension from Extension:ExtensionClass
  2. Get this extension's code

Changes to LocalSettings.php [edit]

require('extensions/ExtensionClass.php');
require('extension/ShowRedirectPageText/ShowRedirectPageText.php');

Code [edit]

<?php
/*
 * ShowRedirectPageText.php
 *
 * $Id: ShowRedirectPageText.php 172 2007-06-15 19:39:10Z jeanlou.dupont $
 * @author Jean-Lou Dupont
 * 
 * <b>Purpose:</b>  This extension enables the display of the text included
 *                  in a 'redirect' page.
 *
 *                  The inclusion of wikitext in a redirect page is helpful
 *                  in situations, for example, where redirects are used to manage a 
 *                  'cluster' of Mediawiki serving machines.
 *
 * FEATURES:
 * =========
 * 1) No mediawiki installation source level changes
 * 2) No impact on parser caching
 *
 * DEPENDANCIES:
 * =============
 * 1) ExtensionClass
 *
 * HISTORY:
 * ========
 *
 * TODO:
 * =====
 * - Clean up the '#redirect' wikitext before displaying
 *
 */
 
ShowRedirectPageText::singleton();
 
class ShowRedirectPageText extends ExtensionClass
{
        const defaultAction = true;   // by default, show the text
 
        const thisName = 'ShowRedirectPageText';
        const thisType = 'other';  // must use this type in order to display useful info in Special:Version
 
        var $found;
        var $actionState;
 
        public static function &singleton( )
        { return parent::singleton( ); }
 
        // Our class defines magic words: tell it to our helper class.
        public function ShowRedirectPageText() 
        { 
                parent::__construct( ); 
 
                global $wgExtensionCredits;
                $wgExtensionCredits[self::thisType][] = array( 
                        'name'    => self::thisName, 
                        'version' => '$Id: ShowRedirectPageText.php 172 2007-06-15 19:39:10Z jeanlou.dupont $',
                        'author'  => 'Jean-Lou Dupont', 
                );
        }
 
        public function setup()
        {
                parent::setup();
 
                $this->found = null;
                $this->actionState = self::defaultAction;
        }
        public function setActionState( $s ) { $this->actionState = $s ;}
 
        public function hArticleViewHeader( &$article )
        {
                // check if we are dealing with a redirect page.
                $this->found = Title::newFromRedirect( $article->getContent() );
 
                return true;            
        }
        public function hOutputPageParserOutput( &$op, $parserOutput )
        {
                // are we dealing with a redirect page?
                if ( ( !is_object($this->found) ) || ( !$this->actionState ) )return true;
 
                // take care of re-entrancy
                if ( !is_object($this->found) ) return true;
                $this->found = null;
 
                $op->addParserOutput( $parserOutput );
                return true;    
        }
 
} // end class definition.
?>

See also [edit]

This extension is part of the BizzWiki package Extension:BizzWiki.