http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73716
Revision: 73716
Author: jeroendedauw
Date: 2010-09-25 05:18:33 +0000 (Sat, 25 Sep 2010)
Log Message:
-----------
Changes for 0.7 - Follow up to r73715 - added file I forgot to svn add
Added Paths:
-----------
trunk/extensions/Maps/includes/manipulations/Maps_ParamDimension.php
Added: trunk/extensions/Maps/includes/manipulations/Maps_ParamDimension.php
===================================================================
--- trunk/extensions/Maps/includes/manipulations/Maps_ParamDimension.php
(rev 0)
+++ trunk/extensions/Maps/includes/manipulations/Maps_ParamDimension.php
2010-09-25 05:18:33 UTC (rev 73716)
@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * Parameter manipulation ensuring the value is width or height.
+ *
+ * @since 0.7
+ *
+ * @file Maps_ParamDimension.php
+ * @ingroup Maps
+ * @ingroup ParameterManipulations
+ *
+ * @author Jeroen De Dauw
+ */
+class MapsParamDimension extends ItemParameterManipulation {
+
+ /**
+ * String indicating if this is for a width or a height.
+ *
+ * @since 0.7
+ *
+ * @var string
+ */
+ protected $dimension;
+
+ /**
+ * Constructor.
+ *
+ * @since 0.7
+ */
+ public function __construct( $dimension ) {
+ parent::__construct();
+
+ $this->dimension = $dimension;
+ }
+
+ /**
+ * @see ItemParameterManipulation::doManipulation
+ *
+ * @since 0.7
+ */
+ public function doManipulation( &$value, array &$parameters ) {
+ global $egMapsSizeRestrictions;
+
+ // Set the default if the value is not valid.
+ if ( !preg_match( '/^\d+(\.\d+)?(px|ex|em|%)?$/', $value ) ) {
+ $value = $this->dimension == 'width' ? $egMapsMapWidth
: $egMapsMapHeight;
+ }
+
+ // Determine the minimum and maximum values.
+ if ( preg_match( '/^.*%$/', $value ) ) {
+ if ( count( $egMapsSizeRestrictions[$this->dimension] )
>= 4 ) {
+ $min =
$egMapsSizeRestrictions[$this->dimension][2];
+ $max =
$egMapsSizeRestrictions[$this->dimension][3];
+ } else {
+ // This is for backward compatibility with
people who have set a custom min and max before 0.6.
+ // Can be removed from version 0.8.
+ $min = 1;
+ $max = 100;
+ }
+ } else {
+ $min = $egMapsSizeRestrictions[$this->dimension][0];
+ $max = $egMapsSizeRestrictions[$this->dimension][1];
+ }
+
+ // See if the actual value is withing the limits.
+ $number = preg_replace( '/[^0-9]/', '', $value );
+ if ( $number < $min ) {
+ $value = $min;
+ } else if ( $number > $max ) {
+ $value = $max;
+ }
+ }
+
+}
\ No newline at end of file
Property changes on:
trunk/extensions/Maps/includes/manipulations/Maps_ParamDimension.php
___________________________________________________________________
Added: svn:eol-style
+ native
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs