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.0.2, 2008-06-05'); |
| 18 | +define('TREEANDMENU_VERSION','1.0.3, 2008-06-05'); |
19 | 19 | |
20 | 20 | # Set any unset images to default titles |
21 | 21 | if (!isset($wgTreeViewImages) || !is_array($wgTreeViewImages)) $wgTreeViewImages = array(); |
— | — | @@ -52,8 +52,8 @@ |
53 | 53 | * Constructor |
54 | 54 | */ |
55 | 55 | function __construct() { |
56 | | - global $wgOut,$wgHooks,$wgParser,$wgScriptPath,$wgJsMimeType, |
57 | | - $wgTreeMagic,$wgMenuMagic,$wgTreeViewImages,$wgTreeViewShowLines; |
| 56 | + global $wgOut, $wgHooks, $wgParser, $wgScriptPath, $wgJsMimeType, |
| 57 | + $wgTreeMagic, $wgMenuMagic, $wgTreeViewImages, $wgTreeViewShowLines; |
58 | 58 | |
59 | 59 | # Add hooks |
60 | 60 | $wgParser->setFunctionHook($wgTreeMagic,array($this,'expandTree')); |
— | — | @@ -62,7 +62,7 @@ |
63 | 63 | |
64 | 64 | # Update general tree paths and properties |
65 | 65 | $this->baseDir = dirname(__FILE__); |
66 | | - $this->baseUrl = preg_replace('|^.+(?=[/\\\\]extensions)|',$wgScriptPath,$this->baseDir); |
| 66 | + $this->baseUrl = preg_replace('|^.+(?=[/\\\\]extensions)|', $wgScriptPath, $this->baseDir); |
67 | 67 | $this->useLines = $wgTreeViewShowLines ? 'true' : 'false'; |
68 | 68 | $this->uniq = uniqid($this->uniqname); |
69 | 69 | |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | */ |
86 | 86 | public function expandTree() { |
87 | 87 | $args = func_get_args(); |
88 | | - return $this->expandTreeAndMenu('tree',$args); |
| 88 | + return $this->expandTreeAndMenu('tree', $args); |
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
— | — | @@ -92,17 +92,17 @@ |
93 | 93 | */ |
94 | 94 | public function expandMenu() { |
95 | 95 | $args = func_get_args(); |
96 | | - return $this->expandTreeAndMenu('menu',$args); |
| 96 | + return $this->expandTreeAndMenu('menu', $args); |
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | 100 | * Expand either kind of parser-function (reformats tree rows for matching later) and store args |
101 | 101 | */ |
102 | | - private function expandTreeAndMenu($magic,$args) { |
| 102 | + private function expandTreeAndMenu($magic, $args) { |
103 | 103 | $parser = array_shift($args); |
104 | 104 | |
105 | 105 | # Store args for this tree for later use |
106 | | - foreach ($args as $arg) if (preg_match('/^(\\w+?)\\s*=\\s*(.+)$/s',$arg,$m)) $args[$m[1]] = $m[2]; else $text = $arg; |
| 106 | + foreach ($args as $arg) if (preg_match('/^(\\w+?)\\s*=\\s*(.+)$/s', $arg, $m)) $args[$m[1]] = $m[2]; else $text = $arg; |
107 | 107 | |
108 | 108 | # If root, parse as wikitext |
109 | 109 | if (isset($args['root'])) { |
— | — | @@ -117,8 +117,8 @@ |
118 | 118 | $this->args[$this->id] = $args; |
119 | 119 | |
120 | 120 | # Reformat tree rows for matching in ParserAfterStrip |
121 | | - $text = preg_replace('/(?<=\\*)\\s*\\[\\[Image:(.+?)\\]\\]/',"{$this->uniq}3$1{$this->uniq}4",$text); |
122 | | - $text = preg_replace_callback('/^(\\*+)(.*?)$/m',array($this,'formatRow'),$text); |
| 121 | + $text = preg_replace('/(?<=\\*)\\s*\\[\\[Image:(.+?)\\]\\]/', "{$this->uniq}3$1{$this->uniq}4", $text); |
| 122 | + $text = preg_replace_callback('/^(\\*+)(.*?)$/m', array($this, 'formatRow'), $text); |
123 | 123 | |
124 | 124 | return $text; |
125 | 125 | } |
— | — | @@ -139,17 +139,17 @@ |
140 | 140 | /** |
141 | 141 | * Called after parser has finished (ParserAfterTidy) so all transcluded parts can be assembled into final trees |
142 | 142 | */ |
143 | | - public function renderTreeAndMenu(&$parser,&$text) { |
| 143 | + public function renderTreeAndMenu(&$parser, &$text) { |
144 | 144 | global $wgJsMimeType; |
145 | 145 | $u = $this->uniq; |
146 | 146 | |
147 | 147 | # Determine which trees are sub trees |
148 | 148 | # - there should be a more robust way to do this, |
149 | 149 | # it's just based on the fact that all sub-tree's have a minus preceding their row data |
150 | | - if (!preg_match_all("/\x7f\x7f1$u\x7f(.+?)\x7f/",$text,$subs)) $subs = array(1 => array()); |
| 150 | + if (!preg_match_all("/\x7f\x7f1$u\x7f(.+?)\x7f/", $text, $subs)) $subs = array(1 => array()); |
151 | 151 | |
152 | 152 | # Extract all the formatted tree rows in the page and if any, replace with dTree JavaScript |
153 | | - if (preg_match_all("/\x7f1$u\x7f(.+?)\x7f([0-9]+)\x7f({$u}3(.+?){$u}4)?(.*?)(?=\x7f[12]$u)/",$text,$matches,PREG_SET_ORDER)) { |
| 153 | + if (preg_match_all("/\x7f1$u\x7f(.+?)\x7f([0-9]+)\x7f({$u}3(.+?){$u}4)?(.*?)(?=\x7f[12]$u)/", $text, $matches, PREG_SET_ORDER)) { |
154 | 154 | |
155 | 155 | # PASS-1: build $rows array containing depth, and tree start/end information |
156 | 156 | $rows = array(); |
— | — | @@ -158,13 +158,13 @@ |
159 | 159 | $lastId = ''; |
160 | 160 | $lastDepth = 0; |
161 | 161 | foreach ($matches as $match) { |
162 | | - list(,$id,$depth,,$icon,$item) = $match; |
| 162 | + list(, $id, $depth,, $icon, $item) = $match; |
163 | 163 | $start = false; |
164 | 164 | if ($id != $lastId) { |
165 | 165 | if (!isset($depths[$id])) $depths[$id] = $depths[$lastId]+$lastDepth; |
166 | | - if ($start = $rootId != $id && !in_array($id,$subs[1])) $depths[$rootId = $id] = 0; |
| 166 | + if ($start = $rootId != $id && !in_array($id, $subs[1])) $depths[$rootId = $id] = 0; |
167 | 167 | } |
168 | | - if ($item) $rows[] = array($rootId,$depth+$depths[$id],$icon,$item,$start); |
| 168 | + if ($item) $rows[] = array($rootId, $depth+$depths[$id], $icon, addslashes($item), $start); |
169 | 169 | $lastId = $id; |
170 | 170 | $lastDepth = $depth; |
171 | 171 | } |
— | — | @@ -175,22 +175,22 @@ |
176 | 176 | $node = 0; |
177 | 177 | $last = -1; |
178 | 178 | $nodes = ''; |
179 | | - foreach ($rows as $info) { |
| 179 | + foreach ($rows as $i => $info) { |
180 | 180 | $node++; |
181 | | - list($id,$depth,$icon,$item,$start) = $info; |
| 181 | + list($id, $depth, $icon, $item, $start) = $info; |
182 | 182 | $args = $this->args[$id]; |
183 | 183 | $type = $args['type']; |
184 | | - $end = $node == count($rows) || $rows[$node][4]; |
| 184 | + $end = $i == count($rows)-1 || $rows[$i+1][4]; |
185 | 185 | if (!isset($args['root'])) $args['root'] = ''; # tmp - need to handle rootless trees |
186 | 186 | if ($start) $node = 1; |
187 | 187 | |
188 | 188 | # Append node script for this row |
189 | 189 | if ($depth > $last) $parents[$depth] = $node-1; |
190 | 190 | $parent = $parents[$depth]; |
191 | | - if ($type == 'tree') $nodes .= "{$this->uniqname}$id.add($node,$parent,'".addslashes($item)."');\n"; |
| 191 | + if ($type == 'tree') $nodes .= "{$this->uniqname}$id.add($node, $parent, '$item ($start)');\n"; |
192 | 192 | else { |
193 | 193 | if (!$start) { |
194 | | - if ($depth < $last) $nodes .= str_repeat('</ul></li>',$last-$depth); |
| 194 | + if ($depth < $last) $nodes .= str_repeat('</ul></li>', $last-$depth); |
195 | 195 | elseif ($depth > $last) $nodes .= "\n<ul>"; |
196 | 196 | } |
197 | 197 | $parity[$depth] = isset($parity[$depth]) ? $parity[$depth]^1 : 0; |
— | — | @@ -229,8 +229,8 @@ |
230 | 230 | else { |
231 | 231 | |
232 | 232 | # Finalise a menu |
233 | | - if ($depth > 0) $nodes .= str_repeat('</ul></li>',$depth); |
234 | | - $nodes = preg_replace("/<(a.*? )title=\".+?\".*?>/","<$1>",$nodes); # IE has problems with title attribute in suckerfish menus |
| 233 | + if ($depth > 0) $nodes .= str_repeat('</ul></li>', $depth); |
| 234 | + $nodes = preg_replace("/<(a.*? )title=\".+?\".*?>/", "<$1>", $nodes); # IE has problems with title attribute in suckerfish menus |
235 | 235 | $html = " |
236 | 236 | <ul class='$class' id='$id'>\n$nodes</ul> |
237 | 237 | <script type=\"$wgJsMimeType\"> |
— | — | @@ -245,14 +245,14 @@ |
246 | 246 | "; |
247 | 247 | } |
248 | 248 | |
249 | | - $text = preg_replace("/\x7f1$u\x7f$id\x7f.+?$/m",$html,$text,1); # replace first occurence of this trees root-id |
| 249 | + $text = preg_replace("/\x7f1$u\x7f$id\x7f.+?$/m", $html, $text, 1); # replace first occurence of this trees root-id |
250 | 250 | $nodes = ''; |
251 | 251 | $last = -1; |
252 | 252 | } |
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
256 | | - $text = preg_replace("/\x7f1$u\x7f.+?[\\r\\n]+/m",'',$text); # Remove all unreplaced row information |
| 256 | + $text = preg_replace("/\x7f1$u\x7f.+?[\\r\\n]+/m", '', $text); # Remove all unreplaced row information |
257 | 257 | return true; |
258 | 258 | } |
259 | 259 | |
— | — | @@ -271,9 +271,9 @@ |
272 | 272 | /** |
273 | 273 | * Needed in MediaWiki >1.8.0 for magic word hooks to work properly |
274 | 274 | */ |
275 | | -function wfTreeAndMenuLanguageGetMagic(&$magicWords,$langCode = 0) { |
276 | | - global $wgTreeMagic,$wgMenuMagic; |
277 | | - $magicWords[$wgTreeMagic] = array($langCode,$wgTreeMagic); |
278 | | - $magicWords[$wgMenuMagic] = array($langCode,$wgMenuMagic); |
| 275 | +function wfTreeAndMenuLanguageGetMagic(&$magicWords, $langCode = 0) { |
| 276 | + global $wgTreeMagic, $wgMenuMagic; |
| 277 | + $magicWords[$wgTreeMagic] = array($langCode, $wgTreeMagic); |
| 278 | + $magicWords[$wgMenuMagic] = array($langCode, $wgMenuMagic); |
279 | 279 | return true; |
280 | 280 | } |