Index: trunk/extensions/CategoryTree/CategoryPageSubclass.php |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | * Add a subcategory to the internal lists |
20 | 20 | */ |
21 | 21 | function addSubcategory( $title, $sortkey, $pageLength ) { |
22 | | - global $wgContLang, $wgOut, $wgRequest; |
| 22 | + global $wgContLang, $wgOut, $wgRequest, $wgCategoryTreeCategoryPageMode; |
23 | 23 | |
24 | 24 | if ( $wgRequest->getCheck( 'notree' ) ) { |
25 | 25 | return parent::addSubcategory( $title, $sortkey, $pageLength ); |
— | — | @@ -34,13 +34,13 @@ |
35 | 35 | $this->categorytree = new CategoryTree; |
36 | 36 | } |
37 | 37 | |
38 | | - $this->children[] = $this->categorytree->renderNode( $title ); |
| 38 | + $this->children[] = $this->categorytree->renderNode( $title, $wgCategoryTreeCategoryPageMode ); |
39 | 39 | |
40 | 40 | $this->children_start_char[] = $this->getSubcategorySortChar( $title, $sortkey ); |
41 | 41 | } |
42 | 42 | |
43 | 43 | function getSubcategorySection() { |
44 | | - global $wgOut, $wgRequest, $wgCookiePrefix; |
| 44 | + global $wgOut, $wgRequest, $wgCookiePrefix, $wgCategoryTreeCategoryPageMode; |
45 | 45 | |
46 | 46 | if ( $wgRequest->getCheck( 'notree' ) ) { |
47 | 47 | return parent::getSubcategorySection(); |
— | — | @@ -102,7 +102,7 @@ |
103 | 103 | $ct = new CategoryTree; |
104 | 104 | |
105 | 105 | foreach ( $this->child_titles as $title ) { |
106 | | - $r .= $ct->renderNode( $title ); |
| 106 | + $r .= $ct->renderNode( $title, $wgCategoryTreeCategoryPageMode ); |
107 | 107 | } |
108 | 108 | } |
109 | 109 | return $r; |
Index: trunk/extensions/CategoryTree/CategoryTree.php |
— | — | @@ -49,6 +49,8 @@ |
50 | 50 | $wgCategoryTreeOmitNamespace = false; |
51 | 51 | $wgCategoryTreeMaxDepth = array(CT_MODE_PAGES => 1, CT_MODE_ALL => 1, CT_MODE_CATEGORIES => 2); |
52 | 52 | $wgCategoryTreeExtPath = '/extensions/CategoryTree'; |
| 53 | +$wgCategoryTreeDefaultMode = CT_MODE_CATEGORIES; |
| 54 | +$wgCategoryTreeCategoryPageMode = CT_MODE_CATEGORIES; |
53 | 55 | |
54 | 56 | /** |
55 | 57 | * Register extension setup hook and credits |
— | — | @@ -103,7 +105,7 @@ |
104 | 106 | * Entry point for Ajax, registered in $wgAjaxExportList. |
105 | 107 | * This loads CategoryTreeFunctions.php and calls CategoryTree::ajax() |
106 | 108 | */ |
107 | | -function efCategoryTreeAjaxWrapper( $category, $mode = CT_MODE_CATEGORIES ) { |
| 109 | +function efCategoryTreeAjaxWrapper( $category, $mode ) { |
108 | 110 | global $wgCategoryTreeHTTPCache, $wgSquidMaxAge, $wgUseSquid; |
109 | 111 | |
110 | 112 | $ct = new CategoryTree; |
— | — | @@ -165,6 +167,8 @@ |
166 | 168 | * This loads CategoryTreeFunctions.php and calls CategoryTree::getTag() |
167 | 169 | */ |
168 | 170 | function efCategoryTreeParserHook( $cat, $argv, &$parser ) { |
| 171 | + global $wgCategoryTreeDefaultMode; |
| 172 | + |
169 | 173 | $parser->mOutput->mCategoryTreeTag = true; # flag for use by efCategoryTreeParserOutput |
170 | 174 | |
171 | 175 | static $initialized = false; |
— | — | @@ -181,7 +185,7 @@ |
182 | 186 | else if ( $mode == 'categories' ) $mode = CT_MODE_CATEGORIES; |
183 | 187 | } |
184 | 188 | else { |
185 | | - $mode = CT_MODE_CATEGORIES; |
| 189 | + $mode = $wgCategoryTreeDefaultMode; |
186 | 190 | } |
187 | 191 | |
188 | 192 | $hideroot = isset( $argv[ 'hideroot' ] ) ? efCategoryTreeAsBool( $argv[ 'hideroot' ] ) : null; |
Index: trunk/extensions/CategoryTree/README |
— | — | @@ -57,9 +57,10 @@ |
58 | 58 | |
59 | 59 | * onlyroot - set this to "on" show only the "root" node of the tree initially |
60 | 60 | |
61 | | -* mode - can be "categories" (the default), "pages" or "all". "categories" |
62 | | - only lists subcategories; "pages" lists all pages in the category |
63 | | - except images; "all" shows all pages in the category. |
| 61 | +* mode - can be "categories", "pages" or "all". See the Modes section below. |
| 62 | + The default for this attribute is controlled by |
| 63 | + $wgCategoryTreeDefaultMode, and is initially set to CT_MODE_CATEGORIES, |
| 64 | + the equivalent of setting the mode attribute to "categories". |
64 | 65 | |
65 | 66 | * style - can be used to specify any CSS styles you would like for the |
66 | 67 | tree. |
— | — | @@ -69,6 +70,17 @@ |
70 | 71 | extension also adds a tab for this special page to every category page. |
71 | 72 | |
72 | 73 | |
| 74 | +MODES |
| 75 | +-------------------------------------------------------------------------- |
| 76 | + |
| 77 | +The category tree can be shown in different modes, determining what types of |
| 78 | +"leaves" the "tree" has: |
| 79 | +* categories (constant CT_MODE_CATEGORIES): show subcategories only |
| 80 | +* pages (constant CT_MODE_PAGES): show subcategories and pages, except images |
| 81 | +* all (constant CT_MODE_ALL): show all pages, subcategories, images, etc |
| 82 | + |
| 83 | +The CT_MODE_XXX constants can be used with configuration optiosn (see below). |
| 84 | + |
73 | 85 | OPTIONS |
74 | 86 | -------------------------------------------------------------------------- |
75 | 87 | |
— | — | @@ -94,15 +106,23 @@ |
95 | 107 | <manuel.schneider@wikimedia.ch>, Bug 8011 |
96 | 108 | |
97 | 109 | $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. |
| 110 | + or an associative array, mapping CT_MODE_XXX constants |
| 111 | + to the maximum depth for that mode. |
| 112 | + Ignored if $wgCategoryTreeDynamicTag is true. Introduced |
| 113 | + by Steve Sanbeg. |
103 | 114 | |
104 | 115 | $wgCategoryTreeExtPath - the (URL-) path where the extension is installed, |
105 | 116 | relative to $wgScriptPath, with leading "/". Default is |
106 | 117 | "/extensions/CategoryTree". |
107 | 118 | |
| 119 | +$wgCategoryTreeDefaultMode - the default mode to use when no mode attribute |
| 120 | + is specified in a <categorytree> tag. May be |
| 121 | + CT_MODE_CATEGORIES (the default), CT_MODE_PAGES, or |
| 122 | + CT_MODE_ALL. |
| 123 | + |
| 124 | +$wgCategoryTreeCategoryPageMode - the mode to use when rendering trees on |
| 125 | + category pages. May be CT_MODE_CATEGORIES (the default), |
| 126 | + CT_MODE_PAGES, or CT_MODE_ALL. |
| 127 | + |
108 | 128 | -------------------------------------------------------------------------- |
109 | 129 | EOF |
Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php |
— | — | @@ -114,7 +114,7 @@ |
115 | 115 | * Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to |
116 | 116 | * load CategoryTreeFunctions.php on demand. |
117 | 117 | */ |
118 | | - function getTag( &$parser, $category, $mode, $display = 'expandroot', $style = '', $depth=1 ) { |
| 118 | + function getTag( &$parser, $category, $mode, $hideroot = false, $style = '', $depth=1 ) { |
119 | 119 | global $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag; |
120 | 120 | static $uniq = 0; |
121 | 121 | |
— | — | @@ -139,8 +139,8 @@ |
140 | 140 | $html .= wfCloseElement( 'span' ); |
141 | 141 | } |
142 | 142 | else { |
143 | | - if ( $display != 'hideroot' ) $html .= CategoryTree::renderNode( $title, $mode, $depth>0, $wgCategoryTreeDynamicTag, $depth-1 ); |
144 | | - else if ( !$wgCategoryTreeDynamicTag ) $html .= $this->renderChildren( $title, $mode, $depth-1 ); |
| 143 | + if ( !$hideroot ) $html .= CategoryTree::renderNode( $title, $mode, $depth>0, $wgCategoryTreeDynamicTag, $depth-1 ); |
| 144 | + else if ( !$wgCategoryTreeDynamicTag ) $html .= $this->renderChildren( $title, $mode, $depth ); |
145 | 145 | else { //FIXME: depth would need to be propagated here. this would imact the cache key, too |
146 | 146 | $uniq += 1; |
147 | 147 | $load = 'ct-' . $uniq . '-' . mt_rand( 1, 100000 ); |
— | — | @@ -161,8 +161,8 @@ |
162 | 162 | * Returns a string with an HTML representation of the children of the given category. |
163 | 163 | * $title must be a Title object |
164 | 164 | */ |
165 | | - function renderChildren( &$title, $mode = CT_MODE_CATEGORIES, $depth=0 ) { |
166 | | - global $wgCategoryTreeMaxChildren; |
| 165 | + function renderChildren( &$title, $mode = NULL, $depth=0 ) { |
| 166 | + global $wgCategoryTreeMaxChildren, $wgCategoryTreeDefaultMode; |
167 | 167 | |
168 | 168 | $dbr =& wfGetDB( DB_SLAVE ); |
169 | 169 | |
— | — | @@ -170,6 +170,8 @@ |
171 | 171 | $transFields = ''; |
172 | 172 | $transJoin = ''; |
173 | 173 | $transWhere = ''; |
| 174 | + |
| 175 | + if ( $mode === NULL ) $wgCategoryTreeDefaultMode; |
174 | 176 | |
175 | 177 | #namespace filter. Should be configurable |
176 | 178 | if ( $mode == CT_MODE_ALL ) $nsmatch = ''; |
— | — | @@ -268,10 +270,11 @@ |
269 | 271 | * Returns a string with a HTML represenation of the given page. |
270 | 272 | * $title must be a Title object |
271 | 273 | */ |
272 | | - function renderNode( &$title, $mode = CT_MODE_CATEGORIES, $children = false, $loadchildren = false, $depth = 1 ) { |
273 | | - global $wgCategoryTreeOmitNamespace; |
| 274 | + function renderNode( &$title, $mode = NULL, $children = false, $loadchildren = false, $depth = 1 ) { |
| 275 | + global $wgCategoryTreeOmitNamespace, $wgCategoryTreeDefaultMode; |
274 | 276 | static $uniq = 0; |
275 | 277 | |
| 278 | + if ( $mode === NULL ) $wgCategoryTreeDefaultMode; |
276 | 279 | $load = false; |
277 | 280 | |
278 | 281 | if ( $children && $loadchildren ) { |