r7178 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r7177‎ | r7178 | r7179 >
Date:15:57, 19 January 2005
Author:magnus_manske
Status:old
Tags:
Comment:
just saving, half-finished
Modified paths:
  • /trunk/extensions/geo/geo.php (modified) (history)
  • /trunk/extensions/geo/index.php (modified) (history)

Diff [purge]

Index: trunk/extensions/geo/geo.php
@@ -17,7 +17,9 @@
1818 var $starters = array () ; # The objects to start drawing with
1919 var $fits = array () ; # Which objects to fit into the viewport
2020 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
2224
2325 function settings ( $sets )
2426 {
@@ -125,10 +127,8 @@
126128 # This reads the data and manages the cache
127129 function get_raw_text ( $id )
128130 {
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] ;
133133
134134 if ( MEDIAWIKI ) # Direct connection to mediawiki database via Article/Title class
135135 $contents = $this->read_from_article ( $id ) ;
@@ -136,7 +136,7 @@
137137 $contents = $this->read_from_url ( $id ) ;
138138
139139 # Return text
140 - $geo_cache[$id] = $contents ; # Cache the result
 140+# $this->geo_cache[$id] = $contents ; # Cache the result
141141 return $contents ;
142142 }
143143
@@ -233,6 +233,77 @@
234234 }
235235 return $ret ;
236236 }
 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+
237308 }
238309
239310 # "geo" class
@@ -244,7 +315,8 @@
245316
246317 function geo_get_text ( $id , &$params )
247318 {
248 - $id = trim ( strtolower ( $id ) ) ;
 319+ return $params->geo_get_text ( $id ) ;
 320+/* $id = trim ( strtolower ( $id ) ) ;
249321
250322 $parts = explode ( "#" , $id ) ;
251323 if ( count ( $parts ) == 2 )
@@ -269,7 +341,7 @@
270342 }
271343 # print "Not found : {$id}#{$subid}\n" ;
272344 return "" ; # Query not found
273 - }
 345+*/ }
274346
275347 function set_from_id ( $id , &$params )
276348 {
@@ -320,6 +392,7 @@
321393 $data = trim ( substr ( $data , 9 ) ) ;
322394 $data = trim ( substr ( $data , 1 , strlen ( $data ) - 2 ) ) ;
323395 $data = explode ( "," , $data ) ;
 396+ $params->expand_ids ( $data , $this->id ) ;
324397 foreach ( $data AS $v )
325398 {
326399 $v = $this->fullid ( $v ) ;
@@ -396,6 +469,7 @@
397470 if ( $command == "addregs" || $command == "include" )
398471 {
399472 $values = explode ( "," , $values ) ;
 473+ $params->expand_ids ( $values , $this->id ) ;
400474 foreach ( $values AS $v )
401475 {
402476 $v = $this->fullid ( $v ) ;
@@ -409,6 +483,7 @@
410484 if ( !$this->draw_this ( $params ) ) return $ret ;
411485 $data = array () ;
412486 $values = explode ( "," , $values ) ;
 487+ $params->expand_ids ( $values , $this->id ) ;
413488 foreach ( $values AS $v )
414489 {
415490 $v = $this->fullid ( $v ) ;
@@ -473,8 +548,7 @@
474549 $ret .= "<circle cx=\"{$b[0]}\" cy=\"{$b[1]}\" r=\"{$r}\" fill=\"red\" style=\"fill-opacity:0.5\"/>\n" ;
475550 $this->add_label ( $b[0] , $b[1] , $params ) ;
476551 }
477 -
478 - if ( $match != "" )
 552+ else if ( $match != "" )
479553 {
480554 $a = $this->data[$match] ;
481555 foreach ( $a AS $line )
Index: trunk/extensions/geo/index.php
@@ -22,7 +22,7 @@
2323 " ) ;
2424
2525 $svg = $p->getSVG () ;
26 -print $svg ;
 26+#print $svg ;
2727 exit ( 0 ) ; # just make SVG
2828
2929
@@ -34,6 +34,7 @@
3535 # Storing in temp file
3636 $tmpfname = tempnam ( "" , "TR2" ) . ".svg" ;
3737 $outfname = tempnam ( "" , "TR2" ) . ".png" ;
 38+#$outfname = $output_filename ;
3839 $handle = fopen($tmpfname, "w");
3940 fwrite($handle, $svg);
4041 fclose($handle);
@@ -47,7 +48,7 @@
4849
4950 print "<html><head></head><body>" ;
5051 print $cmd . " : " . $out ;
51 -#print "<img src=\"/test.png\"/>" ;
52 -print "</body></html>" ;
 52+print "<img src=\"/{$outfname}\"/>" ;
 53+print "</body></html>\n" ;
5354
5455 ?>
\ No newline at end of file

Status & tagging log