MediaWiki  1.23.2
FormAction.php
Go to the documentation of this file.
1 <?php
29 abstract class FormAction extends Action {
30 
35  abstract protected function getFormFields();
36 
41  protected function preText() {
42  return '';
43  }
44 
48  protected function postText() {
49  return '';
50  }
51 
56  protected function alterForm( HTMLForm $form ) {
57  }
58 
63  protected function getForm() {
64  $this->fields = $this->getFormFields();
65 
66  // Give hooks a chance to alter the form, adding extra fields or text etc
67  wfRunHooks( 'ActionModifyFormFields', array( $this->getName(), &$this->fields, $this->page ) );
68 
69  $form = new HTMLForm( $this->fields, $this->getContext(), $this->getName() );
70  $form->setSubmitCallback( array( $this, 'onSubmit' ) );
71 
72  // Retain query parameters (uselang etc)
73  $form->addHiddenField( 'action', $this->getName() ); // Might not be the same as the query string
74  $params = array_diff_key(
75  $this->getRequest()->getQueryValues(),
76  array( 'action' => null, 'title' => null )
77  );
78  $form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) );
79 
80  $form->addPreText( $this->preText() );
81  $form->addPostText( $this->postText() );
82  $this->alterForm( $form );
83 
84  // Give hooks a chance to alter the form, adding extra fields or text etc
85  wfRunHooks( 'ActionBeforeFormDisplay', array( $this->getName(), &$form, $this->page ) );
86 
87  return $form;
88  }
89 
97  abstract public function onSubmit( $data );
98 
104  abstract public function onSuccess();
105 
113  public function show() {
114  $this->setHeaders();
115 
116  // This will throw exceptions if there's a problem
117  $this->checkCanExecute( $this->getUser() );
118 
119  $form = $this->getForm();
120  if ( $form->show() ) {
121  $this->onSuccess();
122  }
123  }
124 
133  public function execute( array $data = null, $captureErrors = true ) {
134  try {
135  // Set a new context so output doesn't leak.
136  $this->context = clone $this->getContext();
137 
138  // This will throw exceptions if there's a problem
139  $this->checkCanExecute( $this->getUser() );
140 
141  $fields = array();
142  foreach ( $this->fields as $key => $params ) {
143  if ( isset( $data[$key] ) ) {
144  $fields[$key] = $data[$key];
145  } elseif ( isset( $params['default'] ) ) {
146  $fields[$key] = $params['default'];
147  } else {
148  $fields[$key] = null;
149  }
150  }
151  $status = $this->onSubmit( $fields );
152  if ( $status === true ) {
153  // This might do permanent stuff
154  $this->onSuccess();
155  return true;
156  } else {
157  return false;
158  }
159  }
160  catch ( ErrorPageError $e ) {
161  if ( $captureErrors ) {
162  return false;
163  } else {
164  throw $e;
165  }
166  }
167  }
168 }
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
Action\setHeaders
setHeaders()
Set output headers for noindexing etc.
Definition: Action.php:338
Action\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: Action.php:182
$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
FormAction
An action which shows a form and does something based on the input from the form.
Definition: FormAction.php:29
Action\getName
getName()
Return the name of the action this object responds to.
$params
$params
Definition: styleTest.css.php:40
FormAction\postText
postText()
Definition: FormAction.php:48
FormAction\onSubmit
onSubmit( $data)
Process the form on POST submission.
FormAction\preText
preText()
Add pre- or post-text to the form.
Definition: FormAction.php:41
Action
Actions are things which can be done to pages (edit, delete, rollback, etc).
Definition: Action.php:37
FormAction\onSuccess
onSuccess()
Do something exciting on successful processing of the form.
Action\getContext
getContext()
Get the IContextSource in use here.
Definition: Action.php:164
Action\checkCanExecute
checkCanExecute(User $user)
Checks if the given user (identified by an object) can perform this action.
Definition: Action.php:295
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4001
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
FormAction\getFormFields
getFormFields()
Get an HTMLForm descriptor array.
FormAction\getForm
getForm()
Get the HTMLForm to control behavior.
Definition: FormAction.php:63
Action\getUser
getUser()
Shortcut to get the User being used for this instance.
Definition: Action.php:200
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Action\$fields
array $fields
The fields used to create the HTMLForm $fields.
Definition: Action.php:52
FormAction\alterForm
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
Definition: FormAction.php:56
$e
if( $useReadline) $e
Definition: eval.php:66
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:27
FormAction\execute
execute(array $data=null, $captureErrors=true)
Definition: FormAction.php:133
FormAction\show
show()
The basic pattern for actions is to display some sort of HTMLForm UI, maybe with some stuff underneat...
Definition: FormAction.php:113
page
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values my talk page
Definition: hooks.txt:1956
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