Use FormSpecialPage for Special:RandomInCategory
authorDouglas Gardner <douglas@chippy.ch>
Sat, 16 Aug 2014 02:01:48 +0000 (03:01 +0100)
committerLegoktm <legoktm.wikipedia@gmail.com>
Wed, 20 Aug 2014 06:15:04 +0000 (06:15 +0000)
This commit moves [[Special:RandomInCategory]] from using the SpecialPage class
to using the FormSpecialPage class, in the process moving from a simple input
box in the middle of a sentence to a "proper" form.

Bug: 67581
Bug: 67253
Change-Id: Ibf8694c0643f7cd3964ff9f62ffc6049f0978416

includes/specials/SpecialRandomInCategory.php
languages/i18n/en.json
languages/i18n/qqq.json

index 28a1bc5..570ab3b 100644 (file)
@@ -46,7 +46,7 @@
  *
  * @ingroup SpecialPage
  */
-class SpecialRandomInCategory extends SpecialPage {
+class SpecialRandomInCategory extends FormSpecialPage {
        protected $extra = array(); // Extra SQL statements
        protected $category = false; // Title object of category
        protected $maxOffset = 30; // Max amount to fudge randomness by.
@@ -67,10 +67,35 @@ class SpecialRandomInCategory extends SpecialPage {
                $this->minTimestamp = null;
        }
 
-       public function execute( $par ) {
+       protected function getFormFields() {
+               $form = array(
+                       'category' => array(
+                               'type' => 'text',
+                               'label-message' => 'randomincategory-category',
+                               'required' => true,
+                       )
+               );
+
+               return $form;
+       }
+
+       public function requiresWrite() {
+               return false;
+       }
+
+       public function requiresUnblock() {
+               return false;
+       }
+
+       protected function setParameter( $par ) {
+               // if subpage present, fake form submission
+               $this->onSubmit( array( 'category' => $par ) );
+       }
+
+       public function onSubmit( array $data ) {
                $cat = false;
 
-               $categoryStr = $this->getRequest()->getText( 'category', $par );
+               $categoryStr = $data['category'];
 
                if ( $categoryStr ) {
                        $cat = Title::newFromText( $categoryStr, NS_CATEGORY );
@@ -86,41 +111,25 @@ class SpecialRandomInCategory extends SpecialPage {
                }
 
                if ( !$this->category && $categoryStr ) {
-                       $this->setHeaders();
-                       $this->getOutput()->addWikiMsg( 'randomincategory-invalidcategory',
+                       $msg = $this->msg( 'randomincategory-invalidcategory',
                                wfEscapeWikiText( $categoryStr ) );
 
-                       return;
+                       return Status::newFatal( $msg );
+
                } elseif ( !$this->category ) {
-                       $this->setHeaders();
-                       $input = Html::input( 'category' );
-                       $submitText = $this->msg( 'randomincategory-selectcategory-submit' )->text();
-                       $submit = Html::input( '', $submitText, 'submit' );
-
-                       $msg = $this->msg( 'randomincategory-selectcategory' );
-                       $form = Html::rawElement( 'form', array( 'action' => wfScript() ),
-                               Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ) .
-                               $msg->rawParams( $input, $submit )->parse()
-                       );
-                       $this->getOutput()->addHtml( $form );
-
-                       return;
+                       return; // no data sent
                }
 
                $title = $this->getRandomTitle();
 
                if ( is_null( $title ) ) {
-                       $this->setHeaders();
-                       $this->getOutput()->addWikiMsg( 'randomincategory-nopages',
+                       $msg = $this->msg( 'randomincategory-nopages',
                                $this->category->getText() );
 
-                       return;
+                       return Status::newFatal( $msg );
                }
 
-               $query = $this->getRequest()->getValues();
-               unset( $query['title'] );
-               unset( $query['category'] );
-               $this->getOutput()->redirect( $title->getFullURL( $query ) );
+               $this->getOutput()->redirect( $title->getFullURL() );
        }
 
        /**
index a43a742..2af3d3f 100644 (file)
        "randomincategory": "Random page in category",
        "randomincategory-invalidcategory": "\"$1\" is not a valid category name.",
        "randomincategory-nopages": "There are no pages in the [[:Category:$1|$1]] category.",
-       "randomincategory-selectcategory": "Get random page from category: $1 $2.",
-       "randomincategory-selectcategory-submit": "Go",
+       "randomincategory-category": "Category:",
+       "randomincategory-legend": "Random page in category",
        "randomredirect": "Random redirect",
        "randomredirect-nopages": "There are no redirects in the namespace \"$1\".",
        "statistics": "Statistics",
index 74e2954..e1967f8 100644 (file)
        "randomincategory": "{{doc-special|RandomInCategory}}",
        "randomincategory-invalidcategory": "Message shown if an invalid category is specified.\n\nParameters:\n* $1 - the invalid category name given\n\n(Note, if the category is simply empty, but could possibly exist, {{msg-mw|randomincategory-nopages}} is shown instead)",
        "randomincategory-nopages": "Message shown from [[Special:RandomInCategory]] if the category is empty.\n\nParameters:\n* $1 - the category name (without the namespace prefix)",
-       "randomincategory-selectcategory": "Shown on [[Special:RandomInCategory]] if no category is selected.\n\nDisplays a form allowing the user to input a category name.\n\nParameters:\n* $1 - the text field input box\n* $2 - the go button which has the label {{msg-mw|randomincategory-selectcategory-submit}}.",
-       "randomincategory-selectcategory-submit": "Used as label for the Submit button which is used as <code>$2</code> in {{msg-mw|Randomincategory-selectcategory}}.\n{{Identical|Go}}",
+       "randomincategory-category": "Shown on [[Special:RandomInCategory]] as a label for a text box allowing the user to input a category name.",
+       "randomincategory-legend": "Legend to the form on [[Special:RandomInCategory]]. {{identical|randomicategory}}",
        "randomredirect": "{{doc-special|RandomRedirect}}",
        "randomredirect-nopages": "Parameters:\n* $1 - list of namespaces\n* $2 - (Unused) number of namespaces\nSee also:\n* {{msg-mw|Randompage-nopages}}",
        "statistics": "{{doc-special|Statistics}}\n{{Identical|Statistics}}",