53 MediaWiki\Session\SessionManager::getGlobalSession()->persist();
59 $out->setRobotPolicy(
'noindex,nofollow' );
60 if ( $this->
getContext()->getConfig()->
get(
'UseMediaWikiUIEverywhere' ) ) {
61 $out->addModuleStyles( [
63 'mediawiki.ui.checkbox',
71 "<div id=\"mw-read-only-warning\">\n$1\n</div>",
74 } elseif ( $this->context->getUser()->isAnon() ) {
75 if ( !$this->
getRequest()->getCheck(
'wpPreview' ) ) {
77 "<div id='mw-anon-edit-warning' class='warningbox'>\n$1\n</div>",
81 'returnto' => $this->
getTitle()->getPrefixedDBkey()
85 'returnto' => $this->
getTitle()->getPrefixedDBkey()
90 $out->wrapWikiMsg(
"<div id=\"mw-anon-preview-warning\" class=\"warningbox\">\n$1</div>",
100 $this->undoafter = $this->
getRequest()->getInt(
'undoafter' );
101 $this->undo = $this->
getRequest()->getInt(
'undo' );
103 if ( $this->undo == 0 || $this->undoafter == 0 ) {
104 throw new ErrorPageError(
'mcrundofailed',
'mcrundo-missingparam' );
112 $this->cur = $this->
getRequest()->getInt(
'cur', $this->curRev->getId() );
116 parent::checkCanExecute( $user );
120 $revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup();
124 $undoRev = $revisionLookup->getRevisionByTitle(
$title, $this->undo );
125 $oldRev = $revisionLookup->getRevisionByTitle(
$title, $this->undoafter );
127 if ( $undoRev ===
null || $oldRev ===
null ||
128 $undoRev->isDeleted( RevisionRecord::DELETED_TEXT ) ||
129 $oldRev->isDeleted( RevisionRecord::DELETED_TEXT )
141 $revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup();
143 $undoRev = $revisionLookup->getRevisionById( $this->undo );
144 $oldRev = $revisionLookup->getRevisionById( $this->undoafter );
149 if ( $undoRev ===
null || $oldRev ===
null ||
150 $undoRev->isDeleted( RevisionRecord::DELETED_TEXT ) ||
151 $oldRev->isDeleted( RevisionRecord::DELETED_TEXT )
158 return MutableRevisionRecord::newFromParentRevision( $oldRev );
161 $newRev = MutableRevisionRecord::newFromParentRevision(
$curRev );
165 $rolesToMerge = array_unique( array_merge(
166 $oldRev->getSlotRoles(),
167 $undoRev->getSlotRoles(),
173 $rolesToMerge = array_intersect(
174 $rolesToMerge, $oldRev->getSlots()->getRolesWithDifferentContent( $undoRev->getSlots() )
176 if ( !$rolesToMerge ) {
182 $rolesToMerge = array_intersect(
183 $rolesToMerge, $oldRev->getSlots()->getRolesWithDifferentContent(
$curRev->
getSlots() )
185 if ( !$rolesToMerge ) {
191 $diffRoles = array_intersect(
192 $rolesToMerge, $undoRev->getSlots()->getRolesWithDifferentContent(
$curRev->
getSlots() )
194 foreach ( array_diff( $rolesToMerge, $diffRoles ) as $role ) {
195 if ( $oldRev->hasSlot( $role ) ) {
196 $newRev->inheritSlot( $oldRev->getSlot( $role, RevisionRecord::RAW ) );
198 $newRev->removeSlot( $role );
201 $rolesToMerge = $diffRoles;
212 foreach ( $rolesToMerge as $role ) {
213 if ( !$oldRev->hasSlot( $role ) || !$undoRev->hasSlot( $role ) || !
$curRev->
hasSlot( $role ) ) {
219 foreach ( $rolesToMerge as $role ) {
220 $oldContent = $oldRev->getSlot( $role, RevisionRecord::RAW )->getContent();
221 $undoContent = $undoRev->getSlot( $role, RevisionRecord::RAW )->getContent();
222 $curContent =
$curRev->
getSlot( $role, RevisionRecord::RAW )->getContent();
223 $newContent = $undoContent->getContentHandler()
224 ->getUndoContent( $curContent, $undoContent, $oldContent, $isLatest );
225 if ( !$newContent ) {
228 $newRev->setSlot( SlotRecord::newUnsaved( $role, $newContent ) );
236 if ( $newRev->hasSameContent( $this->curRev ) ) {
241 $diffEngine->setRevisions( $this->curRev, $newRev );
243 $oldtitle = $this->context->msg(
'currentrev' )->parse();
244 $newtitle = $this->context->msg(
'yourtext' )->parse();
246 if ( $this->
getRequest()->getCheck(
'wpPreview' ) ) {
250 $diffText = $diffEngine->getDiff( $oldtitle, $newtitle );
251 $diffEngine->showDiffStyle();
252 return '<div id="wikiDiff">' . $diffText .
'</div>';
263 # provide a anchor link to the form
264 $continueEditing =
'<span class="mw-continue-editing">' .
265 '[[#mw-mcrundo-form|' .
266 $this->context->getLanguage()->getArrow() .
' ' .
267 $this->context->msg(
'continue-editing' )->text() .
']]</span>';
269 $note = $this->context->msg(
'previewnote' )->plain() .
' ' . $continueEditing;
271 $parserOptions = $this->
getWikiPage()->makeParserOptions( $this->context );
272 $parserOptions->setIsPreview(
true );
273 $parserOptions->setIsSectionPreview(
false );
274 $parserOptions->enableLimitReport();
276 $parserOutput = MediaWikiServices::getInstance()->getRevisionRenderer()
277 ->getRenderedRevision( $rev, $parserOptions, $this->context->
getUser() )
278 ->getRevisionParserOutput();
279 $previewHTML = $parserOutput->getText( [
'enableSectionEditLinks' =>
false ] );
281 $out->addParserOutputMetadata( $parserOutput );
282 if ( count( $parserOutput->getWarnings() ) ) {
283 $note .=
"\n\n" . implode(
"\n\n", $parserOutput->getWarnings() );
286 $m = $this->context->msg(
287 'content-failed-to-parse',
290 $note .=
"\n\n" . $m->parse();
294 $previewhead = Html::rawElement(
295 'div', [
'class' =>
'previewnote' ],
297 'h2', [
'id' =>
'mw-previewheader' ],
298 $this->context->msg(
'preview' )->text()
300 Html::rawElement(
'div', [
'class' =>
'warningbox' ],
301 $out->parseAsInterface( $note )
305 $pageViewLang = $this->
getTitle()->getPageViewLanguage();
306 $attribs = [
'lang' => $pageViewLang->getHtmlCode(),
'dir' => $pageViewLang->getDir(),
307 'class' =>
'mw-content-' . $pageViewLang->getDir() ];
308 $previewHTML = Html::rawElement(
'div', $attribs, $previewHTML );
310 $out->addHTML( $previewhead . $previewHTML );
316 if ( !$this->
getRequest()->getCheck(
'wpSave' ) ) {
321 $updater = $this->
getWikiPage()->newPageUpdater( $this->context->getUser() );
322 $curRev = $updater->grabParentRevision();
328 return Status::newFatal(
'mcrundo-changed' );
331 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
332 $errors = $permissionManager->getPermissionErrors(
333 'edit', $this->context->getUser(), $this->getTitle()
335 if ( count( $errors ) ) {
340 if ( !$newRev->hasSameContent(
$curRev ) ) {
341 $hookRunner = Hooks::runner();
342 foreach ( $newRev->getSlotRoles() as $slotRole ) {
343 $slot = $newRev->getSlot( $slotRole, RevisionRecord::RAW );
346 $hookResult = $hookRunner->onEditFilterMergedContent(
350 trim( $this->
getRequest()->getVal(
'wpSummary' ) ??
'' ),
355 if ( !$hookResult ) {
356 if ( $status->isGood() ) {
357 $status->error(
'hookaborted' );
361 } elseif ( !$status->isOK() ) {
362 if ( !$status->getErrors() ) {
363 $status->error(
'hookaborted' );
369 $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
374 foreach ( $newRev->getSlots()->getSlots() as $slot ) {
375 $updater->setSlot( $slot );
378 if ( !$newRev->hasSlot( $role ) ) {
379 $updater->removeSlot( $role );
385 $oldRev = $revisionStore->getRevisionById( $this->undoafter );
386 $oldestRevertedRev = $revisionStore->getNextRevision( $oldRev );
387 if ( $oldestRevertedRev ) {
388 $updater->markAsRevert(
389 EditResult::REVERT_UNDO,
390 $oldestRevertedRev->getId(),
395 $updater->markAsRevert( EditResult::REVERT_UNDO, $this->undo );
398 if ( $oldRev->hasSameContent( $newRev ) ) {
399 $updater->setOriginalRevisionId( $oldRev->getId() );
402 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
410 $updater->setRcPatrolStatus( RecentChange::PRC_AUTOPATROLLED );
413 $updater->saveRevision(
414 CommentStoreComment::newUnsavedComment(
415 trim( $this->
getRequest()->getVal(
'wpSummary' ) ??
'' ) ),
419 return $updater->getStatus();
422 return Status::newGood();
434 'vertical-label' =>
true,
436 'default' =>
function () {
443 'name' =>
'wpSummary',
444 'cssclass' =>
'mw-summary',
445 'label-message' =>
'summary',
446 'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT,
447 'value' => $request->getVal(
'wpSummary',
'' ),
449 'spellcheck' =>
'true',
451 'summarypreview' => [
453 'label-message' =>
'summary-preview',
458 if ( $request->getCheck(
'wpSummary' ) ) {
459 $ret[
'summarypreview'][
'default'] = Xml::tags(
'div', [
'class' =>
'mw-summary-preview' ],
463 unset( $ret[
'summarypreview'] );
472 $labelAsPublish = $this->context->getConfig()->get(
'EditSubmitButtonLabelPublish' );
474 $form->
setId(
'mw-mcrundo-form' );
477 $form->
setSubmitTextMsg( $labelAsPublish ?
'publishchanges' :
'savechanges' );
481 'name' =>
'wpPreview',
483 'label-message' =>
'showpreview',
489 'label-message' =>
'showdiff',
507 return '<div style="clear:both"></div>';
$wgUseRCPatrol
Use RC Patrolling to check for vandalism (from recent changes and watchlists) New pages and new files...
wfReadOnly()
Check whether the wiki is in read-only mode.
wfReadOnlyReason()
Check if the site is in read-only mode and return the message if so.
getWikiPage()
Get a WikiPage object.
getTitle()
Shortcut to get the Title object from the page.
getContext()
Get the IContextSource in use here.
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User being used for this instance.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
getRequest()
Get the WebRequest being used for this instance.
DifferenceEngine is responsible for rendering the difference between two revisions as HTML.
An error page which can definitely be safely rendered using the OutputPage.
static commentBlock( $comment, $title=null, $local=false, $wikiId=null, $useParentheses=true)
Wrap a comment in standard punctuation and formatting if it's non-empty, otherwise return empty strin...
static tooltipAndAccesskeyAttribs( $name, array $msgParams=[], $options=null)
Returns the attributes for the tooltip and access key.
Exception representing a failure to serialize or unserialize a content object.
Temporary action for MCR undos.
show()
The basic pattern for actions is to display some sort of HTMLForm UI, maybe with some stuff underneat...
onSuccess()
Do something exciting on successful processing of the form.
showPreview(RevisionRecord $rev)
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially Stable to override.
checkCanExecute(User $user)
Checks if the given user (identified by an object) can perform this action.
onSubmit( $data)
Process the form on POST submission.
RevisionRecord null $curRev
getDescription()
Returns the description that goes below the <h1> tag.
preText()
Add pre- or post-text to the form Stable to override.
addStatePropagationFields(HTMLForm $form)
getName()
Return the name of the action this object responds to.
getRestriction()
Get the permission required to perform this action.
usesOOUI()
Whether the form should use OOUI Stable to override.
getFormFields()
Get an HTMLForm descriptor array Stable to override.
Show an error when a user tries to do something they do not have the necessary permissions for.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Generic operation result class Has warning/error list, boolean status and arbitrary value.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...