| Index: trunk/extensions/CategoryTree/CategoryTree.php | ||
| — | — | @@ -81,7 +81,7 @@ |
| 82 | 82 | $wgHooks['OutputPageParserOutput'][] = 'efCategoryTreeParserOutput'; |
| 83 | 83 | $wgHooks['LoadAllMessages'][] = 'efInjectCategoryTreeMessages'; |
| 84 | 84 | $wgHooks['ArticleFromTitle'][] = 'efCategoryTreeArticleFromTitle'; |
| 85 | ||
| 85 | +$wgHooks['LanguageGetMagic'][] = 'efCategoryTreeGetMagic'; | |
| 86 | 86 | /** |
| 87 | 87 | * register Ajax function |
| 88 | 88 | */ |
| — | — | @@ -99,10 +99,27 @@ |
| 100 | 100 | return; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | ||
| 103 | + if ( $wgCategoryTreeAllowTag ) { | |
| 104 | + $wgParser->setHook( 'categorytree' , 'efCategoryTreeParserHook' ); | |
| 105 | + $wgParser->setFunctionHook( 'categorytree' , 'efCategoryTreeParserFunction' ); | |
| 106 | + } | |
| 104 | 107 | } |
| 105 | 108 | |
| 106 | 109 | /** |
| 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 | +/** | |
| 107 | 124 | * Entry point for Ajax, registered in $wgAjaxExportList. |
| 108 | 125 | * This loads CategoryTreeFunctions.php and calls CategoryTree::ajax() |
| 109 | 126 | */ |
| — | — | @@ -164,6 +181,38 @@ |
| 165 | 182 | } |
| 166 | 183 | |
| 167 | 184 | /** |
| 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 | +/** | |
| 168 | 217 | * Entry point for the <categorytree> tag parser hook. |
| 169 | 218 | * This loads CategoryTreeFunctions.php and calls CategoryTree::getTag() |
| 170 | 219 | */ |
| Index: trunk/extensions/CategoryTree/README | ||
| — | — | @@ -48,9 +48,9 @@ |
| 49 | 49 | parsing the HTML of category pages. |
| 50 | 50 | |
| 51 | 51 | The custom tag is called <categorytree>. For example, if you put |
| 52 | ||
| 53 | ||
| 54 | ||
| 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: | |
| 55 | 55 | |
| 56 | 56 | * hideroot - set this to "on" to hide the "root" node of the tree, i.e. |
| 57 | 57 | the mention of category Foo from the example. |
| — | — | @@ -64,7 +64,11 @@ |
| 65 | 65 | |
| 66 | 66 | * style - can be used to specify any CSS styles you would like for the |
| 67 | 67 | 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 | + | |
| 69 | 73 | The special page is called Special:CategoryTree; there you can enter the |
| 70 | 74 | name of a category and then browse it's content. The CategoryTree |
| 71 | 75 | extension also adds a tab for this special page to every category page. |
US