Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php |
— | — | @@ -58,12 +58,12 @@ |
59 | 59 | * load CategoryTreeFunctions.php on demand. |
60 | 60 | */ |
61 | 61 | function efCategoryTreeTag( $category, $mode, $hideroot = false, $style = '' ) { |
62 | | - global $wgOut, $wgParser, $wgCategoryTreeDisableCache; |
| 62 | + global $wgOut, $wgParser, $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag; |
63 | 63 | |
64 | 64 | efInjectCategoryTreeMessages(); |
65 | 65 | efCategoryTreeHeader(); |
66 | 66 | |
67 | | - if ( $wgCategoryTreeDisableCache ) $wgParser->disableCache(); |
| 67 | + if ( $wgCategoryTreeDisableCache && !$wgCategoryTreeDynamicTag ) $wgParser->disableCache(); |
68 | 68 | |
69 | 69 | $title = efCategoryTreeMakeTitle( $category ); |
70 | 70 | |
— | — | @@ -197,6 +197,17 @@ |
198 | 198 | * $title must be a Title object |
199 | 199 | */ |
200 | 200 | 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 | + } |
201 | 212 | |
202 | 213 | $ns = $title->getNamespace(); |
203 | 214 | $key = $title->getDBKey(); |
— | — | @@ -219,17 +230,20 @@ |
220 | 231 | |
221 | 232 | if ( ( $ns % 2 ) > 0 ) $labelClass .= ' CategoryTreeLabelTalk'; |
222 | 233 | |
| 234 | + $linkattr= array( 'href' => 'javascript:void(0)' ); |
| 235 | + |
| 236 | + if ( $load ) $linkattr[ 'id' ] = $load; |
| 237 | + |
223 | 238 | if ( !$children ) { |
224 | | - $js = "categoryTreeExpandNode('".addslashes($key)."','".$mode."',this);"; |
225 | 239 | $txt = '+'; |
226 | | - $ttl = wfMsg('categorytree-load'); |
227 | | - $cls = ''; |
| 240 | + $linkattr[ 'onclick' ] = "categoryTreeExpandNode('".Xml::escapeJsString($key)."','".$mode."',this);"; |
| 241 | + $linkattr[ 'title' ] = wfMsg('categorytree-load'); |
228 | 242 | } |
229 | 243 | 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'; |
234 | 248 | } |
235 | 249 | |
236 | 250 | $s = ''; |
— | — | @@ -242,7 +256,7 @@ |
243 | 257 | $s .= wfOpenElement( 'div', array( 'class' => 'CategoryTreeItem' ) ); |
244 | 258 | |
245 | 259 | $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 ) . '] '; |
247 | 261 | else $s .= ' '; |
248 | 262 | $s .= wfCloseElement( 'span' ); |
249 | 263 | |
— | — | @@ -253,6 +267,14 @@ |
254 | 268 | if ( $children ) $s .= efCategoryTreeRenderChildren( $title, $mode ); |
255 | 269 | $s .= wfCloseElement( 'div' ); |
256 | 270 | $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 | + |
257 | 279 | $s .= "\n\t\t"; |
258 | 280 | |
259 | 281 | return $s; |
Index: trunk/extensions/CategoryTree/CategoryTree.php |
— | — | @@ -37,18 +37,21 @@ |
38 | 38 | * |
39 | 39 | * $wgCategoryTreeMaxChildren - maximum number of children shown in a tree node. Default is 200 |
40 | 40 | * $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. |
41 | 43 | * $wgCategoryTreeDisableCache - disabled the parser cache for pages with a <categorytree> tag. Default is true. |
42 | 44 | */ |
43 | 45 | if ( !isset( $wgCategoryTreeMaxChildren ) ) $wgCategoryTreeMaxChildren = 200; |
44 | 46 | if ( !isset( $wgCategoryTreeAllowTag ) ) $wgCategoryTreeAllowTag = true; |
45 | 47 | if ( !isset( $wgCategoryTreeDisableCache ) ) $wgCategoryTreeDisableCache = true; |
| 48 | +if ( !isset( $wgCategoryTreeDynamicTag ) ) $wgCategoryTreeDynamicTag = false; |
46 | 49 | |
47 | 50 | /** |
48 | 51 | * Register extension setup hook and credits |
49 | 52 | */ |
50 | 53 | $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' ); |
53 | 56 | |
54 | 57 | /** |
55 | 58 | * 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 |