From: Alexandre Emsenhuber Date: Fri, 29 Mar 2013 17:12:30 +0000 (+0100) Subject: Fix the target URL of HTMLForm X-Git-Tag: 1.31.0-rc.0~19118^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=aad8dc4c03cd5498b8cc636c883a60a688da3ef8;p=lhc%2Fweb%2Fwiklou.git Fix the target URL of HTMLForm - Use a local URL instead of a full one - Use $wgScriptPath instead of title's URL when $wgArticlePath contains a "?" since it'll be removed by web browser - Move the URL generation to getAction() for better readability - Use getMethod() instead of mMethod for consistency Change-Id: I7c40cae839e52e2e8618d48c7a3b2f9709e6f2d6 --- diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index ad7574f279..aeba22b487 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -643,8 +643,8 @@ class HTMLForm extends ContextSource { : 'application/x-www-form-urlencoded'; # Attributes $attribs = array( - 'action' => $this->mAction === false ? $this->getTitle()->getFullURL() : $this->mAction, - 'method' => $this->mMethod, + 'action' => $this->getAction(), + 'method' => $this->getMethod(), 'class' => 'visualClear', 'enctype' => $encType, ); @@ -1107,6 +1107,33 @@ class HTMLForm extends ContextSource { $this->mAction = $action; return $this; } + + /** + * Get the value for the action attribute of the form. + * + * @since 1.22 + * + * @return string + */ + public function getAction() { + global $wgScript, $wgArticlePath; + + // If an action is alredy provided, return it + if ( $this->mAction !== false ) { + return $this->mAction; + } + + // Check whether we are in GET mode and $wgArticlePath contains a "?" + // meaning that getLocalURL() would return something like "index.php?title=...". + // As browser remove the query string before submitting GET forms, + // it means that the title would be lost. In such case use $wgScript instead + // and put title in an hidden field (see getHiddenFields()). + if ( strpos( $wgArticlePath, '?' ) !== false && $this->getMethod() === 'get' ) { + return $wgScript; + } + + return $this->getTitle()->getLocalURL(); + } } /**