http://www.mediawiki.org/wiki/Special:Code/MediaWiki/83596

Revision: 83596
Author:   jeroendedauw
Date:     2011-03-09 17:48:06 +0000 (Wed, 09 Mar 2011)
Log Message:
-----------
some work on the form inputs

Modified Paths:
--------------
    branches/SemanticMaps0.8/includes/forminputs/SM_FormInput.php
    branches/SemanticMaps0.8/includes/forminputs/SM_FormInputs.php
    branches/SemanticMaps0.8/includes/queryprinters/SM_MapPrinter.php
    branches/SemanticMaps0.8/includes/services/GoogleMaps3/SM_GoogleMaps3.php
    
branches/SemanticMaps0.8/includes/services/GoogleMaps3/jquery.googlemapsinput.js

Added Paths:
-----------
    
branches/SemanticMaps0.8/includes/services/GoogleMaps3/SM_GoogleMaps3FormInput.php
    
branches/SemanticMaps0.8/includes/services/GoogleMaps3/ext.sm.googlemapsinput.js

Modified: branches/SemanticMaps0.8/includes/forminputs/SM_FormInput.php
===================================================================
--- branches/SemanticMaps0.8/includes/forminputs/SM_FormInput.php       
2011-03-09 17:30:22 UTC (rev 83595)
+++ branches/SemanticMaps0.8/includes/forminputs/SM_FormInput.php       
2011-03-09 17:48:06 UTC (rev 83596)
@@ -1,6 +1,14 @@
 <?php
 
-
+/**
+ * Base form input class.
+ *
+ * @file SM_FormInput.php
+ * @ingroup SemanticMaps
+ *
+ * @licence GNU GPL v3
+ * @author Jeroen De Dauw < jeroended...@gmail.com >
+ */
 class SMFormInput {
 
        /**
@@ -21,5 +29,157 @@
                $this->service = $service;
        }
        
+       /**
+        * Returns an array containing the parameter info.
+        * 
+        * @since 0.8
+        * 
+        * @return array
+        */
+       protected function getParameterInfo() {
+               $params = MapsMapper::getCommonParameters();
+               $this->service->addParameterInfo( $params );            
+               
+               $params['zoom']->setDefault( false );           
+               $params['zoom']->setDoManipulationOfDefault( false );           
        
+               
+               $params['centre'] = new Parameter( 'centre' );
+               $params['centre']->setDefault( false );
+               $params['centre']->addAliases( 'center' );
+               $params['centre']->addCriteria( new CriterionIsLocation() );
+               $params['centre']->setDoManipulationOfDefault( false );
+               $manipulation = new MapsParamLocation();
+               $manipulation->toJSONObj = true;
+               $params['centre']->addManipulations( $manipulation );   
+
+               $params['icon'] = new Parameter( 'icon' );
+               $params['icon']->setDefault( '' );
+               $params['icon']->addCriteria( New CriterionNotEmpty() );
+               
+               return $params;
+       }
        
-}
\ No newline at end of file
+       /**
+        * 
+        * 
+        * @since 0.8
+        * 
+        * @param string $coordinates
+        * @param string $input_name
+        * @param boolean $is_mandatory
+        * @param boolean $is_disabled
+        * @param array $field_args
+        * 
+        * @return string
+        */
+       public function getInputOutput( $coordinates, $input_name, 
$is_mandatory, $is_disabled, array $params ) {
+               $parameters = array();
+               foreach ( $params as $key => $value ) {
+                       if ( !is_array( $value ) && !is_object( $value ) ) {
+                               $parameters[$key] = $value;
+                       }
+               }                       
+               
+               $validator = new Validator( wfMsg( 'maps_' . 
$this->service->getName() ), false );
+               $validator->setParameters( $parameters, 
$this->getParameterInfo() );
+               $validator->validateParameters();
+               
+               $fatalError  = $validator->hasFatalError();
+               
+               if ( $fatalError === false ) {
+                       global $wgParser, $wgTitle;
+                       
+                       $params = $validator->getParameterValues();
+                       $mapName = $this->service->getMapId();
+                       
+                       $output = $this->getInputHTML( $params, $wgParser, 
$mapName ) . $this->getJSON( $params, $wgParser, $mapName );
+                       
+                       $this->service->addResourceModules( 
$this->getResourceModules() );
+                       
+                       if ( $wgTitle->isSpecialPage() ) {
+                               global $wgOut;
+                               $this->service->addDependencies( $wgOut );
+                       }
+                       else {
+                               $this->service->addDependencies( $wgParser );   
                
+                       }                       
+                       
+                       return $output;
+               }
+               else {
+                       return
+                               '<span class="errorbox">' .
+                               htmlspecialchars( wfMsgExt( 
'validator-fatal-error', 'parsemag', $fatalError->getMessage() ) ) . 
+                               '</span>';                      
+               }                       
+       }
+       
+       /**
+        * Returns the HTML to display the map input.
+        * 
+        * @since 0.8
+        * 
+        * @param array $params
+        * @param Parser $parser
+        * @param string $mapName
+        * 
+        * @return string
+        */
+       protected function getInputHTML( array $params, Parser $parser, 
$mapName ) {
+               return Html::element(
+                       'div',
+                       array(
+                               'id' => $mapName . '_forminput',
+                       ),
+                       wfMsg( 'semanticmaps-loading-forminput' )
+               );
+       }
+
+       /**
+        * Returns the JSON with the maps data.
+        *
+        * @since 0.8
+        *
+        * @param array $params
+        * @param Parser $parser
+        * @param string $mapName
+        * 
+        * @return string
+        */     
+       protected function getJSON( array $params, Parser $parser, $mapName ) {
+               $object = $this->getJSONObject( $params, $parser );
+               
+               if ( $object === false ) {
+                       return '';
+               }
+               
+               return Html::inlineScript(
+                       MapsMapper::getBaseMapJSON( $this->service->getName() . 
'_forminputs' )
+                       . 
"maps.{$this->service->getName()}_forminputs.{$mapName}=" . json_encode( 
$object ) . ';'
+               );
+       }
+       
+       /**
+        * Returns a PHP object to encode to JSON with the map data.
+        *
+        * @since 0.8
+        *
+        * @param array $params
+        * @param Parser $parser
+        * 
+        * @return mixed
+        */     
+       protected function getJSONObject( array $params, Parser $parser ) {
+               return $params;
+       }
+       
+       /**
+        * @since 0.8
+        * 
+        * @return array of string
+        */
+       protected function getResourceModules() {
+               return array();
+       }
+       
+}

