r20385 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r20384 | r20385 (on ViewVC) | r20386 >
Date:11:39, 13 March 2007
Author:daniel
Status:new
Tags:
Comment:introducing onlyroot option (and removing obsolete email address)
Modified paths:

Diff [purge]

Index: trunk/extensions/CategoryTree/CategoryTree.i18n.lt.php
===================================================================
--- trunk/extensions/CategoryTree/CategoryTree.i18n.lt.php	(revision 20384)
+++ trunk/extensions/CategoryTree/CategoryTree.i18n.lt.php	(revision 20385)
@@ -4,7 +4,7 @@
  * Internationalisation file for the CategoryTree extension
  *
  * @addtogroup Extensions
- * @author Daniel Kinzler <duesentrieb@brightbyte.de>
+ * @author Daniel Kinzler, brightbyte.de
  * @copyright © 2006 Daniel Kinzler
  * @licence GNU General Public Licence 2.0 or later
  */
Index: trunk/extensions/CategoryTree/CategoryTreePage.php
===================================================================
--- trunk/extensions/CategoryTree/CategoryTreePage.php	(revision 20384)
+++ trunk/extensions/CategoryTree/CategoryTreePage.php	(revision 20385)
@@ -4,7 +4,7 @@
  * to display the category structure of a wiki
  *
  * @addtogroup Extensions
- * @author Daniel Kinzler <duesentrieb@brightbyte.de>
+ * @author Daniel Kinzler, brightbyte.de
  * @copyright © 2006 Daniel Kinzler
  * @licence GNU General Public Licence 2.0 or later
  */
Index: trunk/extensions/CategoryTree/CategoryTree.css
===================================================================
--- trunk/extensions/CategoryTree/CategoryTree.css	(revision 20384)
+++ trunk/extensions/CategoryTree/CategoryTree.css	(revision 20385)
@@ -4,7 +4,7 @@
  *
  * @package MediaWiki
  * @subpackage Extensions
- * @author Daniel Kinzler <duesentrieb@brightbyte.de>
+ * @author Daniel Kinzler, brightbyte.de
  * @copyright © 2006 Daniel Kinzler
  * @licence GNU General Public Licence 2.0 or later
 */
Index: trunk/extensions/CategoryTree/CategoryTree.php
===================================================================
--- trunk/extensions/CategoryTree/CategoryTree.php	(revision 20384)
+++ trunk/extensions/CategoryTree/CategoryTree.php	(revision 20385)
@@ -5,8 +5,8 @@
  * to display the category structure of a wiki
  *
  * @addtogroup Extensions
- * @author Daniel Kinzler <duesentrieb@brightbyte.de>
- * @copyright © 2006 Daniel Kinzler
+ * @author Daniel Kinzler, brightbyte.de
+ * @copyright © 2006-2007 Daniel Kinzler
  * @licence GNU General Public Licence 2.0 or later
  */
  
@@ -112,6 +112,25 @@
 }
 
 /**
+* Helper function to convert a string to a boolean value.
+* Perhaps make this a global function in MediaWiki proper
+*/
+function efCategoryTreeAsBool( $s ) {
+	if ( is_null( $s ) || is_bool( $s ) ) return $s;
+	$s = trim( strtolower( $s ) );
+
+	if ( $s === '1' || $s === 'yes' || $s === 'on' || $s === 'true' ) {
+		return true;
+	}
+	else if ( $s === '0' || $s === 'no' || $s === 'off' || $s === 'false' ) {
+		return false;
+	}
+	else {
+		return NULL;
+	}
+}
+
+/**
  * Entry point for the <categorytree> tag parser hook.
  * This loads CategoryTreeFunctions.php and calls CategoryTree::getTag()
  */
@@ -135,20 +154,15 @@
 		$mode = CT_MODE_CATEGORIES;
 	}
 	
-	$hideroot = isset( $argv[ 'hideroot' ] ) ? $argv[ 'hideroot' ] : null;
-	if ( $hideroot !== NULL ) {
-		$hideroot = trim( strtolower( $hideroot ) );
-		
-		if ( $hideroot === '1' || $hideroot === 'yes' || $hideroot === 'on' || $hideroot === 'true' ) {
-			$hideroot = true;
-		}
-		else if ( $hideroot === '0' || $hideroot === 'no' || $hideroot === 'off' || $hideroot === 'false' ) {
-			$hideroot = false;
-		}
-	}
+	$hideroot = isset( $argv[ 'hideroot' ] ) ? efCategoryTreeAsBool( $argv[ 'hideroot' ] ) : null;
+	$onlyroot = isset( $argv[ 'onlyroot' ] ) ? efCategoryTreeAsBool( $argv[ 'onlyroot' ] ) : null;
 
+	if ( $onlyroot ) $display = 'onlyroot';
+	else if ( $hideroot ) $display = 'hideroot';
+	else $display = 'expandroot';
+
 	$ct = new CategoryTree;
