*
* @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.
$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 );
}
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() );
}
/**
"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",
"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}}",