Index: trunk/extensions/geo/geo.php |
— | — | @@ -17,7 +17,9 @@ |
18 | 18 | var $starters = array () ; # The objects to start drawing with |
19 | 19 | var $fits = array () ; # Which objects to fit into the viewport |
20 | 20 | var $object_tree = array () ; # The current object(s) being rendered |
21 | | - var $geo_cache = array () ; # The article cache |
| 21 | + var $cache2 = array () ; # The article cache |
| 22 | + |
| 23 | +# var $geo_cache = array () ; # The article cache |
22 | 24 | |
23 | 25 | function settings ( $sets ) |
24 | 26 | { |
— | — | @@ -125,10 +127,8 @@ |
126 | 128 | # This reads the data and manages the cache |
127 | 129 | function get_raw_text ( $id ) |
128 | 130 | { |
129 | | - global $geo_cache ; |
130 | | - |
131 | | - if ( isset ( $geo_cache[$id] ) ) # Try the cache first... |
132 | | - return $geo_cache[$id] ; |
| 131 | +# if ( isset ( $this->geo_cache[$id] ) ) # Try the cache first... |
| 132 | +# return $this->geo_cache[$id] ; |
133 | 133 | |
134 | 134 | if ( MEDIAWIKI ) # Direct connection to mediawiki database via Article/Title class |
135 | 135 | $contents = $this->read_from_article ( $id ) ; |
— | — | @@ -136,7 +136,7 @@ |
137 | 137 | $contents = $this->read_from_url ( $id ) ; |
138 | 138 | |
139 | 139 | # Return text |
140 | | - $geo_cache[$id] = $contents ; # Cache the result |
| 140 | +# $this->geo_cache[$id] = $contents ; # Cache the result |
141 | 141 | return $contents ; |
142 | 142 | } |
143 | 143 | |
— | — | @@ -233,6 +233,77 @@ |
234 | 234 | } |
235 | 235 | return $ret ; |
236 | 236 | } |
| 237 | + |
| 238 | + # This function converts an ID like "germany.bavaria.cities#*" into the actual list of entries on the given page |
| 239 | + # An ID "#*" will load every entry on that page |
| 240 | + function expand_ids ( $ids , $me ) |
| 241 | + { |
| 242 | + $ret = array () ; |
| 243 | + foreach ( $ids AS $id ) |
| 244 | + { |
| 245 | + $id = trim ( $id ) ; |
| 246 | + if ( substr ( $id , -2 ) == "#*" ) |
| 247 | + { |
| 248 | + $this->geo_get_text ( substr ( $id , 0 , - 2 ) ) ; # Force page into cache |
| 249 | + $match = substr ( $id , 0 , - 1 ) ; |
| 250 | + if ( $match == "#" ) $match = $me . $match ; # the "#*" case |
| 251 | + foreach ( array_keys ( $this->cache2 ) AS $x ) |
| 252 | + { |
| 253 | + if ( substr ( $x , 0 , strlen ( $match ) ) == $match # Same beginning |
| 254 | + AND $x != $match AND $x != $me ) # Don't want recursive inclusion of head element ;-) |
| 255 | + $ret[] = $x ; |
| 256 | + } |
| 257 | + } |
| 258 | + else $ret[] = $id ; |
| 259 | + } |
| 260 | + print implode ( ", " , $ret ) . "\n" ; |
| 261 | + return $ret ; |
| 262 | + } |
| 263 | + |
| 264 | + # This gets the text of an entry. An ID like "germany.bavaria.cities" will get the first entry, |
| 265 | + # while "germany.bavaria.cities#munich" will get only the munich data. |
| 266 | + # The function caches all entries of a page, and acts as a key generator for expand_ids |
| 267 | + function geo_get_text ( $id ) |
| 268 | + { |
| 269 | + $id = trim ( strtolower ( $id ) ) ; |
| 270 | + |
| 271 | + $parts = explode ( "#" , $id ) ; |
| 272 | + if ( count ( $parts ) == 2 ) |
| 273 | + { |
| 274 | + $id = array_shift ( $parts ) ; |
| 275 | + $subid = array_shift ( $parts ) ; |
| 276 | + } |
| 277 | + else $subid = "" ; |
| 278 | + |
| 279 | + # Is this already in the parts cache? |
| 280 | + if ( isset ( $this->cache2["{$id}#{$subid}"] ) ) |
| 281 | + return $this->cache2["{$id}#{$subid}"] ; |
| 282 | + |
| 283 | + # We have this already loaded, nothing to see here... |
| 284 | + if ( isset ( $this->cache2["{$id}#"] ) ) |
| 285 | + return "" ; |
| 286 | + |
| 287 | + $ret = "\n" . $this->get_raw_text ( $id ) ; |
| 288 | + $ret = explode ( "\n==" , $ret ) ; |
| 289 | + |
| 290 | +# if ( $subid == "" ) return $ret[0] ; # Default |
| 291 | + |
| 292 | + $this->cache2["{$id}#"] = array_shift ( $ret ) ; |
| 293 | + foreach ( $ret AS $s ) |
| 294 | + { |
| 295 | + $s = explode ( "\n" , $s , 2 ) ; |
| 296 | + $heading = array_shift ( $s ) ; |
| 297 | + $heading = strtolower ( trim ( str_replace ( "=" , "" , $heading ) ) ) ; |
| 298 | + $this->cache2["{$id}#{$heading}"] = array_shift ( $s ) ; |
| 299 | +# if ( $heading == $subid ) return array_shift ( $s ) ; |
| 300 | + } |
| 301 | + |
| 302 | + if ( isset ( $this->cache2["{$id}#{$subid}"] ) ) |
| 303 | + return $this->cache2["{$id}#{$subid}"] ; |
| 304 | + # print "Not found : {$id}#{$subid}\n" ; |
| 305 | + return "" ; # Query not found |
| 306 | + } |
| 307 | + |
237 | 308 | } |
238 | 309 | |
239 | 310 | # "geo" class |
— | — | @@ -244,7 +315,8 @@ |
245 | 316 | |
246 | 317 | function geo_get_text ( $id , &$params ) |
247 | 318 | { |
248 | | - $id = trim ( strtolower ( $id ) ) ; |
| 319 | + return $params->geo_get_text ( $id ) ; |
| 320 | +/* $id = trim ( strtolower ( $id ) ) ; |
249 | 321 | |
250 | 322 | $parts = explode ( "#" , $id ) ; |
251 | 323 | if ( count ( $parts ) == 2 ) |
— | — | @@ -269,7 +341,7 @@ |
270 | 342 | } |
271 | 343 | # print "Not found : {$id}#{$subid}\n" ; |
272 | 344 | return "" ; # Query not found |
273 | | - } |
| 345 | +*/ } |
274 | 346 | |
275 | 347 | function set_from_id ( $id , &$params ) |
276 | 348 | { |
— | — | @@ -320,6 +392,7 @@ |
321 | 393 | $data = trim ( substr ( $data , 9 ) ) ; |
322 | 394 | $data = trim ( substr ( $data , 1 , strlen ( $data ) - 2 ) ) ; |
323 | 395 | $data = explode ( "," , $data ) ; |
| 396 | + $params->expand_ids ( $data , $this->id ) ; |
324 | 397 | foreach ( $data AS $v ) |
325 | 398 | { |
326 | 399 | $v = $this->fullid ( $v ) ; |
— | — | @@ -396,6 +469,7 @@ |
397 | 470 | if ( $command == "addregs" || $command == "include" ) |
398 | 471 | { |
399 | 472 | $values = explode ( "," , $values ) ; |
| 473 | + $params->expand_ids ( $values , $this->id ) ; |
400 | 474 | foreach ( $values AS $v ) |
401 | 475 | { |
402 | 476 | $v = $this->fullid ( $v ) ; |
— | — | @@ -409,6 +483,7 @@ |
410 | 484 | if ( !$this->draw_this ( $params ) ) return $ret ; |
411 | 485 | $data = array () ; |
412 | 486 | $values = explode ( "," , $values ) ; |
| 487 | + $params->expand_ids ( $values , $this->id ) ; |
413 | 488 | foreach ( $values AS $v ) |
414 | 489 | { |
415 | 490 | $v = $this->fullid ( $v ) ; |
— | — | @@ -473,8 +548,7 @@ |
474 | 549 | $ret .= "<circle cx=\"{$b[0]}\" cy=\"{$b[1]}\" r=\"{$r}\" fill=\"red\" style=\"fill-opacity:0.5\"/>\n" ; |
475 | 550 | $this->add_label ( $b[0] , $b[1] , $params ) ; |
476 | 551 | } |
477 | | - |
478 | | - if ( $match != "" ) |
| 552 | + else if ( $match != "" ) |
479 | 553 | { |
480 | 554 | $a = $this->data[$match] ; |
481 | 555 | foreach ( $a AS $line ) |
Index: trunk/extensions/geo/index.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | " ) ; |
24 | 24 | |
25 | 25 | $svg = $p->getSVG () ; |
26 | | -print $svg ; |
| 26 | +#print $svg ; |
27 | 27 | exit ( 0 ) ; # just make SVG |
28 | 28 | |
29 | 29 | |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | # Storing in temp file |
36 | 36 | $tmpfname = tempnam ( "" , "TR2" ) . ".svg" ; |
37 | 37 | $outfname = tempnam ( "" , "TR2" ) . ".png" ; |
| 38 | +#$outfname = $output_filename ; |
38 | 39 | $handle = fopen($tmpfname, "w"); |
39 | 40 | fwrite($handle, $svg); |
40 | 41 | fclose($handle); |
— | — | @@ -47,7 +48,7 @@ |
48 | 49 | |
49 | 50 | print "<html><head></head><body>" ; |
50 | 51 | print $cmd . " : " . $out ; |
51 | | -#print "<img src=\"/test.png\"/>" ; |
52 | | -print "</body></html>" ; |
| 52 | +print "<img src=\"/{$outfname}\"/>" ; |
| 53 | +print "</body></html>\n" ; |
53 | 54 | |
54 | 55 | ?> |
\ No newline at end of file |