r74883 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74882‎ | r74883 | r74884 >
Date:08:08, 17 October 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added validation to layer pages
Modified paths:
  • /trunk/extensions/Maps/Maps.i18n.php (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_Layer.php (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_LayerPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps.i18n.php
@@ -26,6 +26,7 @@
2727 'maps-ns-layer-talk' => 'Layer talk',
2828 'maps-layer-property' => 'Property',
2929 'maps-layer-value' => 'Value',
 30+ 'maps-error-invalid-layerdef' => 'This layer definition is not valid.',
3031
3132 // Validation
3233 'validation-error-invalid-location' => 'Parameter $1 must be a valid location.',
Index: trunk/extensions/Maps/includes/Maps_LayerPage.php
@@ -13,6 +13,15 @@
1414 class MapsLayerPage extends Article {
1515
1616 /**
 17+ * Cached MapsLayer or false.
 18+ *
 19+ * @since 0.7.1
 20+ *
 21+ * @var false or MapsLayer
 22+ */
 23+ protected $cachedLayer = false;
 24+
 25+ /**
1726 * Constructor.
1827 *
1928 * @since 0.7.1
@@ -33,6 +42,16 @@
3443
3544 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
3645
 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+
3756 $rows = array();
3857
3958 $rows[] = Html::rawElement(
@@ -50,7 +69,7 @@
5170 )
5271 );
5372
54 - foreach ( $this->getProperties() as $property => $value ) {
 73+ foreach ( $layer->getProperties() as $property => $value ) {
5574 $rows[] = Html::rawElement(
5675 'tr',
5776 array(),
@@ -71,6 +90,18 @@
7291 }
7392
7493 /**
 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+ /**
75106 * Returns a new MapsLayer object created from the data in the page.
76107 *
77108 * @since 0.7.1
@@ -78,7 +109,11 @@
79110 * @return MapsLayer
80111 */
81112 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;
83118 }
84119
85120 /**
@@ -89,12 +124,6 @@
90125 * @return array
91126 */
92127 protected function getProperties() {
93 - static $cachedProperties = false;
94 -
95 - if ( $cachedProperties !== false ) {
96 - return $cachedProperties;
97 - }
98 -
99128 $properties = array();
100129
101130 if ( is_null( $this->mContent ) ) {
@@ -109,7 +138,8 @@
110139 }
111140 }
112141
113 - $cachedProperties = $properties;
 142+ $properties['type'] = array_key_exists( 'type', $properties ) ? $properties['type'] : MapsLayer::getDefaultType();
 143+
114144 return $properties;
115145 }
116146
Index: trunk/extensions/Maps/includes/Maps_Layer.php
@@ -81,17 +81,6 @@
8282 }
8383
8484 /**
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 - /**
9685 * Returns the type of the layer.
9786 *
9887 * @since 0.7.1
@@ -103,6 +92,17 @@
10493 }
10594
10695 /**
 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+ /**
107107 * Gets if the properties make up a valid layer definition.
108108 *
109109 * @since 0.7.1
@@ -125,6 +125,17 @@
126126 else {
127127 return false;
128128 }
 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;
129140 }
130141
131142 /**

Status & tagging log