Difference between revisions of "Extension:DisplayFilter.php"
m |
({{AddJavaScript}}, const ver etc) |
||
Line 4: | Line 4: | ||
# - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:Extension|DisplayFilter}} | # - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category:Extensions created with Template:Extension|DisplayFilter}} | ||
− | + | if (!defined('MEDIAWIKI')) die('Not an entry point.'); | |
+ | |||
+ | define('DISPLAYFILTER_VERSION','0.0.1, 2007-05-10'); | ||
+ | |||
$wgDisplayFilterMagic = "filter"; | $wgDisplayFilterMagic = "filter"; | ||
$wgExtensionFunctions[] = 'wfSetupDisplayFilter'; | $wgExtensionFunctions[] = 'wfSetupDisplayFilter'; | ||
Line 10: | Line 13: | ||
$wgExtensionCredits['parserhook'][] = array( | $wgExtensionCredits['parserhook'][] = array( | ||
− | 'name' | + | 'name' => 'Display Filter', |
− | 'author' => '[http://www.organicdesign.co.nz/nad User:Nad]', | + | 'author' => '[http://www.organicdesign.co.nz/nad User:Nad]', |
− | 'url' | + | 'description' => 'Create links which control visibility of areas by CSS class', |
+ | 'url' => 'http://www.mediawiki.org/wiki/Extension:Display_Filter', | ||
+ | 'version' => DISPLAYFILTER_VERSION | ||
); | ); | ||
Line 31: | Line 36: | ||
$wgParser->setHook($wgDisplayFilterTag,array($this,'tagFoo')); | $wgParser->setHook($wgDisplayFilterTag,array($this,'tagFoo')); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
Line 62: | Line 62: | ||
); | ); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
Line 87: | Line 80: | ||
return true; | return true; | ||
} | } | ||
+ | |||
+ | {{AddJavaScript}} | ||
?> | ?> |
Revision as of 05:39, 10 May 2007
<?php
- Extension:Display Filter
{{#Security:*|dev}}{{#Security:view|*}}Template:Php
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: User:NadCategory:Extensions created with Template:Extension
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('DISPLAYFILTER_VERSION','0.0.1, 2007-05-10');
$wgDisplayFilterMagic = "filter"; $wgExtensionFunctions[] = 'wfSetupDisplayFilter'; $wgHooks['LanguageGetMagic'][] = 'wfDisplayFilterLanguageGetMagic';
$wgExtensionCredits['parserhook'][] = array( 'name' => 'Display Filter', 'author' => 'User:Nad', 'description' => 'Create links which control visibility of areas by CSS class', 'url' => 'http://www.mediawiki.org/wiki/Extension:Display_Filter', 'version' => DISPLAYFILTER_VERSION );
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'));
}
# 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 );
}
# Needed in some versions to prevent Special:Version from breaking function __toString() { return 'Display Filter'; }
}
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupDisplayFilter() { global $wgDisplayFilter; $wgDisplay Filter = new DisplayFilter(); }
- 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; }