Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php |
— | — | @@ -340,7 +340,7 @@ |
341 | 341 | * Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to |
342 | 342 | * load CategoryTreeFunctions.php on demand. |
343 | 343 | */ |
344 | | - function getTag( &$parser, $category, $hideroot = false, $attr, $depth=1 ) { |
| 344 | + function getTag( $parser, $category, $hideroot = false, $attr, $depth=1 ) { |
345 | 345 | global $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag; |
346 | 346 | static $uniq = 0; |
347 | 347 | |
— | — | @@ -348,7 +348,7 @@ |
349 | 349 | if ( $category === '' ) { |
350 | 350 | return false; |
351 | 351 | } |
352 | | - if ( $wgCategoryTreeDisableCache && !$wgCategoryTreeDynamicTag ) { |
| 352 | + if ( $parser && $wgCategoryTreeDisableCache && !$wgCategoryTreeDynamicTag ) { |
353 | 353 | $parser->disableCache(); |
354 | 354 | } |
355 | 355 | $title = self::makeTitle( $category ); |
Index: trunk/extensions/CategoryTree/CategoryTree.i18n.php |
— | — | @@ -15,7 +15,8 @@ |
16 | 16 | */ |
17 | 17 | $messages['en'] = array( |
18 | 18 | 'categorytree' => 'CategoryTree', |
19 | | - 'categorytree-tab' => 'Tree', |
| 19 | + 'categorytree-portlet' => 'Categories', |
| 20 | +# 'categorytree-tab' => 'Tree', |
20 | 21 | 'categorytree-legend' => 'Show category tree', |
21 | 22 | 'categorytree-desc' => 'Dynamically navigate the [[Special:CategoryTree|category structure]]', |
22 | 23 | 'categorytree-header' => 'Enter a category name to see its contents as a tree structure. |
— | — | @@ -592,6 +593,7 @@ |
593 | 594 | */ |
594 | 595 | $messages['de'] = array( |
595 | 596 | 'categorytree' => 'Kategorienbaum', |
| 597 | + 'categorytree-portlet' => 'Kategorien', |
596 | 598 | 'categorytree-tab' => 'Baum', |
597 | 599 | 'categorytree-legend' => 'Zeige Kategorienbaum', |
598 | 600 | 'categorytree-desc' => 'Dynamische Navigation für die [[Special:CategoryTree|Kategorien-Struktur]]', |
Index: trunk/extensions/CategoryTree/CategoryTree.php |
— | — | @@ -62,6 +62,7 @@ |
63 | 63 | # Set $wgCategoryTreeForceHeaders to true to force the JS and CSS headers for CategoryTree to be included on every page. |
64 | 64 | # May be usefull for using CategoryTree from within system messages, in the sidebar, or a custom skin. |
65 | 65 | $wgCategoryTreeForceHeaders = false; |
| 66 | +$wgCategoryTreeSidebarRoot = NULL; |
66 | 67 | |
67 | 68 | $wgCategoryTreeExtPath = '/extensions/CategoryTree'; |
68 | 69 | $wgCategoryTreeVersion = '2'; #NOTE: bump this when you change the CSS or JS files! |
— | — | @@ -83,6 +84,14 @@ |
84 | 85 | $wgCategoryTreeSpecialPageOptions = array(); #Options to be used for Special:CategoryTree |
85 | 86 | $wgCategoryTreeSpecialPageOptions['showcount'] = true; |
86 | 87 | |
| 88 | +$wgCategoryTreeSidebarOptions = array(); #Options to be used in the sidebar (for use with $wgCategoryTreeSidebarRoot) |
| 89 | +$wgCategoryTreeSidebarOptions['mode'] = CT_MODE_CATEGORIES; |
| 90 | +$wgCategoryTreeSidebarOptions['hideprefix'] = CT_HIDEPREFIX_CATEGORIES; |
| 91 | +$wgCategoryTreeSidebarOptions['showcount'] = false; |
| 92 | +$wgCategoryTreeSidebarOptions['hideroot'] = true; |
| 93 | +$wgCategoryTreeSidebarOptions['namespaces'] = false; |
| 94 | +$wgCategoryTreeSidebarOptions['depth'] = 1; |
| 95 | + |
87 | 96 | /** |
88 | 97 | * Register extension setup hook and credits |
89 | 98 | */ |
— | — | @@ -132,7 +141,7 @@ |
133 | 142 | global $wgUseAjax, $wgHooks, $wgOut; |
134 | 143 | global $wgCategoryTreeDefaultOptions, $wgCategoryTreeDefaultMode, $wgCategoryTreeOmitNamespace; |
135 | 144 | global $wgCategoryTreeCategoryPageOptions, $wgCategoryTreeCategoryPageMode; |
136 | | - global $wgCategoryTreeForceHeaders; |
| 145 | + global $wgCategoryTreeSidebarRoot, $wgCategoryTreeForceHeaders; |
137 | 146 | |
138 | 147 | # Abort if AJAX is not enabled |
139 | 148 | if ( !$wgUseAjax ) { |
— | — | @@ -140,6 +149,11 @@ |
141 | 150 | return; |
142 | 151 | } |
143 | 152 | |
| 153 | + if ( $wgCategoryTreeSidebarRoot ) { |
| 154 | + $wgCategoryTreeForceHeaders = true; # needed on every page anyway |
| 155 | + $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'efCategoryTreeSkinTemplateOutputPageBeforeExec'; |
| 156 | + } |
| 157 | + |
144 | 158 | if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { |
145 | 159 | $wgHooks['ParserFirstCallInit'][] = 'efCategoryTreeSetHooks'; |
146 | 160 | } else { |
— | — | @@ -274,23 +288,40 @@ |
275 | 289 | } |
276 | 290 | |
277 | 291 | /** |
| 292 | + * Hook implementation for injecting a category tree into the sidebar. |
| 293 | + * Registered automatically if $wgCategoryTreeSidebarRoot is set to a category name. |
| 294 | + */ |
| 295 | +function efCategoryTreeSkinTemplateOutputPageBeforeExec( &$skin, &$tpl ) { |
| 296 | + global $wgCategoryTreeSidebarRoot, $wgCategoryTreeSidebarOptions; |
| 297 | + |
| 298 | + $html = efCategoryTreeParserHook( $wgCategoryTreeSidebarRoot, $wgCategoryTreeSidebarOptions ); |
| 299 | + if ( $html ) $tpl->data['sidebar']['categorytree-portlet'] = $html; //requires MW 1.13, r36917 |
| 300 | + |
| 301 | + return true; |
| 302 | +} |
| 303 | + |
| 304 | + |
| 305 | +/** |
278 | 306 | * Entry point for the <categorytree> tag parser hook. |
279 | 307 | * This loads CategoryTreeFunctions.php and calls CategoryTree::getTag() |
280 | 308 | */ |
281 | | -function efCategoryTreeParserHook( $cat, $argv, &$parser ) { |
282 | | - global $wgCategoryTreeDefaultMode; |
| 309 | +function efCategoryTreeParserHook( $cat, $argv, $parser = NULL ) { |
| 310 | + global $wgCategoryTreeDefaultMode, $wgOut; |
283 | 311 | |
284 | | - $parser->mOutput->mCategoryTreeTag = true; # flag for use by efCategoryTreeParserOutput |
| 312 | + if ( $parser ) { |
| 313 | + $parser->mOutput->mCategoryTreeTag = true; # flag for use by efCategoryTreeParserOutput |
| 314 | + } |
| 315 | + else { |
| 316 | + CategoryTree::setHeaders( $wgOut ); |
| 317 | + } |
285 | 318 | |
286 | | - static $initialized = false; |
287 | | - |
288 | 319 | $ct = new CategoryTree( $argv ); |
289 | 320 | |
290 | 321 | $attr = Sanitizer::validateTagAttributes( $argv, 'div' ); |
291 | 322 | |
292 | 323 | $hideroot = isset( $argv[ 'hideroot' ] ) ? CategoryTree::decodeBoolean( $argv[ 'hideroot' ] ) : null; |
293 | 324 | $onlyroot = isset( $argv[ 'onlyroot' ] ) ? CategoryTree::decodeBoolean( $argv[ 'onlyroot' ] ) : null; |
294 | | - $depthArg = isset( $argv[ 'depth' ] ) ? $argv[ 'depth' ] : null; |
| 325 | + $depthArg = isset( $argv[ 'depth' ] ) ? (int)$argv[ 'depth' ] : null; |
295 | 326 | |
296 | 327 | $depth = efCategoryTreeCapDepth( $ct->getOption( 'mode' ), $depthArg ); |
297 | 328 | if ( $onlyroot ) $depth = 0; |