Modified: branches/SemanticMaps0.8/includes/forminputs/SM_FormInputs.php
===================================================================
--- branches/SemanticMaps0.8/includes/forminputs/SM_FormInputs.php      
2011-03-09 17:30:22 UTC (rev 83595)
+++ branches/SemanticMaps0.8/includes/forminputs/SM_FormInputs.php      
2011-03-09 17:48:06 UTC (rev 83596)
@@ -100,5 +100,5 @@
        $formInput = $service->getFeatureInstance( 'fi' );    
     
     // Get and return the form input HTML from the hook corresponding with the 
provided service.
-    return $formInput->formInputHTML( $coordinates, $input_name, 
$is_mandatory, $is_disabled, $field_args );
+    return $formInput->getInputOutput( $coordinates, $input_name, 
$is_mandatory, $is_disabled, $field_args );
 }

Modified: branches/SemanticMaps0.8/includes/queryprinters/SM_MapPrinter.php
===================================================================
--- branches/SemanticMaps0.8/includes/queryprinters/SM_MapPrinter.php   
2011-03-09 17:30:22 UTC (rev 83595)
+++ branches/SemanticMaps0.8/includes/queryprinters/SM_MapPrinter.php   
2011-03-09 17:48:06 UTC (rev 83596)
@@ -9,6 +9,8 @@
  *
  * @licence GNU GPL v3
  * @author Jeroen De Dauw < jeroended...@gmail.com >
+ * 
+ * TODO: implement forceshow and showtitle
  */
 class SMMapPrinter extends SMWResultPrinter {
        

Modified: 
branches/SemanticMaps0.8/includes/services/GoogleMaps3/SM_GoogleMaps3.php
===================================================================
--- branches/SemanticMaps0.8/includes/services/GoogleMaps3/SM_GoogleMaps3.php   
2011-03-09 17:30:22 UTC (rev 83595)
+++ branches/SemanticMaps0.8/includes/services/GoogleMaps3/SM_GoogleMaps3.php   
2011-03-09 17:48:06 UTC (rev 83596)
@@ -10,24 +10,39 @@
 /**
  * This file holds the general information for the Google Maps v3 service.
  *
+ * @since 0.8
+ *
  * @file SM_GoogleMaps3.php
  * @ingroup SMGoogleMaps3
  *
- * @author Jeroen De Dauw
+ * @licence GNU GPL v3
+ * @author Jeroen De Dauw < jeroended...@gmail.com >
  */
 
 if ( !defined( 'MEDIAWIKI' ) ) {
        die( 'Not an entry point.' );
 }
 
+$wgResourceModules['ext.sm.fi.googlemaps3'] = array(
+       'dependencies' => array( 'ext.maps.googlemaps3' ),
+       'localBasePath' => dirname( __FILE__ ),
+       'remoteBasePath' => $smgScriptPath .  '/includes/services/GoogleMaps3', 
+       'group' => 'ext.semanticmaps',
+       'scripts' => array(
+               'jquery.googlemapsinput.js',
+               'ext.sm.googlemapsinput.js'
+       ),
+);
+
 $wgHooks['MappingServiceLoad'][] = 'smfInitGoogleMaps3';
 
 function smfInitGoogleMaps3() {
        global $wgAutoloadClasses;
        
-       $wgAutoloadClasses['SMGoogleMaps3QP'] = dirname( __FILE__ ) . 
'/SM_GoogleMaps3QP.php';
+       $wgAutoloadClasses['SMGoogleMaps3FormInput'] = dirname( __FILE__ ) . 
'/SM_GoogleMaps3FormInput.php';
        
        MapsMappingServices::registerServiceFeature( 'googlemaps3', 'qp', 
'SMMapPrinter' );
+       MapsMappingServices::registerServiceFeature( 'googlemaps3', 'fi', 
'SMGoogleMaps3FormInput' );
        
        return true;
 }

Added: 
branches/SemanticMaps0.8/includes/services/GoogleMaps3/SM_GoogleMaps3FormInput.php
===================================================================
--- 
branches/SemanticMaps0.8/includes/services/GoogleMaps3/SM_GoogleMaps3FormInput.php
                          (rev 0)
+++ 
branches/SemanticMaps0.8/includes/services/GoogleMaps3/SM_GoogleMaps3FormInput.php
  2011-03-09 17:48:06 UTC (rev 83596)
@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * Google Maps v3 form input class.
+ *
+ * @file SM_GoogleMaps3FormInput.php
+ * @ingroup SemanticMaps
+ *
+ * @licence GNU GPL v3
+ * @author Jeroen De Dauw < jeroended...@gmail.com >
+ */
+class SMGoogleMaps3FormInput extends SMFormInput {
+       
+       /**
+        * @see SMFormInput::getInputHTML
+        * 
+        * @since 0.8
+        * 
+        * @param array $params
+        * @param Parser $parser
+        * @param string $mapName
+        * 
+        * @return string
+        */     
+       protected function getInputHTML( array $params, Parser $parser, 
$mapName ) {
+               $html = '';
+               
+               $html .= parent::getInputHTML( $params, $parser, $mapName );
+               
+               return $html;
+       }
+       
+       /**
+        * @see SMFormInput::getResourceModules
+        * 
+        * @since 0.8
+        * 
+        * @return array of string
+        */
+       protected function getResourceModules() {
+               return array_merge( parent::getResourceModules(), array( 
'ext.sm.fi.googlemaps3' ) );
+       }       
+       
+}


Property changes on: 
branches/SemanticMaps0.8/includes/services/GoogleMaps3/SM_GoogleMaps3FormInput.php
___________________________________________________________________
Added: svn:eol-style
   + native

Added: 
branches/SemanticMaps0.8/includes/services/GoogleMaps3/ext.sm.googlemapsinput.js
===================================================================
--- 
branches/SemanticMaps0.8/includes/services/GoogleMaps3/ext.sm.googlemapsinput.js
                            (rev 0)
+++ 
branches/SemanticMaps0.8/includes/services/GoogleMaps3/ext.sm.googlemapsinput.js
    2011-03-09 17:48:06 UTC (rev 83596)
@@ -0,0 +1,25 @@
+/**
+ * JavasSript for the Google Maps v3 form input in the Semantic Maps extension.
+ * @see http://www.mediawiki.org/wiki/Extension:Semantic_Maps
+ * 
+ * @since 0.8
+ * @ingroup SemanticMaps
+ * 
+ * @licence GNU GPL v3
+ * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
+ */
+
+jQuery(document).ready(function() {
+       if ( true ) {
+               for ( i in window.maps.googlemaps3_forminputs ) {
+                       jQuery( '#' + i + '_forminput' ).googlemapsinput( i, 
window.maps.googlemaps3_forminputs[i] );
+               }
+       }
+       else {
+               alert( mediaWiki.msg( 'maps-googlemaps3-incompatbrowser' ) );
+               
+               for ( i in window.maps.googlemaps3 ) {
+                       jQuery( '#' + i + '_forminput' ).text( mediaWiki.msg( 
'maps-load-failed' ) );
+               }
+       }       
+});


Property changes on: 
branches/SemanticMaps0.8/includes/services/GoogleMaps3/ext.sm.googlemapsinput.js
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: 
branches/SemanticMaps0.8/includes/services/GoogleMaps3/jquery.googlemapsinput.js
===================================================================
--- 
branches/SemanticMaps0.8/includes/services/GoogleMaps3/jquery.googlemapsinput.js
    2011-03-09 17:30:22 UTC (rev 83595)
+++ 
branches/SemanticMaps0.8/includes/services/GoogleMaps3/jquery.googlemapsinput.js
    2011-03-09 17:48:06 UTC (rev 83596)
@@ -9,9 +9,19 @@
  * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
  */
 
-(function( $ ){ $.fn.googlemapsinput = function( options ) {
+(function( $ ){ $.fn.googlemapsinput = function( mapDivId, options ) {
+       this.text( '' );
        
+       this.html(
+               $( '<div />' )
+                       .attr( {
+                               'id': mapDivId,
+                               'width': options.width,
+                               'height': options.height
+                       } )
+       );
        
+       //$('#' + mapDivId).googlemaps( options )
        
        return this;
        


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to