MediaWiki  master
EditPage.php
Go to the documentation of this file.
1 <?php
47 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
62 use OOUI\CheckboxInputWidget;
63 use OOUI\DropdownInputWidget;
64 use OOUI\FieldLayout;
67 use Wikimedia\ScopedCallback;
68 
89 class EditPage implements IEditObject {
91  use ProtectedHookAccessorTrait;
92 
96  public const UNICODE_CHECK = UnicodeConstraint::VALID_UNICODE;
97 
101  public const EDITFORM_ID = 'editform';
102 
107  public const POST_EDIT_COOKIE_KEY_PREFIX = 'PostEditRevision';
108 
122  public const POST_EDIT_COOKIE_DURATION = 1200;
123 
128  public $mArticle;
129 
131  private $page;
132 
137  public $mTitle;
138 
140  private $mContextTitle = null;
141 
143  public $action = 'submit';
144 
149  public $isConflict = false;
150 
152  public $isNew = false;
153 
156 
158  public $formtype;
159 
164  public $firsttime;
165 
167  private $lastDelete;
168 
170  private $mTokenOk = false;
171 
173  private $mTriedSave = false;
174 
176  private $incompleteForm = false;
177 
179  private $tooBig = false;
180 
182  private $missingComment = false;
183 
185  private $missingSummary = false;
186 
188  private $allowBlankSummary = false;
189 
191  protected $blankArticle = false;
192 
194  protected $allowBlankArticle = false;
195 
197  protected $selfRedirect = false;
198 
200  protected $allowSelfRedirect = false;
201 
203  private $autoSumm = '';
204 
206  private $hookError = '';
207 
209  private $mParserOutput;
210 
214  private $hasPresetSummary = false;
215 
221  private $mExpectedParentRevision = false;
222 
224  public $mShowSummaryField = true;
225 
226  # Form values
227 
229  public $save = false;
230 
232  public $preview = false;
233 
235  public $diff = false;
236 
238  private $minoredit = false;
239 
241  private $watchthis = false;
242 
245 
248 
251 
253  private $recreate = false;
254 
258  public $textbox1 = '';
259 
261  public $textbox2 = '';
262 
264  public $summary = '';
265 
270  private $nosummary = false;
271 
276  public $edittime = '';
277 
289  private $editRevId = null;
290 
292  public $section = '';
293 
295  public $sectiontitle = '';
296 
300  public $starttime = '';
301 
307  public $oldid = 0;
308 
315  private $parentRevId = 0;
316 
318  private $editintro = '';
319 
321  private $scrolltop = null;
322 
324  private $markAsBot = true;
325 
328 
330  public $contentFormat = null;
331 
333  private $changeTags = null;
334 
335  # Placeholders for text injection by hooks (must be HTML)
336  # extensions should take care to _append_ to the present value
337 
339  public $editFormPageTop = '';
340  public $editFormTextTop = '';
344  public $editFormTextBottom = '';
347  public $mPreloadContent = null;
348 
349  /* $didSave should be set to true whenever an article was successfully altered. */
350  public $didSave = false;
351  public $undidRev = 0;
352  public $undoAfter = 0;
353 
354  public $suppressIntro = false;
355 
357  protected $edit;
358 
360  protected $contentLength = false;
361 
365  private $enableApiEditOverride = false;
366 
370  protected $context;
371 
375  private $isOldRev = false;
376 
380  private $unicodeCheck;
381 
388 
393 
398 
402  private $permManager;
403 
407  private $revisionStore;
408 
413 
418 
422  private $userNameUtils;
423 
428  public function __construct( Article $article ) {
429  $this->mArticle = $article;
430  $this->page = $article->getPage(); // model object
431  $this->mTitle = $article->getTitle();
432 
433  // Make sure the local context is in sync with other member variables.
434  // Particularly make sure everything is using the same WikiPage instance.
435  // This should probably be the case in Article as well, but it's
436  // particularly important for EditPage, to make use of the in-place caching
437  // facility in WikiPage::prepareContentForEdit.
438  $this->context = new DerivativeContext( $article->getContext() );
439  $this->context->setWikiPage( $this->page );
440  $this->context->setTitle( $this->mTitle );
441 
442  $this->contentModel = $this->mTitle->getContentModel();
443 
444  $services = MediaWikiServices::getInstance();
445  $this->contentHandlerFactory = $services->getContentHandlerFactory();
446  $this->contentFormat = $this->contentHandlerFactory
447  ->getContentHandler( $this->contentModel )
448  ->getDefaultFormat();
449  $this->editConflictHelperFactory = [ $this, 'newTextConflictHelper' ];
450  $this->permManager = $services->getPermissionManager();
451  $this->revisionStore = $services->getRevisionStore();
452  $this->watchlistExpiryEnabled = $this->getContext()->getConfig() instanceof Config
453  && $this->getContext()->getConfig()->get( 'WatchlistExpiry' );
454  $this->watchedItemStore = $services->getWatchedItemStore();
455  $this->wikiPageFactory = $services->getWikiPageFactory();
456  $this->watchlistManager = $services->getWatchlistManager();
457  $this->userNameUtils = $services->getUserNameUtils();
458 
459  $this->deprecatePublicProperty( 'deletedSinceEdit', '1.35', __CLASS__ );
460  $this->deprecatePublicProperty( 'lastDelete', '1.35', __CLASS__ );
461  $this->deprecatePublicProperty( 'mTokenOk', '1.35', __CLASS__ );
462  $this->deprecatePublicProperty( 'mTriedSave', '1.35', __CLASS__ );
463  $this->deprecatePublicProperty( 'incompleteForm', '1.35', __CLASS__ );
464  $this->deprecatePublicProperty( 'tooBig', '1.35', __CLASS__ );
465  $this->deprecatePublicProperty( 'missingComment', '1.35', __CLASS__ );
466  $this->deprecatePublicProperty( 'missingSummary', '1.35', __CLASS__ );
467  $this->deprecatePublicProperty( 'allowBlankSummary', '1.35', __CLASS__ );
468  $this->deprecatePublicProperty( 'autoSumm', '1.35', __CLASS__ );
469  $this->deprecatePublicProperty( 'mParserOutput', '1.35', __CLASS__ );
470  $this->deprecatePublicProperty( 'hasPresetSummary', '1.35', __CLASS__ );
471  $this->deprecatePublicProperty( 'minoredit', '1.35', __CLASS__ );
472  $this->deprecatePublicProperty( 'watchthis', '1.35', __CLASS__ );
473  $this->deprecatePublicProperty( 'recreate', '1.35', __CLASS__ );
474  $this->deprecatePublicProperty( 'nosummaryparentRevId', '1.35', __CLASS__ );
475  $this->deprecatePublicProperty( 'editintro', '1.35', __CLASS__ );
476  $this->deprecatePublicProperty( 'scrolltop', '1.35', __CLASS__ );
477  $this->deprecatePublicProperty( 'markAsBot', '1.35', __CLASS__ );
478  }
479 
483  public function getArticle() {
484  return $this->mArticle;
485  }
486 
491  public function getContext() {
492  return $this->context;
493  }
494 
499  public function getTitle() {
500  return $this->mTitle;
501  }
502 
506  public function setContextTitle( $title ) {
507  $this->mContextTitle = $title;
508  }
509 
514  public function getContextTitle() {
515  if ( $this->mContextTitle === null ) {
516  throw new RuntimeException( "EditPage does not have a context title set" );
517  } else {
518  return $this->mContextTitle;
519  }
520  }
521 
529  public function isSupportedContentModel( $modelId ) {
530  return $this->enableApiEditOverride === true ||
531  $this->contentHandlerFactory->getContentHandler( $modelId )->supportsDirectEditing();
532  }
533 
540  public function setApiEditOverride( $enableOverride ) {
541  $this->enableApiEditOverride = $enableOverride;
542  }
543 
555  public function edit() {
556  // Allow extensions to modify/prevent this form or submission
557  if ( !$this->getHookRunner()->onAlternateEdit( $this ) ) {
558  return;
559  }
560 
561  wfDebug( __METHOD__ . ": enter" );
562 
563  $request = $this->context->getRequest();
564  // If they used redlink=1 and the page exists, redirect to the main article
565  if ( $request->getBool( 'redlink' ) && $this->mTitle->exists() ) {
566  $this->context->getOutput()->redirect( $this->mTitle->getFullURL() );
567  return;
568  }
569 
570  $this->importFormData( $request );
571  $this->firsttime = false;
572 
573  if ( wfReadOnly() && $this->save ) {
574  // Force preview
575  $this->save = false;
576  $this->preview = true;
577  }
578 
579  if ( $this->save ) {
580  $this->formtype = 'save';
581  } elseif ( $this->preview ) {
582  $this->formtype = 'preview';
583  } elseif ( $this->diff ) {
584  $this->formtype = 'diff';
585  } else { # First time through
586  $this->firsttime = true;
587  if ( $this->previewOnOpen() ) {
588  $this->formtype = 'preview';
589  } else {
590  $this->formtype = 'initial';
591  }
592  }
593 
594  $permErrors = $this->getEditPermissionErrors(
595  $this->save ? PermissionManager::RIGOR_SECURE : PermissionManager::RIGOR_FULL
596  );
597  if ( $permErrors ) {
598  wfDebug( __METHOD__ . ": User can't edit" );
599 
600  if ( $this->context->getUser()->getBlock() ) {
601  // Auto-block user's IP if the account was "hard" blocked
602  if ( !wfReadOnly() ) {
604  $this->context->getUser()->spreadAnyEditBlock();
605  } );
606  }
607  }
608  $this->displayPermissionsError( $permErrors );
609 
610  return;
611  }
612 
613  $revRecord = $this->mArticle->fetchRevisionRecord();
614  // Disallow editing revisions with content models different from the current one
615  // Undo edits being an exception in order to allow reverting content model changes.
616  $revContentModel = $revRecord ?
617  $revRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel() :
618  false;
619  if ( $revContentModel && $revContentModel !== $this->contentModel ) {
620  $prevRevRecord = null;
621  $prevContentModel = false;
622  if ( $this->undidRev ) {
623  $undidRevRecord = $this->revisionStore
624  ->getRevisionById( $this->undidRev );
625  $prevRevRecord = $undidRevRecord ?
626  $this->revisionStore->getPreviousRevision( $undidRevRecord ) :
627  null;
628 
629  $prevContentModel = $prevRevRecord ?
630  $prevRevRecord
631  ->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )
632  ->getModel() :
633  '';
634  }
635 
636  if ( !$this->undidRev
637  || !$prevRevRecord
638  || $prevContentModel !== $this->contentModel
639  ) {
640  $this->displayViewSourcePage(
641  $this->getContentObject(),
642  $this->context->msg(
643  'contentmodelediterror',
644  $revContentModel,
645  $this->contentModel
646  )->plain()
647  );
648  return;
649  }
650  }
651 
652  $this->isConflict = false;
653 
654  # Show applicable editing introductions
655  if ( $this->formtype == 'initial' || $this->firsttime ) {
656  $this->showIntro();
657  }
658 
659  # Attempt submission here. This will check for edit conflicts,
660  # and redundantly check for locked database, blocked IPs, etc.
661  # that edit() already checked just in case someone tries to sneak
662  # in the back door with a hand-edited submission URL.
663 
664  if ( $this->formtype == 'save' ) {
665  $resultDetails = null;
666  $status = $this->attemptSave( $resultDetails );
667  if ( !$this->handleStatus( $status, $resultDetails ) ) {
668  return;
669  }
670  }
671 
672  # First time through: get contents, set time for conflict
673  # checking, etc.
674  if ( $this->formtype == 'initial' || $this->firsttime ) {
675  if ( $this->initialiseForm() === false ) {
676  return;
677  }
678 
679  if ( !$this->mTitle->getArticleID() ) {
680  $this->getHookRunner()->onEditFormPreloadText( $this->textbox1, $this->mTitle );
681  } else {
682  $this->getHookRunner()->onEditFormInitialText( $this );
683  }
684 
685  }
686 
687  // If we're displaying an old revision, and there are differences between it and the
688  // current revision outside the main slot, then we can't allow the old revision to be
689  // editable, as what would happen to the non-main-slot data if someone saves the old
690  // revision is undefined.
691  // When this is the case, display a read-only version of the page instead, with a link
692  // to a diff page from which the old revision can be restored
693  $curRevisionRecord = $this->page->getRevisionRecord();
694  if ( $curRevisionRecord
695  && $revRecord
696  && $curRevisionRecord->getId() !== $revRecord->getId()
698  $revRecord,
699  $curRevisionRecord
700  ) || !$this->isSupportedContentModel(
701  $revRecord->getSlot(
702  SlotRecord::MAIN,
703  RevisionRecord::RAW
704  )->getModel()
705  ) )
706  ) {
707  $restoreLink = $this->mTitle->getFullURL(
708  [
709  'action' => 'mcrrestore',
710  'restore' => $revRecord->getId(),
711  ]
712  );
713  $this->displayViewSourcePage(
714  $this->getContentObject(),
715  $this->context->msg(
716  'nonmain-slot-differences-therefore-readonly',
717  $restoreLink
718  )->plain()
719  );
720  return;
721  }
722 
723  $this->showEditForm();
724  }
725 
730  protected function getEditPermissionErrors( $rigor = PermissionManager::RIGOR_SECURE ) {
731  $user = $this->context->getUser();
732  $permErrors = $this->permManager->getPermissionErrors(
733  'edit',
734  $user,
735  $this->mTitle,
736  $rigor
737  );
738  # Ignore some permissions errors when a user is just previewing/viewing diffs
739  $remove = [];
740  foreach ( $permErrors as $error ) {
741  if ( ( $this->preview || $this->diff )
742  && (
743  $error[0] == 'blockedtext' ||
744  $error[0] == 'autoblockedtext' ||
745  $error[0] == 'systemblockedtext'
746  )
747  ) {
748  $remove[] = $error;
749  }
750  }
751  $permErrors = wfArrayDiff2( $permErrors, $remove );
752 
753  return $permErrors;
754  }
755 
768  protected function displayPermissionsError( array $permErrors ) {
769  $out = $this->context->getOutput();
770  if ( $this->context->getRequest()->getBool( 'redlink' ) ) {
771  // The edit page was reached via a red link.
772  // Redirect to the article page and let them click the edit tab if
773  // they really want a permission error.
774  $out->redirect( $this->mTitle->getFullURL() );
775  return;
776  }
777 
778  $content = $this->getContentObject();
779 
780  // Use the normal message if there's nothing to display
781  // We used to only do this if $this->firsttime was truthy, and there was no content
782  // or the content was empty, but sometimes there was no content even if it not the
783  // first time, we can't use displayViewSourcePage if there is no content (T281400)
784  if ( !$content || ( $this->firsttime && $content->isEmpty() ) ) {
785  $action = $this->mTitle->exists() ? 'edit' :
786  ( $this->mTitle->isTalkPage() ? 'createtalk' : 'createpage' );
787  throw new PermissionsError( $action, $permErrors );
788  }
789 
790  $this->displayViewSourcePage(
791  $content,
792  $out->formatPermissionsErrorMessage( $permErrors, 'edit' )
793  );
794  }
795 
801  protected function displayViewSourcePage( Content $content, $errorMessage = '' ) {
802  $out = $this->context->getOutput();
803  $this->getHookRunner()->onEditPage__showReadOnlyForm_initial( $this, $out );
804 
805  $out->setRobotPolicy( 'noindex,nofollow' );
806  $out->setPageTitle( $this->context->msg(
807  'viewsource-title',
808  $this->getContextTitle()->getPrefixedText()
809  ) );
810  $out->addBacklinkSubtitle( $this->getContextTitle() );
811  $out->addHTML( $this->editFormPageTop );
812  $out->addHTML( $this->editFormTextTop );
813 
814  if ( $errorMessage !== '' ) {
815  $out->addWikiTextAsInterface( $errorMessage );
816  $out->addHTML( "<hr />\n" );
817  }
818 
819  # If the user made changes, preserve them when showing the markup
820  # (This happens when a user is blocked during edit, for instance)
821  if ( !$this->firsttime ) {
822  $text = $this->textbox1;
823  $out->addWikiMsg( 'viewyourtext' );
824  } else {
825  try {
826  $text = $this->toEditText( $content );
827  } catch ( MWException $e ) {
828  # Serialize using the default format if the content model is not supported
829  # (e.g. for an old revision with a different model)
830  $text = $content->serialize();
831  }
832  $out->addWikiMsg( 'viewsourcetext' );
833  }
834 
835  $out->addHTML( $this->editFormTextBeforeContent );
836  $this->showTextbox( $text, 'wpTextbox1', [ 'readonly' ] );
837  $out->addHTML( $this->editFormTextAfterContent );
838 
839  $out->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) );
840 
841  $out->addModules( 'mediawiki.action.edit.collapsibleFooter' );
842 
843  $out->addHTML( $this->editFormTextBottom );
844  if ( $this->mTitle->exists() ) {
845  $out->returnToMain( null, $this->mTitle );
846  }
847  }
848 
854  protected function previewOnOpen() {
855  $config = $this->context->getConfig();
856  $previewOnOpenNamespaces = $config->get( 'PreviewOnOpenNamespaces' );
857  $request = $this->context->getRequest();
858  if ( $config->get( 'RawHtml' ) ) {
859  // If raw HTML is enabled, disable preview on open
860  // since it has to be posted with a token for
861  // security reasons
862  return false;
863  }
864  if ( $request->getVal( 'preview' ) == 'yes' ) {
865  // Explicit override from request
866  return true;
867  } elseif ( $request->getVal( 'preview' ) == 'no' ) {
868  // Explicit override from request
869  return false;
870  } elseif ( $this->section == 'new' ) {
871  // Nothing *to* preview for new sections
872  return false;
873  } elseif ( ( $request->getCheck( 'preload' ) || $this->mTitle->exists() )
874  && $this->context->getUser()->getOption( 'previewonfirst' )
875  ) {
876  // Standard preference behavior
877  return true;
878  } elseif ( !$this->mTitle->exists()
879  && isset( $previewOnOpenNamespaces[$this->mTitle->getNamespace()] )
880  && $previewOnOpenNamespaces[$this->mTitle->getNamespace()]
881  ) {
882  // Categories are special
883  return true;
884  } else {
885  return false;
886  }
887  }
888 
895  protected function isWrongCaseUserConfigPage() {
896  if ( $this->mTitle->isUserConfigPage() ) {
897  $name = $this->mTitle->getSkinFromConfigSubpage();
898  $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
899  $skins = array_merge(
900  array_keys( $skinFactory->getInstalledSkins() ),
901  [ 'common' ]
902  );
903  return !in_array( $name, $skins )
904  && in_array( strtolower( $name ), $skins );
905  } else {
906  return false;
907  }
908  }
909 
916  protected function isSectionEditSupported() {
917  $currentRev = $this->page->getRevisionRecord();
918 
919  // $currentRev is null for non-existing pages, use the page default content model.
920  $revContentModel = $currentRev
921  ? $currentRev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel()
922  : $this->page->getContentModel();
923 
924  return (
925  ( $this->mArticle->getRevIdFetched() === $this->page->getLatest() ) &&
926  $this->contentHandlerFactory->getContentHandler( $revContentModel )->supportsSections()
927  );
928  }
929 
935  public function importFormData( &$request ) {
936  # Section edit can come from either the form or a link
937  $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
938 
939  if ( $this->section !== null && $this->section !== '' && !$this->isSectionEditSupported() ) {
940  throw new ErrorPageError( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
941  }
942 
943  $this->isNew = !$this->mTitle->exists() || $this->section == 'new';
944 
945  if ( $request->wasPosted() ) {
946  # These fields need to be checked for encoding.
947  # Also remove trailing whitespace, but don't remove _initial_
948  # whitespace from the text boxes. This may be significant formatting.
949  $this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) );
950  if ( !$request->getCheck( 'wpTextbox2' ) ) {
951  // Skip this if wpTextbox2 has input, it indicates that we came
952  // from a conflict page with raw page text, not a custom form
953  // modified by subclasses
954  $textbox1 = $this->importContentFormData( $request );
955  if ( $textbox1 !== null ) {
956  $this->textbox1 = $textbox1;
957  }
958  }
959 
960  $this->unicodeCheck = $request->getText( 'wpUnicodeCheck' );
961 
962  $this->summary = $request->getText( 'wpSummary' );
963 
964  # If the summary consists of a heading, e.g. '==Foobar==', extract the title from the
965  # header syntax, e.g. 'Foobar'. This is mainly an issue when we are using wpSummary for
966  # section titles.
967  $this->summary = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary );
968 
969  # Treat sectiontitle the same way as summary.
970  # Note that wpSectionTitle is not yet a part of the actual edit form, as wpSummary is
971  # currently doing double duty as both edit summary and section title. Right now this
972  # is just to allow API edits to work around this limitation, but this should be
973  # incorporated into the actual edit form when EditPage is rewritten (T20654, T28312).
974  $this->sectiontitle = $request->getText( 'wpSectionTitle' );
975  $this->sectiontitle = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->sectiontitle );
976 
977  $this->edittime = $request->getVal( 'wpEdittime' );
978  $this->editRevId = $request->getIntOrNull( 'editRevId' );
979  $this->starttime = $request->getVal( 'wpStarttime' );
980 
981  $undidRev = $request->getInt( 'wpUndidRevision' );
982  if ( $undidRev ) {
983  $this->undidRev = $undidRev;
984  }
985  $undoAfter = $request->getInt( 'wpUndoAfter' );
986  if ( $undoAfter ) {
987  $this->undoAfter = $undoAfter;
988  }
989 
990  $this->scrolltop = $request->getIntOrNull( 'wpScrolltop' );
991 
992  if ( $this->textbox1 === '' && !$request->getCheck( 'wpTextbox1' ) ) {
993  // wpTextbox1 field is missing, possibly due to being "too big"
994  // according to some filter rules such as Suhosin's setting for
995  // suhosin.request.max_value_length (d'oh)
996  $this->incompleteForm = true;
997  } else {
998  // If we receive the last parameter of the request, we can fairly
999  // claim the POST request has not been truncated.
1000  $this->incompleteForm = !$request->getVal( 'wpUltimateParam' );
1001  }
1002  if ( $this->incompleteForm ) {
1003  # If the form is incomplete, force to preview.
1004  wfDebug( __METHOD__ . ": Form data appears to be incomplete" );
1005  wfDebug( "POST DATA: " . var_export( $request->getPostValues(), true ) );
1006  $this->preview = true;
1007  } else {
1008  $this->preview = $request->getCheck( 'wpPreview' );
1009  $this->diff = $request->getCheck( 'wpDiff' );
1010 
1011  // Remember whether a save was requested, so we can indicate
1012  // if we forced preview due to session failure.
1013  $this->mTriedSave = !$this->preview;
1014 
1015  if ( $this->tokenOk( $request ) ) {
1016  # Some browsers will not report any submit button
1017  # if the user hits enter in the comment box.
1018  # The unmarked state will be assumed to be a save,
1019  # if the form seems otherwise complete.
1020  wfDebug( __METHOD__ . ": Passed token check." );
1021  } elseif ( $this->diff ) {
1022  # Failed token check, but only requested "Show Changes".
1023  wfDebug( __METHOD__ . ": Failed token check; Show Changes requested." );
1024  } else {
1025  # Page might be a hack attempt posted from
1026  # an external site. Preview instead of saving.
1027  wfDebug( __METHOD__ . ": Failed token check; forcing preview" );
1028  $this->preview = true;
1029  }
1030  }
1031  $this->save = !$this->preview && !$this->diff;
1032  if ( !preg_match( '/^\d{14}$/', $this->edittime ) ) {
1033  $this->edittime = null;
1034  }
1035 
1036  if ( !preg_match( '/^\d{14}$/', $this->starttime ) ) {
1037  $this->starttime = null;
1038  }
1039 
1040  $this->recreate = $request->getCheck( 'wpRecreate' );
1041 
1042  $user = $this->getContext()->getUser();
1043 
1044  $this->minoredit = $request->getCheck( 'wpMinoredit' );
1045  $this->watchthis = $request->getCheck( 'wpWatchthis' );
1046  $expiry = $request->getText( 'wpWatchlistExpiry' );
1047  if ( $this->watchlistExpiryEnabled && $expiry !== '' ) {
1048  // This parsing of the user-posted expiry is done for both preview and saving. This
1049  // is necessary because ApiEditPage uses preview when it saves (yuck!). Note that it
1050  // only works because the unnormalized value is retrieved again below in
1051  // getCheckboxesDefinitionForWatchlist().
1052  $expiry = ExpiryDef::normalizeExpiry( $expiry, TS_ISO_8601 );
1053  if ( $expiry !== false ) {
1054  $this->watchlistExpiry = $expiry;
1055  }
1056  }
1057 
1058  # Don't force edit summaries when a user is editing their own user or talk page
1059  if ( ( $this->mTitle->getNamespace() === NS_USER || $this->mTitle->getNamespace() === NS_USER_TALK )
1060  && $this->mTitle->getText() == $user->getName()
1061  ) {
1062  $this->allowBlankSummary = true;
1063  } else {
1064  $this->allowBlankSummary = $request->getBool( 'wpIgnoreBlankSummary' )
1065  || !$user->getOption( 'forceeditsummary' );
1066  }
1067 
1068  $this->autoSumm = $request->getText( 'wpAutoSummary' );
1069 
1070  $this->allowBlankArticle = $request->getBool( 'wpIgnoreBlankArticle' );
1071  $this->allowSelfRedirect = $request->getBool( 'wpIgnoreSelfRedirect' );
1072 
1073  $changeTags = $request->getVal( 'wpChangeTags' );
1074  if ( $changeTags === null || $changeTags === '' ) {
1075  $this->changeTags = [];
1076  } else {
1077  $this->changeTags = array_filter( array_map( 'trim', explode( ',',
1078  $changeTags ) ) );
1079  }
1080  } else {
1081  # Not a posted form? Start with nothing.
1082  wfDebug( __METHOD__ . ": Not a posted form." );
1083  $this->textbox1 = '';
1084  $this->summary = '';
1085  $this->sectiontitle = '';
1086  $this->edittime = '';
1087  $this->editRevId = null;
1088  $this->starttime = wfTimestampNow();
1089  $this->edit = false;
1090  $this->preview = false;
1091  $this->save = false;
1092  $this->diff = false;
1093  $this->minoredit = false;
1094  // Watch may be overridden by request parameters
1095  $this->watchthis = $request->getBool( 'watchthis', false );
1096  if ( $this->watchlistExpiryEnabled ) {
1097  $this->watchlistExpiry = null;
1098  }
1099  $this->recreate = false;
1100 
1101  // When creating a new section, we can preload a section title by passing it as the
1102  // preloadtitle parameter in the URL (T15100)
1103  if ( $this->section == 'new' && $request->getVal( 'preloadtitle' ) ) {
1104  $this->sectiontitle = $request->getVal( 'preloadtitle' );
1105  // Once wpSummary isn't being use for setting section titles, we should delete this.
1106  $this->summary = $request->getVal( 'preloadtitle' );
1107  } elseif ( $this->section != 'new' && $request->getVal( 'summary' ) !== '' ) {
1108  $this->summary = $request->getText( 'summary' );
1109  if ( $this->summary !== '' ) {
1110  $this->hasPresetSummary = true;
1111  }
1112  }
1113 
1114  if ( $request->getVal( 'minor' ) ) {
1115  $this->minoredit = true;
1116  }
1117  }
1118 
1119  $this->oldid = $request->getInt( 'oldid' );
1120  $this->parentRevId = $request->getInt( 'parentRevId' );
1121 
1122  $this->markAsBot = $request->getBool( 'bot', true );
1123  $this->nosummary = $request->getBool( 'nosummary' );
1124 
1125  // May be overridden by revision.
1126  $this->contentModel = $request->getText( 'model', $this->contentModel );
1127  // May be overridden by revision.
1128  $this->contentFormat = $request->getText( 'format', $this->contentFormat );
1129 
1130  try {
1131  $handler = $this->contentHandlerFactory->getContentHandler( $this->contentModel );
1132  } catch ( MWUnknownContentModelException $e ) {
1133  throw new ErrorPageError(
1134  'editpage-invalidcontentmodel-title',
1135  'editpage-invalidcontentmodel-text',
1136  [ wfEscapeWikiText( $this->contentModel ) ]
1137  );
1138  }
1139 
1140  if ( !$handler->isSupportedFormat( $this->contentFormat ) ) {
1141  throw new ErrorPageError(
1142  'editpage-notsupportedcontentformat-title',
1143  'editpage-notsupportedcontentformat-text',
1144  [
1145  wfEscapeWikiText( $this->contentFormat ),
1146  wfEscapeWikiText( ContentHandler::getLocalizedName( $this->contentModel ) )
1147  ]
1148  );
1149  }
1150 
1157  $this->editintro = $request->getText( 'editintro',
1158  // Custom edit intro for new sections
1159  $this->section === 'new' ? 'MediaWiki:addsection-editintro' : '' );
1160 
1161  // Allow extensions to modify form data
1162  $this->getHookRunner()->onEditPage__importFormData( $this, $request );
1163  }
1164 
1174  protected function importContentFormData( &$request ) {
1175  return null; // Don't do anything, EditPage already extracted wpTextbox1
1176  }
1177 
1183  private function initialiseForm() {
1184  $this->edittime = $this->page->getTimestamp();
1185  $this->editRevId = $this->page->getLatest();
1186 
1187  $dummy = $this->contentHandlerFactory
1188  ->getContentHandler( $this->contentModel )
1189  ->makeEmptyContent();
1190  $content = $this->getContentObject( $dummy ); # TODO: track content object?!
1191  if ( $content === $dummy ) { // Invalid section
1192  $this->noSuchSectionPage();
1193  return false;
1194  }
1195 
1196  if ( !$content ) {
1197  $out = $this->context->getOutput();
1198  $this->editFormPageTop .= Html::rawElement(
1199  'div', [ 'class' => 'errorbox' ],
1200  $out->parseAsInterface( $this->context->msg( 'missing-revision-content',
1201  $this->oldid,
1202  Message::plaintextParam( $this->mTitle->getPrefixedText() )
1203  ) )
1204  );
1205  } elseif ( !$this->isSupportedContentModel( $content->getModel() ) ) {
1206  $modelMsg = $this->getContext()->msg( 'content-model-' . $content->getModel() );
1207  $modelName = $modelMsg->exists() ? $modelMsg->text() : $content->getModel();
1208 
1209  $out = $this->context->getOutput();
1210  $out->showErrorPage(
1211  'modeleditnotsupported-title',
1212  'modeleditnotsupported-text',
1213  [ $modelName ]
1214  );
1215  return false;
1216  }
1217 
1218  $this->textbox1 = $this->toEditText( $content );
1219 
1220  $user = $this->context->getUser();
1221  // activate checkboxes if user wants them to be always active
1222  # Sort out the "watch" checkbox
1223  if ( $user->getOption( 'watchdefault' ) ) {
1224  # Watch all edits
1225  $this->watchthis = true;
1226  } elseif ( $user->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) {
1227  # Watch creations
1228  $this->watchthis = true;
1229  } elseif ( $this->watchlistManager->isWatched( $user, $this->mTitle ) ) {
1230  # Already watched
1231  $this->watchthis = true;
1232  }
1233  if ( $this->watchthis && $this->watchlistExpiryEnabled ) {
1234  $watchedItem = $this->watchedItemStore->getWatchedItem( $user, $this->getTitle() );
1235  $this->watchlistExpiry = $watchedItem ? $watchedItem->getExpiry() : null;
1236  }
1237  if ( $user->getOption( 'minordefault' ) && !$this->isNew ) {
1238  $this->minoredit = true;
1239  }
1240  if ( $this->textbox1 === false ) {
1241  return false;
1242  }
1243  return true;
1244  }
1245 
1253  protected function getContentObject( $def_content = null ) {
1254  global $wgDisableAnonTalk;
1255 
1256  $content = false;
1257 
1258  $user = $this->context->getUser();
1259  $request = $this->context->getRequest();
1260  // For message page not locally set, use the i18n message.
1261  // For other non-existent articles, use preload text if any.
1262  if ( !$this->mTitle->exists() || $this->section == 'new' ) {
1263  if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI && $this->section != 'new' ) {
1264  # If this is a system message, get the default text.
1265  $msg = $this->mTitle->getDefaultMessageText();
1266 
1267  $content = $this->toEditContent( $msg );
1268  }
1269  if ( $content === false ) {
1270  # If requested, preload some text.
1271  $preload = $request->getVal( 'preload',
1272  // Custom preload text for new sections
1273  $this->section === 'new' ? 'MediaWiki:addsection-preload' : '' );
1274  $params = $request->getArray( 'preloadparams', [] );
1275 
1276  $content = $this->getPreloadedContent( $preload, $params );
1277  }
1278  // For existing pages, get text based on "undo" or section parameters.
1279  } elseif ( $this->section != '' ) {
1280  // Get section edit text (returns $def_text for invalid sections)
1281  $orig = $this->getOriginalContent( $user );
1282  $content = $orig ? $orig->getSection( $this->section ) : null;
1283 
1284  if ( !$content ) {
1285  $content = $def_content;
1286  }
1287  } else {
1288  $undoafter = $request->getInt( 'undoafter' );
1289  $undo = $request->getInt( 'undo' );
1290 
1291  if ( $undo > 0 && $undoafter > 0 ) {
1292  $undorev = $this->revisionStore->getRevisionById( $undo );
1293  $oldrev = $this->revisionStore->getRevisionById( $undoafter );
1294  $undoMsg = null;
1295 
1296  # Sanity check, make sure it's the right page,
1297  # the revisions exist and they were not deleted.
1298  # Otherwise, $content will be left as-is.
1299  if ( $undorev !== null && $oldrev !== null &&
1300  !$undorev->isDeleted( RevisionRecord::DELETED_TEXT ) &&
1301  !$oldrev->isDeleted( RevisionRecord::DELETED_TEXT )
1302  ) {
1303  if ( WikiPage::hasDifferencesOutsideMainSlot( $undorev, $oldrev )
1304  || !$this->isSupportedContentModel(
1305  $oldrev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel()
1306  )
1307  ) {
1308  // Hack for undo while EditPage can't handle multi-slot editing
1309  $this->context->getOutput()->redirect( $this->mTitle->getFullURL( [
1310  'action' => 'mcrundo',
1311  'undo' => $undo,
1312  'undoafter' => $undoafter,
1313  ] ) );
1314  return false;
1315  } else {
1316  $content = $this->getUndoContent( $undorev, $oldrev );
1317 
1318  if ( $content === false ) {
1319  # Warn the user that something went wrong
1320  $undoMsg = 'failure';
1321  }
1322  }
1323 
1324  if ( $undoMsg === null ) {
1325  $oldContent = $this->page->getContent( RevisionRecord::RAW );
1326  $services = MediaWikiServices::getInstance();
1327  $popts = ParserOptions::newFromUserAndLang( $user, $services->getContentLanguage() );
1328  $contentTransformer = $services->getContentTransformer();
1329  $newContent = $contentTransformer->preSaveTransform( $content, $this->mTitle, $user, $popts );
1330 
1331  if ( $newContent->getModel() !== $oldContent->getModel() ) {
1332  // The undo may change content
1333  // model if its reverting the top
1334  // edit. This can result in
1335  // mismatched content model/format.
1336  $this->contentModel = $newContent->getModel();
1337  $oldMainSlot = $oldrev->getSlot(
1338  SlotRecord::MAIN,
1339  RevisionRecord::RAW
1340  );
1341  $this->contentFormat = $oldMainSlot->getFormat();
1342  if ( $this->contentFormat === null ) {
1343  $this->contentFormat = $this->contentHandlerFactory
1344  ->getContentHandler( $oldMainSlot->getModel() )
1345  ->getDefaultFormat();
1346  }
1347  }
1348 
1349  if ( $newContent->equals( $oldContent ) ) {
1350  # Tell the user that the undo results in no change,
1351  # i.e. the revisions were already undone.
1352  $undoMsg = 'nochange';
1353  $content = false;
1354  } else {
1355  # Inform the user of our success and set an automatic edit summary
1356  $undoMsg = 'success';
1357 
1358  # If we just undid one rev, use an autosummary
1359  $firstrev = $this->revisionStore->getNextRevision( $oldrev );
1360  if ( $firstrev && $firstrev->getId() == $undo ) {
1361  $userText = $undorev->getUser() ?
1362  $undorev->getUser()->getName() :
1363  '';
1364  if ( $userText === '' ) {
1365  $undoSummary = $this->context->msg(
1366  'undo-summary-username-hidden',
1367  $undo
1368  )->inContentLanguage()->text();
1369  // Handle external users (imported revisions)
1370  } elseif ( ExternalUserNames::isExternal( $userText ) ) {
1371  $userLinkTitle = ExternalUserNames::getUserLinkTitle( $userText );
1372  if ( $userLinkTitle ) {
1373  $userLink = $userLinkTitle->getPrefixedText();
1374  $undoSummary = $this->context->msg(
1375  'undo-summary-import',
1376  $undo,
1377  $userLink,
1378  $userText
1379  )->inContentLanguage()->text();
1380  } else {
1381  $undoSummary = $this->context->msg(
1382  'undo-summary-import2',
1383  $undo,
1384  $userText
1385  )->inContentLanguage()->text();
1386  }
1387  } else {
1388  $undoIsAnon = $undorev->getUser() ?
1389  !$undorev->getUser()->isRegistered() :
1390  true;
1391  $undoMessage = ( $undoIsAnon && $wgDisableAnonTalk ) ?
1392  'undo-summary-anon' :
1393  'undo-summary';
1394  $undoSummary = $this->context->msg(
1395  $undoMessage,
1396  $undo,
1397  $userText
1398  )->inContentLanguage()->text();
1399  }
1400  if ( $this->summary === '' ) {
1401  $this->summary = $undoSummary;
1402  } else {
1403  $this->summary = $undoSummary . $this->context->msg( 'colon-separator' )
1404  ->inContentLanguage()->text() . $this->summary;
1405  }
1406  }
1407  $this->undidRev = $undo;
1408  $this->undoAfter = $undoafter;
1409  $this->formtype = 'diff';
1410  }
1411  }
1412  } else {
1413  // Failed basic sanity checks.
1414  // Older revisions may have been removed since the link
1415  // was created, or we may simply have got bogus input.
1416  $undoMsg = 'norev';
1417  }
1418 
1419  $out = $this->context->getOutput();
1420  // Messages: undo-success, undo-failure, undo-main-slot-only, undo-norev,
1421  // undo-nochange.
1422  $class = ( $undoMsg == 'success' ? '' : 'error ' ) . "mw-undo-{$undoMsg}";
1423  $this->editFormPageTop .= Html::rawElement(
1424  'div', [ 'class' => $class ],
1425  $out->parseAsInterface(
1426  $this->context->msg( 'undo-' . $undoMsg )->plain()
1427  )
1428  );
1429  }
1430 
1431  if ( $content === false ) {
1432  $content = $this->getOriginalContent( $user );
1433  }
1434  }
1435 
1436  return $content;
1437  }
1438 
1449  private function getUndoContent( RevisionRecord $undoRev, RevisionRecord $oldRev ) {
1450  $handler = $this->contentHandlerFactory
1451  ->getContentHandler( $undoRev->getSlot(
1452  SlotRecord::MAIN,
1453  RevisionRecord::RAW
1454  )->getModel() );
1455  $currentContent = $this->page->getRevisionRecord()
1456  ->getContent( SlotRecord::MAIN );
1457  $undoContent = $undoRev->getContent( SlotRecord::MAIN );
1458  $undoAfterContent = $oldRev->getContent( SlotRecord::MAIN );
1459  $undoIsLatest = $this->page->getRevisionRecord()->getId() === $undoRev->getId();
1460 
1461  return $handler->getUndoContent(
1462  $currentContent,
1463  $undoContent,
1464  $undoAfterContent,
1465  $undoIsLatest
1466  );
1467  }
1468 
1484  private function getOriginalContent( Authority $performer ) {
1485  if ( $this->section == 'new' ) {
1486  return $this->getCurrentContent();
1487  }
1488  $revRecord = $this->mArticle->fetchRevisionRecord();
1489  if ( $revRecord === null ) {
1490  return $this->contentHandlerFactory
1491  ->getContentHandler( $this->contentModel )
1492  ->makeEmptyContent();
1493  }
1494  return $revRecord->getContent( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $performer );
1495  }
1496 
1509  public function getParentRevId() {
1510  if ( $this->parentRevId ) {
1511  return $this->parentRevId;
1512  } else {
1513  return $this->mArticle->getRevIdFetched();
1514  }
1515  }
1516 
1525  protected function getCurrentContent() {
1526  $revRecord = $this->page->getRevisionRecord();
1527  $content = $revRecord ? $revRecord->getContent(
1528  SlotRecord::MAIN,
1529  RevisionRecord::RAW
1530  ) : null;
1531 
1532  if ( $content === null ) {
1533  return $this->contentHandlerFactory
1534  ->getContentHandler( $this->contentModel )
1535  ->makeEmptyContent();
1536  }
1537 
1538  return $content;
1539  }
1540 
1552  protected function getPreloadedContent( $preload, $params = [] ) {
1553  if ( !empty( $this->mPreloadContent ) ) {
1554  return $this->mPreloadContent;
1555  }
1556 
1557  $handler = $this->contentHandlerFactory->getContentHandler( $this->contentModel );
1558 
1559  if ( $preload === '' ) {
1560  return $handler->makeEmptyContent();
1561  }
1562 
1563  $user = $this->context->getUser();
1564  $title = Title::newFromText( $preload );
1565 
1566  # Check for existence to avoid getting MediaWiki:Noarticletext
1567  if ( !$this->isPageExistingAndViewable( $title, $this->getContext()->getAuthority() ) ) {
1568  // TODO: somehow show a warning to the user!
1569  return $handler->makeEmptyContent();
1570  }
1571 
1572  $page = $this->wikiPageFactory->newFromTitle( $title );
1573  if ( $page->isRedirect() ) {
1575  # Same as before
1576  if ( !$this->isPageExistingAndViewable( $title, $this->getContext()->getAuthority() ) ) {
1577  // TODO: somehow show a warning to the user!
1578  return $handler->makeEmptyContent();
1579  }
1580  $page = $this->wikiPageFactory->newFromTitle( $title );
1581  }
1582 
1583  $parserOptions = ParserOptions::newFromUser( $user );
1584  $content = $page->getContent( RevisionRecord::RAW );
1585 
1586  if ( !$content ) {
1587  // TODO: somehow show a warning to the user!
1588  return $handler->makeEmptyContent();
1589  }
1590 
1591  if ( $content->getModel() !== $handler->getModelID() ) {
1592  $converted = $content->convert( $handler->getModelID() );
1593 
1594  if ( !$converted ) {
1595  // TODO: somehow show a warning to the user!
1596  wfDebug( "Attempt to preload incompatible content: " .
1597  "can't convert " . $content->getModel() .
1598  " to " . $handler->getModelID() );
1599 
1600  return $handler->makeEmptyContent();
1601  }
1602 
1603  $content = $converted;
1604  }
1605 
1606  $contentTransformer = MediaWikiServices::getInstance()->getContentTransformer();
1607  return $contentTransformer->preloadTransform(
1608  $content,
1609  $title,
1610  $parserOptions,
1611  $params
1612  );
1613  }
1614 
1624  private function isPageExistingAndViewable( ?PageIdentity $page, Authority $performer ) {
1625  return $page && $page->exists() && $performer->authorizeRead( 'read', $page );
1626  }
1627 
1635  public function tokenOk( &$request ) {
1636  $token = $request->getVal( 'wpEditToken' );
1637  $user = $this->context->getUser();
1638  $this->mTokenOk = $user->matchEditToken( $token );
1639  return $this->mTokenOk;
1640  }
1641 
1656  protected function setPostEditCookie( $statusValue ) {
1657  $revisionId = $this->page->getLatest();
1658  $postEditKey = self::POST_EDIT_COOKIE_KEY_PREFIX . $revisionId;
1659 
1660  $val = 'saved';
1661  if ( $statusValue == self::AS_SUCCESS_NEW_ARTICLE ) {
1662  $val = 'created';
1663  } elseif ( $this->oldid ) {
1664  $val = 'restored';
1665  }
1666 
1667  $response = $this->context->getRequest()->response();
1668  $response->setCookie( $postEditKey, $val, time() + self::POST_EDIT_COOKIE_DURATION );
1669  }
1670 
1677  public function attemptSave( &$resultDetails = false ) {
1678  // Allow bots to exempt some edits from bot flagging
1679  $markAsBot = $this->markAsBot
1680  && $this->context->getAuthority()->isAllowed( 'bot' );
1681 
1682  // Allow trusted users to mark some edits as minor
1683  $markAsMinor = $this->minoredit && !$this->isNew
1684  && $this->context->getAuthority()->isAllowed( 'minoredit' );
1685 
1686  $status = $this->internalAttemptSave( $resultDetails, $markAsBot, $markAsMinor );
1687 
1688  $this->getHookRunner()->onEditPage__attemptSave_after( $this, $status, $resultDetails );
1689 
1690  return $status;
1691  }
1692 
1696  private function incrementResolvedConflicts() {
1697  if ( $this->context->getRequest()->getText( 'mode' ) !== 'conflict' ) {
1698  return;
1699  }
1700 
1701  $this->getEditConflictHelper()->incrementResolvedStats( $this->context->getUser() );
1702  }
1703 
1713  private function handleStatus( Status $status, $resultDetails ) {
1714  $statusValue = is_int( $status->value ) ? $status->value : 0;
1715 
1720  if ( $statusValue == self::AS_SUCCESS_UPDATE
1721  || $statusValue == self::AS_SUCCESS_NEW_ARTICLE
1722  ) {
1723  $this->incrementResolvedConflicts();
1724 
1725  $this->didSave = true;
1726  if ( !$resultDetails['nullEdit'] ) {
1727  $this->setPostEditCookie( $statusValue );
1728  }
1729  }
1730 
1731  $out = $this->context->getOutput();
1732 
1733  // "wpExtraQueryRedirect" is a hidden input to modify
1734  // after save URL and is not used by actual edit form
1735  $request = $this->context->getRequest();
1736  $extraQueryRedirect = $request->getVal( 'wpExtraQueryRedirect' );
1737 
1738  switch ( $statusValue ) {
1746  case self::AS_END:
1749  return true;
1750 
1751  case self::AS_HOOK_ERROR:
1752  return false;
1753 
1755  wfDeprecated(
1756  __METHOD__ . ' with $statusValue == AS_CANNOT_USE_CUSTOM_MODEL',
1757  '1.35'
1758  );
1759  // ...and fall through to next case
1760  case self::AS_PARSE_ERROR:
1762  $out->wrapWikiTextAsInterface( 'error',
1763  $status->getWikiText( false, false, $this->context->getLanguage() )
1764  );
1765  return true;
1766 
1768  $query = $resultDetails['redirect'] ? 'redirect=no' : '';
1769  if ( $extraQueryRedirect ) {
1770  if ( $query !== '' ) {
1771  $query .= '&';
1772  }
1773  $query .= $extraQueryRedirect;
1774  }
1775  $anchor = $resultDetails['sectionanchor'] ?? '';
1776  $out->redirect( $this->mTitle->getFullURL( $query ) . $anchor );
1777  return false;
1778 
1780  $extraQuery = '';
1781  $sectionanchor = $resultDetails['sectionanchor'];
1782 
1783  // Give extensions a chance to modify URL query on update
1784  $this->getHookRunner()->onArticleUpdateBeforeRedirect( $this->mArticle,
1785  $sectionanchor, $extraQuery );
1786 
1787  if ( $resultDetails['redirect'] ) {
1788  if ( $extraQuery !== '' ) {
1789  $extraQuery = '&' . $extraQuery;
1790  }
1791  $extraQuery = 'redirect=no' . $extraQuery;
1792  }
1793  if ( $extraQueryRedirect ) {
1794  if ( $extraQuery !== '' ) {
1795  $extraQuery .= '&';
1796  }
1797  $extraQuery .= $extraQueryRedirect;
1798  }
1799 
1800  $out->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor );
1801  return false;
1802 
1803  case self::AS_SPAM_ERROR:
1804  $this->spamPageWithContent( $resultDetails['spam'] ?? false );
1805  return false;
1806 
1808  throw new UserBlockedError(
1809  $this->context->getUser()->getBlock(),
1810  $this->context->getUser(),
1811  $this->context->getLanguage(),
1812  $request->getIP()
1813  );
1814 
1817  throw new PermissionsError( 'upload' );
1818 
1821  throw new PermissionsError( 'edit' );
1822 
1824  throw new ReadOnlyError;
1825 
1826  case self::AS_RATE_LIMITED:
1827  throw new ThrottledError();
1828 
1830  $permission = $this->mTitle->isTalkPage() ? 'createtalk' : 'createpage';
1831  throw new PermissionsError( $permission );
1832 
1834  throw new PermissionsError( 'editcontentmodel' );
1835 
1836  default:
1837  // We don't recognize $statusValue. The only way that can happen
1838  // is if an extension hook aborted from inside ArticleSave.
1839  // Render the status object into $this->hookError
1840  // FIXME this sucks, we should just use the Status object throughout
1841  $this->hookError = Html::errorBox(
1842  "\n" . $status->getWikiText( false, false, $this->context->getLanguage() )
1843  );
1844  return true;
1845  }
1846  }
1847 
1853  private function newSectionSummary(): array {
1854  $newSectionSummary = $this->summary;
1855  $newSectionAnchor = '';
1856  $services = MediaWikiServices::getInstance();
1857  $parser = $services->getParser();
1858  $textFormatter = $services->getMessageFormatterFactory()->getTextFormatter(
1859  $services->getContentLanguage()->getCode()
1860  );
1861 
1862  if ( $this->sectiontitle !== '' ) {
1863  $newSectionAnchor = $this->guessSectionName( $this->sectiontitle );
1864  // If no edit summary was specified, create one automatically from the section
1865  // title and have it link to the new section. Otherwise, respect the summary as
1866  // passed.
1867  if ( $this->summary === '' ) {
1868  $messageValue = MessageValue::new( 'newsectionsummary' )
1869  ->plaintextParams( $parser->stripSectionName( $this->sectiontitle ) );
1870  $newSectionSummary = $textFormatter->format( $messageValue );
1871  }
1872  } elseif ( $this->summary !== '' ) {
1873  $newSectionAnchor = $this->guessSectionName( $this->summary );
1874  // This is a new section, so create a link to the new section
1875  // in the revision summary.
1876  $messageValue = MessageValue::new( 'newsectionsummary' )
1877  ->plaintextParams( $parser->stripSectionName( $this->summary ) );
1878  $newSectionSummary = $textFormatter->format( $messageValue );
1879  }
1880  return [ $newSectionSummary, $newSectionAnchor ];
1881  }
1882 
1909  public function internalAttemptSave( &$result, $markAsBot = false, $markAsMinor = false ) {
1911 
1912  if ( !$this->getHookRunner()->onEditPage__attemptSave( $this ) ) {
1913  wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" );
1914  $status = Status::newFatal( 'hookaborted' );
1915  $status->value = self::AS_HOOK_ERROR;
1916  return $status;
1917  }
1918 
1919  if ( !$this->getHookRunner()->onEditFilter( $this, $this->textbox1, $this->section,
1920  $this->hookError, $this->summary )
1921  ) {
1922  # Error messages etc. could be handled within the hook...
1923  $status = Status::newFatal( 'hookaborted' );
1924  $status->value = self::AS_HOOK_ERROR;
1925  return $status;
1926  } elseif ( $this->hookError != '' ) {
1927  # ...or the hook could be expecting us to produce an error
1928  $status = Status::newFatal( 'hookaborted' );
1929  $status->value = self::AS_HOOK_ERROR_EXPECTED;
1930  return $status;
1931  }
1932 
1933  try {
1934  # Construct Content object
1935  $textbox_content = $this->toEditContent( $this->textbox1 );
1936  } catch ( MWContentSerializationException $ex ) {
1937  $status = Status::newFatal(
1938  'content-failed-to-parse',
1939  $this->contentModel,
1940  $this->contentFormat,
1941  $ex->getMessage()
1942  );
1943  $status->value = self::AS_PARSE_ERROR;
1944  return $status;
1945  }
1946 
1947  $this->contentLength = strlen( $this->textbox1 );
1948  $user = $this->context->getUser();
1949 
1950  $changingContentModel = false;
1951  if ( $this->contentModel !== $this->mTitle->getContentModel() ) {
1952  $changingContentModel = true;
1953  $oldContentModel = $this->mTitle->getContentModel();
1954  }
1955 
1956  // BEGINNING OF MIGRATION TO EDITCONSTRAINT SYSTEM (see T157658)
1957  $constraintFactory = MediaWikiServices::getInstance()->getService( '_EditConstraintFactory' );
1958  $constraintRunner = new EditConstraintRunner();
1959 
1960  // UnicodeConstraint: ensure that `$this->unicodeCheck` is the correct unicode
1961  $constraintRunner->addConstraint(
1962  new UnicodeConstraint( $this->unicodeCheck )
1963  );
1964 
1965  // SimpleAntiSpamConstraint: ensure that the context request does not have
1966  // `wpAntispam` set
1967  $constraintRunner->addConstraint(
1968  $constraintFactory->newSimpleAntiSpamConstraint(
1969  $this->context->getRequest()->getText( 'wpAntispam' ),
1970  $user,
1971  $this->mTitle
1972  )
1973  );
1974 
1975  // SpamRegexConstraint: ensure that the summary and text don't match the spam regex
1976  // FIXME $this->section is documented to always be a string, but it can be null
1977  // since importFormData does not provide a default when getting the section from
1978  // WebRequest, and the default default is null.
1979  $constraintRunner->addConstraint(
1980  $constraintFactory->newSpamRegexConstraint(
1981  $this->summary,
1982  $this->section ?? '',
1983  $this->sectiontitle,
1984  $this->textbox1,
1985  $this->context->getRequest()->getIP(),
1986  $this->mTitle
1987  )
1988  );
1989  $constraintRunner->addConstraint(
1990  new EditRightConstraint( $user )
1991  );
1992  $constraintRunner->addConstraint(
1994  $textbox_content,
1995  $this->mTitle,
1996  $user
1997  )
1998  );
1999  $constraintRunner->addConstraint(
2000  $constraintFactory->newUserBlockConstraint( $this->mTitle, $user )
2001  );
2002  $constraintRunner->addConstraint(
2004  $user,
2005  $this->mTitle,
2006  $this->contentModel
2007  )
2008  );
2009 
2010  $constraintRunner->addConstraint(
2011  $constraintFactory->newReadOnlyConstraint()
2012  );
2013  $constraintRunner->addConstraint(
2014  new UserRateLimitConstraint( $user, $this->mTitle, $this->contentModel )
2015  );
2016  $constraintRunner->addConstraint(
2017  // Same constraint is used to check size before and after merging the
2018  // edits, which use different failure codes
2019  $constraintFactory->newPageSizeConstraint(
2020  $this->contentLength,
2021  PageSizeConstraint::BEFORE_MERGE
2022  )
2023  );
2024  $constraintRunner->addConstraint(
2025  new ChangeTagsConstraint( $user, $this->changeTags )
2026  );
2027 
2028  // If the article has been deleted while editing, don't save it without
2029  // confirmation
2030  $constraintRunner->addConstraint(
2032  $this->wasDeletedSinceLastEdit(),
2033  $this->recreate
2034  )
2035  );
2036 
2037  // Check the constraints
2038  if ( !$constraintRunner->checkConstraints() ) {
2039  $failed = $constraintRunner->getFailedConstraint();
2040 
2041  // Need to check SpamRegexConstraint here, to avoid needing to pass
2042  // $result by reference again
2043  if ( $failed instanceof SpamRegexConstraint ) {
2044  $result['spam'] = $failed->getMatch();
2045  } else {
2046  $this->handleFailedConstraint( $failed );
2047  }
2048 
2049  return Status::wrap( $failed->getLegacyStatus() );
2050  }
2051  // END OF MIGRATION TO EDITCONSTRAINT SYSTEM (continued below)
2052 
2053  # Load the page data from the primary DB. If anything changes in the meantime,
2054  # we detect it by using page_latest like a token in a 1 try compare-and-swap.
2055  $this->page->loadPageData( WikiPage::READ_LATEST );
2056  $new = !$this->page->exists();
2057 
2058  $flags = EDIT_AUTOSUMMARY |
2059  ( $new ? EDIT_NEW : EDIT_UPDATE ) |
2060  ( $markAsMinor ? EDIT_MINOR : 0 ) |
2061  ( $markAsBot ? EDIT_FORCE_BOT : 0 );
2062 
2063  if ( $new ) {
2064  $content = $textbox_content;
2065 
2066  $result['sectionanchor'] = '';
2067  if ( $this->section == 'new' ) {
2068  if ( $this->sectiontitle !== '' ) {
2069  // Insert the section title above the content.
2070  $content = $content->addSectionHeader( $this->sectiontitle );
2071  } elseif ( $this->summary !== '' ) {
2072  // Insert the section title above the content.
2073  $content = $content->addSectionHeader( $this->summary );
2074  }
2075 
2076  list( $newSectionSummary, $anchor ) = $this->newSectionSummary();
2077  $this->summary = $newSectionSummary;
2078  $result['sectionanchor'] = $anchor;
2079  }
2080 
2081  $pageUpdater = $this->page->newPageUpdater( $user )
2082  ->setContent( SlotRecord::MAIN, $content );
2083  $pageUpdater->prepareUpdate( $flags );
2084 
2085  // BEGINNING OF MIGRATION TO EDITCONSTRAINT SYSTEM (see T157658)
2086  // Create a new runner to avoid rechecking the prior constraints, use the same factory
2087  $constraintRunner = new EditConstraintRunner();
2088  // Late check for create permission, just in case *PARANOIA*
2089  $constraintRunner->addConstraint(
2090  new CreationPermissionConstraint( $user, $this->mTitle )
2091  );
2092 
2093  // Don't save a new page if it's blank or if it's a MediaWiki:
2094  // message with content equivalent to default (allow empty pages
2095  // in this case to disable messages, see T52124)
2096  $constraintRunner->addConstraint(
2098  $this->mTitle,
2099  $this->allowBlankArticle,
2100  $this->textbox1
2101  )
2102  );
2103 
2104  $constraintRunner->addConstraint(
2105  $constraintFactory->newEditFilterMergedContentHookConstraint(
2106  $content,
2107  $this->context,
2108  $this->summary,
2109  $markAsMinor
2110  )
2111  );
2112 
2113  // Check the constraints
2114  if ( !$constraintRunner->checkConstraints() ) {
2115  $failed = $constraintRunner->getFailedConstraint();
2116  $this->handleFailedConstraint( $failed );
2117  return Status::wrap( $failed->getLegacyStatus() );
2118  }
2119  // END OF MIGRATION TO EDITCONSTRAINT SYSTEM (continued below)
2120  } else { # not $new
2121 
2122  # Article exists. Check for edit conflict.
2123 
2124  $timestamp = $this->page->getTimestamp();
2125  $latest = $this->page->getLatest();
2126 
2127  wfDebug( "timestamp: {$timestamp}, edittime: {$this->edittime}" );
2128  wfDebug( "revision: {$latest}, editRevId: {$this->editRevId}" );
2129 
2130  $editConflictLogger = LoggerFactory::getInstance( 'EditConflict' );
2131  // An edit conflict is detected if the current revision is different from the
2132  // revision that was current when editing was initiated on the client.
2133  // This is checked based on the timestamp and revision ID.
2134  // TODO: the timestamp based check can probably go away now.
2135  if ( ( $this->edittime !== null && $this->edittime != $timestamp )
2136  || ( $this->editRevId !== null && $this->editRevId != $latest )
2137  ) {
2138  $this->isConflict = true;
2139  list( $newSectionSummary, $newSectionAnchor ) = $this->newSectionSummary();
2140  if ( $this->section == 'new' ) {
2141  if ( $this->page->getUserText() == $user->getName() &&
2142  $this->page->getComment() == $newSectionSummary
2143  ) {
2144  // Probably a duplicate submission of a new comment.
2145  // This can happen when CDN resends a request after
2146  // a timeout but the first one actually went through.
2147  $editConflictLogger->debug(
2148  'Duplicate new section submission; trigger edit conflict!'
2149  );
2150  } else {
2151  // New comment; suppress conflict.
2152  $this->isConflict = false;
2153  $editConflictLogger->debug( 'Conflict suppressed; new section' );
2154  }
2155  } elseif ( $this->section == ''
2156  && $this->edittime
2157  && $this->revisionStore->userWasLastToEdit(
2158  wfGetDB( DB_PRIMARY ),
2159  $this->mTitle->getArticleID(),
2160  $user->getId(),
2161  $this->edittime
2162  )
2163  ) {
2164  # Suppress edit conflict with self, except for section edits where merging is required.
2165  $editConflictLogger->debug( 'Suppressing edit conflict, same user.' );
2166  $this->isConflict = false;
2167  }
2168  }
2169 
2170  // If sectiontitle is set, use it, otherwise use the summary as the section title.
2171  if ( $this->sectiontitle !== '' ) {
2172  $sectionTitle = $this->sectiontitle;
2173  } else {
2174  $sectionTitle = $this->summary;
2175  }
2176 
2177  $content = null;
2178 
2179  if ( $this->isConflict ) {
2180  $editConflictLogger->debug(
2181  'Conflict! Getting section {section} for time {editTime}'
2182  . ' (id {editRevId}, article time {timestamp})',
2183  [
2184  'section' => $this->section,
2185  'editTime' => $this->edittime,
2186  'editRevId' => $this->editRevId,
2187  'timestamp' => $timestamp,
2188  ]
2189  );
2190  // @TODO: replaceSectionAtRev() with base ID (not prior current) for ?oldid=X case
2191  // ...or disable section editing for non-current revisions (not exposed anyway).
2192  if ( $this->editRevId !== null ) {
2193  $content = $this->page->replaceSectionAtRev(
2194  $this->section,
2195  $textbox_content,
2196  $sectionTitle,
2197  $this->editRevId
2198  );
2199  } else {
2200  $content = $this->page->replaceSectionContent(
2201  $this->section,
2202  $textbox_content,
2203  $sectionTitle,
2204  $this->edittime
2205  );
2206  }
2207  } else {
2208  $editConflictLogger->debug(
2209  'Getting section {section}',
2210  [ 'section' => $this->section ]
2211  );
2212  $content = $this->page->replaceSectionContent(
2213  $this->section,
2214  $textbox_content,
2215  $sectionTitle
2216  );
2217  }
2218 
2219  if ( $content === null ) {
2220  $editConflictLogger->debug( 'Activating conflict; section replace failed.' );
2221  $this->isConflict = true;
2222  $content = $textbox_content; // do not try to merge here!
2223  } elseif ( $this->isConflict ) {
2224  // Attempt merge
2225  $mergedChange = $this->mergeChangesIntoContent( $content );
2226  if ( $mergedChange !== false ) {
2227  // Successful merge! Maybe we should tell the user the good news?
2228  $content = $mergedChange[0];
2229  $this->parentRevId = $mergedChange[1];
2230  $this->isConflict = false;
2231  $editConflictLogger->debug( 'Suppressing edit conflict, successful merge.' );
2232  } else {
2233  $this->section = '';
2234  $this->textbox1 = ( $content instanceof TextContent ) ? $content->getText() : '';
2235  $editConflictLogger->debug( 'Keeping edit conflict, failed merge.' );
2236  }
2237  }
2238 
2239  if ( $this->isConflict ) {
2240  return Status::newGood( self::AS_CONFLICT_DETECTED )->setOK( false );
2241  }
2242 
2243  $pageUpdater = $this->page->newPageUpdater( $user )
2244  ->setContent( SlotRecord::MAIN, $content );
2245  $pageUpdater->prepareUpdate( $flags );
2246 
2247  // BEGINNING OF MIGRATION TO EDITCONSTRAINT SYSTEM (see T157658)
2248  // Create a new runner to avoid rechecking the prior constraints, use the same factory
2249  $constraintRunner = new EditConstraintRunner();
2250  $constraintRunner->addConstraint(
2251  $constraintFactory->newEditFilterMergedContentHookConstraint(
2252  $content,
2253  $this->context,
2254  $this->summary,
2255  $markAsMinor
2256  )
2257  );
2258 
2259  if ( $this->section == 'new' ) {
2260  $constraintRunner->addConstraint(
2262  $this->summary,
2263  $this->allowBlankSummary
2264  )
2265  );
2266  $constraintRunner->addConstraint(
2267  new MissingCommentConstraint( $this->textbox1 )
2268  );
2269  } else {
2270  $constraintRunner->addConstraint(
2272  $this->summary,
2273  $this->autoSumm,
2274  $this->allowBlankSummary,
2275  $content,
2276  $this->getOriginalContent( $user )
2277  )
2278  );
2279  }
2280  // Check the constraints
2281  if ( !$constraintRunner->checkConstraints() ) {
2282  $failed = $constraintRunner->getFailedConstraint();
2283  $this->handleFailedConstraint( $failed );
2284  return Status::wrap( $failed->getLegacyStatus() );
2285  }
2286  // END OF MIGRATION TO EDITCONSTRAINT SYSTEM (continued below)
2287 
2288  # All's well
2289  $sectionAnchor = '';
2290  if ( $this->section == 'new' ) {
2291  list( $newSectionSummary, $anchor ) = $this->newSectionSummary();
2292  $this->summary = $newSectionSummary;
2293  $sectionAnchor = $anchor;
2294  } elseif ( $this->section != '' ) {
2295  # Try to get a section anchor from the section source, redirect
2296  # to edited section if header found.
2297  # XXX: Might be better to integrate this into WikiPage::replaceSectionAtRev
2298  # for duplicate heading checking and maybe parsing.
2299  $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );
2300  # We can't deal with anchors, includes, html etc in the header for now,
2301  # headline would need to be parsed to improve this.
2302  if ( $hasmatch && strlen( $matches[2] ) > 0 ) {
2303  $sectionAnchor = $this->guessSectionName( $matches[2] );
2304  }
2305  }
2306  $result['sectionanchor'] = $sectionAnchor;
2307 
2308  // Save errors may fall down to the edit form, but we've now
2309  // merged the section into full text. Clear the section field
2310  // so that later submission of conflict forms won't try to
2311  // replace that into a duplicated mess.
2312  $this->textbox1 = $this->toEditText( $content );
2313  $this->section = '';
2314  }
2315 
2316  // Check for length errors again now that the section is merged in
2317  $this->contentLength = strlen( $this->toEditText( $content ) );
2318 
2319  // BEGINNING OF MIGRATION TO EDITCONSTRAINT SYSTEM (see T157658)
2320  // Create a new runner to avoid rechecking the prior constraints, use the same factory
2321  $constraintRunner = new EditConstraintRunner();
2322  $constraintRunner->addConstraint(
2324  $this->allowSelfRedirect,
2325  $content,
2326  $this->getCurrentContent(),
2327  $this->getTitle()
2328  )
2329  );
2330  $constraintRunner->addConstraint(
2331  // Same constraint is used to check size before and after merging the
2332  // edits, which use different failure codes
2333  $constraintFactory->newPageSizeConstraint(
2334  $this->contentLength,
2335  PageSizeConstraint::AFTER_MERGE
2336  )
2337  );
2338  // Check the constraints
2339  if ( !$constraintRunner->checkConstraints() ) {
2340  $failed = $constraintRunner->getFailedConstraint();
2341  $this->handleFailedConstraint( $failed );
2342  return Status::wrap( $failed->getLegacyStatus() );
2343  }
2344  // END OF MIGRATION TO EDITCONSTRAINT SYSTEM
2345 
2346  if ( $this->undidRev && $this->isUndoClean( $content ) ) {
2347  // As the user can change the edit's content before saving, we only mark
2348  // "clean" undos as reverts. This is to avoid abuse by marking irrelevant
2349  // edits as undos.
2350  $pageUpdater
2351  ->setOriginalRevisionId( $this->undoAfter ?: false )
2352  ->markAsRevert(
2353  EditResult::REVERT_UNDO,
2354  $this->undidRev,
2355  $this->undoAfter ?: null
2356  );
2357  }
2358 
2359  $needsPatrol = $wgUseRCPatrol || ( $wgUseNPPatrol && !$this->page->exists() );
2360  if ( $needsPatrol && $this->context->getAuthority()
2361  ->authorizeWrite( 'autopatrol', $this->getTitle() )
2362  ) {
2363  $pageUpdater->setRcPatrolStatus( RecentChange::PRC_AUTOPATROLLED );
2364  }
2365 
2366  $pageUpdater
2367  ->addTags( $this->changeTags )
2368  ->saveRevision(
2369  CommentStoreComment::newUnsavedComment( trim( $this->summary ) ),
2370  $flags
2371  );
2372  $doEditStatus = $pageUpdater->getStatus();
2373 
2374  if ( !$doEditStatus->isOK() ) {
2375  // Failure from doEdit()
2376  // Show the edit conflict page for certain recognized errors from doEdit(),
2377  // but don't show it for errors from extension hooks
2378  $errors = $doEditStatus->getErrorsArray();
2379  if ( in_array( $errors[0][0],
2380  [ 'edit-gone-missing', 'edit-conflict', 'edit-already-exists' ] )
2381  ) {
2382  $this->isConflict = true;
2383  // Destroys data doEdit() put in $status->value but who cares
2384  $doEditStatus->value = self::AS_END;
2385  }
2386  return $doEditStatus;
2387  }
2388 
2389  $result['nullEdit'] = $doEditStatus->hasMessage( 'edit-no-change' );
2390  if ( $result['nullEdit'] ) {
2391  // We don't know if it was a null edit until now, so increment here
2392  $user->pingLimiter( 'linkpurge' );
2393  }
2394  $result['redirect'] = $content->isRedirect();
2395 
2396  $this->updateWatchlist();
2397 
2398  // If the content model changed, add a log entry
2399  if ( $changingContentModel ) {
2401  $user,
2402  $new ? false : $oldContentModel,
2403  $this->contentModel,
2404  $this->summary
2405  );
2406  }
2407 
2408  // Instead of carrying the same status object throughout, it is created right
2409  // when it is returned, either at an earlier point due to an error or here
2410  // due to a successful edit.
2411  $statusCode = ( $new ? self::AS_SUCCESS_NEW_ARTICLE : self::AS_SUCCESS_UPDATE );
2412  $status = Status::newGood( $statusCode );
2413  return $status;
2414  }
2415 
2424  private function handleFailedConstraint( IEditConstraint $failed ) {
2425  if ( $failed instanceof PageSizeConstraint ) {
2426  // Error will be displayed by showEditForm()
2427  $this->tooBig = true;
2428  } elseif ( $failed instanceof UserBlockConstraint ) {
2429  // Auto-block user's IP if the account was "hard" blocked
2430  if ( !wfReadOnly() ) {
2431  $this->context->getUser()->spreadAnyEditBlock();
2432  }
2433  } elseif ( $failed instanceof DefaultTextConstraint ) {
2434  $this->blankArticle = true;
2435  } elseif ( $failed instanceof EditFilterMergedContentHookConstraint ) {
2436  $this->hookError = $failed->getHookError();
2437  } elseif (
2438  $failed instanceof AutoSummaryMissingSummaryConstraint ||
2439  $failed instanceof NewSectionMissingSummaryConstraint
2440  ) {
2441  $this->missingSummary = true;
2442  } elseif ( $failed instanceof MissingCommentConstraint ) {
2443  $this->missingComment = true;
2444  } elseif ( $failed instanceof SelfRedirectConstraint ) {
2445  $this->selfRedirect = true;
2446  }
2447  }
2448 
2459  private function isUndoClean( Content $content ): bool {
2460  // Check whether the undo was "clean", that is the user has not modified
2461  // the automatically generated content.
2462  $undoRev = $this->revisionStore->getRevisionById( $this->undidRev );
2463  if ( $undoRev === null ) {
2464  return false;
2465  }
2466 
2467  if ( $this->undoAfter ) {
2468  $oldRev = $this->revisionStore->getRevisionById( $this->undoAfter );
2469  } else {
2470  $oldRev = $this->revisionStore->getPreviousRevision( $undoRev );
2471  }
2472 
2473  // Sanity checks
2474  if ( $oldRev === null ||
2475  $undoRev->isDeleted( RevisionRecord::DELETED_TEXT ) ||
2476  $oldRev->isDeleted( RevisionRecord::DELETED_TEXT )
2477  ) {
2478  return false;
2479  }
2480 
2481  $undoContent = $this->getUndoContent( $undoRev, $oldRev );
2482  if ( !$undoContent ) {
2483  return false;
2484  }
2485 
2486  // Do a pre-save transform on the retrieved undo content
2487  $services = MediaWikiServices::getInstance();
2488  $contentLanguage = $services->getContentLanguage();
2489  $user = $this->context->getUser();
2490  $parserOptions = ParserOptions::newFromUserAndLang( $user, $contentLanguage );
2491  $contentTransformer = $services->getContentTransformer();
2492  $undoContent = $contentTransformer->preSaveTransform( $undoContent, $this->mTitle, $user, $parserOptions );
2493 
2494  if ( $undoContent->equals( $content ) ) {
2495  return true;
2496  }
2497  return false;
2498  }
2499 
2506  protected function addContentModelChangeLogEntry( UserIdentity $user, $oldModel, $newModel, $reason ) {
2507  $new = $oldModel === false;
2508  $log = new ManualLogEntry( 'contentmodel', $new ? 'new' : 'change' );
2509  $log->setPerformer( $user );
2510  $log->setTarget( $this->mTitle );
2511  $log->setComment( $reason );
2512  $log->setParameters( [
2513  '4::oldmodel' => $oldModel,
2514  '5::newmodel' => $newModel
2515  ] );
2516  $logid = $log->insert();
2517  $log->publish( $logid );
2518  }
2519 
2523  protected function updateWatchlist() {
2524  $performer = $this->context->getAuthority();
2525  if ( !$performer->getUser()->isRegistered() ) {
2526  return;
2527  }
2528 
2530  $watch = $this->watchthis;
2532 
2533  // This can't run as a DeferredUpdate due to a possible race condition
2534  // when the post-edit redirect happens if the pendingUpdates queue is
2535  // too large to finish in time (T259564)
2536  $this->watchlistManager->setWatch( $watch, $performer, $title, $watchlistExpiry );
2537 
2538  $this->watchedItemStore->maybeEnqueueWatchlistExpiryJob();
2539  }
2540 
2553  private function mergeChangesIntoContent( $editContent ) {
2554  // This is the revision that was current at the time editing was initiated on the client,
2555  // even if the edit was based on an old revision.
2556  $baseRevRecord = $this->getExpectedParentRevision();
2557  $baseContent = $baseRevRecord ?
2558  $baseRevRecord->getContent( SlotRecord::MAIN ) :
2559  null;
2560 
2561  if ( $baseContent === null ) {
2562  return false;
2563  }
2564 
2565  // The current state, we want to merge updates into it
2566  $currentRevisionRecord = $this->revisionStore->getRevisionByTitle(
2567  $this->mTitle,
2568  0,
2569  RevisionStore::READ_LATEST
2570  );
2571  $currentContent = $currentRevisionRecord
2572  ? $currentRevisionRecord->getContent( SlotRecord::MAIN )
2573  : null;
2574 
2575  if ( $currentContent === null ) {
2576  return false;
2577  }
2578 
2579  $mergedContent = $this->contentHandlerFactory
2580  ->getContentHandler( $baseContent->getModel() )
2581  ->merge3( $baseContent, $editContent, $currentContent );
2582 
2583  if ( $mergedContent ) {
2584  // Also need to update parentRevId to what we just merged.
2585  return [ $mergedContent, $currentRevisionRecord->getId() ];
2586  }
2587 
2588  return false;
2589  }
2590 
2598  public function getExpectedParentRevision() {
2599  if ( $this->mExpectedParentRevision === false ) {
2600  $revRecord = null;
2601  if ( $this->editRevId ) {
2602  $revRecord = $this->revisionStore->getRevisionById(
2603  $this->editRevId,
2604  RevisionStore::READ_LATEST
2605  );
2606  } elseif ( $this->edittime ) {
2607  $revRecord = $this->revisionStore->getRevisionByTimestamp(
2608  $this->getTitle(),
2609  $this->edittime,
2610  RevisionStore::READ_LATEST
2611  );
2612  }
2613  $this->mExpectedParentRevision = $revRecord;
2614  }
2616  }
2617 
2618  public function setHeaders() {
2619  $out = $this->context->getOutput();
2620 
2621  $out->addModules( 'mediawiki.action.edit' );
2622  $out->addModuleStyles( 'mediawiki.action.edit.styles' );
2623  $out->addModuleStyles( 'mediawiki.editfont.styles' );
2624  $out->addModuleStyles( 'mediawiki.interface.helpers.styles' );
2625 
2626  $user = $this->context->getUser();
2627 
2628  if ( $user->getOption( 'uselivepreview' ) ) {
2629  $out->addModules( 'mediawiki.action.edit.preview' );
2630  }
2631 
2632  if ( $user->getOption( 'useeditwarning' ) ) {
2633  $out->addModules( 'mediawiki.action.edit.editWarning' );
2634  }
2635 
2636  # Enabled article-related sidebar, toplinks, etc.
2637  $out->setArticleRelated( true );
2638 
2639  $contextTitle = $this->getContextTitle();
2640  if ( $this->isConflict ) {
2641  $msg = 'editconflict';
2642  } elseif ( $contextTitle->exists() && $this->section != '' ) {
2643  $msg = $this->section == 'new' ? 'editingcomment' : 'editingsection';
2644  } else {
2645  $msg = $contextTitle->exists()
2646  || ( $contextTitle->getNamespace() === NS_MEDIAWIKI
2647  && $contextTitle->getDefaultMessageText() !== false
2648  )
2649  ? 'editing'
2650  : 'creating';
2651  }
2652 
2653  # Use the title defined by DISPLAYTITLE magic word when present
2654  # NOTE: getDisplayTitle() returns HTML while getPrefixedText() returns plain text.
2655  # setPageTitle() treats the input as wikitext, which should be safe in either case.
2656  $displayTitle = isset( $this->mParserOutput ) ? $this->mParserOutput->getDisplayTitle() : false;
2657  if ( $displayTitle === false ) {
2658  $displayTitle = $contextTitle->getPrefixedText();
2659  } else {
2660  $out->setDisplayTitle( $displayTitle );
2661  }
2662  $out->setPageTitle( $this->context->msg( $msg, $displayTitle ) );
2663 
2664  $config = $this->context->getConfig();
2665 
2666  # Transmit the name of the message to JavaScript for live preview
2667  # Keep Resources.php/mediawiki.action.edit.preview in sync with the possible keys
2668  $out->addJsConfigVars( [
2669  'wgEditMessage' => $msg,
2670  ] );
2671 
2672  // Add whether to use 'save' or 'publish' messages to JavaScript for post-edit, other
2673  // editors, etc.
2674  $out->addJsConfigVars(
2675  'wgEditSubmitButtonLabelPublish',
2676  $config->get( 'EditSubmitButtonLabelPublish' )
2677  );
2678  }
2679 
2683  protected function showIntro() {
2684  if ( $this->suppressIntro ) {
2685  return;
2686  }
2687 
2688  $out = $this->context->getOutput();
2689  $namespace = $this->mTitle->getNamespace();
2690 
2691  if ( $namespace === NS_MEDIAWIKI ) {
2692  # Show a warning if editing an interface message
2693  $out->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1\n</div>", 'editinginterface' );
2694  # If this is a default message (but not css, json, or js),
2695  # show a hint that it is translatable on translatewiki.net
2696  if (
2697  !$this->mTitle->hasContentModel( CONTENT_MODEL_CSS )
2698  && !$this->mTitle->hasContentModel( CONTENT_MODEL_JSON )
2699  && !$this->mTitle->hasContentModel( CONTENT_MODEL_JAVASCRIPT )
2700  ) {
2701  $defaultMessageText = $this->mTitle->getDefaultMessageText();
2702  if ( $defaultMessageText !== false ) {
2703  $out->wrapWikiMsg( "<div class='mw-translateinterface'>\n$1\n</div>",
2704  'translateinterface' );
2705  }
2706  }
2707  } elseif ( $namespace === NS_FILE ) {
2708  # Show a hint to shared repo
2709  $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $this->mTitle );
2710  if ( $file && !$file->isLocal() ) {
2711  $descUrl = $file->getDescriptionUrl();
2712  # there must be a description url to show a hint to shared repo
2713  if ( $descUrl ) {
2714  if ( !$this->mTitle->exists() ) {
2715  $out->wrapWikiMsg( "<div class=\"mw-sharedupload-desc-create\">\n$1\n</div>", [
2716  'sharedupload-desc-create', $file->getRepo()->getDisplayName(), $descUrl
2717  ] );
2718  } else {
2719  $out->wrapWikiMsg( "<div class=\"mw-sharedupload-desc-edit\">\n$1\n</div>", [
2720  'sharedupload-desc-edit', $file->getRepo()->getDisplayName(), $descUrl
2721  ] );
2722  }
2723  }
2724  }
2725  }
2726 
2727  # Show a warning message when someone creates/edits a user (talk) page but the user does not exist
2728  # Show log extract when the user is currently blocked
2729  if ( $namespace === NS_USER || $namespace === NS_USER_TALK ) {
2730  $username = explode( '/', $this->mTitle->getText(), 2 )[0];
2731  $user = User::newFromName( $username, false /* allow IP users */ );
2732  $ip = $this->userNameUtils->isIP( $username );
2733  $block = DatabaseBlock::newFromTarget( $user, $user );
2734 
2735  $userExists = ( $user && $user->isRegistered() );
2736  if ( $userExists && $user->isHidden() &&
2737  !$this->permManager->userHasRight( $this->context->getUser(), 'hideuser' )
2738  ) {
2739  // If the user exists, but is hidden, and the viewer cannot see hidden
2740  // users, pretend like they don't exist at all. See T120883
2741  $userExists = false;
2742  }
2743 
2744  if ( !$userExists && !$ip ) { # User does not exist
2745  $out->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
2746  [ 'userpage-userdoesnotexist', wfEscapeWikiText( $username ) ] );
2747  } elseif (
2748  $block !== null &&
2749  $block->getType() != DatabaseBlock::TYPE_AUTO &&
2750  (
2751  $block->isSitewide() ||
2752  $user->isBlockedFrom(
2753  $this->mTitle,
2754  true
2755  )
2756  )
2757  ) {
2758  // Show log extract if the user is sitewide blocked or is partially
2759  // blocked and not allowed to edit their user page or user talk page
2761  $out,
2762  'block',
2763  MediaWikiServices::getInstance()->getNamespaceInfo()->
2764  getCanonicalName( NS_USER ) . ':' . $block->getTargetName(),
2765  '',
2766  [
2767  'lim' => 1,
2768  'showIfEmpty' => false,
2769  'msgKey' => [
2770  'blocked-notice-logextract',
2771  $user->getName() # Support GENDER in notice
2772  ]
2773  ]
2774  );
2775  }
2776  }
2777  # Try to add a custom edit intro, or use the standard one if this is not possible.
2778  if ( !$this->showCustomIntro() && !$this->mTitle->exists() ) {
2780  $this->context->msg( 'helppage' )->inContentLanguage()->text()
2781  ) );
2782  if ( $this->context->getUser()->isRegistered() ) {
2783  $out->wrapWikiMsg(
2784  // Suppress the external link icon, consider the help url an internal one
2785  "<div class=\"mw-newarticletext plainlinks\">\n$1\n</div>",
2786  [
2787  'newarticletext',
2788  $helpLink
2789  ]
2790  );
2791  } else {
2792  $out->wrapWikiMsg(
2793  // Suppress the external link icon, consider the help url an internal one
2794  "<div class=\"mw-newarticletextanon plainlinks\">\n$1\n</div>",
2795  [
2796  'newarticletextanon',
2797  $helpLink
2798  ]
2799  );
2800  }
2801  }
2802  # Give a notice if the user is editing a deleted/moved page...
2803  if ( !$this->mTitle->exists() ) {
2804  $dbr = wfGetDB( DB_REPLICA );
2805 
2806  LogEventsList::showLogExtract( $out, [ 'delete', 'move' ], $this->mTitle,
2807  '',
2808  [
2809  'lim' => 10,
2810  'conds' => [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ],
2811  'showIfEmpty' => false,
2812  'msgKey' => [ 'recreate-moveddeleted-warn' ]
2813  ]
2814  );
2815  }
2816  }
2817 
2823  protected function showCustomIntro() {
2824  if ( $this->editintro ) {
2825  $title = Title::newFromText( $this->editintro );
2826  if ( $this->isPageExistingAndViewable( $title, $this->context->getUser() ) ) {
2827  // Added using template syntax, to take <noinclude>'s into account.
2828  $this->context->getOutput()->addWikiTextAsContent(
2829  '<div class="mw-editintro">{{:' . $title->getFullText() . '}}</div>',
2830  /*linestart*/true,
2831  $this->mTitle
2832  );
2833  return true;
2834  }
2835  }
2836  return false;
2837  }
2838 
2857  protected function toEditText( $content ) {
2858  if ( $content === null || $content === false || is_string( $content ) ) {
2859  return $content;
2860  }
2861 
2862  if ( !$this->isSupportedContentModel( $content->getModel() ) ) {
2863  throw new MWException( 'This content model is not supported: ' . $content->getModel() );
2864  }
2865 
2866  return $content->serialize( $this->contentFormat );
2867  }
2868 
2885  protected function toEditContent( $text ) {
2886  if ( $text === false || $text === null ) {
2887  return $text;
2888  }
2889 
2890  $content = ContentHandler::makeContent( $text, $this->getTitle(),
2891  $this->contentModel, $this->contentFormat );
2892 
2893  if ( !$this->isSupportedContentModel( $content->getModel() ) ) {
2894  throw new MWException( 'This content model is not supported: ' . $content->getModel() );
2895  }
2896 
2897  return $content;
2898  }
2899 
2908  public function showEditForm( $formCallback = null ) {
2909  # need to parse the preview early so that we know which templates are used,
2910  # otherwise users with "show preview after edit box" will get a blank list
2911  # we parse this near the beginning so that setHeaders can do the title
2912  # setting work instead of leaving it in getPreviewText
2913  $previewOutput = '';
2914  if ( $this->formtype == 'preview' ) {
2915  $previewOutput = $this->getPreviewText();
2916  }
2917 
2918  $out = $this->context->getOutput();
2919 
2920  $this->getHookRunner()->onEditPage__showEditForm_initial( $this, $out );
2921 
2922  $this->setHeaders();
2923 
2924  $this->addTalkPageText();
2925  $this->addEditNotices();
2926 
2927  if ( !$this->isConflict &&
2928  $this->section != '' &&
2929  !$this->isSectionEditSupported() ) {
2930  // We use $this->section to much before this and getVal('wgSection') directly in other places
2931  // at this point we can't reset $this->section to '' to fallback to non-section editing.
2932  // Someone is welcome to try refactoring though
2933  $out->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
2934  return;
2935  }
2936 
2937  $this->showHeader();
2938 
2939  $out->addHTML( $this->editFormPageTop );
2940 
2941  $user = $this->context->getUser();
2942  if ( $user->getOption( 'previewontop' ) ) {
2943  $this->displayPreviewArea( $previewOutput, true );
2944  }
2945 
2946  $out->addHTML( $this->editFormTextTop );
2947 
2948  if ( $this->wasDeletedSinceLastEdit() && $this->formtype !== 'save' ) {
2949  $out->addHTML( Html::errorBox(
2950  $out->msg( 'deletedwhileediting' )->parse(),
2951  '',
2952  'mw-deleted-while-editing'
2953  ) );
2954  }
2955 
2956  // @todo add EditForm plugin interface and use it here!
2957  // search for textarea1 and textarea2, and allow EditForm to override all uses.
2958  $out->addHTML( Html::openElement(
2959  'form',
2960  [
2961  'class' => 'mw-editform',
2962  'id' => self::EDITFORM_ID,
2963  'name' => self::EDITFORM_ID,
2964  'method' => 'post',
2965  'action' => $this->getActionURL( $this->getContextTitle() ),
2966  'enctype' => 'multipart/form-data'
2967  ]
2968  ) );
2969 
2970  if ( is_callable( $formCallback ) ) {
2971  wfWarn( 'The $formCallback parameter to ' . __METHOD__ . ' is deprecated' );
2972  call_user_func_array( $formCallback, [ &$out ] );
2973  }
2974 
2975  // Add a check for Unicode support
2976  $out->addHTML( Html::hidden( 'wpUnicodeCheck', self::UNICODE_CHECK ) );
2977 
2978  // Add an empty field to trip up spambots
2979  $out->addHTML(
2980  Xml::openElement( 'div', [ 'id' => 'antispam-container', 'style' => 'display: none;' ] )
2981  . Html::rawElement(
2982  'label',
2983  [ 'for' => 'wpAntispam' ],
2984  $this->context->msg( 'simpleantispam-label' )->parse()
2985  )
2986  . Xml::element(
2987  'input',
2988  [
2989  'type' => 'text',
2990  'name' => 'wpAntispam',
2991  'id' => 'wpAntispam',
2992  'value' => ''
2993  ]
2994  )
2995  . Xml::closeElement( 'div' )
2996  );
2997 
2998  $this->getHookRunner()->onEditPage__showEditForm_fields( $this, $out );
2999 
3000  // Put these up at the top to ensure they aren't lost on early form submission
3001  $this->showFormBeforeText();
3002 
3003  if ( $this->wasDeletedSinceLastEdit() && $this->formtype == 'save' ) {
3004  $username = $this->lastDelete->actor_name;
3005  $comment = CommentStore::getStore()
3006  ->getComment( 'log_comment', $this->lastDelete )->text;
3007 
3008  // It is better to not parse the comment at all than to have templates expanded in the middle
3009  // TODO: can the checkLabel be moved outside of the div so that wrapWikiMsg could be used?
3010  $key = $comment === ''
3011  ? 'confirmrecreate-noreason'
3012  : 'confirmrecreate';
3013  $out->addHTML(
3014  '<div class="mw-confirm-recreate">' .
3015  $this->context->msg( $key, $username, "<nowiki>$comment</nowiki>" )->parse() .
3016  Xml::checkLabel( $this->context->msg( 'recreate' )->text(), 'wpRecreate', 'wpRecreate', false,
3017  [ 'title' => Linker::titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' ]
3018  ) .
3019  '</div>'
3020  );
3021  }
3022 
3023  # When the summary is hidden, also hide them on preview/show changes
3024  if ( $this->nosummary ) {
3025  $out->addHTML( Html::hidden( 'nosummary', true ) );
3026  }
3027 
3028  # If a blank edit summary was previously provided, and the appropriate
3029  # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
3030  # user being bounced back more than once in the event that a summary
3031  # is not required.
3032  # ####
3033  # For a bit more sophisticated detection of blank summaries, hash the
3034  # automatic one and pass that in the hidden field wpAutoSummary.
3035  if (
3036  $this->missingSummary ||
3037  ( $this->section == 'new' && $this->nosummary ) ||
3038  $this->allowBlankSummary
3039  ) {
3040  $out->addHTML( Html::hidden( 'wpIgnoreBlankSummary', true ) );
3041  }
3042 
3043  if ( $this->undidRev ) {
3044  $out->addHTML( Html::hidden( 'wpUndidRevision', $this->undidRev ) );
3045  }
3046  if ( $this->undoAfter ) {
3047  $out->addHTML( Html::hidden( 'wpUndoAfter', $this->undoAfter ) );
3048  }
3049 
3050  if ( $this->selfRedirect ) {
3051  $out->addHTML( Html::hidden( 'wpIgnoreSelfRedirect', true ) );
3052  }
3053 
3054  if ( $this->hasPresetSummary ) {
3055  // If a summary has been preset using &summary= we don't want to prompt for
3056  // a different summary. Only prompt for a summary if the summary is blanked.
3057  // (T19416)
3058  $this->autoSumm = md5( '' );
3059  }
3060 
3061  $autosumm = $this->autoSumm !== '' ? $this->autoSumm : md5( $this->summary );
3062  $out->addHTML( Html::hidden( 'wpAutoSummary', $autosumm ) );
3063 
3064  $out->addHTML( Html::hidden( 'oldid', $this->oldid ) );
3065  $out->addHTML( Html::hidden( 'parentRevId', $this->getParentRevId() ) );
3066 
3067  $out->addHTML( Html::hidden( 'format', $this->contentFormat ) );
3068  $out->addHTML( Html::hidden( 'model', $this->contentModel ) );
3069 
3070  $out->enableOOUI();
3071 
3072  if ( $this->section == 'new' ) {
3073  $this->showSummaryInput( true, $this->summary );
3074  $out->addHTML( $this->getSummaryPreview( true, $this->summary ) );
3075  }
3076 
3077  $out->addHTML( $this->editFormTextBeforeContent );
3078  if ( $this->isConflict ) {
3079  // In an edit conflict, we turn textbox2 into the user's text,
3080  // and textbox1 into the stored version
3081  $this->textbox2 = $this->textbox1;
3082 
3083  $content = $this->getCurrentContent();
3084  $this->textbox1 = $this->toEditText( $content );
3085 
3087  $editConflictHelper->setTextboxes( $this->textbox2, $this->textbox1 );
3088  $editConflictHelper->setContentModel( $this->contentModel );
3089  $editConflictHelper->setContentFormat( $this->contentFormat );
3091  }
3092 
3093  if ( !$this->mTitle->isUserConfigPage() ) {
3094  $out->addHTML( self::getEditToolbar() );
3095  }
3096 
3097  if ( $this->blankArticle ) {
3098  $out->addHTML( Html::hidden( 'wpIgnoreBlankArticle', true ) );
3099  }
3100 
3101  if ( $this->isConflict ) {
3102  // In an edit conflict bypass the overridable content form method
3103  // and fallback to the raw wpTextbox1 since editconflicts can't be
3104  // resolved between page source edits and custom ui edits using the
3105  // custom edit ui.
3106  $conflictTextBoxAttribs = [];
3107  if ( $this->wasDeletedSinceLastEdit() ) {
3108  $conflictTextBoxAttribs['style'] = 'display:none;';
3109  } elseif ( $this->isOldRev ) {
3110  $conflictTextBoxAttribs['class'] = 'mw-textarea-oldrev';
3111  }
3112 
3113  $out->addHTML( $editConflictHelper->getEditConflictMainTextBox( $conflictTextBoxAttribs ) );
3115  } else {
3116  $this->showContentForm();
3117  }
3118 
3119  $out->addHTML( $this->editFormTextAfterContent );
3120 
3121  $this->showStandardInputs();
3122 
3123  $this->showFormAfterText();
3124 
3125  $this->showTosSummary();
3126 
3127  $this->showEditTools();
3128 
3129  $out->addHTML( $this->editFormTextAfterTools . "\n" );
3130 
3131  $out->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) );
3132 
3133  $out->addHTML( Html::rawElement( 'div', [ 'class' => 'hiddencats' ],
3134  Linker::formatHiddenCategories( $this->page->getHiddenCategories() ) ) );
3135 
3136  $out->addHTML( Html::rawElement( 'div', [ 'class' => 'limitreport' ],
3137  self::getPreviewLimitReport( $this->mParserOutput ) ) );
3138 
3139  $out->addModules( 'mediawiki.action.edit.collapsibleFooter' );
3140 
3141  if ( $this->isConflict ) {
3142  try {
3143  $this->showConflict();
3144  } catch ( MWContentSerializationException $ex ) {
3145  // this can't really happen, but be nice if it does.
3146  $msg = $this->context->msg(
3147  'content-failed-to-parse',
3148  $this->contentModel,
3149  $this->contentFormat,
3150  $ex->getMessage()
3151  );
3152  $out->wrapWikiTextAsInterface( 'error', $msg->plain() );
3153  }
3154  }
3155 
3156  // Set a hidden field so JS knows what edit form mode we are in
3157  if ( $this->isConflict ) {
3158  $mode = 'conflict';
3159  } elseif ( $this->preview ) {
3160  $mode = 'preview';
3161  } elseif ( $this->diff ) {
3162  $mode = 'diff';
3163  } else {
3164  $mode = 'text';
3165  }
3166  $out->addHTML( Html::hidden( 'mode', $mode, [ 'id' => 'mw-edit-mode' ] ) );
3167 
3168  // Marker for detecting truncated form data. This must be the last
3169  // parameter sent in order to be of use, so do not move me.
3170  $out->addHTML( Html::hidden( 'wpUltimateParam', true ) );
3171  $out->addHTML( $this->editFormTextBottom . "\n</form>\n" );
3172 
3173  if ( !$user->getOption( 'previewontop' ) ) {
3174  $this->displayPreviewArea( $previewOutput, false );
3175  }
3176  }
3177 
3185  public function makeTemplatesOnThisPageList( array $templates ) {
3186  $templateListFormatter = new TemplatesOnThisPageFormatter(
3187  $this->context, MediaWikiServices::getInstance()->getLinkRenderer()
3188  );
3189 
3190  // preview if preview, else section if section, else false
3191  $type = false;
3192  if ( $this->preview ) {
3193  $type = 'preview';
3194  } elseif ( $this->section != '' ) {
3195  $type = 'section';
3196  }
3197 
3198  return Html::rawElement( 'div', [ 'class' => 'templatesUsed' ],
3199  $templateListFormatter->format( $templates, $type )
3200  );
3201  }
3202 
3209  private static function extractSectionTitle( $text ) {
3210  if ( preg_match( "/^(=+)(.+)\\1\\s*(\n|$)/i", $text, $matches ) ) {
3211  return MediaWikiServices::getInstance()->getParser()
3212  ->stripSectionName( trim( $matches[2] ) );
3213  } else {
3214  return false;
3215  }
3216  }
3217 
3218  protected function showHeader() {
3219  $out = $this->context->getOutput();
3220  $user = $this->context->getUser();
3221  if ( $this->isConflict ) {
3222  $this->addExplainConflictHeader( $out );
3223  $this->editRevId = $this->page->getLatest();
3224  } else {
3225  if ( $this->section != '' && $this->section != 'new' && !$this->summary &&
3226  !$this->preview && !$this->diff
3227  ) {
3228  $sectionTitle = self::extractSectionTitle( $this->textbox1 ); // FIXME: use Content object
3229  if ( $sectionTitle !== false ) {
3230  $this->summary = "/* $sectionTitle */ ";
3231  }
3232  }
3233 
3234  $buttonLabel = $this->context->msg( $this->getSubmitButtonLabel() )->text();
3235 
3236  if ( $this->missingComment ) {
3237  $out->wrapWikiMsg( "<div id='mw-missingcommenttext'>\n$1\n</div>", 'missingcommenttext' );
3238  }
3239 
3240  if ( $this->missingSummary && $this->section != 'new' ) {
3241  $out->wrapWikiMsg(
3242  "<div id='mw-missingsummary'>\n$1\n</div>",
3243  [ 'missingsummary', $buttonLabel ]
3244  );
3245  }
3246 
3247  if ( $this->missingSummary && $this->section == 'new' ) {
3248  $out->wrapWikiMsg(
3249  "<div id='mw-missingcommentheader'>\n$1\n</div>",
3250  [ 'missingcommentheader', $buttonLabel ]
3251  );
3252  }
3253 
3254  if ( $this->blankArticle ) {
3255  $out->wrapWikiMsg(
3256  "<div id='mw-blankarticle'>\n$1\n</div>",
3257  [ 'blankarticle', $buttonLabel ]
3258  );
3259  }
3260 
3261  if ( $this->selfRedirect ) {
3262  $out->wrapWikiMsg(
3263  "<div id='mw-selfredirect'>\n$1\n</div>",
3264  [ 'selfredirect', $buttonLabel ]
3265  );
3266  }
3267 
3268  if ( $this->hookError !== '' ) {
3269  $out->addWikiTextAsInterface( $this->hookError );
3270  }
3271 
3272  if ( $this->section != 'new' ) {
3273  $revRecord = $this->mArticle->fetchRevisionRecord();
3274  if ( $revRecord && $revRecord instanceof RevisionStoreRecord ) {
3275  // Let sysop know that this will make private content public if saved
3276 
3277  if ( !$revRecord->userCan( RevisionRecord::DELETED_TEXT, $user ) ) {
3278  $out->addHtml(
3280  $out->msg( 'rev-deleted-text-permission', $this->mTitle->getPrefixedDBkey() )->parse(),
3281  'plainlinks'
3282  )
3283  );
3284  } elseif ( $revRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
3285  $out->addHtml(
3287  // title used in wikilinks, should not contain whitespaces
3288  $out->msg( 'rev-deleted-text-view', $this->mTitle->getPrefixedDBkey() )->parse(),
3289  'plainlinks'
3290  )
3291  );
3292  }
3293 
3294  if ( !$revRecord->isCurrent() ) {
3295  $this->mArticle->setOldSubtitle( $revRecord->getId() );
3296  $out->wrapWikiMsg(
3297  Html::warningBox( "\n$1\n" ),
3298  'editingold'
3299  );
3300  $this->isOldRev = true;
3301  }
3302  } elseif ( $this->mTitle->exists() ) {
3303  // Something went wrong
3304 
3305  $out->wrapWikiMsg( "<div class='errorbox'>\n$1\n</div>\n",
3306  [ 'missing-revision', $this->oldid ] );
3307  }
3308  }
3309  }
3310 
3311  if ( wfReadOnly() ) {
3312  $out->wrapWikiMsg(
3313  "<div id=\"mw-read-only-warning\">\n$1\n</div>",
3314  [ 'readonlywarning', wfReadOnlyReason() ]
3315  );
3316  } elseif ( $user->isAnon() ) {
3317  if ( $this->formtype != 'preview' ) {
3318  $returntoquery = array_diff_key(
3319  $this->context->getRequest()->getValues(),
3320  [ 'title' => true, 'returnto' => true, 'returntoquery' => true ]
3321  );
3322  $out->wrapWikiMsg(
3323  "<div id='mw-anon-edit-warning' class='warningbox'>\n$1\n</div>",
3324  [ 'anoneditwarning',
3325  // Log-in link
3326  SpecialPage::getTitleFor( 'Userlogin' )->getFullURL( [
3327  'returnto' => $this->getTitle()->getPrefixedDBkey(),
3328  'returntoquery' => wfArrayToCgi( $returntoquery ),
3329  ] ),
3330  // Sign-up link
3331  SpecialPage::getTitleFor( 'CreateAccount' )->getFullURL( [
3332  'returnto' => $this->getTitle()->getPrefixedDBkey(),
3333  'returntoquery' => wfArrayToCgi( $returntoquery ),
3334  ] )
3335  ]
3336  );
3337  } else {
3338  $out->wrapWikiMsg( "<div id=\"mw-anon-preview-warning\" class=\"warningbox\">\n$1</div>",
3339  'anonpreviewwarning'
3340  );
3341  }
3342  } elseif ( $this->mTitle->isUserConfigPage() ) {
3343  # Check the skin exists
3344  if ( $this->isWrongCaseUserConfigPage() ) {
3345  $out->wrapWikiMsg(
3346  "<div class='errorbox' id='mw-userinvalidconfigtitle'>\n$1\n</div>",
3347  [ 'userinvalidconfigtitle', $this->mTitle->getSkinFromConfigSubpage() ]
3348  );
3349  }
3350  if ( $this->getTitle()->isSubpageOf( $user->getUserPage() ) ) {
3351  $isUserCssConfig = $this->mTitle->isUserCssConfigPage();
3352  $isUserJsonConfig = $this->mTitle->isUserJsonConfigPage();
3353  $isUserJsConfig = $this->mTitle->isUserJsConfigPage();
3354 
3355  $warning = $isUserCssConfig
3356  ? 'usercssispublic'
3357  : ( $isUserJsonConfig ? 'userjsonispublic' : 'userjsispublic' );
3358 
3359  $out->wrapWikiMsg( '<div class="mw-userconfigpublic">$1</div>', $warning );
3360 
3361  if ( $isUserJsConfig ) {
3362  $out->wrapWikiMsg( '<div class="mw-userconfigdangerous">$1</div>', 'userjsdangerous' );
3363  }
3364 
3365  if ( $this->formtype !== 'preview' ) {
3366  $config = $this->context->getConfig();
3367  if ( $isUserCssConfig && $config->get( 'AllowUserCss' ) ) {
3368  $out->wrapWikiMsg(
3369  "<div id='mw-usercssyoucanpreview'>\n$1\n</div>",
3370  [ 'usercssyoucanpreview' ]
3371  );
3372  } elseif ( $isUserJsonConfig /* No comparable 'AllowUserJson' */ ) {
3373  $out->wrapWikiMsg(
3374  "<div id='mw-userjsonyoucanpreview'>\n$1\n</div>",
3375  [ 'userjsonyoucanpreview' ]
3376  );
3377  } elseif ( $isUserJsConfig && $config->get( 'AllowUserJs' ) ) {
3378  $out->wrapWikiMsg(
3379  "<div id='mw-userjsyoucanpreview'>\n$1\n</div>",
3380  [ 'userjsyoucanpreview' ]
3381  );
3382  }
3383  }
3384  }
3385  }
3386 
3388 
3389  $this->addLongPageWarningHeader();
3390 
3391  # Add header copyright warning
3392  $this->showHeaderCopyrightWarning();
3393  }
3394 
3402  private function getSummaryInputAttributes( array $inputAttrs = null ) {
3403  // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
3404  // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
3405  // Unicode codepoints.
3406  return ( is_array( $inputAttrs ) ? $inputAttrs : [] ) + [
3407  'id' => 'wpSummary',
3408  'name' => 'wpSummary',
3410  'tabindex' => 1,
3411  'size' => 60,
3412  'spellcheck' => 'true',
3413  ];
3414  }
3415 
3425  private function getSummaryInputWidget( $summary = "", $labelText = null, $inputAttrs = null ) {
3426  $inputAttrs = OOUI\Element::configFromHtmlAttributes(
3427  $this->getSummaryInputAttributes( $inputAttrs )
3428  );
3429  $inputAttrs += [
3430  'title' => Linker::titleAttrib( 'summary' ),
3431  'accessKey' => Linker::accesskey( 'summary' ),
3432  ];
3433 
3434  // For compatibility with old scripts and extensions, we want the legacy 'id' on the `<input>`
3435  $inputAttrs['inputId'] = $inputAttrs['id'];
3436  $inputAttrs['id'] = 'wpSummaryWidget';
3437 
3438  return new OOUI\FieldLayout(
3439  new OOUI\TextInputWidget( [
3440  'value' => $summary,
3441  'infusable' => true,
3442  ] + $inputAttrs ),
3443  [
3444  'label' => new OOUI\HtmlSnippet( $labelText ),
3445  'align' => 'top',
3446  'id' => 'wpSummaryLabel',
3447  'classes' => [ $this->missingSummary ? 'mw-summarymissed' : 'mw-summary' ],
3448  ]
3449  );
3450  }
3451 
3458  protected function showSummaryInput( $isSubjectPreview, $summary = "" ) {
3459  # Add a class if 'missingsummary' is triggered to allow styling of the summary line
3460  $summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary';
3461  if ( $isSubjectPreview ) {
3462  if ( $this->nosummary ) {
3463  return;
3464  }
3465  } elseif ( !$this->mShowSummaryField ) {
3466  return;
3467  }
3468 
3469  $labelText = $this->context->msg( $isSubjectPreview ? 'subject' : 'summary' )->parse();
3470  $this->context->getOutput()->addHTML( $this->getSummaryInputWidget(
3471  $summary,
3472  $labelText,
3473  [ 'class' => $summaryClass ]
3474  ) );
3475  }
3476 
3484  protected function getSummaryPreview( $isSubjectPreview, $summary = "" ) {
3485  // avoid spaces in preview, gets always trimmed on save
3486  $summary = trim( $summary );
3487  if ( !$summary || ( !$this->preview && !$this->diff ) ) {
3488  return "";
3489  }
3490 
3491  if ( $isSubjectPreview ) {
3492  $summary = $this->context->msg( 'newsectionsummary' )
3493  ->rawParams( MediaWikiServices::getInstance()->getParser()
3494  ->stripSectionName( $summary ) )
3495  ->inContentLanguage()->text();
3496  }
3497 
3498  $message = $isSubjectPreview ? 'subject-preview' : 'summary-preview';
3499 
3500  $summary = $this->context->msg( $message )->parse()
3501  . Linker::commentBlock( $summary, $this->mTitle, $isSubjectPreview );
3502  return Xml::tags( 'div', [ 'class' => 'mw-summary-preview' ], $summary );
3503  }
3504 
3505  protected function showFormBeforeText() {
3506  $out = $this->context->getOutput();
3507  $out->addHTML( Html::hidden( 'wpSection', $this->section ) );
3508  $out->addHTML( Html::hidden( 'wpStarttime', $this->starttime ) );
3509  $out->addHTML( Html::hidden( 'wpEdittime', $this->edittime ) );
3510  $out->addHTML( Html::hidden( 'editRevId', $this->editRevId ) );
3511  $out->addHTML( Html::hidden( 'wpScrolltop', $this->scrolltop, [ 'id' => 'wpScrolltop' ] ) );
3512  }
3513 
3514  protected function showFormAfterText() {
3527  $this->context->getOutput()->addHTML(
3528  "\n" .
3529  Html::hidden( "wpEditToken", $this->context->getUser()->getEditToken() ) .
3530  "\n"
3531  );
3532  }
3533 
3542  protected function showContentForm() {
3543  $this->showTextbox1();
3544  }
3545 
3554  protected function showTextbox1( $customAttribs = null, $textoverride = null ) {
3555  if ( $this->wasDeletedSinceLastEdit() && $this->formtype == 'save' ) {
3556  $attribs = [ 'style' => 'display:none;' ];
3557  } else {
3558  $builder = new TextboxBuilder();
3559  $classes = $builder->getTextboxProtectionCSSClasses( $this->getTitle() );
3560 
3561  # Is an old revision being edited?
3562  if ( $this->isOldRev ) {
3563  $classes[] = 'mw-textarea-oldrev';
3564  }
3565 
3566  $attribs = [
3567  'aria-label' => $this->context->msg( 'edit-textarea-aria-label' )->text(),
3568  'tabindex' => 1
3569  ];
3570 
3571  if ( is_array( $customAttribs ) ) {
3572  $attribs += $customAttribs;
3573  }
3574 
3575  $attribs = $builder->mergeClassesIntoAttributes( $classes, $attribs );
3576  }
3577 
3578  $this->showTextbox(
3579  $textoverride ?? $this->textbox1,
3580  'wpTextbox1',
3581  $attribs
3582  );
3583  }
3584 
3585  protected function showTextbox2() {
3586  $this->showTextbox( $this->textbox2, 'wpTextbox2', [ 'tabindex' => 6, 'readonly' ] );
3587  }
3588 
3589  protected function showTextbox( $text, $name, $customAttribs = [] ) {
3590  $builder = new TextboxBuilder();
3591  $attribs = $builder->buildTextboxAttribs(
3592  $name,
3593  $customAttribs,
3594  $this->context->getUser(),
3595  $this->mTitle
3596  );
3597 
3598  $this->context->getOutput()->addHTML(
3599  Html::textarea( $name, $builder->addNewLineAtEnd( $text ), $attribs )
3600  );
3601  }
3602 
3603  protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
3604  $attribs = [ 'id' => 'wikiPreview' ];
3605  if ( $isOnTop ) {
3606  $attribs['class'] = 'ontop';
3607  }
3608  if ( $this->formtype != 'preview' ) {
3609  $attribs['style'] = 'display: none;';
3610  }
3611 
3612  $out = $this->context->getOutput();
3613  $out->addHTML( Xml::openElement( 'div', $attribs ) );
3614 
3615  if ( $this->formtype == 'preview' ) {
3616  $this->showPreview( $previewOutput );
3617  } else {
3618  // Empty content container for LivePreview
3619  $pageViewLang = $this->mTitle->getPageViewLanguage();
3620  $attribs = [ 'lang' => $pageViewLang->getHtmlCode(), 'dir' => $pageViewLang->getDir(),
3621  'class' => 'mw-content-' . $pageViewLang->getDir() ];
3622  $out->addHTML( Html::rawElement( 'div', $attribs ) );
3623  }
3624 
3625  $out->addHTML( '</div>' );
3626 
3627  if ( $this->formtype == 'diff' ) {
3628  try {
3629  $this->showDiff();
3630  } catch ( MWContentSerializationException $ex ) {
3631  $msg = $this->context->msg(
3632  'content-failed-to-parse',
3633  $this->contentModel,
3634  $this->contentFormat,
3635  $ex->getMessage()
3636  );
3637  $out->wrapWikiTextAsInterface( 'error', $msg->plain() );
3638  }
3639  }
3640  }
3641 
3648  protected function showPreview( $text ) {
3649  if ( $this->mArticle instanceof CategoryPage ) {
3650  $this->mArticle->openShowCategory();
3651  }
3652  # This hook seems slightly odd here, but makes things more
3653  # consistent for extensions.
3654  $out = $this->context->getOutput();
3655  $this->getHookRunner()->onOutputPageBeforeHTML( $out, $text );
3656  $out->addHTML( $text );
3657  if ( $this->mArticle instanceof CategoryPage ) {
3658  $this->mArticle->closeShowCategory();
3659  }
3660  }
3661 
3669  public function showDiff() {
3670  $oldtitlemsg = 'currentrev';
3671  # if message does not exist, show diff against the preloaded default
3672  if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI && !$this->mTitle->exists() ) {
3673  $oldtext = $this->mTitle->getDefaultMessageText();
3674  if ( $oldtext !== false ) {
3675  $oldtitlemsg = 'defaultmessagetext';
3676  $oldContent = $this->toEditContent( $oldtext );
3677  } else {
3678  $oldContent = null;
3679  }
3680  } else {
3681  $oldContent = $this->getCurrentContent();
3682  }
3683 
3684  $textboxContent = $this->toEditContent( $this->textbox1 );
3685  if ( $this->editRevId !== null ) {
3686  $newContent = $this->page->replaceSectionAtRev(
3687  $this->section, $textboxContent, $this->summary, $this->editRevId
3688  );
3689  } else {
3690  $newContent = $this->page->replaceSectionContent(
3691  $this->section, $textboxContent, $this->summary, $this->edittime
3692  );
3693  }
3694 
3695  if ( $newContent ) {
3696  $this->getHookRunner()->onEditPageGetDiffContent( $this, $newContent );
3697 
3698  $user = $this->context->getUser();
3699  $popts = ParserOptions::newFromUserAndLang( $user,
3700  MediaWikiServices::getInstance()->getContentLanguage() );
3701  $services = MediaWikiServices::getInstance();
3702  $contentTransformer = $services->getContentTransformer();
3703  $newContent = $contentTransformer->preSaveTransform( $newContent, $this->mTitle, $user, $popts );
3704  }
3705 
3706  if ( ( $oldContent && !$oldContent->isEmpty() ) || ( $newContent && !$newContent->isEmpty() ) ) {
3707  $oldtitle = $this->context->msg( $oldtitlemsg )->parse();
3708  $newtitle = $this->context->msg( 'yourtext' )->parse();
3709 
3710  if ( !$oldContent ) {
3711  $oldContent = $newContent->getContentHandler()->makeEmptyContent();
3712  }
3713 
3714  if ( !$newContent ) {
3715  $newContent = $oldContent->getContentHandler()->makeEmptyContent();
3716  }
3717 
3718  $de = $oldContent->getContentHandler()->createDifferenceEngine( $this->context );
3719  $de->setContent( $oldContent, $newContent );
3720 
3721  $difftext = $de->getDiff( $oldtitle, $newtitle );
3722  $de->showDiffStyle();
3723  } else {
3724  $difftext = '';
3725  }
3726 
3727  $this->context->getOutput()->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
3728  }
3729 
3730  protected function showHeaderCopyrightWarning() {
3731  $msg = 'editpage-head-copy-warn';
3732  if ( !$this->context->msg( $msg )->isDisabled() ) {
3733  $this->context->getOutput()->wrapWikiMsg( "<div class='editpage-head-copywarn'>\n$1\n</div>",
3734  'editpage-head-copy-warn' );
3735  }
3736  }
3737 
3746  protected function showTosSummary() {
3747  $msg = 'editpage-tos-summary';
3748  $this->getHookRunner()->onEditPageTosSummary( $this->mTitle, $msg );
3749  if ( !$this->context->msg( $msg )->isDisabled() ) {
3750  $out = $this->context->getOutput();
3751  $out->addHTML( '<div class="mw-tos-summary">' );
3752  $out->addWikiMsg( $msg );
3753  $out->addHTML( '</div>' );
3754  }
3755  }
3756 
3761  protected function showEditTools() {
3762  $this->context->getOutput()->addHTML( '<div class="mw-editTools">' .
3763  $this->context->msg( 'edittools' )->inContentLanguage()->parse() .
3764  '</div>' );
3765  }
3766 
3773  protected function getCopywarn() {
3774  return self::getCopyrightWarning( $this->mTitle );
3775  }
3776 
3785  public static function getCopyrightWarning( $title, $format = 'plain', $langcode = null ) {
3786  global $wgRightsText;
3787  if ( $wgRightsText ) {
3788  $copywarnMsg = [ 'copyrightwarning',
3789  '[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]',
3790  $wgRightsText ];
3791  } else {
3792  $copywarnMsg = [ 'copyrightwarning2',
3793  '[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]' ];
3794  }
3795  // Allow for site and per-namespace customization of contribution/copyright notice.
3796  Hooks::runner()->onEditPageCopyrightWarning( $title, $copywarnMsg );
3797 
3798  $msg = wfMessage( ...$copywarnMsg )->page( $title );
3799  if ( $langcode ) {
3800  $msg->inLanguage( $langcode );
3801  }
3802  return "<div id=\"editpage-copywarn\">\n" .
3803  $msg->$format() . "\n</div>";
3804  }
3805 
3813  public static function getPreviewLimitReport( ParserOutput $output = null ) {
3814  if ( !$output || !$output->getLimitReportData() ) {
3815  return '';
3816  }
3817 
3818  $limitReport = Html::rawElement( 'div', [ 'class' => 'mw-limitReportExplanation' ],
3819  wfMessage( 'limitreport-title' )->parseAsBlock()
3820  );
3821 
3822  // Show/hide animation doesn't work correctly on a table, so wrap it in a div.
3823  $limitReport .= Html::openElement( 'div', [ 'class' => 'preview-limit-report-wrapper' ] );
3824 
3825  $limitReport .= Html::openElement( 'table', [
3826  'class' => 'preview-limit-report wikitable'
3827  ] ) .
3828  Html::openElement( 'tbody' );
3829 
3830  foreach ( $output->getLimitReportData() as $key => $value ) {
3831  if ( Hooks::runner()->onParserLimitReportFormat( $key, $value, $limitReport, true, true ) ) {
3832  $keyMsg = wfMessage( $key );
3833  $valueMsg = wfMessage( [ "$key-value-html", "$key-value" ] );
3834  if ( !$valueMsg->exists() ) {
3835  // This is formatted raw, not as localized number.
3836  // If you want the parameter formatted as a number,
3837  // define the `$key-value` message.
3838  $valueMsg = ( new RawMessage( '$1' ) )->params( $value );
3839  } else {
3840  // If you define the `$key-value` or `$key-value-html`
3841  // message then the argument *must* be numeric.
3842  $valueMsg = $valueMsg->numParams( $value );
3843  }
3844  if ( !$keyMsg->isDisabled() && !$valueMsg->isDisabled() ) {
3845  $limitReport .= Html::openElement( 'tr' ) .
3846  Html::rawElement( 'th', null, $keyMsg->parse() ) .
3847  Html::rawElement( 'td', null, $valueMsg->parse() ) .
3848  Html::closeElement( 'tr' );
3849  }
3850  }
3851  }
3852 
3853  $limitReport .= Html::closeElement( 'tbody' ) .
3854  Html::closeElement( 'table' ) .
3855  Html::closeElement( 'div' );
3856 
3857  return $limitReport;
3858  }
3859 
3860  protected function showStandardInputs( &$tabindex = 2 ) {
3861  $out = $this->context->getOutput();
3862  $out->addHTML( "<div class='editOptions'>\n" );
3863 
3864  if ( $this->section != 'new' ) {
3865  $this->showSummaryInput( false, $this->summary );
3866  $out->addHTML( $this->getSummaryPreview( false, $this->summary ) );
3867  }
3868 
3869  $checkboxes = $this->getCheckboxesWidget(
3870  $tabindex,
3871  [ 'minor' => $this->minoredit, 'watch' => $this->watchthis ]
3872  );
3873  $checkboxesHTML = new OOUI\HorizontalLayout( [ 'items' => $checkboxes ] );
3874 
3875  $out->addHTML( "<div class='editCheckboxes'>" . $checkboxesHTML . "</div>\n" );
3876 
3877  // Show copyright warning.
3878  $out->addWikiTextAsInterface( $this->getCopywarn() );
3879  $out->addHTML( $this->editFormTextAfterWarn );
3880 
3881  $out->addHTML( "<div class='editButtons'>\n" );
3882  $out->addHTML( implode( "\n", $this->getEditButtons( $tabindex ) ) . "\n" );
3883 
3884  $cancel = $this->getCancelLink( $tabindex++ );
3885 
3886  $message = $this->context->msg( 'edithelppage' )->inContentLanguage()->text();
3887  $edithelpurl = Skin::makeInternalOrExternalUrl( $message );
3888  $edithelp =
3890  $this->context->msg( 'edithelp' )->text(),
3891  [ 'target' => 'helpwindow', 'href' => $edithelpurl ],
3892  [ 'mw-ui-quiet' ]
3893  ) .
3894  $this->context->msg( 'word-separator' )->escaped() .
3895  $this->context->msg( 'newwindow' )->parse();
3896 
3897  $out->addHTML( " <span class='cancelLink'>{$cancel}</span>\n" );
3898  $out->addHTML( " <span class='editHelp'>{$edithelp}</span>\n" );
3899  $out->addHTML( "</div><!-- editButtons -->\n" );
3900 
3901  $this->getHookRunner()->onEditPage__showStandardInputs_options( $this, $out, $tabindex );
3902 
3903  $out->addHTML( "</div><!-- editOptions -->\n" );
3904  }
3905 
3910  protected function showConflict() {
3911  $out = $this->context->getOutput();
3912  // Avoid PHP 7.1 warning of passing $this by reference
3913  $editPage = $this;
3914  if ( $this->getHookRunner()->onEditPageBeforeConflictDiff( $editPage, $out ) ) {
3915  $this->incrementConflictStats();
3916 
3917  $this->getEditConflictHelper()->showEditFormTextAfterFooters();
3918  }
3919  }
3920 
3921  protected function incrementConflictStats() {
3922  $this->getEditConflictHelper()->incrementConflictStats( $this->context->getUser() );
3923  }
3924 
3929  public function getCancelLink( $tabindex = 0 ) {
3930  $cancelParams = [];
3931  if ( !$this->isConflict && $this->oldid > 0 ) {
3932  $cancelParams['oldid'] = $this->oldid;
3933  } elseif ( $this->getContextTitle()->isRedirect() ) {
3934  $cancelParams['redirect'] = 'no';
3935  }
3936 
3937  return new OOUI\ButtonWidget( [
3938  'id' => 'mw-editform-cancel',
3939  'tabIndex' => $tabindex,
3940  'href' => $this->getContextTitle()->getLinkURL( $cancelParams ),
3941  'label' => new OOUI\HtmlSnippet( $this->context->msg( 'cancel' )->parse() ),
3942  'framed' => false,
3943  'infusable' => true,
3944  'flags' => 'destructive',
3945  ] );
3946  }
3947 
3957  protected function getActionURL( Title $title ) {
3958  return $title->getLocalURL( [ 'action' => $this->action ] );
3959  }
3960 
3968  protected function wasDeletedSinceLastEdit() {
3969  if ( $this->deletedSinceEdit !== null ) {
3970  return $this->deletedSinceEdit;
3971  }
3972 
3973  $this->deletedSinceEdit = false;
3974 
3975  if ( !$this->mTitle->exists() && $this->mTitle->hasDeletedEdits() ) {
3976  $this->lastDelete = $this->getLastDelete();
3977  if ( $this->lastDelete ) {
3978  $deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp );
3979  if ( $deleteTime > $this->starttime ) {
3980  $this->deletedSinceEdit = true;
3981  }
3982  }
3983  }
3984 
3985  return $this->deletedSinceEdit;
3986  }
3987 
3993  protected function getLastDelete() {
3994  $dbr = wfGetDB( DB_REPLICA );
3995  $commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
3996  $data = $dbr->selectRow(
3997  array_merge( [ 'logging' ], $commentQuery['tables'], [ 'actor' ] ),
3998  [
3999  'log_type',
4000  'log_action',
4001  'log_timestamp',
4002  'log_namespace',
4003  'log_title',
4004  'log_params',
4005  'log_deleted',
4006  'actor_name'
4007  ] + $commentQuery['fields'],
4008  [
4009  'log_namespace' => $this->mTitle->getNamespace(),
4010  'log_title' => $this->mTitle->getDBkey(),
4011  'log_type' => 'delete',
4012  'log_action' => 'delete',
4013  ],
4014  __METHOD__,
4015  [ 'ORDER BY' => 'log_timestamp DESC' ],
4016  [
4017  'actor' => [ 'JOIN', 'actor_id=log_actor' ],
4018  ] + $commentQuery['joins']
4019  );
4020  // Quick paranoid permission checks...
4021  if ( is_object( $data ) ) {
4022  if ( $data->log_deleted & LogPage::DELETED_USER ) {
4023  $data->actor_name = $this->context->msg( 'rev-deleted-user' )->escaped();
4024  }
4025 
4026  if ( $data->log_deleted & LogPage::DELETED_COMMENT ) {
4027  $data->log_comment_text = $this->context->msg( 'rev-deleted-comment' )->escaped();
4028  $data->log_comment_data = null;
4029  }
4030  }
4031 
4032  return $data;
4033  }
4034 
4040  public function getPreviewText() {
4041  $out = $this->context->getOutput();
4042  $config = $this->context->getConfig();
4043 
4044  if ( $config->get( 'RawHtml' ) && !$this->mTokenOk ) {
4045  // Could be an offsite preview attempt. This is very unsafe if
4046  // HTML is enabled, as it could be an attack.
4047  $parsedNote = '';
4048  if ( $this->textbox1 !== '' ) {
4049  // Do not put big scary notice, if previewing the empty
4050  // string, which happens when you initially edit
4051  // a category page, due to automatic preview-on-open.
4052  $parsedNote = Html::rawElement( 'div', [ 'class' => 'previewnote' ],
4053  $out->parseAsInterface(
4054  $this->context->msg( 'session_fail_preview_html' )->plain()
4055  ) );
4056  }
4057  $this->incrementEditFailureStats( 'session_loss' );
4058  return $parsedNote;
4059  }
4060 
4061  $note = '';
4062 
4063  try {
4064  $content = $this->toEditContent( $this->textbox1 );
4065 
4066  $previewHTML = '';
4067  if ( !$this->getHookRunner()->onAlternateEditPreview(
4068  $this, $content, $previewHTML, $this->mParserOutput )
4069  ) {
4070  return $previewHTML;
4071  }
4072 
4073  # provide a anchor link to the editform
4074  $continueEditing = '<span class="mw-continue-editing">' .
4075  '[[#' . self::EDITFORM_ID . '|' .
4076  $this->context->getLanguage()->getArrow() . ' ' .
4077  $this->context->msg( 'continue-editing' )->text() . ']]</span>';
4078  if ( $this->mTriedSave && !$this->mTokenOk ) {
4079  $note = $this->context->msg( 'session_fail_preview' )->plain();
4080  $this->incrementEditFailureStats( 'session_loss' );
4081  } elseif ( $this->incompleteForm ) {
4082  $note = $this->context->msg( 'edit_form_incomplete' )->plain();
4083  if ( $this->mTriedSave ) {
4084  $this->incrementEditFailureStats( 'incomplete_form' );
4085  }
4086  } else {
4087  $note = $this->context->msg( 'previewnote' )->plain() . ' ' . $continueEditing;
4088  }
4089 
4090  # don't parse non-wikitext pages, show message about preview
4091  if ( $this->mTitle->isUserConfigPage() || $this->mTitle->isSiteConfigPage() ) {
4092  if ( $this->mTitle->isUserConfigPage() ) {
4093  $level = 'user';
4094  } elseif ( $this->mTitle->isSiteConfigPage() ) {
4095  $level = 'site';
4096  } else {
4097  $level = false;
4098  }
4099 
4100  if ( $content->getModel() == CONTENT_MODEL_CSS ) {
4101  $format = 'css';
4102  if ( $level === 'user' && !$config->get( 'AllowUserCss' ) ) {
4103  $format = false;
4104  }
4105  } elseif ( $content->getModel() == CONTENT_MODEL_JSON ) {
4106  $format = 'json';
4107  if ( $level === 'user' /* No comparable 'AllowUserJson' */ ) {
4108  $format = false;
4109  }
4110  } elseif ( $content->getModel() == CONTENT_MODEL_JAVASCRIPT ) {
4111  $format = 'js';
4112  if ( $level === 'user' && !$config->get( 'AllowUserJs' ) ) {
4113  $format = false;
4114  }
4115  } else {
4116  $format = false;
4117  }
4118 
4119  # Used messages to make sure grep find them:
4120  # Messages: usercsspreview, userjsonpreview, userjspreview,
4121  # sitecsspreview, sitejsonpreview, sitejspreview
4122  if ( $level && $format ) {
4123  $note = "<div id='mw-{$level}{$format}preview'>" .
4124  $this->context->msg( "{$level}{$format}preview" )->plain() .
4125  ' ' . $continueEditing . "</div>";
4126  }
4127  }
4128 
4129  # If we're adding a comment, we need to show the
4130  # summary as the headline
4131  if ( $this->section === "new" && $this->summary !== "" ) {
4132  $content = $content->addSectionHeader( $this->summary );
4133  }
4134 
4135  $this->getHookRunner()->onEditPageGetPreviewContent( $this, $content );
4136 
4137  $parserResult = $this->doPreviewParse( $content );
4138  $parserOutput = $parserResult['parserOutput'];
4139  $previewHTML = $parserResult['html'];
4140  $this->mParserOutput = $parserOutput;
4141  $out->addParserOutputMetadata( $parserOutput );
4142  if ( $out->userCanPreview() ) {
4143  $out->addContentOverride( $this->getTitle(), $content );
4144  }
4145 
4146  if ( count( $parserOutput->getWarnings() ) ) {
4147  $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
4148  }
4149 
4150  } catch ( MWContentSerializationException $ex ) {
4151  $m = $this->context->msg(
4152  'content-failed-to-parse',
4153  $this->contentModel,
4154  $this->contentFormat,
4155  $ex->getMessage()
4156  );
4157  $note .= "\n\n" . $m->plain(); # gets parsed down below
4158  $previewHTML = '';
4159  }
4160 
4161  if ( $this->isConflict ) {
4162  $conflict = Html::rawElement(
4163  'div', [ 'id' => 'mw-previewconflict', 'class' => 'warningbox' ],
4164  $this->context->msg( 'previewconflict' )->escaped()
4165  );
4166  } else {
4167  $conflict = '';
4168  }
4169 
4170  $previewhead = Html::rawElement(
4171  'div', [ 'class' => 'previewnote' ],
4173  'h2', [ 'id' => 'mw-previewheader' ],
4174  $this->context->msg( 'preview' )->escaped()
4175  ) .
4176  Html::rawElement( 'div', [ 'class' => 'warningbox' ],
4177  $out->parseAsInterface( $note )
4178  ) . $conflict
4179  );
4180 
4181  $pageViewLang = $this->mTitle->getPageViewLanguage();
4182  $attribs = [ 'lang' => $pageViewLang->getHtmlCode(), 'dir' => $pageViewLang->getDir(),
4183  'class' => 'mw-content-' . $pageViewLang->getDir() ];
4184  $previewHTML = Html::rawElement( 'div', $attribs, $previewHTML );
4185 
4186  return $previewhead . $previewHTML . $this->previewTextAfterContent;
4187  }
4188 
4189  private function incrementEditFailureStats( $failureType ) {
4190  $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
4191  $stats->increment( 'edit.failures.' . $failureType );
4192  }
4193 
4198  protected function getPreviewParserOptions() {
4199  $parserOptions = $this->page->makeParserOptions( $this->context );
4200  $parserOptions->setIsPreview( true );
4201  $parserOptions->setIsSectionPreview( $this->section !== null && $this->section !== '' );
4202  $parserOptions->enableLimitReport();
4203 
4204  // XXX: we could call $parserOptions->setCurrentRevisionRecordCallback here to force the
4205  // current revision to be null during PST, until setupFakeRevision is called on
4206  // the ParserOptions. Currently, we rely on Parser::getRevisionRecordObject() to ignore
4207  // existing revisions in preview mode.
4208 
4209  return $parserOptions;
4210  }
4211 
4221  protected function doPreviewParse( Content $content ) {
4222  $user = $this->context->getUser();
4223  $parserOptions = $this->getPreviewParserOptions();
4224 
4225  // NOTE: preSaveTransform doesn't have a fake revision to operate on.
4226  // Parser::getRevisionRecordObject() will return null in preview mode,
4227  // causing the context user to be used for {{subst:REVISIONUSER}}.
4228  // XXX: Alternatively, we could also call setupFakeRevision() a second time:
4229  // once before PST with $content, and then after PST with $pstContent.
4230  $services = MediaWikiServices::getInstance();
4231  $contentTransformer = $services->getContentTransformer();
4232  $pstContent = $contentTransformer->preSaveTransform( $content, $this->mTitle, $user, $parserOptions );
4233  $scopedCallback = $parserOptions->setupFakeRevision( $this->mTitle, $pstContent, $user );
4234  $parserOutput = $pstContent->getParserOutput( $this->mTitle, null, $parserOptions );
4235  ScopedCallback::consume( $scopedCallback );
4236  return [
4237  'parserOutput' => $parserOutput,
4238  'html' => $parserOutput->getText( [
4239  'enableSectionEditLinks' => false
4240  ] )
4241  ];
4242  }
4243 
4247  public function getTemplates() {
4248  if ( $this->preview || $this->section != '' ) {
4249  $templates = [];
4250  if ( !isset( $this->mParserOutput ) ) {
4251  return $templates;
4252  }
4253  foreach ( $this->mParserOutput->getTemplates() as $ns => $template ) {
4254  foreach ( array_keys( $template ) as $dbk ) {
4255  $templates[] = Title::makeTitle( $ns, $dbk );
4256  }
4257  }
4258  return $templates;
4259  } else {
4260  return $this->mTitle->getTemplateLinksFrom();
4261  }
4262  }
4263 
4269  public static function getEditToolbar() {
4270  $startingToolbar = '<div id="toolbar"></div>';
4271  $toolbar = $startingToolbar;
4272 
4273  if ( !Hooks::runner()->onEditPageBeforeEditToolbar( $toolbar ) ) {
4274  return null;
4275  }
4276  // Don't add a pointless `<div>` to the page unless a hook caller populated it
4277  return ( $toolbar === $startingToolbar ) ? null : $toolbar;
4278  }
4279 
4305  public function getCheckboxesDefinition( $checked ) {
4306  $checkboxes = [];
4307 
4308  $user = $this->context->getUser();
4309  // don't show the minor edit checkbox if it's a new page or section
4310  if ( !$this->isNew && $this->permManager->userHasRight( $user, 'minoredit' ) ) {
4311  $checkboxes['wpMinoredit'] = [
4312  'id' => 'wpMinoredit',
4313  'label-message' => 'minoredit',
4314  // Uses messages: tooltip-minoredit, accesskey-minoredit
4315  'tooltip' => 'minoredit',
4316  'label-id' => 'mw-editpage-minoredit',
4317  'legacy-name' => 'minor',
4318  'default' => $checked['minor'],
4319  ];
4320  }
4321 
4322  if ( $user->isRegistered() ) {
4323  $checkboxes = array_merge(
4324  $checkboxes,
4325  $this->getCheckboxesDefinitionForWatchlist( $checked['watch'] )
4326  );
4327  }
4328 
4329  $this->getHookRunner()->onEditPageGetCheckboxesDefinition( $this, $checkboxes );
4330 
4331  return $checkboxes;
4332  }
4333 
4341  private function getCheckboxesDefinitionForWatchlist( $watch ) {
4342  $fieldDefs = [
4343  'wpWatchthis' => [
4344  'id' => 'wpWatchthis',
4345  'label-message' => 'watchthis',
4346  // Uses messages: tooltip-watch, accesskey-watch
4347  'tooltip' => 'watch',
4348  'label-id' => 'mw-editpage-watch',
4349  'legacy-name' => 'watch',
4350  'default' => $watch,
4351  ]
4352  ];
4353  if ( $this->watchlistExpiryEnabled ) {
4354  $watchedItem = $this->watchedItemStore->getWatchedItem( $this->getContext()->getUser(), $this->getTitle() );
4355  $expiryOptions = WatchAction::getExpiryOptions( $this->getContext(), $watchedItem );
4356  // When previewing, override the selected dropdown option to select whatever was posted
4357  // (if it's a valid option) rather than the current value for watchlistExpiry.
4358  // See also above in $this->importFormData().
4359  $expiryFromRequest = $this->getContext()->getRequest()->getText( 'wpWatchlistExpiry' );
4360  if ( ( $this->preview || $this->diff ) && in_array( $expiryFromRequest, $expiryOptions['options'] ) ) {
4361  $expiryOptions['default'] = $expiryFromRequest;
4362  }
4363  // Reformat the options to match what DropdownInputWidget wants.
4364  $options = [];
4365  foreach ( $expiryOptions['options'] as $label => $value ) {
4366  $options[] = [ 'data' => $value, 'label' => $label ];
4367  }
4368  $fieldDefs['wpWatchlistExpiry'] = [
4369  'id' => 'wpWatchlistExpiry',
4370  'label-message' => 'confirm-watch-label',
4371  // Uses messages: tooltip-watchlist-expiry, accesskey-watchlist-expiry
4372  'tooltip' => 'watchlist-expiry',
4373  'label-id' => 'mw-editpage-watchlist-expiry',
4374  'default' => $expiryOptions['default'],
4375  'value-attr' => 'value',
4376  'class' => DropdownInputWidget::class,
4377  'options' => $options,
4378  'invisibleLabel' => true,
4379  ];
4380  }
4381  return $fieldDefs;
4382  }
4383 
4395  public function getCheckboxesWidget( &$tabindex, $checked ) {
4396  $checkboxes = [];
4397  $checkboxesDef = $this->getCheckboxesDefinition( $checked );
4398 
4399  foreach ( $checkboxesDef as $name => $options ) {
4400  $legacyName = $options['legacy-name'] ?? $name;
4401 
4402  $title = null;
4403  $accesskey = null;
4404  if ( isset( $options['tooltip'] ) ) {
4405  $accesskey = $this->context->msg( "accesskey-{$options['tooltip']}" )->text();
4406  $title = Linker::titleAttrib( $options['tooltip'] );
4407  }
4408  if ( isset( $options['title-message'] ) ) {
4409  $title = $this->context->msg( $options['title-message'] )->text();
4410  }
4411  // Allow checkbox definitions to set their own class and value-attribute names.
4412  // See $this->getCheckboxesDefinition() for details.
4413  $className = $options['class'] ?? CheckboxInputWidget::class;
4414  $valueAttr = $options['value-attr'] ?? 'selected';
4415  $checkboxes[ $legacyName ] = new FieldLayout(
4416  new $className( [
4417  'tabIndex' => ++$tabindex,
4418  'accessKey' => $accesskey,
4419  'id' => $options['id'] . 'Widget',
4420  'inputId' => $options['id'],
4421  'name' => $name,
4422  $valueAttr => $options['default'],
4423  'infusable' => true,
4424  'options' => $options['options'] ?? null,
4425  ] ),
4426  [
4427  'align' => 'inline',
4428  'label' => new OOUI\HtmlSnippet( $this->context->msg( $options['label-message'] )->parse() ),
4429  'title' => $title,
4430  'id' => $options['label-id'] ?? null,
4431  'invisibleLabel' => $options['invisibleLabel'] ?? null,
4432  ]
4433  );
4434  }
4435 
4436  return $checkboxes;
4437  }
4438 
4445  protected function getSubmitButtonLabel() {
4446  $labelAsPublish =
4447  $this->context->getConfig()->get( 'EditSubmitButtonLabelPublish' );
4448 
4449  // Can't use $this->isNew as that's also true if we're adding a new section to an extant page
4450  $newPage = !$this->mTitle->exists();
4451 
4452  if ( $labelAsPublish ) {
4453  $buttonLabelKey = $newPage ? 'publishpage' : 'publishchanges';
4454  } else {
4455  $buttonLabelKey = $newPage ? 'savearticle' : 'savechanges';
4456  }
4457 
4458  return $buttonLabelKey;
4459  }
4460 
4471  public function getEditButtons( &$tabindex ) {
4472  $buttons = [];
4473 
4474  $labelAsPublish =
4475  $this->context->getConfig()->get( 'EditSubmitButtonLabelPublish' );
4476 
4477  $buttonLabel = $this->context->msg( $this->getSubmitButtonLabel() )->text();
4478  $buttonTooltip = $labelAsPublish ? 'publish' : 'save';
4479 
4480  $buttons['save'] = new OOUI\ButtonInputWidget( [
4481  'name' => 'wpSave',
4482  'tabIndex' => ++$tabindex,
4483  'id' => 'wpSaveWidget',
4484  'inputId' => 'wpSave',
4485  // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
4486  'useInputTag' => true,
4487  'flags' => [ 'progressive', 'primary' ],
4488  'label' => $buttonLabel,
4489  'infusable' => true,
4490  'type' => 'submit',
4491  // Messages used: tooltip-save, tooltip-publish
4492  'title' => Linker::titleAttrib( $buttonTooltip ),
4493  // Messages used: accesskey-save, accesskey-publish
4494  'accessKey' => Linker::accesskey( $buttonTooltip ),
4495  ] );
4496 
4497  $buttons['preview'] = new OOUI\ButtonInputWidget( [
4498  'name' => 'wpPreview',
4499  'tabIndex' => ++$tabindex,
4500  'id' => 'wpPreviewWidget',
4501  'inputId' => 'wpPreview',
4502  // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
4503  'useInputTag' => true,
4504  'label' => $this->context->msg( 'showpreview' )->text(),
4505  'infusable' => true,
4506  'type' => 'submit',
4507  // Message used: tooltip-preview
4508  'title' => Linker::titleAttrib( 'preview' ),
4509  // Message used: accesskey-preview
4510  'accessKey' => Linker::accesskey( 'preview' ),
4511  ] );
4512 
4513  $buttons['diff'] = new OOUI\ButtonInputWidget( [
4514  'name' => 'wpDiff',
4515  'tabIndex' => ++$tabindex,
4516  'id' => 'wpDiffWidget',
4517  'inputId' => 'wpDiff',
4518  // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
4519  'useInputTag' => true,
4520  'label' => $this->context->msg( 'showdiff' )->text(),
4521  'infusable' => true,
4522  'type' => 'submit',
4523  // Message used: tooltip-diff
4524  'title' => Linker::titleAttrib( 'diff' ),
4525  // Message used: accesskey-diff
4526  'accessKey' => Linker::accesskey( 'diff' ),
4527  ] );
4528 
4529  $this->getHookRunner()->onEditPageBeforeEditButtons( $this, $buttons, $tabindex );
4530 
4531  return $buttons;
4532  }
4533 
4538  private function noSuchSectionPage() {
4539  $out = $this->context->getOutput();
4540  $out->prepareErrorPage( $this->context->msg( 'nosuchsectiontitle' ) );
4541 
4542  $res = $this->context->msg( 'nosuchsectiontext', $this->section )->parseAsBlock();
4543 
4544  $this->getHookRunner()->onEditPageNoSuchSection( $this, $res );
4545  $out->addHTML( $res );
4546 
4547  $out->returnToMain( false, $this->mTitle );
4548  }
4549 
4555  public function spamPageWithContent( $match = false ) {
4556  $this->textbox2 = $this->textbox1;
4557 
4558  if ( is_array( $match ) ) {
4559  $match = $this->context->getLanguage()->listToText( $match );
4560  }
4561  $out = $this->context->getOutput();
4562  $out->prepareErrorPage( $this->context->msg( 'spamprotectiontitle' ) );
4563 
4564  $out->addHTML( '<div id="spamprotected">' );
4565  $out->addWikiMsg( 'spamprotectiontext' );
4566  if ( $match ) {
4567  // @phan-suppress-next-line SecurityCheck-DoubleEscaped false positive
4568  $out->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
4569  }
4570  $out->addHTML( '</div>' );
4571 
4572  $out->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
4573  $this->showDiff();
4574 
4575  $out->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
4576  $this->showTextbox2();
4577 
4578  $out->addReturnTo( $this->getContextTitle(), [ 'action' => 'edit' ] );
4579  }
4580 
4584  protected function addEditNotices() {
4585  $out = $this->context->getOutput();
4586  $editNotices = $this->mTitle->getEditNotices( $this->oldid );
4587  if ( count( $editNotices ) ) {
4588  $out->addHTML( implode( "\n", $editNotices ) );
4589  } else {
4590  $msg = $this->context->msg( 'editnotice-notext' );
4591  if ( !$msg->isDisabled() ) {
4592  $out->addHTML(
4593  '<div class="mw-editnotice-notext">'
4594  . $msg->parseAsBlock()
4595  . '</div>'
4596  );
4597  }
4598  }
4599  }
4600 
4604  protected function addTalkPageText() {
4605  if ( $this->mTitle->isTalkPage() ) {
4606  $this->context->getOutput()->addWikiMsg( 'talkpagetext' );
4607  }
4608  }
4609 
4613  protected function addLongPageWarningHeader() {
4614  if ( $this->contentLength === false ) {
4615  $this->contentLength = strlen( $this->textbox1 );
4616  }
4617 
4618  $out = $this->context->getOutput();
4619  $lang = $this->context->getLanguage();
4620  $maxArticleSize = $this->context->getConfig()->get( 'MaxArticleSize' );
4621  if ( $this->tooBig || $this->contentLength > $maxArticleSize * 1024 ) {
4622  $out->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
4623  [
4624  'longpageerror',
4625  $lang->formatNum( round( $this->contentLength / 1024, 3 ) ),
4626  $lang->formatNum( $maxArticleSize )
4627  ]
4628  );
4629  } else {
4630  $longPageHint = $this->context->msg( 'longpage-hint' );
4631  if ( !$longPageHint->isDisabled() ) {
4632  $msgText = trim( $longPageHint->params( $lang->formatSize( $this->contentLength ),
4633  $this->contentLength )->text() );
4634  if ( $msgText !== '' && $msgText !== '-' ) {
4635  $out->addWikiTextAsInterface( "<div id='mw-edit-longpage-hint'>\n$msgText\n</div>" );
4636  }
4637  }
4638  }
4639  }
4640 
4644  protected function addPageProtectionWarningHeaders() {
4645  $out = $this->context->getOutput();
4646  if ( $this->mTitle->isProtected( 'edit' ) &&
4647  $this->permManager->getNamespaceRestrictionLevels(
4648  $this->getTitle()->getNamespace()
4649  ) !== [ '' ]
4650  ) {
4651  # Is the title semi-protected?
4652  if ( $this->mTitle->isSemiProtected() ) {
4653  $noticeMsg = 'semiprotectedpagewarning';
4654  } else {
4655  # Then it must be protected based on static groups (regular)
4656  $noticeMsg = 'protectedpagewarning';
4657  }
4658  LogEventsList::showLogExtract( $out, 'protect', $this->mTitle, '',
4659  [ 'lim' => 1, 'msgKey' => [ $noticeMsg ] ] );
4660  }
4661  if ( $this->mTitle->isCascadeProtected() ) {
4662  # Is this page under cascading protection from some source pages?
4663 
4664  list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources();
4665  $notice = "<div class='warningbox mw-cascadeprotectedwarning'>\n$1\n";
4666  $cascadeSourcesCount = count( $cascadeSources );
4667  if ( $cascadeSourcesCount > 0 ) {
4668  # Explain, and list the titles responsible
4669  foreach ( $cascadeSources as $page ) {
4670  $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
4671  }
4672  }
4673  $notice .= '</div>';
4674  $out->wrapWikiMsg( $notice, [ 'cascadeprotectedwarning', $cascadeSourcesCount ] );
4675  }
4676  if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
4677  LogEventsList::showLogExtract( $out, 'protect', $this->mTitle, '',
4678  [ 'lim' => 1,
4679  'showIfEmpty' => false,
4680  'msgKey' => [ 'titleprotectedwarning' ],
4681  'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ] );
4682  }
4683  }
4684 
4689  protected function addExplainConflictHeader( OutputPage $out ) {
4690  $out->addHTML(
4691  $this->getEditConflictHelper()->getExplainHeader()
4692  );
4693  }
4694 
4700  protected function addNewLineAtEnd( $wikitext ) {
4701  return ( new TextboxBuilder() )->addNewLineAtEnd( $wikitext );
4702  }
4703 
4714  private function guessSectionName( $text ) {
4715  // Detect Microsoft browsers
4716  $userAgent = $this->context->getRequest()->getHeader( 'User-Agent' );
4717  $parser = MediaWikiServices::getInstance()->getParser();
4718  if ( $userAgent && preg_match( '/MSIE|Edge/', $userAgent ) ) {
4719  // ...and redirect them to legacy encoding, if available
4720  return $parser->guessLegacySectionNameFromWikiText( $text );
4721  }
4722  // Meanwhile, real browsers get real anchors
4723  $name = $parser->guessSectionNameFromWikiText( $text );
4724  // With one little caveat: per T216029, fragments in HTTP redirects need to be urlencoded,
4725  // otherwise Chrome double-escapes the rest of the URL.
4726  return '#' . urlencode( mb_substr( $name, 1 ) );
4727  }
4728 
4735  public function setEditConflictHelperFactory( callable $factory ) {
4736  $this->editConflictHelperFactory = $factory;
4737  $this->editConflictHelper = null;
4738  }
4739 
4743  private function getEditConflictHelper() {
4744  if ( !$this->editConflictHelper ) {
4745  $this->editConflictHelper = call_user_func(
4746  $this->editConflictHelperFactory,
4747  $this->getSubmitButtonLabel()
4748  );
4749  }
4750 
4752  }
4753 
4759  private function newTextConflictHelper( $submitButtonLabel ) {
4760  return new TextConflictHelper(
4761  $this->getTitle(),
4762  $this->getContext()->getOutput(),
4763  MediaWikiServices::getInstance()->getStatsdDataFactory(),
4764  $submitButtonLabel,
4765  MediaWikiServices::getInstance()->getContentHandlerFactory()
4766  );
4767  }
4768 }
ReadOnlyError
Show an error when the wiki is locked/read-only and the user tries to do something that requires writ...
Definition: ReadOnlyError.php:29
EditPage\__construct
__construct(Article $article)
Definition: EditPage.php:428
EditPage\$editFormTextBeforeContent
$editFormTextBeforeContent
Definition: EditPage.php:341
MediaWiki\EditPage\IEditObject\AS_READ_ONLY_PAGE_ANON
const AS_READ_ONLY_PAGE_ANON
Status: this anonymous user is not allowed to edit this page.
Definition: IEditObject.php:50
Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition: PageIdentity.php:64
EditPage\$mTriedSave
bool $mTriedSave
Definition: EditPage.php:173
MediaWiki\EditPage\IEditObject\AS_ARTICLE_WAS_DELETED
const AS_ARTICLE_WAS_DELETED
Status: article was deleted while editing and wpRecreate == false or form was not posted.
Definition: IEditObject.php:62
EDIT_AUTOSUMMARY
const EDIT_AUTOSUMMARY
Definition: Defines.php:131
CommentStoreComment\newUnsavedComment
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
Definition: CommentStoreComment.php:67
MediaWiki\Revision\RevisionRecord\getContent
getContent( $role, $audience=self::FOR_PUBLIC, Authority $performer=null)
Returns the Content of the given slot of this revision.
Definition: RevisionRecord.php:156
EditPage\$watchlistManager
WatchlistManager $watchlistManager
Definition: EditPage.php:417
EditPage\$contentModel
string $contentModel
Definition: EditPage.php:327
EditPage\showFormBeforeText
showFormBeforeText()
Definition: EditPage.php:3505
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:382
EditPage\$lastDelete
bool stdClass $lastDelete
Definition: EditPage.php:167
EditPage\tokenOk
tokenOk(&$request)
Make sure the form isn't faking a user's credentials.
Definition: EditPage.php:1635
EditPage\$editFormPageTop
string $editFormPageTop
Before even the preview.
Definition: EditPage.php:339
MediaWiki\EditPage\IEditObject\AS_SUCCESS_NEW_ARTICLE
const AS_SUCCESS_NEW_ARTICLE
Status: Article successfully created.
Definition: IEditObject.php:35
EditPage\showContentForm
showContentForm()
Subpage overridable method for printing the form for page content editing By default this simply outp...
Definition: EditPage.php:3542
EditPage\$mTitle
Title $mTitle
Definition: EditPage.php:137
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
EditPage\$watchlistExpiryEnabled
bool $watchlistExpiryEnabled
Corresponds to $wgWatchlistExpiry.
Definition: EditPage.php:244
MediaWiki\EditPage\IEditObject\AS_BLOCKED_PAGE_FOR_USER
const AS_BLOCKED_PAGE_FOR_USER
Status: User is blocked from editing this page.
Definition: IEditObject.php:44
Html\linkButton
static linkButton( $text, array $attrs, array $modifiers=[])
Returns an HTML link element in a string styled as a button (when $wgUseMediaWikiUIEverywhere is enab...
Definition: Html.php:166
Html\textarea
static textarea( $name, $value='', array $attribs=[])
Convenience function to produce a <textarea> element.
Definition: Html.php:847
EditPage\spamPageWithContent
spamPageWithContent( $match=false)
Show "your edit contains spam" page with your diff and text.
Definition: EditPage.php:4555
MediaWiki\EditPage\IEditObject\AS_TEXTBOX_EMPTY
const AS_TEXTBOX_EMPTY
Status: user tried to create a new section without content.
Definition: IEditObject.php:80
EditPage\$section
string $section
Definition: EditPage.php:292
ParserOutput
Definition: ParserOutput.php:32
StatusValue\newFatal
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:70
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:72
WikiPage\getRedirectTarget
getRedirectTarget()
If this page is a redirect, get its target.
Definition: WikiPage.php:1023
UserBlockedError
Show an error when the user tries to do something whilst blocked.
Definition: UserBlockedError.php:32
MediaWiki\EditPage\IEditObject\AS_SUMMARY_NEEDED
const AS_SUMMARY_NEEDED
Status: no edit summary given and the user has forceeditsummary set and the user is not editing in hi...
Definition: IEditObject.php:77
MediaWiki\EditPage\IEditObject\AS_CONFLICT_DETECTED
const AS_CONFLICT_DETECTED
Status: (non-resolvable) edit conflict.
Definition: IEditObject.php:71
EditPage\displayPermissionsError
displayPermissionsError(array $permErrors)
Display a permissions error page, like OutputPage::showPermissionsErrorPage(), but with the following...
Definition: EditPage.php:768
MediaWiki\EditPage\IEditObject\AS_CANNOT_USE_CUSTOM_MODEL
const AS_CANNOT_USE_CUSTOM_MODEL
Status: when changing the content model is disallowed due to $wgContentHandlerUseDB being false.
Definition: IEditObject.php:118
EditPage\$editFormTextAfterContent
$editFormTextAfterContent
Definition: EditPage.php:345
EditPage\displayPreviewArea
displayPreviewArea( $previewOutput, $isOnTop=false)
Definition: EditPage.php:3603
MediaWiki\EditPage\Constraint\EditConstraintRunner
Back end to process the edit constraints.
Definition: EditConstraintRunner.php:36
EditPage\$blankArticle
bool $blankArticle
Definition: EditPage.php:191
EditPage\$allowBlankSummary
bool $allowBlankSummary
Definition: EditPage.php:188
$wgRightsText
$wgRightsText
If either $wgRightsUrl or $wgRightsPage is specified then this variable gives the text for the link.
Definition: DefaultSettings.php:8323
EditPage\$editFormTextBottom
$editFormTextBottom
Definition: EditPage.php:344
EditPage\getSummaryInputAttributes
getSummaryInputAttributes(array $inputAttrs=null)
Helper function for summary input functions, which returns the necessary attributes for the input.
Definition: EditPage.php:3402
EditPage\$editFormTextTop
$editFormTextTop
Definition: EditPage.php:340
EditPage\$editintro
string $editintro
Definition: EditPage.php:318
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:193
EditPage\showTextbox2
showTextbox2()
Definition: EditPage.php:3585
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
EditPage\$summary
string $summary
Definition: EditPage.php:264
MediaWiki\Revision\RevisionStore
Service for looking up page revisions.
Definition: RevisionStore.php:88
EditPage\$textbox2
string $textbox2
Definition: EditPage.php:261
EditPage\getPreloadedContent
getPreloadedContent( $preload, $params=[])
Get the contents to be preloaded into the box, either set by an earlier setPreloadText() or by loadin...
Definition: EditPage.php:1552
EditPage\$mTokenOk
bool $mTokenOk
Definition: EditPage.php:170
EditPage\$contentHandlerFactory
IContentHandlerFactory $contentHandlerFactory
Definition: EditPage.php:397
MediaWiki\EditPage\Constraint\ContentModelChangeConstraint
Verify user permissions if changing content model: Must have editcontentmodel rights Must be able to ...
Definition: ContentModelChangeConstraint.php:36
EditPage\getUndoContent
getUndoContent(RevisionRecord $undoRev, RevisionRecord $oldRev)
Returns the result of a three-way merge when undoing changes.
Definition: EditPage.php:1449
MediaWiki\EditPage\Constraint\UserRateLimitConstraint
Verify user doesn't exceed rate limits.
Definition: UserRateLimitConstraint.php:34
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1668
MediaWiki\EditPage\Constraint\PageSizeConstraint
Verify the page isn't larger than the maximum.
Definition: PageSizeConstraint.php:36
EditPage\$oldid
int $oldid
Revision ID the edit is based on, or 0 if it's the current revision.
Definition: EditPage.php:307
MediaWiki\EditPage\TextboxBuilder
Helps EditPage build textboxes.
Definition: TextboxBuilder.php:38
EditPage\getContextTitle
getContextTitle()
Definition: EditPage.php:514
EditPage\getEditToolbar
static getEditToolbar()
Allow extensions to provide a toolbar.
Definition: EditPage.php:4269
MediaWiki\EditPage\Constraint\UserBlockConstraint
Verify user permissions: Must not be blocked from the page.
Definition: UserBlockConstraint.php:36
MediaWiki\EditPage\IEditObject\AS_SPAM_ERROR
const AS_SPAM_ERROR
Status: summary contained spam according to one of the regexes in $wgSummarySpamRegex.
Definition: IEditObject.php:89
EditPage\showTosSummary
showTosSummary()
Give a chance for site and per-namespace customizations of terms of service summary link that might e...
Definition: EditPage.php:3746
CategoryPage
Special handling for category description pages, showing pages, subcategories and file that belong to...
Definition: CategoryPage.php:30
EditPage\$page
WikiPage $page
Definition: EditPage.php:131
EditPage\$save
bool $save
Definition: EditPage.php:229
WatchAction\getExpiryOptions
static getExpiryOptions(MessageLocalizer $msgLocalizer, $watchedItem)
Get options and default for a watchlist expiry select list.
Definition: WatchAction.php:148
EditPage\addPageProtectionWarningHeaders
addPageProtectionWarningHeaders()
Definition: EditPage.php:4644
EditPage\getExpectedParentRevision
getExpectedParentRevision()
Returns the RevisionRecord corresponding to the revision that was current at the time editing was ini...
Definition: EditPage.php:2598
EditPage\setContextTitle
setContextTitle( $title)
Definition: EditPage.php:506
EditPage\handleFailedConstraint
handleFailedConstraint(IEditConstraint $failed)
Apply the specific updates needed for the EditPage fields based on which constraint failed,...
Definition: EditPage.php:2424
getAuthority
getAuthority()
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:60
EditPage\edit
edit()
This is the function that gets called for "action=edit".
Definition: EditPage.php:555
ParserOptions\newFromUserAndLang
static newFromUserAndLang(UserIdentity $user, Language $lang)
Get a ParserOptions object from a given user and language.
Definition: ParserOptions.php:1087
EditPage\$autoSumm
string $autoSumm
Definition: EditPage.php:203
MediaWiki\EditPage\IEditObject\AS_END
const AS_END
Status: WikiPage::doEdit() was unsuccessful.
Definition: IEditObject.php:86
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
EditPage\getLastDelete
getLastDelete()
Get the last log record of this page being deleted, if ever.
Definition: EditPage.php:3993
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1101
EditPage\incrementConflictStats
incrementConflictStats()
Definition: EditPage.php:3921
EditPage\addEditNotices
addEditNotices()
Definition: EditPage.php:4584
MediaWiki\Permissions\Authority\authorizeRead
authorizeRead(string $action, PageIdentity $target, PermissionStatus $status=null)
Authorize read access.
User\newFromName
static newFromName( $name, $validate='valid')
Definition: User.php:606
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1186
EditPage\newSectionSummary
newSectionSummary()
Return the summary to be used for a new section.
Definition: EditPage.php:1853
EditPage\$editFormTextAfterTools
$editFormTextAfterTools
Definition: EditPage.php:343
EditPage\addContentModelChangeLogEntry
addContentModelChangeLogEntry(UserIdentity $user, $oldModel, $newModel, $reason)
Definition: EditPage.php:2506
MediaWiki\EditPage\Constraint\SpamRegexConstraint
Verify summary and text do not match spam regexes.
Definition: SpamRegexConstraint.php:35
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:107
EditPage\getEditPermissionErrors
getEditPermissionErrors( $rigor=PermissionManager::RIGOR_SECURE)
Definition: EditPage.php:730
EditPage\$editFormTextAfterWarn
$editFormTextAfterWarn
Definition: EditPage.php:342
MediaWiki\EditPage\Constraint\EditFilterMergedContentHookConstraint
Verify EditFilterMergedContent hook.
Definition: EditFilterMergedContentHookConstraint.php:37
MediaWiki\EditPage\IEditObject\AS_CONTENT_TOO_BIG
const AS_CONTENT_TOO_BIG
Status: Content too big (> $wgMaxArticleSize)
Definition: IEditObject.php:47
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition: PermissionsError.php:32
MediaWiki\EditPage\IEditObject\AS_NO_CREATE_PERMISSION
const AS_NO_CREATE_PERMISSION
Status: user tried to create this page, but is not allowed to do that.
Definition: IEditObject.php:65
MediaWiki\EditPage\IEditObject\AS_SUCCESS_UPDATE
const AS_SUCCESS_UPDATE
Status: Article successfully updated.
Definition: IEditObject.php:32
MediaWiki\EditPage\TextConflictHelper\setContentFormat
setContentFormat( $contentFormat)
Definition: TextConflictHelper.php:139
EditPage\showHeaderCopyrightWarning
showHeaderCopyrightWarning()
Definition: EditPage.php:3730
MediaWiki\EditPage\Constraint\AutoSummaryMissingSummaryConstraint
For an edit to an existing page but not with a new section, do not allow the user to post with a summ...
Definition: AutoSummaryMissingSummaryConstraint.php:41
MediaWiki\EditPage\Constraint\DefaultTextConstraint
Don't save a new page if it's blank or if it's a MediaWiki: message with content equivalent to defaul...
Definition: DefaultTextConstraint.php:35
EditPage\getCheckboxesDefinitionForWatchlist
getCheckboxesDefinitionForWatchlist( $watch)
Get the watchthis and watchlistExpiry form field definitions.
Definition: EditPage.php:4341
Html\warningBox
static warningBox( $html, $className='')
Return a warning box.
Definition: Html.php:755
EditPage\$mExpectedParentRevision
RevisionRecord bool null $mExpectedParentRevision
A RevisionRecord corresponding to $this->editRevId or $this->edittime.
Definition: EditPage.php:221
EditPage\$userNameUtils
UserNameUtils $userNameUtils
Definition: EditPage.php:422
EditPage\addLongPageWarningHeader
addLongPageWarningHeader()
Definition: EditPage.php:4613
EditPage\$context
IContextSource $context
Definition: EditPage.php:370
$res
$res
Definition: testCompression.php:57
EditPage\$didSave
$didSave
Definition: EditPage.php:350
$wgUseRCPatrol
$wgUseRCPatrol
Use RC Patrolling to check for vandalism (from recent changes and watchlists) New pages and new files...
Definition: DefaultSettings.php:8040
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:110
$wgUseNPPatrol
$wgUseNPPatrol
Use new page patrolling to check new pages on Special:Newpages.
Definition: DefaultSettings.php:8056
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
OutputPage\addHTML
addHTML( $text)
Append $text to the body HTML.
Definition: OutputPage.php:1627
Wikimedia\Message\MessageValue
Value object representing a message for i18n.
Definition: MessageValue.php:16
Linker\formatHiddenCategories
static formatHiddenCategories( $hiddencats)
Returns HTML for the "hidden categories on this page" list.
Definition: Linker.php:2241
EditPage\$mArticle
Article $mArticle
Definition: EditPage.php:128
EditPage\$contentFormat
null string $contentFormat
Definition: EditPage.php:330
EditPage\POST_EDIT_COOKIE_DURATION
const POST_EDIT_COOKIE_DURATION
Duration of PostEdit cookie, in seconds.
Definition: EditPage.php:122
$dbr
$dbr
Definition: testCompression.php:54
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:44
EditPage\$editConflictHelper
TextConflictHelper null $editConflictHelper
Definition: EditPage.php:392
EditPage\$watchthis
bool $watchthis
Definition: EditPage.php:241
EditPage\$previewTextAfterContent
$previewTextAfterContent
Definition: EditPage.php:346
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:316
EditPage\showDiff
showDiff()
Get a diff between the current contents of the edit box and the version of the page we're editing fro...
Definition: EditPage.php:3669
EditPage\$tooBig
bool $tooBig
Definition: EditPage.php:179
Status\getWikiText
getWikiText( $shortContext=false, $longContext=false, $lang=null)
Get the error list as a wikitext formatted list.
Definition: Status.php:189
Config
Interface for configuration instances.
Definition: Config.php:30
MediaWiki\Block\DatabaseBlock
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
Definition: DatabaseBlock.php:52
Wikimedia\ParamValidator\TypeDef\ExpiryDef
Type definition for expiry timestamps.
Definition: ExpiryDef.php:17
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:32
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:212
MediaWiki\EditPage\IEditObject\AS_RATE_LIMITED
const AS_RATE_LIMITED
Status: rate limiter for action 'edit' was tripped.
Definition: IEditObject.php:59
EditPage\UNICODE_CHECK
const UNICODE_CHECK
Used for Unicode support checks.
Definition: EditPage.php:96
MWException
MediaWiki exception.
Definition: MWException.php:29
EditPage\toEditContent
toEditContent( $text)
Turns the given text into a Content object by unserializing it.
Definition: EditPage.php:2885
Article\getTitle
getTitle()
Get the title object of the article.
Definition: Article.php:224
EditPage\getEditButtons
getEditButtons(&$tabindex)
Returns an array of html code of the following buttons: save, diff and preview.
Definition: EditPage.php:4471
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Definition: GlobalFunctions.php:997
MediaWiki\EditPage\Constraint\CreationPermissionConstraint
Verify be able to create the page in question if it is a new page.
Definition: CreationPermissionConstraint.php:34
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
LogPage\DELETED_COMMENT
const DELETED_COMMENT
Definition: LogPage.php:40
WikiPage\hasDifferencesOutsideMainSlot
static hasDifferencesOutsideMainSlot(RevisionRecord $a, RevisionRecord $b)
Helper method for checking whether two revisions have differences that go beyond the main slot.
Definition: WikiPage.php:1534
EditPage\$editRevId
int $editRevId
Revision ID of the latest revision of the page when editing was initiated on the client.
Definition: EditPage.php:289
EditPage\showSummaryInput
showSummaryInput( $isSubjectPreview, $summary="")
Definition: EditPage.php:3458
MediaWiki\Watchlist\WatchlistManager
WatchlistManager service.
Definition: WatchlistManager.php:52
EditPage\getParentRevId
getParentRevId()
Get the edit's parent revision ID.
Definition: EditPage.php:1509
wfArrayDiff2
wfArrayDiff2( $a, $b)
Like array_diff( $a, $b ) except that it works with two-dimensional arrays.
Definition: GlobalFunctions.php:113
MediaWiki\EditPage\Constraint\MissingCommentConstraint
Do not allow the user to post an empty comment (only used for new section)
Definition: MissingCommentConstraint.php:32
EditPage\isSectionEditSupported
isSectionEditSupported()
Section editing is supported when the page content model allows section edit and we are editing curre...
Definition: EditPage.php:916
EditPage\importFormData
importFormData(&$request)
This function collects the form data and uses it to populate various member variables.
Definition: EditPage.php:935
Status\wrap
static wrap( $sv)
Succinct helper method to wrap a StatusValue.
Definition: Status.php:62
EditPage\getActionURL
getActionURL(Title $title)
Returns the URL to use in the form's action attribute.
Definition: EditPage.php:3957
EditPage\addExplainConflictHeader
addExplainConflictHeader(OutputPage $out)
Definition: EditPage.php:4689
LogPage\DELETED_USER
const DELETED_USER
Definition: LogPage.php:41
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2203
EditPage\showIntro
showIntro()
Show all applicable editing introductions.
Definition: EditPage.php:2683
EditPage\$firsttime
bool $firsttime
True the first time the edit form is rendered, false after re-rendering with diff,...
Definition: EditPage.php:164
$matches
$matches
Definition: NoLocalSettings.php:24
EditPage\$missingComment
bool $missingComment
Definition: EditPage.php:182
MediaWiki\EditPage\IEditObject\AS_SELF_REDIRECT
const AS_SELF_REDIRECT
Status: user tried to create self-redirect and wpIgnoreSelfRedirect is false.
Definition: IEditObject.php:104
EditPage\getPreviewLimitReport
static getPreviewLimitReport(ParserOutput $output=null)
Get the Limit report for page previews.
Definition: EditPage.php:3813
EditPage\$editConflictHelperFactory
callable $editConflictHelperFactory
Factory function to create an edit conflict helper.
Definition: EditPage.php:387
MWContentSerializationException
Exception representing a failure to serialize or unserialize a content object.
Definition: MWContentSerializationException.php:8
EditPage\attemptSave
attemptSave(&$resultDetails=false)
Attempt submission.
Definition: EditPage.php:1677
WikiPage\exists
exists()
Definition: WikiPage.php:596
Xml\element
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:41
Article\getPage
getPage()
Get the WikiPage object of this instance.
Definition: Article.php:234
Article\getContext
getContext()
Gets the context this Article is executed in.
Definition: Article.php:1957
EDIT_NEW
const EDIT_NEW
Definition: Defines.php:125
EditPage\getArticle
getArticle()
Definition: EditPage.php:483
MediaWiki\EditPage\Constraint\ImageRedirectConstraint
Verify user permissions: If creating a redirect in the file namespace, must have upload rights.
Definition: ImageRedirectConstraint.php:36
Page\WikiPageFactory
Definition: WikiPageFactory.php:20
ThrottledError
Show an error when the user hits a rate limit.
Definition: ThrottledError.php:28
EditPage\getCheckboxesWidget
getCheckboxesWidget(&$tabindex, $checked)
Returns an array of checkboxes for the edit form, including 'minor' and 'watch' checkboxes and any ot...
Definition: EditPage.php:4395
EditPage\previewOnOpen
previewOnOpen()
Should we show a preview when the edit form is first shown?
Definition: EditPage.php:854
EditPage\incrementEditFailureStats
incrementEditFailureStats( $failureType)
Definition: EditPage.php:4189
$title
$title
Definition: testCompression.php:38
EditPage\$allowSelfRedirect
bool $allowSelfRedirect
Definition: EditPage.php:200
EditPage\showEditForm
showEditForm( $formCallback=null)
Send the edit form and related headers to OutputPage.
Definition: EditPage.php:2908
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:650
LogEventsList\showLogExtract
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Definition: LogEventsList.php:597
EditPage\isUndoClean
isUndoClean(Content $content)
Does sanity checks and compares the automatically generated undo content with the one that was submit...
Definition: EditPage.php:2459
EditPage\wasDeletedSinceLastEdit
wasDeletedSinceLastEdit()
Check if a page was deleted while the user was editing it, before submit.
Definition: EditPage.php:3968
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
EditPage\getTemplates
getTemplates()
Definition: EditPage.php:4247
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1697
EditPage\getPreviewParserOptions
getPreviewParserOptions()
Get parser options for a preview.
Definition: EditPage.php:4198
EditPage\$mContextTitle
null Title $mContextTitle
Definition: EditPage.php:140
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:894
EditPage\showFormAfterText
showFormAfterText()
Definition: EditPage.php:3514
EditPage\getCancelLink
getCancelLink( $tabindex=0)
Definition: EditPage.php:3929
OutputPage
This is one of the Core classes and should be read at least once by any new developers.
Definition: OutputPage.php:50
EditPage\showPreview
showPreview( $text)
Append preview output to OutputPage.
Definition: EditPage.php:3648
Html\errorBox
static errorBox( $html, $heading='', $className='')
Return an error box.
Definition: Html.php:768
EditPage\initialiseForm
initialiseForm()
Initialise form fields in the object Called on the first invocation, e.g.
Definition: EditPage.php:1183
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:146
deprecatePublicProperty
deprecatePublicProperty( $property, $version, $class=null, $component=null)
Mark a property as deprecated.
Definition: DeprecationHelper.php:94
MediaWiki\EditPage\Constraint\SelfRedirectConstraint
Verify the page does not redirect to itself unless.
Definition: SelfRedirectConstraint.php:35
EditPage\mergeChangesIntoContent
mergeChangesIntoContent( $editContent)
Attempts to do 3-way merge of edit content with a base revision and current content,...
Definition: EditPage.php:2553
MediaWiki\Storage\EditResult
Object for storing information about the effects of an edit.
Definition: EditResult.php:38
MediaWiki\EditPage\TextConflictHelper\setTextboxes
setTextboxes( $yourtext, $storedversion)
Definition: TextConflictHelper.php:124
MediaWiki\EditPage\TextConflictHelper
Helper for displaying edit conflicts in text content models to users.
Definition: TextConflictHelper.php:44
EditPage\internalAttemptSave
internalAttemptSave(&$result, $markAsBot=false, $markAsMinor=false)
Attempt submission (no UI)
Definition: EditPage.php:1909
MediaWiki\Permissions\Authority
This interface represents the authority associated the current execution context, such as a web reque...
Definition: Authority.php:37
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:831
EditPage\$recreate
bool $recreate
Definition: EditPage.php:253
MediaWiki\EditPage\IEditObject\AS_UNICODE_NOT_SUPPORTED
const AS_UNICODE_NOT_SUPPORTED
Status: edit rejected because browser doesn't support Unicode.
Definition: IEditObject.php:121
EditPage\$contentLength
bool int $contentLength
Definition: EditPage.php:360
MediaWiki\EditPage\IEditObject\AS_NO_CHANGE_CONTENT_MODEL
const AS_NO_CHANGE_CONTENT_MODEL
Status: user tried to modify the content model, but is not allowed to do that ( User::isAllowed('edit...
Definition: IEditObject.php:101
MediaWiki\EditPage\IEditObject\AS_READ_ONLY_PAGE_LOGGED
const AS_READ_ONLY_PAGE_LOGGED
Status: this logged in user is not allowed to edit this page.
Definition: IEditObject.php:53
EditPage\showTextbox1
showTextbox1( $customAttribs=null, $textoverride=null)
Method to output wpTextbox1 The $textoverride method can be used by subclasses overriding showContent...
Definition: EditPage.php:3554
MediaWiki\EditPage\Constraint\AccidentalRecreationConstraint
Make sure user doesn't accidentally recreate a page deleted after they started editing.
Definition: AccidentalRecreationConstraint.php:32
EditPage\addTalkPageText
addTalkPageText()
Definition: EditPage.php:4604
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:53
$content
$content
Definition: router.php:76
EditPage\getSummaryPreview
getSummaryPreview( $isSubjectPreview, $summary="")
Definition: EditPage.php:3484
EditPage\importContentFormData
importContentFormData(&$request)
Subpage overridable method for extracting the page content data from the posted form to be placed in ...
Definition: EditPage.php:1174
EditPage\$minoredit
bool $minoredit
Definition: EditPage.php:238
EditPage\$isOldRev
bool $isOldRev
Whether an old revision is edited.
Definition: EditPage.php:375
TemplatesOnThisPageFormatter
Handles formatting for the "templates used on this page" lists.
Definition: TemplatesOnThisPageFormatter.php:32
ExternalUserNames\getUserLinkTitle
static getUserLinkTitle( $userName)
Get a target Title to link a username.
Definition: ExternalUserNames.php:63
EditPage\$enableApiEditOverride
bool $enableApiEditOverride
Set in ApiEditPage, based on ContentHandler::allowsDirectApiEditing.
Definition: EditPage.php:365
WikiPage\getContent
getContent( $audience=RevisionRecord::FOR_PUBLIC, Authority $performer=null)
Get the content of the current revision.
Definition: WikiPage.php:837
EditPage\showHeader
showHeader()
Definition: EditPage.php:3218
MediaWiki\EditPage\TextConflictHelper\getEditFormHtmlAfterContent
getEditFormHtmlAfterContent()
Content to go in the edit form after textbox1.
Definition: TextConflictHelper.php:264
ContentHandler\getLocalizedName
static getLocalizedName( $name, Language $lang=null)
Returns the localized name for a given content model.
Definition: ContentHandler.php:307
Linker\commentBlock
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...
Definition: Linker.php:1749
EditPage\addNewLineAtEnd
addNewLineAtEnd( $wikitext)
Definition: EditPage.php:4700
MediaWiki\Content\IContentHandlerFactory
Definition: IContentHandlerFactory.php:10
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
MediaWiki\EditPage\IEditObject\AS_IMAGE_REDIRECT_ANON
const AS_IMAGE_REDIRECT_ANON
Status: anonymous user is not allowed to upload (User::isAllowed('upload') == false)
Definition: IEditObject.php:92
Message\plaintextParam
static plaintextParam( $plaintext)
Definition: Message.php:1184
EditPage\incrementResolvedConflicts
incrementResolvedConflicts()
Log when a page was successfully saved after the edit conflict view.
Definition: EditPage.php:1696
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
Xml\tags
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:132
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:173
EditPage\showEditTools
showEditTools()
Inserts optional text shown below edit and upload forms.
Definition: EditPage.php:3761
EditPage\$preview
bool $preview
Definition: EditPage.php:232
EditPage\$isNew
bool $isNew
New page or new section.
Definition: EditPage.php:152
EditPage\getCheckboxesDefinition
getCheckboxesDefinition( $checked)
Return an array of checkbox definitions.
Definition: EditPage.php:4305
MediaWiki\EditPage\Constraint\NewSectionMissingSummaryConstraint
For a new section, do not allow the user to post with an empty summary unless they choose to.
Definition: NewSectionMissingSummaryConstraint.php:32
EditPage\getCopywarn
getCopywarn()
Get the copyright warning.
Definition: EditPage.php:3773
EditPage\setApiEditOverride
setApiEditOverride( $enableOverride)
Allow editing of content that supports API direct editing, but not general direct editing.
Definition: EditPage.php:540
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1459
EditPage\$watchlistExpiry
string null $watchlistExpiry
The expiry time of the watch item, or null if it is not watched temporarily.
Definition: EditPage.php:250
EditPage\newTextConflictHelper
newTextConflictHelper( $submitButtonLabel)
Definition: EditPage.php:4759
EditPage\showCustomIntro
showCustomIntro()
Attempt to show a custom editing introduction, if supplied.
Definition: EditPage.php:2823
EditPage\getContext
getContext()
Definition: EditPage.php:491
MediaWiki\Revision\RevisionStoreRecord
A RevisionRecord representing an existing revision persisted in the revision table.
Definition: RevisionStoreRecord.php:39
NS_USER
const NS_USER
Definition: Defines.php:66
EditPage\EDITFORM_ID
const EDITFORM_ID
HTML id and name for the beginning of the edit form.
Definition: EditPage.php:101
RecentChange\PRC_AUTOPATROLLED
const PRC_AUTOPATROLLED
Definition: RecentChange.php:93
EditPage\extractSectionTitle
static extractSectionTitle( $text)
Extract the section title from current section text, if any.
Definition: EditPage.php:3209
EditPage\makeTemplatesOnThisPageList
makeTemplatesOnThisPageList(array $templates)
Wrapper around TemplatesOnThisPageFormatter to make a "templates on this page" list.
Definition: EditPage.php:3185
EditPage\$textbox1
string $textbox1
Page content input field.
Definition: EditPage.php:258
TextContent
Content object implementation for representing flat text.
Definition: TextContent.php:39
EditPage\$parentRevId
int $parentRevId
Revision ID the edit is based on, adjusted when an edit conflict is resolved.
Definition: EditPage.php:315
MediaWiki\EditPage\TextConflictHelper\setContentModel
setContentModel( $contentModel)
Definition: TextConflictHelper.php:132
EditPage\$undidRev
$undidRev
Definition: EditPage.php:351
Linker\titleAttrib
static titleAttrib( $name, $options=null, array $msgParams=[])
Given the id of an interface element, constructs the appropriate title attribute from the system mess...
Definition: Linker.php:2276
MediaWiki\EditPage\Constraint\UnicodeConstraint
Verify unicode constraint.
Definition: UnicodeConstraint.php:31
EditPage\$changeTags
null array $changeTags
Definition: EditPage.php:333
EditPage
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Definition: EditPage.php:89
EditPage\noSuchSectionPage
noSuchSectionPage()
Creates a basic error page which informs the user that they have attempted to edit a nonexistent sect...
Definition: EditPage.php:4538
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
EditPage\$formtype
string $formtype
Definition: EditPage.php:158
EDIT_UPDATE
const EDIT_UPDATE
Definition: Defines.php:126
Content
Base interface for content objects.
Definition: Content.php:35
MediaWiki\EditPage\Constraint\EditRightConstraint
Verify user permissions: Must have edit rights.
Definition: EditRightConstraint.php:34
EditPage\getSummaryInputWidget
getSummaryInputWidget( $summary="", $labelText=null, $inputAttrs=null)
Builds a standard summary input with a label.
Definition: EditPage.php:3425
CommentStore\COMMENT_CHARACTER_LIMIT
const COMMENT_CHARACTER_LIMIT
Maximum length of a comment in UTF-8 characters.
Definition: CommentStore.php:48
EditPage\$hasPresetSummary
bool $hasPresetSummary
Has a summary been preset using GET parameter &summary= ?
Definition: EditPage.php:214
MediaWiki\EditPage\IEditObject\AS_BLANK_ARTICLE
const AS_BLANK_ARTICLE
Status: user tried to create a blank page and wpIgnoreBlankArticle == false.
Definition: IEditObject.php:68
EditPage\$mParserOutput
ParserOutput $mParserOutput
Definition: EditPage.php:209
Title
Represents a title within MediaWiki.
Definition: Title.php:47
EditPage\$mShowSummaryField
bool $mShowSummaryField
Definition: EditPage.php:224
EditPage\$sectiontitle
string $sectiontitle
Definition: EditPage.php:295
EditPage\$starttime
string $starttime
Timestamp from the first time the edit form was rendered.
Definition: EditPage.php:300
EditPage\$suppressIntro
$suppressIntro
Definition: EditPage.php:354
EditPage\$permManager
PermissionManager $permManager
Definition: EditPage.php:402
MediaWiki\EditPage\TextConflictHelper\getEditFormHtmlBeforeContent
getEditFormHtmlBeforeContent()
Content to go in the edit form before textbox1.
Definition: TextConflictHelper.php:254
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:119
wfReadOnlyReason
wfReadOnlyReason()
Check if the site is in read-only mode and return the message if so.
Definition: GlobalFunctions.php:1116
MediaWiki\Revision\RevisionRecord\getId
getId( $wikiId=self::LOCAL)
Get revision ID.
Definition: RevisionRecord.php:279
EditPage\$scrolltop
int null $scrolltop
Definition: EditPage.php:321
EditPage\$deletedSinceEdit
bool $deletedSinceEdit
Definition: EditPage.php:155
MediaWiki\EditPage\IEditObject\AS_PARSE_ERROR
const AS_PARSE_ERROR
Status: can't parse content.
Definition: IEditObject.php:110
EditPage\$selfRedirect
bool $selfRedirect
Definition: EditPage.php:197
EditPage\$edit
bool $edit
Definition: EditPage.php:357
EditPage\isSupportedContentModel
isSupportedContentModel( $modelId)
Returns if the given content model is editable.
Definition: EditPage.php:529
EditPage\$mPreloadContent
$mPreloadContent
Definition: EditPage.php:347
MediaWiki\User\UserNameUtils
UserNameUtils service.
Definition: UserNameUtils.php:42
MediaWiki\EditPage\IEditObject\AS_IMAGE_REDIRECT_LOGGED
const AS_IMAGE_REDIRECT_LOGGED
Status: logged in user is not allowed to upload (User::isAllowed('upload') == false)
Definition: IEditObject.php:95
EditPage\showConflict
showConflict()
Show an edit conflict.
Definition: EditPage.php:3910
EditPage\isPageExistingAndViewable
isPageExistingAndViewable(?PageIdentity $page, Authority $performer)
Verify if a given title exists and the given user is allowed to view it.
Definition: EditPage.php:1624
EditPage\getSubmitButtonLabel
getSubmitButtonLabel()
Get the message key of the label for the button to save the page.
Definition: EditPage.php:4445
MediaWiki\EditPage\IEditObject\AS_MAX_ARTICLE_SIZE_EXCEEDED
const AS_MAX_ARTICLE_SIZE_EXCEEDED
Status: article is too big (> $wgMaxArticleSize), after merging in the new section.
Definition: IEditObject.php:83
EditPage\$watchedItemStore
WatchedItemStoreInterface $watchedItemStore
Definition: EditPage.php:247
EditPage\$unicodeCheck
string null $unicodeCheck
What the user submitted in the 'wpUnicodeCheck' field.
Definition: EditPage.php:380
EditPage\$edittime
string null $edittime
Timestamp of the latest revision of the page when editing was initiated on the client.
Definition: EditPage.php:276
MediaWiki\EditPage\IEditObject\AS_READ_ONLY_PAGE
const AS_READ_ONLY_PAGE
Status: wiki is in readonly mode (wfReadOnly() == true)
Definition: IEditObject.php:56
EditPage\$diff
bool $diff
Definition: EditPage.php:235
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:209
EditPage\doPreviewParse
doPreviewParse(Content $content)
Parse the page for a preview.
Definition: EditPage.php:4221
EditPage\$action
string $action
Definition: EditPage.php:143
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:252
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
EditPage\setEditConflictHelperFactory
setEditConflictHelperFactory(callable $factory)
Set a factory function to create an EditConflictHelper.
Definition: EditPage.php:4735
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:67
EditPage\$wikiPageFactory
WikiPageFactory $wikiPageFactory
Definition: EditPage.php:412
EditPage\showTextbox
showTextbox( $text, $name, $customAttribs=[])
Definition: EditPage.php:3589
EditPage\getTitle
getTitle()
Definition: EditPage.php:499
ManualLogEntry
Class for creating new log entries and inserting them into the database.
Definition: ManualLogEntry.php:44
MediaWiki\EditPage\Constraint\ChangeTagsConstraint
Verify user can add change tags.
Definition: ChangeTagsConstraint.php:34
MWUnknownContentModelException
Exception thrown when an unregistered content model is requested.
Definition: MWUnknownContentModelException.php:11
MediaWiki\EditPage\IEditObject
Serves as a common repository of constants for EditPage edit status results.
Definition: IEditObject.php:30
EditPage\getCurrentContent
getCurrentContent()
Get the current content of the page.
Definition: EditPage.php:1525
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Definition: GlobalFunctions.php:1043
EditPage\$isConflict
bool $isConflict
Whether an edit conflict needs to be resolved.
Definition: EditPage.php:149
EditPage\displayViewSourcePage
displayViewSourcePage(Content $content, $errorMessage='')
Display a read-only View Source page.
Definition: EditPage.php:801
Article
Class for viewing MediaWiki article and history.
Definition: Article.php:49
EditPage\getContentObject
getContentObject( $def_content=null)
Definition: EditPage.php:1253
EditPage\showStandardInputs
showStandardInputs(&$tabindex=2)
Definition: EditPage.php:3860
MediaWiki\EditPage\TextConflictHelper\getEditConflictMainTextBox
getEditConflictMainTextBox(array $customAttribs=[])
HTML to build the textbox1 on edit conflicts.
Definition: TextConflictHelper.php:222
NS_FILE
const NS_FILE
Definition: Defines.php:70
EDIT_FORCE_BOT
const EDIT_FORCE_BOT
Definition: Defines.php:129
MediaWiki\EditPage\IEditObject\AS_HOOK_ERROR_EXPECTED
const AS_HOOK_ERROR_EXPECTED
Status: A hook function returned an error.
Definition: IEditObject.php:41
RawMessage
Variant of the Message class.
Definition: RawMessage.php:35
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:30
WikiPage\isRedirect
isRedirect()
Is the page a redirect, according to secondary tracking tables? If this is true, getRedirectTarget() ...
Definition: WikiPage.php:621
EditPage\$revisionStore
RevisionStore $revisionStore
Definition: EditPage.php:407
EditPage\POST_EDIT_COOKIE_KEY_PREFIX
const POST_EDIT_COOKIE_KEY_PREFIX
Prefix of key for cookie used to pass post-edit state.
Definition: EditPage.php:107
DeprecationHelper
trait DeprecationHelper
Use this trait in classes which have properties for which public access is deprecated or implementati...
Definition: DeprecationHelper.php:60
EDIT_MINOR
const EDIT_MINOR
Definition: Defines.php:127
EditPage\setPostEditCookie
setPostEditCookie( $statusValue)
Sets post-edit cookie indicating the user just saved a particular revision.
Definition: EditPage.php:1656
EditPage\$undoAfter
$undoAfter
Definition: EditPage.php:352
EditPage\getOriginalContent
getOriginalContent(Authority $performer)
Get the content of the wanted revision, without section extraction.
Definition: EditPage.php:1484
Linker\accesskey
static accesskey( $name)
Given the id of an interface element, constructs the appropriate accesskey attribute from the system ...
Definition: Linker.php:2324
WatchedItemStoreInterface
Definition: WatchedItemStoreInterface.php:31
CommentStore\getStore
static getStore()
Definition: CommentStore.php:120
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:210
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:68
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add an update to the pending update queue that invokes the specified callback when run.
Definition: DeferredUpdates.php:145
EditPage\isWrongCaseUserConfigPage
isWrongCaseUserConfigPage()
Checks whether the user entered a skin name in uppercase, e.g.
Definition: EditPage.php:895
EditPage\$incompleteForm
bool $incompleteForm
Definition: EditPage.php:176
EditPage\$missingSummary
bool $missingSummary
Definition: EditPage.php:185
EditPage\getEditConflictHelper
getEditConflictHelper()
Definition: EditPage.php:4743
ExternalUserNames\isExternal
static isExternal( $username)
Tells whether the username is external or not.
Definition: ExternalUserNames.php:149
EditPage\$markAsBot
bool $markAsBot
Definition: EditPage.php:324
EditPage\getCopyrightWarning
static getCopyrightWarning( $title, $format='plain', $langcode=null)
Get the copyright warning, by default returns wikitext.
Definition: EditPage.php:3785
MediaWiki\Revision\RevisionRecord\getSlot
getSlot( $role, $audience=self::FOR_PUBLIC, Authority $performer=null)
Returns meta-data for the given slot.
Definition: RevisionRecord.php:180
MediaWiki\EditPage\IEditObject\AS_HOOK_ERROR
const AS_HOOK_ERROR
Status: Article update aborted by a hook function.
Definition: IEditObject.php:38
$wgDisableAnonTalk
$wgDisableAnonTalk
Disable links to talk pages of anonymous users (IPs) in listings on special pages like page history,...
Definition: DefaultSettings.php:8153
Skin\makeInternalOrExternalUrl
static makeInternalOrExternalUrl( $name)
If url string starts with http, consider as external URL, else internal.
Definition: Skin.php:1160
MediaWiki\EditPage\Constraint\IEditConstraint
Interface for all constraints that can prevent edits.
Definition: IEditConstraint.php:33
EditPage\updateWatchlist
updateWatchlist()
Register the change of watch status.
Definition: EditPage.php:2523
MediaWiki\Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:40
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:474
EditPage\handleStatus
handleStatus(Status $status, $resultDetails)
Handle status, such as after attempt save.
Definition: EditPage.php:1713
ParserOptions\newFromUser
static newFromUser( $user)
Get a ParserOptions object from a given user.
Definition: ParserOptions.php:1074
EditPage\$hookError
string $hookError
Definition: EditPage.php:206
EditPage\$allowBlankArticle
bool $allowBlankArticle
Definition: EditPage.php:194
EditPage\toEditText
toEditText( $content)
Gets an editable textual representation of $content.
Definition: EditPage.php:2857
Xml\checkLabel
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:425
EditPage\setHeaders
setHeaders()
Definition: EditPage.php:2618
EditPage\guessSectionName
guessSectionName( $text)
Turns section name wikitext into anchors for use in HTTP redirects.
Definition: EditPage.php:4714
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
Definition: GlobalFunctions.php:330
$type
$type
Definition: testCompression.php:52
EditPage\$nosummary
bool $nosummary
If true, hide the summary field.
Definition: EditPage.php:270
EditPage\getPreviewText
getPreviewText()
Get the rendered text for previewing.
Definition: EditPage.php:4040