r83582 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83581‎ | r83582 | r83583 >
Date:12:15, 9 March 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
adding js files and copy of old file
Modified paths:
  • /branches/SemanticMaps0.8/includes/forminputs/SM_FormInput.old.php (added) (history)
  • /branches/SemanticMaps0.8/includes/services/GoogleMaps/jquery.googlemaps2input.js (added) (history)
  • /branches/SemanticMaps0.8/includes/services/GoogleMaps3/jquery.googlemapsinput.js (added) (history)
  • /branches/SemanticMaps0.8/includes/services/OpenLayers/jquery.openlayersinput.js (added) (history)
  • /branches/SemanticMaps0.8/includes/services/YahooMaps/jquery.yahoomapsinput.js (added) (history)

Diff [purge]

Index: branches/SemanticMaps0.8/includes/services/GoogleMaps3/jquery.googlemapsinput.js
@@ -0,0 +1,18 @@
 2+/**
 3+ * JavasSript for the Google Maps v3 form input of the Semantic Maps extension.
 4+ * @see http://www.mediawiki.org/wiki/Extension:Semantic_Maps
 5+ *
 6+ * @since 0.8
 7+ * @ingroup SemanticMaps
 8+ *
 9+ * @licence GNU GPL v3
 10+ * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
 11+ */
 12+
 13+(function( $ ){ $.fn.googlemapsinput = function( options ) {
 14+
 15+
 16+
 17+ return this;
 18+
 19+}; })( jQuery );
\ No newline at end of file
Property changes on: branches/SemanticMaps0.8/includes/services/GoogleMaps3/jquery.googlemapsinput.js
___________________________________________________________________
Added: svn:eol-style
120 + native
Index: branches/SemanticMaps0.8/includes/services/YahooMaps/jquery.yahoomapsinput.js
@@ -0,0 +1,18 @@
 2+/**
 3+ * JavasSript for the Yahoo! Maps form input of the Semantic Maps extension.
 4+ * @see http://www.mediawiki.org/wiki/Extension:Semantic_Maps
 5+ *
 6+ * @since 0.8
 7+ * @ingroup SemanticMaps
 8+ *
 9+ * @licence GNU GPL v3
 10+ * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
 11+ */
 12+
 13+(function( $ ){ $.fn.yahoomapsinput = function( options ) {
 14+
 15+
 16+
 17+ return this;
 18+
 19+}; })( jQuery );
\ No newline at end of file
Property changes on: branches/SemanticMaps0.8/includes/services/YahooMaps/jquery.yahoomapsinput.js
___________________________________________________________________
Added: svn:eol-style
120 + native
Index: branches/SemanticMaps0.8/includes/services/OpenLayers/jquery.openlayersinput.js
@@ -0,0 +1,18 @@
 2+/**
 3+ * JavasSript for the OpenLayers form input of the Semantic Maps extension.
 4+ * @see http://www.mediawiki.org/wiki/Extension:Semantic_Maps
 5+ *
 6+ * @since 0.8
 7+ * @ingroup SemanticMaps
 8+ *
 9+ * @licence GNU GPL v3
 10+ * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
 11+ */
 12+
 13+(function( $ ){ $.fn.openlayersinput = function( options ) {
 14+
 15+
 16+
 17+ return this;
 18+
 19+}; })( jQuery );
\ No newline at end of file
Property changes on: branches/SemanticMaps0.8/includes/services/OpenLayers/jquery.openlayersinput.js
___________________________________________________________________
Added: svn:eol-style
120 + native
Index: branches/SemanticMaps0.8/includes/services/GoogleMaps/jquery.googlemaps2input.js
@@ -0,0 +1,18 @@
 2+/**
 3+ * JavasSript for the Google Maps v2 form input of the Semantic Maps extension.
 4+ * @see http://www.mediawiki.org/wiki/Extension:Semantic_Maps
 5+ *
 6+ * @since 0.8
 7+ * @ingroup SemanticMaps
 8+ *
 9+ * @licence GNU GPL v3
 10+ * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
 11+ */
 12+
 13+(function( $ ){ $.fn.googlemaps2input = function( options ) {
 14+
 15+
 16+
 17+ return this;
 18+
 19+}; })( jQuery );
