45 private $readOnlyMode;
48 private $revisionLookup;
51 private $revisionRenderer;
54 private $commentFormatter;
77 parent::__construct( $article,
$context );
78 $this->readOnlyMode = $readOnlyMode;
79 $this->revisionLookup = $revisionLookup;
80 $this->revisionRenderer = $revisionRenderer;
81 $this->commentFormatter = $commentFormatter;
82 $this->useRCPatrol = $config->
get( MainConfigNames::UseRCPatrol );
107 $out->setRobotPolicy(
'noindex,nofollow' );
108 if ( $this->
getContext()->getConfig()->
get( MainConfigNames::UseMediaWikiUIEverywhere ) ) {
109 $out->addModuleStyles( [
110 'mediawiki.ui.input',
111 'mediawiki.ui.checkbox',
117 if ( $this->readOnlyMode->isReadOnly() ) {
119 "<div id=\"mw-read-only-warning\">\n$1\n</div>",
120 [
'readonlywarning', $this->readOnlyMode->getReason() ]
122 } elseif ( $this->context->getUser()->isAnon() ) {
125 if ( !$this->
getRequest()->getCheck(
'wpPreview' ) ) {
132 'returnto' => $this->getTitle()->getPrefixedDBkey()
136 'returnto' => $this->getTitle()->getPrefixedDBkey()
139 'mw-anon-edit-warning'
145 $out->msg(
'anonpreviewwarning' )->parse(),
146 'mw-anon-preview-warning'
156 $this->undoafter = $this->
getRequest()->getInt(
'undoafter' );
157 $this->undo = $this->
getRequest()->getInt(
'undo' );
159 if ( $this->undo == 0 || $this->undoafter == 0 ) {
160 throw new ErrorPageError(
'mcrundofailed',
'mcrundo-missingparam' );
168 $this->cur = $this->
getRequest()->getInt(
'cur', $this->curRev->getId() );
172 parent::checkCanExecute( $user );
178 $undoRev = $this->revisionLookup->getRevisionByTitle(
$title, $this->undo );
179 $oldRev = $this->revisionLookup->getRevisionByTitle(
$title, $this->undoafter );
181 if ( $undoRev ===
null || $oldRev ===
null ||
182 $undoRev->isDeleted( RevisionRecord::DELETED_TEXT ) ||
183 $oldRev->isDeleted( RevisionRecord::DELETED_TEXT )
194 private function getNewRevision() {
195 $undoRev = $this->revisionLookup->getRevisionById( $this->undo );
196 $oldRev = $this->revisionLookup->getRevisionById( $this->undoafter );
201 if ( $undoRev ===
null || $oldRev ===
null ||
202 $undoRev->isDeleted( RevisionRecord::DELETED_TEXT ) ||
203 $oldRev->isDeleted( RevisionRecord::DELETED_TEXT )
210 return MutableRevisionRecord::newFromParentRevision( $oldRev );
213 $newRev = MutableRevisionRecord::newFromParentRevision(
$curRev );
217 $rolesToMerge = array_unique( array_merge(
218 $oldRev->getSlotRoles(),
219 $undoRev->getSlotRoles(),
225 $rolesToMerge = array_intersect(
226 $rolesToMerge, $oldRev->getSlots()->getRolesWithDifferentContent( $undoRev->getSlots() )
228 if ( !$rolesToMerge ) {
234 $rolesToMerge = array_intersect(
235 $rolesToMerge, $oldRev->getSlots()->getRolesWithDifferentContent(
$curRev->
getSlots() )
237 if ( !$rolesToMerge ) {
243 $diffRoles = array_intersect(
244 $rolesToMerge, $undoRev->getSlots()->getRolesWithDifferentContent(
$curRev->
getSlots() )
246 foreach ( array_diff( $rolesToMerge, $diffRoles ) as $role ) {
247 if ( $oldRev->hasSlot( $role ) ) {
248 $newRev->inheritSlot( $oldRev->getSlot( $role, RevisionRecord::RAW ) );
250 $newRev->removeSlot( $role );
253 $rolesToMerge = $diffRoles;
264 foreach ( $rolesToMerge as $role ) {
265 if ( !$oldRev->hasSlot( $role ) || !$undoRev->hasSlot( $role ) || !
$curRev->
hasSlot( $role ) ) {
271 foreach ( $rolesToMerge as $role ) {
272 $oldContent = $oldRev->getSlot( $role, RevisionRecord::RAW )->getContent();
273 $undoContent = $undoRev->getSlot( $role, RevisionRecord::RAW )->getContent();
274 $curContent =
$curRev->
getSlot( $role, RevisionRecord::RAW )->getContent();
275 $newContent = $undoContent->getContentHandler()
276 ->getUndoContent( $curContent, $undoContent, $oldContent, $isLatest );
277 if ( !$newContent ) {
280 $newRev->setSlot( SlotRecord::newUnsaved( $role, $newContent ) );
286 private function generateDiffOrPreview() {
287 $newRev = $this->getNewRevision();
288 if ( $newRev->hasSameContent( $this->curRev ) ) {
293 $diffEngine->setRevisions( $this->curRev, $newRev );
295 $oldtitle = $this->context->msg(
'currentrev' )->parse();
296 $newtitle = $this->context->msg(
'yourtext' )->parse();
298 if ( $this->
getRequest()->getCheck(
'wpPreview' ) ) {
299 $this->showPreview( $newRev );
302 $diffText = $diffEngine->getDiff( $oldtitle, $newtitle );
303 $diffEngine->showDiffStyle();
304 return '<div id="wikiDiff">' . $diffText .
'</div>';
313 # provide a anchor link to the form
314 $continueEditing =
'<span class="mw-continue-editing">' .
315 '[[#mw-mcrundo-form|' .
316 $this->context->getLanguage()->getArrow() .
' ' .
317 $this->context->msg(
'continue-editing' )->text() .
']]</span>';
319 $note = $this->context->msg(
'previewnote' )->plain() .
' ' . $continueEditing;
321 $parserOptions = $this->
getWikiPage()->makeParserOptions( $this->context );
322 $parserOptions->setRenderReason(
'page-preview' );
323 $parserOptions->setIsPreview(
true );
324 $parserOptions->setIsSectionPreview(
false );
326 $parserOutput = $this->revisionRenderer
327 ->getRenderedRevision( $rev, $parserOptions, $this->
getAuthority() )
328 ->getRevisionParserOutput();
329 $previewHTML = $parserOutput->getText( [
330 'enableSectionEditLinks' =>
false,
331 'includeDebugInfo' =>
true,
334 $out->addParserOutputMetadata( $parserOutput );
335 if ( count( $parserOutput->getWarnings() ) ) {
336 $note .=
"\n\n" . implode(
"\n\n", $parserOutput->getWarnings() );
339 $m = $this->context->msg(
340 'content-failed-to-parse',
343 $note .=
"\n\n" . $m->parse();
347 $previewhead = Html::rawElement(
348 'div', [
'class' =>
'previewnote' ],
350 'h2', [
'id' =>
'mw-previewheader' ],
351 $this->context->msg(
'preview' )->text()
354 $out->parseAsInterface( $note )
358 $pageViewLang = $this->
getTitle()->getPageViewLanguage();
359 $attribs = [
'lang' => $pageViewLang->getHtmlCode(),
'dir' => $pageViewLang->getDir(),
360 'class' =>
'mw-content-' . $pageViewLang->getDir() ];
361 $previewHTML = Html::rawElement(
'div', $attribs, $previewHTML );
363 $out->addHTML( $previewhead . $previewHTML );
367 if ( !$this->
getRequest()->getCheck(
'wpSave' ) ) {
372 $updater = $this->
getWikiPage()->newPageUpdater( $this->context->getUser() );
373 $curRev = $updater->grabParentRevision();
384 if ( !$status->isOK() ) {
388 $newRev = $this->getNewRevision();
389 if ( !$newRev->hasSameContent(
$curRev ) ) {
391 foreach ( $newRev->getSlotRoles() as $slotRole ) {
392 $slot = $newRev->getSlot( $slotRole, RevisionRecord::RAW );
395 $hookResult = $hookRunner->onEditFilterMergedContent(
399 trim( $this->
getRequest()->getVal(
'wpSummary' ) ??
'' ),
404 if ( !$hookResult ) {
405 if ( $status->isGood() ) {
406 $status->error(
'hookaborted' );
410 } elseif ( !$status->isOK() ) {
411 if ( !$status->getErrors() ) {
412 $status->error(
'hookaborted' );
421 foreach ( $newRev->getSlots()->getSlots() as $slot ) {
422 $updater->setSlot( $slot );
425 if ( !$newRev->hasSlot( $role ) ) {
426 $updater->removeSlot( $role );
430 $updater->markAsRevert( EditResult::REVERT_UNDO, $this->undo, $this->undoafter );
433 ->authorizeWrite(
'autopatrol', $this->
getTitle() )
438 $updater->saveRevision(
439 CommentStoreComment::newUnsavedComment(
440 trim( $this->
getRequest()->getVal(
'wpSummary' ) ??
'' ) ),
444 return $updater->getStatus();
460 'default' =>
function () {
461 return $this->generateDiffOrPreview();
467 'name' =>
'wpSummary',
468 'cssclass' =>
'mw-summary',
469 'label-message' =>
'summary',
470 'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT,
471 'value' => $request->getVal(
'wpSummary',
'' ),
473 'spellcheck' =>
'true',
475 'summarypreview' => [
477 'label-message' =>
'summary-preview',
482 if ( $request->getCheck(
'wpSummary' ) ) {
483 $ret[
'summarypreview'][
'default'] =
Xml::tags(
485 [
'class' =>
'mw-summary-preview' ],
486 $this->commentFormatter->formatBlock(
487 trim( $request->getVal(
'wpSummary' ) ),
493 unset( $ret[
'summarypreview'] );
502 $labelAsPublish = $this->context->getConfig()->get( MainConfigNames::EditSubmitButtonLabelPublish );
504 $form->
setId(
'mw-mcrundo-form' );
507 $form->
setSubmitTextMsg( $labelAsPublish ?
'publishchanges' :
'savechanges' );
511 'name' =>
'wpPreview',
513 'label-message' =>
'showpreview',
514 'attribs' => Linker::tooltipAndAccesskeyAttribs(
'preview' ),
519 'label-message' =>
'showdiff',
520 'attribs' => Linker::tooltipAndAccesskeyAttribs(
'diff' ),
537 return '<div style="clear:both"></div>';
getWikiPage()
Get a WikiPage object.
IContextSource null $context
IContextSource if specified; otherwise we'll use the Context from the Page.
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.
getAuthority()
Shortcut to get the Authority executing this instance.
getRequest()
Get the WebRequest being used for this instance.
Legacy class representing an editable page and handling UI for some page actions.
DifferenceEngine is responsible for rendering the difference between two revisions as HTML.
An error page which can definitely be safely rendered using the OutputPage.
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...
__construct(Article $article, IContextSource $context, ReadOnlyMode $readOnlyMode, RevisionLookup $revisionLookup, RevisionRenderer $revisionRenderer, CommentFormatter $commentFormatter, Config $config)
onSuccess()
Do something exciting on successful processing of the form.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
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> element.
preText()
Add pre- or post-text to the form.
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.
getFormFields()
Get an HTMLForm descriptor array.
A class containing constants representing the names of configuration variables.
Show an error when a user tries to do something they do not have the necessary permissions for.
A service class for fetching the wiki's current read-only mode.
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,...
static newFatal( $message,... $parameters)
Factory function for fatal errors.
static newGood( $value=null)
Factory function for good results.
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,...
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Interface for configuration instances.
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
Interface for objects which can provide a MediaWiki context on request.