<?php
+/**
+ * HTML form generation and submission handling.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
/**
* Object handling generic submission, CSRF protection, layout and
* other logic for UI forms. in a reusable manner.
* the message.
* 'label' -- alternatively, a raw text message. Overridden by
* label-message
+ * 'help' -- message text for a message to use as a help text.
* 'help-message' -- message key for a message to use as a help text.
* can be an array of msg key and then parameters to
* the message.
- * Overwrites 'help-messages'.
+ * Overwrites 'help-messages' and 'help'.
* 'help-messages' -- array of message key. As above, each item can
* be an array of msg key and then parameters.
- * Overwrites 'help-message'.
+ * Overwrites 'help'.
* 'required' -- passed through to the object, indicating that it
* is a required field.
* 'size' -- the length of text fields
$descriptor['fieldname'] = $fieldname;
+ # TODO
+ # This will throw a fatal error whenever someone try to use
+ # 'class' to feed a CSS class instead of 'cssclass'. Would be
+ # great to avoid the fatal error and show a nice error.
$obj = new $class( $descriptor );
return $obj;
/**
* The here's-one-I-made-earlier option: do the submission if
- * posted, or display the form with or without funky valiation
+ * posted, or display the form with or without funky validation
* errors
* @return Bool or Status whether submission was successful.
*/
$this->prepareForm();
$result = $this->tryAuthorizedSubmit();
- if ( $result === true || ( $result instanceof Status && $result->isGood() ) ){
+ if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) {
return $result;
}
* @return String HTML.
*/
function getHiddenFields() {
- global $wgUsePathInfo;
+ global $wgArticlePath;
$html = '';
if( $this->getMethod() == 'post' ){
$html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
}
- if ( !$wgUsePathInfo && $this->getMethod() == 'get' ) {
+ if ( strpos( $wgArticlePath, '?' ) !== false && $this->getMethod() == 'get' ) {
$html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
}
* @param $msg String message key
*/
public function setSubmitTextMsg( $msg ) {
- return $this->setSubmitText( $this->msg( $msg )->escaped() );
+ return $this->setSubmitText( $this->msg( $msg )->text() );
}
/**
* Get the text for the submit button, either customised or a default.
- * @return unknown_type
+ * @return string
*/
function getSubmitText() {
return $this->mSubmitText
* Set the method used to submit the form
* @param $method String
*/
- public function setMethod( $method='post' ){
+ public function setMethod( $method = 'post' ) {
$this->mMethod = $method;
}
- public function getMethod(){
+ public function getMethod() {
return $this->mMethod;
}
* to the form as a whole, after it's submitted but before it's
* processed.
* @param $data
- * @return unknown_type
+ * @return
*/
function filterDataForSubmit( $data ) {
return $data;
$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
+ $this->mParams['help-messages'] = array( $this->mParams['help-message'] );
+ }
+
+ if ( isset( $this->mParams['help-messages'] ) ) {
foreach( $this->mParams['help-messages'] as $name ) {
- $msg = wfMessage( $name );
+ $helpMessage = (array)$name;
+ $msg = wfMessage( array_shift( $helpMessage ), $helpMessage );
+
if( $msg->exists() ) {
- $helptext .= $msg->parse(); // append message
+ if( is_null( $helptext ) ) {
+ $helptext = '';
+ } else {
+ $helptext .= wfMessage( 'word-separator' )->escaped(); // some space
+ }
+ $helptext .= $msg->parse(); // Append message
}
}
- } elseif ( isset( $this->mParams['help'] ) ) {
+ }
+ 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(
+ 'td',
+ array( 'colspan' => 2, 'class' => 'htmlform-tip' ),
+ $helptext
+ );
$row = Html::rawElement( 'tr', array(), $row );
$html .= "$row\n";
}
$attribs['readonly'] = 'readonly';
}
+ if ( isset( $this->mParams['placeholder'] ) ) {
+ $attribs['placeholder'] = $this->mParams['placeholder'];
+ }
+
foreach ( array( 'required', 'autofocus' ) as $param ) {
if ( isset( $this->mParams[$param] ) ) {
$attribs[$param] = '';