MediaWiki  1.23.2
RevertAction.php
Go to the documentation of this file.
1 <?php
31 class RevertAction extends Action {
32 
33  public function getName() {
34  return 'revert';
35  }
36 
37  public function show() {
38  $this->getOutput()->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
39  }
40 
41  public function execute() {
42  }
43 }
44 
54  protected $oldFile;
55 
56  public function getName() {
57  return 'revert';
58  }
59 
60  public function getRestriction() {
61  return 'upload';
62  }
63 
64  protected function checkCanExecute( User $user ) {
65  parent::checkCanExecute( $user );
66 
67  $oldimage = $this->getRequest()->getText( 'oldimage' );
68  if ( strlen( $oldimage ) < 16
69  || strpos( $oldimage, '/' ) !== false
70  || strpos( $oldimage, '\\' ) !== false
71  ) {
72  throw new ErrorPageError( 'internalerror', 'unexpected', array( 'oldimage', $oldimage ) );
73  }
74 
75  $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName(
76  $this->getTitle(),
77  $oldimage
78  );
79 
80  if ( !$this->oldFile->exists() ) {
81  throw new ErrorPageError( '', 'filerevert-badversion' );
82  }
83  }
84 
85  protected function alterForm( HTMLForm $form ) {
86  $form->setWrapperLegendMsg( 'filerevert-legend' );
87  $form->setSubmitTextMsg( 'filerevert-submit' );
88  $form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) );
89  }
90 
91  protected function getFormFields() {
93 
94  $timestamp = $this->oldFile->getTimestamp();
95 
96  $user = $this->getUser();
97  $lang = $this->getLanguage();
98  $userDate = $lang->userDate( $timestamp, $user );
99  $userTime = $lang->userTime( $timestamp, $user );
100  $siteDate = $wgContLang->date( $timestamp, false, false );
101  $siteTime = $wgContLang->time( $timestamp, false, false );
102 
103  return array(
104  'intro' => array(
105  'type' => 'info',
106  'vertical-label' => true,
107  'raw' => true,
108  'default' => $this->msg( 'filerevert-intro',
109  $this->getTitle()->getText(), $userDate, $userTime,
110  wfExpandUrl(
111  $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
113  ) )->parseAsBlock()
114  ),
115  'comment' => array(
116  'type' => 'text',
117  'label-message' => 'filerevert-comment',
118  'default' => $this->msg( 'filerevert-defaultcomment', $siteDate, $siteTime
119  )->inContentLanguage()->text()
120  )
121  );
122  }
123 
124  public function onSubmit( $data ) {
125  $source = $this->page->getFile()->getArchiveVirtualUrl(
126  $this->getRequest()->getText( 'oldimage' )
127  );
128  $comment = $data['comment'];
129 
130  // TODO: Preserve file properties from database instead of reloading from file
131  return $this->page->getFile()->upload(
132  $source,
133  $comment,
134  $comment,
135  0,
136  false,
137  false,
138  $this->getUser()
139  );
140  }
141 
142  public function onSuccess() {
143  $timestamp = $this->oldFile->getTimestamp();
144  $user = $this->getUser();
145  $lang = $this->getLanguage();
146  $userDate = $lang->userDate( $timestamp, $user );
147  $userTime = $lang->userTime( $timestamp, $user );
148 
149  $this->getOutput()->addWikiMsg( 'filerevert-success', $this->getTitle()->getText(),
150  $userDate, $userTime,
151  wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
153  ) );
154  $this->getOutput()->returnToMain( false, $this->getTitle() );
155  }
156 
157  protected function getPageTitle() {
158  return $this->msg( 'filerevert', $this->getTitle()->getText() );
159  }
160 
161  protected function getDescription() {
162  $this->getOutput()->addBacklinkSubtitle( $this->getTitle() );
163 
164  return '';
165  }
166 }
RevertFileAction\$oldFile
OldLocalFile $oldFile
Definition: RevertAction.php:53
RevertAction\getName
getName()
Return the name of the action this object responds to.
Definition: RevertAction.php:33
RepoGroup\singleton
static singleton()
Get a RepoGroup instance.
Definition: RepoGroup.php:53
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
RevertAction\show
show()
The main action entry point.
Definition: RevertAction.php:37
RevertFileAction\getDescription
getDescription()
Returns the description that goes below the <h1> tag.
Definition: RevertAction.php:160
Action\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: Action.php:182
RevertFileAction
Class for pages in NS_FILE.
Definition: RevertAction.php:50
$timestamp
if( $limit) $timestamp
Definition: importImages.php:104
$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
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
RevertAction
Dummy class for pages not in NS_FILE.
Definition: RevertAction.php:31
Action
Actions are things which can be done to pages (edit, delete, rollback, etc).
Definition: Action.php:37
RevertFileAction\alterForm
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
Definition: RevertAction.php:84
RevertFileAction\onSuccess
onSuccess()
Do something exciting on successful processing of the form.
Definition: RevertAction.php:141
RevertFileAction\getFormFields
getFormFields()
Get an HTMLForm descriptor array.
Definition: RevertAction.php:90
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:270
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$comment
$comment
Definition: importImages.php:107
RevertAction\execute
execute()
Execute the action in a silent fashion: do not display anything or release any errors.
Definition: RevertAction.php:41
Action\getUser
getUser()
Shortcut to get the User being used for this instance.
Definition: Action.php:200
Action\getTitle
getTitle()
Shortcut to get the Title object from the page.
Definition: Action.php:237
$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
Action\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: Action.php:247
RevertFileAction\getPageTitle
getPageTitle()
Returns the name that goes in the <h1> page title.
Definition: RevertAction.php:156
RevertFileAction\getRestriction
getRestriction()
Get the permission required to perform this action.
Definition: RevertAction.php:59
Action\getLanguage
getLanguage()
Shortcut to get the user Language being used for this instance.
Definition: Action.php:218
$source
if(PHP_SAPI !='cli') $source
Definition: mwdoc-filter.php:18
RevertFileAction\onSubmit
onSubmit( $data)
Process the form on POST submission.
Definition: RevertAction.php:123
Action\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: Action.php:191
RevertFileAction\checkCanExecute
checkCanExecute(User $user)
Checks if the given user (identified by an object) can perform this action.
Definition: RevertAction.php:63
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:27
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
OldLocalFile
Class to represent a file in the oldimage table.
Definition: OldLocalFile.php:29
RevertFileAction\getName
getName()
Return the name of the action this object responds to.
Definition: RevertAction.php:55
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:497
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