Index: trunk/extensions/TreeAndMenu/TreeAndMenu.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | |
16 | 16 | if ( !defined( 'MEDIAWIKI' ) ) die( 'Not an entry point.' ); |
17 | 17 | |
18 | | -define( 'TREEANDMENU_VERSION','1.1.1, 2009-07-29' ); |
| 18 | +define( 'TREEANDMENU_VERSION','1.2.0, 2011-07-08' ); |
19 | 19 | |
20 | 20 | # Set any unset images to default titles |
21 | 21 | if ( !isset( $wgTreeViewImages ) || !is_array( $wgTreeViewImages ) ) $wgTreeViewImages = array(); |
— | — | @@ -38,24 +38,23 @@ |
39 | 39 | |
40 | 40 | class TreeAndMenu { |
41 | 41 | |
42 | | - var $version = TREEANDMENU_VERSION; |
43 | | - var $uniq = ''; # uniq part of all tree id's |
44 | | - var $uniqname = 'tam'; # input name for uniqid |
45 | | - var $id = ''; # id for specific tree |
46 | | - var $baseDir = ''; # internal absolute path to treeview directory |
47 | | - var $baseRelDir = ''; # internal relative path to treeview directory |
48 | | - var $baseUrl = ''; # external URL to treeview directory (relative to domain) |
49 | | - var $images = ''; # internal JS to update dTree images |
50 | | - var $useLines = true; # internal variable determining whether to render connector lines |
51 | | - var $args = array(); # args for each tree |
| 42 | + var $version = TREEANDMENU_VERSION; |
| 43 | + var $uniq = ''; # uniq part of all tree id's |
| 44 | + var $uniqname = 'tam'; # input name for uniqid |
| 45 | + var $id = ''; # id for specific tree |
| 46 | + var $baseDir = ''; # internal absolute path to treeview directory |
| 47 | + var $baseUrl = ''; # external URL to treeview directory (relative to domain) |
| 48 | + var $images = ''; # internal JS to update dTree images |
| 49 | + var $useLines = true; # internal variable determining whether to render connector lines |
| 50 | + var $args = array(); # args for each tree |
| 51 | + var $js = 0; |
52 | 52 | |
53 | | - |
54 | 53 | /** |
55 | 54 | * Constructor |
56 | 55 | */ |
57 | 56 | function __construct() { |
58 | | - global $wgOut, $wgHooks, $wgParser, $wgScriptPath, $wgJsMimeType, |
59 | | - $wgTreeMagic, $wgMenuMagic, $wgTreeViewImages, $wgTreeViewShowLines; |
| 57 | + global $wgOut, $wgHooks, $wgParser, $wgScriptPath, $wgJsMimeType, $wgTreeMagic, |
| 58 | + $wgMenuMagic, $wgTreeViewImages, $wgTreeViewShowLines, $wgTreeViewBaseDir, $wgTreeViewBaseUrl; |
60 | 59 | |
61 | 60 | # Add hooks |
62 | 61 | $wgParser->setFunctionHook( $wgTreeMagic, array( $this,'expandTree' ) ); |
— | — | @@ -63,12 +62,8 @@ |
64 | 63 | $wgHooks['ParserAfterTidy'][] = array( $this, 'renderTreeAndMenu' ); |
65 | 64 | |
66 | 65 | # Update general tree paths and properties |
67 | | - $this->baseDir = dirname( __FILE__ ); |
68 | | - $this->baseRelDir = strstr( $this->baseDir, 'extensions'); |
69 | | - $this->baseRelDir = str_replace( '\\', '/',$this->baseRelDir ); |
70 | | - $this->baseRelDir = $wgScriptPath . '/' . $this->baseRelDir; |
71 | | - $this->baseUrl = str_replace( '\\', '/', $this->baseDir ); |
72 | | - $this->baseUrl = preg_replace( '|^.+(?=/ext)|', $wgScriptPath, $this->baseDir ); |
| 66 | + $this->baseDir = isset( $wgTreeViewBaseDir ) ? $wgTreeViewBaseDir : dirname( __FILE__ ); |
| 67 | + $this->baseUrl = isset( $wgTreeViewBaseUrl ) ? $wgTreeViewBaseUrl : preg_replace( '|^.+(?=/ext)|', $wgScriptPath, $this->baseDir ); |
73 | 68 | $this->useLines = $wgTreeViewShowLines ? 'true' : 'false'; |
74 | 69 | $this->uniq = uniqid( $this->uniqname ); |
75 | 70 | |
— | — | @@ -79,9 +74,6 @@ |
80 | 75 | $v = $image && $image->exists() ? $image->getURL() : $wgTreeViewImages[$k]; |
81 | 76 | $this->images .= "tree.icon['$k'] = '$v';"; |
82 | 77 | } |
83 | | - |
84 | | - # Add link to output to load dtree.js script |
85 | | - $wgOut->addScript( "<script type=\"$wgJsMimeType\" src=\"{$this->baseRelDir}/dtree.js\"><!-- TreeAndMenu --></script>\n" ); |
86 | 78 | } |
87 | 79 | |
88 | 80 | |
— | — | @@ -149,7 +141,7 @@ |
150 | 142 | * Called after parser has finished (ParserAfterTidy) so all transcluded parts can be assembled into final trees |
151 | 143 | */ |
152 | 144 | public function renderTreeAndMenu( &$parser, &$text ) { |
153 | | - global $wgJsMimeType; |
| 145 | + global $wgJsMimeType, $wgOut; |
154 | 146 | $u = $this->uniq; |
155 | 147 | |
156 | 148 | # Determine which trees are sub trees |
— | — | @@ -233,7 +225,7 @@ |
234 | 226 | <script type=\"$wgJsMimeType\">/*<![CDATA[*/ |
235 | 227 | // TreeAndMenu{$this->version} |
236 | 228 | tree = new dTree('$objid'); |
237 | | - for (i in tree.icon) tree.icon[i] = '{$this->baseRelDir}/'+tree.icon[i];{$this->images} |
| 229 | + for (i in tree.icon) tree.icon[i] = '{$this->baseUrl}/'+tree.icon[i];{$this->images} |
238 | 230 | tree.config.useLines = {$this->useLines}; |
239 | 231 | $add |
240 | 232 | $objid = tree; |
— | — | @@ -270,6 +262,9 @@ |
271 | 263 | } |
272 | 264 | |
273 | 265 | $text = preg_replace( "/\x7f1$u\x7f.+?[\\r\\n]+/m", '', $text ); # Remove all unreplaced row information |
| 266 | + |
| 267 | + # Add the dTRee script if not loaded yet |
| 268 | + if( !$this->js++ ) $wgOut->addHtml( "<script type=\"$wgJsMimeType\" src=\"{$this->baseUrl}/dtree.js\"></script>" ); |
274 | 269 | return true; |
275 | 270 | } |
276 | 271 | |