r91711 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91710‎ | r91711 | r91712 >
Date:04:59, 8 July 2011
Author:nad
Status:deferred
Tags:
Comment:
update to work with 1.17
Modified paths:
  • /trunk/extensions/TreeAndMenu/TreeAndMenu.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TreeAndMenu/TreeAndMenu.php
@@ -14,7 +14,7 @@
1515
1616 if ( !defined( 'MEDIAWIKI' ) ) die( 'Not an entry point.' );
1717
18 -define( 'TREEANDMENU_VERSION','1.1.1, 2009-07-29' );
 18+define( 'TREEANDMENU_VERSION','1.2.0, 2011-07-08' );
1919
2020 # Set any unset images to default titles
2121 if ( !isset( $wgTreeViewImages ) || !is_array( $wgTreeViewImages ) ) $wgTreeViewImages = array();
@@ -38,24 +38,23 @@
3939
4040 class TreeAndMenu {
4141
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;
5252
53 -
5453 /**
5554 * Constructor
5655 */
5756 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;
6059
6160 # Add hooks
6261 $wgParser->setFunctionHook( $wgTreeMagic, array( $this,'expandTree' ) );
@@ -63,12 +62,8 @@
6463 $wgHooks['ParserAfterTidy'][] = array( $this, 'renderTreeAndMenu' );
6564
6665 # 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 );
7368 $this->useLines = $wgTreeViewShowLines ? 'true' : 'false';
7469 $this->uniq = uniqid( $this->uniqname );
7570
@@ -79,9 +74,6 @@
8075 $v = $image && $image->exists() ? $image->getURL() : $wgTreeViewImages[$k];
8176 $this->images .= "tree.icon['$k'] = '$v';";
8277 }
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" );
8678 }
8779
8880
@@ -149,7 +141,7 @@
150142 * Called after parser has finished (ParserAfterTidy) so all transcluded parts can be assembled into final trees
151143 */
152144 public function renderTreeAndMenu( &$parser, &$text ) {
153 - global $wgJsMimeType;
 145+ global $wgJsMimeType, $wgOut;
154146 $u = $this->uniq;
155147
156148 # Determine which trees are sub trees
@@ -233,7 +225,7 @@
234226 <script type=\"$wgJsMimeType\">/*<![CDATA[*/
235227 // TreeAndMenu{$this->version}
236228 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}
238230 tree.config.useLines = {$this->useLines};
239231 $add
240232 $objid = tree;
@@ -270,6 +262,9 @@
271263 }
272264
273265 $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>" );
274269 return true;
275270 }
276271

Status & tagging log