\ No newline at end of file
Property changes on: branches/SemanticMaps0.8/includes/services/GoogleMaps/jquery.googlemaps2input.js
___________________________________________________________________
Added: svn:eol-style
120 + native
Index: branches/SemanticMaps0.8/includes/forminputs/SM_FormInput.old.php
@@ -0,0 +1,392 @@
 2+<?php
 3+
 4+/**
 5+ * Abstract class that provides the common functionality for all map form inputs
 6+ *
 7+ * @file SM_FormInput.php
 8+ * @ingroup SemanticMaps
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+abstract class SMFormInput implements iMappingFeature {
 13+
 14+ /**
 15+ * Ensures all dependencies for the used map are loaded, and increases that map service's count
 16+ */
 17+ protected abstract function addFormDependencies();
 18+
 19+ /**
 20+ * Returns the zoom level at which the whole earth is visible.
 21+ */
 22+ protected abstract function getEarthZoom();
 23+
 24+ /**
 25+ * List of parameter definitions for forms.
 26+ *
 27+ * @var array or false
 28+ */
 29+ protected static $formParameters = false;
 30+
 31+ /**
 32+ * @var iMappingService
 33+ */
 34+ protected $service;
 35+
 36+ /**
 37+ * @var array
 38+ */
 39+ protected $markerCoords;
 40+
 41+ /**
 42+ * Parameters specific to this feature.
 43+ *
 44+ * @var mixed
 45+ */
 46+ protected $specificParameters = false;
 47+
 48+ protected $coordsFieldName;
 49+
 50+ private $coordinates;
 51+
 52+ /**
 53+ * Constructor.
 54+ *
 55+ * @param iMappingService $service
 56+ */
 57+ public function __construct( iMappingService $service ) {
 58+ $this->service = $service;
 59+ }
 60+
 61+ /**
 62+ * Returns the specific parameters by first checking if they have been initialized yet,
 63+ * doing to work if this is not the case, and then returning them.
 64+ *
 65+ * @since 0.6.5
 66+ *
 67+ * @return array
 68+ */
 69+ public final function getSpecificParameterInfo() {
 70+ if ( $this->specificParameters === false ) {
 71+ $this->specificParameters = array();
 72+ $this->initSpecificParamInfo( $this->specificParameters );
 73+ }
 74+
 75+ return $this->specificParameters;
 76+ }
 77+
 78+ /**
 79+ * Initializes the specific parameters.
 80+ *
 81+ * Override this method to set parameters specific to a feature service comibination in
 82+ * the inheriting class.
 83+ *
 84+ * @since 0.6.5
 85+ *
 86+ * @param array $parameters
 87+ */
 88+ protected function initSpecificParamInfo( array &$parameters ) {
 89+ }
 90+
 91+ /**
 92+ * Validates and corrects the provided map properties, and the sets them as class fields.
 93+ *
 94+ * @param array $mapProperties
 95+ *
 96+ * @return mixed ValidationError object if there is a fatal error, false othewise
 97+ */
 98+ protected final function setMapProperties( array $mapProperties ) {
 99+ /*
 100+ * Assembliy of the allowed parameters and their information.
 101+ * The main parameters (the ones that are shared by everything) are overidden
 102+ * by the feature parameters (the ones specific to a feature). The result is then
 103+ * again overidden by the service parameters (the ones specific to the service),
 104+ * and finally by the specific parameters (the ones specific to a service-feature combination).
 105+ */
 106+ $parameterInfo = $this->getFormParameterInfo();
 107+ $this->service->addParameterInfo( $parameterInfo );
 108+
 109+ // TODO
 110+ $parameterInfo = array_merge_recursive( $parameterInfo, $this->getSpecificParameterInfo() );
 111+
 112+ $validator = new Validator( 'form', false ); // TODO
 113+
 114+ $validator->setParameters( $mapProperties, $parameterInfo );
 115+
 116+ $validator->validateParameters();
 117+
 118+ $fatalError = $validator->hasFatalError();
 119+
 120+ if ( $fatalError === false ) {
 121+ $parameters = $validator->getParameterValues();
 122+
 123+ foreach ( $parameters as $paramName => $paramValue ) {
 124+ if ( !property_exists( __CLASS__, $paramName ) ) {
 125+ $this-> { $paramName } = $paramValue;
 126+ }
 127+ else {
 128+ // If this happens in any way, it could be a big vunerability, so throw an exception.
 129+ throw new Exception( 'Attempt to override a class field during map property assignment. Field name: ' . $paramName );
 130+ }
 131+ }
 132+ }
 133+
 134+ return $fatalError;
 135+ }
 136+
 137+ /**
 138+ * This function is a hook for Semantic Forms, and returns the HTML needed in
 139+ * the form to handle coordinate data.
 140+ *
 141+ * TODO: Use function args for sf stuffz
 142+ *
 143+ * @return array
 144+ */
 145+ public final function formInputHTML( $coordinates, $input_name, $is_mandatory, $is_disabled, $field_args ) {
 146+ global $sfgTabIndex;
 147+
 148+ $this->coordinates = $coordinates;
 149+
 150+ $fatalError = $this->setMapProperties( $field_args );
 151+
 152+ if ( $fatalError !== false ) {
 153+ return array(
 154+ '<div><span class="errorbox">' .
 155+ htmlspecialchars( wfMsgExt( 'validator-fatal-error', 'parsemag', $fatalError->getMessage() ) ) .
 156+ '</span></div><br /><br /><br /><br />',
 157+ ''
 158+ );
 159+ }
 160+
 161+ $this->setCoordinates();
 162+ $this->setCentre();
 163+ $this->setZoom();
 164+
 165+ // Create html element names.
 166+ $mapName = $this->service->getMapId();
 167+ $this->coordsFieldName = $mapName . '_coords_' . $sfgTabIndex;
 168+ $infoFieldName = $mapName . '_info_' . $sfgTabIndex;
 169+
 170+ $geocodingFunction = $this->getShowAddressFunction();
 171+
 172+ static $addedFormJs = false;
 173+ if ( !$addedFormJs ) {
 174+ global $wgOut;
 175+ $addedFormJs = true;
 176+
 177+ $n = Xml::escapeJsString( wfMsgForContent( 'maps-abb-north' ) );
 178+ $e = Xml::escapeJsString( wfMsgForContent( 'maps-abb-east' ) );
 179+ $s = Xml::escapeJsString( wfMsgForContent( 'maps-abb-south' ) );
 180+ $w = Xml::escapeJsString( wfMsgForContent( 'maps-abb-west' ) );
 181+ $deg = Xml::escapeJsString( MapsCoordinateParser::SYMBOL_DEG );
 182+
 183+ $wgOut->addInlineScript(
 184+ <<<EOT
 185+function convertLatToDMS (val) {
 186+ return Math.abs(val) + "$deg " + ( val < 0 ? "$s" : "$n" );
 187+}
 188+function convertLngToDMS (val) {
 189+ return Math.abs(val) + "$deg " + ( val < 0 ? "$w" : "$e" );
 190+}
 191+EOT
 192+ );
 193+ }
 194+
 195+ // Create the non specific form HTML.
 196+ $this->output .= Html::input(
 197+ $input_name,
 198+ $this->markerCoords ? MapsCoordinateParser::formatCoordinates( $this->markerCoords ) : '',
 199+ 'text',
 200+ array(
 201+ 'size' => 42, #_O
 202+ 'tabindex' => $sfgTabIndex,
 203+ 'id' => $this->coordsFieldName
 204+ )
 205+ );
 206+
 207+ $this->output .= Html::element(
 208+ 'span',
 209+ array(
 210+ 'class' => 'error_message',
 211+ 'id' => $infoFieldName
 212+ )
 213+ );
 214+
 215+ if ( $geocodingFunction !== false ) {
 216+ $this->addGeocodingField( $geocodingFunction, $mapName, $mapName . '_geocode_' . $sfgTabIndex );
 217+ }
 218+
 219+ if ( $this->markerCoords === false ) {
 220+ $this->markerCoords = array(
 221+ 'lat' => 'null',
 222+ 'lon' => 'null'
 223+ );
 224+
 225+ $this->centreLat = 'null';
 226+ $this->centreLon = 'null';
 227+ }
 228+
 229+ $this->addSpecificMapHTML();
 230+
 231+ $this->addFormDependencies();
 232+
 233+ // TODO: errors
 234+ return array( $this->output, '' );
 235+ }
 236+
 237+ /**
 238+ * Adds geocoding controls to the form.
 239+ *
 240+ * @param string $geocodingFunction
 241+ * @param string $mapName
 242+ * @param string $geocodeFieldName
 243+ */
 244+ private function addGeocodingField( $geocodingFunction, $mapName, $geocodeFieldId ) {
 245+ global $sfgTabIndex;
 246+ $sfgTabIndex++;
 247+
 248+ $adressField = SMFormInput::getDynamicInput(
 249+ 'geocode',
 250+ wfMsg( 'semanticmaps_enteraddresshere' ),
 251+ array(
 252+ 'size' => '30',
 253+ 'id' => $geocodeFieldId,
 254+ 'style' => 'color: #707070',
 255+ 'tabindex' => $sfgTabIndex
 256+ )
 257+ );
 258+
 259+ $notFoundText = Xml::escapeJsString( wfMsg( 'semanticmaps_notfound' ) );
 260+ $mapName = Xml::escapeJsString( $mapName );
 261+ $geoFieldId = Xml::escapeJsString( $geocodeFieldId );
 262+ $coordFieldName = Xml::escapeJsString( $this->coordsFieldName );
 263+
 264+ $this->output .= '<p>' . $adressField .
 265+ Html::input(
 266+ 'geosubmit',
 267+ wfMsg( 'semanticmaps_lookupcoordinates' ),
 268+ 'submit',
 269+ array(
 270+ 'onClick' => "$geocodingFunction( document.forms['createbox'].$geoFieldId.value, '$mapName', '$coordFieldName', '$notFoundText'); return false"
 271+ )
 272+ ) .
 273+ '</p>';
 274+ }
 275+
 276+ /**
 277+ * Sets the zoom so the whole map is visible in case there is no maker yet,
 278+ * and sets it to the default when there is a marker but no zoom parameter.
 279+ */
 280+ private function setZoom() {
 281+ if ( empty( $this->coordinates ) ) {
 282+ $this->zoom = $this->getEarthZoom();
 283+ } else if ( $this->zoom == 'null' ) {
 284+ $this->zoom = $this->service->getDefaultZoom();
 285+ }
 286+ }
 287+
 288+ /**
 289+ * Sets the $this->markerCoords value, which are the coordinates for the marker.
 290+ */
 291+ private function setCoordinates() {
 292+ if ( empty( $this->coordinates ) ) {
 293+ // If no coordinates exist yet, no marker should be displayed.
 294+ $this->markerCoords = false;
 295+ }
 296+ else {
 297+ $this->markerCoords = MapsCoordinateParser::parseCoordinates( $this->coordinates );
 298+ }
 299+ }
 300+
 301+ /**
 302+ * Sets the $centreLat and $centreLon fields.
 303+ * Note: this needs to be done AFTRE the maker coordinates are set.
 304+ */
 305+ private function setCentre() {
 306+ if ( empty( $this->centre ) ) {
 307+ if ( isset( $this->coordinates ) ) {
 308+ $this->centreLat = $this->markerCoords['lat'];
 309+ $this->centreLon = $this->markerCoords['lon'];
 310+ }
 311+ else {
 312+ $this->centreLat = '0';
 313+ $this->centreLon = '0';
 314+ }
 315+ }
 316+ else {
 317+ // Geocode and convert if required.
 318+ $centre = MapsGeocoders::attemptToGeocode( $this->centre, $this->geoservice, $this->serviceName );
 319+
 320+ $this->centreLat = Xml::escapeJsString( $centre['lat'] );
 321+ $this->centreLon = Xml::escapeJsString( $centre['lon'] );
 322+ }
 323+ }
 324+
 325+ /**
 326+ * Returns html for an html input field with a default value that will automatically dissapear when
 327+ * the user clicks in it, and reappers when the focus on the field is lost and it's still empty.
 328+ *
 329+ * @param string $name
 330+ * @param string $value
 331+ * @param array $attribs
 332+ *
 333+ * @return string (html)
 334+ */
 335+ protected static function getDynamicInput( $name, $value, $attribs = array() ) {
 336+ $escapedValue = Xml::escapeJsString( $value );
 337+
 338+ $attribs['onfocus'] = "if (this.value==\"$escapedValue\") {this.value='';}";
 339+ $attribs['onblur'] = "if (this.value=='') {this.value=\"$escapedValue\";}";
 340+
 341+ return Html::input(
 342+ $name,
 343+ $value,
 344+ 'text',
 345+ $attribs
 346+ );
 347+ }
 348+
 349+ /**
 350+ * Returns the name of the JavaScript function to use for live geocoding,
 351+ * or false to indicate there is no such function. Override this method
 352+ * to implement geocoding functionallity.
 353+ *
 354+ * @return mixed: string or false
 355+ */
 356+ protected function getShowAddressFunction() {
 357+ return false;
 358+ }
 359+
 360+ /**
 361+ * Gets the definitions for the parameters specific to the form input feature.
 362+ * This function implements a form of caching by storing the definitions, once
 363+ * created, in self::$formParameters, and returning that field when set.
 364+ *
 365+ * @since 0.6.5
 366+ *
 367+ * @return array
 368+ */
 369+ protected function getFormParameterInfo() {
 370+ $params = MapsMapper::getCommonParameters();
 371+
 372+ // TODO
 373+ //$params['width']->setDefault( $smgFIWidth );
 374+ //$params['height']->setDefault( $smgFIHeight );
 375+
 376+ $params['centre'] = new Parameter(
 377+ 'centre',
 378+ Parameter::TYPE_STRING,
 379+ '', // TODO
 380+ array( 'center' ),
 381+ array(
 382+ new CriterionIsLocation(),
 383+ )
 384+ );
 385+
 386+ // TODO
 387+ //$params['geoservice']->setDefault( $egMapsDefaultGeoService );
 388+ //$params['mappingservice']->setDefault( $egMapsDefaultServices['fi'] );
 389+
 390+ return $params;
 391+ }
 392+
 393+}
\ No newline at end of file
Property changes on: branches/SemanticMaps0.8/includes/forminputs/SM_FormInput.old.php
___________________________________________________________________
Added: svn:eol-style
1394 + native

Status & tagging log