Merge changes I48dcf831,I8922b80e
[lhc/web/wiklou.git] / includes / HTMLForm.php
index 33e447e..e06a934 100644 (file)
@@ -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();
+       }
 }
 
 /**
@@ -1887,7 +1914,7 @@ class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable {
        public function __construct( $params ) {
                $missing = array_diff( self::$requiredParams, array_keys( $params ) );
                if ( $missing ) {
-                       throw HTMLFormFieldRequiredOptionsException::create( $this, $missing );
+                       throw new HTMLFormFieldRequiredOptionsException( $this, $missing );
                }
                parent::__construct( $params );
        }
@@ -2803,8 +2830,8 @@ interface HTMLNestedFilterable {
 }
 
 class HTMLFormFieldRequiredOptionsException extends MWException {
-       static public function create( HTMLFormField $field, array $missing ) {
-               return new self( sprintf(
+       public function __construct( HTMLFormField $field, array $missing ) {
+               parent::__construct( sprintf(
                        "Form type `%s` expected the following parameters to be set: %s",
                        get_class( $field ),
                        implode( ', ', $missing )