r15870 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r15869‎ | r15870 | r15871 >
Date:16:07, 28 July 2006
Author:daniel
Status:old
Tags:
Comment:
added $wgCategoryTreeDynamicTag option
added README
Modified paths:
  • /trunk/extensions/CategoryTree/CategoryTree.php (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTreeFunctions.php (modified) (history)
  • /trunk/extensions/CategoryTree/README (added) (history)

Diff [purge]

Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php
@@ -58,12 +58,12 @@
5959 * load CategoryTreeFunctions.php on demand.
6060 */
6161 function efCategoryTreeTag( $category, $mode, $hideroot = false, $style = '' ) {
62 - global $wgOut, $wgParser, $wgCategoryTreeDisableCache;
 62+ global $wgOut, $wgParser, $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag;
6363
6464 efInjectCategoryTreeMessages();
6565 efCategoryTreeHeader();
6666
67 - if ( $wgCategoryTreeDisableCache ) $wgParser->disableCache();
 67+ if ( $wgCategoryTreeDisableCache && !$wgCategoryTreeDynamicTag ) $wgParser->disableCache();
6868
6969 $title = efCategoryTreeMakeTitle( $category );
7070
@@ -197,6 +197,17 @@
198198 * $title must be a Title object
199199 */
200200 function efCategoryTreeRenderNode( &$title, $mode = CT_MODE_CATEGORIES, $children = false ) {
 201+ global $wgCategoryTreeDynamicTag;
 202+ static $uniq = 0;
 203+
 204+ $load = false;
 205+
 206+ if ( $children && $wgCategoryTreeDynamicTag ) {
 207+ $uniq += 1;
 208+
 209+ $load = 'ct-' . $uniq . '-' . mt_rand( 1, 100000 );
 210+ $children = false;
 211+ }
201212
202213 $ns = $title->getNamespace();
203214 $key = $title->getDBKey();
@@ -219,17 +230,20 @@
220231
221232 if ( ( $ns % 2 ) > 0 ) $labelClass .= ' CategoryTreeLabelTalk';
222233
 234+ $linkattr= array( 'href' => 'javascript:void(0)' );
 235+
 236+ if ( $load ) $linkattr[ 'id' ] = $load;
 237+
223238 if ( !$children ) {
224 - $js = "categoryTreeExpandNode('".addslashes($key)."','".$mode."',this);";
225239 $txt = '+';
226 - $ttl = wfMsg('categorytree-load');
227 - $cls = '';
 240+ $linkattr[ 'onclick' ] = "categoryTreeExpandNode('".Xml::escapeJsString($key)."','".$mode."',this);";
 241+ $linkattr[ 'title' ] = wfMsg('categorytree-load');
228242 }
229243 else {
230 - $js = "categoryTreeCollapseNode('".addslashes($key)."','".$mode."',this);";
231 - $txt = '–'; #NOTE: that'S not a minus but a unicode ndash!
232 - $ttl = wfMsg('categorytree-collapse');
233 - $cls = 'CategoryTreeLoaded';
 244+ $txt = '–'; #NOTE: that's not a minus but a unicode ndash!
 245+ $linkattr[ 'onclick' ] = "categoryTreeCollapseNode('".Xml::escapeJsString($key)."','".$mode."',this);";
 246+ $linkattr[ 'title' ] = wfMsg('categorytree-collapse');
 247+ $linkattr[ 'class' ] = 'CategoryTreeLoaded';
234248 }
235249
236250 $s = '';
@@ -242,7 +256,7 @@
243257 $s .= wfOpenElement( 'div', array( 'class' => 'CategoryTreeItem' ) );
244258
245259 $s .= wfOpenElement( 'span', array( 'class' => 'CategoryTreeBullet' ) );
246 - if ( $ns == NS_CATEGORY ) $s .= '[' . wfElement( 'a', array( 'href' => 'javascript:void(0)', 'onclick' => $js, 'title' => $ttl, 'class' => $cls ), $txt ) . '] ';
 260+ if ( $ns == NS_CATEGORY ) $s .= '[' . wfElement( 'a', $linkattr, $txt ) . '] ';
247261 else $s .= ' ';
248262 $s .= wfCloseElement( 'span' );
249263
@@ -253,6 +267,14 @@
254268 if ( $children ) $s .= efCategoryTreeRenderChildren( $title, $mode );
255269 $s .= wfCloseElement( 'div' );
256270 $s .= wfCloseElement( 'div' );
 271+
 272+ if ( $load ) {
 273+ $s .= "\n\t\t";
 274+ $s .= wfOpenElement( 'script', array( 'type' => 'text/javascript' ) );
 275+ $s .= 'categoryTreeExpandNode("'.Xml::escapeJsString($key).'", "'.$mode.'", document.getElementById("'.$load.'") );';
 276+ $s .= wfCloseElement( 'script' );
 277+ }
 278+
257279 $s .= "\n\t\t";
258280
259281 return $s;
Index: trunk/extensions/CategoryTree/CategoryTree.php
@@ -37,18 +37,21 @@
3838 *
3939 * $wgCategoryTreeMaxChildren - maximum number of children shown in a tree node. Default is 200
4040 * $wgCategoryTreeAllowTag - enable <categorytree> tag. Default is true.
 41+ * $wgCategoryTreeDynamicTag - loads the first level of the tree in a <categorytag> dynamically.
 42+ * This way, the cache does not need to be disabled. Default is false.
4143 * $wgCategoryTreeDisableCache - disabled the parser cache for pages with a <categorytree> tag. Default is true.
4244 */
4345 if ( !isset( $wgCategoryTreeMaxChildren ) ) $wgCategoryTreeMaxChildren = 200;
4446 if ( !isset( $wgCategoryTreeAllowTag ) ) $wgCategoryTreeAllowTag = true;
4547 if ( !isset( $wgCategoryTreeDisableCache ) ) $wgCategoryTreeDisableCache = true;
 48+if ( !isset( $wgCategoryTreeDynamicTag ) ) $wgCategoryTreeDynamicTag = false;
4649
4750 /**
4851 * Register extension setup hook and credits
4952 */
5053 $wgExtensionFunctions[] = 'efCategoryTree';
51 -$wgExtensionCredits['specialpage'][] = array( 'name' => 'CategoryTree', 'author' => 'Daniel Kinzler', 'url' => 'http://meta.wikimedia.org/wiki/CategoryTree extension' );
52 -$wgExtensionCredits['parserhook'][] = array( 'name' => 'CategoryTree', 'author' => 'Daniel Kinzler', 'url' => 'http://meta.wikimedia.org/wiki/CategoryTree extension' );
 54+$wgExtensionCredits['specialpage'][] = array( 'name' => 'CategoryTree', 'author' => 'Daniel Kinzler', 'url' => 'http://meta.wikimedia.org/wiki/CategoryTree_extension' );
 55+$wgExtensionCredits['parserhook'][] = array( 'name' => 'CategoryTree', 'author' => 'Daniel Kinzler', 'url' => 'http://meta.wikimedia.org/wiki/CategoryTree_extension' );
5356
5457 /**
5558 * Register the special page
Index: trunk/extensions/CategoryTree/README
@@ -0,0 +1,80 @@
 2+--------------------------------------------------------------------------
 3+README for the CategoryTree extesion
 4+Copyright © 2006 Daniel Kinzler
 5+Licenses: GNU General Public Licence (GPL)
 6+ GNU Free Documentation License (GFDL)
 7+--------------------------------------------------------------------------
 8+
 9+The CategoryTree extension provides a dynamic view of the wiki's category
 10+structure as a tree. It uses AJAX to load parts of the tree on demand.
 11+
 12+<http://meta.wikimedia.org/wiki/CategoryTree_extension>
 13+
 14+The CategoryTree extension was originally written by Daniel Kinzler in
 15+2006 and is released under the GNU General Public Licence (GPL). The
 16+internationalization files contain contributions by several people;
 17+they are mentioned in each file individually.
 18+
 19+
 20+INSTALLING
 21+--------------------------------------------------------------------------
 22+
 23+Copy the CategoryTree directory into the extenstions folder of your
 24+MediaWiki installation. Then add the following lines to your
 25+LocalSettings.php file (near the end):
 26+
 27+ $wgUseAjax = true;
 28+ require_once( 'extenstions/CategoryTree/CategoryTree.php' );
 29+
 30+Note that $wgUseAjax = true; will enable the ajax framework in MediaWiki,
 31+which is required by the CategoryTree extension. AJAX is a term for using
 32+JavaScript to load parts of a page on demand. It is supported by all
 33+recent graphic web browsers. For more information about AJAX see
 34+<http://en.wikipedia.org/wiki/Ajax_%28programming%29>.
 35+
 36+
 37+USAGE
 38+--------------------------------------------------------------------------
 39+
 40+CategoryTree can be used in two ways: as a "custom tag" to show a category
 41+structure inline on a wiki page, and as a special page.
 42+
 43+The special page is called Special:CategoryTree; there you can enter the
 44+name of a category and then browse it's content. The CategoryTree
 45+extension also adds a tab for this special page to every category page.
 46+
 47+The custom tag is called <categorytree>. For example, if you put
 48+<categorytree>Foo</categorytree> on a wiki page, it will show the contents
 49+of category Foo as a dynamic tree on that page. The tag accepts three
 50+attributes, using a HTML-like syntax:
 51+
 52+* hideroot - set this to "on" to hide the "root" node of the tree, i.e.
 53+ the mention of category Foo from the example.
 54+
 55+* mode - can be "categories" (the default), "pages" or "all". "categories"
 56+ only lists subcategories; "pages" lists all pages in the category
 57+ except images; "all" shows all pages in the category.
 58+
 59+* style - can be used to specify any CSS styles you would like for the
 60+ tree.
 61+
 62+
 63+OPTIONS
 64+--------------------------------------------------------------------------
 65+
 66+There are some options you can spefify in your LocalSettings.php file:
 67+
 68+$wgCategoryTreeMaxChildren - maximum number of children shown in a tree
 69+ node. Default is 200
 70+
 71+$wgCategoryTreeAllowTag - enable <categorytree> tag. Default is true.
 72+
 73+$wgCategoryTreeDynamicTag - loads the first level of the tree in a
 74+ <categorytag> dynamically. This way, the cache
 75+ does not need to be disabled. Default is false
 76+
 77+$wgCategoryTreeDisableCache - disabled the parser cache for pages with a
 78+ <categorytree> tag. Default is true.
 79+
 80+--------------------------------------------------------------------------
 81+EOF
\ No newline at end of file