r62561 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62560‎ | r62561 | r62562 >
Date:00:40, 16 February 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.5.4.
* Added JS var escaping to display_point base class
Modified paths:
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
@@ -47,8 +47,6 @@
4848
4949 $this->setMapName();
5050
51 - $this->doParsing($parser);
52 -
5351 $this->setMarkerData($parser);
5452
5553 $this->createMarkerString();
@@ -88,6 +86,9 @@
8987 private function setMarkerData($parser) {
9088 $this->coordinates = explode(';', $this->coordinates);
9189
 90+ $this->title = Xml::escapeJsString( $parser->recursiveTagParse( $this->title ) );
 91+ $this->label = Xml::escapeJsString( $parser->recursiveTagParse( $this->label ) );
 92+
9293 foreach($this->coordinates as $coordinates) {
9394 $args = explode('~', $coordinates);
9495
@@ -98,11 +99,11 @@
99100
100101 if (count($args) > 1) {
101102 // Parse and add the point specific title if it's present.
102 - $markerData['title'] = $this->doEscaping( $parser->recursiveTagParse( $args[1] ) );
 103+ $markerData['title'] = $parser->recursiveTagParse( $args[1] );
103104
104105 if (count($args) > 2) {
105106 // Parse and add the point specific label if it's present.
106 - $markerData['label'] = $this->doEscaping( $parser->recursiveTagParse( $args[2] ) );
 107+ $markerData['label'] = $parser->recursiveTagParse( $args[2] );
107108
108109 if (count($args) > 3) {
109110 // Add the point specific icon if it's present.
@@ -128,17 +129,19 @@
129130 }
130131
131132 /**
132 - * Creates a JS string with the marker data.
133 - *
134 - * @return unknown_type
 133+ * Creates a JS string with the marker data. Takes care of escaping the used values.
135134 */
136135 private function createMarkerString() {
137136 $markerItems = array();
138137
139138 foreach ($this->markerData as $markerData) {
140 - $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title;
141 - $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label;
 139+ $title = array_key_exists('title', $markerData) ? Xml::escapeJsString($markerData['title']) : $this->title;
 140+ $label = array_key_exists('label', $markerData) ? Xml::escapeJsString($markerData['label']) : $this->label;
142141
 142+ $markerData['lon'] = Xml::escapeJsString($markerData['lon']);
 143+ $markerData['lat'] = Xml::escapeJsString($markerData['lat']);
 144+ $markerData['icon'] = Xml::escapeJsString($markerData['icon']);
 145+
143146 $markerItems[] = str_replace( array('lon', 'lat', 'title', 'label', 'icon'),
144147 array($markerData['lon'], $markerData['lat'], $title, $label, $markerData['icon']),
145148 $this->markerStringFormat
@@ -156,8 +159,8 @@
157160 if (empty($this->centre)) {
158161 if (count($this->markerData) == 1) {
159162 // If centre is not set and there is exactelly one marker, use it's coordinates.
160 - $this->centre_lat = $this->markerData[0]['lat'];
161 - $this->centre_lon = $this->markerData[0]['lon'];
 163+ $this->centre_lat = Xml::escapeJsString( $this->markerData[0]['lat'] );
 164+ $this->centre_lon = Xml::escapeJsString( $this->markerData[0]['lon'] );
162165 }
163166 elseif (count($this->markerData) > 1) {
164167 // If centre is not set and there are multiple markers, set the values to null,
@@ -176,8 +179,8 @@
177180 // If the centre is not false, it will be a valid coordinate, which can be used to set the latitude and longitutde.
178181 if ($this->centre) {
179182 $this->centre = MapsUtils::getLatLon($this->centre);
180 - $this->centre_lat = $this->centre['lat'];
181 - $this->centre_lon = $this->centre['lon'];
 183+ $this->centre_lat = Xml::escapeJsString( $this->centre['lat'] );
 184+ $this->centre_lon = Xml::escapeJsString( $this->centre['lon'] );
182185 }
183186 else { // If it's false, the coordinate was invalid, or geocoding failed. Either way, the default's should be used.
184187 $this->setCentreDefaults();
@@ -193,23 +196,4 @@
194197 $this->centre_lat = $egMapsMapLat;
195198 $this->centre_lon = $egMapsMapLon;
196199 }
197 -
198 - /**
199 - * Parse the wiki text in the title and label values.
200 - *
201 - * @param unknown_type $parser
202 - */
203 - private function doParsing(&$parser) {
204 - $this->title = $this->doEscaping( $parser->recursiveTagParse( $this->title ) );
205 - $this->label = $this->doEscaping( $parser->recursiveTagParse( $this->label ) );
206 - }
207 -
208 - /**
209 - * Escape function for titles and labels.
210 - */
211 - private function doEscaping($text) {
212 - // TODO: links do not get escaped properly yet.
213 - return str_replace("'", "\'", $text);
214 - }
215 -
216200 }
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php
@@ -67,7 +67,7 @@
6868 public function addSpecificMapHTML() {
6969 global $wgJsMimeType;
7070
71 - $onloadFunctions = MapsGoogleMaps::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls);
 71+ $onloadFunctions = MapsGoogleMaps::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls);
7272
7373 $this->output .=<<<END
7474

Status & tagging log