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