-	return $ct->getTag( $parser, $cat, $mode, $hideroot, $style );
+	return $ct->getTag( $parser, $cat, $mode, $display, $style );
 }
 
 /**
Index: trunk/extensions/CategoryTree/README
===================================================================
--- trunk/extensions/CategoryTree/README	(revision 20384)
+++ trunk/extensions/CategoryTree/README	(revision 20385)
@@ -1,6 +1,6 @@
 --------------------------------------------------------------------------
 README for the CategoryTree extension
-Copyright © 2006 Daniel Kinzler
+Copyright © 2006-2007 Daniel Kinzler
 Licenses: GNU General Public Licence (GPL)
           GNU Free Documentation License (GFDL)
 --------------------------------------------------------------------------
@@ -49,12 +49,14 @@
 
 The custom tag is called <categorytree>. For example, if you put
 <categorytree>Foo</categorytree> on a wiki page, it will show the contents
-of category Foo as a dynamic tree on that page. The tag accepts three
+of category Foo as a dynamic tree on that page. The tag accepts the following
 attributes, using a HTML-like syntax:
 
 * hideroot - set this to "on" to hide the "root" node of the tree, i.e.
              the mention of category Foo from the example.
              
+* onlyroot - set this to "on" show only the "root" node of the tree initially
+             
 * mode - can be "categories" (the default), "pages" or "all". "categories"
          only lists subcategories; "pages" lists all pages in the category
          except images; "all" shows all pages in the category.
Index: trunk/extensions/CategoryTree/CategoryTree.i18n.php
===================================================================
--- trunk/extensions/CategoryTree/CategoryTree.i18n.php	(revision 20384)
+++ trunk/extensions/CategoryTree/CategoryTree.i18n.php	(revision 20385)
@@ -4,7 +4,7 @@
  * Internationalisation file for the CategoryTree extension
  *
  * @addtogroup Extensions
- * @author Daniel Kinzler <duesentrieb@brightbyte.de>
+ * @author Daniel Kinzler, brightbyte.de
  * @copyright © 2006 Daniel Kinzler
  * @licence GNU General Public Licence 2.0 or later
  */
Index: trunk/extensions/CategoryTree/CategoryTree.js
===================================================================
--- trunk/extensions/CategoryTree/CategoryTree.js	(revision 20384)
+++ trunk/extensions/CategoryTree/CategoryTree.js	(revision 20385)
@@ -4,7 +4,7 @@
  *
  * @package MediaWiki
  * @subpackage Extensions
- * @author Daniel Kinzler <duesentrieb@brightbyte.de>
+ * @author Daniel Kinzler, brightbyte.de
  * @copyright © 2006 Daniel Kinzler
  * @licence GNU General Public Licence 2.0 or later
 */
Index: trunk/extensions/CategoryTree/CategoryTree.i18n.nl.php
===================================================================
--- trunk/extensions/CategoryTree/CategoryTree.i18n.nl.php	(revision 20384)
+++ trunk/extensions/CategoryTree/CategoryTree.i18n.nl.php	(revision 20385)
@@ -4,7 +4,7 @@
  * Internationalisation file for the CategoryTree extension
  *
  * @addtogroup Extensions
- * @author Dutch translation by JePe and Siebrand, source file by Daniel Kinzler <duesentrieb@brightbyte.de>
+ * @author Dutch translation by JePe and Siebrand, source file by Daniel Kinzler, brightbyte.de
  * @copyright © 2006 Daniel Kinzler, JePe, Siebrand
  * @licence GNU General Public Licence 2.0 or later
  */
Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php
===================================================================
--- trunk/extensions/CategoryTree/CategoryTreeFunctions.php	(revision 20384)
+++ trunk/extensions/CategoryTree/CategoryTreeFunctions.php	(revision 20385)
@@ -5,8 +5,8 @@
  * to display the category structure of a wiki
  *
  * @addtogroup Extensions
- * @author Daniel Kinzler <duesentrieb@brightbyte.de>
- * @copyright © 2006 Daniel Kinzler
+ * @author Daniel Kinzler, brightbyte.de
+ * @copyright © 2006-2007 Daniel Kinzler
  * @licence GNU General Public Licence 2.0 or later
  */
  
@@ -113,7 +113,7 @@
 	* Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to 
 	* load CategoryTreeFunctions.php on demand.
 	*/
-	function getTag( &$parser, $category, $mode, $hideroot = false, $style = '' ) {
+	function getTag( &$parser, $category, $mode, $display = 'expandroot', $style = '' ) {
 		global $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag;
 		static $uniq = 0;
 
@@ -138,7 +138,7 @@
 			$html .= wfCloseElement( 'span' );
 			}
 		else {
-			if ( !$hideroot ) $html .= CategoryTree::renderNode( $title, $mode, true, $wgCategoryTreeDynamicTag );
+			if ( $display != 'hideroot' ) $html .= CategoryTree::renderNode( $title, $mode, $display != 'onlyroot', $wgCategoryTreeDynamicTag );
 			else if ( !$wgCategoryTreeDynamicTag ) $html .= $this->renderChildren( $title, $mode );
 			else {
 				$uniq += 1;
@@ -273,7 +273,7 @@
 		
 		$load = false;
 		
-		if ( $loadchildren ) {
+		if ( $children && $loadchildren ) {
 			$uniq += 1;
 
 			$load = 'ct-' . $uniq . '-' . mt_rand( 1, 100000 );
Views
Toolbox