Difference between revisions of "Extension:DisplayFilter.php"

From Organic Design wiki
(start from template)
 
m
Line 4: Line 4:
 
# - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:Extension}}
 
# - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:Extension}}
 
   
 
   
$wgDisplay FilterVersion      = "0.0.0/2007-05-07";
+
$wgDisplayFilterVersion        = "0.0.0/2007-05-07";
$wgDisplay FilterMagic        = "filter";
+
$wgDisplayFilterMagic          = "filter";
$wgExtensionFunctions[]        = 'wfSetupDisplay Filter';
+
$wgExtensionFunctions[]        = 'wfSetupDisplayFilter';
$wgHooks['LanguageGetMagic'][] = 'wfDisplay FilterLanguageGetMagic';
+
$wgHooks['LanguageGetMagic'][] = 'wfDisplayFilterLanguageGetMagic';
 
   
 
   
 
$wgExtensionCredits['parserhook'][] = array(
 
$wgExtensionCredits['parserhook'][] = array(
Line 15: Line 15:
 
);
 
);
 
   
 
   
class Display Filter {
+
class DisplayFilter {
 
   
 
   
 
# Properties
 
# Properties
Line 22: Line 22:
 
   
 
   
 
# Constructor
 
# Constructor
function Display Filter() {
+
function DisplayFilter() {
global $wgHooks,$wgParser,$wgDisplay FilterMagic,$wgDisplay FilterTag,$wgJavaScriptFunctions;
+
global $wgHooks,$wgParser,$wgDisplayFilterMagic,$wgDisplay FilterTag,$wgJavaScriptFunctions;
 
   
 
   
 
# Add the parser-function
 
# Add the parser-function
$wgParser->setFunctionHook($wgDisplay FilterMagic,array($this,'magicFilter'));
+
$wgParser->setFunctionHook($wgDisplayFilterMagic,array($this,'magicFilter'));
 
   
 
   
 
# Add the tagHook
 
# Add the tagHook
$wgParser->setHook($wgDisplay FilterTag,array($this,'tagFoo'));
+
$wgParser->setHook($wgDisplayFilterTag,array($this,'tagFoo'));
 
   
 
   
 
# This allows JS functions to be added to the global $wgJavaScriptFunctions array for inclusion in the output page
 
# This allows JS functions to be added to the global $wgJavaScriptFunctions array for inclusion in the output page
Line 76: Line 76:
 
   
 
   
 
# Called from $wgExtensionFunctions array when initialising extensions
 
# Called from $wgExtensionFunctions array when initialising extensions
function wfSetupDisplay Filter() {
+
function wfSetupDisplayFilter() {
global $wgDisplay Filter;
+
global $wgDisplayFilter;
$wgDisplay Filter = new Display Filter();
+
$wgDisplay Filter = new DisplayFilter();
 
}
 
}
 
   
 
   
 
# Needed in MediaWiki >1.8.0 for magic word hooks to work properly
 
# Needed in MediaWiki >1.8.0 for magic word hooks to work properly
function wfDisplay FilterLanguageGetMagic(&$magicWords,$langCode = 0) {
+
function wfDisplayFilterLanguageGetMagic(&$magicWords,$langCode = 0) {
global $wgDisplay FilterMagic;
+
global $wgDisplayFilterMagic;
$magicWords[$wgDisplay FilterMagic] = array(0,$wgDisplay FilterMagic);
+
$magicWords[$wgDisplayFilterMagic] = array(0,$wgDisplayFilterMagic);
 
return true;
 
return true;
 
}
 
}
 
?>
 
?>

Revision as of 01:18, 8 May 2007

<?php

  1. Extension:Display Filter
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

{{#Security:*|dev}}{{#Security:view|*}}Template:Php

  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:NadCategory:Extensions created with Template:Extension

$wgDisplayFilterVersion = "0.0.0/2007-05-07"; $wgDisplayFilterMagic = "filter"; $wgExtensionFunctions[] = 'wfSetupDisplayFilter'; $wgHooks['LanguageGetMagic'][] = 'wfDisplayFilterLanguageGetMagic';

$wgExtensionCredits['parserhook'][] = array( 'name' => 'Display Filter', 'author' => 'User:Nad', 'url' => 'http://www.mediawiki.org/wiki/Extension:Display_Filter' );

class DisplayFilter {

# Properties var $prop1: 'default value'; var $prop2: 'default value';

# Constructor function DisplayFilter() { global $wgHooks,$wgParser,$wgDisplayFilterMagic,$wgDisplay FilterTag,$wgJavaScriptFunctions;

# Add the parser-function $wgParser->setFunctionHook($wgDisplayFilterMagic,array($this,'magicFilter'));

# Add the tagHook $wgParser->setHook($wgDisplayFilterTag,array($this,'tagFoo'));

# This allows JS functions to be added to the global $wgJavaScriptFunctions array for inclusion in the output page if (!is_array($wgJavaScriptFunctions)) { $wgJavaScriptFunctions = array(); $wgHooks['OutputPageBeforeHTML'][] = $this; } }

# Expand the filter-magic function magicFilter(&$parser) {

# Populate $argv with both named and numeric parameters $argv = array(); foreach (func_get_args() as $arg) if (!is_object($arg)) { if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $argv[] = $arg; }

# Build text of expaded result $args = ; foreach ($argv as $k => $v) $args .= "*$k: $v\n"; $text = "=== magicFilter(): ===\n$args";

# Return result with available parser flags return array( $text, found => true, nowiki => false, noparse => false, noargs => false, isHTML => false );

}

# Add any JS functions to the output page function onOutputPageBeforeHTML(&$out) { global $wgJavaScriptFunctions; foreach ($wgJavaScriptFunctions as $js) $out->addScript("\n<script type=\"text/javascript\">$js</script>\n"); return true; }

# Needed in some versions to prevent Special:Version from breaking function __toString() { return 'Display Filter'; }

	}

  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupDisplayFilter() { global $wgDisplayFilter; $wgDisplay Filter = new DisplayFilter(); }

  1. Needed in MediaWiki >1.8.0 for magic word hooks to work properly

function wfDisplayFilterLanguageGetMagic(&$magicWords,$langCode = 0) { global $wgDisplayFilterMagic; $magicWords[$wgDisplayFilterMagic] = array(0,$wgDisplayFilterMagic); return true; } ?>