MediaWiki  master
EditPage.php
Go to the documentation of this file.
1 <?php
28 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
36 use OOUI\CheckboxInputWidget;
37 use OOUI\DropdownInputWidget;
38 use OOUI\FieldLayout;
40 use Wikimedia\ScopedCallback;
41 
62 class EditPage implements IEditObject {
64  use ProtectedHookAccessorTrait;
65 
69  public const UNICODE_CHECK = 'ℳ𝒲♥𝓊𝓃𝒾𝒸ℴ𝒹ℯ';
70 
74  public const EDITFORM_ID = 'editform';
75 
80  public const POST_EDIT_COOKIE_KEY_PREFIX = 'PostEditRevision';
81 
95  public const POST_EDIT_COOKIE_DURATION = 1200;
96 
101  public $mArticle;
103  private $page;
104 
109  public $mTitle;
110 
112  private $mContextTitle = null;
113 
115  public $action = 'submit';
116 
121  public $isConflict = false;
122 
124  public $isNew = false;
125 
131 
133  public $formtype;
134 
139  public $firsttime;
140 
145  public $lastDelete;
146 
151  public $mTokenOk = false;
152 
157  public $mTokenOkExceptSuffix = false;
158 
163  public $mTriedSave = false;
164 
169  public $incompleteForm = false;
170 
175  public $tooBig = false;
176 
181  public $missingComment = false;
182 
187  public $missingSummary = false;
188 
193  public $allowBlankSummary = false;
194 
196  protected $blankArticle = false;
197 
199  protected $allowBlankArticle = false;
200 
202  protected $selfRedirect = false;
203 
205  protected $allowSelfRedirect = false;
206 
211  public $autoSumm = '';
212 
214  private $hookError = '';
215 
221 
226  public $hasPresetSummary = false;
227 
236  protected $mBaseRevision = false;
237 
244  private $mExpectedParentRevision = false;
245 
247  public $mShowSummaryField = true;
248 
249  # Form values
250 
252  public $save = false;
253 
255  public $preview = false;
256 
258  public $diff = false;
259 
264  public $minoredit = false;
265 
270  public $watchthis = false;
271 
273  private $watchlistExpiryEnabled = false;
274 
277 
280 
285  public $recreate = false;
286 
290  public $textbox1 = '';
291 
293  public $textbox2 = '';
294 
296  public $summary = '';
297 
303  public $nosummary = false;
304 
309  public $edittime = '';
310 
322  private $editRevId = null;
323 
325  public $section = '';
326 
328  public $sectiontitle = '';
329 
333  public $starttime = '';
334 
340  public $oldid = 0;
341 
349  public $parentRevId = 0;
350 
355  public $editintro = '';
356 
361  public $scrolltop = null;
362 
367  public $markAsBot = true;
368 
371 
373  public $contentFormat = null;
374 
376  private $changeTags = null;
377 
378  # Placeholders for text injection by hooks (must be HTML)
379  # extensions should take care to _append_ to the present value
380 
382  public $editFormPageTop = '';
383  public $editFormTextTop = '';
387  public $editFormTextBottom = '';
390  public $mPreloadContent = null;
391 
392  /* $didSave should be set to true whenever an article was successfully altered. */
393  public $didSave = false;
394  public $undidRev = 0;
395  public $undoAfter = 0;
396 
397  public $suppressIntro = false;
398 
400  protected $edit;
401 
403  protected $contentLength = false;
404 
408  private $enableApiEditOverride = false;
409 
413  protected $context;
414 
418  private $isOldRev = false;
419 
423  private $unicodeCheck;
424 
431 
436 
441 
445  private $permManager;
446 
450  private $revisionStore;
451 
456  public function __construct( Article $article ) {
457  $this->mArticle = $article;
458  $this->page = $article->getPage(); // model object
459  $this->mTitle = $article->getTitle();
460 
461  // Make sure the local context is in sync with other member variables.
462  // Particularly make sure everything is using the same WikiPage instance.
463  // This should probably be the case in Article as well, but it's
464  // particularly important for EditPage, to make use of the in-place caching
465  // facility in WikiPage::prepareContentForEdit.
466  $this->context = new DerivativeContext( $article->getContext() );
467  $this->context->setWikiPage( $this->page );
468  $this->context->setTitle( $this->mTitle );
469 
470  $this->contentModel = $this->mTitle->getContentModel();
471 
472  $services = MediaWikiServices::getInstance();
473  $this->contentHandlerFactory = $services->getContentHandlerFactory();
474  $this->contentFormat = $this->contentHandlerFactory
475  ->getContentHandler( $this->contentModel )
476  ->getDefaultFormat();
477  $this->editConflictHelperFactory = [ $this, 'newTextConflictHelper' ];
478  $this->permManager = $services->getPermissionManager();
479  $this->revisionStore = $services->getRevisionStore();
480  $this->watchlistExpiryEnabled = $this->getContext()->getConfig() instanceof Config
481  && $this->getContext()->getConfig()->get( 'WatchlistExpiry' );
482  $this->watchedItemStore = $services->getWatchedItemStore();
483 
484  $this->deprecatePublicProperty( 'mBaseRevision', '1.35', __CLASS__ );
485  }
486 
490  public function getArticle() {
491  return $this->mArticle;
492  }
493 
498  public function getContext() {
499  return $this->context;
500  }
501 
506  public function getTitle() {
507  return $this->mTitle;
508  }
509 
515  public function setContextTitle( $title ) {
516  $this->mContextTitle = $title;
517  }
518 
527  public function getContextTitle() {
528  if ( $this->mContextTitle === null ) {
529  wfDeprecated( get_class( $this ) . '::getContextTitle called with no title set', '1.32' );
530  global $wgTitle;
531  return $wgTitle;
532  } else {
533  return $this->mContextTitle;
534  }
535  }
536 
544  public function isSupportedContentModel( $modelId ) {
545  return $this->enableApiEditOverride === true ||
546  $this->contentHandlerFactory->getContentHandler( $modelId )->supportsDirectEditing();
547  }
548 
555  public function setApiEditOverride( $enableOverride ) {
556  $this->enableApiEditOverride = $enableOverride;
557  }
558 
570  public function edit() {
571  // Allow extensions to modify/prevent this form or submission
572  if ( !$this->getHookRunner()->onAlternateEdit( $this ) ) {
573  return;
574  }
575 
576  wfDebug( __METHOD__ . ": enter" );
577 
578  $request = $this->context->getRequest();
579  // If they used redlink=1 and the page exists, redirect to the main article
580  if ( $request->getBool( 'redlink' ) && $this->mTitle->exists() ) {
581  $this->context->getOutput()->redirect( $this->mTitle->getFullURL() );
582  return;
583  }
584 
585  $this->importFormData( $request );
586  $this->firsttime = false;
587 
588  if ( wfReadOnly() && $this->save ) {
589  // Force preview
590  $this->save = false;
591  $this->preview = true;
592  }
593 
594  if ( $this->save ) {
595  $this->formtype = 'save';
596  } elseif ( $this->preview ) {
597  $this->formtype = 'preview';
598  } elseif ( $this->diff ) {
599  $this->formtype = 'diff';
600  } else { # First time through
601  $this->firsttime = true;
602  if ( $this->previewOnOpen() ) {
603  $this->formtype = 'preview';
604  } else {
605  $this->formtype = 'initial';
606  }
607  }
608 
609  $permErrors = $this->getEditPermissionErrors(
610  $this->save ? PermissionManager::RIGOR_SECURE : PermissionManager::RIGOR_FULL
611  );
612  if ( $permErrors ) {
613  wfDebug( __METHOD__ . ": User can't edit" );
614 
615  if ( $this->context->getUser()->getBlock() ) {
616  // Auto-block user's IP if the account was "hard" blocked
617  if ( !wfReadOnly() ) {
619  $this->context->getUser()->spreadAnyEditBlock();
620  } );
621  }
622  }
623  $this->displayPermissionsError( $permErrors );
624 
625  return;
626  }
627 
628  $revRecord = $this->mArticle->fetchRevisionRecord();
629  // Disallow editing revisions with content models different from the current one
630  // Undo edits being an exception in order to allow reverting content model changes.
631  $revContentModel = $revRecord ?
632  $revRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel() :
633  false;
634  if ( $revContentModel && $revContentModel !== $this->contentModel ) {
635  $prevRevRecord = null;
636  $prevContentModel = false;
637  if ( $this->undidRev ) {
638  $undidRevRecord = $this->revisionStore
639  ->getRevisionById( $this->undidRev );
640  $prevRevRecord = $undidRevRecord ?
641  $this->revisionStore->getPreviousRevision( $undidRevRecord ) :
642  null;
643 
644  $prevContentModel = $prevRevRecord ?
645  $prevRevRecord
646  ->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )
647  ->getModel() :
648  '';
649  }
650 
651  if ( !$this->undidRev
652  || !$prevRevRecord
653  || $prevContentModel !== $this->contentModel
654  ) {
655  $this->displayViewSourcePage(
656  $this->getContentObject(),
657  $this->context->msg(
658  'contentmodelediterror',
659  $revContentModel,
660  $this->contentModel
661  )->plain()
662  );
663  return;
664  }
665  }
666 
667  $this->isConflict = false;
668 
669  # Show applicable editing introductions
670  if ( $this->formtype == 'initial' || $this->firsttime ) {
671  $this->showIntro();
672  }
673 
674  # Attempt submission here. This will check for edit conflicts,
675  # and redundantly check for locked database, blocked IPs, etc.
676  # that edit() already checked just in case someone tries to sneak
677  # in the back door with a hand-edited submission URL.
678 
679  if ( $this->formtype == 'save' ) {
680  $resultDetails = null;
681  $status = $this->attemptSave( $resultDetails );
682  if ( !$this->handleStatus( $status, $resultDetails ) ) {
683  return;
684  }
685  }
686 
687  # First time through: get contents, set time for conflict
688  # checking, etc.
689  if ( $this->formtype == 'initial' || $this->firsttime ) {
690  if ( $this->initialiseForm() === false ) {
691  return;
692  }
693 
694  if ( !$this->mTitle->getArticleID() ) {
695  $this->getHookRunner()->onEditFormPreloadText( $this->textbox1, $this->mTitle );
696  } else {
697  $this->getHookRunner()->onEditFormInitialText( $this );
698  }
699 
700  }
701 
702  $this->showEditForm();
703  }
704 
709  protected function getEditPermissionErrors( $rigor = PermissionManager::RIGOR_SECURE ) {
710  $user = $this->context->getUser();
711  $permErrors = $this->permManager->getPermissionErrors(
712  'edit',
713  $user,
714  $this->mTitle,
715  $rigor
716  );
717  # Can this title be created?
718  if ( !$this->mTitle->exists() ) {
719  $permErrors = array_merge(
720  $permErrors,
721  wfArrayDiff2(
722  $this->permManager->getPermissionErrors(
723  'create',
724  $user,
725  $this->mTitle,
726  $rigor
727  ),
728  $permErrors
729  )
730  );
731  }
732  # Ignore some permissions errors when a user is just previewing/viewing diffs
733  $remove = [];
734  foreach ( $permErrors as $error ) {
735  if ( ( $this->preview || $this->diff )
736  && (
737  $error[0] == 'blockedtext' ||
738  $error[0] == 'autoblockedtext' ||
739  $error[0] == 'systemblockedtext'
740  )
741  ) {
742  $remove[] = $error;
743  }
744  }
745  $permErrors = wfArrayDiff2( $permErrors, $remove );
746 
747  return $permErrors;
748  }
749 
762  protected function displayPermissionsError( array $permErrors ) {
763  $out = $this->context->getOutput();
764  if ( $this->context->getRequest()->getBool( 'redlink' ) ) {
765  // The edit page was reached via a red link.
766  // Redirect to the article page and let them click the edit tab if
767  // they really want a permission error.
768  $out->redirect( $this->mTitle->getFullURL() );
769  return;
770  }
771 
772  $content = $this->getContentObject();
773 
774  # Use the normal message if there's nothing to display
775  if ( $this->firsttime && ( !$content || $content->isEmpty() ) ) {
776  $action = $this->mTitle->exists() ? 'edit' :
777  ( $this->mTitle->isTalkPage() ? 'createtalk' : 'createpage' );
778  throw new PermissionsError( $action, $permErrors );
779  }
780 
781  $this->displayViewSourcePage(
782  $content,
783  $out->formatPermissionsErrorMessage( $permErrors, 'edit' )
784  );
785  }
786 
792  protected function displayViewSourcePage( Content $content, $errorMessage = '' ) {
793  $out = $this->context->getOutput();
794  $this->getHookRunner()->onEditPage__showReadOnlyForm_initial( $this, $out );
795 
796  $out->setRobotPolicy( 'noindex,nofollow' );
797  $out->setPageTitle( $this->context->msg(
798  'viewsource-title',
799  $this->getContextTitle()->getPrefixedText()
800  ) );
801  $out->addBacklinkSubtitle( $this->getContextTitle() );
802  $out->addHTML( $this->editFormPageTop );
803  $out->addHTML( $this->editFormTextTop );
804 
805  if ( $errorMessage !== '' ) {
806  $out->addWikiTextAsInterface( $errorMessage );
807  $out->addHTML( "<hr />\n" );
808  }
809 
810  # If the user made changes, preserve them when showing the markup
811  # (This happens when a user is blocked during edit, for instance)
812  if ( !$this->firsttime ) {
813  $text = $this->textbox1;
814  $out->addWikiMsg( 'viewyourtext' );
815  } else {
816  try {
817  $text = $this->toEditText( $content );
818  } catch ( MWException $e ) {
819  # Serialize using the default format if the content model is not supported
820  # (e.g. for an old revision with a different model)
821  $text = $content->serialize();
822  }
823  $out->addWikiMsg( 'viewsourcetext' );
824  }
825 
826  $out->addHTML( $this->editFormTextBeforeContent );
827  $this->showTextbox( $text, 'wpTextbox1', [ 'readonly' ] );
828  $out->addHTML( $this->editFormTextAfterContent );
829 
830  $out->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) );
831 
832  $out->addModules( 'mediawiki.action.edit.collapsibleFooter' );
833 
834  $out->addHTML( $this->editFormTextBottom );
835  if ( $this->mTitle->exists() ) {
836  $out->returnToMain( null, $this->mTitle );
837  }
838  }
839 
845  protected function previewOnOpen() {
846  $config = $this->context->getConfig();
847  $previewOnOpenNamespaces = $config->get( 'PreviewOnOpenNamespaces' );
848  $request = $this->context->getRequest();
849  if ( $config->get( 'RawHtml' ) ) {
850  // If raw HTML is enabled, disable preview on open
851  // since it has to be posted with a token for
852  // security reasons
853  return false;
854  }
855  if ( $request->getVal( 'preview' ) == 'yes' ) {
856  // Explicit override from request
857  return true;
858  } elseif ( $request->getVal( 'preview' ) == 'no' ) {
859  // Explicit override from request
860  return false;
861  } elseif ( $this->section == 'new' ) {
862  // Nothing *to* preview for new sections
863  return false;
864  } elseif ( ( $request->getCheck( 'preload' ) || $this->mTitle->exists() )
865  && $this->context->getUser()->getOption( 'previewonfirst' )
866  ) {
867  // Standard preference behavior
868  return true;
869  } elseif ( !$this->mTitle->exists()
870  && isset( $previewOnOpenNamespaces[$this->mTitle->getNamespace()] )
871  && $previewOnOpenNamespaces[$this->mTitle->getNamespace()]
872  ) {
873  // Categories are special
874  return true;
875  } else {
876  return false;
877  }
878  }
879 
886  protected function isWrongCaseUserConfigPage() {
887  if ( $this->mTitle->isUserConfigPage() ) {
888  $name = $this->mTitle->getSkinFromConfigSubpage();
889  $skins = array_merge(
890  array_keys( Skin::getSkinNames() ),
891  [ 'common' ]
892  );
893  return !in_array( $name, $skins )
894  && in_array( strtolower( $name ), $skins );
895  } else {
896  return false;
897  }
898  }
899 
907  protected function isSectionEditSupported() {
908  return $this->contentHandlerFactory
909  ->getContentHandler( $this->mTitle->getContentModel() )
910  ->supportsSections();
911  }
912 
918  public function importFormData( &$request ) {
919  # Section edit can come from either the form or a link
920  $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
921 
922  if ( $this->section !== null && $this->section !== '' && !$this->isSectionEditSupported() ) {
923  throw new ErrorPageError( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
924  }
925 
926  $this->isNew = !$this->mTitle->exists() || $this->section == 'new';
927 
928  if ( $request->wasPosted() ) {
929  # These fields need to be checked for encoding.
930  # Also remove trailing whitespace, but don't remove _initial_
931  # whitespace from the text boxes. This may be significant formatting.
932  $this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) );
933  if ( !$request->getCheck( 'wpTextbox2' ) ) {
934  // Skip this if wpTextbox2 has input, it indicates that we came
935  // from a conflict page with raw page text, not a custom form
936  // modified by subclasses
937  $textbox1 = $this->importContentFormData( $request );
938  if ( $textbox1 !== null ) {
939  $this->textbox1 = $textbox1;
940  }
941  }
942 
943  $this->unicodeCheck = $request->getText( 'wpUnicodeCheck' );
944 
945  $this->summary = $request->getText( 'wpSummary' );
946 
947  # If the summary consists of a heading, e.g. '==Foobar==', extract the title from the
948  # header syntax, e.g. 'Foobar'. This is mainly an issue when we are using wpSummary for
949  # section titles.
950  $this->summary = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary );
951 
952  # Treat sectiontitle the same way as summary.
953  # Note that wpSectionTitle is not yet a part of the actual edit form, as wpSummary is
954  # currently doing double duty as both edit summary and section title. Right now this
955  # is just to allow API edits to work around this limitation, but this should be
956  # incorporated into the actual edit form when EditPage is rewritten (T20654, T28312).
957  $this->sectiontitle = $request->getText( 'wpSectionTitle' );
958  $this->sectiontitle = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->sectiontitle );
959 
960  $this->edittime = $request->getVal( 'wpEdittime' );
961  $this->editRevId = $request->getIntOrNull( 'editRevId' );
962  $this->starttime = $request->getVal( 'wpStarttime' );
963 
964  $undidRev = $request->getInt( 'wpUndidRevision' );
965  if ( $undidRev ) {
966  $this->undidRev = $undidRev;
967  }
968  $undoAfter = $request->getInt( 'wpUndoAfter' );
969  if ( $undoAfter ) {
970  $this->undoAfter = $undoAfter;
971  }
972 
973  $this->scrolltop = $request->getIntOrNull( 'wpScrolltop' );
974 
975  if ( $this->textbox1 === '' && !$request->getCheck( 'wpTextbox1' ) ) {
976  // wpTextbox1 field is missing, possibly due to being "too big"
977  // according to some filter rules such as Suhosin's setting for
978  // suhosin.request.max_value_length (d'oh)
979  $this->incompleteForm = true;
980  } else {
981  // If we receive the last parameter of the request, we can fairly
982  // claim the POST request has not been truncated.
983  $this->incompleteForm = !$request->getVal( 'wpUltimateParam' );
984  }
985  if ( $this->incompleteForm ) {
986  # If the form is incomplete, force to preview.
987  wfDebug( __METHOD__ . ": Form data appears to be incomplete" );
988  wfDebug( "POST DATA: " . var_export( $request->getPostValues(), true ) );
989  $this->preview = true;
990  } else {
991  $this->preview = $request->getCheck( 'wpPreview' );
992  $this->diff = $request->getCheck( 'wpDiff' );
993 
994  // Remember whether a save was requested, so we can indicate
995  // if we forced preview due to session failure.
996  $this->mTriedSave = !$this->preview;
997 
998  if ( $this->tokenOk( $request ) ) {
999  # Some browsers will not report any submit button
1000  # if the user hits enter in the comment box.
1001  # The unmarked state will be assumed to be a save,
1002  # if the form seems otherwise complete.
1003  wfDebug( __METHOD__ . ": Passed token check." );
1004  } elseif ( $this->diff ) {
1005  # Failed token check, but only requested "Show Changes".
1006  wfDebug( __METHOD__ . ": Failed token check; Show Changes requested." );
1007  } else {
1008  # Page might be a hack attempt posted from
1009  # an external site. Preview instead of saving.
1010  wfDebug( __METHOD__ . ": Failed token check; forcing preview" );
1011  $this->preview = true;
1012  }
1013  }
1014  $this->save = !$this->preview && !$this->diff;
1015  if ( !preg_match( '/^\d{14}$/', $this->edittime ) ) {
1016  $this->edittime = null;
1017  }
1018 
1019  if ( !preg_match( '/^\d{14}$/', $this->starttime ) ) {
1020  $this->starttime = null;
1021  }
1022 
1023  $this->recreate = $request->getCheck( 'wpRecreate' );
1024 
1025  $user = $this->getContext()->getUser();
1026 
1027  $this->minoredit = $request->getCheck( 'wpMinoredit' );
1028  $this->watchthis = $request->getCheck( 'wpWatchthis' );
1029  if ( $this->watchlistExpiryEnabled ) {
1030  // This parsing of the user-posted expiry is done for both preview and saving. This
1031  // is necessary because ApiEditPage uses preview when it saves (yuck!). Note that it
1032  // only works because the unnormalized value is retrieved again below in
1033  // getCheckboxesDefinitionForWatchlist().
1034  $expiry = ExpiryDef::normalizeExpiry( $request->getText( 'wpWatchlistExpiry' ) );
1035  if ( $expiry !== false ) {
1036  $this->watchlistExpiry = $expiry;
1037  }
1038  }
1039 
1040  # Don't force edit summaries when a user is editing their own user or talk page
1041  if ( ( $this->mTitle->mNamespace === NS_USER || $this->mTitle->mNamespace === NS_USER_TALK )
1042  && $this->mTitle->getText() == $user->getName()
1043  ) {
1044  $this->allowBlankSummary = true;
1045  } else {
1046  $this->allowBlankSummary = $request->getBool( 'wpIgnoreBlankSummary' )
1047  || !$user->getOption( 'forceeditsummary' );
1048  }
1049 
1050  $this->autoSumm = $request->getText( 'wpAutoSummary' );
1051 
1052  $this->allowBlankArticle = $request->getBool( 'wpIgnoreBlankArticle' );
1053  $this->allowSelfRedirect = $request->getBool( 'wpIgnoreSelfRedirect' );
1054 
1055  $changeTags = $request->getVal( 'wpChangeTags' );
1056  if ( $changeTags === null || $changeTags === '' ) {
1057  $this->changeTags = [];
1058  } else {
1059  $this->changeTags = array_filter( array_map( 'trim', explode( ',',
1060  $changeTags ) ) );
1061  }
1062  } else {
1063  # Not a posted form? Start with nothing.
1064  wfDebug( __METHOD__ . ": Not a posted form." );
1065  $this->textbox1 = '';
1066  $this->summary = '';
1067  $this->sectiontitle = '';
1068  $this->edittime = '';
1069  $this->editRevId = null;
1070  $this->starttime = wfTimestampNow();
1071  $this->edit = false;
1072  $this->preview = false;
1073  $this->save = false;
1074  $this->diff = false;
1075  $this->minoredit = false;
1076  // Watch may be overridden by request parameters
1077  $this->watchthis = $request->getBool( 'watchthis', false );
1078  if ( $this->watchlistExpiryEnabled ) {
1079  $this->watchlistExpiry = null;
1080  }
1081  $this->recreate = false;
1082 
1083  // When creating a new section, we can preload a section title by passing it as the
1084  // preloadtitle parameter in the URL (T15100)
1085  if ( $this->section == 'new' && $request->getVal( 'preloadtitle' ) ) {
1086  $this->sectiontitle = $request->getVal( 'preloadtitle' );
1087  // Once wpSummary isn't being use for setting section titles, we should delete this.
1088  $this->summary = $request->getVal( 'preloadtitle' );
1089  } elseif ( $this->section != 'new' && $request->getVal( 'summary' ) !== '' ) {
1090  $this->summary = $request->getText( 'summary' );
1091  if ( $this->summary !== '' ) {
1092  $this->hasPresetSummary = true;
1093  }
1094  }
1095 
1096  if ( $request->getVal( 'minor' ) ) {
1097  $this->minoredit = true;
1098  }
1099  }
1100 
1101  $this->oldid = $request->getInt( 'oldid' );
1102  $this->parentRevId = $request->getInt( 'parentRevId' );
1103 
1104  $this->markAsBot = $request->getBool( 'bot', true );
1105  $this->nosummary = $request->getBool( 'nosummary' );
1106 
1107  // May be overridden by revision.
1108  $this->contentModel = $request->getText( 'model', $this->contentModel );
1109  // May be overridden by revision.
1110  $this->contentFormat = $request->getText( 'format', $this->contentFormat );
1111 
1112  try {
1113  $handler = $this->contentHandlerFactory->getContentHandler( $this->contentModel );
1114  } catch ( MWUnknownContentModelException $e ) {
1115  throw new ErrorPageError(
1116  'editpage-invalidcontentmodel-title',
1117  'editpage-invalidcontentmodel-text',
1118  [ wfEscapeWikiText( $this->contentModel ) ]
1119  );
1120  }
1121 
1122  if ( !$handler->isSupportedFormat( $this->contentFormat ) ) {
1123  throw new ErrorPageError(
1124  'editpage-notsupportedcontentformat-title',
1125  'editpage-notsupportedcontentformat-text',
1126  [
1127  wfEscapeWikiText( $this->contentFormat ),
1128  wfEscapeWikiText( ContentHandler::getLocalizedName( $this->contentModel ) )
1129  ]
1130  );
1131  }
1132 
1139  $this->editintro = $request->getText( 'editintro',
1140  // Custom edit intro for new sections
1141  $this->section === 'new' ? 'MediaWiki:addsection-editintro' : '' );
1142 
1143  // Allow extensions to modify form data
1144  $this->getHookRunner()->onEditPage__importFormData( $this, $request );
1145  }
1146 
1156  protected function importContentFormData( &$request ) {
1157  return null; // Don't do anything, EditPage already extracted wpTextbox1
1158  }
1159 
1165  public function initialiseForm() {
1166  $this->edittime = $this->page->getTimestamp();
1167  $this->editRevId = $this->page->getLatest();
1168 
1169  $dummy = $this->contentHandlerFactory
1170  ->getContentHandler( $this->contentModel )
1171  ->makeEmptyContent();
1172  $content = $this->getContentObject( $dummy ); # TODO: track content object?!
1173  if ( $content === $dummy ) { // Invalid section
1174  $this->noSuchSectionPage();
1175  return false;
1176  }
1177 
1178  if ( !$content ) {
1179  $out = $this->context->getOutput();
1180  $this->editFormPageTop .= Html::rawElement(
1181  'div', [ 'class' => 'errorbox' ],
1182  $out->parseAsInterface( $this->context->msg( 'missing-revision-content',
1183  $this->oldid,
1184  Message::plaintextParam( $this->mTitle->getPrefixedText() )
1185  ) )
1186  );
1187  } elseif ( !$this->isSupportedContentModel( $content->getModel() ) ) {
1188  $modelMsg = $this->getContext()->msg( 'content-model-' . $content->getModel() );
1189  $modelName = $modelMsg->exists() ? $modelMsg->text() : $content->getModel();
1190 
1191  $out = $this->context->getOutput();
1192  $out->showErrorPage(
1193  'modeleditnotsupported-title',
1194  'modeleditnotsupported-text',
1195  [ $modelName ]
1196  );
1197  return false;
1198  }
1199 
1200  $this->textbox1 = $this->toEditText( $content );
1201 
1202  $user = $this->context->getUser();
1203  // activate checkboxes if user wants them to be always active
1204  # Sort out the "watch" checkbox
1205  if ( $user->getOption( 'watchdefault' ) ) {
1206  # Watch all edits
1207  $this->watchthis = true;
1208  } elseif ( $user->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) {
1209  # Watch creations
1210  $this->watchthis = true;
1211  } elseif ( $user->isWatched( $this->mTitle ) ) {
1212  # Already watched
1213  $this->watchthis = true;
1214  }
1215  if ( $this->watchthis && $this->watchlistExpiryEnabled ) {
1216  $watchedItem = $this->watchedItemStore->getWatchedItem( $user, $this->getTitle() );
1217  $this->watchlistExpiry = $watchedItem ? $watchedItem->getExpiry() : null;
1218  }
1219  if ( $user->getOption( 'minordefault' ) && !$this->isNew ) {
1220  $this->minoredit = true;
1221  }
1222  if ( $this->textbox1 === false ) {
1223  return false;
1224  }
1225  return true;
1226  }
1227 
1235  protected function getContentObject( $def_content = null ) {
1236  global $wgDisableAnonTalk;
1237 
1238  $content = false;
1239 
1240  $user = $this->context->getUser();
1241  $request = $this->context->getRequest();
1242  // For message page not locally set, use the i18n message.
1243  // For other non-existent articles, use preload text if any.
1244  if ( !$this->mTitle->exists() || $this->section == 'new' ) {
1245  if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI && $this->section != 'new' ) {
1246  # If this is a system message, get the default text.
1247  $msg = $this->mTitle->getDefaultMessageText();
1248 
1249  $content = $this->toEditContent( $msg );
1250  }
1251  if ( $content === false ) {
1252  # If requested, preload some text.
1253  $preload = $request->getVal( 'preload',
1254  // Custom preload text for new sections
1255  $this->section === 'new' ? 'MediaWiki:addsection-preload' : '' );
1256  $params = $request->getArray( 'preloadparams', [] );
1257 
1258  $content = $this->getPreloadedContent( $preload, $params );
1259  }
1260  // For existing pages, get text based on "undo" or section parameters.
1261  } elseif ( $this->section != '' ) {
1262  // Get section edit text (returns $def_text for invalid sections)
1263  $orig = $this->getOriginalContent( $user );
1264  $content = $orig ? $orig->getSection( $this->section ) : null;
1265 
1266  if ( !$content ) {
1267  $content = $def_content;
1268  }
1269  } else {
1270  $undoafter = $request->getInt( 'undoafter' );
1271  $undo = $request->getInt( 'undo' );
1272 
1273  if ( $undo > 0 && $undoafter > 0 ) {
1274  $undorev = $this->revisionStore->getRevisionById( $undo );
1275  $oldrev = $this->revisionStore->getRevisionById( $undoafter );
1276  $undoMsg = null;
1277 
1278  # Sanity check, make sure it's the right page,
1279  # the revisions exist and they were not deleted.
1280  # Otherwise, $content will be left as-is.
1281  if ( $undorev !== null && $oldrev !== null &&
1282  !$undorev->isDeleted( RevisionRecord::DELETED_TEXT ) &&
1283  !$oldrev->isDeleted( RevisionRecord::DELETED_TEXT )
1284  ) {
1285  if ( WikiPage::hasDifferencesOutsideMainSlot( $undorev, $oldrev )
1286  || !$this->isSupportedContentModel(
1287  $oldrev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel()
1288  )
1289  ) {
1290  // Hack for undo while EditPage can't handle multi-slot editing
1291  $this->context->getOutput()->redirect( $this->mTitle->getFullURL( [
1292  'action' => 'mcrundo',
1293  'undo' => $undo,
1294  'undoafter' => $undoafter,
1295  ] ) );
1296  return false;
1297  } else {
1298  $content = $this->getUndoContent( $undorev, $oldrev );
1299 
1300  if ( $content === false ) {
1301  # Warn the user that something went wrong
1302  $undoMsg = 'failure';
1303  }
1304  }
1305 
1306  if ( $undoMsg === null ) {
1307  $oldContent = $this->page->getContent( RevisionRecord::RAW );
1309  $user, MediaWikiServices::getInstance()->getContentLanguage() );
1310  $newContent = $content->preSaveTransform( $this->mTitle, $user, $popts );
1311  if ( $newContent->getModel() !== $oldContent->getModel() ) {
1312  // The undo may change content
1313  // model if its reverting the top
1314  // edit. This can result in
1315  // mismatched content model/format.
1316  $this->contentModel = $newContent->getModel();
1317  $oldMainSlot = $oldrev->getSlot(
1318  SlotRecord::MAIN,
1319  RevisionRecord::RAW
1320  );
1321  $this->contentFormat = $oldMainSlot->getFormat();
1322  if ( $this->contentFormat === null ) {
1323  $this->contentFormat = $this->contentHandlerFactory
1324  ->getContentHandler( $oldMainSlot->getModel() )
1325  ->getDefaultFormat();
1326  }
1327  }
1328 
1329  if ( $newContent->equals( $oldContent ) ) {
1330  # Tell the user that the undo results in no change,
1331  # i.e. the revisions were already undone.
1332  $undoMsg = 'nochange';
1333  $content = false;
1334  } else {
1335  # Inform the user of our success and set an automatic edit summary
1336  $undoMsg = 'success';
1337 
1338  # If we just undid one rev, use an autosummary
1339  $firstrev = $this->revisionStore->getNextRevision( $oldrev );
1340  if ( $firstrev && $firstrev->getId() == $undo ) {
1341  $userText = $undorev->getUser() ?
1342  $undorev->getUser()->getName() :
1343  '';
1344  if ( $userText === '' ) {
1345  $undoSummary = $this->context->msg(
1346  'undo-summary-username-hidden',
1347  $undo
1348  )->inContentLanguage()->text();
1349  // Handle external users (imported revisions)
1350  } elseif ( ExternalUserNames::isExternal( $userText ) ) {
1351  $userLinkTitle = ExternalUserNames::getUserLinkTitle( $userText );
1352  if ( $userLinkTitle ) {
1353  $userLink = $userLinkTitle->getPrefixedText();
1354  $undoSummary = $this->context->msg(
1355  'undo-summary-import',
1356  $undo,
1357  $userLink,
1358  $userText
1359  )->inContentLanguage()->text();
1360  } else {
1361  $undoSummary = $this->context->msg(
1362  'undo-summary-import2',
1363  $undo,
1364  $userText
1365  )->inContentLanguage()->text();
1366  }
1367  } else {
1368  $undoIsAnon = $undorev->getUser() ?
1369  !$undorev->getUser()->isRegistered() :
1370  true;
1371  $undoMessage = ( $undoIsAnon && $wgDisableAnonTalk ) ?
1372  'undo-summary-anon' :
1373  'undo-summary';
1374  $undoSummary = $this->context->msg(
1375  $undoMessage,
1376  $undo,
1377  $userText
1378  )->inContentLanguage()->text();
1379  }
1380  if ( $this->summary === '' ) {
1381  $this->summary = $undoSummary;
1382  } else {
1383  $this->summary = $undoSummary . $this->context->msg( 'colon-separator' )
1384  ->inContentLanguage()->text() . $this->summary;
1385  }
1386  }
1387  $this->undidRev = $undo;
1388  $this->undoAfter = $undoafter;
1389  $this->formtype = 'diff';
1390  }
1391  }
1392  } else {
1393  // Failed basic sanity checks.
1394  // Older revisions may have been removed since the link
1395  // was created, or we may simply have got bogus input.
1396  $undoMsg = 'norev';
1397  }
1398 
1399  $out = $this->context->getOutput();
1400  // Messages: undo-success, undo-failure, undo-main-slot-only, undo-norev,
1401  // undo-nochange.
1402  $class = ( $undoMsg == 'success' ? '' : 'error ' ) . "mw-undo-{$undoMsg}";
1403  $this->editFormPageTop .= Html::rawElement(
1404  'div', [ 'class' => $class ],
1405  $out->parseAsInterface(
1406  $this->context->msg( 'undo-' . $undoMsg )->plain()
1407  )
1408  );
1409  }
1410 
1411  if ( $content === false ) {
1412  // Hack for restoring old revisions while EditPage
1413  // can't handle multi-slot editing.
1414  $curRevisionRecord = $this->page->getRevisionRecord();
1415  $oldRevisionRecord = $this->mArticle->fetchRevisionRecord();
1416 
1417  if ( $curRevisionRecord
1418  && $oldRevisionRecord
1419  && $curRevisionRecord->getId() !== $oldRevisionRecord->getId()
1421  $oldRevisionRecord,
1422  $curRevisionRecord
1423  ) || !$this->isSupportedContentModel(
1424  $oldRevisionRecord->getSlot(
1425  SlotRecord::MAIN,
1426  RevisionRecord::RAW
1427  )->getModel()
1428  ) )
1429  ) {
1430  $this->context->getOutput()->redirect(
1431  $this->mTitle->getFullURL(
1432  [
1433  'action' => 'mcrrestore',
1434  'restore' => $oldRevisionRecord->getId(),
1435  ]
1436  )
1437  );
1438 
1439  return false;
1440  }
1441  }
1442 
1443  if ( $content === false ) {
1444  $content = $this->getOriginalContent( $user );
1445  }
1446  }
1447 
1448  return $content;
1449  }
1450 
1461  private function getUndoContent( RevisionRecord $undoRev, RevisionRecord $oldRev ) {
1462  $handler = $this->contentHandlerFactory
1463  ->getContentHandler( $undoRev->getSlot(
1464  SlotRecord::MAIN,
1465  RevisionRecord::RAW
1466  )->getModel() );
1467  $currentContent = $this->page->getRevisionRecord()
1468  ->getContent( SlotRecord::MAIN );
1469  $undoContent = $undoRev->getContent( SlotRecord::MAIN );
1470  $undoAfterContent = $oldRev->getContent( SlotRecord::MAIN );
1471  $undoIsLatest = $this->page->getRevisionRecord()->getId() === $undoRev->getId();
1472 
1473  return $handler->getUndoContent(
1474  $currentContent,
1475  $undoContent,
1476  $undoAfterContent,
1477  $undoIsLatest
1478  );
1479  }
1480 
1496  private function getOriginalContent( User $user ) {
1497  if ( $this->section == 'new' ) {
1498  return $this->getCurrentContent();
1499  }
1500  $revRecord = $this->mArticle->fetchRevisionRecord();
1501  if ( $revRecord === null ) {
1502  return $this->contentHandlerFactory
1503  ->getContentHandler( $this->contentModel )
1504  ->makeEmptyContent();
1505  }
1506  return $revRecord->getContent( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $user );
1507  }
1508 
1521  public function getParentRevId() {
1522  if ( $this->parentRevId ) {
1523  return $this->parentRevId;
1524  } else {
1525  return $this->mArticle->getRevIdFetched();
1526  }
1527  }
1528 
1537  protected function getCurrentContent() {
1538  $revRecord = $this->page->getRevisionRecord();
1539  $content = $revRecord ? $revRecord->getContent(
1540  SlotRecord::MAIN,
1541  RevisionRecord::RAW
1542  ) : null;
1543 
1544  if ( $content === false || $content === null ) {
1545  return $this->contentHandlerFactory
1546  ->getContentHandler( $this->contentModel )
1547  ->makeEmptyContent();
1548  } elseif ( !$this->undidRev ) {
1549  $mainSlot = $revRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
1550 
1551  // Content models should always be the same since we error
1552  // out if they are different before this point (in ->edit()).
1553  // The exception being, during an undo, the current revision might
1554  // differ from the prior revision.
1555  $logger = LoggerFactory::getInstance( 'editpage' );
1556  if ( $this->contentModel !== $mainSlot->getModel() ) {
1557  $logger->warning( "Overriding content model from current edit {prev} to {new}", [
1558  'prev' => $this->contentModel,
1559  'new' => $mainSlot->getModel(),
1560  'title' => $this->getTitle()->getPrefixedDBkey(),
1561  'method' => __METHOD__
1562  ] );
1563  $this->contentModel = $mainSlot->getModel();
1564  }
1565 
1566  // Given that the content models should match, the current selected
1567  // format should be supported.
1568  if ( !$content->isSupportedFormat( $this->contentFormat ) ) {
1569  $revFormat = $mainSlot->getFormat();
1570  if ( $revFormat === null ) {
1571  $revFormat = $this->contentHandlerFactory
1572  ->getContentHandler( $mainSlot->getModel() )
1573  ->getDefaultFormat();
1574  }
1575 
1576  $logger->warning( "Current revision content format unsupported. Overriding {prev} to {new}", [
1577  'prev' => $this->contentFormat,
1578  'new' => $revFormat,
1579  'title' => $this->getTitle()->getPrefixedDBkey(),
1580  'method' => __METHOD__
1581  ] );
1582  $this->contentFormat = $revFormat;
1583  }
1584  }
1585  return $content;
1586  }
1587 
1595  public function setPreloadedContent( Content $content ) {
1596  $this->mPreloadContent = $content;
1597  }
1598 
1610  protected function getPreloadedContent( $preload, $params = [] ) {
1611  if ( !empty( $this->mPreloadContent ) ) {
1612  return $this->mPreloadContent;
1613  }
1614 
1615  $handler = $this->contentHandlerFactory->getContentHandler( $this->contentModel );
1616 
1617  if ( $preload === '' ) {
1618  return $handler->makeEmptyContent();
1619  }
1620 
1621  $user = $this->context->getUser();
1622  $title = Title::newFromText( $preload );
1623 
1624  # Check for existence to avoid getting MediaWiki:Noarticletext
1625  if ( !$this->isPageExistingAndViewable( $title, $user ) ) {
1626  // TODO: somehow show a warning to the user!
1627  return $handler->makeEmptyContent();
1628  }
1629 
1631  if ( $page->isRedirect() ) {
1633  # Same as before
1634  if ( !$this->isPageExistingAndViewable( $title, $user ) ) {
1635  // TODO: somehow show a warning to the user!
1636  return $handler->makeEmptyContent();
1637  }
1639  }
1640 
1641  $parserOptions = ParserOptions::newFromUser( $user );
1642  $content = $page->getContent( RevisionRecord::RAW );
1643 
1644  if ( !$content ) {
1645  // TODO: somehow show a warning to the user!
1646  return $handler->makeEmptyContent();
1647  }
1648 
1649  if ( $content->getModel() !== $handler->getModelID() ) {
1650  $converted = $content->convert( $handler->getModelID() );
1651 
1652  if ( !$converted ) {
1653  // TODO: somehow show a warning to the user!
1654  wfDebug( "Attempt to preload incompatible content: " .
1655  "can't convert " . $content->getModel() .
1656  " to " . $handler->getModelID() );
1657 
1658  return $handler->makeEmptyContent();
1659  }
1660 
1661  $content = $converted;
1662  }
1663 
1664  return $content->preloadTransform( $title, $parserOptions, $params );
1665  }
1666 
1676  private function isPageExistingAndViewable( $title, User $user ) {
1677  return $title && $title->exists() && $this->permManager->userCan( 'read', $user, $title );
1678  }
1679 
1687  public function tokenOk( &$request ) {
1688  $token = $request->getVal( 'wpEditToken' );
1689  $user = $this->context->getUser();
1690  $this->mTokenOk = $user->matchEditToken( $token );
1691  $this->mTokenOkExceptSuffix = $user->matchEditTokenNoSuffix( $token );
1692  return $this->mTokenOk;
1693  }
1694 
1709  protected function setPostEditCookie( $statusValue ) {
1710  $revisionId = $this->page->getLatest();
1711  $postEditKey = self::POST_EDIT_COOKIE_KEY_PREFIX . $revisionId;
1712 
1713  $val = 'saved';
1714  if ( $statusValue == self::AS_SUCCESS_NEW_ARTICLE ) {
1715  $val = 'created';
1716  } elseif ( $this->oldid ) {
1717  $val = 'restored';
1718  }
1719 
1720  $response = $this->context->getRequest()->response();
1721  $response->setCookie( $postEditKey, $val, time() + self::POST_EDIT_COOKIE_DURATION );
1722  }
1723 
1730  public function attemptSave( &$resultDetails = false ) {
1731  // TODO: MCR:
1732  // * treat $this->minoredit like $this->markAsBot and check isAllowed( 'minoredit' )!
1733  // * add $this->autopatrol like $this->markAsBot and check isAllowed( 'autopatrol' )!
1734  // This is needed since PageUpdater no longer checks these rights!
1735 
1736  // Allow bots to exempt some edits from bot flagging
1737  $markAsBot = $this->markAsBot
1738  && $this->permManager->userHasRight( $this->context->getUser(), 'bot' );
1739  $status = $this->internalAttemptSave( $resultDetails, $markAsBot );
1740 
1741  $this->getHookRunner()->onEditPage__attemptSave_after( $this, $status, $resultDetails );
1742 
1743  return $status;
1744  }
1745 
1749  private function incrementResolvedConflicts() {
1750  if ( $this->context->getRequest()->getText( 'mode' ) !== 'conflict' ) {
1751  return;
1752  }
1753 
1754  $this->getEditConflictHelper()->incrementResolvedStats( $this->context->getUser() );
1755  }
1756 
1766  private function handleStatus( Status $status, $resultDetails ) {
1771  if ( $status->value == self::AS_SUCCESS_UPDATE
1772  || $status->value == self::AS_SUCCESS_NEW_ARTICLE
1773  ) {
1774  $this->incrementResolvedConflicts();
1775 
1776  $this->didSave = true;
1777  if ( !$resultDetails['nullEdit'] ) {
1778  $this->setPostEditCookie( $status->value );
1779  }
1780  }
1781 
1782  $out = $this->context->getOutput();
1783 
1784  // "wpExtraQueryRedirect" is a hidden input to modify
1785  // after save URL and is not used by actual edit form
1786  $request = $this->context->getRequest();
1787  $extraQueryRedirect = $request->getVal( 'wpExtraQueryRedirect' );
1788 
1789  switch ( $status->value ) {
1797  case self::AS_END:
1800  return true;
1801 
1802  case self::AS_HOOK_ERROR:
1803  return false;
1804 
1806  wfDeprecated(
1807  __METHOD__ . ' with $status->value == AS_CANNOT_USE_CUSTOM_MODEL',
1808  '1.35'
1809  );
1810  // ...and fall through to next case
1811  case self::AS_PARSE_ERROR:
1813  $out->wrapWikiTextAsInterface( 'error',
1814  $status->getWikiText( false, false, $this->context->getLanguage() )
1815  );
1816  return true;
1817 
1819  $query = $resultDetails['redirect'] ? 'redirect=no' : '';
1820  if ( $extraQueryRedirect ) {
1821  if ( $query !== '' ) {
1822  $query .= '&';
1823  }
1824  $query .= $extraQueryRedirect;
1825  }
1826  $anchor = $resultDetails['sectionanchor'] ?? '';
1827  $out->redirect( $this->mTitle->getFullURL( $query ) . $anchor );
1828  return false;
1829 
1831  $extraQuery = '';
1832  $sectionanchor = $resultDetails['sectionanchor'];
1833 
1834  // Give extensions a chance to modify URL query on update
1835  $this->getHookRunner()->onArticleUpdateBeforeRedirect( $this->mArticle,
1836  $sectionanchor, $extraQuery );
1837 
1838  if ( $resultDetails['redirect'] ) {
1839  if ( $extraQuery !== '' ) {
1840  $extraQuery = '&' . $extraQuery;
1841  }
1842  $extraQuery = 'redirect=no' . $extraQuery;
1843  }
1844  if ( $extraQueryRedirect ) {
1845  if ( $extraQuery !== '' ) {
1846  $extraQuery .= '&';
1847  }
1848  $extraQuery .= $extraQueryRedirect;
1849  }
1850 
1851  $out->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor );
1852  return false;
1853 
1854  case self::AS_SPAM_ERROR:
1855  $this->spamPageWithContent( $resultDetails['spam'] ?? false );
1856  return false;
1857 
1859  throw new UserBlockedError(
1860  $this->context->getUser()->getBlock(),
1861  $this->context->getUser(),
1862  $this->context->getLanguage(),
1863  $request->getIP()
1864  );
1865 
1868  throw new PermissionsError( 'upload' );
1869 
1872  throw new PermissionsError( 'edit' );
1873 
1875  throw new ReadOnlyError;
1876 
1877  case self::AS_RATE_LIMITED:
1878  throw new ThrottledError();
1879 
1881  $permission = $this->mTitle->isTalkPage() ? 'createtalk' : 'createpage';
1882  throw new PermissionsError( $permission );
1883 
1885  throw new PermissionsError( 'editcontentmodel' );
1886 
1887  default:
1888  // We don't recognize $status->value. The only way that can happen
1889  // is if an extension hook aborted from inside ArticleSave.
1890  // Render the status object into $this->hookError
1891  // FIXME this sucks, we should just use the Status object throughout
1892  $this->hookError = '<div class="error">' . "\n" .
1893  $status->getWikiText( false, false, $this->context->getLanguage() ) .
1894  '</div>';
1895  return true;
1896  }
1897  }
1898 
1908  protected function runPostMergeFilters( Content $content, Status $status, User $user ) {
1909  // Run old style post-section-merge edit filter
1910  if ( $this->hookError != '' ) {
1911  # ...or the hook could be expecting us to produce an error
1912  $status->fatal( 'hookaborted' );
1913  $status->value = self::AS_HOOK_ERROR_EXPECTED;
1914  return false;
1915  }
1916 
1917  // Run new style post-section-merge edit filter
1918  if ( !$this->getHookRunner()->onEditFilterMergedContent( $this->context, $content,
1919  $status, $this->summary, $user, $this->minoredit )
1920  ) {
1921  # Error messages etc. could be handled within the hook...
1922  if ( $status->isGood() ) {
1923  $status->fatal( 'hookaborted' );
1924  // Not setting $this->hookError here is a hack to allow the hook
1925  // to cause a return to the edit page without $this->hookError
1926  // being set. This is used by ConfirmEdit to display a captcha
1927  // without any error message cruft.
1928  } else {
1929  $this->hookError = $this->formatStatusErrors( $status );
1930  }
1931  // Use the existing $status->value if the hook set it
1932  if ( !$status->value ) {
1933  $status->value = self::AS_HOOK_ERROR;
1934  }
1935  return false;
1936  } elseif ( !$status->isOK() ) {
1937  # ...or the hook could be expecting us to produce an error
1938  // FIXME this sucks, we should just use the Status object throughout
1939  if ( !$status->getErrors() ) {
1940  // Provide a fallback error message if none was set
1941  $status->fatal( 'hookaborted' );
1942  }
1943  $this->hookError = $this->formatStatusErrors( $status );
1944  $status->value = self::AS_HOOK_ERROR_EXPECTED;
1945  return false;
1946  }
1947 
1948  return true;
1949  }
1950 
1957  private function formatStatusErrors( Status $status ) {
1958  $errmsg = $status->getWikiText(
1959  'edit-error-short',
1960  'edit-error-long',
1961  $this->context->getLanguage()
1962  );
1963  return <<<ERROR
1964 <div class="errorbox">
1965 {$errmsg}
1966 </div>
1967 <br clear="all" />
1968 ERROR;
1969  }
1970 
1977  private function newSectionSummary( &$sectionanchor = null ) {
1978  if ( $this->sectiontitle !== '' ) {
1979  $sectionanchor = $this->guessSectionName( $this->sectiontitle );
1980  // If no edit summary was specified, create one automatically from the section
1981  // title and have it link to the new section. Otherwise, respect the summary as
1982  // passed.
1983  if ( $this->summary === '' ) {
1984  $cleanSectionTitle = MediaWikiServices::getInstance()->getParser()
1985  ->stripSectionName( $this->sectiontitle );
1986  return $this->context->msg( 'newsectionsummary' )
1987  ->plaintextParams( $cleanSectionTitle )->inContentLanguage()->text();
1988  }
1989  } elseif ( $this->summary !== '' ) {
1990  $sectionanchor = $this->guessSectionName( $this->summary );
1991  # This is a new section, so create a link to the new section
1992  # in the revision summary.
1993  $cleanSummary = MediaWikiServices::getInstance()->getParser()
1994  ->stripSectionName( $this->summary );
1995  return $this->context->msg( 'newsectionsummary' )
1996  ->plaintextParams( $cleanSummary )->inContentLanguage()->text();
1997  }
1998  return $this->summary;
1999  }
2000 
2026  public function internalAttemptSave( &$result, $markAsBot = false ) {
2027  $status = Status::newGood();
2028  $user = $this->context->getUser();
2029 
2030  if ( !$this->getHookRunner()->onEditPage__attemptSave( $this ) ) {
2031  wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" );
2032  $status->fatal( 'hookaborted' );
2033  $status->value = self::AS_HOOK_ERROR;
2034  return $status;
2035  }
2036 
2037  if ( $this->unicodeCheck !== self::UNICODE_CHECK ) {
2038  $status->fatal( 'unicode-support-fail' );
2039  $status->value = self::AS_UNICODE_NOT_SUPPORTED;
2040  return $status;
2041  }
2042 
2043  $request = $this->context->getRequest();
2044  $spam = $request->getText( 'wpAntispam' );
2045  if ( $spam !== '' ) {
2046  wfDebugLog(
2047  'SimpleAntiSpam',
2048  $user->getName() .
2049  ' editing "' .
2050  $this->mTitle->getPrefixedText() .
2051  '" submitted bogus field "' .
2052  $spam .
2053  '"'
2054  );
2055  $status->fatal( 'spamprotectionmatch', false );
2056  $status->value = self::AS_SPAM_ERROR;
2057  return $status;
2058  }
2059 
2060  try {
2061  # Construct Content object
2062  $textbox_content = $this->toEditContent( $this->textbox1 );
2063  } catch ( MWContentSerializationException $ex ) {
2064  $status->fatal(
2065  'content-failed-to-parse',
2066  $this->contentModel,
2067  $this->contentFormat,
2068  $ex->getMessage()
2069  );
2070  $status->value = self::AS_PARSE_ERROR;
2071  return $status;
2072  }
2073 
2074  # Check image redirect
2075  if ( $this->mTitle->getNamespace() === NS_FILE &&
2076  $textbox_content->isRedirect() &&
2077  !$this->permManager->userHasRight( $user, 'upload' )
2078  ) {
2080  $status->setResult( false, $code );
2081 
2082  return $status;
2083  }
2084 
2085  # Check for spam
2086  $spamRegexChecker = MediaWikiServices::getInstance()->getSpamChecker();
2087  $match = $spamRegexChecker->checkSummary( $this->summary );
2088  if ( $match === false && $this->section == 'new' ) {
2089  # $wgSpamRegex is enforced on this new heading/summary because, unlike
2090  # regular summaries, it is added to the actual wikitext.
2091  if ( $this->sectiontitle !== '' ) {
2092  # This branch is taken when the API is used with the 'sectiontitle' parameter.
2093  $match = $spamRegexChecker->checkContent( $this->sectiontitle );
2094  } else {
2095  # This branch is taken when the "Add Topic" user interface is used, or the API
2096  # is used with the 'summary' parameter.
2097  $match = $spamRegexChecker->checkContent( $this->summary );
2098  }
2099  }
2100  if ( $match === false ) {
2101  $match = $spamRegexChecker->checkContent( $this->textbox1 );
2102  }
2103  if ( $match !== false ) {
2104  $result['spam'] = $match;
2105  $ip = $request->getIP();
2106  $pdbk = $this->mTitle->getPrefixedDBkey();
2107  $match = str_replace( "\n", '', $match );
2108  wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
2109  $status->fatal( 'spamprotectionmatch', $match );
2110  $status->value = self::AS_SPAM_ERROR;
2111  return $status;
2112  }
2113  if ( !$this->getHookRunner()->onEditFilter( $this, $this->textbox1, $this->section,
2114  $this->hookError, $this->summary )
2115  ) {
2116  # Error messages etc. could be handled within the hook...
2117  $status->fatal( 'hookaborted' );
2118  $status->value = self::AS_HOOK_ERROR;
2119  return $status;
2120  } elseif ( $this->hookError != '' ) {
2121  # ...or the hook could be expecting us to produce an error
2122  $status->fatal( 'hookaborted' );
2123  $status->value = self::AS_HOOK_ERROR_EXPECTED;
2124  return $status;
2125  }
2126 
2127  if ( $this->permManager->isBlockedFrom( $user, $this->mTitle ) ) {
2128  // Auto-block user's IP if the account was "hard" blocked
2129  if ( !wfReadOnly() ) {
2130  $user->spreadAnyEditBlock();
2131  }
2132  # Check block state against master, thus 'false'.
2133  $status->setResult( false, self::AS_BLOCKED_PAGE_FOR_USER );
2134  return $status;
2135  }
2136 
2137  $this->contentLength = strlen( $this->textbox1 );
2138  $config = $this->context->getConfig();
2139  $maxArticleSize = $config->get( 'MaxArticleSize' );
2140  if ( $this->contentLength > $maxArticleSize * 1024 ) {
2141  // Error will be displayed by showEditForm()
2142  $this->tooBig = true;
2143  $status->setResult( false, self::AS_CONTENT_TOO_BIG );
2144  return $status;
2145  }
2146 
2147  if ( !$this->permManager->userHasRight( $user, 'edit' ) ) {
2148  if ( $user->isAnon() ) {
2149  $status->setResult( false, self::AS_READ_ONLY_PAGE_ANON );
2150  return $status;
2151  } else {
2152  $status->fatal( 'readonlytext' );
2153  $status->value = self::AS_READ_ONLY_PAGE_LOGGED;
2154  return $status;
2155  }
2156  }
2157 
2158  $changingContentModel = false;
2159  if ( $this->contentModel !== $this->mTitle->getContentModel() ) {
2160  if ( !$this->permManager->userHasRight( $user, 'editcontentmodel' ) ) {
2161  $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL );
2162  return $status;
2163  }
2164  // Make sure the user can edit the page under the new content model too
2165  $titleWithNewContentModel = clone $this->mTitle;
2166  $titleWithNewContentModel->setContentModel( $this->contentModel );
2167 
2168  $canEditModel = $this->permManager->userCan(
2169  'editcontentmodel',
2170  $user,
2171  $titleWithNewContentModel
2172  );
2173 
2174  if (
2175  !$canEditModel
2176  || !$this->permManager->userCan( 'edit', $user, $titleWithNewContentModel )
2177  ) {
2178  $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL );
2179 
2180  return $status;
2181  }
2182 
2183  $changingContentModel = true;
2184  $oldContentModel = $this->mTitle->getContentModel();
2185  }
2186 
2187  if ( $this->changeTags ) {
2188  $changeTagsStatus = ChangeTags::canAddTagsAccompanyingChange(
2189  $this->changeTags, $user );
2190  if ( !$changeTagsStatus->isOK() ) {
2191  $changeTagsStatus->value = self::AS_CHANGE_TAG_ERROR;
2192  return $changeTagsStatus;
2193  }
2194  }
2195 
2196  if ( wfReadOnly() ) {
2197  $status->fatal( 'readonlytext' );
2198  $status->value = self::AS_READ_ONLY_PAGE;
2199  return $status;
2200  }
2201  if ( $user->pingLimiter() || $user->pingLimiter( 'linkpurge', 0 )
2202  || ( $changingContentModel && $user->pingLimiter( 'editcontentmodel' ) )
2203  ) {
2204  $status->fatal( 'actionthrottledtext' );
2205  $status->value = self::AS_RATE_LIMITED;
2206  return $status;
2207  }
2208 
2209  # If the article has been deleted while editing, don't save it without
2210  # confirmation
2211  if ( $this->wasDeletedSinceLastEdit() && !$this->recreate ) {
2212  $status->setResult( false, self::AS_ARTICLE_WAS_DELETED );
2213  return $status;
2214  }
2215 
2216  # Load the page data from the master. If anything changes in the meantime,
2217  # we detect it by using page_latest like a token in a 1 try compare-and-swap.
2218  $this->page->loadPageData( 'fromdbmaster' );
2219  $new = !$this->page->exists();
2220 
2221  if ( $new ) {
2222  // Late check for create permission, just in case *PARANOIA*
2223  if ( !$this->permManager->userCan( 'create', $user, $this->mTitle ) ) {
2224  $status->fatal( 'nocreatetext' );
2225  $status->value = self::AS_NO_CREATE_PERMISSION;
2226  wfDebug( __METHOD__ . ": no create permission" );
2227  return $status;
2228  }
2229 
2230  // Don't save a new page if it's blank or if it's a MediaWiki:
2231  // message with content equivalent to default (allow empty pages
2232  // in this case to disable messages, see T52124)
2233  $defaultMessageText = $this->mTitle->getDefaultMessageText();
2234  if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI && $defaultMessageText !== false ) {
2235  $defaultText = $defaultMessageText;
2236  } else {
2237  $defaultText = '';
2238  }
2239 
2240  if ( !$this->allowBlankArticle && $this->textbox1 === $defaultText ) {
2241  $this->blankArticle = true;
2242  $status->fatal( 'blankarticle' );
2243  $status->setResult( false, self::AS_BLANK_ARTICLE );
2244  return $status;
2245  }
2246 
2247  if ( !$this->runPostMergeFilters( $textbox_content, $status, $user ) ) {
2248  return $status;
2249  }
2250 
2251  $content = $textbox_content;
2252 
2253  $result['sectionanchor'] = '';
2254  if ( $this->section == 'new' ) {
2255  // @phan-suppress-next-line PhanSuspiciousValueComparison
2256  if ( $this->sectiontitle !== '' ) {
2257  // Insert the section title above the content.
2258  $content = $content->addSectionHeader( $this->sectiontitle );
2259  } elseif ( $this->summary !== '' ) {
2260  // Insert the section title above the content.
2261  $content = $content->addSectionHeader( $this->summary );
2262  }
2263  $this->summary = $this->newSectionSummary( $result['sectionanchor'] );
2264  }
2265 
2266  $status->value = self::AS_SUCCESS_NEW_ARTICLE;
2267 
2268  } else { # not $new
2269 
2270  # Article exists. Check for edit conflict.
2271 
2272  $this->page->clear(); # Force reload of dates, etc.
2273  $timestamp = $this->page->getTimestamp();
2274  $latest = $this->page->getLatest();
2275 
2276  wfDebug( "timestamp: {$timestamp}, edittime: {$this->edittime}" );
2277  wfDebug( "revision: {$latest}, editRevId: {$this->editRevId}" );
2278 
2279  // An edit conflict is detected if the current revision is different from the
2280  // revision that was current when editing was initiated on the client.
2281  // This is checked based on the timestamp and revision ID.
2282  // TODO: the timestamp based check can probably go away now.
2283  if ( ( $this->edittime !== null && $this->edittime != $timestamp )
2284  || ( $this->editRevId !== null && $this->editRevId != $latest )
2285  ) {
2286  $this->isConflict = true;
2287  if ( $this->section == 'new' ) {
2288  if ( $this->page->getUserText() == $user->getName() &&
2289  $this->page->getComment() == $this->newSectionSummary()
2290  ) {
2291  // Probably a duplicate submission of a new comment.
2292  // This can happen when CDN resends a request after
2293  // a timeout but the first one actually went through.
2294  wfDebug( __METHOD__
2295  . ": duplicate new section submission; trigger edit conflict!" );
2296  } else {
2297  // New comment; suppress conflict.
2298  $this->isConflict = false;
2299  wfDebug( __METHOD__ . ": conflict suppressed; new section" );
2300  }
2301  } elseif ( $this->section == ''
2302  && $this->edittime
2303  && $this->revisionStore->userWasLastToEdit(
2304  wfGetDB( DB_MASTER ),
2305  $this->mTitle->getArticleID(),
2306  $user->getId(),
2307  $this->edittime
2308  )
2309  ) {
2310  # Suppress edit conflict with self, except for section edits where merging is required.
2311  wfDebug( __METHOD__ . ": Suppressing edit conflict, same user." );
2312  $this->isConflict = false;
2313  }
2314  }
2315 
2316  // If sectiontitle is set, use it, otherwise use the summary as the section title.
2317  // @phan-suppress-next-line PhanSuspiciousValueComparison
2318  if ( $this->sectiontitle !== '' ) {
2319  $sectionTitle = $this->sectiontitle;
2320  } else {
2321  $sectionTitle = $this->summary;
2322  }
2323 
2324  $content = null;
2325 
2326  if ( $this->isConflict ) {
2327  wfDebug( __METHOD__
2328  . ": conflict! getting section '{$this->section}' for time '{$this->edittime}'"
2329  . " (id '{$this->editRevId}') (article time '{$timestamp}')" );
2330  // @TODO: replaceSectionAtRev() with base ID (not prior current) for ?oldid=X case
2331  // ...or disable section editing for non-current revisions (not exposed anyway).
2332  if ( $this->editRevId !== null ) {
2333  $content = $this->page->replaceSectionAtRev(
2334  $this->section,
2335  $textbox_content,
2336  $sectionTitle,
2337  $this->editRevId
2338  );
2339  } else {
2340  $content = $this->page->replaceSectionContent(
2341  $this->section,
2342  $textbox_content,
2343  $sectionTitle,
2344  $this->edittime
2345  );
2346  }
2347  } else {
2348  wfDebug( __METHOD__ . ": getting section '{$this->section}'" );
2349  $content = $this->page->replaceSectionContent(
2350  $this->section,
2351  $textbox_content,
2352  $sectionTitle
2353  );
2354  }
2355 
2356  if ( $content === null ) {
2357  wfDebug( __METHOD__ . ": activating conflict; section replace failed." );
2358  $this->isConflict = true;
2359  $content = $textbox_content; // do not try to merge here!
2360  } elseif ( $this->isConflict ) {
2361  # Attempt merge
2362  if ( $this->mergeChangesIntoContent( $content ) ) {
2363  // Successful merge! Maybe we should tell the user the good news?
2364  $this->isConflict = false;
2365  wfDebug( __METHOD__ . ": Suppressing edit conflict, successful merge." );
2366  } else {
2367  $this->section = '';
2368  $this->textbox1 = ContentHandler::getContentText( $content );
2369  wfDebug( __METHOD__ . ": Keeping edit conflict, failed merge." );
2370  }
2371  }
2372 
2373  if ( $this->isConflict ) {
2374  $status->setResult( false, self::AS_CONFLICT_DETECTED );
2375  return $status;
2376  }
2377 
2378  if ( !$this->runPostMergeFilters( $content, $status, $user ) ) {
2379  return $status;
2380  }
2381 
2382  if ( $this->section == 'new' ) {
2383  // Handle the user preference to force summaries here
2384  if ( !$this->allowBlankSummary && trim( $this->summary ) == '' ) {
2385  $this->missingSummary = true;
2386  $status->fatal( 'missingsummary' ); // or 'missingcommentheader' if $section == 'new'. Blegh
2387  $status->value = self::AS_SUMMARY_NEEDED;
2388  return $status;
2389  }
2390 
2391  // Do not allow the user to post an empty comment
2392  if ( $this->textbox1 == '' ) {
2393  $this->missingComment = true;
2394  $status->fatal( 'missingcommenttext' );
2395  $status->value = self::AS_TEXTBOX_EMPTY;
2396  return $status;
2397  }
2398  } elseif ( !$this->allowBlankSummary
2399  && !$content->equals( $this->getOriginalContent( $user ) )
2400  && !$content->isRedirect()
2401  && md5( $this->summary ) == $this->autoSumm
2402  ) {
2403  $this->missingSummary = true;
2404  $status->fatal( 'missingsummary' );
2405  $status->value = self::AS_SUMMARY_NEEDED;
2406  return $status;
2407  }
2408 
2409  # All's well
2410  $sectionanchor = '';
2411  if ( $this->section == 'new' ) {
2412  $this->summary = $this->newSectionSummary( $sectionanchor );
2413  } elseif ( $this->section != '' ) {
2414  # Try to get a section anchor from the section source, redirect
2415  # to edited section if header found.
2416  # XXX: Might be better to integrate this into Article::replaceSectionAtRev
2417  # for duplicate heading checking and maybe parsing.
2418  $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );
2419  # We can't deal with anchors, includes, html etc in the header for now,
2420  # headline would need to be parsed to improve this.
2421  if ( $hasmatch && strlen( $matches[2] ) > 0 ) {
2422  $sectionanchor = $this->guessSectionName( $matches[2] );
2423  }
2424  }
2425  $result['sectionanchor'] = $sectionanchor;
2426 
2427  // Save errors may fall down to the edit form, but we've now
2428  // merged the section into full text. Clear the section field
2429  // so that later submission of conflict forms won't try to
2430  // replace that into a duplicated mess.
2431  $this->textbox1 = $this->toEditText( $content );
2432  $this->section = '';
2433 
2434  $status->value = self::AS_SUCCESS_UPDATE;
2435  }
2436 
2437  if ( !$this->allowSelfRedirect
2438  && $content->isRedirect()
2439  && $content->getRedirectTarget()->equals( $this->getTitle() )
2440  ) {
2441  // If the page already redirects to itself, don't warn.
2442  $currentTarget = $this->getCurrentContent()->getRedirectTarget();
2443  if ( !$currentTarget || !$currentTarget->equals( $this->getTitle() ) ) {
2444  $this->selfRedirect = true;
2445  $status->fatal( 'selfredirect' );
2446  $status->value = self::AS_SELF_REDIRECT;
2447  return $status;
2448  }
2449  }
2450 
2451  // Check for length errors again now that the section is merged in
2452  $this->contentLength = strlen( $this->toEditText( $content ) );
2453  if ( $this->contentLength > $maxArticleSize * 1024 ) {
2454  $this->tooBig = true;
2455  $status->setResult( false, self::AS_MAX_ARTICLE_SIZE_EXCEEDED );
2456  return $status;
2457  }
2458 
2459  $flags = EDIT_AUTOSUMMARY |
2460  ( $new ? EDIT_NEW : EDIT_UPDATE ) |
2461  ( ( $this->minoredit && !$this->isNew ) ? EDIT_MINOR : 0 ) |
2462  ( $markAsBot ? EDIT_FORCE_BOT : 0 );
2463 
2464  $isUndo = false;
2465  if ( $this->undidRev ) {
2466  // As the user can change the edit's content before saving, we only mark
2467  // "clean" undos as reverts. This is to avoid abuse by marking irrelevant
2468  // edits as undos.
2469  $isUndo = $this->isUndoClean( $content );
2470  }
2471 
2472  $doEditStatus = $this->page->doEditContent(
2473  $content,
2474  $this->summary,
2475  $flags,
2476  $isUndo && $this->undoAfter ? $this->undoAfter : false,
2477  $user,
2478  $content->getDefaultFormat(),
2479  $this->changeTags,
2480  $isUndo ? $this->undidRev : 0
2481  );
2482 
2483  if ( !$doEditStatus->isOK() ) {
2484  // Failure from doEdit()
2485  // Show the edit conflict page for certain recognized errors from doEdit(),
2486  // but don't show it for errors from extension hooks
2487  $errors = $doEditStatus->getErrorsArray();
2488  if ( in_array( $errors[0][0],
2489  [ 'edit-gone-missing', 'edit-conflict', 'edit-already-exists' ] )
2490  ) {
2491  $this->isConflict = true;
2492  }
2493  // Destroys data doEdit() put in $status->value but who cares
2494  $doEditStatus->value = self::AS_END;
2495  return $doEditStatus;
2496  }
2497 
2498  $result['nullEdit'] = $doEditStatus->hasMessage( 'edit-no-change' );
2499  if ( $result['nullEdit'] ) {
2500  // We don't know if it was a null edit until now, so increment here
2501  $user->pingLimiter( 'linkpurge' );
2502  }
2503  $result['redirect'] = $content->isRedirect();
2504 
2505  $this->updateWatchlist();
2506 
2507  // If the content model changed, add a log entry
2508  if ( $changingContentModel ) {
2510  $user,
2511  $new ? false : $oldContentModel,
2512  $this->contentModel,
2513  $this->summary
2514  );
2515  }
2516 
2517  return $status;
2518  }
2519 
2530  private function isUndoClean( Content $content ) : bool {
2531  // Check whether the undo was "clean", that is the user has not modified
2532  // the automatically generated content.
2533  $undoRev = $this->revisionStore->getRevisionById( $this->undidRev );
2534  if ( $undoRev === null ) {
2535  return false;
2536  }
2537 
2538  if ( $this->undoAfter ) {
2539  $oldRev = $this->revisionStore->getRevisionById( $this->undoAfter );
2540  } else {
2541  $oldRev = $this->revisionStore->getPreviousRevision( $undoRev );
2542  }
2543 
2544  // Sanity checks
2545  if ( $oldRev === null ||
2546  $undoRev->isDeleted( RevisionRecord::DELETED_TEXT ) ||
2547  $oldRev->isDeleted( RevisionRecord::DELETED_TEXT )
2548  ) {
2549  return false;
2550  }
2551 
2552  $undoContent = $this->getUndoContent( $undoRev, $oldRev );
2553 
2554  // Do a pre-save transform on the retrieved undo content
2555  $user = $this->context->getUser();
2556  $parserOptions = ParserOptions::newFromUserAndLang(
2557  $user, MediaWikiServices::getInstance()->getContentLanguage() );
2558  $undoContent = $undoContent->preSaveTransform( $this->mTitle, $user, $parserOptions );
2559 
2560  if ( $undoContent && $undoContent->equals( $content ) ) {
2561  return true;
2562  }
2563  return false;
2564  }
2565 
2572  protected function addContentModelChangeLogEntry( User $user, $oldModel, $newModel, $reason ) {
2573  $new = $oldModel === false;
2574  $log = new ManualLogEntry( 'contentmodel', $new ? 'new' : 'change' );
2575  $log->setPerformer( $user );
2576  $log->setTarget( $this->mTitle );
2577  $log->setComment( $reason );
2578  $log->setParameters( [
2579  '4::oldmodel' => $oldModel,
2580  '5::newmodel' => $newModel
2581  ] );
2582  $logid = $log->insert();
2583  $log->publish( $logid );
2584  }
2585 
2589  protected function updateWatchlist() {
2590  $user = $this->context->getUser();
2591  if ( !$user->isLoggedIn() ) {
2592  return;
2593  }
2594 
2596  $watch = $this->watchthis;
2598  // Do this in its own transaction to reduce contention...
2599  DeferredUpdates::addCallableUpdate( function () use ( $user, $title, $watch, $watchlistExpiry ) {
2601  } );
2602 
2603  // Add a job to purge expired watchlist items. Jobs will only be added at the rate
2604  // specified by $wgWatchlistPurgeRate, which by default is every tenth edit.
2605  if ( $this->watchlistExpiryEnabled ) {
2606  $purgeRate = $this->getContext()->getConfig()->get( 'WatchlistPurgeRate' );
2607  $this->watchedItemStore->enqueueWatchlistExpiryJob( $purgeRate );
2608  }
2609  }
2610 
2622  private function mergeChangesIntoContent( &$editContent ) {
2623  // This is the revision that was current at the time editing was initiated on the client,
2624  // even if the edit was based on an old revision.
2625  $baseRevRecord = $this->getExpectedParentRevision();
2626  $baseContent = $baseRevRecord ?
2627  $baseRevRecord->getContent( SlotRecord::MAIN ) :
2628  null;
2629 
2630  if ( $baseContent === null ) {
2631  return false;
2632  }
2633 
2634  // The current state, we want to merge updates into it
2635  $currentRevisionRecord = $this->revisionStore->getRevisionByTitle(
2636  $this->mTitle,
2637  0,
2638  RevisionStore::READ_LATEST
2639  );
2640  $currentContent = $currentRevisionRecord
2641  ? $currentRevisionRecord->getContent( SlotRecord::MAIN )
2642  : null;
2643 
2644  if ( $currentContent === null ) {
2645  return false;
2646  }
2647 
2648  $result = $this->contentHandlerFactory
2649  ->getContentHandler( $baseContent->getModel() )
2650  ->merge3( $baseContent, $editContent, $currentContent );
2651 
2652  if ( $result ) {
2653  $editContent = $result;
2654  // Update parentRevId to what we just merged.
2655  $this->parentRevId = $currentRevisionRecord->getId();
2656  return true;
2657  }
2658 
2659  return false;
2660  }
2661 
2676  public function getBaseRevision() {
2677  wfDeprecated( __METHOD__, '1.35' );
2678  if ( $this->mBaseRevision === false ) {
2679  $revRecord = $this->getExpectedParentRevision();
2680  $this->mBaseRevision = $revRecord ? new Revision( $revRecord ) : null;
2681  }
2682  return $this->mBaseRevision;
2683  }
2684 
2692  public function getExpectedParentRevision() {
2693  if ( $this->mExpectedParentRevision === false ) {
2694  $revRecord = null;
2695  if ( $this->editRevId ) {
2696  $revRecord = $this->revisionStore->getRevisionById(
2697  $this->editRevId,
2698  RevisionStore::READ_LATEST
2699  );
2700  } else {
2701  $revRecord = $this->revisionStore->getRevisionByTimestamp(
2702  $this->getTitle(),
2703  $this->edittime,
2704  RevisionStore::READ_LATEST
2705  );
2706  }
2707  $this->mExpectedParentRevision = $revRecord;
2708  }
2710  }
2711 
2721  public static function matchSpamRegex( $text ) {
2722  wfDeprecated( __METHOD__, '1.35' );
2723  return MediaWikiServices::getInstance()->getSpamChecker()->checkContent( $text );
2724  }
2725 
2735  public static function matchSummarySpamRegex( $text ) {
2736  wfDeprecated( __METHOD__, '1.35' );
2737  return MediaWikiServices::getInstance()->getSpamChecker()->checkSummary( $text );
2738  }
2739 
2740  public function setHeaders() {
2741  $out = $this->context->getOutput();
2742 
2743  $out->addModules( 'mediawiki.action.edit' );
2744  $out->addModuleStyles( 'mediawiki.action.edit.styles' );
2745  $out->addModuleStyles( 'mediawiki.editfont.styles' );
2746 
2747  $user = $this->context->getUser();
2748 
2749  if ( $user->getOption( 'uselivepreview' ) ) {
2750  $out->addModules( 'mediawiki.action.edit.preview' );
2751  }
2752 
2753  if ( $user->getOption( 'useeditwarning' ) ) {
2754  $out->addModules( 'mediawiki.action.edit.editWarning' );
2755  }
2756 
2757  if ( $this->watchlistExpiryEnabled && $user->isRegistered() ) {
2758  $out->addModules( 'mediawiki.action.edit.watchlistExpiry' );
2759  }
2760 
2761  # Enabled article-related sidebar, toplinks, etc.
2762  $out->setArticleRelated( true );
2763 
2764  $contextTitle = $this->getContextTitle();
2765  if ( $this->isConflict ) {
2766  $msg = 'editconflict';
2767  } elseif ( $contextTitle->exists() && $this->section != '' ) {
2768  $msg = $this->section == 'new' ? 'editingcomment' : 'editingsection';
2769  } else {
2770  $msg = $contextTitle->exists()
2771  || ( $contextTitle->getNamespace() === NS_MEDIAWIKI
2772  && $contextTitle->getDefaultMessageText() !== false
2773  )
2774  ? 'editing'
2775  : 'creating';
2776  }
2777 
2778  # Use the title defined by DISPLAYTITLE magic word when present
2779  # NOTE: getDisplayTitle() returns HTML while getPrefixedText() returns plain text.
2780  # setPageTitle() treats the input as wikitext, which should be safe in either case.
2781  $displayTitle = isset( $this->mParserOutput ) ? $this->mParserOutput->getDisplayTitle() : false;
2782  if ( $displayTitle === false ) {
2783  $displayTitle = $contextTitle->getPrefixedText();
2784  } else {
2785  $out->setDisplayTitle( $displayTitle );
2786  }
2787  $out->setPageTitle( $this->context->msg( $msg, $displayTitle ) );
2788 
2789  $config = $this->context->getConfig();
2790 
2791  # Transmit the name of the message to JavaScript for live preview
2792  # Keep Resources.php/mediawiki.action.edit.preview in sync with the possible keys
2793  $out->addJsConfigVars( [
2794  'wgEditMessage' => $msg,
2795  'wgAjaxEditStash' => $config->get( 'AjaxEditStash' ),
2796  ] );
2797 
2798  // Add whether to use 'save' or 'publish' messages to JavaScript for post-edit, other
2799  // editors, etc.
2800  $out->addJsConfigVars(
2801  'wgEditSubmitButtonLabelPublish',
2802  $config->get( 'EditSubmitButtonLabelPublish' )
2803  );
2804  }
2805 
2809  protected function showIntro() {
2810  if ( $this->suppressIntro ) {
2811  return;
2812  }
2813 
2814  $out = $this->context->getOutput();
2815  $namespace = $this->mTitle->getNamespace();
2816 
2817  if ( $namespace === NS_MEDIAWIKI ) {
2818  # Show a warning if editing an interface message
2819  $out->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1\n</div>", 'editinginterface' );
2820  # If this is a default message (but not css, json, or js),
2821  # show a hint that it is translatable on translatewiki.net
2822  if (
2823  !$this->mTitle->hasContentModel( CONTENT_MODEL_CSS )
2824  && !$this->mTitle->hasContentModel( CONTENT_MODEL_JSON )
2825  && !$this->mTitle->hasContentModel( CONTENT_MODEL_JAVASCRIPT )
2826  ) {
2827  $defaultMessageText = $this->mTitle->getDefaultMessageText();
2828  if ( $defaultMessageText !== false ) {
2829  $out->wrapWikiMsg( "<div class='mw-translateinterface'>\n$1\n</div>",
2830  'translateinterface' );
2831  }
2832  }
2833  } elseif ( $namespace === NS_FILE ) {
2834  # Show a hint to shared repo
2835  $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $this->mTitle );
2836  if ( $file && !$file->isLocal() ) {
2837  $descUrl = $file->getDescriptionUrl();
2838  # there must be a description url to show a hint to shared repo
2839  if ( $descUrl ) {
2840  if ( !$this->mTitle->exists() ) {
2841  $out->wrapWikiMsg( "<div class=\"mw-sharedupload-desc-create\">\n$1\n</div>", [
2842  'sharedupload-desc-create', $file->getRepo()->getDisplayName(), $descUrl
2843  ] );
2844  } else {
2845  $out->wrapWikiMsg( "<div class=\"mw-sharedupload-desc-edit\">\n$1\n</div>", [
2846  'sharedupload-desc-edit', $file->getRepo()->getDisplayName(), $descUrl
2847  ] );
2848  }
2849  }
2850  }
2851  }
2852 
2853  # Show a warning message when someone creates/edits a user (talk) page but the user does not exist
2854  # Show log extract when the user is currently blocked
2855  if ( $namespace === NS_USER || $namespace === NS_USER_TALK ) {
2856  $username = explode( '/', $this->mTitle->getText(), 2 )[0];
2857  $user = User::newFromName( $username, false /* allow IP users */ );
2858  $ip = User::isIP( $username );
2859  $block = DatabaseBlock::newFromTarget( $user, $user );
2860  if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
2861  $out->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
2862  [ 'userpage-userdoesnotexist', wfEscapeWikiText( $username ) ] );
2863  } elseif (
2864  $block !== null &&
2865  $block->getType() != DatabaseBlock::TYPE_AUTO &&
2866  ( $block->isSitewide() || $user->isBlockedFrom( $this->mTitle ) )
2867  ) {
2868  // Show log extract if the user is sitewide blocked or is partially
2869  // blocked and not allowed to edit their user page or user talk page
2871  $out,
2872  'block',
2873  MediaWikiServices::getInstance()->getNamespaceInfo()->
2874  getCanonicalName( NS_USER ) . ':' . $block->getTarget(),
2875  '',
2876  [
2877  'lim' => 1,
2878  'showIfEmpty' => false,
2879  'msgKey' => [
2880  'blocked-notice-logextract',
2881  $user->getName() # Support GENDER in notice
2882  ]
2883  ]
2884  );
2885  }
2886  }
2887  # Try to add a custom edit intro, or use the standard one if this is not possible.
2888  if ( !$this->showCustomIntro() && !$this->mTitle->exists() ) {
2890  $this->context->msg( 'helppage' )->inContentLanguage()->text()
2891  ) );
2892  if ( $this->context->getUser()->isLoggedIn() ) {
2893  $out->wrapWikiMsg(
2894  // Suppress the external link icon, consider the help url an internal one
2895  "<div class=\"mw-newarticletext plainlinks\">\n$1\n</div>",
2896  [
2897  'newarticletext',
2898  $helpLink
2899  ]
2900  );
2901  } else {
2902  $out->wrapWikiMsg(
2903  // Suppress the external link icon, consider the help url an internal one
2904  "<div class=\"mw-newarticletextanon plainlinks\">\n$1\n</div>",
2905  [
2906  'newarticletextanon',
2907  $helpLink
2908  ]
2909  );
2910  }
2911  }
2912  # Give a notice if the user is editing a deleted/moved page...
2913  if ( !$this->mTitle->exists() ) {
2914  $dbr = wfGetDB( DB_REPLICA );
2915 
2916  LogEventsList::showLogExtract( $out, [ 'delete', 'move' ], $this->mTitle,
2917  '',
2918  [
2919  'lim' => 10,
2920  'conds' => [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ],
2921  'showIfEmpty' => false,
2922  'msgKey' => [ 'recreate-moveddeleted-warn' ]
2923  ]
2924  );
2925  }
2926  }
2927 
2933  protected function showCustomIntro() {
2934  if ( $this->editintro ) {
2935  $title = Title::newFromText( $this->editintro );
2936  if ( $this->isPageExistingAndViewable( $title, $this->context->getUser() ) ) {
2937  // Added using template syntax, to take <noinclude>'s into account.
2938  $this->context->getOutput()->addWikiTextAsContent(
2939  '<div class="mw-editintro">{{:' . $title->getFullText() . '}}</div>',
2940  /*linestart*/true,
2941  $this->mTitle
2942  );
2943  return true;
2944  }
2945  }
2946  return false;
2947  }
2948 
2967  protected function toEditText( $content ) {
2968  if ( $content === null || $content === false || is_string( $content ) ) {
2969  return $content;
2970  }
2971 
2972  if ( !$this->isSupportedContentModel( $content->getModel() ) ) {
2973  throw new MWException( 'This content model is not supported: ' . $content->getModel() );
2974  }
2975 
2976  return $content->serialize( $this->contentFormat );
2977  }
2978 
2995  protected function toEditContent( $text ) {
2996  if ( $text === false || $text === null ) {
2997  return $text;
2998  }
2999 
3000  $content = ContentHandler::makeContent( $text, $this->getTitle(),
3001  $this->contentModel, $this->contentFormat );
3002 
3003  if ( !$this->isSupportedContentModel( $content->getModel() ) ) {
3004  throw new MWException( 'This content model is not supported: ' . $content->getModel() );
3005  }
3006 
3007  return $content;
3008  }
3009 
3018  public function showEditForm( $formCallback = null ) {
3019  # need to parse the preview early so that we know which templates are used,
3020  # otherwise users with "show preview after edit box" will get a blank list
3021  # we parse this near the beginning so that setHeaders can do the title
3022  # setting work instead of leaving it in getPreviewText
3023  $previewOutput = '';
3024  if ( $this->formtype == 'preview' ) {
3025  $previewOutput = $this->getPreviewText();
3026  }
3027 
3028  $out = $this->context->getOutput();
3029 
3030  $this->getHookRunner()->onEditPage__showEditForm_initial( $this, $out );
3031 
3032  $this->setHeaders();
3033 
3034  $this->addTalkPageText();
3035  $this->addEditNotices();
3036 
3037  if ( !$this->isConflict &&
3038  $this->section != '' &&
3039  !$this->isSectionEditSupported() ) {
3040  // We use $this->section to much before this and getVal('wgSection') directly in other places
3041  // at this point we can't reset $this->section to '' to fallback to non-section editing.
3042  // Someone is welcome to try refactoring though
3043  $out->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
3044  return;
3045  }
3046 
3047  $this->showHeader();
3048 
3049  $out->addHTML( $this->editFormPageTop );
3050 
3051  $user = $this->context->getUser();
3052  if ( $user->getOption( 'previewontop' ) ) {
3053  $this->displayPreviewArea( $previewOutput, true );
3054  }
3055 
3056  $out->addHTML( $this->editFormTextTop );
3057 
3058  if ( $this->wasDeletedSinceLastEdit() && $this->formtype !== 'save' ) {
3059  $out->wrapWikiMsg( "<div class='error mw-deleted-while-editing'>\n$1\n</div>",
3060  'deletedwhileediting' );
3061  }
3062 
3063  // @todo add EditForm plugin interface and use it here!
3064  // search for textarea1 and textarea2, and allow EditForm to override all uses.
3065  $out->addHTML( Html::openElement(
3066  'form',
3067  [
3068  'class' => 'mw-editform',
3069  'id' => self::EDITFORM_ID,
3070  'name' => self::EDITFORM_ID,
3071  'method' => 'post',
3072  'action' => $this->getActionURL( $this->getContextTitle() ),
3073  'enctype' => 'multipart/form-data'
3074  ]
3075  ) );
3076 
3077  if ( is_callable( $formCallback ) ) {
3078  wfWarn( 'The $formCallback parameter to ' . __METHOD__ . 'is deprecated' );
3079  call_user_func_array( $formCallback, [ &$out ] );
3080  }
3081 
3082  // Add a check for Unicode support
3083  $out->addHTML( Html::hidden( 'wpUnicodeCheck', self::UNICODE_CHECK ) );
3084 
3085  // Add an empty field to trip up spambots
3086  $out->addHTML(
3087  Xml::openElement( 'div', [ 'id' => 'antispam-container', 'style' => 'display: none;' ] )
3088  . Html::rawElement(
3089  'label',
3090  [ 'for' => 'wpAntispam' ],
3091  $this->context->msg( 'simpleantispam-label' )->parse()
3092  )
3093  . Xml::element(
3094  'input',
3095  [
3096  'type' => 'text',
3097  'name' => 'wpAntispam',
3098  'id' => 'wpAntispam',
3099  'value' => ''
3100  ]
3101  )
3102  . Xml::closeElement( 'div' )
3103  );
3104 
3105  $this->getHookRunner()->onEditPage__showEditForm_fields( $this, $out );
3106 
3107  // Put these up at the top to ensure they aren't lost on early form submission
3108  $this->showFormBeforeText();
3109 
3110  if ( $this->wasDeletedSinceLastEdit() && $this->formtype == 'save' ) {
3111  $username = $this->lastDelete->user_name;
3112  $comment = CommentStore::getStore()
3113  ->getComment( 'log_comment', $this->lastDelete )->text;
3114 
3115  // It is better to not parse the comment at all than to have templates expanded in the middle
3116  // TODO: can the checkLabel be moved outside of the div so that wrapWikiMsg could be used?
3117  $key = $comment === ''
3118  ? 'confirmrecreate-noreason'
3119  : 'confirmrecreate';
3120  $out->addHTML(
3121  '<div class="mw-confirm-recreate">' .
3122  $this->context->msg( $key, $username, "<nowiki>$comment</nowiki>" )->parse() .
3123  Xml::checkLabel( $this->context->msg( 'recreate' )->text(), 'wpRecreate', 'wpRecreate', false,
3124  [ 'title' => Linker::titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' ]
3125  ) .
3126  '</div>'
3127  );
3128  }
3129 
3130  # When the summary is hidden, also hide them on preview/show changes
3131  if ( $this->nosummary ) {
3132  $out->addHTML( Html::hidden( 'nosummary', true ) );
3133  }
3134 
3135  # If a blank edit summary was previously provided, and the appropriate
3136  # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
3137  # user being bounced back more than once in the event that a summary
3138  # is not required.
3139  # ####
3140  # For a bit more sophisticated detection of blank summaries, hash the
3141  # automatic one and pass that in the hidden field wpAutoSummary.
3142  if ( $this->missingSummary || ( $this->section == 'new' && $this->nosummary ) ) {
3143  $out->addHTML( Html::hidden( 'wpIgnoreBlankSummary', true ) );
3144  }
3145 
3146  if ( $this->undidRev ) {
3147  $out->addHTML( Html::hidden( 'wpUndidRevision', $this->undidRev ) );
3148  }
3149  if ( $this->undoAfter ) {
3150  $out->addHTML( Html::hidden( 'wpUndoAfter', $this->undoAfter ) );
3151  }
3152 
3153  if ( $this->selfRedirect ) {
3154  $out->addHTML( Html::hidden( 'wpIgnoreSelfRedirect', true ) );
3155  }
3156 
3157  if ( $this->hasPresetSummary ) {
3158  // If a summary has been preset using &summary= we don't want to prompt for
3159  // a different summary. Only prompt for a summary if the summary is blanked.
3160  // (T19416)
3161  $this->autoSumm = md5( '' );
3162  }
3163 
3164  $autosumm = $this->autoSumm !== '' ? $this->autoSumm : md5( $this->summary );
3165  $out->addHTML( Html::hidden( 'wpAutoSummary', $autosumm ) );
3166 
3167  $out->addHTML( Html::hidden( 'oldid', $this->oldid ) );
3168  $out->addHTML( Html::hidden( 'parentRevId', $this->getParentRevId() ) );
3169 
3170  $out->addHTML( Html::hidden( 'format', $this->contentFormat ) );
3171  $out->addHTML( Html::hidden( 'model', $this->contentModel ) );
3172 
3173  $out->enableOOUI();
3174 
3175  if ( $this->section == 'new' ) {
3176  $this->showSummaryInput( true, $this->summary );
3177  $out->addHTML( $this->getSummaryPreview( true, $this->summary ) );
3178  }
3179 
3180  $out->addHTML( $this->editFormTextBeforeContent );
3181  if ( $this->isConflict ) {
3182  // In an edit conflict, we turn textbox2 into the user's text,
3183  // and textbox1 into the stored version
3184  $this->textbox2 = $this->textbox1;
3185 
3186  $content = $this->getCurrentContent();
3187  $this->textbox1 = $this->toEditText( $content );
3188 
3190  $editConflictHelper->setTextboxes( $this->textbox2, $this->textbox1 );
3191  $editConflictHelper->setContentModel( $this->contentModel );
3192  $editConflictHelper->setContentFormat( $this->contentFormat );
3194  }
3195 
3196  if ( !$this->mTitle->isUserConfigPage() ) {
3197  $out->addHTML( self::getEditToolbar() );
3198  }
3199 
3200  if ( $this->blankArticle ) {
3201  $out->addHTML( Html::hidden( 'wpIgnoreBlankArticle', true ) );
3202  }
3203 
3204  if ( $this->isConflict ) {
3205  // In an edit conflict bypass the overridable content form method
3206  // and fallback to the raw wpTextbox1 since editconflicts can't be
3207  // resolved between page source edits and custom ui edits using the
3208  // custom edit ui.
3209  $conflictTextBoxAttribs = [];
3210  if ( $this->wasDeletedSinceLastEdit() ) {
3211  $conflictTextBoxAttribs['style'] = 'display:none;';
3212  } elseif ( $this->isOldRev ) {
3213  $conflictTextBoxAttribs['class'] = 'mw-textarea-oldrev';
3214  }
3215 
3216  $out->addHTML( $editConflictHelper->getEditConflictMainTextBox( $conflictTextBoxAttribs ) );
3218  } else {
3219  $this->showContentForm();
3220  }
3221 
3222  $out->addHTML( $this->editFormTextAfterContent );
3223 
3224  $this->showStandardInputs();
3225 
3226  $this->showFormAfterText();
3227 
3228  $this->showTosSummary();
3229 
3230  $this->showEditTools();
3231 
3232  $out->addHTML( $this->editFormTextAfterTools . "\n" );
3233 
3234  $out->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) );
3235 
3236  $out->addHTML( Html::rawElement( 'div', [ 'class' => 'hiddencats' ],
3237  Linker::formatHiddenCategories( $this->page->getHiddenCategories() ) ) );
3238 
3239  $out->addHTML( Html::rawElement( 'div', [ 'class' => 'limitreport' ],
3240  self::getPreviewLimitReport( $this->mParserOutput ) ) );
3241 
3242  $out->addModules( 'mediawiki.action.edit.collapsibleFooter' );
3243 
3244  if ( $this->isConflict ) {
3245  try {
3246  $this->showConflict();
3247  } catch ( MWContentSerializationException $ex ) {
3248  // this can't really happen, but be nice if it does.
3249  $msg = $this->context->msg(
3250  'content-failed-to-parse',
3251  $this->contentModel,
3252  $this->contentFormat,
3253  $ex->getMessage()
3254  );
3255  $out->wrapWikiTextAsInterface( 'error', $msg->plain() );
3256  }
3257  }
3258 
3259  // Set a hidden field so JS knows what edit form mode we are in
3260  if ( $this->isConflict ) {
3261  $mode = 'conflict';
3262  } elseif ( $this->preview ) {
3263  $mode = 'preview';
3264  } elseif ( $this->diff ) {
3265  $mode = 'diff';
3266  } else {
3267  $mode = 'text';
3268  }
3269  $out->addHTML( Html::hidden( 'mode', $mode, [ 'id' => 'mw-edit-mode' ] ) );
3270 
3271  // Marker for detecting truncated form data. This must be the last
3272  // parameter sent in order to be of use, so do not move me.
3273  $out->addHTML( Html::hidden( 'wpUltimateParam', true ) );
3274  $out->addHTML( $this->editFormTextBottom . "\n</form>\n" );
3275 
3276  if ( !$user->getOption( 'previewontop' ) ) {
3277  $this->displayPreviewArea( $previewOutput, false );
3278  }
3279  }
3280 
3288  public function makeTemplatesOnThisPageList( array $templates ) {
3289  $templateListFormatter = new TemplatesOnThisPageFormatter(
3290  $this->context, MediaWikiServices::getInstance()->getLinkRenderer()
3291  );
3292 
3293  // preview if preview, else section if section, else false
3294  $type = false;
3295  if ( $this->preview ) {
3296  $type = 'preview';
3297  } elseif ( $this->section != '' ) {
3298  $type = 'section';
3299  }
3300 
3301  return Html::rawElement( 'div', [ 'class' => 'templatesUsed' ],
3302  $templateListFormatter->format( $templates, $type )
3303  );
3304  }
3305 
3312  public static function extractSectionTitle( $text ) {
3313  if ( preg_match( "/^(=+)(.+)\\1\\s*(\n|$)/i", $text, $matches ) ) {
3314  return MediaWikiServices::getInstance()->getParser()
3315  ->stripSectionName( trim( $matches[2] ) );
3316  } else {
3317  return false;
3318  }
3319  }
3320 
3321  protected function showHeader() {
3322  $out = $this->context->getOutput();
3323  $user = $this->context->getUser();
3324  if ( $this->isConflict ) {
3325  $this->addExplainConflictHeader( $out );
3326  $this->editRevId = $this->page->getLatest();
3327  } else {
3328  if ( $this->section != '' && $this->section != 'new' && !$this->summary &&
3329  !$this->preview && !$this->diff
3330  ) {
3331  $sectionTitle = self::extractSectionTitle( $this->textbox1 ); // FIXME: use Content object
3332  if ( $sectionTitle !== false ) {
3333  $this->summary = "/* $sectionTitle */ ";
3334  }
3335  }
3336 
3337  $buttonLabel = $this->context->msg( $this->getSubmitButtonLabel() )->text();
3338 
3339  if ( $this->missingComment ) {
3340  $out->wrapWikiMsg( "<div id='mw-missingcommenttext'>\n$1\n</div>", 'missingcommenttext' );
3341  }
3342 
3343  if ( $this->missingSummary && $this->section != 'new' ) {
3344  $out->wrapWikiMsg(
3345  "<div id='mw-missingsummary'>\n$1\n</div>",
3346  [ 'missingsummary', $buttonLabel ]
3347  );
3348  }
3349 
3350  if ( $this->missingSummary && $this->section == 'new' ) {
3351  $out->wrapWikiMsg(
3352  "<div id='mw-missingcommentheader'>\n$1\n</div>",
3353  [ 'missingcommentheader', $buttonLabel ]
3354  );
3355  }
3356 
3357  if ( $this->blankArticle ) {
3358  $out->wrapWikiMsg(
3359  "<div id='mw-blankarticle'>\n$1\n</div>",
3360  [ 'blankarticle', $buttonLabel ]
3361  );
3362  }
3363 
3364  if ( $this->selfRedirect ) {
3365  $out->wrapWikiMsg(
3366  "<div id='mw-selfredirect'>\n$1\n</div>",
3367  [ 'selfredirect', $buttonLabel ]
3368  );
3369  }
3370 
3371  if ( $this->hookError !== '' ) {
3372  $out->addWikiTextAsInterface( $this->hookError );
3373  }
3374 
3375  if ( $this->section != 'new' ) {
3376  $revRecord = $this->mArticle->fetchRevisionRecord();
3377  if ( $revRecord && $revRecord instanceof RevisionStoreRecord ) {
3378  // Let sysop know that this will make private content public if saved
3379 
3380  if ( !RevisionRecord::userCanBitfield(
3381  $revRecord->getVisibility(),
3382  RevisionRecord::DELETED_TEXT,
3383  $user
3384  ) ) {
3385  $out->wrapWikiMsg(
3386  "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
3387  [ 'rev-deleted-text-permission', $this->mTitle->getPrefixedText() ]
3388  );
3389  } elseif ( $revRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
3390  $out->wrapWikiMsg(
3391  "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
3392  [ 'rev-deleted-text-view', $this->mTitle->getPrefixedText() ]
3393  );
3394  }
3395 
3396  if ( !$revRecord->isCurrent() ) {
3397  $this->mArticle->setOldSubtitle( $revRecord->getId() );
3398  $out->wrapWikiMsg(
3399  Html::warningBox( "\n$1\n" ),
3400  'editingold'
3401  );
3402  $this->isOldRev = true;
3403  }
3404  } elseif ( $this->mTitle->exists() ) {
3405  // Something went wrong
3406 
3407  $out->wrapWikiMsg( "<div class='errorbox'>\n$1\n</div>\n",
3408  [ 'missing-revision', $this->oldid ] );
3409  }
3410  }
3411  }
3412 
3413  if ( wfReadOnly() ) {
3414  $out->wrapWikiMsg(
3415  "<div id=\"mw-read-only-warning\">\n$1\n</div>",
3416  [ 'readonlywarning', wfReadOnlyReason() ]
3417  );
3418  } elseif ( $user->isAnon() ) {
3419  if ( $this->formtype != 'preview' ) {
3420  $returntoquery = array_diff_key(
3421  $this->context->getRequest()->getValues(),
3422  [ 'title' => true, 'returnto' => true, 'returntoquery' => true ]
3423  );
3424  $out->wrapWikiMsg(
3425  "<div id='mw-anon-edit-warning' class='warningbox'>\n$1\n</div>",
3426  [ 'anoneditwarning',
3427  // Log-in link
3428  SpecialPage::getTitleFor( 'Userlogin' )->getFullURL( [
3429  'returnto' => $this->getTitle()->getPrefixedDBkey(),
3430  'returntoquery' => wfArrayToCgi( $returntoquery ),
3431  ] ),
3432  // Sign-up link
3433  SpecialPage::getTitleFor( 'CreateAccount' )->getFullURL( [
3434  'returnto' => $this->getTitle()->getPrefixedDBkey(),
3435  'returntoquery' => wfArrayToCgi( $returntoquery ),
3436  ] )
3437  ]
3438  );
3439  } else {
3440  $out->wrapWikiMsg( "<div id=\"mw-anon-preview-warning\" class=\"warningbox\">\n$1</div>",
3441  'anonpreviewwarning'
3442  );
3443  }
3444  } elseif ( $this->mTitle->isUserConfigPage() ) {
3445  # Check the skin exists
3446  if ( $this->isWrongCaseUserConfigPage() ) {
3447  $out->wrapWikiMsg(
3448  "<div class='error' id='mw-userinvalidconfigtitle'>\n$1\n</div>",
3449  [ 'userinvalidconfigtitle', $this->mTitle->getSkinFromConfigSubpage() ]
3450  );
3451  }
3452  if ( $this->getTitle()->isSubpageOf( $user->getUserPage() ) ) {
3453  $isUserCssConfig = $this->mTitle->isUserCssConfigPage();
3454  $isUserJsonConfig = $this->mTitle->isUserJsonConfigPage();
3455  $isUserJsConfig = $this->mTitle->isUserJsConfigPage();
3456 
3457  $warning = $isUserCssConfig
3458  ? 'usercssispublic'
3459  : ( $isUserJsonConfig ? 'userjsonispublic' : 'userjsispublic' );
3460 
3461  $out->wrapWikiMsg( '<div class="mw-userconfigpublic">$1</div>', $warning );
3462 
3463  if ( $isUserJsConfig ) {
3464  $out->wrapWikiMsg( '<div class="mw-userconfigdangerous">$1</div>', 'userjsdangerous' );
3465  }
3466 
3467  if ( $this->formtype !== 'preview' ) {
3468  $config = $this->context->getConfig();
3469  if ( $isUserCssConfig && $config->get( 'AllowUserCss' ) ) {
3470  $out->wrapWikiMsg(
3471  "<div id='mw-usercssyoucanpreview'>\n$1\n</div>",
3472  [ 'usercssyoucanpreview' ]
3473  );
3474  } elseif ( $isUserJsonConfig /* No comparable 'AllowUserJson' */ ) {
3475  $out->wrapWikiMsg(
3476  "<div id='mw-userjsonyoucanpreview'>\n$1\n</div>",
3477  [ 'userjsonyoucanpreview' ]
3478  );
3479  } elseif ( $isUserJsConfig && $config->get( 'AllowUserJs' ) ) {
3480  $out->wrapWikiMsg(
3481  "<div id='mw-userjsyoucanpreview'>\n$1\n</div>",
3482  [ 'userjsyoucanpreview' ]
3483  );
3484  }
3485  }
3486  }
3487  }
3488 
3490 
3491  $this->addLongPageWarningHeader();
3492 
3493  # Add header copyright warning
3494  $this->showHeaderCopyrightWarning();
3495  }
3496 
3504  private function getSummaryInputAttributes( array $inputAttrs = null ) {
3505  // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
3506  // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
3507  // Unicode codepoints.
3508  return ( is_array( $inputAttrs ) ? $inputAttrs : [] ) + [
3509  'id' => 'wpSummary',
3510  'name' => 'wpSummary',
3512  'tabindex' => 1,
3513  'size' => 60,
3514  'spellcheck' => 'true',
3515  ];
3516  }
3517 
3527  public function getSummaryInputWidget( $summary = "", $labelText = null, $inputAttrs = null ) {
3528  $inputAttrs = OOUI\Element::configFromHtmlAttributes(
3529  $this->getSummaryInputAttributes( $inputAttrs )
3530  );
3531  $inputAttrs += [
3532  'title' => Linker::titleAttrib( 'summary' ),
3533  'accessKey' => Linker::accesskey( 'summary' ),
3534  ];
3535 
3536  // For compatibility with old scripts and extensions, we want the legacy 'id' on the `<input>`
3537  $inputAttrs['inputId'] = $inputAttrs['id'];
3538  $inputAttrs['id'] = 'wpSummaryWidget';
3539 
3540  return new OOUI\FieldLayout(
3541  new OOUI\TextInputWidget( [
3542  'value' => $summary,
3543  'infusable' => true,
3544  ] + $inputAttrs ),
3545  [
3546  'label' => new OOUI\HtmlSnippet( $labelText ),
3547  'align' => 'top',
3548  'id' => 'wpSummaryLabel',
3549  'classes' => [ $this->missingSummary ? 'mw-summarymissed' : 'mw-summary' ],
3550  ]
3551  );
3552  }
3553 
3560  protected function showSummaryInput( $isSubjectPreview, $summary = "" ) {
3561  # Add a class if 'missingsummary' is triggered to allow styling of the summary line
3562  $summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary';
3563  if ( $isSubjectPreview ) {
3564  if ( $this->nosummary ) {
3565  return;
3566  }
3567  } elseif ( !$this->mShowSummaryField ) {
3568  return;
3569  }
3570 
3571  $labelText = $this->context->msg( $isSubjectPreview ? 'subject' : 'summary' )->parse();
3572  $this->context->getOutput()->addHTML( $this->getSummaryInputWidget(
3573  $summary,
3574  $labelText,
3575  [ 'class' => $summaryClass ]
3576  ) );
3577  }
3578 
3586  protected function getSummaryPreview( $isSubjectPreview, $summary = "" ) {
3587  // avoid spaces in preview, gets always trimmed on save
3588  $summary = trim( $summary );
3589  if ( !$summary || ( !$this->preview && !$this->diff ) ) {
3590  return "";
3591  }
3592 
3593  if ( $isSubjectPreview ) {
3594  $summary = $this->context->msg( 'newsectionsummary' )
3595  ->rawParams( MediaWikiServices::getInstance()->getParser()
3596  ->stripSectionName( $summary ) )
3597  ->inContentLanguage()->text();
3598  }
3599 
3600  $message = $isSubjectPreview ? 'subject-preview' : 'summary-preview';
3601 
3602  $summary = $this->context->msg( $message )->parse()
3603  . Linker::commentBlock( $summary, $this->mTitle, $isSubjectPreview );
3604  return Xml::tags( 'div', [ 'class' => 'mw-summary-preview' ], $summary );
3605  }
3606 
3607  protected function showFormBeforeText() {
3608  $out = $this->context->getOutput();
3609  $out->addHTML( Html::hidden( 'wpSection', $this->section ) );
3610  $out->addHTML( Html::hidden( 'wpStarttime', $this->starttime ) );
3611  $out->addHTML( Html::hidden( 'wpEdittime', $this->edittime ) );
3612  $out->addHTML( Html::hidden( 'editRevId', $this->editRevId ) );
3613  $out->addHTML( Html::hidden( 'wpScrolltop', $this->scrolltop, [ 'id' => 'wpScrolltop' ] ) );
3614  }
3615 
3616  protected function showFormAfterText() {
3629  $this->context->getOutput()->addHTML(
3630  "\n" .
3631  Html::hidden( "wpEditToken", $this->context->getUser()->getEditToken() ) .
3632  "\n"
3633  );
3634  }
3635 
3644  protected function showContentForm() {
3645  $this->showTextbox1();
3646  }
3647 
3656  protected function showTextbox1( $customAttribs = null, $textoverride = null ) {
3657  if ( $this->wasDeletedSinceLastEdit() && $this->formtype == 'save' ) {
3658  $attribs = [ 'style' => 'display:none;' ];
3659  } else {
3660  $builder = new TextboxBuilder();
3661  $classes = $builder->getTextboxProtectionCSSClasses( $this->getTitle() );
3662 
3663  # Is an old revision being edited?
3664  if ( $this->isOldRev ) {
3665  $classes[] = 'mw-textarea-oldrev';
3666  }
3667 
3668  $attribs = [
3669  'aria-label' => $this->context->msg( 'edit-textarea-aria-label' )->text(),
3670  'tabindex' => 1
3671  ];
3672 
3673  if ( is_array( $customAttribs ) ) {
3674  $attribs += $customAttribs;
3675  }
3676 
3677  $attribs = $builder->mergeClassesIntoAttributes( $classes, $attribs );
3678  }
3679 
3680  $this->showTextbox(
3681  $textoverride ?? $this->textbox1,
3682  'wpTextbox1',
3683  $attribs
3684  );
3685  }
3686 
3687  protected function showTextbox2() {
3688  $this->showTextbox( $this->textbox2, 'wpTextbox2', [ 'tabindex' => 6, 'readonly' ] );
3689  }
3690 
3691  protected function showTextbox( $text, $name, $customAttribs = [] ) {
3692  $builder = new TextboxBuilder();
3693  $attribs = $builder->buildTextboxAttribs(
3694  $name,
3695  $customAttribs,
3696  $this->context->getUser(),
3697  $this->mTitle
3698  );
3699 
3700  $this->context->getOutput()->addHTML(
3701  Html::textarea( $name, $builder->addNewLineAtEnd( $text ), $attribs )
3702  );
3703  }
3704 
3705  protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
3706  $classes = [];
3707  if ( $isOnTop ) {
3708  $classes[] = 'ontop';
3709  }
3710 
3711  $attribs = [ 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) ];
3712 
3713  if ( $this->formtype != 'preview' ) {
3714  $attribs['style'] = 'display: none;';
3715  }
3716 
3717  $out = $this->context->getOutput();
3718  $out->addHTML( Xml::openElement( 'div', $attribs ) );
3719 
3720  if ( $this->formtype == 'preview' ) {
3721  $this->showPreview( $previewOutput );
3722  } else {
3723  // Empty content container for LivePreview
3724  $pageViewLang = $this->mTitle->getPageViewLanguage();
3725  $attribs = [ 'lang' => $pageViewLang->getHtmlCode(), 'dir' => $pageViewLang->getDir(),
3726  'class' => 'mw-content-' . $pageViewLang->getDir() ];
3727  $out->addHTML( Html::rawElement( 'div', $attribs ) );
3728  }
3729 
3730  $out->addHTML( '</div>' );
3731 
3732  if ( $this->formtype == 'diff' ) {
3733  try {
3734  $this->showDiff();
3735  } catch ( MWContentSerializationException $ex ) {
3736  $msg = $this->context->msg(
3737  'content-failed-to-parse',
3738  $this->contentModel,
3739  $this->contentFormat,
3740  $ex->getMessage()
3741  );
3742  $out->wrapWikiTextAsInterface( 'error', $msg->plain() );
3743  }
3744  }
3745  }
3746 
3753  protected function showPreview( $text ) {
3754  if ( $this->mArticle instanceof CategoryPage ) {
3755  $this->mArticle->openShowCategory();
3756  }
3757  # This hook seems slightly odd here, but makes things more
3758  # consistent for extensions.
3759  $out = $this->context->getOutput();
3760  $this->getHookRunner()->onOutputPageBeforeHTML( $out, $text );
3761  $out->addHTML( $text );
3762  if ( $this->mArticle instanceof CategoryPage ) {
3763  $this->mArticle->closeShowCategory();
3764  }
3765  }
3766 
3774  public function showDiff() {
3775  $oldtitlemsg = 'currentrev';
3776  # if message does not exist, show diff against the preloaded default
3777  if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI && !$this->mTitle->exists() ) {
3778  $oldtext = $this->mTitle->getDefaultMessageText();
3779  if ( $oldtext !== false ) {
3780  $oldtitlemsg = 'defaultmessagetext';
3781  $oldContent = $this->toEditContent( $oldtext );
3782  } else {
3783  $oldContent = null;
3784  }
3785  } else {
3786  $oldContent = $this->getCurrentContent();
3787  }
3788 
3789  $textboxContent = $this->toEditContent( $this->textbox1 );
3790  if ( $this->editRevId !== null ) {
3791  $newContent = $this->page->replaceSectionAtRev(
3792  $this->section, $textboxContent, $this->summary, $this->editRevId
3793  );
3794  } else {
3795  $newContent = $this->page->replaceSectionContent(
3796  $this->section, $textboxContent, $this->summary, $this->edittime
3797  );
3798  }
3799 
3800  if ( $newContent ) {
3801  $this->getHookRunner()->onEditPageGetDiffContent( $this, $newContent );
3802 
3803  $user = $this->context->getUser();
3804  $popts = ParserOptions::newFromUserAndLang( $user,
3805  MediaWikiServices::getInstance()->getContentLanguage() );
3806  $newContent = $newContent->preSaveTransform( $this->mTitle, $user, $popts );
3807  }
3808 
3809  if ( ( $oldContent && !$oldContent->isEmpty() ) || ( $newContent && !$newContent->isEmpty() ) ) {
3810  $oldtitle = $this->context->msg( $oldtitlemsg )->parse();
3811  $newtitle = $this->context->msg( 'yourtext' )->parse();
3812 
3813  if ( !$oldContent ) {
3814  $oldContent = $newContent->getContentHandler()->makeEmptyContent();
3815  }
3816 
3817  if ( !$newContent ) {
3818  $newContent = $oldContent->getContentHandler()->makeEmptyContent();
3819  }
3820 
3821  $de = $oldContent->getContentHandler()->createDifferenceEngine( $this->context );
3822  $de->setContent( $oldContent, $newContent );
3823 
3824  $difftext = $de->getDiff( $oldtitle, $newtitle );
3825  $de->showDiffStyle();
3826  } else {
3827  $difftext = '';
3828  }
3829 
3830  $this->context->getOutput()->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
3831  }
3832 
3836  protected function showHeaderCopyrightWarning() {
3837  $msg = 'editpage-head-copy-warn';
3838  if ( !$this->context->msg( $msg )->isDisabled() ) {
3839  $this->context->getOutput()->wrapWikiMsg( "<div class='editpage-head-copywarn'>\n$1\n</div>",
3840  'editpage-head-copy-warn' );
3841  }
3842  }
3843 
3852  protected function showTosSummary() {
3853  $msg = 'editpage-tos-summary';
3854  $this->getHookRunner()->onEditPageTosSummary( $this->mTitle, $msg );
3855  if ( !$this->context->msg( $msg )->isDisabled() ) {
3856  $out = $this->context->getOutput();
3857  $out->addHTML( '<div class="mw-tos-summary">' );
3858  $out->addWikiMsg( $msg );
3859  $out->addHTML( '</div>' );
3860  }
3861  }
3862 
3867  protected function showEditTools() {
3868  $this->context->getOutput()->addHTML( '<div class="mw-editTools">' .
3869  $this->context->msg( 'edittools' )->inContentLanguage()->parse() .
3870  '</div>' );
3871  }
3872 
3879  protected function getCopywarn() {
3880  return self::getCopyrightWarning( $this->mTitle );
3881  }
3882 
3891  public static function getCopyrightWarning( $title, $format = 'plain', $langcode = null ) {
3892  global $wgRightsText;
3893  if ( $wgRightsText ) {
3894  $copywarnMsg = [ 'copyrightwarning',
3895  '[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]',
3896  $wgRightsText ];
3897  } else {
3898  $copywarnMsg = [ 'copyrightwarning2',
3899  '[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]' ];
3900  }
3901  // Allow for site and per-namespace customization of contribution/copyright notice.
3902  Hooks::runner()->onEditPageCopyrightWarning( $title, $copywarnMsg );
3903 
3904  $msg = wfMessage( ...$copywarnMsg )->title( $title );
3905  if ( $langcode ) {
3906  $msg->inLanguage( $langcode );
3907  }
3908  return "<div id=\"editpage-copywarn\">\n" .
3909  $msg->$format() . "\n</div>";
3910  }
3911 
3919  public static function getPreviewLimitReport( ParserOutput $output = null ) {
3920  global $wgLang;
3921 
3922  if ( !$output || !$output->getLimitReportData() ) {
3923  return '';
3924  }
3925 
3926  $limitReport = Html::rawElement( 'div', [ 'class' => 'mw-limitReportExplanation' ],
3927  wfMessage( 'limitreport-title' )->parseAsBlock()
3928  );
3929 
3930  // Show/hide animation doesn't work correctly on a table, so wrap it in a div.
3931  $limitReport .= Html::openElement( 'div', [ 'class' => 'preview-limit-report-wrapper' ] );
3932 
3933  $limitReport .= Html::openElement( 'table', [
3934  'class' => 'preview-limit-report wikitable'
3935  ] ) .
3936  Html::openElement( 'tbody' );
3937 
3938  foreach ( $output->getLimitReportData() as $key => $value ) {
3939  if ( Hooks::runner()->onParserLimitReportFormat( $key, $value, $limitReport, true, true ) ) {
3940  $keyMsg = wfMessage( $key );
3941  $valueMsg = wfMessage( [ "$key-value-html", "$key-value" ] );
3942  if ( !$valueMsg->exists() ) {
3943  $valueMsg = new RawMessage( '$1' );
3944  }
3945  if ( !$keyMsg->isDisabled() && !$valueMsg->isDisabled() ) {
3946  $limitReport .= Html::openElement( 'tr' ) .
3947  Html::rawElement( 'th', null, $keyMsg->parse() ) .
3948  Html::rawElement( 'td', null,
3949  $wgLang->formatNum( $valueMsg->params( $value )->parse() )
3950  ) .
3951  Html::closeElement( 'tr' );
3952  }
3953  }
3954  }
3955 
3956  $limitReport .= Html::closeElement( 'tbody' ) .
3957  Html::closeElement( 'table' ) .
3958  Html::closeElement( 'div' );
3959 
3960  return $limitReport;
3961  }
3962 
3963  protected function showStandardInputs( &$tabindex = 2 ) {
3964  $out = $this->context->getOutput();
3965  $out->addHTML( "<div class='editOptions'>\n" );
3966 
3967  if ( $this->section != 'new' ) {
3968  $this->showSummaryInput( false, $this->summary );
3969  $out->addHTML( $this->getSummaryPreview( false, $this->summary ) );
3970  }
3971 
3972  $checkboxes = $this->getCheckboxesWidget(
3973  $tabindex,
3974  [ 'minor' => $this->minoredit, 'watch' => $this->watchthis ]
3975  );
3976  $checkboxesHTML = new OOUI\HorizontalLayout( [ 'items' => $checkboxes ] );
3977 
3978  $out->addHTML( "<div class='editCheckboxes'>" . $checkboxesHTML . "</div>\n" );
3979 
3980  // Show copyright warning.
3981  $out->addWikiTextAsInterface( $this->getCopywarn() );
3982  $out->addHTML( $this->editFormTextAfterWarn );
3983 
3984  $out->addHTML( "<div class='editButtons'>\n" );
3985  $out->addHTML( implode( "\n", $this->getEditButtons( $tabindex ) ) . "\n" );
3986 
3987  $cancel = $this->getCancelLink( $tabindex++ );
3988 
3989  $message = $this->context->msg( 'edithelppage' )->inContentLanguage()->text();
3990  $edithelpurl = Skin::makeInternalOrExternalUrl( $message );
3991  $edithelp =
3993  $this->context->msg( 'edithelp' )->text(),
3994  [ 'target' => 'helpwindow', 'href' => $edithelpurl ],
3995  [ 'mw-ui-quiet' ]
3996  ) .
3997  $this->context->msg( 'word-separator' )->escaped() .
3998  $this->context->msg( 'newwindow' )->parse();
3999 
4000  $out->addHTML( " <span class='cancelLink'>{$cancel}</span>\n" );
4001  $out->addHTML( " <span class='editHelp'>{$edithelp}</span>\n" );
4002  $out->addHTML( "</div><!-- editButtons -->\n" );
4003 
4004  $this->getHookRunner()->onEditPage__showStandardInputs_options( $this, $out, $tabindex );
4005 
4006  $out->addHTML( "</div><!-- editOptions -->\n" );
4007  }
4008 
4013  protected function showConflict() {
4014  $out = $this->context->getOutput();
4015  // Avoid PHP 7.1 warning of passing $this by reference
4016  $editPage = $this;
4017  if ( $this->getHookRunner()->onEditPageBeforeConflictDiff( $editPage, $out ) ) {
4018  $this->incrementConflictStats();
4019 
4020  $this->getEditConflictHelper()->showEditFormTextAfterFooters();
4021  }
4022  }
4023 
4024  protected function incrementConflictStats() {
4025  $this->getEditConflictHelper()->incrementConflictStats( $this->context->getUser() );
4026  }
4027 
4032  public function getCancelLink( $tabindex = 0 ) {
4033  $cancelParams = [];
4034  if ( !$this->isConflict && $this->oldid > 0 ) {
4035  $cancelParams['oldid'] = $this->oldid;
4036  } elseif ( $this->getContextTitle()->isRedirect() ) {
4037  $cancelParams['redirect'] = 'no';
4038  }
4039 
4040  return new OOUI\ButtonWidget( [
4041  'id' => 'mw-editform-cancel',
4042  'tabIndex' => $tabindex,
4043  'href' => $this->getContextTitle()->getLinkURL( $cancelParams ),
4044  'label' => new OOUI\HtmlSnippet( $this->context->msg( 'cancel' )->parse() ),
4045  'framed' => false,
4046  'infusable' => true,
4047  'flags' => 'destructive',
4048  ] );
4049  }
4050 
4060  protected function getActionURL( Title $title ) {
4061  return $title->getLocalURL( [ 'action' => $this->action ] );
4062  }
4063 
4071  protected function wasDeletedSinceLastEdit() {
4072  if ( $this->deletedSinceEdit !== null ) {
4073  return $this->deletedSinceEdit;
4074  }
4075 
4076  $this->deletedSinceEdit = false;
4077 
4078  if ( !$this->mTitle->exists() && $this->mTitle->isDeletedQuick() ) {
4079  $this->lastDelete = $this->getLastDelete();
4080  if ( $this->lastDelete ) {
4081  $deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp );
4082  if ( $deleteTime > $this->starttime ) {
4083  $this->deletedSinceEdit = true;
4084  }
4085  }
4086  }
4087 
4088  return $this->deletedSinceEdit;
4089  }
4090 
4096  protected function getLastDelete() {
4097  $dbr = wfGetDB( DB_REPLICA );
4098  $commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
4099  $actorQuery = ActorMigration::newMigration()->getJoin( 'log_user' );
4100  $data = $dbr->selectRow(
4101  array_merge( [ 'logging' ], $commentQuery['tables'], $actorQuery['tables'], [ 'user' ] ),
4102  [
4103  'log_type',
4104  'log_action',
4105  'log_timestamp',
4106  'log_namespace',
4107  'log_title',
4108  'log_params',
4109  'log_deleted',
4110  'user_name'
4111  ] + $commentQuery['fields'] + $actorQuery['fields'],
4112  [
4113  'log_namespace' => $this->mTitle->getNamespace(),
4114  'log_title' => $this->mTitle->getDBkey(),
4115  'log_type' => 'delete',
4116  'log_action' => 'delete',
4117  ],
4118  __METHOD__,
4119  [ 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ],
4120  [
4121  'user' => [ 'JOIN', 'user_id=' . $actorQuery['fields']['log_user'] ],
4122  ] + $commentQuery['joins'] + $actorQuery['joins']
4123  );
4124  // Quick paranoid permission checks...
4125  if ( is_object( $data ) ) {
4126  if ( $data->log_deleted & LogPage::DELETED_USER ) {
4127  $data->user_name = $this->context->msg( 'rev-deleted-user' )->escaped();
4128  }
4129 
4130  if ( $data->log_deleted & LogPage::DELETED_COMMENT ) {
4131  $data->log_comment_text = $this->context->msg( 'rev-deleted-comment' )->escaped();
4132  $data->log_comment_data = null;
4133  }
4134  }
4135 
4136  return $data;
4137  }
4138 
4144  public function getPreviewText() {
4145  $out = $this->context->getOutput();
4146  $config = $this->context->getConfig();
4147 
4148  if ( $config->get( 'RawHtml' ) && !$this->mTokenOk ) {
4149  // Could be an offsite preview attempt. This is very unsafe if
4150  // HTML is enabled, as it could be an attack.
4151  $parsedNote = '';
4152  if ( $this->textbox1 !== '' ) {
4153  // Do not put big scary notice, if previewing the empty
4154  // string, which happens when you initially edit
4155  // a category page, due to automatic preview-on-open.
4156  $parsedNote = Html::rawElement( 'div', [ 'class' => 'previewnote' ],
4157  $out->parseAsInterface(
4158  $this->context->msg( 'session_fail_preview_html' )->plain()
4159  ) );
4160  }
4161  $this->incrementEditFailureStats( 'session_loss' );
4162  return $parsedNote;
4163  }
4164 
4165  $note = '';
4166 
4167  try {
4168  $content = $this->toEditContent( $this->textbox1 );
4169 
4170  $previewHTML = '';
4171  if ( !$this->getHookRunner()->onAlternateEditPreview(
4172  $this, $content, $previewHTML, $this->mParserOutput )
4173  ) {
4174  return $previewHTML;
4175  }
4176 
4177  # provide a anchor link to the editform
4178  $continueEditing = '<span class="mw-continue-editing">' .
4179  '[[#' . self::EDITFORM_ID . '|' .
4180  $this->context->getLanguage()->getArrow() . ' ' .
4181  $this->context->msg( 'continue-editing' )->text() . ']]</span>';
4182  if ( $this->mTriedSave && !$this->mTokenOk ) {
4183  if ( $this->mTokenOkExceptSuffix ) {
4184  $note = $this->context->msg( 'token_suffix_mismatch' )->plain();
4185  $this->incrementEditFailureStats( 'bad_token' );
4186  } else {
4187  $note = $this->context->msg( 'session_fail_preview' )->plain();
4188  $this->incrementEditFailureStats( 'session_loss' );
4189  }
4190  } elseif ( $this->incompleteForm ) {
4191  $note = $this->context->msg( 'edit_form_incomplete' )->plain();
4192  if ( $this->mTriedSave ) {
4193  $this->incrementEditFailureStats( 'incomplete_form' );
4194  }
4195  } else {
4196  $note = $this->context->msg( 'previewnote' )->plain() . ' ' . $continueEditing;
4197  }
4198 
4199  # don't parse non-wikitext pages, show message about preview
4200  if ( $this->mTitle->isUserConfigPage() || $this->mTitle->isSiteConfigPage() ) {
4201  if ( $this->mTitle->isUserConfigPage() ) {
4202  $level = 'user';
4203  } elseif ( $this->mTitle->isSiteConfigPage() ) {
4204  $level = 'site';
4205  } else {
4206  $level = false;
4207  }
4208 
4209  if ( $content->getModel() == CONTENT_MODEL_CSS ) {
4210  $format = 'css';
4211  if ( $level === 'user' && !$config->get( 'AllowUserCss' ) ) {
4212  $format = false;
4213  }
4214  } elseif ( $content->getModel() == CONTENT_MODEL_JSON ) {
4215  $format = 'json';
4216  if ( $level === 'user' /* No comparable 'AllowUserJson' */ ) {
4217  $format = false;
4218  }
4219  } elseif ( $content->getModel() == CONTENT_MODEL_JAVASCRIPT ) {
4220  $format = 'js';
4221  if ( $level === 'user' && !$config->get( 'AllowUserJs' ) ) {
4222  $format = false;
4223  }
4224  } else {
4225  $format = false;
4226  }
4227 
4228  # Used messages to make sure grep find them:
4229  # Messages: usercsspreview, userjsonpreview, userjspreview,
4230  # sitecsspreview, sitejsonpreview, sitejspreview
4231  if ( $level && $format ) {
4232  $note = "<div id='mw-{$level}{$format}preview'>" .
4233  $this->context->msg( "{$level}{$format}preview" )->plain() .
4234  ' ' . $continueEditing . "</div>";
4235  }
4236  }
4237 
4238  # If we're adding a comment, we need to show the
4239  # summary as the headline
4240  if ( $this->section === "new" && $this->summary !== "" ) {
4241  $content = $content->addSectionHeader( $this->summary );
4242  }
4243 
4244  $this->getHookRunner()->onEditPageGetPreviewContent( $this, $content );
4245 
4246  $parserResult = $this->doPreviewParse( $content );
4247  $parserOutput = $parserResult['parserOutput'];
4248  $previewHTML = $parserResult['html'];
4249  $this->mParserOutput = $parserOutput;
4250  $out->addParserOutputMetadata( $parserOutput );
4251  if ( $out->userCanPreview() ) {
4252  $out->addContentOverride( $this->getTitle(), $content );
4253  }
4254 
4255  if ( count( $parserOutput->getWarnings() ) ) {
4256  $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
4257  }
4258 
4259  } catch ( MWContentSerializationException $ex ) {
4260  $m = $this->context->msg(
4261  'content-failed-to-parse',
4262  $this->contentModel,
4263  $this->contentFormat,
4264  $ex->getMessage()
4265  );
4266  $note .= "\n\n" . $m->plain(); # gets parsed down below
4267  $previewHTML = '';
4268  }
4269 
4270  if ( $this->isConflict ) {
4271  $conflict = Html::rawElement(
4272  'div', [ 'id' => 'mw-previewconflict', 'class' => 'warningbox' ],
4273  $this->context->msg( 'previewconflict' )->escaped()
4274  );
4275  } else {
4276  $conflict = '';
4277  }
4278 
4279  $previewhead = Html::rawElement(
4280  'div', [ 'class' => 'previewnote' ],
4282  'h2', [ 'id' => 'mw-previewheader' ],
4283  $this->context->msg( 'preview' )->escaped()
4284  ) .
4285  Html::rawElement( 'div', [ 'class' => 'warningbox' ],
4286  $out->parseAsInterface( $note )
4287  ) . $conflict
4288  );
4289 
4290  $pageViewLang = $this->mTitle->getPageViewLanguage();
4291  $attribs = [ 'lang' => $pageViewLang->getHtmlCode(), 'dir' => $pageViewLang->getDir(),
4292  'class' => 'mw-content-' . $pageViewLang->getDir() ];
4293  $previewHTML = Html::rawElement( 'div', $attribs, $previewHTML );
4294 
4295  return $previewhead . $previewHTML . $this->previewTextAfterContent;
4296  }
4297 
4298  private function incrementEditFailureStats( $failureType ) {
4299  $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
4300  $stats->increment( 'edit.failures.' . $failureType );
4301  }
4302 
4307  protected function getPreviewParserOptions() {
4308  $parserOptions = $this->page->makeParserOptions( $this->context );
4309  $parserOptions->setIsPreview( true );
4310  $parserOptions->setIsSectionPreview( $this->section !== null && $this->section !== '' );
4311  $parserOptions->enableLimitReport();
4312 
4313  // XXX: we could call $parserOptions->setCurrentRevisionCallback here to force the
4314  // current revision to be null during PST, until setupFakeRevision is called on
4315  // the ParserOptions. Currently, we rely on Parser::getRevisionObject() to ignore
4316  // existing revisions in preview mode.
4317 
4318  return $parserOptions;
4319  }
4320 
4330  protected function doPreviewParse( Content $content ) {
4331  $user = $this->context->getUser();
4332  $parserOptions = $this->getPreviewParserOptions();
4333 
4334  // NOTE: preSaveTransform doesn't have a fake revision to operate on.
4335  // Parser::getRevisionObject() will return null in preview mode,
4336  // causing the context user to be used for {{subst:REVISIONUSER}}.
4337  // XXX: Alternatively, we could also call setupFakeRevision() a second time:
4338  // once before PST with $content, and then after PST with $pstContent.
4339  $pstContent = $content->preSaveTransform( $this->mTitle, $user, $parserOptions );
4340  $scopedCallback = $parserOptions->setupFakeRevision( $this->mTitle, $pstContent, $user );
4341  $parserOutput = $pstContent->getParserOutput( $this->mTitle, null, $parserOptions );
4342  ScopedCallback::consume( $scopedCallback );
4343  return [
4344  'parserOutput' => $parserOutput,
4345  'html' => $parserOutput->getText( [
4346  'enableSectionEditLinks' => false
4347  ] )
4348  ];
4349  }
4350 
4354  public function getTemplates() {
4355  if ( $this->preview || $this->section != '' ) {
4356  $templates = [];
4357  if ( !isset( $this->mParserOutput ) ) {
4358  return $templates;
4359  }
4360  foreach ( $this->mParserOutput->getTemplates() as $ns => $template ) {
4361  foreach ( array_keys( $template ) as $dbk ) {
4362  $templates[] = Title::makeTitle( $ns, $dbk );
4363  }
4364  }
4365  return $templates;
4366  } else {
4367  return $this->mTitle->getTemplateLinksFrom();
4368  }
4369  }
4370 
4376  public static function getEditToolbar() {
4377  $startingToolbar = '<div id="toolbar"></div>';
4378  $toolbar = $startingToolbar;
4379 
4380  if ( !Hooks::runner()->onEditPageBeforeEditToolbar( $toolbar ) ) {
4381  return null;
4382  }
4383  // Don't add a pointless `<div>` to the page unless a hook caller populated it
4384  return ( $toolbar === $startingToolbar ) ? null : $toolbar;
4385  }
4386 
4412  public function getCheckboxesDefinition( $checked ) {
4413  $checkboxes = [];
4414 
4415  $user = $this->context->getUser();
4416  // don't show the minor edit checkbox if it's a new page or section
4417  if ( !$this->isNew && $this->permManager->userHasRight( $user, 'minoredit' ) ) {
4418  $checkboxes['wpMinoredit'] = [
4419  'id' => 'wpMinoredit',
4420  'label-message' => 'minoredit',
4421  // Uses messages: tooltip-minoredit, accesskey-minoredit
4422  'tooltip' => 'minoredit',
4423  'label-id' => 'mw-editpage-minoredit',
4424  'legacy-name' => 'minor',
4425  'default' => $checked['minor'],
4426  ];
4427  }
4428 
4429  if ( $user->isLoggedIn() ) {
4430  $checkboxes = array_merge(
4431  $checkboxes,
4432  $this->getCheckboxesDefinitionForWatchlist( $checked['watch'] )
4433  );
4434  }
4435 
4436  $this->getHookRunner()->onEditPageGetCheckboxesDefinition( $this, $checkboxes );
4437 
4438  return $checkboxes;
4439  }
4440 
4448  private function getCheckboxesDefinitionForWatchlist( $watch ) {
4449  $fieldDefs = [
4450  'wpWatchthis' => [
4451  'id' => 'wpWatchthis',
4452  'label-message' => 'watchthis',
4453  // Uses messages: tooltip-watch, accesskey-watch
4454  'tooltip' => 'watch',
4455  'label-id' => 'mw-editpage-watch',
4456  'legacy-name' => 'watch',
4457  'default' => $watch,
4458  ]
4459  ];
4460  if ( $this->watchlistExpiryEnabled ) {
4461  $watchedItem = $this->watchedItemStore->getWatchedItem( $this->getContext()->getUser(), $this->getTitle() );
4462  $expiryOptions = WatchAction::getExpiryOptions( $this->getContext(), $watchedItem );
4463  // When previewing, override the selected dropdown option to select whatever was posted
4464  // (if it's a valid option) rather than the current value for watchlistExpiry.
4465  // See also above in $this->importFormData().
4466  $expiryFromRequest = $this->getContext()->getRequest()->getText( 'wpWatchlistExpiry' );
4467  if ( $this->preview && in_array( $expiryFromRequest, $expiryOptions['options'] ) ) {
4468  $expiryOptions['default'] = $expiryFromRequest;
4469  }
4470  // Reformat the options to match what DropdownInputWidget wants.
4471  $options = [];
4472  foreach ( $expiryOptions['options'] as $label => $value ) {
4473  $options[] = [ 'data' => $value, 'label' => $label ];
4474  }
4475  $fieldDefs['wpWatchlistExpiry'] = [
4476  'id' => 'wpWatchlistExpiry',
4477  'label-message' => 'confirm-watch-label',
4478  // Uses messages: tooltip-watchlist-expiry, accesskey-watchlist-expiry
4479  'tooltip' => 'watchlist-expiry',
4480  'label-id' => 'mw-editpage-watchlist-expiry',
4481  'default' => $expiryOptions['default'],
4482  'value-attr' => 'value',
4483  'class' => DropdownInputWidget::class,
4484  'options' => $options,
4485  ];
4486  }
4487  return $fieldDefs;
4488  }
4489 
4501  public function getCheckboxesWidget( &$tabindex, $checked ) {
4502  $checkboxes = [];
4503  $checkboxesDef = $this->getCheckboxesDefinition( $checked );
4504 
4505  foreach ( $checkboxesDef as $name => $options ) {
4506  $legacyName = $options['legacy-name'] ?? $name;
4507 
4508  $title = null;
4509  $accesskey = null;
4510  if ( isset( $options['tooltip'] ) ) {
4511  $accesskey = $this->context->msg( "accesskey-{$options['tooltip']}" )->text();
4512  $title = Linker::titleAttrib( $options['tooltip'] );
4513  }
4514  if ( isset( $options['title-message'] ) ) {
4515  $title = $this->context->msg( $options['title-message'] )->text();
4516  }
4517  // Allow checkbox definitions to set their own class and value-attribute names.
4518  // See $this->getCheckboxesDefinition() for details.
4519  $className = $options['class'] ?? CheckboxInputWidget::class;
4520  $valueAttr = $options['value-attr'] ?? 'selected';
4521  $checkboxes[ $legacyName ] = new FieldLayout(
4522  new $className( [
4523  'tabIndex' => ++$tabindex,
4524  'accessKey' => $accesskey,
4525  'id' => $options['id'] . 'Widget',
4526  'inputId' => $options['id'],
4527  'name' => $name,
4528  $valueAttr => $options['default'],
4529  'infusable' => true,
4530  'options' => $options['options'] ?? null,
4531  ] ),
4532  [
4533  'align' => 'inline',
4534  'label' => new OOUI\HtmlSnippet( $this->context->msg( $options['label-message'] )->parse() ),
4535  'title' => $title,
4536  'id' => $options['label-id'] ?? null,
4537  ]
4538  );
4539  }
4540 
4541  return $checkboxes;
4542  }
4543 
4550  protected function getSubmitButtonLabel() {
4551  $labelAsPublish =
4552  $this->context->getConfig()->get( 'EditSubmitButtonLabelPublish' );
4553 
4554  // Can't use $this->isNew as that's also true if we're adding a new section to an extant page
4555  $newPage = !$this->mTitle->exists();
4556 
4557  if ( $labelAsPublish ) {
4558  $buttonLabelKey = $newPage ? 'publishpage' : 'publishchanges';
4559  } else {
4560  $buttonLabelKey = $newPage ? 'savearticle' : 'savechanges';
4561  }
4562 
4563  return $buttonLabelKey;
4564  }
4565 
4574  public function getEditButtons( &$tabindex ) {
4575  $buttons = [];
4576 
4577  $labelAsPublish =
4578  $this->context->getConfig()->get( 'EditSubmitButtonLabelPublish' );
4579 
4580  $buttonLabel = $this->context->msg( $this->getSubmitButtonLabel() )->text();
4581  $buttonTooltip = $labelAsPublish ? 'publish' : 'save';
4582 
4583  $buttons['save'] = new OOUI\ButtonInputWidget( [
4584  'name' => 'wpSave',
4585  'tabIndex' => ++$tabindex,
4586  'id' => 'wpSaveWidget',
4587  'inputId' => 'wpSave',
4588  // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
4589  'useInputTag' => true,
4590  'flags' => [ 'progressive', 'primary' ],
4591  'label' => $buttonLabel,
4592  'infusable' => true,
4593  'type' => 'submit',
4594  // Messages used: tooltip-save, tooltip-publish
4595  'title' => Linker::titleAttrib( $buttonTooltip ),
4596  // Messages used: accesskey-save, accesskey-publish
4597  'accessKey' => Linker::accesskey( $buttonTooltip ),
4598  ] );
4599 
4600  $buttons['preview'] = new OOUI\ButtonInputWidget( [
4601  'name' => 'wpPreview',
4602  'tabIndex' => ++$tabindex,
4603  'id' => 'wpPreviewWidget',
4604  'inputId' => 'wpPreview',
4605  // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
4606  'useInputTag' => true,
4607  'label' => $this->context->msg( 'showpreview' )->text(),
4608  'infusable' => true,
4609  'type' => 'submit',
4610  // Message used: tooltip-preview
4611  'title' => Linker::titleAttrib( 'preview' ),
4612  // Message used: accesskey-preview
4613  'accessKey' => Linker::accesskey( 'preview' ),
4614  ] );
4615 
4616  $buttons['diff'] = new OOUI\ButtonInputWidget( [
4617  'name' => 'wpDiff',
4618  'tabIndex' => ++$tabindex,
4619  'id' => 'wpDiffWidget',
4620  'inputId' => 'wpDiff',
4621  // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
4622  'useInputTag' => true,
4623  'label' => $this->context->msg( 'showdiff' )->text(),
4624  'infusable' => true,
4625  'type' => 'submit',
4626  // Message used: tooltip-diff
4627  'title' => Linker::titleAttrib( 'diff' ),
4628  // Message used: accesskey-diff
4629  'accessKey' => Linker::accesskey( 'diff' ),
4630  ] );
4631 
4632  $this->getHookRunner()->onEditPageBeforeEditButtons( $this, $buttons, $tabindex );
4633 
4634  return $buttons;
4635  }
4636 
4641  public function noSuchSectionPage() {
4642  $out = $this->context->getOutput();
4643  $out->prepareErrorPage( $this->context->msg( 'nosuchsectiontitle' ) );
4644 
4645  $res = $this->context->msg( 'nosuchsectiontext', $this->section )->parseAsBlock();
4646 
4647  $this->getHookRunner()->onEditPageNoSuchSection( $this, $res );
4648  $out->addHTML( $res );
4649 
4650  $out->returnToMain( false, $this->mTitle );
4651  }
4652 
4658  public function spamPageWithContent( $match = false ) {
4659  $this->textbox2 = $this->textbox1;
4660 
4661  if ( is_array( $match ) ) {
4662  $match = $this->context->getLanguage()->listToText( $match );
4663  }
4664  $out = $this->context->getOutput();
4665  $out->prepareErrorPage( $this->context->msg( 'spamprotectiontitle' ) );
4666 
4667  $out->addHTML( '<div id="spamprotected">' );
4668  $out->addWikiMsg( 'spamprotectiontext' );
4669  if ( $match ) {
4670  $out->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
4671  }
4672  $out->addHTML( '</div>' );
4673 
4674  $out->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
4675  $this->showDiff();
4676 
4677  $out->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
4678  $this->showTextbox2();
4679 
4680  $out->addReturnTo( $this->getContextTitle(), [ 'action' => 'edit' ] );
4681  }
4682 
4686  protected function addEditNotices() {
4687  $out = $this->context->getOutput();
4688  $editNotices = $this->mTitle->getEditNotices( $this->oldid );
4689  if ( count( $editNotices ) ) {
4690  $out->addHTML( implode( "\n", $editNotices ) );
4691  } else {
4692  $msg = $this->context->msg( 'editnotice-notext' );
4693  if ( !$msg->isDisabled() ) {
4694  $out->addHTML(
4695  '<div class="mw-editnotice-notext">'
4696  . $msg->parseAsBlock()
4697  . '</div>'
4698  );
4699  }
4700  }
4701  }
4702 
4706  protected function addTalkPageText() {
4707  if ( $this->mTitle->isTalkPage() ) {
4708  $this->context->getOutput()->addWikiMsg( 'talkpagetext' );
4709  }
4710  }
4711 
4715  protected function addLongPageWarningHeader() {
4716  if ( $this->contentLength === false ) {
4717  $this->contentLength = strlen( $this->textbox1 );
4718  }
4719 
4720  $out = $this->context->getOutput();
4721  $lang = $this->context->getLanguage();
4722  $maxArticleSize = $this->context->getConfig()->get( 'MaxArticleSize' );
4723  if ( $this->tooBig || $this->contentLength > $maxArticleSize * 1024 ) {
4724  $out->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
4725  [
4726  'longpageerror',
4727  $lang->formatNum( round( $this->contentLength / 1024, 3 ) ),
4728  $lang->formatNum( $maxArticleSize )
4729  ]
4730  );
4731  } elseif ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) {
4732  $out->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
4733  [
4734  'longpage-hint',
4735  $lang->formatSize( strlen( $this->textbox1 ) ),
4736  strlen( $this->textbox1 )
4737  ]
4738  );
4739  }
4740  }
4741 
4745  protected function addPageProtectionWarningHeaders() {
4746  $out = $this->context->getOutput();
4747  if ( $this->mTitle->isProtected( 'edit' ) &&
4748  $this->permManager->getNamespaceRestrictionLevels(
4749  $this->getTitle()->getNamespace()
4750  ) !== [ '' ]
4751  ) {
4752  # Is the title semi-protected?
4753  if ( $this->mTitle->isSemiProtected() ) {
4754  $noticeMsg = 'semiprotectedpagewarning';
4755  } else {
4756  # Then it must be protected based on static groups (regular)
4757  $noticeMsg = 'protectedpagewarning';
4758  }
4759  LogEventsList::showLogExtract( $out, 'protect', $this->mTitle, '',
4760  [ 'lim' => 1, 'msgKey' => [ $noticeMsg ] ] );
4761  }
4762  if ( $this->mTitle->isCascadeProtected() ) {
4763  # Is this page under cascading protection from some source pages?
4764 
4765  list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources();
4766  $notice = "<div class='warningbox mw-cascadeprotectedwarning'>\n$1\n";
4767  $cascadeSourcesCount = count( $cascadeSources );
4768  if ( $cascadeSourcesCount > 0 ) {
4769  # Explain, and list the titles responsible
4770  foreach ( $cascadeSources as $page ) {
4771  $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
4772  }
4773  }
4774  $notice .= '</div>';
4775  $out->wrapWikiMsg( $notice, [ 'cascadeprotectedwarning', $cascadeSourcesCount ] );
4776  }
4777  if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
4778  LogEventsList::showLogExtract( $out, 'protect', $this->mTitle, '',
4779  [ 'lim' => 1,
4780  'showIfEmpty' => false,
4781  'msgKey' => [ 'titleprotectedwarning' ],
4782  'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ] );
4783  }
4784  }
4785 
4790  protected function addExplainConflictHeader( OutputPage $out ) {
4791  $out->addHTML(
4792  $this->getEditConflictHelper()->getExplainHeader()
4793  );
4794  }
4795 
4803  protected function buildTextboxAttribs( $name, array $customAttribs, User $user ) {
4804  return ( new TextboxBuilder() )->buildTextboxAttribs(
4805  $name, $customAttribs, $user, $this->mTitle
4806  );
4807  }
4808 
4814  protected function addNewLineAtEnd( $wikitext ) {
4815  return ( new TextboxBuilder() )->addNewLineAtEnd( $wikitext );
4816  }
4817 
4828  private function guessSectionName( $text ) {
4829  // Detect Microsoft browsers
4830  $userAgent = $this->context->getRequest()->getHeader( 'User-Agent' );
4831  $parser = MediaWikiServices::getInstance()->getParser();
4832  if ( $userAgent && preg_match( '/MSIE|Edge/', $userAgent ) ) {
4833  // ...and redirect them to legacy encoding, if available
4834  return $parser->guessLegacySectionNameFromWikiText( $text );
4835  }
4836  // Meanwhile, real browsers get real anchors
4837  $name = $parser->guessSectionNameFromWikiText( $text );
4838  // With one little caveat: per T216029, fragments in HTTP redirects need to be urlencoded,
4839  // otherwise Chrome double-escapes the rest of the URL.
4840  return '#' . urlencode( mb_substr( $name, 1 ) );
4841  }
4842 
4849  public function setEditConflictHelperFactory( callable $factory ) {
4850  $this->editConflictHelperFactory = $factory;
4851  $this->editConflictHelper = null;
4852  }
4853 
4857  private function getEditConflictHelper() {
4858  if ( !$this->editConflictHelper ) {
4859  $this->editConflictHelper = call_user_func(
4860  $this->editConflictHelperFactory,
4861  $this->getSubmitButtonLabel()
4862  );
4863  }
4864 
4866  }
4867 
4873  private function newTextConflictHelper( $submitButtonLabel ) {
4874  return new TextConflictHelper(
4875  $this->getTitle(),
4876  $this->getContext()->getOutput(),
4877  MediaWikiServices::getInstance()->getStatsdDataFactory(),
4878  $submitButtonLabel,
4879  MediaWikiServices::getInstance()->getContentHandlerFactory()
4880  );
4881  }
4882 }
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
WikiPage\hasDifferencesOutsideMainSlot
static hasDifferencesOutsideMainSlot( $a, $b)
Helper method for checking whether two revisions have differences that go beyond the main slot.
Definition: WikiPage.php:1526
EditPage\__construct
__construct(Article $article)
Stable to call.
Definition: EditPage.php:456
EditPage\$editFormTextBeforeContent
$editFormTextBeforeContent
Definition: EditPage.php:384
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:32
EditPage\$mTriedSave
bool $mTriedSave
Definition: EditPage.php:163
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:228
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:44
EditPage\$contentModel
string $contentModel
Definition: EditPage.php:370
EditPage\showFormBeforeText
showFormBeforeText()
Definition: EditPage.php:3607
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:329
EditPage\$lastDelete
bool stdClass $lastDelete
Definition: EditPage.php:145
EditPage\tokenOk
tokenOk(&$request)
Make sure the form isn't faking a user's credentials.
Definition: EditPage.php:1687
EditPage\$editFormPageTop
string $editFormPageTop
Before even the preview.
Definition: EditPage.php:382
MediaWiki\EditPage\IEditObject\AS_SUCCESS_NEW_ARTICLE
const AS_SUCCESS_NEW_ARTICLE
Status: Article successfully created.
Definition: IEditObject.php:17
EditPage\showContentForm
showContentForm()
Subpage overridable method for printing the form for page content editing By default this simply outp...
Definition: EditPage.php:3644
EditPage\$mTitle
Title $mTitle
Definition: EditPage.php:109
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
EditPage\$watchlistExpiryEnabled
bool $watchlistExpiryEnabled
Corresponds to $wgWatchlistExpiry.
Definition: EditPage.php:273
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:26
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:165
Html\textarea
static textarea( $name, $value='', array $attribs=[])
Convenience function to produce a <textarea> element.
Definition: Html.php:818
EditPage\spamPageWithContent
spamPageWithContent( $match=false)
Show "your edit contains spam" page with your diff and text.
Definition: EditPage.php:4658
MediaWiki\EditPage\IEditObject\AS_TEXTBOX_EMPTY
const AS_TEXTBOX_EMPTY
Status: user tried to create a new section without content.
Definition: IEditObject.php:62
EditPage\$section
string $section
Definition: EditPage.php:325
ParserOutput
Definition: ParserOutput.php:25
WikiPage\getRedirectTarget
getRedirectTarget()
If this page is a redirect, get its target.
Definition: WikiPage.php:978
UserBlockedError
Show an error when the user tries to do something whilst blocked.
Definition: UserBlockedError.php:31
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:59
MediaWiki\EditPage\IEditObject\AS_CONFLICT_DETECTED
const AS_CONFLICT_DETECTED
Status: (non-resolvable) edit conflict.
Definition: IEditObject.php:53
EditPage\mergeChangesIntoContent
mergeChangesIntoContent(&$editContent)
Attempts to do 3-way merge of edit content with a base revision and current content,...
Definition: EditPage.php:2622
EditPage\displayPermissionsError
displayPermissionsError(array $permErrors)
Display a permissions error page, like OutputPage::showPermissionsErrorPage(), but with the following...
Definition: EditPage.php:762
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:100
EditPage\$editFormTextAfterContent
$editFormTextAfterContent
Definition: EditPage.php:388
EditPage\displayPreviewArea
displayPreviewArea( $previewOutput, $isOnTop=false)
Definition: EditPage.php:3705
EditPage\$blankArticle
bool $blankArticle
Definition: EditPage.php:196
EditPage\$allowBlankSummary
bool $allowBlankSummary
Definition: EditPage.php:193
$wgRightsText
$wgRightsText
If either $wgRightsUrl or $wgRightsPage is specified then this variable gives the text for the link.
Definition: DefaultSettings.php:7573
EditPage\$editFormTextBottom
$editFormTextBottom
Definition: EditPage.php:387
EditPage\getSummaryInputAttributes
getSummaryInputAttributes(array $inputAttrs=null)
Helper function for summary input functions, which returns the necessary attributes for the input.
Definition: EditPage.php:3504
EditPage\$editFormTextTop
$editFormTextTop
Definition: EditPage.php:383
EditPage\$editintro
string $editintro
Definition: EditPage.php:355
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:154
EditPage\showTextbox2
showTextbox2()
Definition: EditPage.php:3687
EDIT_FORCE_BOT
const EDIT_FORCE_BOT
Definition: Defines.php:145
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
EditPage\$summary
string $summary
Definition: EditPage.php:296
EditPage\buildTextboxAttribs
buildTextboxAttribs( $name, array $customAttribs, User $user)
Definition: EditPage.php:4803
Revision\RevisionStore
Service for looking up page revisions.
Definition: RevisionStore.php:81
EditPage\$textbox2
string $textbox2
Definition: EditPage.php:293
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:1610
EditPage\$mTokenOk
bool $mTokenOk
Definition: EditPage.php:151
EditPage\$contentHandlerFactory
IContentHandlerFactory $contentHandlerFactory
Definition: EditPage.php:440
EditPage\getUndoContent
getUndoContent(RevisionRecord $undoRev, RevisionRecord $oldRev)
Returns the result of a three-way merge when undoing changes.
Definition: EditPage.php:1461
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:226
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1808
EditPage\$oldid
int $oldid
Revision ID the edit is based on, or 0 if it's the current revision.
Definition: EditPage.php:340
MediaWiki\EditPage\TextboxBuilder
Helps EditPage build textboxes.
Definition: TextboxBuilder.php:37
getUser
getUser()
EditPage\getContextTitle
getContextTitle()
Get the context title object.
Definition: EditPage.php:527
EditPage\getEditToolbar
static getEditToolbar()
Allow extensions to provide a toolbar.
Definition: EditPage.php:4376
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:71
EditPage\showTosSummary
showTosSummary()
Give a chance for site and per-namespace customizations of terms of service summary link that might e...
Definition: EditPage.php:3852
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:103
EditPage\$save
bool $save
Definition: EditPage.php:252
WatchAction\getExpiryOptions
static getExpiryOptions(MessageLocalizer $msgLocalizer, $watchedItem)
Get options and default for a watchlist expiry select list.
Definition: WatchAction.php:125
EditPage\addPageProtectionWarningHeaders
addPageProtectionWarningHeaders()
Definition: EditPage.php:4745
EditPage\getExpectedParentRevision
getExpectedParentRevision()
Returns the RevisionRecord corresponding to the revision that was current at the time editing was ini...
Definition: EditPage.php:2692
EditPage\setContextTitle
setContextTitle( $title)
Set the context Title object.
Definition: EditPage.php:515
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:52
EditPage\edit
edit()
This is the function that gets called for "action=edit".
Definition: EditPage.php:570
EditPage\$autoSumm
string $autoSumm
Definition: EditPage.php:211
MediaWiki\EditPage\IEditObject\AS_END
const AS_END
Status: WikiPage::doEdit() was unsuccessful.
Definition: IEditObject.php:68
NS_FILE
const NS_FILE
Definition: Defines.php:75
$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:4096
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1125
EditPage\incrementConflictStats
incrementConflictStats()
Definition: EditPage.php:4024
EditPage\addEditNotices
addEditNotices()
Definition: EditPage.php:4686
StatusValue\fatal
fatal( $message,... $parameters)
Add an error and set OK to false, indicating that the operation as a whole was fatal.
Definition: StatusValue.php:209
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:538
Revision\RevisionRecord\getSlot
getSlot( $role, $audience=self::FOR_PUBLIC, User $user=null)
Returns meta-data for the given slot.
Definition: RevisionRecord.php:191
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1219
EditPage\$editFormTextAfterTools
$editFormTextAfterTools
Definition: EditPage.php:386
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:92
EditPage\getEditPermissionErrors
getEditPermissionErrors( $rigor=PermissionManager::RIGOR_SECURE)
Definition: EditPage.php:709
EditPage\$editFormTextAfterWarn
$editFormTextAfterWarn
Definition: EditPage.php:385
EditPage\setPreloadedContent
setPreloadedContent(Content $content)
Use this method before edit() to preload some content into the edit box.
Definition: EditPage.php:1595
MediaWiki\EditPage\IEditObject\AS_CONTENT_TOO_BIG
const AS_CONTENT_TOO_BIG
Status: Content too big (> $wgMaxArticleSize)
Definition: IEditObject.php:29
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition: PermissionsError.php:31
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:47
MediaWiki\EditPage\IEditObject\AS_SUCCESS_UPDATE
const AS_SUCCESS_UPDATE
Status: Article successfully updated.
Definition: IEditObject.php:14
MediaWiki\EditPage\TextConflictHelper\setContentFormat
setContentFormat( $contentFormat)
Definition: TextConflictHelper.php:139
EditPage\showHeaderCopyrightWarning
showHeaderCopyrightWarning()
Show the header copyright warning.
Definition: EditPage.php:3836
EditPage\getCheckboxesDefinitionForWatchlist
getCheckboxesDefinitionForWatchlist( $watch)
Get the watchthis and watchlistExpiry form field definitions.
Definition: EditPage.php:4448
Html\warningBox
static warningBox( $html, $className='')
Return a warning box.
Definition: Html.php:726
EditPage\$mExpectedParentRevision
RevisionRecord bool null $mExpectedParentRevision
A RevisionRecord corresponding to $this->editRevId or $this->edittime Replaced $mBaseRevision.
Definition: EditPage.php:244
EditPage\addLongPageWarningHeader
addLongPageWarningHeader()
Definition: EditPage.php:4715
EditPage\$context
IContextSource $context
Definition: EditPage.php:413
$res
$res
Definition: testCompression.php:57
EditPage\$didSave
$didSave
Definition: EditPage.php:393
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:108
$wgTitle
$wgTitle
Definition: Setup.php:794
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:988
OutputPage\addHTML
addHTML( $text)
Append $text to the body HTML.
Definition: OutputPage.php:1615
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:140
Linker\formatHiddenCategories
static formatHiddenCategories( $hiddencats)
Returns HTML for the "hidden categories on this page" list.
Definition: Linker.php:2075
EditPage\$mArticle
Article $mArticle
Definition: EditPage.php:101
EditPage\$contentFormat
null string $contentFormat
Definition: EditPage.php:373
Skin\getSkinNames
static getSkinNames()
Fetch the set of available skins.
Definition: Skin.php:66
EditPage\POST_EDIT_COOKIE_DURATION
const POST_EDIT_COOKIE_DURATION
Duration of PostEdit cookie, in seconds.
Definition: EditPage.php:95
$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:435
Revision
Definition: Revision.php:40
EditPage\$watchthis
bool $watchthis
Definition: EditPage.php:270
EditPage\$previewTextAfterContent
$previewTextAfterContent
Definition: EditPage.php:389
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:315
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:3774
EditPage\$tooBig
bool $tooBig
Definition: EditPage.php:175
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:16
StatusValue\isGood
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Definition: StatusValue.php:122
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:31
MediaWiki\EditPage\IEditObject\AS_RATE_LIMITED
const AS_RATE_LIMITED
Status: rate limiter for action 'edit' was tripped.
Definition: IEditObject.php:41
EditPage\UNICODE_CHECK
const UNICODE_CHECK
Used for Unicode support checks.
Definition: EditPage.php:69
MWException
MediaWiki exception.
Definition: MWException.php:29
EditPage\addContentModelChangeLogEntry
addContentModelChangeLogEntry(User $user, $oldModel, $newModel, $reason)
Definition: EditPage.php:2572
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:156
EditPage\toEditContent
toEditContent( $text)
Turns the given text into a Content object by unserializing it.
Definition: EditPage.php:2995
Article\getTitle
getTitle()
Get the title object of the article.
Definition: Article.php:255
EditPage\getEditButtons
getEditButtons(&$tabindex)
Returns an array of html code of the following buttons: save, diff and preview.
Definition: EditPage.php:4574
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1026
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
LogPage\DELETED_COMMENT
const DELETED_COMMENT
Definition: LogPage.php:39
EditPage\$editRevId
int $editRevId
Revision ID of the latest revision of the page when editing was initiated on the client.
Definition: EditPage.php:322
EditPage\showSummaryInput
showSummaryInput( $isSubjectPreview, $summary="")
Definition: EditPage.php:3560
EditPage\getParentRevId
getParentRevId()
Get the edit's parent revision ID.
Definition: EditPage.php:1521
ParserOptions\newFromUserAndLang
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
Definition: ParserOptions.php:1101
wfArrayDiff2
wfArrayDiff2( $a, $b)
Like array_diff( $a, $b ) except that it works with two-dimensional arrays.
Definition: GlobalFunctions.php:112
EditPage\isSectionEditSupported
isSectionEditSupported()
Returns whether section editing is supported for the current page.
Definition: EditPage.php:907
EditPage\importFormData
importFormData(&$request)
This function collects the form data and uses it to populate various member variables.
Definition: EditPage.php:918
EditPage\getActionURL
getActionURL(Title $title)
Returns the URL to use in the form's action attribute.
Definition: EditPage.php:4060
EditPage\addExplainConflictHeader
addExplainConflictHeader(OutputPage $out)
Definition: EditPage.php:4790
LogPage\DELETED_USER
const DELETED_USER
Definition: LogPage.php:40
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2467
EditPage\showIntro
showIntro()
Show all applicable editing introductions.
Definition: EditPage.php:2809
EditPage\$firsttime
bool $firsttime
True the first time the edit form is rendered, false after re-rendering with diff,...
Definition: EditPage.php:139
$matches
$matches
Definition: NoLocalSettings.php:24
StatusValue\isOK
isOK()
Returns whether the operation completed.
Definition: StatusValue.php:131
EditPage\$missingComment
bool $missingComment
Definition: EditPage.php:181
MediaWiki\EditPage\IEditObject\AS_SELF_REDIRECT
const AS_SELF_REDIRECT
Status: user tried to create self-redirect and wpIgnoreSelfRedirect is false.
Definition: IEditObject.php:86
EditPage\getPreviewLimitReport
static getPreviewLimitReport(ParserOutput $output=null)
Get the Limit report for page previews.
Definition: EditPage.php:3919
EditPage\$editConflictHelperFactory
callable $editConflictHelperFactory
Factory function to create an edit conflict helper.
Definition: EditPage.php:430
$wgLang
$wgLang
Definition: Setup.php:776
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:1730
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:265
Article\getContext
getContext()
Gets the context this Article is executed in.
Definition: Article.php:2336
User\isIP
static isIP( $name)
Does the string match an anonymous IP address?
Definition: User.php:948
EditPage\getArticle
getArticle()
Definition: EditPage.php:490
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:4501
EditPage\previewOnOpen
previewOnOpen()
Should we show a preview when the edit form is first shown?
Definition: EditPage.php:845
EditPage\incrementEditFailureStats
incrementEditFailureStats( $failureType)
Definition: EditPage.php:4298
$title
$title
Definition: testCompression.php:38
EditPage\$allowSelfRedirect
bool $allowSelfRedirect
Definition: EditPage.php:205
EditPage\showEditForm
showEditForm( $formCallback=null)
Send the edit form and related headers to OutputPage.
Definition: EditPage.php:3018
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:592
LogEventsList\showLogExtract
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Definition: LogEventsList.php:639
EditPage\isUndoClean
isUndoClean(Content $content)
Does sanity checks and compares the automatically generated undo content with the one that was submit...
Definition: EditPage.php:2530
EditPage\wasDeletedSinceLastEdit
wasDeletedSinceLastEdit()
Check if a page was deleted while the user was editing it, before submit.
Definition: EditPage.php:4071
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
EditPage\getTemplates
getTemplates()
Definition: EditPage.php:4354
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1837
EditPage\getPreviewParserOptions
getPreviewParserOptions()
Get parser options for a preview.
Definition: EditPage.php:4307
EditPage\runPostMergeFilters
runPostMergeFilters(Content $content, Status $status, User $user)
Run hooks that can filter edits just before they get saved.
Definition: EditPage.php:1908
DB_MASTER
const DB_MASTER
Definition: defines.php:26
EditPage\$mContextTitle
null Title $mContextTitle
Definition: EditPage.php:112
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:909
EditPage\showFormAfterText
showFormAfterText()
Definition: EditPage.php:3616
EditPage\getCancelLink
getCancelLink( $tabindex=0)
Definition: EditPage.php:4032
OutputPage
This is one of the Core classes and should be read at least once by any new developers.
Definition: OutputPage.php:47
EditPage\showPreview
showPreview( $text)
Append preview output to OutputPage.
Definition: EditPage.php:3753
EditPage\initialiseForm
initialiseForm()
Initialise form fields in the object Called on the first invocation, e.g.
Definition: EditPage.php:1165
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:142
deprecatePublicProperty
deprecatePublicProperty( $property, $version, $class=null, $component=null)
Mark a property as deprecated.
Definition: DeprecationHelper.php:68
MediaWiki\EditPage\TextConflictHelper\setTextboxes
setTextboxes( $yourtext, $storedversion)
Definition: TextConflictHelper.php:124
Revision\RevisionRecord\getId
getId()
Get revision ID.
Definition: RevisionRecord.php:279
MediaWiki\EditPage\TextConflictHelper
Helper for displaying edit conflicts in text content models to users.
Definition: TextConflictHelper.php:44
EditPage\isPageExistingAndViewable
isPageExistingAndViewable( $title, User $user)
Verify if a given title exists and the given user is allowed to view it.
Definition: EditPage.php:1676
EditPage\matchSpamRegex
static matchSpamRegex( $text)
Check given input text against $wgSpamRegex, and return the text of the first match.
Definition: EditPage.php:2721
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:802
EditPage\$recreate
bool $recreate
Definition: EditPage.php:285
MediaWiki\EditPage\IEditObject\AS_UNICODE_NOT_SUPPORTED
const AS_UNICODE_NOT_SUPPORTED
Status: edit rejected because browser doesn't support Unicode.
Definition: IEditObject.php:103
EditPage\$contentLength
bool int $contentLength
Definition: EditPage.php:403
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:83
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:35
EditPage\showTextbox1
showTextbox1( $customAttribs=null, $textoverride=null)
Method to output wpTextbox1 The $textoverride method can be used by subclasses overriding showContent...
Definition: EditPage.php:3656
EditPage\addTalkPageText
addTalkPageText()
Definition: EditPage.php:4706
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:49
$content
$content
Definition: router.php:76
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:72
EditPage\getSummaryPreview
getSummaryPreview( $isSubjectPreview, $summary="")
Definition: EditPage.php:3586
EditPage\importContentFormData
importContentFormData(&$request)
Subpage overridable method for extracting the page content data from the posted form to be placed in ...
Definition: EditPage.php:1156
EditPage\$minoredit
bool $minoredit
Definition: EditPage.php:264
EditPage\$isOldRev
bool $isOldRev
Whether an old revision is edited.
Definition: EditPage.php:418
TemplatesOnThisPageFormatter
Handles formatting for the "templates used on this page" lists.
Definition: TemplatesOnThisPageFormatter.php:31
ExternalUserNames\getUserLinkTitle
static getUserLinkTitle( $userName)
Get a target Title to link a username.
Definition: ExternalUserNames.php:62
EditPage\$enableApiEditOverride
bool $enableApiEditOverride
Set in ApiEditPage, based on ContentHandler::allowsDirectApiEditing.
Definition: EditPage.php:408
EDIT_UPDATE
const EDIT_UPDATE
Definition: Defines.php:142
EditPage\showHeader
showHeader()
Definition: EditPage.php:3321
MediaWiki\EditPage\TextConflictHelper\getEditFormHtmlAfterContent
getEditFormHtmlAfterContent()
Content to go in the edit form after textbox1.
Definition: TextConflictHelper.php:264
EditPage\getBaseRevision
getBaseRevision()
Returns the revision that was current at the time editing was initiated on the client,...
Definition: EditPage.php:2676
ContentHandler\getLocalizedName
static getLocalizedName( $name, Language $lang=null)
Returns the localized name for a given content model.
Definition: ContentHandler.php:299
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:1574
EditPage\addNewLineAtEnd
addNewLineAtEnd( $wikitext)
Definition: EditPage.php:4814
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:74
Message\plaintextParam
static plaintextParam( $plaintext)
Definition: Message.php:1114
EditPage\incrementResolvedConflicts
incrementResolvedConflicts()
Log when a page was successfully saved after the edit conflict view.
Definition: EditPage.php:1749
StatusValue\getErrors
getErrors()
Get the list of errors.
Definition: StatusValue.php:149
Xml\tags
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:130
EditPage\$edittime
string $edittime
Timestamp of the latest revision of the page when editing was initiated on the client.
Definition: EditPage.php:309
EditPage\matchSummarySpamRegex
static matchSummarySpamRegex( $text)
Check given input text against $wgSummarySpamRegex, and return the text of the first match.
Definition: EditPage.php:2735
EditPage\$mTokenOkExceptSuffix
bool $mTokenOkExceptSuffix
Definition: EditPage.php:157
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:172
EditPage\showEditTools
showEditTools()
Inserts optional text shown below edit and upload forms.
Definition: EditPage.php:3867
EditPage\$preview
bool $preview
Definition: EditPage.php:255
EditPage\$isNew
bool $isNew
New page or new section.
Definition: EditPage.php:124
EditPage\getCheckboxesDefinition
getCheckboxesDefinition( $checked)
Return an array of checkbox definitions.
Definition: EditPage.php:4412
EditPage\$mBaseRevision
Revision bool null $mBaseRevision
A revision object corresponding to $this->editRevId.
Definition: EditPage.php:236
EditPage\internalAttemptSave
internalAttemptSave(&$result, $markAsBot=false)
Attempt submission (no UI)
Definition: EditPage.php:2026
EditPage\getCopywarn
getCopywarn()
Get the copyright warning.
Definition: EditPage.php:3879
EditPage\setApiEditOverride
setApiEditOverride( $enableOverride)
Allow editing of content that supports API direct editing, but not general direct editing.
Definition: EditPage.php:555
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1487
EditPage\$watchlistExpiry
string null $watchlistExpiry
The expiry time of the watch item, or null if it is not watched temporarily.
Definition: EditPage.php:279
EditPage\newTextConflictHelper
newTextConflictHelper( $submitButtonLabel)
Definition: EditPage.php:4873
EditPage\showCustomIntro
showCustomIntro()
Attempt to show a custom editing introduction, if supplied.
Definition: EditPage.php:2933
EditPage\getContext
getContext()
Definition: EditPage.php:498
Revision\RevisionStoreRecord
A RevisionRecord representing an existing revision persisted in the revision table.
Definition: RevisionStoreRecord.php:40
EditPage\EDITFORM_ID
const EDITFORM_ID
HTML id and name for the beginning of the edit form.
Definition: EditPage.php:74
EditPage\extractSectionTitle
static extractSectionTitle( $text)
Extract the section title from current section text, if any.
Definition: EditPage.php:3312
WatchAction\doWatchOrUnwatch
static doWatchOrUnwatch( $watch, Title $title, User $user, string $expiry=null)
Watch or unwatch a page.
Definition: WatchAction.php:172
EditPage\makeTemplatesOnThisPageList
makeTemplatesOnThisPageList(array $templates)
Wrapper around TemplatesOnThisPageFormatter to make a "templates on this page" list.
Definition: EditPage.php:3288
EditPage\$textbox1
string $textbox1
Page content input field.
Definition: EditPage.php:290
EditPage\$parentRevId
int $parentRevId
Revision ID the edit is based on, adjusted when an edit conflict is resolved.
Definition: EditPage.php:349
MediaWiki\EditPage\TextConflictHelper\setContentModel
setContentModel( $contentModel)
Definition: TextConflictHelper.php:132
EditPage\$undidRev
$undidRev
Definition: EditPage.php:394
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:2110
EditPage\$changeTags
null array $changeTags
Definition: EditPage.php:376
EditPage
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Definition: EditPage.php:62
EditPage\noSuchSectionPage
noSuchSectionPage()
Creates a basic error page which informs the user that they have attempted to edit a nonexistent sect...
Definition: EditPage.php:4641
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
EditPage\$formtype
string $formtype
Definition: EditPage.php:133
Content
Base interface for content objects.
Definition: Content.php:35
EditPage\getSummaryInputWidget
getSummaryInputWidget( $summary="", $labelText=null, $inputAttrs=null)
Builds a standard summary input with a label.
Definition: EditPage.php:3527
CommentStore\COMMENT_CHARACTER_LIMIT
const COMMENT_CHARACTER_LIMIT
Maximum length of a comment in UTF-8 characters.
Definition: CommentStore.php:48
EDIT_NEW
const EDIT_NEW
Definition: Defines.php:141
EditPage\$hasPresetSummary
bool $hasPresetSummary
Has a summary been preset using GET parameter &summary= ?
Definition: EditPage.php:226
ChangeTags\canAddTagsAccompanyingChange
static canAddTagsAccompanyingChange(array $tags, User $user=null)
Is it OK to allow the user to apply all the specified tags at the same time as they edit/make the cha...
Definition: ChangeTags.php:544
MediaWiki\EditPage\IEditObject\AS_BLANK_ARTICLE
const AS_BLANK_ARTICLE
Status: user tried to create a blank page and wpIgnoreBlankArticle == false.
Definition: IEditObject.php:50
EditPage\$mParserOutput
ParserOutput $mParserOutput
Definition: EditPage.php:220
Title
Represents a title within MediaWiki.
Definition: Title.php:42
EDIT_AUTOSUMMARY
const EDIT_AUTOSUMMARY
Definition: Defines.php:147
EditPage\$mShowSummaryField
bool $mShowSummaryField
Definition: EditPage.php:247
EditPage\$sectiontitle
string $sectiontitle
Definition: EditPage.php:328
EditPage\$starttime
string $starttime
Timestamp from the first time the edit form was rendered.
Definition: EditPage.php:333
EditPage\$suppressIntro
$suppressIntro
Definition: EditPage.php:397
ContentHandler\getContentText
static getContentText(Content $content=null)
Convenience function for getting flat text from a Content object.
Definition: ContentHandler.php:91
EditPage\$permManager
PermissionManager $permManager
Definition: EditPage.php:445
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:117
wfReadOnlyReason
wfReadOnlyReason()
Check if the site is in read-only mode and return the message if so.
Definition: GlobalFunctions.php:1138
EditPage\$scrolltop
int null $scrolltop
Definition: EditPage.php:361
EditPage\formatStatusErrors
formatStatusErrors(Status $status)
Wrap status errors in an errorbox for increased visibility.
Definition: EditPage.php:1957
EditPage\$deletedSinceEdit
bool $deletedSinceEdit
Definition: EditPage.php:130
MediaWiki\EditPage\IEditObject\AS_PARSE_ERROR
const AS_PARSE_ERROR
Status: can't parse content.
Definition: IEditObject.php:92
EditPage\$selfRedirect
bool $selfRedirect
Definition: EditPage.php:202
EditPage\$edit
bool $edit
Definition: EditPage.php:400
EditPage\isSupportedContentModel
isSupportedContentModel( $modelId)
Returns if the given content model is editable.
Definition: EditPage.php:544
EditPage\$mPreloadContent
$mPreloadContent
Definition: EditPage.php:390
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:77
EditPage\showConflict
showConflict()
Show an edit conflict.
Definition: EditPage.php:4013
EditPage\getSubmitButtonLabel
getSubmitButtonLabel()
Get the message key of the label for the button to save the page.
Definition: EditPage.php:4550
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:65
EditPage\$watchedItemStore
WatchedItemStoreInterface $watchedItemStore
Definition: EditPage.php:276
EditPage\$unicodeCheck
string null $unicodeCheck
What the user submitted in the 'wpUnicodeCheck' field.
Definition: EditPage.php:423
MediaWiki\EditPage\IEditObject\AS_READ_ONLY_PAGE
const AS_READ_ONLY_PAGE
Status: wiki is in readonly mode (wfReadOnly() == true)
Definition: IEditObject.php:38
EditPage\$diff
bool $diff
Definition: EditPage.php:258
EditPage\doPreviewParse
doPreviewParse(Content $content)
Parse the page for a preview.
Definition: EditPage.php:4330
EditPage\newSectionSummary
newSectionSummary(&$sectionanchor=null)
Return the summary to be used for a new section.
Definition: EditPage.php:1977
EditPage\$action
string $action
Definition: EditPage.php:115
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:251
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
EditPage\setEditConflictHelperFactory
setEditConflictHelperFactory(callable $factory)
Set a factory function to create an EditConflictHelper.
Definition: EditPage.php:4849
Revision\RevisionRecord\getContent
getContent( $role, $audience=self::FOR_PUBLIC, User $user=null)
Returns the Content of the given slot of this revision.
Definition: RevisionRecord.php:167
NS_USER
const NS_USER
Definition: Defines.php:71
EditPage\showTextbox
showTextbox( $text, $name, $customAttribs=[])
Definition: EditPage.php:3691
EditPage\getTitle
getTitle()
Definition: EditPage.php:506
ManualLogEntry
Class for creating new log entries and inserting them into the database.
Definition: ManualLogEntry.php:42
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:12
EditPage\getCurrentContent
getCurrentContent()
Get the current content of the page.
Definition: EditPage.php:1537
Title\setContentModel
setContentModel( $model)
Set a proposed content model for the page for permissions checking.
Definition: Title.php:1094
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:1073
EditPage\$isConflict
bool $isConflict
Whether an edit conflict needs to be resolved.
Definition: EditPage.php:121
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:77
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:225
EditPage\displayViewSourcePage
displayViewSourcePage(Content $content, $errorMessage='')
Display a read-only View Source page.
Definition: EditPage.php:792
EDIT_MINOR
const EDIT_MINOR
Definition: Defines.php:143
Article
Class for viewing MediaWiki article and history.
Definition: Article.php:46
EditPage\getContentObject
getContentObject( $def_content=null)
Definition: EditPage.php:1235
EditPage\showStandardInputs
showStandardInputs(&$tabindex=2)
Definition: EditPage.php:3963
MediaWiki\EditPage\TextConflictHelper\getEditConflictMainTextBox
getEditConflictMainTextBox(array $customAttribs=[])
HTML to build the textbox1 on edit conflicts.
Definition: TextConflictHelper.php:222
MediaWiki\EditPage\IEditObject\AS_HOOK_ERROR_EXPECTED
const AS_HOOK_ERROR_EXPECTED
Status: A hook function returned an error.
Definition: IEditObject.php:23
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()
Tests if the article content represents a redirect.
Definition: WikiPage.php:575
EditPage\$revisionStore
RevisionStore $revisionStore
Definition: EditPage.php:450
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:80
DeprecationHelper
trait DeprecationHelper
Use this trait in classes which have properties for which public access is deprecated.
Definition: DeprecationHelper.php:45
EditPage\getOriginalContent
getOriginalContent(User $user)
Get the content of the wanted revision, without section extraction.
Definition: EditPage.php:1496
EditPage\setPostEditCookie
setPostEditCookie( $statusValue)
Sets post-edit cookie indicating the user just saved a particular revision.
Definition: EditPage.php:1709
EditPage\$undoAfter
$undoAfter
Definition: EditPage.php:395
Linker\accesskey
static accesskey( $name)
Given the id of an interface element, constructs the appropriate accesskey attribute from the system ...
Definition: Linker.php:2158
WatchedItemStoreInterface
Definition: WatchedItemStoreInterface.php:30
CommentStore\getStore
static getStore()
Definition: CommentStore.php:120
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:55
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add a callable update.
Definition: DeferredUpdates.php:145
EditPage\isWrongCaseUserConfigPage
isWrongCaseUserConfigPage()
Checks whether the user entered a skin name in uppercase, e.g.
Definition: EditPage.php:886
EditPage\$incompleteForm
bool $incompleteForm
Definition: EditPage.php:169
EditPage\$missingSummary
bool $missingSummary
Definition: EditPage.php:187
EditPage\getEditConflictHelper
getEditConflictHelper()
Definition: EditPage.php:4857
WikiPage\getContent
getContent( $audience=RevisionRecord::FOR_PUBLIC, User $user=null)
Get the content of the current revision.
Definition: WikiPage.php:765
ExternalUserNames\isExternal
static isExternal( $username)
Tells whether the username is external or not.
Definition: ExternalUserNames.php:137
EditPage\$markAsBot
bool $markAsBot
Definition: EditPage.php:367
EditPage\getCopyrightWarning
static getCopyrightWarning( $title, $format='plain', $langcode=null)
Get the copyright warning, by default returns wikitext.
Definition: EditPage.php:3891
MediaWiki\EditPage\IEditObject\AS_HOOK_ERROR
const AS_HOOK_ERROR
Status: Article update aborted by a hook function.
Definition: IEditObject.php:20
$wgDisableAnonTalk
$wgDisableAnonTalk
Disable links to talk pages of anonymous users (IPs) in listings on special pages like page history,...
Definition: DefaultSettings.php:7446
MediaWiki\EditPage\IEditObject\AS_CHANGE_TAG_ERROR
const AS_CHANGE_TAG_ERROR
Status: an error relating to change tagging.
Definition: IEditObject.php:89
Skin\makeInternalOrExternalUrl
static makeInternalOrExternalUrl( $name)
If url string starts with http, consider as external URL, else internal.
Definition: Skin.php:1262
EditPage\updateWatchlist
updateWatchlist()
Register the change of watch status.
Definition: EditPage.php:2589
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:490
EditPage\handleStatus
handleStatus(Status $status, $resultDetails)
Handle status, such as after attempt save.
Definition: EditPage.php:1766
ParserOptions\newFromUser
static newFromUser( $user)
Get a ParserOptions object from a given user.
Definition: ParserOptions.php:1088
EditPage\$hookError
string $hookError
Definition: EditPage.php:214
EditPage\$allowBlankArticle
bool $allowBlankArticle
Definition: EditPage.php:199
EditPage\toEditText
toEditText( $content)
Gets an editable textual representation of $content.
Definition: EditPage.php:2967
Xml\checkLabel
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:423
EditPage\setHeaders
setHeaders()
Definition: EditPage.php:2740
EditPage\guessSectionName
guessSectionName( $text)
Turns section name wikitext into anchors for use in HTTP redirects.
Definition: EditPage.php:4828
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:346
$type
$type
Definition: testCompression.php:52
EditPage\$nosummary
bool $nosummary
Definition: EditPage.php:303
EditPage\getPreviewText
getPreviewText()
Get the rendered text for previewing.
Definition: EditPage.php:4144