X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHTMLForm.php;h=ec038c90f7b27d94479a028b6446a28635a13a48;hb=0a49fd69b0f1ba627ac82e4a91ed1f825e4235ce;hp=5a0fbaed4e7ab6106867ccc2ee5117da6124c7b7;hpb=968340d3107b43e11fc789508b6f2cee46e1cd7c;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php
index 5a0fbaed4e..ec038c90f7 100644
--- a/includes/HTMLForm.php
+++ b/includes/HTMLForm.php
@@ -101,6 +101,8 @@ class HTMLForm {
protected $mSubmitName;
protected $mSubmitText;
protected $mSubmitTooltip;
+
+ protected $mContext; // setTitle()
* @param $messagePrefix String a prefix to go in front of default messages
*/
- public function __construct( $descriptor, $messagePrefix = '' ) {
- $this->mMessagePrefix = $messagePrefix;
+ public function __construct( $descriptor, /*RequestContext*/ $context = null, $messagePrefix = '' ) {
+ if( $context instanceof RequestContext ){
+ $this->mContext = $context;
+ $this->mTitle = false; // We don't need them to set a title
+ $this->mMessagePrefix = $messagePrefix;
+ } else {
+ // B/C since 1.18
+ if( is_string( $context ) && $messagePrefix === '' ){
+ // it's actually $messagePrefix
+ $this->mMessagePrefix = $context;
+ }
+ }
// Expand out into a tree.
$loadedDescriptor = array();
@@ -159,7 +173,7 @@ class HTMLForm {
/**
* Add the HTMLForm-specific JavaScript, if it hasn't been
* done already.
- * @deprecated @since 1.18 load modules with ResourceLoader instead
+ * @deprecated since 1.18 load modules with ResourceLoader instead
*/
static function addJS() { }
@@ -174,6 +188,8 @@ class HTMLForm {
} elseif ( isset( $descriptor['type'] ) ) {
$class = self::$typeMappings[$descriptor['type']];
$descriptor['class'] = $class;
+ } else {
+ $class = null;
}
if ( !$class ) {
@@ -192,7 +208,7 @@ class HTMLForm {
*/
function prepareForm() {
# Check if we have the info we need
- if ( ! $this->mTitle ) {
+ if ( !$this->mTitle instanceof Title && $this->mTitle !== false ) {
throw new MWException( "You must call setTitle() on an HTMLForm" );
}
@@ -205,11 +221,10 @@ class HTMLForm {
* @return Status|boolean
*/
function tryAuthorizedSubmit() {
- global $wgUser, $wgRequest;
- $editToken = $wgRequest->getVal( 'wpEditToken' );
+ $editToken = $this->getRequest()->getVal( 'wpEditToken' );
$result = false;
- if ( $this->getMethod() != 'post' || $wgUser->matchEditToken( $editToken ) ) {
+ if ( $this->getMethod() != 'post' || $this->getUser()->matchEditToken( $editToken ) ) {
$result = $this->trySubmit();
}
return $result;
@@ -303,9 +318,9 @@ class HTMLForm {
* Add header text, inside the form.
* @param $msg String complete text of message to display
*/
- function addHeaderText( $msg, $section = null ) {
+ function addHeaderText( $msg, $section = null ) {
if ( is_null( $section ) ) {
- $this->mHeader .= $msg;
+ $this->mHeader .= $msg;
} else {
if ( !isset( $this->mSectionHeaders[$section] ) ) {
$this->mSectionHeaders[$section] = '';
@@ -318,14 +333,14 @@ class HTMLForm {
* Add footer text, inside the form.
* @param $msg String complete text of message to display
*/
- function addFooterText( $msg, $section = null ) {
+ function addFooterText( $msg, $section = null ) {
if ( is_null( $section ) ) {
- $this->mFooter .= $msg;
+ $this->mFooter .= $msg;
} else {
if ( !isset( $this->mSectionFooters[$section] ) ) {
$this->mSectionFooters[$section] = '';
}
- $this->mSectionFooters[$section] .= $msg;
+ $this->mSectionFooters[$section] .= $msg;
}
}
@@ -356,11 +371,9 @@ class HTMLForm {
* @param $submitResult Mixed output from HTMLForm::trySubmit()
*/
function displayForm( $submitResult ) {
- global $wgOut;
-
# For good measure (it is the default)
- $wgOut->preventClickjacking();
- $wgOut->addModules( 'mediawiki.htmlform' );
+ $this->getOutput()->preventClickjacking();
+ $this->getOutput()->addModules( 'mediawiki.htmlform' );
$html = ''
. $this->getErrors( $submitResult )
@@ -373,7 +386,7 @@ class HTMLForm {
$html = $this->wrapForm( $html );
- $wgOut->addHTML( ''
+ $this->getOutput()->addHTML( ''
. $this->mPre
. $html
. $this->mPost
@@ -414,11 +427,9 @@ class HTMLForm {
* @return String HTML.
*/
function getHiddenFields() {
- global $wgUser;
-
$html = '';
if( $this->getMethod() == 'post' ){
- $html .= Html::hidden( 'wpEditToken', $wgUser->editToken(), array( 'id' => 'wpEditToken' ) ) . "\n";
+ $html .= Html::hidden( 'wpEditToken', $this->getUser()->editToken(), array( 'id' => 'wpEditToken' ) ) . "\n";
$html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
}
@@ -447,8 +458,7 @@ class HTMLForm {
}
if ( isset( $this->mSubmitTooltip ) ) {
- global $wgUser;
- $attribs += $wgUser->getSkin()->tooltipAndAccessKeyAttribs( $this->mSubmitTooltip );
+ $attribs += Linker::tooltipAndAccessKeyAttribs( $this->mSubmitTooltip );
}
$attribs['class'] = 'mw-htmlform-submit';
@@ -495,16 +505,15 @@ class HTMLForm {
/**
* Format and display an error message stack.
- * @param $errors Mixed String or Array of message keys
+ * @param $errors String|Array|Status
* @return String
*/
function getErrors( $errors ) {
if ( $errors instanceof Status ) {
- global $wgOut;
if ( $errors->isOK() ) {
$errorstr = '';
} else {
- $errorstr = $wgOut->parse( $errors->getWikiText() );
+ $errorstr = $this->getOutput()->parse( $errors->getWikiText() );
}
} elseif ( is_array( $errors ) ) {
$errorstr = $this->formatErrors( $errors );
@@ -522,7 +531,7 @@ class HTMLForm {
* @param $errors Array of message keys/values
* @return String HTML, a
list of errors
*/
- static function formatErrors( $errors ) {
+ public static function formatErrors( $errors ) {
$errorstr = '';
foreach ( $errors as $error ) {
@@ -535,7 +544,7 @@ class HTMLForm {
$errorstr .= Html::rawElement(
'li',
- null,
+ array(),
wfMsgExt( $msg, array( 'parseinline' ), $error )
);
}
@@ -573,7 +582,8 @@ class HTMLForm {
/**
* Set the id for the submit button.
- * @param $t String. FIXME: Integrity is *not* validated
+ * @param $t String.
+ * @todo FIXME: Integrity of $t is *not* validated
*/
function setSubmitID( $t ) {
$this->mSubmitID = $t;
@@ -613,7 +623,39 @@ class HTMLForm {
* @return Title
*/
function getTitle() {
- return $this->mTitle;
+ return $this->mTitle === false
+ ? $this->getContext()->title
+ : $this->mTitle;
+ }
+
+ /**
+ * @return RequestContext
+ */
+ public function getContext(){
+ return $this->mContext instanceof RequestContext
+ ? $this->mContext
+ : RequestContext::getMain();
+ }
+
+ /**
+ * @return OutputPage
+ */
+ public function getOutput(){
+ return $this->getContext()->output;
+ }
+
+ /**
+ * @return WebRequest
+ */
+ public function getRequest(){
+ return $this->getContext()->request;
+ }
+
+ /**
+ * @return User
+ */
+ public function getUser(){
+ return $this->getContext()->user;
}
/**
@@ -648,14 +690,14 @@ class HTMLForm {
$hasLeftColumn = true;
} elseif ( is_array( $value ) ) {
$section = $this->displaySection( $value, $key );
- $legend = wfMsg( "{$this->mMessagePrefix}-$key" );
+ $legend = $this->getLegend( $key );
if ( isset( $this->mSectionHeaders[$key] ) ) {
$section = $this->mSectionHeaders[$key] . $section;
- }
+ }
if ( isset( $this->mSectionFooters[$key] ) ) {
$section .= $this->mSectionFooters[$key];
}
- $subsectionHtml .= Xml::fieldset( $legend, $section ) . "\n";
+ $subsectionHtml .= Xml::fieldset( $legend, $section ) . "\n";
}
}
@@ -683,8 +725,6 @@ class HTMLForm {
* Construct the form fields from the Descriptor array
*/
function loadData() {
- global $wgRequest;
-
$fieldData = array();
foreach ( $this->mFlatFields as $fieldname => $field ) {
@@ -693,7 +733,7 @@ class HTMLForm {
} elseif ( !empty( $field->mParams['disabled'] ) ) {
$fieldData[$fieldname] = $field->getDefault();
} else {
- $fieldData[$fieldname] = $field->loadDataFromRequest( $wgRequest );
+ $fieldData[$fieldname] = $field->loadDataFromRequest( $this->getRequest() );
}
}
@@ -725,6 +765,16 @@ class HTMLForm {
function filterDataForSubmit( $data ) {
return $data;
}
+
+ /**
+ * Get a string to go in the