diff --git a/_test/core/DokuWikiTest.php b/_test/core/DokuWikiTest.php index 7c6f3d616..c9a598af4 100644 --- a/_test/core/DokuWikiTest.php +++ b/_test/core/DokuWikiTest.php @@ -140,7 +140,7 @@ abstract class DokuWikiTest extends PHPUnit_Framework_TestCase { trigger_event('INIT_LANG_LOAD', $local, 'init_lang', true); global $INPUT; - $INPUT = new Input(); + $INPUT = new \dokuwiki\Input\Input(); } /** diff --git a/_test/core/TestRequest.php b/_test/core/TestRequest.php index fcc80328c..23ca76eec 100644 --- a/_test/core/TestRequest.php +++ b/_test/core/TestRequest.php @@ -4,6 +4,8 @@ * runtime inspection. */ +use dokuwiki\Input\Input; + /** * Helper class to execute a fake request */ diff --git a/_test/tests/inc/auth_deleteprofile.test.php b/_test/tests/inc/auth_deleteprofile.test.php index dc38fcd16..e9f679d5c 100644 --- a/_test/tests/inc/auth_deleteprofile.test.php +++ b/_test/tests/inc/auth_deleteprofile.test.php @@ -1,5 +1,7 @@ remove('confirm_delete'); $this->assertFalse(auth_deleteprofile()); } -} \ No newline at end of file +} diff --git a/_test/tests/inc/input.test.php b/_test/tests/inc/input.test.php index 4a8fb8d71..099a8eb81 100644 --- a/_test/tests/inc/input.test.php +++ b/_test/tests/inc/input.test.php @@ -1,7 +1,9 @@ - */ -class Input { - - /** @var PostInput Access $_POST parameters */ - public $post; - /** @var GetInput Access $_GET parameters */ - public $get; - /** @var ServerInput Access $_SERVER parameters */ - public $server; - - protected $access; - - /** - * @var Callable - */ - protected $filter; - - /** - * Intilizes the Input class and it subcomponents - */ - public function __construct() { - $this->access = &$_REQUEST; - $this->post = new PostInput(); - $this->get = new GetInput(); - $this->server = new ServerInput(); - } - - /** - * Apply the set filter to the given value - * - * @param string $data - * @return string - */ - protected function applyfilter($data){ - if(!$this->filter) return $data; - return call_user_func($this->filter, $data); - } - - /** - * Return a filtered copy of the input object - * - * Expects a callable that accepts one string parameter and returns a filtered string - * - * @param Callable|string $filter - * @return Input - */ - public function filter($filter='stripctl'){ - $this->filter = $filter; - $clone = clone $this; - $this->filter = ''; - return $clone; - } - - /** - * Check if a parameter was set - * - * Basically a wrapper around isset. When called on the $post and $get subclasses, - * the parameter is set to $_POST or $_GET and to $_REQUEST - * - * @see isset - * @param string $name Parameter name - * @return bool - */ - public function has($name) { - return isset($this->access[$name]); - } - - /** - * Remove a parameter from the superglobals - * - * Basically a wrapper around unset. When NOT called on the $post and $get subclasses, - * the parameter will also be removed from $_POST or $_GET - * - * @see isset - * @param string $name Parameter name - */ - public function remove($name) { - if(isset($this->access[$name])) { - unset($this->access[$name]); - } - // also remove from sub classes - if(isset($this->post) && isset($_POST[$name])) { - unset($_POST[$name]); - } - if(isset($this->get) && isset($_GET[$name])) { - unset($_GET[$name]); - } - } - - /** - * Access a request parameter without any type conversion - * - * @param string $name Parameter name - * @param mixed $default Default to return if parameter isn't set - * @param bool $nonempty Return $default if parameter is set but empty() - * @return mixed - */ - public function param($name, $default = null, $nonempty = false) { - if(!isset($this->access[$name])) return $default; - $value = $this->applyfilter($this->access[$name]); - if($nonempty && empty($value)) return $default; - return $value; - } - - /** - * Sets a parameter - * - * @param string $name Parameter name - * @param mixed $value Value to set - */ - public function set($name, $value) { - $this->access[$name] = $value; - } - - /** - * Get a reference to a request parameter - * - * This avoids copying data in memory, when the parameter is not set it will be created - * and intialized with the given $default value before a reference is returned - * - * @param string $name Parameter name - * @param mixed $default If parameter is not set, initialize with this value - * @param bool $nonempty Init with $default if parameter is set but empty() - * @return mixed (reference) - */ - public function &ref($name, $default = '', $nonempty = false) { - if(!isset($this->access[$name]) || ($nonempty && empty($this->access[$name]))) { - $this->set($name, $default); - } - - return $this->access[$name]; - } - - /** - * Access a request parameter as int - * - * @param string $name Parameter name - * @param int $default Default to return if parameter isn't set or is an array - * @param bool $nonempty Return $default if parameter is set but empty() - * @return int - */ - public function int($name, $default = 0, $nonempty = false) { - if(!isset($this->access[$name])) return $default; - if(is_array($this->access[$name])) return $default; - $value = $this->applyfilter($this->access[$name]); - if($value === '') return $default; - if($nonempty && empty($value)) return $default; - - return (int) $value; - } - - /** - * Access a request parameter as string - * - * @param string $name Parameter name - * @param string $default Default to return if parameter isn't set or is an array - * @param bool $nonempty Return $default if parameter is set but empty() - * @return string - */ - public function str($name, $default = '', $nonempty = false) { - if(!isset($this->access[$name])) return $default; - if(is_array($this->access[$name])) return $default; - $value = $this->applyfilter($this->access[$name]); - if($nonempty && empty($value)) return $default; - - return (string) $value; - } - - /** - * Access a request parameter and make sure it is has a valid value - * - * Please note that comparisons to the valid values are not done typesafe (request vars - * are always strings) however the function will return the correct type from the $valids - * array when an match was found. - * - * @param string $name Parameter name - * @param array $valids Array of valid values - * @param mixed $default Default to return if parameter isn't set or not valid - * @return null|mixed - */ - public function valid($name, $valids, $default = null) { - if(!isset($this->access[$name])) return $default; - if(is_array($this->access[$name])) return $default; // we don't allow arrays - $value = $this->applyfilter($this->access[$name]); - $found = array_search($value, $valids); - if($found !== false) return $valids[$found]; // return the valid value for type safety - return $default; - } - - /** - * Access a request parameter as bool - * - * Note: $nonempty is here for interface consistency and makes not much sense for booleans - * - * @param string $name Parameter name - * @param mixed $default Default to return if parameter isn't set - * @param bool $nonempty Return $default if parameter is set but empty() - * @return bool - */ - public function bool($name, $default = false, $nonempty = false) { - if(!isset($this->access[$name])) return $default; - if(is_array($this->access[$name])) return $default; - $value = $this->applyfilter($this->access[$name]); - if($value === '') return $default; - if($nonempty && empty($value)) return $default; - - return (bool) $value; - } - - /** - * Access a request parameter as array - * - * @param string $name Parameter name - * @param mixed $default Default to return if parameter isn't set - * @param bool $nonempty Return $default if parameter is set but empty() - * @return array - */ - public function arr($name, $default = array(), $nonempty = false) { - if(!isset($this->access[$name])) return $default; - if(!is_array($this->access[$name])) return $default; - if($nonempty && empty($this->access[$name])) return $default; - - return (array) $this->access[$name]; - } - - /** - * Create a simple key from an array key - * - * This is useful to access keys where the information is given as an array key or as a single array value. - * For example when the information was submitted as the name of a submit button. - * - * This function directly changes the access array. - * - * Eg. $_REQUEST['do']['save']='Speichern' becomes $_REQUEST['do'] = 'save' - * - * This function returns the $INPUT object itself for easy chaining - * - * @param string $name - * @return Input - */ - public function extract($name){ - if(!isset($this->access[$name])) return $this; - if(!is_array($this->access[$name])) return $this; - $keys = array_keys($this->access[$name]); - if(!$keys){ - // this was an empty array - $this->remove($name); - return $this; - } - // get the first key - $value = array_shift($keys); - if($value === 0){ - // we had a numeric array, assume the value is not in the key - $value = array_shift($this->access[$name]); - } - - $this->set($name, $value); - return $this; - } -} - -/** - * Internal class used for $_POST access in Input class - */ -class PostInput extends Input { - - protected $access; - - /** @noinspection PhpMissingParentConstructorInspection - * Initialize the $access array, remove subclass members - */ - public function __construct() { - $this->access = &$_POST; - } - - /** - * Sets a parameter in $_POST and $_REQUEST - * - * @param string $name Parameter name - * @param mixed $value Value to set - */ - public function set($name, $value) { - parent::set($name, $value); - $_REQUEST[$name] = $value; - } -} - -/** - * Internal class used for $_GET access in Input class - */ -class GetInput extends Input { - protected $access; - - /** @noinspection PhpMissingParentConstructorInspection - * Initialize the $access array, remove subclass members - */ - public function __construct() { - $this->access = &$_GET; - } - - /** - * Sets a parameter in $_GET and $_REQUEST - * - * @param string $name Parameter name - * @param mixed $value Value to set - */ - public function set($name, $value) { - parent::set($name, $value); - $_REQUEST[$name] = $value; - } -} - -/** - * Internal class used for $_SERVER access in Input class - */ -class ServerInput extends Input { - protected $access; - - /** @noinspection PhpMissingParentConstructorInspection - * Initialize the $access array, remove subclass members - */ - public function __construct() { - $this->access = &$_SERVER; - } - -} diff --git a/inc/Input/Get.php b/inc/Input/Get.php new file mode 100644 index 000000000..99ab2655d --- /dev/null +++ b/inc/Input/Get.php @@ -0,0 +1,29 @@ +access = &$_GET; + } + + /** + * Sets a parameter in $_GET and $_REQUEST + * + * @param string $name Parameter name + * @param mixed $value Value to set + */ + public function set($name, $value) + { + parent::set($name, $value); + $_REQUEST[$name] = $value; + } +} diff --git a/inc/Input/Input.php b/inc/Input/Input.php new file mode 100644 index 000000000..3d2426bcc --- /dev/null +++ b/inc/Input/Input.php @@ -0,0 +1,287 @@ + + */ +class Input +{ + + /** @var Post Access $_POST parameters */ + public $post; + /** @var Get Access $_GET parameters */ + public $get; + /** @var Server Access $_SERVER parameters */ + public $server; + + protected $access; + + /** + * @var Callable + */ + protected $filter; + + /** + * Intilizes the dokuwiki\Input\Input class and it subcomponents + */ + public function __construct() + { + $this->access = &$_REQUEST; + $this->post = new Post(); + $this->get = new Get(); + $this->server = new Server(); + } + + /** + * Apply the set filter to the given value + * + * @param string $data + * @return string + */ + protected function applyfilter($data) + { + if (!$this->filter) return $data; + return call_user_func($this->filter, $data); + } + + /** + * Return a filtered copy of the input object + * + * Expects a callable that accepts one string parameter and returns a filtered string + * + * @param Callable|string $filter + * @return Input + */ + public function filter($filter = 'stripctl') + { + $this->filter = $filter; + $clone = clone $this; + $this->filter = ''; + return $clone; + } + + /** + * Check if a parameter was set + * + * Basically a wrapper around isset. When called on the $post and $get subclasses, + * the parameter is set to $_POST or $_GET and to $_REQUEST + * + * @see isset + * @param string $name Parameter name + * @return bool + */ + public function has($name) + { + return isset($this->access[$name]); + } + + /** + * Remove a parameter from the superglobals + * + * Basically a wrapper around unset. When NOT called on the $post and $get subclasses, + * the parameter will also be removed from $_POST or $_GET + * + * @see isset + * @param string $name Parameter name + */ + public function remove($name) + { + if (isset($this->access[$name])) { + unset($this->access[$name]); + } + // also remove from sub classes + if (isset($this->post) && isset($_POST[$name])) { + unset($_POST[$name]); + } + if (isset($this->get) && isset($_GET[$name])) { + unset($_GET[$name]); + } + } + + /** + * Access a request parameter without any type conversion + * + * @param string $name Parameter name + * @param mixed $default Default to return if parameter isn't set + * @param bool $nonempty Return $default if parameter is set but empty() + * @return mixed + */ + public function param($name, $default = null, $nonempty = false) + { + if (!isset($this->access[$name])) return $default; + $value = $this->applyfilter($this->access[$name]); + if ($nonempty && empty($value)) return $default; + return $value; + } + + /** + * Sets a parameter + * + * @param string $name Parameter name + * @param mixed $value Value to set + */ + public function set($name, $value) + { + $this->access[$name] = $value; + } + + /** + * Get a reference to a request parameter + * + * This avoids copying data in memory, when the parameter is not set it will be created + * and intialized with the given $default value before a reference is returned + * + * @param string $name Parameter name + * @param mixed $default If parameter is not set, initialize with this value + * @param bool $nonempty Init with $default if parameter is set but empty() + * @return mixed (reference) + */ + public function &ref($name, $default = '', $nonempty = false) + { + if (!isset($this->access[$name]) || ($nonempty && empty($this->access[$name]))) { + $this->set($name, $default); + } + + return $this->access[$name]; + } + + /** + * Access a request parameter as int + * + * @param string $name Parameter name + * @param int $default Default to return if parameter isn't set or is an array + * @param bool $nonempty Return $default if parameter is set but empty() + * @return int + */ + public function int($name, $default = 0, $nonempty = false) + { + if (!isset($this->access[$name])) return $default; + if (is_array($this->access[$name])) return $default; + $value = $this->applyfilter($this->access[$name]); + if ($value === '') return $default; + if ($nonempty && empty($value)) return $default; + + return (int)$value; + } + + /** + * Access a request parameter as string + * + * @param string $name Parameter name + * @param string $default Default to return if parameter isn't set or is an array + * @param bool $nonempty Return $default if parameter is set but empty() + * @return string + */ + public function str($name, $default = '', $nonempty = false) + { + if (!isset($this->access[$name])) return $default; + if (is_array($this->access[$name])) return $default; + $value = $this->applyfilter($this->access[$name]); + if ($nonempty && empty($value)) return $default; + + return (string)$value; + } + + /** + * Access a request parameter and make sure it is has a valid value + * + * Please note that comparisons to the valid values are not done typesafe (request vars + * are always strings) however the function will return the correct type from the $valids + * array when an match was found. + * + * @param string $name Parameter name + * @param array $valids Array of valid values + * @param mixed $default Default to return if parameter isn't set or not valid + * @return null|mixed + */ + public function valid($name, $valids, $default = null) + { + if (!isset($this->access[$name])) return $default; + if (is_array($this->access[$name])) return $default; // we don't allow arrays + $value = $this->applyfilter($this->access[$name]); + $found = array_search($value, $valids); + if ($found !== false) return $valids[$found]; // return the valid value for type safety + return $default; + } + + /** + * Access a request parameter as bool + * + * Note: $nonempty is here for interface consistency and makes not much sense for booleans + * + * @param string $name Parameter name + * @param mixed $default Default to return if parameter isn't set + * @param bool $nonempty Return $default if parameter is set but empty() + * @return bool + */ + public function bool($name, $default = false, $nonempty = false) + { + if (!isset($this->access[$name])) return $default; + if (is_array($this->access[$name])) return $default; + $value = $this->applyfilter($this->access[$name]); + if ($value === '') return $default; + if ($nonempty && empty($value)) return $default; + + return (bool)$value; + } + + /** + * Access a request parameter as array + * + * @param string $name Parameter name + * @param mixed $default Default to return if parameter isn't set + * @param bool $nonempty Return $default if parameter is set but empty() + * @return array + */ + public function arr($name, $default = array(), $nonempty = false) + { + if (!isset($this->access[$name])) return $default; + if (!is_array($this->access[$name])) return $default; + if ($nonempty && empty($this->access[$name])) return $default; + + return (array)$this->access[$name]; + } + + /** + * Create a simple key from an array key + * + * This is useful to access keys where the information is given as an array key or as a single array value. + * For example when the information was submitted as the name of a submit button. + * + * This function directly changes the access array. + * + * Eg. $_REQUEST['do']['save']='Speichern' becomes $_REQUEST['do'] = 'save' + * + * This function returns the $INPUT object itself for easy chaining + * + * @param string $name + * @return Input + */ + public function extract($name) + { + if (!isset($this->access[$name])) return $this; + if (!is_array($this->access[$name])) return $this; + $keys = array_keys($this->access[$name]); + if (!$keys) { + // this was an empty array + $this->remove($name); + return $this; + } + // get the first key + $value = array_shift($keys); + if ($value === 0) { + // we had a numeric array, assume the value is not in the key + $value = array_shift($this->access[$name]); + } + + $this->set($name, $value); + return $this; + } +} diff --git a/inc/Input/Post.php b/inc/Input/Post.php new file mode 100644 index 000000000..137cd72f4 --- /dev/null +++ b/inc/Input/Post.php @@ -0,0 +1,30 @@ +access = &$_POST; + } + + /** + * Sets a parameter in $_POST and $_REQUEST + * + * @param string $name Parameter name + * @param mixed $value Value to set + */ + public function set($name, $value) + { + parent::set($name, $value); + $_REQUEST[$name] = $value; + } +} diff --git a/inc/Input/Server.php b/inc/Input/Server.php new file mode 100644 index 000000000..60964fd8f --- /dev/null +++ b/inc/Input/Server.php @@ -0,0 +1,19 @@ +access = &$_SERVER; + } + +} diff --git a/inc/Remote/Api.php b/inc/Remote/Api.php index 36957a873..bcb5f028c 100644 --- a/inc/Remote/Api.php +++ b/inc/Remote/Api.php @@ -3,7 +3,7 @@ namespace dokuwiki\Remote; use DokuWiki_Remote_Plugin; -use Input; +use dokuwiki\Input\Input; /** * This class provides information about remote access to the wiki. @@ -245,7 +245,7 @@ class Api { global $conf; global $USERINFO; - /** @var Input $INPUT */ + /** @var \dokuwiki\Input\Input $INPUT */ global $INPUT; if (!$conf['remote']) { diff --git a/inc/deprecated.php b/inc/deprecated.php index a4a5988fb..daa5e7ff1 100644 --- a/inc/deprecated.php +++ b/inc/deprecated.php @@ -187,3 +187,67 @@ class JSON return $this->decode($str); } } + +/** + * @inheritdoc + * @deprecated 2019-02-19 + */ +class Input extends \dokuwiki\Input\Input { + /** + * @inheritdoc + * @deprecated 2019-02-19 + */ + public function __construct() + { + dbg_deprecated(\dokuwiki\Input\Input::class); + parent::__construct(); + } +} + +/** + * @inheritdoc + * @deprecated 2019-02-19 + */ +class PostInput extends \dokuwiki\Input\Post { + /** + * @inheritdoc + * @deprecated 2019-02-19 + */ + public function __construct() + { + dbg_deprecated(\dokuwiki\Input\Post::class); + parent::__construct(); + } +} + +/** + * @inheritdoc + * @deprecated 2019-02-19 + */ +class GetInput extends \dokuwiki\Input\Get { + /** + * @inheritdoc + * @deprecated 2019-02-19 + */ + public function __construct() + { + dbg_deprecated(\dokuwiki\Input\Get::class); + parent::__construct(); + } +} + +/** + * @inheritdoc + * @deprecated 2019-02-19 + */ +class ServerInput extends \dokuwiki\Input\Server { + /** + * @inheritdoc + * @deprecated 2019-02-19 + */ + public function __construct() + { + dbg_deprecated(\dokuwiki\Input\Server::class); + parent::__construct(); + } +} diff --git a/inc/init.php b/inc/init.php index 109f6d93b..24552835c 100644 --- a/inc/init.php +++ b/inc/init.php @@ -3,7 +3,6 @@ * Initialize some defaults needed for DokuWiki */ - /** * timing Dokuwiki execution * @@ -209,7 +208,7 @@ if($conf['compression'] == 'gz' && !DOKU_HAS_GZIP) { // input handle class global $INPUT; -$INPUT = new Input(); +$INPUT = new \dokuwiki\Input\Input(); // initialize plugin controller $plugin_controller = new $plugin_controller_class(); diff --git a/inc/lang/az/wordblock.txt b/inc/lang/az/wordblock.txt deleted file mode 100644 index ec8b102af..000000000 --- a/inc/lang/az/wordblock.txt +++ /dev/null @@ -1,3 +0,0 @@ -====== SPAM-ın qarşısı alındı ====== - -Sizin dəyişiklər **yaddaşa saxlanmadı**, çünki onların içində bir və ya daha çox içazəsiz sözlər var idi. Əgər siz wiki-yə spam əlavə etmək istəyirdinizsə, onda utanmırsız?! Əgər siz bunu səhv hesab edirsinizsə, onda administrator ilə əlaqə saxlayın. diff --git a/inc/lang/be/wordblock.txt b/inc/lang/be/wordblock.txt deleted file mode 100644 index a92d7524e..000000000 --- a/inc/lang/be/wordblock.txt +++ /dev/null @@ -1,3 +0,0 @@ -====== СПАМ заблакаваны ====== - -Вашы змены **не** захаваны, так як яны ўтрымліваюць адзін ці больш забароненых слоў. Калі Вы спрабавалі дадаць спам у Вікі -- ай-яй-яй! Калі Вы лічыце, што гэта нейкая памылка, звярніцеся да адміністратара вікі. diff --git a/inc/lang/gl/wordblock.txt b/inc/lang/gl/wordblock.txt deleted file mode 100644 index 686aea36c..000000000 --- a/inc/lang/gl/wordblock.txt +++ /dev/null @@ -1,3 +0,0 @@ -====== Bloqueo por Correo-lixo ====== - -Os teus trocos **non** foron gardados porque conteñen unha ou varias verbas bloqueadas. Se tentaches deixar correo-lixo no wiki -- Estívoche ben! Se consideras que é un erro, contacta co administrador deste Wiki. diff --git a/inc/lang/ru/wordblock.txt b/inc/lang/ru/wordblock.txt deleted file mode 100644 index 09c663fb3..000000000 --- a/inc/lang/ru/wordblock.txt +++ /dev/null @@ -1,3 +0,0 @@ -====== СПАМ заблокирован ====== - -Ваши изменения **не были** сохранены, так как они содержат одно или более запрещенных слов. Если Вы пытались добавить спам в Вики -- ай-яй-яй! Если Вы считаете, что это какая-то ошибка, обратитесь к администратору вики. diff --git a/inc/load.php b/inc/load.php index 001f73dde..26600f367 100644 --- a/inc/load.php +++ b/inc/load.php @@ -63,7 +63,6 @@ function load_autoload($name){ 'cache_renderer' => DOKU_INC.'inc/cache.php', 'Doku_Event' => DOKU_INC.'inc/events.php', 'Doku_Event_Handler' => DOKU_INC.'inc/events.php', - 'Input' => DOKU_INC.'inc/Input.class.php', 'JpegMeta' => DOKU_INC.'inc/JpegMeta.php', 'SimplePie' => DOKU_INC.'inc/SimplePie.php', 'FeedParser' => DOKU_INC.'inc/FeedParser.php', diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php index 933367e35..a9070abfc 100644 --- a/lib/exe/fetch.php +++ b/lib/exe/fetch.php @@ -14,7 +14,7 @@ session_write_close(); //close session require_once(DOKU_INC.'inc/fetch.functions.php'); if (defined('SIMPLE_TEST')) { - $INPUT = new Input(); + $INPUT = new \dokuwiki\Input\Input(); } // BEGIN main