summaryrefslogtreecommitdiff
path: root/includes/FormOptions.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2011-06-22 11:28:20 +0200
committerPierre Schmitz <pierre@archlinux.de>2011-06-22 11:28:20 +0200
commit9db190c7e736ec8d063187d4241b59feaf7dc2d1 (patch)
tree46d1a0dee7febef5c2d57a9f7b972be16a163b3d /includes/FormOptions.php
parent78677c7bbdcc9739f6c10c75935898a20e1acd9e (diff)
update to MediaWiki 1.17.0
Diffstat (limited to 'includes/FormOptions.php')
-rw-r--r--includes/FormOptions.php40
1 files changed, 26 insertions, 14 deletions
diff --git a/includes/FormOptions.php b/includes/FormOptions.php
index 262c8c7f..2442a330 100644
--- a/includes/FormOptions.php
+++ b/includes/FormOptions.php
@@ -2,16 +2,17 @@
/**
* Helper class to keep track of options when mixing links and form elements.
*
+ * Copyright © 2008, Niklas Laxström
+ *
* @author Niklas Laxström
- * @copyright Copyright © 2008, Niklas Laxström
*/
class FormOptions implements ArrayAccess {
- const AUTO = -1; //! Automatically detects simple data types
+ const AUTO = -1; // ! Automatically detects simple data types
const STRING = 0;
const INT = 1;
const BOOL = 2;
- const INTNULL = 3; //! Useful for namespace selector
+ const INTNULL = 3; // ! Useful for namespace selector
protected $options = array();
@@ -34,15 +35,15 @@ class FormOptions implements ArrayAccess {
public function delete( $name ) {
$this->validateName( $name, true );
- unset($this->options[$name]);
+ unset( $this->options[$name] );
}
public static function guessType( $data ) {
- if ( is_bool($data) ) {
+ if ( is_bool( $data ) ) {
return self::BOOL;
- } elseif( is_int($data) ) {
+ } elseif ( is_int( $data ) ) {
return self::INT;
- } elseif( is_string($data) ) {
+ } elseif ( is_string( $data ) ) {
return self::STRING;
} else {
throw new MWException( 'Unsupported datatype' );
@@ -52,7 +53,7 @@ class FormOptions implements ArrayAccess {
# Handling values
public function validateName( $name, $strict = false ) {
- if ( !isset($this->options[$name]) ) {
+ if ( !isset( $this->options[$name] ) ) {
if ( $strict ) {
throw new MWException( "Invalid option $name" );
} else {
@@ -64,6 +65,7 @@ class FormOptions implements ArrayAccess {
public function setValue( $name, $value, $force = false ) {
$this->validateName( $name, true );
+
if ( !$force && $value === $this->options[$name]['default'] ) {
// null default values as unchanged
$this->options[$name]['value'] = null;
@@ -74,6 +76,7 @@ class FormOptions implements ArrayAccess {
public function getValue( $name ) {
$this->validateName( $name, true );
+
return $this->getValueReal( $this->options[$name] );
}
@@ -93,16 +96,19 @@ class FormOptions implements ArrayAccess {
public function consumeValue( $name ) {
$this->validateName( $name, true );
$this->options[$name]['consumed'] = true;
+
return $this->getValueReal( $this->options[$name] );
}
public function consumeValues( /*Array*/ $names ) {
$out = array();
+
foreach ( $names as $name ) {
$this->validateName( $name, true );
$this->options[$name]['consumed'] = true;
$out[] = $this->getValueReal( $this->options[$name] );
}
+
return $out;
}
@@ -111,8 +117,9 @@ class FormOptions implements ArrayAccess {
public function validateIntBounds( $name, $min, $max ) {
$this->validateName( $name, true );
- if ( $this->options[$name]['type'] !== self::INT )
+ if ( $this->options[$name]['type'] !== self::INT ) {
throw new MWException( "Option $name is not of type int" );
+ }
$value = $this->getValueReal( $this->options[$name] );
$value = max( $min, min( $max, $value ) );
@@ -124,6 +131,7 @@ class FormOptions implements ArrayAccess {
public function getUnconsumedValues( $all = false ) {
$values = array();
+
foreach ( $this->options as $name => $data ) {
if ( !$data['consumed'] ) {
if ( $all || $data['value'] !== null ) {
@@ -131,24 +139,29 @@ class FormOptions implements ArrayAccess {
}
}
}
+
return $values;
}
public function getChangedValues() {
$values = array();
+
foreach ( $this->options as $name => $data ) {
if ( $data['value'] !== null ) {
$values[$name] = $data['value'];
}
}
+
return $values;
}
public function getAllValues() {
$values = array();
+
foreach ( $this->options as $name => $data ) {
$values[$name] = $this->getValueReal( $data );
}
+
return $values;
}
@@ -156,7 +169,7 @@ class FormOptions implements ArrayAccess {
public function fetchValuesFromRequest( WebRequest $r, $values = false ) {
if ( !$values ) {
- $values = array_keys($this->options);
+ $values = array_keys( $this->options );
}
foreach ( $values as $name ) {
@@ -184,7 +197,7 @@ class FormOptions implements ArrayAccess {
/* ArrayAccess methods */
public function offsetExists( $name ) {
- return isset($this->options[$name]);
+ return isset( $this->options[$name] );
}
public function offsetGet( $name ) {
@@ -192,11 +205,10 @@ class FormOptions implements ArrayAccess {
}
public function offsetSet( $name, $value ) {
- return $this->setValue( $name, $value );
+ $this->setValue( $name, $value );
}
public function offsetUnset( $name ) {
- return $this->delete( $name );
+ $this->delete( $name );
}
-
}