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

Revision: 71860
Author:   jeroendedauw
Date:     2010-08-28 18:23:20 +0000 (Sat, 28 Aug 2010)

Log Message:
-----------
Follow up to r71859

Modified Paths:
--------------
    trunk/extensions/Maps/ParserHooks/Maps_Coordinates.php

Modified: trunk/extensions/Maps/ParserHooks/Maps_Coordinates.php
===================================================================
--- trunk/extensions/Maps/ParserHooks/Maps_Coordinates.php      2010-08-28 
18:23:04 UTC (rev 71859)
+++ trunk/extensions/Maps/ParserHooks/Maps_Coordinates.php      2010-08-28 
18:23:20 UTC (rev 71860)
@@ -16,10 +16,10 @@
 
 $wgAutoloadClasses['MapsCoordinates'] = dirname( __FILE__ ) . 
'/Maps_Coordinates.php';
 
-$wgHooks['ParserFirstCallInit'][] = 'MapsCoordinates::init';
+$wgHooks['ParserFirstCallInit'][] = 'MapsCoordinates::staticInit';
 
 if ( version_compare( $wgVersion, '1.16alpha', '<' ) ) {
-       $wgHooks['LanguageGetMagic'][] = 'MapsCoordinates::magic';
+       $wgHooks['LanguageGetMagic'][] = 'MapsCoordinates::staticMagic';
 }
 
 /**
@@ -30,85 +30,49 @@
  * 
  * @author Jeroen De Dauw
  */
-class MapsCoordinates {
+class MapsCoordinates extends ParserHook {
        
        /**
-        * Function to hook up the coordinate rendering functions to the parser.
-        * 
-        * @since 0.7
-        * 
-        * @param Parser $wgParser
-        * 
-        * @return true
+        * No LST in pre-5.3 PHP *sigh*.
+        * This is to be refactored as soon as php >=5.3 becomes acceptable.
         */
-       public static function init( Parser &$wgParser ) {
-               $wgParser->setHook( 'coordinates', __CLASS__ . '::renderTag' );
-               $wgParser->setFunctionHook( 'coordinates', __CLASS__ . 
'::renderFunction' );
-               
-               return true;
+       public static function staticMagic( array &$magicWords, $langCode ) {
+               $className = __CLASS__;
+               $instance = new $className();
+               return $instance->magic( $magicWords, $langCode );
        }
        
        /**
-        * Function to add the magic word in pre MW 1.16.
-        * 
-        * @since 0.7
-        * 
-        * @param array $magicWords
-        * @param string $langCode
-        * 
-        * @return true
-        */
-       public static function magic( array &$magicWords, $langCode ) {
-               $magicWords['coordinates'] = array( 0, 'coordinates' );
-               
-               return true;
+        * No LST in pre-5.3 PHP *sigh*.
+        * This is to be refactored as soon as php >=5.3 becomes acceptable.
+        */     
+       public static function staticInit( Parser &$wgParser ) {
+               $className = __CLASS__;
+               $instance = new $className();
+               return $instance->init( $wgParser );
        }       
        
        /**
-        * Handler for rendering the tag hook.
+        * Gets the name of the parser hook.
+        * @see ParserHook::getName
         * 
         * @since 0.7
         * 
-        * @param minxed $input string or null
-        * @param array $args
-        * @param Parser $parser
-        * @param PPFrame $frame
+        * @return string
         */
-       public static function renderTag( $input, array $args, Parser $parser, 
PPFrame $frame ) {
-               $defaultParam = array_shift( self::getDefaultParameters() );
-               
-               if ( !is_null( $defaultParam ) ) {
-                       $args[$defaultParam] = $input;
-               }
-               
-               return self::render( $args, true );
+       protected function getName() {
+               return 'coordinates';
        }
        
        /**
-        * Handler for rendering the function hook.
-        * 
-        * @since 0.7
-        * 
-        * @param Parser $parser
-        * ... further arguments ...
-        */     
-       public static function renderFunction() {
-               $args = func_get_args();
-               
-               // No need for the parser...
-               array_shift( $args );   
-       
-               return array( self::render( $args, false ) );
-       }
-       
-       /**
         * Returns an array containing the parameter info.
+        * @see ParserHook::getParameterInfo
         * 
         * @since 0.7
         * 
         * @return array
         */
-       protected static function getParameterInfo() {
+       protected function getParameterInfo() {
                global $egMapsAvailableServices, $egMapsAvailableCoordNotations;
                global $egMapsDefaultServices, $egMapsDefaultGeoService, 
$egMapsCoordinateNotation;
                global $egMapsAllowCoordsGeocoding, 
$egMapsCoordinateDirectional;
@@ -136,63 +100,35 @@
        
        /**
         * Returns the list of default parameters.
+        * @see ParserHook::getDefaultParameters
         * 
         * @since 0.7
         * 
         * @return array
         */
-       protected static function getDefaultParameters() {
+       protected function getDefaultParameters() {
                return array( 'location', 'format', 'directional' );
        }
        
        /**
         * Renders and returns the output.
+        * @see ParserHook::render
         * 
         * @since 0.7
         * 
-        * @param array $arguments
-        * @param boolean $parsed
+        * @param array $parameters
         * 
         * @return string
         */
-       public static function render( array $arguments, $parsed ) {
-               $manager = new ValidatorManager();
+       public function render( array $parameters ) {
+               $parsedCoords = MapsCoordinateParser::parseCoordinates( 
$parameters['location'] );
                
-               if ( $parsed ) {
-                       $doFormatting = $manager->manageParsedParameters(
-                               $arguments,
-                               self::getParameterInfo(),
-                               self::getDefaultParameters()
-                       );                      
-               }
-               else {
-                       $doFormatting = $manager->manageParameters(
-                               $arguments,
-                               self::getParameterInfo(),
-                               self::getDefaultParameters()
-                       );                      
-               }
-               
-               if ( $doFormatting ) {
-                       $parameters = $manager->getParameters( false );
-                       
-                       $parsedCoords = MapsCoordinateParser::parseCoordinates( 
$parameters['location'] );
-                       
-                       if ( $parsedCoords ) {
-                               $output = 
MapsCoordinateParser::formatCoordinates( $parsedCoords, $parameters['format'], 
$parameters['directional'] );
-                       } else {
-                               $output = htmlspecialchars( wfMsgExt( 
'maps-invalid-coordinates', 'parsemag', $parameters['location'] ) );
-                       }
-                       
-                       $errorList = $manager->getErrorList();
-       
-                       if ( $errorList != '' ) {
-                               $output .= '<br />' . $errorList;
-                       }
+               if ( $parsedCoords ) {
+                       $output = MapsCoordinateParser::formatCoordinates( 
$parsedCoords, $parameters['format'], $parameters['directional'] );
                } else {
-                       $output = $manager->getErrorList();
+                       $output = htmlspecialchars( wfMsgExt( 
'maps-invalid-coordinates', 'parsemag', $parameters['location'] ) );
                }
-       
+               
                return $output;         
        }
        



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to