Index: trunk/extensions/Maps/Maps.i18n.php |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | 'maps-ns-layer-talk' => 'Layer talk', |
28 | 28 | 'maps-layer-property' => 'Property', |
29 | 29 | 'maps-layer-value' => 'Value', |
| 30 | + 'maps-error-invalid-layerdef' => 'This layer definition is not valid.', |
30 | 31 | |
31 | 32 | // Validation |
32 | 33 | 'validation-error-invalid-location' => 'Parameter $1 must be a valid location.', |
Index: trunk/extensions/Maps/includes/Maps_LayerPage.php |
— | — | @@ -13,6 +13,15 @@ |
14 | 14 | class MapsLayerPage extends Article { |
15 | 15 | |
16 | 16 | /** |
| 17 | + * Cached MapsLayer or false. |
| 18 | + * |
| 19 | + * @since 0.7.1 |
| 20 | + * |
| 21 | + * @var false or MapsLayer |
| 22 | + */ |
| 23 | + protected $cachedLayer = false; |
| 24 | + |
| 25 | + /** |
17 | 26 | * Constructor. |
18 | 27 | * |
19 | 28 | * @since 0.7.1 |
— | — | @@ -33,6 +42,16 @@ |
34 | 43 | |
35 | 44 | $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); |
36 | 45 | |
| 46 | + $layer = $this->getLayer(); |
| 47 | + |
| 48 | + if ( !$layer->isValid() ) { |
| 49 | + $wgOut->addHTML( |
| 50 | + '<span class="errorbox">' . |
| 51 | + htmlspecialchars( wfMsg( 'maps-error-invalid-layerdef' ) ) . |
| 52 | + '</span><br />' |
| 53 | + ); |
| 54 | + } |
| 55 | + |
37 | 56 | $rows = array(); |
38 | 57 | |
39 | 58 | $rows[] = Html::rawElement( |
— | — | @@ -50,7 +69,7 @@ |
51 | 70 | ) |
52 | 71 | ); |
53 | 72 | |
54 | | - foreach ( $this->getProperties() as $property => $value ) { |
| 73 | + foreach ( $layer->getProperties() as $property => $value ) { |
55 | 74 | $rows[] = Html::rawElement( |
56 | 75 | 'tr', |
57 | 76 | array(), |
— | — | @@ -71,6 +90,18 @@ |
72 | 91 | } |
73 | 92 | |
74 | 93 | /** |
| 94 | + * Returns if the layer definition in the page is valid. |
| 95 | + * |
| 96 | + * @since 0.7.1 |
| 97 | + * |
| 98 | + * @return boolean |
| 99 | + */ |
| 100 | + public function hasValidDefinition() { |
| 101 | + $layer = $this->getLayer(); |
| 102 | + return $layer->isValid(); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
75 | 106 | * Returns a new MapsLayer object created from the data in the page. |
76 | 107 | * |
77 | 108 | * @since 0.7.1 |
— | — | @@ -78,7 +109,11 @@ |
79 | 110 | * @return MapsLayer |
80 | 111 | */ |
81 | 112 | public function getLayer() { |
82 | | - return MapsLayer::newFromArray( $this->getProperties() ); |
| 113 | + if ( $this->cachedLayer === false ) { |
| 114 | + $this->cachedLayer = MapsLayer::newFromArray( $this->getProperties() ); |
| 115 | + } |
| 116 | + |
| 117 | + return $this->cachedLayer; |
83 | 118 | } |
84 | 119 | |
85 | 120 | /** |
— | — | @@ -89,12 +124,6 @@ |
90 | 125 | * @return array |
91 | 126 | */ |
92 | 127 | protected function getProperties() { |
93 | | - static $cachedProperties = false; |
94 | | - |
95 | | - if ( $cachedProperties !== false ) { |
96 | | - return $cachedProperties; |
97 | | - } |
98 | | - |
99 | 128 | $properties = array(); |
100 | 129 | |
101 | 130 | if ( is_null( $this->mContent ) ) { |
— | — | @@ -109,7 +138,8 @@ |
110 | 139 | } |
111 | 140 | } |
112 | 141 | |
113 | | - $cachedProperties = $properties; |
| 142 | + $properties['type'] = array_key_exists( 'type', $properties ) ? $properties['type'] : MapsLayer::getDefaultType(); |
| 143 | + |
114 | 144 | return $properties; |
115 | 145 | } |
116 | 146 | |
Index: trunk/extensions/Maps/includes/Maps_Layer.php |
— | — | @@ -81,17 +81,6 @@ |
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | | - * Sets the properties. |
86 | | - * |
87 | | - * @since 0.7.1 |
88 | | - * |
89 | | - * @param array $properties |
90 | | - */ |
91 | | - public function setProperties( array $properties ) { |
92 | | - $this->properties = $properties; |
93 | | - } |
94 | | - |
95 | | - /** |
96 | 85 | * Returns the type of the layer. |
97 | 86 | * |
98 | 87 | * @since 0.7.1 |
— | — | @@ -103,6 +92,17 @@ |
104 | 93 | } |
105 | 94 | |
106 | 95 | /** |
| 96 | + * Returns the layers properties. |
| 97 | + * |
| 98 | + * @since 0.7.1 |
| 99 | + * |
| 100 | + * @return array |
| 101 | + */ |
| 102 | + public function getProperties() { |
| 103 | + return $this->properties; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
107 | 107 | * Gets if the properties make up a valid layer definition. |
108 | 108 | * |
109 | 109 | * @since 0.7.1 |
— | — | @@ -125,6 +125,17 @@ |
126 | 126 | else { |
127 | 127 | return false; |
128 | 128 | } |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Sets the properties. |
| 133 | + * |
| 134 | + * @since 0.7.1 |
| 135 | + * |
| 136 | + * @param array $properties |
| 137 | + */ |
| 138 | + public function setProperties( array $properties ) { |
| 139 | + $this->properties = $properties; |
129 | 140 | } |
130 | 141 | |
131 | 142 | /** |