MediaWiki  1.23.8
FormSpecialPage.php
Go to the documentation of this file.
1 <?php
31 abstract class FormSpecialPage extends SpecialPage {
36  protected $par = null;
37 
42  abstract protected function getFormFields();
43 
48  protected function preText() {
49  return '';
50  }
51 
56  protected function postText() {
57  return '';
58  }
59 
64  protected function alterForm( HTMLForm $form ) {
65  }
66 
73  protected function getMessagePrefix() {
74  return strtolower( $this->getName() );
75  }
76 
81  protected function getForm() {
82  $this->fields = $this->getFormFields();
83 
84  $form = new HTMLForm( $this->fields, $this->getContext(), $this->getMessagePrefix() );
85  $form->setSubmitCallback( array( $this, 'onSubmit' ) );
86  // If the form is a compact vertical form, then don't output this ugly
87  // fieldset surrounding it.
88  // XXX Special pages can setDisplayFormat to 'vform' in alterForm(), but that
89  // is called after this.
90  if ( !$form->isVForm() ) {
91  $form->setWrapperLegendMsg( $this->getMessagePrefix() . '-legend' );
92  }
93 
94  $headerMsg = $this->msg( $this->getMessagePrefix() . '-text' );
95  if ( !$headerMsg->isDisabled() ) {
96  $form->addHeaderText( $headerMsg->parseAsBlock() );
97  }
98 
99  // Retain query parameters (uselang etc)
100  $params = array_diff_key(
101  $this->getRequest()->getQueryValues(), array( 'title' => null ) );
102  $form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) );
103 
104  $form->addPreText( $this->preText() );
105  $form->addPostText( $this->postText() );
106  $this->alterForm( $form );
107 
108  // Give hooks a chance to alter the form, adding extra fields or text etc
109  wfRunHooks( "Special{$this->getName()}BeforeFormDisplay", array( &$form ) );
110 
111  return $form;
112  }
113 
119  abstract public function onSubmit( array $data );
120 
126  public function onSuccess() {
127  }
128 
134  public function execute( $par ) {
135  $this->setParameter( $par );
136  $this->setHeaders();
137 
138  // This will throw exceptions if there's a problem
139  $this->checkExecutePermissions( $this->getUser() );
140 
141  $form = $this->getForm();
142  if ( $form->show() ) {
143  $this->onSuccess();
144  }
145  }
146 
151  protected function setParameter( $par ) {
152  $this->par = $par;
153  }
154 
162  protected function checkExecutePermissions( User $user ) {
163  $this->checkPermissions();
164 
165  if ( $this->requiresUnblock() && $user->isBlocked() ) {
166  $block = $user->getBlock();
167  throw new UserBlockedError( $block );
168  }
169 
170  if ( $this->requiresWrite() ) {
171  $this->checkReadOnly();
172  }
173 
174  return true;
175  }
176 
181  public function requiresWrite() {
182  return true;
183  }
184 
189  public function requiresUnblock() {
190  return true;
191  }
192 }
FormSpecialPage\onSuccess
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
Definition: FormSpecialPage.php:125
FormSpecialPage\getFormFields
getFormFields()
Get an HTMLForm descriptor array.
FormSpecialPage\alterForm
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
Definition: FormSpecialPage.php:63
FormSpecialPage\requiresUnblock
requiresUnblock()
Whether this action cannot be executed by a blocked user.
Definition: FormSpecialPage.php:188
FormSpecialPage\onSubmit
onSubmit(array $data)
Process the form on POST submission.
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
FormSpecialPage\getForm
getForm()
Get the HTMLForm to control behavior.
Definition: FormSpecialPage.php:80
UserBlockedError
Show an error when the user tries to do something whilst blocked.
Definition: UserBlockedError.php:27
$form
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead $form
Definition: hooks.txt:2573
SpecialPage\checkPermissions
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
Definition: SpecialPage.php:287
HTMLForm\show
show()
The here's-one-I-made-earlier option: do the submission if posted, or display the form with or withou...
Definition: HTMLForm.php:420
FormSpecialPage\requiresWrite
requiresWrite()
Whether this action requires the wiki not to be locked.
Definition: FormSpecialPage.php:180
FormSpecialPage\setParameter
setParameter( $par)
Maybe do something interesting with the subpage parameter.
Definition: FormSpecialPage.php:150
$params
$params
Definition: styleTest.css.php:40
FormSpecialPage
Special page which uses an HTMLForm to handle processing.
Definition: FormSpecialPage.php:31
FormSpecialPage\preText
preText()
Add pre-text to the form.
Definition: FormSpecialPage.php:47
SpecialPage\getName
getName()
Get the name of this Special Page.
Definition: SpecialPage.php:139
FormSpecialPage\postText
postText()
Add post-text to the form.
Definition: FormSpecialPage.php:55
FormSpecialPage\getMessagePrefix
getMessagePrefix()
Get message prefix for HTMLForm.
Definition: FormSpecialPage.php:72
FormSpecialPage\checkExecutePermissions
checkExecutePermissions(User $user)
Called from execute() to check if the given user can perform this action.
Definition: FormSpecialPage.php:161
FormSpecialPage\execute
execute( $par)
Basic SpecialPage workflow: get a form, send it to the user; get some data back,.
Definition: FormSpecialPage.php:133
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4010
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:352
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:545
HTMLForm\setSubmitCallback
setSubmitCallback( $cb)
Set a callback to a function to do something with the form once it's been successfully validated.
Definition: HTMLForm.php:482
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:508
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:609
FormSpecialPage\$par
string $par
The sub-page of the special page.
Definition: FormSpecialPage.php:35
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:33
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:525
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
SpecialPage\checkReadOnly
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
Definition: SpecialPage.php:300
HTMLForm\addPostText
addPostText( $msg)
Add text to the end of the display.
Definition: HTMLForm.php:629
User\isBlocked
isBlocked( $bFromSlave=true)
Check if user is blocked.
Definition: User.php:1722
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:100
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes two arrays as input, and returns a CGI-style string, e.g.
Definition: GlobalFunctions.php:367