IAlex has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/56610


Change subject: Fix the target URL of HTMLForm
......................................................................

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
---
M includes/HTMLForm.php
1 file changed, 28 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/10/56610/1

diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php
index 4a527bb..6c2f496 100644
--- a/includes/HTMLForm.php
+++ b/includes/HTMLForm.php
@@ -640,8 +640,8 @@
                        : '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,
                );
@@ -1074,6 +1074,32 @@
                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();
+       }
 }
 
 /**

-- 
To view, visit https://gerrit.wikimedia.org/r/56610
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7c40cae839e52e2e8618d48c7a3b2f9709e6f2d6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: IAlex <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to