Open main menu

Extension:SessionMagicWords

MediaWiki extensions manual
OOjs UI icon advanced.svg
SessionMagicWords
Release status: unmaintained
Implementation Variable
Description Magic Words from $_SESSION["wsMagicWords"]
Author(s) Alexandre Porto da Silva (Alexandre Portotalk)
Latest version 11.12.26
License GPL
Download copy/paste
Translate the SessionMagicWords extension if it is available at translatewiki.net
Check usage and version matrix.

Contents

InstallEdit

Copy & paste in: /path/to/wiki/extensions/SessionMagicWords/SessionMagicWords.php

Include on LocalSettings.php:

# SessionMagicWords
# More info: http://www.mediawiki.org/wiki/Extension:SessionMagicWords
include_once( "$IP/extensions/SessionMagicWords/SessionMagicWords.php" );
# mandatory: $wgSessionMagicWordsCall or $wgSessionMagicWordsList
$wgSessionMagicWordsList = array(); # used before $wgSessionMagicWordsCall
$wgSessionMagicWordsCall = '';      # call a user function if $wgSessionMagicWordsList is empty
# optional:
$wgSessionMagicWordsId = "wsMagicWords";

SourceEdit

SessionMagicWords.phpEdit

<?php
/**
 * SessionMagicWords - Magic Words from $_SESSION["wsMagicWords"].
 * Based on: http://www.mediawiki.org/wiki/Extension:MyVariables
 * 
 * To activate this extension, add the following into your LocalSettings.php file:
//start-SessionMagicWords:
# SessionMagicWords
# More info: http://www.mediawiki.org/wiki/Extension:SessionMagicWords
include_once( "$IP/extensions/SessionMagicWords/SessionMagicWords.php" );
# mandatory: $wgSessionMagicWordsCall or $wgSessionMagicWordsList
$wgSessionMagicWordsList = array(); # used before $wgSessionMagicWordsCall
$wgSessionMagicWordsCall = '';      # call a user function if $wgSessionMagicWordsList is empty
# optional:
$wgSessionMagicWordsId = "wsMagicWords";
//end-SessionMagicWords.
 * 
 * @ingroup Extensions
 * @author Alexandre Porto da Silva
 * @link http://www.mediawiki.org/wiki/Extension:SessionMagicWords
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 */

/**
 * Protect against register_globals vulnerabilities.
 * This line must be present before any global variable is referenced.
 */
if( !defined( 'MEDIAWIKI' ) ) {
        echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
        die( -1 );
}

define( 'SESSIONMAGICWORDS_VERSION', '11.12.26' );

# Extension credits that will show up on Special:Version    
$wgExtensionCredits['SessionMagicWords'][] = array(
	'path'           => __FILE__,
	'name'           => 'SessionMagicWords',
	'version'        => SESSIONMAGICWORDS_VERSION,
	'author'         => 'Alexandre Porto da Silva', 
	'url'            => 'http://www.mediawiki.org/wiki/Extension:SessionMagicWords',
	'descriptionmsg' => 'Magic Words from $_SESSION["wsMagicWords"].',
	'description'    => 'Magic Words from $_SESSION["wsMagicWords"].'
);

$wgSessionMagicWordsList = array();
$wgSessionMagicWordsCall = '';
$wgSessionMagicWordsId = 'wsMagicWords';

class SessionMagicWords {

	static function getList() {
		global $wgSessionMagicWordsList;
		if ( !$wgSessionMagicWordsList ) {
			global $wgSessionMagicWordsCall;
			if ( is_callable( $wgSessionMagicWordsCall ) ) {
				$retval = call_user_func( $wgSessionMagicWordsCall );
				$wgSessionMagicWordsList = is_array( $retval ) ? array_unique( $retval ) : array();
			}
		}
		return $wgSessionMagicWordsList;
	}

	static function MagicWordMagicWords( &$magicWords ) {
		# http://www.mediawiki.org/wiki/Manual:Hooks/MagicWordMagicWords
		$list = self::getList();
		foreach( $list as $variable ) {
			$magicWords[] = $variable;
		}
		return true;
	}

	static function MagicWordwgVariableIDs( &$aCustomVariableIds ) {
		# http://www.mediawiki.org/wiki/Manual:Hooks/MagicWordwgVariableIDs
		$list = self::getList();
		foreach( $list as $variable ) {
			$aCustomVariableIds[] = constant( $variable );
		}
		return true;
	}

	static function LanguageGetMagic( array &$magicWords, $langCode ) {
		# http://www.mediawiki.org/wiki/Manual:Hooks/LanguageGetMagic
		$list = self::getList();
		foreach( $list as $variable ) {
			$magicWords[$variable] = array( 0, $variable );
		}
		return true;
	}

	static function ParserGetVariableValueSwitch( &$parser, &$cache, &$magicWordId, &$ret ) {
		# http://www.mediawiki.org/wiki/Manual:Hooks/ParserGetVariableValueSwitch
		global $wgSessionMagicWordsId;
		if ( isset( $_SESSION[$wgSessionMagicWordsId][$magicWordId] ) ) {
			$parser->disableCache(); # Mark this content as uncacheable
			$ret = $_SESSION[$wgSessionMagicWordsId][$magicWordId];
		}
		return true;
	}
}

$wgHooks['LanguageGetMagic'][] = 'SessionMagicWords::LanguageGetMagic';
$wgHooks['MagicWordMagicWords'][] = 'SessionMagicWords::MagicWordMagicWords';
$wgHooks['MagicWordwgVariableIDs'][] = 'SessionMagicWords::MagicWordwgVariableIDs';
$wgHooks['ParserGetVariableValueSwitch'][] = 'SessionMagicWords::ParserGetVariableValueSwitch';

See alsoEdit