r21727 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r21726‎ | r21727 | r21728 >
Date:21:18, 30 April 2007
Author:daniel
Status:old
Tags:
Comment:
introducing and options
Modified paths:
  • /trunk/extensions/CategoryTree/CategoryPageSubclass.php (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTree.php (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTreeFunctions.php (modified) (history)
  • /trunk/extensions/CategoryTree/README (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryTree/CategoryPageSubclass.php
@@ -18,7 +18,7 @@
1919 * Add a subcategory to the internal lists
2020 */
2121 function addSubcategory( $title, $sortkey, $pageLength ) {
22 - global $wgContLang, $wgOut, $wgRequest;
 22+ global $wgContLang, $wgOut, $wgRequest, $wgCategoryTreeCategoryPageMode;
2323
2424 if ( $wgRequest->getCheck( 'notree' ) ) {
2525 return parent::addSubcategory( $title, $sortkey, $pageLength );
@@ -34,13 +34,13 @@
3535 $this->categorytree = new CategoryTree;
3636 }
3737
38 - $this->children[] = $this->categorytree->renderNode( $title );
 38+ $this->children[] = $this->categorytree->renderNode( $title, $wgCategoryTreeCategoryPageMode );
3939
4040 $this->children_start_char[] = $this->getSubcategorySortChar( $title, $sortkey );
4141 }
4242
4343 function getSubcategorySection() {
44 - global $wgOut, $wgRequest, $wgCookiePrefix;
 44+ global $wgOut, $wgRequest, $wgCookiePrefix, $wgCategoryTreeCategoryPageMode;
4545
4646 if ( $wgRequest->getCheck( 'notree' ) ) {
4747 return parent::getSubcategorySection();
@@ -102,7 +102,7 @@
103103 $ct = new CategoryTree;
104104
105105 foreach ( $this->child_titles as $title ) {
106 - $r .= $ct->renderNode( $title );
 106+ $r .= $ct->renderNode( $title, $wgCategoryTreeCategoryPageMode );
107107 }
108108 }
109109 return $r;
Index: trunk/extensions/CategoryTree/CategoryTree.php
@@ -49,6 +49,8 @@
5050 $wgCategoryTreeOmitNamespace = false;
5151 $wgCategoryTreeMaxDepth = array(CT_MODE_PAGES => 1, CT_MODE_ALL => 1, CT_MODE_CATEGORIES => 2);
5252 $wgCategoryTreeExtPath = '/extensions/CategoryTree';
 53+$wgCategoryTreeDefaultMode = CT_MODE_CATEGORIES;
 54+$wgCategoryTreeCategoryPageMode = CT_MODE_CATEGORIES;
5355
5456 /**
5557 * Register extension setup hook and credits
@@ -103,7 +105,7 @@
104106 * Entry point for Ajax, registered in $wgAjaxExportList.
105107 * This loads CategoryTreeFunctions.php and calls CategoryTree::ajax()
106108 */
107 -function efCategoryTreeAjaxWrapper( $category, $mode = CT_MODE_CATEGORIES ) {
 109+function efCategoryTreeAjaxWrapper( $category, $mode ) {
108110 global $wgCategoryTreeHTTPCache, $wgSquidMaxAge, $wgUseSquid;
109111
110112 $ct = new CategoryTree;
@@ -165,6 +167,8 @@
166168 * This loads CategoryTreeFunctions.php and calls CategoryTree::getTag()
167169 */
168170 function efCategoryTreeParserHook( $cat, $argv, &$parser ) {
 171+ global $wgCategoryTreeDefaultMode;
 172+
169173 $parser->mOutput->mCategoryTreeTag = true; # flag for use by efCategoryTreeParserOutput
170174
171175 static $initialized = false;
@@ -181,7 +185,7 @@
182186 else if ( $mode == 'categories' ) $mode = CT_MODE_CATEGORIES;
183187 }
184188 else {
185 - $mode = CT_MODE_CATEGORIES;
 189+ $mode = $wgCategoryTreeDefaultMode;
186190 }
187191
188192 $hideroot = isset( $argv[ 'hideroot' ] ) ? efCategoryTreeAsBool( $argv[ 'hideroot' ] ) : null;
Index: trunk/extensions/CategoryTree/README
@@ -57,9 +57,10 @@
5858
5959 * onlyroot - set this to "on" show only the "root" node of the tree initially
6060
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".
6465
6566 * style - can be used to specify any CSS styles you would like for the
6667 tree.
@@ -69,6 +70,17 @@
7071 extension also adds a tab for this special page to every category page.
7172
7273
 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+
7385 OPTIONS
7486 --------------------------------------------------------------------------
7587
@@ -94,15 +106,23 @@
95107 <manuel.schneider@wikimedia.ch>, Bug 8011
96108
97109 $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.
103114
104115 $wgCategoryTreeExtPath - the (URL-) path where the extension is installed,
105116 relative to $wgScriptPath, with leading "/". Default is
106117 "/extensions/CategoryTree".
107118
 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+
108128 --------------------------------------------------------------------------
109129 EOF
Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php
@@ -114,7 +114,7 @@
115115 * Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to
116116 * load CategoryTreeFunctions.php on demand.
117117 */
118 - function getTag( &$parser, $category, $mode, $display = 'expandroot', $style = '', $depth=1 ) {
 118+ function getTag( &$parser, $category, $mode, $hideroot = false, $style = '', $depth=1 ) {
119119 global $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag;
120120 static $uniq = 0;
121121
@@ -139,8 +139,8 @@
140140 $html .= wfCloseElement( 'span' );
141141 }
142142 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 );
145145 else { //FIXME: depth would need to be propagated here. this would imact the cache key, too
146146 $uniq += 1;
147147 $load = 'ct-' . $uniq . '-' . mt_rand( 1, 100000 );
@@ -161,8 +161,8 @@
162162 * Returns a string with an HTML representation of the children of the given category.
163163 * $title must be a Title object
164164 */
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;
167167
168168 $dbr =& wfGetDB( DB_SLAVE );
169169
@@ -170,6 +170,8 @@
171171 $transFields = '';
172172 $transJoin = '';
173173 $transWhere = '';
 174+
 175+ if ( $mode === NULL ) $wgCategoryTreeDefaultMode;
174176
175177 #namespace filter. Should be configurable
176178 if ( $mode == CT_MODE_ALL ) $nsmatch = '';
@@ -268,10 +270,11 @@
269271 * Returns a string with a HTML represenation of the given page.
270272 * $title must be a Title object
271273 */
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;
274276 static $uniq = 0;
275277
 278+ if ( $mode === NULL ) $wgCategoryTreeDefaultMode;
276279 $load = false;
277280
278281 if ( $children && $loadchildren ) {