Aleksey Bekh-Ivanov (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/328682 )

Change subject: Introduce utf text form field
......................................................................

Introduce utf text form field

 Simplifies form creation - no need to define filter callback

Change-Id: I7d3188a6780f44813614f75337f1d54dcde44608
---
A repo/includes/Specials/HTMLUtfTextField.php
M repo/includes/Specials/SpecialNewItem.php
M repo/includes/Specials/SpecialNewProperty.php
3 files changed, 33 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/82/328682/1

diff --git a/repo/includes/Specials/HTMLUtfTextField.php 
b/repo/includes/Specials/HTMLUtfTextField.php
new file mode 100644
index 0000000..83910bc
--- /dev/null
+++ b/repo/includes/Specials/HTMLUtfTextField.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Wikibase\Repo\Specials;
+
+use HTMLTextField;
+use Wikibase\StringNormalizer;
+
+class HTMLUtfTextField extends HTMLTextField {
+
+       /**
+        * @var StringNormalizer
+        */
+       private $stringNormalizer;
+
+       public function __construct( array $params ) {
+               parent::__construct( $params );
+
+               $this->stringNormalizer = new StringNormalizer();
+       }
+
+       public function filter( $value, $alldata ) {
+               $filteredValue = $this->stringNormalizer->trimToNFC( $value );
+
+               return parent::filter( $filteredValue, $alldata );
+       }
+
+}
diff --git a/repo/includes/Specials/SpecialNewItem.php 
b/repo/includes/Specials/SpecialNewItem.php
index a445abc..5a7250b 100644
--- a/repo/includes/Specials/SpecialNewItem.php
+++ b/repo/includes/Specials/SpecialNewItem.php
@@ -102,24 +102,22 @@
                        self::FIELD_LABEL => [
                                'name' => self::FIELD_LABEL,
                                'default' => isset( $this->parts[0] ) ? 
$this->parts[0] : '',
-                               'type' => 'text',
+                               'class' => HTMLUtfTextField::class,
                                'id' => 'wb-newentity-label',
-                               'filter-callback' => [ $this->stringNormalizer, 
'trimToNFC' ],
                                'placeholder-message' => 
'wikibase-label-edit-placeholder',
                                'label-message' => 'wikibase-newentity-label',
                        ],
                        self::FIELD_DESCRIPTION => [
                                'name' => self::FIELD_DESCRIPTION,
                                'default' => isset( $this->parts[1] ) ? 
$this->parts[1] : '',
-                               'type' => 'text',
+                               'class' => HTMLUtfTextField::class,
                                'id' => 'wb-newentity-description',
-                               'filter-callback' => [ $this->stringNormalizer, 
'trimToNFC' ],
                                'placeholder-message' => 
'wikibase-description-edit-placeholder',
                                'label-message' => 
'wikibase-newentity-description',
                        ],
                        self::FIELD_ALIASES => [
                                'name' => self::FIELD_ALIASES,
-                               'type' => 'text',
+                               'class' => HTMLUtfTextField::class,
                                'id' => 'wb-newentity-aliases',
                                'placeholder-message' => 
'wikibase-aliases-edit-placeholder',
                                'label-message' => 'wikibase-newentity-aliases',
diff --git a/repo/includes/Specials/SpecialNewProperty.php 
b/repo/includes/Specials/SpecialNewProperty.php
index 753ae35..64434ea 100644
--- a/repo/includes/Specials/SpecialNewProperty.php
+++ b/repo/includes/Specials/SpecialNewProperty.php
@@ -89,24 +89,22 @@
                        self::FIELD_LABEL => [
                                'name' => self::FIELD_LABEL,
                                'default' => isset( $this->parts[0] ) ? 
$this->parts[0] : '',
-                               'type' => 'text',
+                               'class' => HTMLUtfTextField::class,
                                'id' => 'wb-newentity-label',
-                               'filter-callback' => [ $this->stringNormalizer, 
'trimToNFC' ],
                                'placeholder-message' => 
'wikibase-label-edit-placeholder',
                                'label-message' => 'wikibase-newentity-label'
                        ],
                        self::FIELD_DESCRIPTION => [
                                'name' => self::FIELD_DESCRIPTION,
                                'default' => isset( $this->parts[1] ) ? 
$this->parts[1] : '',
-                               'type' => 'text',
+                               'class' => HTMLUtfTextField::class,
                                'id' => 'wb-newentity-description',
-                               'filter-callback' => [ $this->stringNormalizer, 
'trimToNFC' ],
                                'placeholder-message' => 
'wikibase-description-edit-placeholder',
                                'label-message' => 
'wikibase-newentity-description'
                        ],
                        self::FIELD_ALIASES => [
                                'name' => self::FIELD_ALIASES,
-                               'type' => 'text',
+                               'class' => HTMLUtfTextField::class,
                                'id' => 'wb-newentity-aliases',
                                'placeholder-message' => 
'wikibase-aliases-edit-placeholder',
                                'label-message' => 'wikibase-newentity-aliases'

-- 
To view, visit https://gerrit.wikimedia.org/r/328682
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7d3188a6780f44813614f75337f1d54dcde44608
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aleksey Bekh-Ivanov (WMDE) <[email protected]>

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

Reply via email to