Difference between revisions of "Extension:DisplayFilter.php"
(don't allow quotes or backslashes in arg names) |
m |
||
Line 71: | Line 71: | ||
global $wgDisplayFilter; | global $wgDisplayFilter; | ||
$wgDisplayFilter = new DisplayFilter(); | $wgDisplayFilter = new DisplayFilter(); | ||
− | + | $wgDisplayFilter->addJS(); # addScript doesn't seem to work from within parser | |
} | } | ||
Revision as of 10:25, 15 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.2, 2007-05-15');
$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 );
- Keep track of JavaScript added to page to avoid doubleups
if (!isset($wgJS)) $wgJS = array();
class DisplayFilter {
# Constructor function DisplayFilter() { global $wgParser,$wgDisplayFilterMagic; $wgParser->setFunctionHook($wgDisplayFilterMagic,array($this,'filter')); }
# Expand the filter-magic function filter(&$parser) { $this->addJS(); $argv = array(); foreach (func_get_args() as $arg) if (!is_object($arg)) { $arg = ereg_replace('[\\\\\'"]',,$arg); if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $argv[] = $arg; } $anchor = array_shift($argv); $atts = array(); $atts['href'] = "javascript:filter(['".join("','",$argv)."'])"; $link = '<a'; foreach ($atts as $k => $v) $link .= " $k=\"$v\""; $link .= ">$anchor</a>"; return array($link,'noparse' => true, 'isHTML' => true); }
# Add the javascript to the output object if not added yet and there is at least one tree function addJS() { global $wgOut,$wgJS,$wgJsMimeType; if (isset($wgJS['DisplayFilter'])) return; $wgJS['DisplayFilter'] = true; $wgOut->addScript('<script type="'.$wgJsMimeType.'"> function filter(args) { if (args.length == 1) { } else { } } </script>'); }
# 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; $wgDisplayFilter = new DisplayFilter(); $wgDisplayFilter->addJS(); # addScript doesn't seem to work from within parser }
- 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; } ?>