Slight improvements to FormSpecialPage behavior.
authorparent5446 <tylerromeo@gmail.com>
Wed, 17 Apr 2013 20:45:51 +0000 (16:45 -0400)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 22 Apr 2013 16:53:36 +0000 (16:53 +0000)
Added a default implementation of doing nothing
to FormSpecialPage::onSuccess to avoid forms that
don't do anything.

Added a default implementation of FormSpecialPage::setParameter
to store the parameter in a protected variable in
case the child class wants to use it.

Made FormSpecialPage::getForm first check whether the
header message text exists before adding it as header
text, for those forms that don't have header text.

Change-Id: Ifb49c3b2f4079a5fbe379c44b63ee2dcee9eeb48

includes/SpecialPage.php

index c2814e6..71ee4e6 100644 (file)
@@ -924,6 +924,11 @@ class SpecialPage {
  * a new structure for SpecialPages
  */
 abstract class FormSpecialPage extends SpecialPage {
+       /**
+        * The sub-page of the special page.
+        * @var string
+        */
+       protected $par = null;
 
        /**
         * Get an HTMLForm descriptor array
@@ -973,8 +978,11 @@ abstract class FormSpecialPage extends SpecialPage {
                $form = new HTMLForm( $this->fields, $this->getContext(), $this->getMessagePrefix() );
                $form->setSubmitCallback( array( $this, 'onSubmit' ) );
                $form->setWrapperLegendMsg( $this->getMessagePrefix() . '-legend' );
-               $form->addHeaderText(
-                       $this->msg( $this->getMessagePrefix() . '-text' )->parseAsBlock() );
+
+               $headerMsg = $this->msg( $this->getMessagePrefix() . '-text' );
+               if ( !$headerMsg->disabled() ) {
+                       $form->addHeaderText( $headerMsg->parseAsBlock() );
+               }
 
                // Retain query parameters (uselang etc)
                $params = array_diff_key(
@@ -1001,8 +1009,9 @@ abstract class FormSpecialPage extends SpecialPage {
        /**
         * Do something exciting on successful processing of the form, most likely to show a
         * confirmation message
+        * @since 1.22 Default is to do nothing
         */
-       abstract public function onSuccess();
+       public function onSuccess() {}
 
        /**
         * Basic SpecialPage workflow: get a form, send it to the user; get some data back,
@@ -1024,9 +1033,11 @@ abstract class FormSpecialPage extends SpecialPage {
 
        /**
         * Maybe do something interesting with the subpage parameter
-        * @param $par String
+        * @param string $par
         */
-       protected function setParameter( $par ) {}
+       protected function setParameter( $par ) {
+               $this->par = $par;
+       }
 
        /**
         * Called from execute() to check if the given user can perform this action.