r74889 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74888‎ | r74889 | r74890 >
Date:10:17, 17 October 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.7.1 - updated RELEASE-NOTES and did some cleanup
Modified paths:
  • /trunk/extensions/Maps/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_Layer.php (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_Mapper.php (modified) (history)
  • /trunk/extensions/Maps/includes/features/Maps_BasePointMap.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/RELEASE-NOTES
@@ -10,8 +10,14 @@
1111 === Maps 0.7.1 ===
1212 (2010-1x-xx)
1313
14 -*
 14+==== New features ====
1515
 16+* Image layers for OpenLayers maps, defined via pages in the Layer namespace.
 17+
 18+==== Bug fixes ====
 19+
 20+* Support for images without namespace prefix in the display points parser hook.
 21+
1622 === Maps 0.7 ===
1723 (2010-10-15)
1824
Index: trunk/extensions/Maps/includes/Maps_Layer.php
@@ -70,7 +70,9 @@
7171 $this->properties = $properties;
7272
7373 // TODO
74 - $this->properties['source'] = MapsMapper::getImageUrl( $this->properties['source'] );
 74+ if ( array_key_exists( 'source', $this->properties ) ) {
 75+ $this->properties['source'] = MapsMapper::getImageUrl( $this->properties['source'] );
 76+ }
7577 }
7678
7779 /**
@@ -198,7 +200,7 @@
199201
200202 $options = array();
201203
202 - if ( array_key_exists( 'zoomlevels', $this->properties ) ) {
 204+ if ( $this->properties !== false ) {
203205 $options['numZoomLevels'] = $zoomlevels;
204206 }
205207
Index: trunk/extensions/Maps/includes/Maps_Mapper.php
@@ -13,86 +13,6 @@
1414 final class MapsMapper {
1515
1616 /**
17 - * Determines if a value is a valid map dimension, and optionally corrects it.
18 - *
19 - * TODO: move to param validation and manipulation classes
20 - *
21 - * @since 0.6
22 - *
23 - * @param string or number $value The value as it was entered by the user.
24 - * @param string $dimension Must be width or height.
25 - * @param boolean $correct If true, the value will be corrected when invalid. Defaults to false.
26 - * @param number $default The default value for this dimension. Must be set when $correct = true.
27 - *
28 - * @return boolean
29 - */
30 - public static function isMapDimension( &$value, $name, array $parameters, $dimension, $correct = false, $default = 0 ) {
31 - global $egMapsSizeRestrictions;
32 -
33 - // See if the notation is valid.
34 - if ( !preg_match( '/^\d+(\.\d+)?(px|ex|em|%)?$/', $value ) ) {
35 - if ( $correct ) {
36 - $value = $default;
37 - } else {
38 - return false;
39 - }
40 - }
41 -
42 - // Determine the minimum and maximum values.
43 - if ( preg_match( '/^.*%$/', $value ) ) {
44 - if ( count( $egMapsSizeRestrictions[$dimension] ) >= 4 ) {
45 - $min = $egMapsSizeRestrictions[$dimension][2];
46 - $max = $egMapsSizeRestrictions[$dimension][3];
47 - } else {
48 - // This is for backward compatibility with people who have set a custom min and max before 0.6.
49 - $min = 1;
50 - $max = 100;
51 - }
52 - } else {
53 - $min = $egMapsSizeRestrictions[$dimension][0];
54 - $max = $egMapsSizeRestrictions[$dimension][1];
55 - }
56 -
57 - // See if the actual value is withing the limits.
58 - $number = preg_replace( '/[^0-9]/', '', $value );
59 - if ( $number < $min ) {
60 - if ( $correct ) {
61 - $value = $min;
62 - } else {
63 - return false;
64 - }
65 - } else if ( $number > $max ) {
66 - if ( $correct ) {
67 - $value = $max;
68 - } else {
69 - return false;
70 - }
71 - }
72 -
73 - // If this is a 'correct the value call', add 'px' if no unit has been provided.
74 - if ( $correct ) {
75 - if ( !preg_match( '/(px|ex|em|%)$/', $value ) ) {
76 - $value .= 'px';
77 - }
78 - }
79 -
80 - return true;
81 - }
82 -
83 - /**
84 - * Corrects the provided map demension value when not valid.
85 - *
86 - * @since 0.6
87 - *
88 - * @param string or number $value The value as it was entered by the user.
89 - * @param string $dimension Must be width or height.
90 - * @param number $default The default value for this dimension.
91 - */
92 - public static function setMapDimension( &$value, $name, array $parameters, $dimension, $default ) {
93 - self::isMapDimension( $value, $name, $parameters, $dimension, true, $default );
94 - }
95 -
96 - /**
9717 * Add a JavaScript file out of skins/common, or a given relative path.
9818 *
9919 * This is a copy of the native function in OutputPage to work around a pre MW 1.16 bug.
@@ -209,8 +129,8 @@
210130 */
211131 public static function getImageUrl( $image ) {
212132 $title = Title::newFromText( $image, NS_FILE );
213 -
214 - if ( $title->getNamespace() == NS_FILE && $title->exists() ) {
 133+
 134+ if ( !is_null( $title ) && $title->getNamespace() == NS_FILE && $title->exists() ) {
215135 $imagePage = new ImagePage( $title );
216136 $image = $imagePage->getDisplayedFile()->getURL();
217137 }
Index: trunk/extensions/Maps/includes/features/Maps_BasePointMap.php
@@ -148,16 +148,7 @@
149149 }
150150
151151 if ( $markerData['icon'] != '' ) {
152 - if ( strpos( $markerData['icon'], ':' ) === false ) {
153 - $markerData['icon'] = 'File:' . $markerData['icon'];
154 - }
155 -
156 - $title = Title::newFromText( $markerData['icon'] );
157 -
158 - if ( !is_null( $title ) && $title->exists() ) {
159 - $iconImagePage = new ImagePage( $title );
160 - $markerData['icon'] = $iconImagePage->getDisplayedFile()->getURL();
161 - }
 152+ $markerData['icon'] = MapsMapper::getImageUrl( $markerData['icon'] );
162153 }
163154
164155 // Temporary fix, will refactor away later

Status & tagging log