Merge "Use {{int:}} on MediaWiki:Blockedtext and MediaWiki:Autoblockedtext"
[lhc/web/wiklou.git] / includes / specials / SpecialBlock.php
index 42e7040..efe354a 100644 (file)
@@ -135,6 +135,9 @@ class SpecialBlock extends FormSpecialPage {
 
                $suggestedDurations = self::getSuggestedDurations();
 
+               $conf = $this->getConfig();
+               $oldCommentSchema = $conf->get( 'CommentTableSchemaMigrationStage' ) === MIGRATION_OLD;
+
                $a = [
                        'Target' => [
                                'type' => 'user',
@@ -148,16 +151,19 @@ class SpecialBlock extends FormSpecialPage {
                                'validation-callback' => [ __CLASS__, 'validateTargetField' ],
                        ],
                        'Expiry' => [
-                               'type' => !count( $suggestedDurations ) ? 'text' : 'selectorother',
+                               'type' => 'expiry',
                                'label-message' => 'ipbexpiry',
                                'required' => true,
                                'options' => $suggestedDurations,
-                               'other' => $this->msg( 'ipbother' )->text(),
                                'default' => $this->msg( 'ipb-default-expiry' )->inContentLanguage()->text(),
                        ],
                        'Reason' => [
                                'type' => 'selectandother',
-                               'maxlength' => 255,
+                               // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
+                               // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
+                               // Unicode codepoints (or 255 UTF-8 bytes for old schema).
+                               'maxlength' => $oldCommentSchema ? 255 : CommentStore::COMMENT_CHARACTER_LIMIT,
+                               'maxlength-unit' => 'codepoints',
                                'label-message' => 'ipbreason',
                                'options-message' => 'ipbreason-dropdown',
                        ],
@@ -869,29 +875,38 @@ class SpecialBlock extends FormSpecialPage {
                        $a[$show] = $value;
                }
 
+               if ( $a ) {
+                       // if options exist, add other to the end instead of the begining (which
+                       // is what happens by default).
+                       $a[ wfMessage( 'ipbother' )->text() ] = 'other';
+               }
+
                return $a;
        }
 
        /**
         * Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
         * ("24 May 2034", etc), into an absolute timestamp we can put into the database.
+        *
+        * @todo strtotime() only accepts English strings. This means the expiry input
+        *       can only be specified in English.
+        * @see https://secure.php.net/manual/en/function.strtotime.php
+        *
         * @param string $expiry Whatever was typed into the form
-        * @return string Timestamp or 'infinity'
+        * @return string|bool Timestamp or 'infinity' or false on error.
         */
        public static function parseExpiryInput( $expiry ) {
                if ( wfIsInfinity( $expiry ) ) {
-                       $expiry = 'infinity';
-               } else {
-                       $expiry = strtotime( $expiry );
+                       return 'infinity';
+               }
 
-                       if ( $expiry < 0 || $expiry === false ) {
-                               return false;
-                       }
+               $expiry = strtotime( $expiry );
 
-                       $expiry = wfTimestamp( TS_MW, $expiry );
+               if ( $expiry < 0 || $expiry === false ) {
+                       return false;
                }
 
-               return $expiry;
+               return wfTimestamp( TS_MW, $expiry );
        }
 
        /**