Microchip08 has uploaded a new change for review.

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

Change subject: Use FormSpecialPage for Special:RandomInCategory
......................................................................

Use FormSpecialPage for Special:RandomInCategory

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.

This commit fixes bug 67581, and invalidates bug 67253.

Bug: 67581
Change-Id: Ibf8694c0643f7cd3964ff9f62ffc6049f0978416
---
M includes/specials/SpecialRandomInCategory.php
M languages/i18n/en.json
M languages/i18n/qqq.json
3 files changed, 32 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/74/154374/1

diff --git a/includes/specials/SpecialRandomInCategory.php 
b/includes/specials/SpecialRandomInCategory.php
index 28a1bc5..807ad28 100644
--- a/includes/specials/SpecialRandomInCategory.php
+++ b/includes/specials/SpecialRandomInCategory.php
@@ -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,27 @@
                $this->minTimestamp = null;
        }
 
-       public function execute( $par ) {
+       protected function getFormFields() {
+               $form = array(
+                       'category' => array(
+                               'type' => 'text',
+                               'label-message' => 
'randomincategory-selectcategory',
+                               'required' => true,
+                       )
+               );
+
+               return $form;
+       }
+
+       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 +103,26 @@
                }
 
                if ( !$this->category && $categoryStr ) {
-                       $this->setHeaders();
-                       $this->getOutput()->addWikiMsg( 
'randomincategory-invalidcategory',
+                       $msg = wfMessage( '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 = wfMessage( '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() );
        }
 
        /**
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index a43a742..37a3030 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -1520,7 +1520,8 @@
        "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": "Category:",
+       "randomincategory-legend": "Random page in category",
        "randomincategory-selectcategory-submit": "Go",
        "randomredirect": "Random redirect",
        "randomredirect-nopages": "There are no redirects in the namespace 
\"$1\".",
diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json
index e135277..f80a740 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -1682,7 +1682,8 @@
        "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": "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}}",
        "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}}",
        "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}}",

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibf8694c0643f7cd3964ff9f62ffc6049f0978416
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Microchip08 <doug...@chippy.ch>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to