r36920 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36919‎ | r36920 | r36921 >
Date:15:13, 2 July 2008
Author:daniel
Status:old
Tags:
Comment:
optionally show category tree in the sidebar (requires skin update from r36917)
Modified paths:
  • /trunk/extensions/CategoryTree/CategoryTree.i18n.php (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTree.php (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTreeFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php
@@ -340,7 +340,7 @@
341341 * Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to
342342 * load CategoryTreeFunctions.php on demand.
343343 */
344 - function getTag( &$parser, $category, $hideroot = false, $attr, $depth=1 ) {
 344+ function getTag( $parser, $category, $hideroot = false, $attr, $depth=1 ) {
345345 global $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag;
346346 static $uniq = 0;
347347
@@ -348,7 +348,7 @@
349349 if ( $category === '' ) {
350350 return false;
351351 }
352 - if ( $wgCategoryTreeDisableCache && !$wgCategoryTreeDynamicTag ) {
 352+ if ( $parser && $wgCategoryTreeDisableCache && !$wgCategoryTreeDynamicTag ) {
353353 $parser->disableCache();
354354 }
355355 $title = self::makeTitle( $category );
Index: trunk/extensions/CategoryTree/CategoryTree.i18n.php
@@ -15,7 +15,8 @@
1616 */
1717 $messages['en'] = array(
1818 'categorytree' => 'CategoryTree',
19 - 'categorytree-tab' => 'Tree',
 19+ 'categorytree-portlet' => 'Categories',
 20+# 'categorytree-tab' => 'Tree',
2021 'categorytree-legend' => 'Show category tree',
2122 'categorytree-desc' => 'Dynamically navigate the [[Special:CategoryTree|category structure]]',
2223 'categorytree-header' => 'Enter a category name to see its contents as a tree structure.
@@ -592,6 +593,7 @@
593594 */
594595 $messages['de'] = array(
595596 'categorytree' => 'Kategorienbaum',
 597+ 'categorytree-portlet' => 'Kategorien',
596598 'categorytree-tab' => 'Baum',
597599 'categorytree-legend' => 'Zeige Kategorienbaum',
598600 'categorytree-desc' => 'Dynamische Navigation für die [[Special:CategoryTree|Kategorien-Struktur]]',
Index: trunk/extensions/CategoryTree/CategoryTree.php
@@ -62,6 +62,7 @@
6363 # Set $wgCategoryTreeForceHeaders to true to force the JS and CSS headers for CategoryTree to be included on every page.
6464 # May be usefull for using CategoryTree from within system messages, in the sidebar, or a custom skin.
6565 $wgCategoryTreeForceHeaders = false;
 66+$wgCategoryTreeSidebarRoot = NULL;
6667
6768 $wgCategoryTreeExtPath = '/extensions/CategoryTree';
6869 $wgCategoryTreeVersion = '2'; #NOTE: bump this when you change the CSS or JS files!
@@ -83,6 +84,14 @@
8485 $wgCategoryTreeSpecialPageOptions = array(); #Options to be used for Special:CategoryTree
8586 $wgCategoryTreeSpecialPageOptions['showcount'] = true;
8687
 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+
8796 /**
8897 * Register extension setup hook and credits
8998 */
@@ -132,7 +141,7 @@
133142 global $wgUseAjax, $wgHooks, $wgOut;
134143 global $wgCategoryTreeDefaultOptions, $wgCategoryTreeDefaultMode, $wgCategoryTreeOmitNamespace;
135144 global $wgCategoryTreeCategoryPageOptions, $wgCategoryTreeCategoryPageMode;
136 - global $wgCategoryTreeForceHeaders;
 145+ global $wgCategoryTreeSidebarRoot, $wgCategoryTreeForceHeaders;
137146
138147 # Abort if AJAX is not enabled
139148 if ( !$wgUseAjax ) {
@@ -140,6 +149,11 @@
141150 return;
142151 }
143152
 153+ if ( $wgCategoryTreeSidebarRoot ) {
 154+ $wgCategoryTreeForceHeaders = true; # needed on every page anyway
 155+ $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'efCategoryTreeSkinTemplateOutputPageBeforeExec';
 156+ }
 157+
144158 if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
145159 $wgHooks['ParserFirstCallInit'][] = 'efCategoryTreeSetHooks';
146160 } else {
@@ -274,23 +288,40 @@
275289 }
276290
277291 /**
 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+/**
278306 * Entry point for the <categorytree> tag parser hook.
279307 * This loads CategoryTreeFunctions.php and calls CategoryTree::getTag()
280308 */
281 -function efCategoryTreeParserHook( $cat, $argv, &$parser ) {
282 - global $wgCategoryTreeDefaultMode;
 309+function efCategoryTreeParserHook( $cat, $argv, $parser = NULL ) {
 310+ global $wgCategoryTreeDefaultMode, $wgOut;
283311
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+ }
285318
286 - static $initialized = false;
287 -
288319 $ct = new CategoryTree( $argv );
289320
290321 $attr = Sanitizer::validateTagAttributes( $argv, 'div' );
291322
292323 $hideroot = isset( $argv[ 'hideroot' ] ) ? CategoryTree::decodeBoolean( $argv[ 'hideroot' ] ) : null;
293324 $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;
295326
296327 $depth = efCategoryTreeCapDepth( $ct->getOption( 'mode' ), $depthArg );
297328 if ( $onlyroot ) $depth = 0;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r36917Allow raw HTML blocks in data['sidebar'] array. This provides a simple ways f...daniel14:45, 2 July 2008

Status & tagging log