Exemplo n.º 1
0
 /**
  * Determine form errors to display and their classes
  * @since 1.20
  *
  * @param string $value The value of the input
  * @return array
  */
 public function getErrorsAndErrorClass($value)
 {
     $errors = $this->validate($value, $this->mParent->mFieldData);
     if ($errors === true || !$this->mParent->getRequest()->wasPosted() && $this->mParent->getMethod() === 'post') {
         $errors = '';
         $errorClass = '';
     } else {
         $errors = self::formatErrors($errors);
         $errorClass = 'mw-htmlform-invalid-input';
     }
     return array($errors, $errorClass);
 }
Exemplo n.º 2
0
 /**
  * Get the complete table row for the input, including help text,
  * labels, and whatever.
  * @param $value String the value to set the input to.
  * @return String complete HTML table row.
  */
 function getTableRow($value)
 {
     # Check for invalid data.
     $errors = $this->validate($value, $this->mParent->mFieldData);
     $cellAttributes = array();
     $verticalLabel = false;
     if (!empty($this->mParams['vertical-label'])) {
         $cellAttributes['colspan'] = 2;
         $verticalLabel = true;
     }
     if ($errors === true || !$this->mParent->getRequest()->wasPosted() && $this->mParent->getMethod() == 'post') {
         $errors = '';
         $errorClass = '';
     } else {
         $errors = self::formatErrors($errors);
         $errorClass = 'mw-htmlform-invalid-input';
     }
     $label = $this->getLabelHtml($cellAttributes);
     $field = Html::rawElement('td', array('class' => 'mw-input') + $cellAttributes, $this->getInputHTML($value) . "\n{$errors}");
     $fieldType = get_class($this);
     if ($verticalLabel) {
         $html = Html::rawElement('tr', array('class' => 'mw-htmlform-vertical-label'), $label);
         $html .= Html::rawElement('tr', array('class' => "mw-htmlform-field-{$fieldType} {$this->mClass} {$errorClass}"), $field);
     } else {
         $html = Html::rawElement('tr', array('class' => "mw-htmlform-field-{$fieldType} {$this->mClass} {$errorClass}"), $label . $field);
     }
     $helptext = null;
     if (isset($this->mParams['help-message'])) {
         $msg = wfMessage($this->mParams['help-message']);
         if ($msg->exists()) {
             $helptext = $msg->parse();
         }
     } elseif (isset($this->mParams['help-messages'])) {
         # help-message can be passed a message key (string) or an array containing
         # a message key and additional parameters. This makes it impossible to pass
         # an array of message key
         foreach ($this->mParams['help-messages'] as $name) {
             $msg = wfMessage($name);
             if ($msg->exists()) {
                 if (is_null($helptext)) {
                     $helptext = '';
                 } else {
                     $helptext .= wfMessage('word-separator')->escaped();
                     // some space
                 }
                 $helptext .= $msg->parse();
                 // append message
             }
         }
     } elseif (isset($this->mParams['help'])) {
         $helptext = $this->mParams['help'];
     }
     if (!is_null($helptext)) {
         $row = Html::rawElement('td', array('colspan' => 2, 'class' => 'htmlform-tip'), $helptext);
         $row = Html::rawElement('tr', array(), $row);
         $html .= "{$row}\n";
     }
     return $html;
 }
Exemplo n.º 3
0
 /**
  * Get the complete table row for the input, including help text,
  * labels, and whatever.
  * @param $value String the value to set the input to.
  * @return String complete HTML table row.
  */
 function getTableRow($value)
 {
     # Check for invalid data.
     $errors = $this->validate($value, $this->mParent->mFieldData);
     $cellAttributes = array();
     $verticalLabel = false;
     if (!empty($this->mParams['vertical-label'])) {
         $cellAttributes['colspan'] = 2;
         $verticalLabel = true;
     }
     if ($errors === true || $this->mParent->blockSubmit || !$this->mParent->getRequest()->wasPosted() && $this->mParent->getMethod() == 'post') {
         $errors = '';
         $errorClass = '';
     } else {
         $errors = self::formatErrors($errors);
         $errorClass = 'mw-htmlform-invalid-input';
     }
     $helptext = null;
     if (isset($this->mParams['help-message'])) {
         // If msg has parameters (to be parsed by i18n logic, help-message is an array.
         if (is_array($this->mParams['help-message'])) {
             // Then first element is i18n id, the rest are parameters.
             $msg = wfMessage(array_shift($this->mParams['help-message']), $this->mParams['help-message']);
         } else {
             $msg = wfMessage($this->mParams['help-message']);
         }
         if ($msg->exists()) {
             $helptext = $msg->parse();
         }
     } elseif (isset($this->mParams['help-messages'])) {
         # help-message can be passed a message key (string) or an array containing
         # a message key and additional parameters. This makes it impossible to pass
         # an array of message key
         foreach ($this->mParams['help-messages'] as $name) {
             if (is_array($name)) {
                 $msg = wfMessage(array_shift($name), $name);
             } else {
                 $msg = wfMessage($name);
             }
             if ($msg->exists()) {
                 $helptext .= $msg->parse();
                 // append message
             }
         }
     } elseif (isset($this->mParams['help'])) {
         $helptext = $this->mParams['help'];
     }
     if (!is_null($helptext)) {
         $helptext = Html::rawElement('span', array('class' => 'sread help htmlform-tip'), $helptext);
     }
     $label = $this->getLabelHtml($cellAttributes);
     $field = $this->getInputHTML($value) . "\n{$errors}";
     $fieldType = get_class($this);
     if ($verticalLabel) {
         $html = Html::rawElement('p', array('class' => 'mw-htmlform-vertical-label'), $label);
         $html .= Html::rawElement('p', array('class' => "mw-htmlform-field-{$fieldType} {$this->mClass} {$errorClass}"), $field . $helptext);
     } else {
         $html = Html::rawElement('p', array('class' => "mw-htmlform-field-{$fieldType} {$this->mClass} {$errorClass}"), $label . $field . $helptext);
     }
     return $html;
 }