r25825 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25824‎ | r25825 | r25826 >
Date:10:23, 13 September 2007
Author:daniel
Status:old
Tags:
Comment:
support parser-function syntax
Modified paths:
  • /trunk/extensions/CategoryTree/CategoryTree.php (modified) (history)
  • /trunk/extensions/CategoryTree/README (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryTree/CategoryTree.php
@@ -81,7 +81,7 @@
8282 $wgHooks['OutputPageParserOutput'][] = 'efCategoryTreeParserOutput';
8383 $wgHooks['LoadAllMessages'][] = 'efInjectCategoryTreeMessages';
8484 $wgHooks['ArticleFromTitle'][] = 'efCategoryTreeArticleFromTitle';
85 -
 85+$wgHooks['LanguageGetMagic'][] = 'efCategoryTreeGetMagic';
8686 /**
8787 * register Ajax function
8888 */
@@ -99,10 +99,27 @@
100100 return;
101101 }
102102
103 - if ( $wgCategoryTreeAllowTag ) $wgParser->setHook( 'categorytree' , 'efCategoryTreeParserHook' );
 103+ if ( $wgCategoryTreeAllowTag ) {
 104+ $wgParser->setHook( 'categorytree' , 'efCategoryTreeParserHook' );
 105+ $wgParser->setFunctionHook( 'categorytree' , 'efCategoryTreeParserFunction' );
 106+ }
104107 }
105108
106109 /**
 110+* Hook magic word
 111+*/
 112+function efCategoryTreeGetMagic( &$magicWords, $langCode ) {
 113+ global $wgUseAjax, $wgCategoryTreeAllowTag;
 114+
 115+ if ( $wgUseAjax && $wgCategoryTreeAllowTag ) {
 116+ //XXX: should we allow a local alias?
 117+ $magicWords['categorytree'] = array( 0, 'categorytree' );
 118+ }
 119+
 120+ return true;
 121+}
 122+
 123+/**
107124 * Entry point for Ajax, registered in $wgAjaxExportList.
108125 * This loads CategoryTreeFunctions.php and calls CategoryTree::ajax()
109126 */
@@ -164,6 +181,38 @@
165182 }
166183
167184 /**
 185+ * Entry point for the {{#categorytree}} tag parser function.
 186+ * This is a wrapper around efCategoryTreeParserHook
 187+ */
 188+function efCategoryTreeParserFunction( &$parser ) {
 189+ $params = func_get_args();
 190+ array_shift( $params ); //first is &$parser, strip it
 191+
 192+ //first user-supplied parameter must be category name
 193+ if ( !$params ) return ''; //no category specified, return nothing
 194+ $cat = array_shift( $params );
 195+
 196+ //build associative arguments from flat parameter list
 197+ $argv = array();
 198+ foreach ( $params as $p ) {
 199+ if ( preg_match('/^\s*(\S.*?)\s*=\s*(.*?)\s*$/', $p, $m) ) {
 200+ $k = $m[1];
 201+ $v = $m[2];
 202+ }
 203+ else {
 204+ $k = trim($p);
 205+ $v = true;
 206+ }
 207+
 208+ $argv[$k] = $v;
 209+ }
 210+
 211+ //now handle just like a <categorytree> tag
 212+ $html = efCategoryTreeParserHook( $cat, $argv, $parser );
 213+ return array( $html, 'noargs' => true, 'noparse' => true ); //XXX: isHTML would be right logically, but it causes extra blank lines
 214+}
 215+
 216+/**
168217 * Entry point for the <categorytree> tag parser hook.
169218 * This loads CategoryTreeFunctions.php and calls CategoryTree::getTag()
170219 */
Index: trunk/extensions/CategoryTree/README
@@ -48,9 +48,9 @@
4949 parsing the HTML of category pages.
5050
5151 The custom tag is called <categorytree>. For example, if you put
52 -<categorytree>Foo</categorytree> on a wiki page, it will show the contents
53 -of category Foo as a dynamic tree on that page. The tag accepts the following
54 -attributes, using a HTML-like syntax:
 52+<categorytree mode="pages">Foo</categorytree> on a wiki page, it will show
 53+the contents of category Foo as a dynamic tree on that page. The tag accepts
 54+the following attributes, using a HTML-like syntax:
5555
5656 * hideroot - set this to "on" to hide the "root" node of the tree, i.e.
5757 the mention of category Foo from the example.
@@ -64,7 +64,11 @@
6565
6666 * style - can be used to specify any CSS styles you would like for the
6767 tree.
68 -
 68+
 69+Alternatively to the <categorytree> tag, parser-function syntax can also be
 70+used, e.g {{#categorytree:Foo|hideroot=yes}}. This syntax allows the use of
 71+magic variables, templates and template parameters for the category name.
 72+
6973 The special page is called Special:CategoryTree; there you can enter the
7074 name of a category and then browse it's content. The CategoryTree
7175 extension also adds a tab for this special page to every category page.

Status & tagging log