X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHTMLForm.php;h=3999e67e5ac934806998cf218f5e95463995b7dc;hb=e0e8f92227f6a62a836d167378116680ac6ae9d1;hp=98800545e3327ac9dbd83422f0518a8dcaa043a4;hpb=4c29198850d2d751211f14b23c159d37aa2bf687;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php
index 98800545e3..3999e67e5a 100644
--- a/includes/HTMLForm.php
+++ b/includes/HTMLForm.php
@@ -33,10 +33,10 @@
* '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'.
- * '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-messages'.
+ * 'help-messages' -- array of message key. As above, each item can
+ * be an array of msg key and then parameters.
+ * Overwrites 'help-message'.
* 'required' -- passed through to the object, indicating that it
* is a required field.
* 'size' -- the length of text fields
@@ -53,9 +53,9 @@
*
* TODO: Document 'section' / 'subsection' stuff
*/
-class HTMLForm {
+class HTMLForm extends ContextSource {
- # A mapping of 'type' inputs onto standard HTMLFormField subclasses
+ // A mapping of 'type' inputs onto standard HTMLFormField subclasses
static $typeMappings = array(
'text' => 'HTMLTextField',
'textarea' => 'HTMLTextAreaField',
@@ -73,15 +73,18 @@ class HTMLForm {
'hidden' => 'HTMLHiddenField',
'edittools' => 'HTMLEditTools',
- # HTMLTextField will output the correct type="" attribute automagically.
- # There are about four zillion other HTML5 input types, like url, but
- # we don't use those at the moment, so no point in adding all of them.
+ // HTMLTextField will output the correct type="" attribute automagically.
+ // There are about four zillion other HTML5 input types, like url, but
+ // we don't use those at the moment, so no point in adding all of them.
'email' => 'HTMLTextField',
'password' => 'HTMLTextField',
);
protected $mMessagePrefix;
+
+ /** @var HTMLFormField[] */
protected $mFlatFields;
+
protected $mFieldTree;
protected $mShowReset = false;
public $mFieldData;
@@ -102,26 +105,40 @@ class HTMLForm {
protected $mSubmitText;
protected $mSubmitTooltip;
- protected $mContext; // setTitle()
* @param $messagePrefix String a prefix to go in front of default messages
*/
- public function __construct( $descriptor, /*RequestContext*/ $context = null, $messagePrefix = '' ) {
- if( $context instanceof RequestContext ){
- $this->mContext = $context;
+ public function __construct( $descriptor, /*IContextSource*/ $context = null, $messagePrefix = '' ) {
+ if( $context instanceof IContextSource ){
+ $this->setContext( $context );
$this->mTitle = false; // We don't need them to set a title
$this->mMessagePrefix = $messagePrefix;
} else {
@@ -175,11 +192,12 @@ class HTMLForm {
* done already.
* @deprecated since 1.18 load modules with ResourceLoader instead
*/
- static function addJS() { }
+ static function addJS() { wfDeprecated( __METHOD__, '1.18' ); }
/**
* Initialise a new Object for the field
- * @param $descriptor input Descriptor, as described above
+ * @param $fieldname string
+ * @param $descriptor string input Descriptor, as described above
* @return HTMLFormField subclass
*/
static function loadInputFromParameters( $fieldname, $descriptor ) {
@@ -276,7 +294,7 @@ class HTMLForm {
$data = $this->filterDataForSubmit( $this->mFieldData );
- $res = call_user_func( $callback, $data );
+ $res = call_user_func( $callback, $data, $this );
return $res;
}
@@ -306,7 +324,16 @@ class HTMLForm {
* Set the introductory message, overwriting any existing message.
* @param $msg String complete text of message to display
*/
- function setIntro( $msg ) { $this->mPre = $msg; }
+ function setIntro( $msg ) {
+ $this->setPreText( $msg );
+ }
+
+ /**
+ * Set the introductory message, overwriting any existing message.
+ * @since 1.19
+ * @param $msg String complete text of message to display
+ */
+ function setPreText( $msg ) { $this->mPre = $msg; }
/**
* Add introductory text.
@@ -317,6 +344,7 @@ class HTMLForm {
/**
* Add header text, inside the form.
* @param $msg String complete text of message to display
+ * @param $section string The section to add the header to
*/
function addHeaderText( $msg, $section = null ) {
if ( is_null( $section ) ) {
@@ -329,9 +357,24 @@ class HTMLForm {
}
}
+ /**
+ * Set header text, inside the form.
+ * @since 1.19
+ * @param $msg String complete text of message to display
+ * @param $section The section to add the header to
+ */
+ function setHeaderText( $msg, $section = null ) {
+ if ( is_null( $section ) ) {
+ $this->mHeader = $msg;
+ } else {
+ $this->mSectionHeaders[$section] = $msg;
+ }
+ }
+
/**
* Add footer text, inside the form.
* @param $msg String complete text of message to display
+ * @param $section string The section to add the footer text to
*/
function addFooterText( $msg, $section = null ) {
if ( is_null( $section ) ) {
@@ -344,12 +387,32 @@ class HTMLForm {
}
}
+ /**
+ * Set footer text, inside the form.
+ * @since 1.19
+ * @param $msg String complete text of message to display
+ * @param $section string The section to add the footer text to
+ */
+ function setFooterText( $msg, $section = null ) {
+ if ( is_null( $section ) ) {
+ $this->mFooter = $msg;
+ } else {
+ $this->mSectionFooters[$section] = $msg;
+ }
+ }
+
/**
* Add text to the end of the display.
* @param $msg String complete text of message to display
*/
function addPostText( $msg ) { $this->mPost .= $msg; }
+ /**
+ * Set text at the end of the display.
+ * @param $msg String complete text of message to display
+ */
+ function setPostText( $msg ) { $this->mPost = $msg; }
+
/**
* Add a hidden field to the output
* @param $name String field name. This will be used exactly as entered
@@ -366,11 +429,20 @@ class HTMLForm {
}
/**
- * Display the form (sending to wgOut), with an appropriate error
+ * Display the form (sending to $wgOut), with an appropriate error
* message or stack of messages, and any validation errors, etc.
* @param $submitResult Mixed output from HTMLForm::trySubmit()
*/
function displayForm( $submitResult ) {
+ $this->getOutput()->addHTML( $this->getHTML( $submitResult ) );
+ }
+
+ /**
+ * Returns the raw HTML generated by the form
+ * @param $submitResult Mixed output from HTMLForm::trySubmit()
+ * @return string
+ */
+ function getHTML( $submitResult ) {
# For good measure (it is the default)
$this->getOutput()->preventClickjacking();
$this->getOutput()->addModules( 'mediawiki.htmlform' );
@@ -386,11 +458,7 @@ class HTMLForm {
$html = $this->wrapForm( $html );
- $this->getOutput()->addHTML( ''
- . $this->mPre
- . $html
- . $this->mPost
- );
+ return '' . $this->mPre . $html . $this->mPost;
}
/**
@@ -410,7 +478,7 @@ class HTMLForm {
: 'application/x-www-form-urlencoded';
# Attributes
$attribs = array(
- 'action' => $this->getTitle()->getFullURL(),
+ 'action' => $this->mAction === false ? $this->getTitle()->getFullURL() : $this->mAction,
'method' => $this->mMethod,
'class' => 'visualClear',
'enctype' => $encType,
@@ -427,9 +495,15 @@ class HTMLForm {
* @return String HTML.
*/
function getHiddenFields() {
+ global $wgUsePathInfo;
+
$html = '';
if( $this->getMethod() == 'post' ){
- $html .= Html::hidden( 'wpEditToken', $this->getUser()->editToken(), array( 'id' => 'wpEditToken' ) ) . "\n";
+ $html .= Html::hidden( 'wpEditToken', $this->getUser()->getEditToken(), array( 'id' => 'wpEditToken' ) ) . "\n";
+ $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
+ }
+
+ if ( !$wgUsePathInfo && $this->getMethod() == 'get' ) {
$html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
}
@@ -458,7 +532,7 @@ class HTMLForm {
}
if ( isset( $this->mSubmitTooltip ) ) {
- $attribs += Linker::tooltipAndAccessKeyAttribs( $this->mSubmitTooltip );
+ $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
}
$attribs['class'] = 'mw-htmlform-submit';
@@ -498,6 +572,7 @@ class HTMLForm {
/**
* Get the whole body of the form.
+ * @return String
*/
function getBody() {
return $this->displaySection( $this->mFieldTree );
@@ -562,6 +637,15 @@ class HTMLForm {
$this->mSubmitText = $t;
}
+ /**
+ * Set the text for the submit button to a message
+ * @since 1.19
+ * @param $msg String message key
+ */
+ public function setSubmitTextMsg( $msg ) {
+ return $this->setSubmitText( $this->msg( $msg )->escaped() );
+ }
+
/**
* Get the text for the submit button, either customised or a default.
* @return unknown_type
@@ -600,6 +684,16 @@ class HTMLForm {
*/
public function setWrapperLegend( $legend ) { $this->mWrapperLegend = $legend; }
+ /**
+ * Prompt the whole form to be wrapped in a