Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php |
— | — | @@ -113,7 +113,7 @@ |
114 | 114 | * Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to |
115 | 115 | * load CategoryTreeFunctions.php on demand. |
116 | 116 | */ |
117 | | - function getTag( &$parser, $category, $mode, $display = 'expandroot', $style = '' ) { |
| 117 | + function getTag( &$parser, $category, $mode, $display = 'expandroot', $style = '', $depth=1 ) { |
118 | 118 | global $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag; |
119 | 119 | static $uniq = 0; |
120 | 120 | |
— | — | @@ -138,8 +138,8 @@ |
139 | 139 | $html .= wfCloseElement( 'span' ); |
140 | 140 | } |
141 | 141 | else { |
142 | | - if ( $display != 'hideroot' ) $html .= CategoryTree::renderNode( $title, $mode, $display != 'onlyroot', $wgCategoryTreeDynamicTag ); |
143 | | - else if ( !$wgCategoryTreeDynamicTag ) $html .= $this->renderChildren( $title, $mode ); |
| 142 | + if ( $display != 'hideroot' ) $html .= CategoryTree::renderNode( $title, $mode, $depth>0, $wgCategoryTreeDynamicTag, $depth-1 ); |
| 143 | + else if ( !$wgCategoryTreeDynamicTag ) $html .= $this->renderChildren( $title, $mode, $depth-1 ); |
144 | 144 | else { |
145 | 145 | $uniq += 1; |
146 | 146 | $load = 'ct-' . $uniq . '-' . mt_rand( 1, 100000 ); |
— | — | @@ -160,7 +160,7 @@ |
161 | 161 | * Returns a string with an HTML representation of the children of the given category. |
162 | 162 | * $title must be a Title object |
163 | 163 | */ |
164 | | - function renderChildren( &$title, $mode = CT_MODE_CATEGORIES ) { |
| 164 | + function renderChildren( &$title, $mode = CT_MODE_CATEGORIES, $depth=0 ) { |
165 | 165 | global $wgCategoryTreeMaxChildren; |
166 | 166 | |
167 | 167 | $dbr =& wfGetDB( DB_SLAVE ); |
— | — | @@ -198,7 +198,7 @@ |
199 | 199 | while ( $row = $dbr->fetchRow( $res ) ) { |
200 | 200 | #TODO: translation support; ideally added to Title object |
201 | 201 | $t = Title::makeTitle( $row['page_namespace'], $row['page_title'] ); |
202 | | - $s .= $this->renderNode( $t, $mode, false ); |
| 202 | + $s .= $this->renderNode( $t, $mode, $depth>0, false, $depth-1 ); |
203 | 203 | $s .= "\n\t\t"; |
204 | 204 | } |
205 | 205 | |
— | — | @@ -267,7 +267,7 @@ |
268 | 268 | * Returns a string with a HTML represenation of the given page. |
269 | 269 | * $title must be a Title object |
270 | 270 | */ |
271 | | - function renderNode( &$title, $mode = CT_MODE_CATEGORIES, $children = false, $loadchildren = false ) { |
| 271 | + function renderNode( &$title, $mode = CT_MODE_CATEGORIES, $children = false, $loadchildren = false, $depth = 1 ) { |
272 | 272 | global $wgCategoryTreeOmitNamespace; |
273 | 273 | static $uniq = 0; |
274 | 274 | |
— | — | @@ -323,7 +323,7 @@ |
324 | 324 | } |
325 | 325 | |
326 | 326 | $s = ''; |
327 | | - |
| 327 | + |
328 | 328 | #NOTE: things in CategoryTree.js rely on the exact order of tags! |
329 | 329 | # Specifically, the CategoryTreeChildren div must be the first |
330 | 330 | # sibling with nodeName = DIV of the grandparent of the expland link. |
— | — | @@ -343,7 +343,8 @@ |
344 | 344 | $s .= wfCloseElement( 'div' ); |
345 | 345 | $s .= "\n\t\t"; |
346 | 346 | $s .= wfOpenElement( 'div', array( 'class' => 'CategoryTreeChildren', 'style' => $children ? "display:block" : "display:none" ) ); |
347 | | - if ( $children ) $s .= $this->renderChildren( $title, $mode ); |
| 347 | + //HACK here? |
| 348 | + if ( $children ) $s .= $this->renderChildren( $title, $mode, $depth ); |
348 | 349 | $s .= wfCloseElement( 'div' ); |
349 | 350 | $s .= wfCloseElement( 'div' ); |
350 | 351 | |
Index: trunk/extensions/CategoryTree/CategoryTree.php |
— | — | @@ -33,8 +33,14 @@ |
34 | 34 | * $wgCategoryTreeDisableCache - disabled the parser cache for pages with a <categorytree> tag. Default is true. |
35 | 35 | * $wgCategoryTreeUseCache - enable HTTP cache for anon users. Default is false. |
36 | 36 | * $wgCategoryTreeUnifiedView - use unified view on category pages, instead of "tree" or "traditional list". Default is true. |
37 | | - * $wgCategoryTreeOmitNamespace - never show namespace prefix. Default is false |
| 37 | + * $wgCategoryTreeOmitNamespace - never show namespace prefix. Default is false |
| 38 | + |
| 39 | + * $wgCategoryMaxDepth - maximum value for depth argument; can be an |
| 40 | + * integer, or an array of two integers. The first element is the maximum |
| 41 | + * depth for the "pages" and "all" modes; the second is for the categories |
| 42 | + * mode. Ignored if $wgCategoryTreeDynamicTag is true. |
38 | 43 | */ |
| 44 | + |
39 | 45 | $wgCategoryTreeMaxChildren = 200; |
40 | 46 | $wgCategoryTreeAllowTag = true; |
41 | 47 | $wgCategoryTreeDisableCache = true; |
— | — | @@ -42,6 +48,7 @@ |
43 | 49 | $wgCategoryTreeHTTPCache = false; |
44 | 50 | $wgCategoryTreeUnifiedView = true; |
45 | 51 | $wgCategoryTreeOmitNamespace = false; |
| 52 | +$wgCategoryMaxDepth = array(1,2); |
46 | 53 | |
47 | 54 | /** |
48 | 55 | * Register extension setup hook and credits |
— | — | @@ -112,6 +119,45 @@ |
113 | 120 | } |
114 | 121 | |
115 | 122 | /** |
| 123 | + * Internal function to cap depth |
| 124 | + */ |
| 125 | + |
| 126 | +function efCategoryTreeCapDepth( $mode, $depth ) |
| 127 | +{ |
| 128 | + |
| 129 | + if (is_numeric($depth)) |
| 130 | + $depth = intval($depth); |
| 131 | + else |
| 132 | + $depth = 1; |
| 133 | + |
| 134 | + |
| 135 | + global $wgCategoryMaxDepth; |
| 136 | + if (is_array($wgCategoryMaxDepth)) { |
| 137 | + switch($mode) { |
| 138 | + case CT_MODE_PAGES: |
| 139 | + case CT_MODE_ALL: |
| 140 | + $max = isset($wgCategoryMaxDepth[0])?$wgCategoryMaxDepth[0]:1; |
| 141 | + break; |
| 142 | + case CT_MODE_CATEGORIES: |
| 143 | + default: |
| 144 | + $max = isset($wgCategoryMaxDepth[1])?$wgCategoryMaxDepth[1]:1; |
| 145 | + break; |
| 146 | + } |
| 147 | + } elseif (is_numeric($wgCategoryMaxDepth)) { |
| 148 | + $max = $wgCategoryMaxDepth; |
| 149 | + } else { |
| 150 | + wfDebug( 'efCategoryTreeCapDepth: $wgCategoryMaxDepth is invalid.' ); |
| 151 | + $max = 1; |
| 152 | + } |
| 153 | + |
| 154 | + //echo "mode $mode:max is $max\n"; |
| 155 | + if ($depth>$max) |
| 156 | + $depth = $max; |
| 157 | + |
| 158 | + return $depth; |
| 159 | +} |
| 160 | + |
| 161 | +/** |
116 | 162 | * Helper function to convert a string to a boolean value. |
117 | 163 | * Perhaps make this a global function in MediaWiki proper |
118 | 164 | */ |
— | — | @@ -157,12 +203,15 @@ |
158 | 204 | $hideroot = isset( $argv[ 'hideroot' ] ) ? efCategoryTreeAsBool( $argv[ 'hideroot' ] ) : null; |
159 | 205 | $onlyroot = isset( $argv[ 'onlyroot' ] ) ? efCategoryTreeAsBool( $argv[ 'onlyroot' ] ) : null; |
160 | 206 | |
| 207 | + $depth = efCategoryTreeCapDepth($mode,@$argv[ 'depth' ]); |
| 208 | + |
161 | 209 | if ( $onlyroot ) $display = 'onlyroot'; |
162 | 210 | else if ( $hideroot ) $display = 'hideroot'; |
163 | 211 | else $display = 'expandroot'; |
164 | 212 | |
165 | 213 | $ct = new CategoryTree; |
166 | | - return $ct->getTag( $parser, $cat, $mode, $display, $style ); |
| 214 | + return $ct->getTag( $parser, $cat, $mode, $hideroot, $style, $depth ); |
| 215 | + return $ct->getTag( $parser, $cat, $mode, $display, $style, $depth ); |
167 | 216 | } |
168 | 217 | |
169 | 218 | /** |
Index: trunk/extensions/CategoryTree/README |
— | — | @@ -93,5 +93,12 @@ |
94 | 94 | false. Patch contributed by Manuel Schneider |
95 | 95 | <manuel.schneider@wikimedia.ch>, Bug 8011 |
96 | 96 | |
| 97 | +$wgCategoryMaxDepth - maximum value for depth argument; can be an integer, |
| 98 | + or an array of two integers. The first element is the |
| 99 | + maximum depth for the "pages" and "all" modes; the |
| 100 | + second is for the categories mode. Ignored if |
| 101 | + $wgCategoryTreeDynamicTag is true. Patch contributed by |
| 102 | + Steve Sanbeg. |
| 103 | + |
97 | 104 | -------------------------------------------------------------------------- |
98 | | -EOF |
\ No newline at end of file |
| 105 | +EOF |