MediaWiki  master
EditPage.php
Go to the documentation of this file.
1 <?php
31 use Wikimedia\ScopedCallback;
32 
48 class EditPage {
52  public const UNICODE_CHECK = 'ℳ𝒲♥𝓊𝓃𝒾𝒸ℴ𝒹ℯ';
53 
57  public const AS_SUCCESS_UPDATE = 200;
58 
62  public const AS_SUCCESS_NEW_ARTICLE = 201;
63 
67  public const AS_HOOK_ERROR = 210;
68 
72  public const AS_HOOK_ERROR_EXPECTED = 212;
73 
77  public const AS_BLOCKED_PAGE_FOR_USER = 215;
78 
82  public const AS_CONTENT_TOO_BIG = 216;
83 
87  public const AS_READ_ONLY_PAGE_ANON = 218;
88 
92  public const AS_READ_ONLY_PAGE_LOGGED = 219;
93 
97  public const AS_READ_ONLY_PAGE = 220;
98 
102  public const AS_RATE_LIMITED = 221;
103 
108  public const AS_ARTICLE_WAS_DELETED = 222;
109 
114  public const AS_NO_CREATE_PERMISSION = 223;
115 
119  public const AS_BLANK_ARTICLE = 224;
120 
124  public const AS_CONFLICT_DETECTED = 225;
125 
130  public const AS_SUMMARY_NEEDED = 226;
131 
135  public const AS_TEXTBOX_EMPTY = 228;
136 
140  public const AS_MAX_ARTICLE_SIZE_EXCEEDED = 229;
141 
145  public const AS_END = 231;
146 
150  public const AS_SPAM_ERROR = 232;
151 
155  public const AS_IMAGE_REDIRECT_ANON = 233;
156 
160  public const AS_IMAGE_REDIRECT_LOGGED = 234;
161 
166  public const AS_NO_CHANGE_CONTENT_MODEL = 235;
167 
172  public const AS_SELF_REDIRECT = 236;
173 
178  public const AS_CHANGE_TAG_ERROR = 237;
179 
183  public const AS_PARSE_ERROR = 240;
184 
189  public const AS_CANNOT_USE_CUSTOM_MODEL = 241;
190 
194  public const AS_UNICODE_NOT_SUPPORTED = 242;
195 
199  public const EDITFORM_ID = 'editform';
200 
205  public const POST_EDIT_COOKIE_KEY_PREFIX = 'PostEditRevision';
206 
220  public const POST_EDIT_COOKIE_DURATION = 1200;
221 
226  public $mArticle;
228  private $page;
229 
234  public $mTitle;
235 
237  private $mContextTitle = null;
238 
240  public $action = 'submit';
241 
246  public $isConflict = false;
247 
249  public $isNew = false;
250 
253 
255  public $formtype;
256 
261  public $firsttime;
262 
264  public $lastDelete;
265 
267  public $mTokenOk = false;
268 
270  public $mTokenOkExceptSuffix = false;
271 
273  public $mTriedSave = false;
274 
276  public $incompleteForm = false;
277 
279  public $tooBig = false;
280 
282  public $missingComment = false;
283 
285  public $missingSummary = false;
286 
288  public $allowBlankSummary = false;
289 
291  protected $blankArticle = false;
292 
294  protected $allowBlankArticle = false;
295 
297  protected $selfRedirect = false;
298 
300  protected $allowSelfRedirect = false;
301 
303  public $autoSumm = '';
304 
306  public $hookError = '';
307 
310 
312  public $hasPresetSummary = false;
313 
315  public $mBaseRevision = false;
316 
318  public $mShowSummaryField = true;
319 
320  # Form values
321 
323  public $save = false;
324 
326  public $preview = false;
327 
329  public $diff = false;
330 
332  public $minoredit = false;
333 
335  public $watchthis = false;
336 
338  public $recreate = false;
339 
343  public $textbox1 = '';
344 
346  public $textbox2 = '';
347 
349  public $summary = '';
350 
354  public $nosummary = false;
355 
360  public $edittime = '';
361 
373  private $editRevId = null;
374 
376  public $section = '';
377 
379  public $sectiontitle = '';
380 
384  public $starttime = '';
385 
391  public $oldid = 0;
392 
398  public $parentRevId = 0;
399 
401  public $editintro = '';
402 
404  public $scrolltop = null;
405 
407  public $bot = true;
408 
411 
413  public $contentFormat = null;
414 
416  private $changeTags = null;
417 
418  # Placeholders for text injection by hooks (must be HTML)
419  # extensions should take care to _append_ to the present value
420 
422  public $editFormPageTop = '';
423  public $editFormTextTop = '';
427  public $editFormTextBottom = '';
430  public $mPreloadContent = null;
431 
432  /* $didSave should be set to true whenever an article was successfully altered. */
433  public $didSave = false;
434  public $undidRev = 0;
435 
436  public $suppressIntro = false;
437 
439  protected $edit;
440 
442  protected $contentLength = false;
443 
447  private $enableApiEditOverride = false;
448 
452  protected $context;
453 
457  private $isOldRev = false;
458 
462  private $unicodeCheck;
463 
470 
475 
480 
484  private $permManager;
485 
489  public function __construct( Article $article ) {
490  $this->mArticle = $article;
491  $this->page = $article->getPage(); // model object
492  $this->mTitle = $article->getTitle();
493 
494  // Make sure the local context is in sync with other member variables.
495  // Particularly make sure everything is using the same WikiPage instance.
496  // This should probably be the case in Article as well, but it's
497  // particularly important for EditPage, to make use of the in-place caching
498  // facility in WikiPage::prepareContentForEdit.
499  $this->context = new DerivativeContext( $article->getContext() );
500  $this->context->setWikiPage( $this->page );
501  $this->context->setTitle( $this->mTitle );
502 
503  $this->contentModel = $this->mTitle->getContentModel();
504 
505  $services = MediaWikiServices::getInstance();
506  $this->contentHandlerFactory = $services->getContentHandlerFactory();
507  $this->contentFormat = $this->contentHandlerFactory
508  ->getContentHandler( $this->contentModel )
509  ->getDefaultFormat();
510  $this->editConflictHelperFactory = [ $this, 'newTextConflictHelper' ];
511  $this->permManager = $services->getPermissionManager();
512  }
513 
517  public function getArticle() {
518  return $this->mArticle;
519  }
520 
525  public function getContext() {
526  return $this->context;
527  }
528 
533  public function getTitle() {
534  return $this->mTitle;
535  }
536 
542  public function setContextTitle( $title ) {
543  $this->mContextTitle = $title;
544  }
545 
554  public function getContextTitle() {
555  if ( $this->mContextTitle === null ) {
556  wfDeprecated( get_class( $this ) . '::getContextTitle called with no title set', '1.32' );
557  global $wgTitle;
558  return $wgTitle;
559  } else {
560  return $this->mContextTitle;
561  }
562  }
563 
571  public function isSupportedContentModel( $modelId ) {
572  return $this->enableApiEditOverride === true ||
573  $this->contentHandlerFactory->getContentHandler( $modelId )->supportsDirectEditing();
574  }
575 
582  public function setApiEditOverride( $enableOverride ) {
583  $this->enableApiEditOverride = $enableOverride;
584  }
585 
597  public function edit() {
598  // Allow extensions to modify/prevent this form or submission
599  if ( !Hooks::run( 'AlternateEdit', [ $this ] ) ) {
600  return;
601  }
602 
603  wfDebug( __METHOD__ . ": enter\n" );
604 
605  $request = $this->context->getRequest();
606  // If they used redlink=1 and the page exists, redirect to the main article
607  if ( $request->getBool( 'redlink' ) && $this->mTitle->exists() ) {
608  $this->context->getOutput()->redirect( $this->mTitle->getFullURL() );
609  return;
610  }
611 
612  $this->importFormData( $request );
613  $this->firsttime = false;
614 
615  if ( wfReadOnly() && $this->save ) {
616  // Force preview
617  $this->save = false;
618  $this->preview = true;
619  }
620 
621  if ( $this->save ) {
622  $this->formtype = 'save';
623  } elseif ( $this->preview ) {
624  $this->formtype = 'preview';
625  } elseif ( $this->diff ) {
626  $this->formtype = 'diff';
627  } else { # First time through
628  $this->firsttime = true;
629  if ( $this->previewOnOpen() ) {
630  $this->formtype = 'preview';
631  } else {
632  $this->formtype = 'initial';
633  }
634  }
635 
636  $permErrors = $this->getEditPermissionErrors(
637  $this->save ? PermissionManager::RIGOR_SECURE : PermissionManager::RIGOR_FULL
638  );
639  if ( $permErrors ) {
640  wfDebug( __METHOD__ . ": User can't edit\n" );
641 
642  if ( $this->context->getUser()->getBlock() ) {
643  // Auto-block user's IP if the account was "hard" blocked
644  if ( !wfReadOnly() ) {
646  $this->context->getUser()->spreadAnyEditBlock();
647  } );
648  }
649  }
650  $this->displayPermissionsError( $permErrors );
651 
652  return;
653  }
654 
655  $revision = $this->mArticle->getRevisionFetched();
656  // Disallow editing revisions with content models different from the current one
657  // Undo edits being an exception in order to allow reverting content model changes.
658  if ( $revision
659  && $revision->getContentModel() !== $this->contentModel
660  ) {
661  $prevRev = null;
662  if ( $this->undidRev ) {
663  $undidRevObj = Revision::newFromId( $this->undidRev );
664  $prevRev = $undidRevObj ? $undidRevObj->getPrevious() : null;
665  }
666  if ( !$this->undidRev
667  || !$prevRev
668  || $prevRev->getContentModel() !== $this->contentModel
669  ) {
670  $this->displayViewSourcePage(
671  $this->getContentObject(),
672  $this->context->msg(
673  'contentmodelediterror',
674  $revision->getContentModel(),
676  )->plain()
677  );
678  return;
679  }
680  }
681 
682  $this->isConflict = false;
683 
684  # Show applicable editing introductions
685  if ( $this->formtype == 'initial' || $this->firsttime ) {
686  $this->showIntro();
687  }
688 
689  # Attempt submission here. This will check for edit conflicts,
690  # and redundantly check for locked database, blocked IPs, etc.
691  # that edit() already checked just in case someone tries to sneak
692  # in the back door with a hand-edited submission URL.
693 
694  if ( $this->formtype == 'save' ) {
695  $resultDetails = null;
696  $status = $this->attemptSave( $resultDetails );
697  if ( !$this->handleStatus( $status, $resultDetails ) ) {
698  return;
699  }
700  }
701 
702  # First time through: get contents, set time for conflict
703  # checking, etc.
704  if ( $this->formtype == 'initial' || $this->firsttime ) {
705  if ( $this->initialiseForm() === false ) {
706  return;
707  }
708 
709  if ( !$this->mTitle->getArticleID() ) {
710  Hooks::run( 'EditFormPreloadText', [ &$this->textbox1, &$this->mTitle ] );
711  } else {
712  Hooks::run( 'EditFormInitialText', [ $this ] );
713  }
714 
715  }
716 
717  $this->showEditForm();
718  }
719 
724  protected function getEditPermissionErrors( $rigor = PermissionManager::RIGOR_SECURE ) {
725  $user = $this->context->getUser();
726  $permErrors = $this->permManager->getPermissionErrors(
727  'edit',
728  $user,
729  $this->mTitle,
730  $rigor
731  );
732  # Can this title be created?
733  if ( !$this->mTitle->exists() ) {
734  $permErrors = array_merge(
735  $permErrors,
736  wfArrayDiff2(
737  $this->permManager->getPermissionErrors(
738  'create',
739  $user,
740  $this->mTitle,
741  $rigor
742  ),
743  $permErrors
744  )
745  );
746  }
747  # Ignore some permissions errors when a user is just previewing/viewing diffs
748  $remove = [];
749  foreach ( $permErrors as $error ) {
750  if ( ( $this->preview || $this->diff )
751  && (
752  $error[0] == 'blockedtext' ||
753  $error[0] == 'autoblockedtext' ||
754  $error[0] == 'systemblockedtext'
755  )
756  ) {
757  $remove[] = $error;
758  }
759  }
760  $permErrors = wfArrayDiff2( $permErrors, $remove );
761 
762  return $permErrors;
763  }
764 
777  protected function displayPermissionsError( array $permErrors ) {
778  $out = $this->context->getOutput();
779  if ( $this->context->getRequest()->getBool( 'redlink' ) ) {
780  // The edit page was reached via a red link.
781  // Redirect to the article page and let them click the edit tab if
782  // they really want a permission error.
783  $out->redirect( $this->mTitle->getFullURL() );
784  return;
785  }
786 
787  $content = $this->getContentObject();
788 
789  # Use the normal message if there's nothing to display
790  if ( $this->firsttime && ( !$content || $content->isEmpty() ) ) {
791  $action = $this->mTitle->exists() ? 'edit' :
792  ( $this->mTitle->isTalkPage() ? 'createtalk' : 'createpage' );
793  throw new PermissionsError( $action, $permErrors );
794  }
795 
796  $this->displayViewSourcePage(
797  $content,
798  $out->formatPermissionsErrorMessage( $permErrors, 'edit' )
799  );
800  }
801 
807  protected function displayViewSourcePage( Content $content, $errorMessage = '' ) {
808  $out = $this->context->getOutput();
809  Hooks::run( 'EditPage::showReadOnlyForm:initial', [ $this, &$out ] );
810 
811  $out->setRobotPolicy( 'noindex,nofollow' );
812  $out->setPageTitle( $this->context->msg(
813  'viewsource-title',
814  $this->getContextTitle()->getPrefixedText()
815  ) );
816  $out->addBacklinkSubtitle( $this->getContextTitle() );
817  $out->addHTML( $this->editFormPageTop );
818  $out->addHTML( $this->editFormTextTop );
819 
820  if ( $errorMessage !== '' ) {
821  $out->addWikiTextAsInterface( $errorMessage );
822  $out->addHTML( "<hr />\n" );
823  }
824 
825  # If the user made changes, preserve them when showing the markup
826  # (This happens when a user is blocked during edit, for instance)
827  if ( !$this->firsttime ) {
828  $text = $this->textbox1;
829  $out->addWikiMsg( 'viewyourtext' );
830  } else {
831  try {
832  $text = $this->toEditText( $content );
833  } catch ( MWException $e ) {
834  # Serialize using the default format if the content model is not supported
835  # (e.g. for an old revision with a different model)
836  $text = $content->serialize();
837  }
838  $out->addWikiMsg( 'viewsourcetext' );
839  }
840 
841  $out->addHTML( $this->editFormTextBeforeContent );
842  $this->showTextbox( $text, 'wpTextbox1', [ 'readonly' ] );
843  $out->addHTML( $this->editFormTextAfterContent );
844 
845  $out->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) );
846 
847  $out->addModules( 'mediawiki.action.edit.collapsibleFooter' );
848 
849  $out->addHTML( $this->editFormTextBottom );
850  if ( $this->mTitle->exists() ) {
851  $out->returnToMain( null, $this->mTitle );
852  }
853  }
854 
860  protected function previewOnOpen() {
861  $config = $this->context->getConfig();
862  $previewOnOpenNamespaces = $config->get( 'PreviewOnOpenNamespaces' );
863  $request = $this->context->getRequest();
864  if ( $config->get( 'RawHtml' ) ) {
865  // If raw HTML is enabled, disable preview on open
866  // since it has to be posted with a token for
867  // security reasons
868  return false;
869  }
870  if ( $request->getVal( 'preview' ) == 'yes' ) {
871  // Explicit override from request
872  return true;
873  } elseif ( $request->getVal( 'preview' ) == 'no' ) {
874  // Explicit override from request
875  return false;
876  } elseif ( $this->section == 'new' ) {
877  // Nothing *to* preview for new sections
878  return false;
879  } elseif ( ( $request->getCheck( 'preload' ) || $this->mTitle->exists() )
880  && $this->context->getUser()->getOption( 'previewonfirst' )
881  ) {
882  // Standard preference behavior
883  return true;
884  } elseif ( !$this->mTitle->exists()
885  && isset( $previewOnOpenNamespaces[$this->mTitle->getNamespace()] )
886  && $previewOnOpenNamespaces[$this->mTitle->getNamespace()]
887  ) {
888  // Categories are special
889  return true;
890  } else {
891  return false;
892  }
893  }
894 
901  protected function isWrongCaseUserConfigPage() {
902  if ( $this->mTitle->isUserConfigPage() ) {
903  $name = $this->mTitle->getSkinFromConfigSubpage();
904  $skins = array_merge(
905  array_keys( Skin::getSkinNames() ),
906  [ 'common' ]
907  );
908  return !in_array( $name, $skins )
909  && in_array( strtolower( $name ), $skins );
910  } else {
911  return false;
912  }
913  }
914 
922  protected function isSectionEditSupported() {
923  return $this->contentHandlerFactory
924  ->getContentHandler( $this->mTitle->getContentModel() )
925  ->supportsSections();
926  }
927 
933  public function importFormData( &$request ) {
934  # Section edit can come from either the form or a link
935  $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
936 
937  if ( $this->section !== null && $this->section !== '' && !$this->isSectionEditSupported() ) {
938  throw new ErrorPageError( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
939  }
940 
941  $this->isNew = !$this->mTitle->exists() || $this->section == 'new';
942 
943  if ( $request->wasPosted() ) {
944  # These fields need to be checked for encoding.
945  # Also remove trailing whitespace, but don't remove _initial_
946  # whitespace from the text boxes. This may be significant formatting.
947  $this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) );
948  if ( !$request->getCheck( 'wpTextbox2' ) ) {
949  // Skip this if wpTextbox2 has input, it indicates that we came
950  // from a conflict page with raw page text, not a custom form
951  // modified by subclasses
952  $textbox1 = $this->importContentFormData( $request );
953  if ( $textbox1 !== null ) {
954  $this->textbox1 = $textbox1;
955  }
956  }
957 
958  $this->unicodeCheck = $request->getText( 'wpUnicodeCheck' );
959 
960  $this->summary = $request->getText( 'wpSummary' );
961 
962  # If the summary consists of a heading, e.g. '==Foobar==', extract the title from the
963  # header syntax, e.g. 'Foobar'. This is mainly an issue when we are using wpSummary for
964  # section titles.
965  $this->summary = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary );
966 
967  # Treat sectiontitle the same way as summary.
968  # Note that wpSectionTitle is not yet a part of the actual edit form, as wpSummary is
969  # currently doing double duty as both edit summary and section title. Right now this
970  # is just to allow API edits to work around this limitation, but this should be
971  # incorporated into the actual edit form when EditPage is rewritten (T20654, T28312).
972  $this->sectiontitle = $request->getText( 'wpSectionTitle' );
973  $this->sectiontitle = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->sectiontitle );
974 
975  $this->edittime = $request->getVal( 'wpEdittime' );
976  $this->editRevId = $request->getIntOrNull( 'editRevId' );
977  $this->starttime = $request->getVal( 'wpStarttime' );
978 
979  $undidRev = $request->getInt( 'wpUndidRevision' );
980  if ( $undidRev ) {
981  $this->undidRev = $undidRev;
982  }
983 
984  $this->scrolltop = $request->getIntOrNull( 'wpScrolltop' );
985 
986  if ( $this->textbox1 === '' && !$request->getCheck( 'wpTextbox1' ) ) {
987  // wpTextbox1 field is missing, possibly due to being "too big"
988  // according to some filter rules such as Suhosin's setting for
989  // suhosin.request.max_value_length (d'oh)
990  $this->incompleteForm = true;
991  } else {
992  // If we receive the last parameter of the request, we can fairly
993  // claim the POST request has not been truncated.
994  $this->incompleteForm = !$request->getVal( 'wpUltimateParam' );
995  }
996  if ( $this->incompleteForm ) {
997  # If the form is incomplete, force to preview.
998  wfDebug( __METHOD__ . ": Form data appears to be incomplete\n" );
999  wfDebug( "POST DATA: " . var_export( $request->getPostValues(), true ) . "\n" );
1000  $this->preview = true;
1001  } else {
1002  $this->preview = $request->getCheck( 'wpPreview' );
1003  $this->diff = $request->getCheck( 'wpDiff' );
1004 
1005  // Remember whether a save was requested, so we can indicate
1006  // if we forced preview due to session failure.
1007  $this->mTriedSave = !$this->preview;
1008 
1009  if ( $this->tokenOk( $request ) ) {
1010  # Some browsers will not report any submit button
1011  # if the user hits enter in the comment box.
1012  # The unmarked state will be assumed to be a save,
1013  # if the form seems otherwise complete.
1014  wfDebug( __METHOD__ . ": Passed token check.\n" );
1015  } elseif ( $this->diff ) {
1016  # Failed token check, but only requested "Show Changes".
1017  wfDebug( __METHOD__ . ": Failed token check; Show Changes requested.\n" );
1018  } else {
1019  # Page might be a hack attempt posted from
1020  # an external site. Preview instead of saving.
1021  wfDebug( __METHOD__ . ": Failed token check; forcing preview\n" );
1022  $this->preview = true;
1023  }
1024  }
1025  $this->save = !$this->preview && !$this->diff;
1026  if ( !preg_match( '/^\d{14}$/', $this->edittime ) ) {
1027  $this->edittime = null;
1028  }
1029 
1030  if ( !preg_match( '/^\d{14}$/', $this->starttime ) ) {
1031  $this->starttime = null;
1032  }
1033 
1034  $this->recreate = $request->getCheck( 'wpRecreate' );
1035 
1036  $this->minoredit = $request->getCheck( 'wpMinoredit' );
1037  $this->watchthis = $request->getCheck( 'wpWatchthis' );
1038 
1039  $user = $this->context->getUser();
1040  # Don't force edit summaries when a user is editing their own user or talk page
1041  if ( ( $this->mTitle->mNamespace == NS_USER || $this->mTitle->mNamespace == NS_USER_TALK )
1042  && $this->mTitle->getText() == $user->getName()
1043  ) {
1044  $this->allowBlankSummary = true;
1045  } else {
1046  $this->allowBlankSummary = $request->getBool( 'wpIgnoreBlankSummary' )
1047  || !$user->getOption( 'forceeditsummary' );
1048  }
1049 
1050  $this->autoSumm = $request->getText( 'wpAutoSummary' );
1051 
1052  $this->allowBlankArticle = $request->getBool( 'wpIgnoreBlankArticle' );
1053  $this->allowSelfRedirect = $request->getBool( 'wpIgnoreSelfRedirect' );
1054 
1055  $changeTags = $request->getVal( 'wpChangeTags' );
1056  if ( $changeTags === null || $changeTags === '' ) {
1057  $this->changeTags = [];
1058  } else {
1059  $this->changeTags = array_filter( array_map( 'trim', explode( ',',
1060  $changeTags ) ) );
1061  }
1062  } else {
1063  # Not a posted form? Start with nothing.
1064  wfDebug( __METHOD__ . ": Not a posted form.\n" );
1065  $this->textbox1 = '';
1066  $this->summary = '';
1067  $this->sectiontitle = '';
1068  $this->edittime = '';
1069  $this->editRevId = null;
1070  $this->starttime = wfTimestampNow();
1071  $this->edit = false;
1072  $this->preview = false;
1073  $this->save = false;
1074  $this->diff = false;
1075  $this->minoredit = false;
1076  // Watch may be overridden by request parameters
1077  $this->watchthis = $request->getBool( 'watchthis', false );
1078  $this->recreate = false;
1079 
1080  // When creating a new section, we can preload a section title by passing it as the
1081  // preloadtitle parameter in the URL (T15100)
1082  if ( $this->section == 'new' && $request->getVal( 'preloadtitle' ) ) {
1083  $this->sectiontitle = $request->getVal( 'preloadtitle' );
1084  // Once wpSummary isn't being use for setting section titles, we should delete this.
1085  $this->summary = $request->getVal( 'preloadtitle' );
1086  } elseif ( $this->section != 'new' && $request->getVal( 'summary' ) !== '' ) {
1087  $this->summary = $request->getText( 'summary' );
1088  if ( $this->summary !== '' ) {
1089  $this->hasPresetSummary = true;
1090  }
1091  }
1092 
1093  if ( $request->getVal( 'minor' ) ) {
1094  $this->minoredit = true;
1095  }
1096  }
1097 
1098  $this->oldid = $request->getInt( 'oldid' );
1099  $this->parentRevId = $request->getInt( 'parentRevId' );
1100 
1101  $this->bot = $request->getBool( 'bot', true );
1102  $this->nosummary = $request->getBool( 'nosummary' );
1103 
1104  // May be overridden by revision.
1105  $this->contentModel = $request->getText( 'model', $this->contentModel );
1106  // May be overridden by revision.
1107  $this->contentFormat = $request->getText( 'format', $this->contentFormat );
1108 
1109  try {
1110  $handler = $this->contentHandlerFactory->getContentHandler( $this->contentModel );
1111  } catch ( MWUnknownContentModelException $e ) {
1112  throw new ErrorPageError(
1113  'editpage-invalidcontentmodel-title',
1114  'editpage-invalidcontentmodel-text',
1115  [ wfEscapeWikiText( $this->contentModel ) ]
1116  );
1117  }
1118 
1119  if ( !$handler->isSupportedFormat( $this->contentFormat ) ) {
1120  throw new ErrorPageError(
1121  'editpage-notsupportedcontentformat-title',
1122  'editpage-notsupportedcontentformat-text',
1123  [
1124  wfEscapeWikiText( $this->contentFormat ),
1125  wfEscapeWikiText( ContentHandler::getLocalizedName( $this->contentModel ) )
1126  ]
1127  );
1128  }
1129 
1136  $this->editintro = $request->getText( 'editintro',
1137  // Custom edit intro for new sections
1138  $this->section === 'new' ? 'MediaWiki:addsection-editintro' : '' );
1139 
1140  // Allow extensions to modify form data
1141  Hooks::run( 'EditPage::importFormData', [ $this, $request ] );
1142  }
1143 
1153  protected function importContentFormData( &$request ) {
1154  return null; // Don't do anything, EditPage already extracted wpTextbox1
1155  }
1156 
1162  public function initialiseForm() {
1163  $this->edittime = $this->page->getTimestamp();
1164  $this->editRevId = $this->page->getLatest();
1165 
1166  $dummy = $this->contentHandlerFactory
1167  ->getContentHandler( $this->contentModel )
1168  ->makeEmptyContent();
1169  $content = $this->getContentObject( $dummy ); # TODO: track content object?!
1170  if ( $content === $dummy ) { // Invalid section
1171  $this->noSuchSectionPage();
1172  return false;
1173  }
1174 
1175  if ( !$content ) {
1176  $out = $this->context->getOutput();
1177  $this->editFormPageTop .= Html::rawElement(
1178  'div', [ 'class' => 'errorbox' ],
1179  $out->parseAsInterface( $this->context->msg( 'missing-revision-content',
1180  $this->oldid,
1181  Message::plaintextParam( $this->mTitle->getPrefixedText() )
1182  ) )
1183  );
1184  } elseif ( !$this->isSupportedContentModel( $content->getModel() ) ) {
1185  $modelMsg = $this->getContext()->msg( 'content-model-' . $content->getModel() );
1186  $modelName = $modelMsg->exists() ? $modelMsg->text() : $content->getModel();
1187 
1188  $out = $this->context->getOutput();
1189  $out->showErrorPage(
1190  'modeleditnotsupported-title',
1191  'modeleditnotsupported-text',
1192  [ $modelName ]
1193  );
1194  return false;
1195  }
1196 
1197  $this->textbox1 = $this->toEditText( $content );
1198 
1199  $user = $this->context->getUser();
1200  // activate checkboxes if user wants them to be always active
1201  # Sort out the "watch" checkbox
1202  if ( $user->getOption( 'watchdefault' ) ) {
1203  # Watch all edits
1204  $this->watchthis = true;
1205  } elseif ( $user->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) {
1206  # Watch creations
1207  $this->watchthis = true;
1208  } elseif ( $user->isWatched( $this->mTitle ) ) {
1209  # Already watched
1210  $this->watchthis = true;
1211  }
1212  if ( $user->getOption( 'minordefault' ) && !$this->isNew ) {
1213  $this->minoredit = true;
1214  }
1215  if ( $this->textbox1 === false ) {
1216  return false;
1217  }
1218  return true;
1219  }
1220 
1228  protected function getContentObject( $def_content = null ) {
1229  global $wgDisableAnonTalk;
1230 
1231  $content = false;
1232 
1233  $user = $this->context->getUser();
1234  $request = $this->context->getRequest();
1235  // For message page not locally set, use the i18n message.
1236  // For other non-existent articles, use preload text if any.
1237  if ( !$this->mTitle->exists() || $this->section == 'new' ) {
1238  if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && $this->section != 'new' ) {
1239  # If this is a system message, get the default text.
1240  $msg = $this->mTitle->getDefaultMessageText();
1241 
1242  $content = $this->toEditContent( $msg );
1243  }
1244  if ( $content === false ) {
1245  # If requested, preload some text.
1246  $preload = $request->getVal( 'preload',
1247  // Custom preload text for new sections
1248  $this->section === 'new' ? 'MediaWiki:addsection-preload' : '' );
1249  $params = $request->getArray( 'preloadparams', [] );
1250 
1251  $content = $this->getPreloadedContent( $preload, $params );
1252  }
1253  // For existing pages, get text based on "undo" or section parameters.
1254  } elseif ( $this->section != '' ) {
1255  // Get section edit text (returns $def_text for invalid sections)
1256  $orig = $this->getOriginalContent( $user );
1257  $content = $orig ? $orig->getSection( $this->section ) : null;
1258 
1259  if ( !$content ) {
1260  $content = $def_content;
1261  }
1262  } else {
1263  $undoafter = $request->getInt( 'undoafter' );
1264  $undo = $request->getInt( 'undo' );
1265 
1266  if ( $undo > 0 && $undoafter > 0 ) {
1267  $undorev = Revision::newFromId( $undo );
1268  $oldrev = Revision::newFromId( $undoafter );
1269  $undoMsg = null;
1270 
1271  # Sanity check, make sure it's the right page,
1272  # the revisions exist and they were not deleted.
1273  # Otherwise, $content will be left as-is.
1274  if ( $undorev !== null && $oldrev !== null &&
1275  !$undorev->isDeleted( RevisionRecord::DELETED_TEXT ) &&
1276  !$oldrev->isDeleted( RevisionRecord::DELETED_TEXT )
1277  ) {
1278  if ( WikiPage::hasDifferencesOutsideMainSlot( $undorev, $oldrev )
1279  || !$this->isSupportedContentModel( $oldrev->getContentModel() )
1280  ) {
1281  // Hack for undo while EditPage can't handle multi-slot editing
1282  $this->context->getOutput()->redirect( $this->mTitle->getFullURL( [
1283  'action' => 'mcrundo',
1284  'undo' => $undo,
1285  'undoafter' => $undoafter,
1286  ] ) );
1287  return false;
1288  } else {
1289  $content = $this->page->getUndoContent( $undorev, $oldrev );
1290 
1291  if ( $content === false ) {
1292  # Warn the user that something went wrong
1293  $undoMsg = 'failure';
1294  }
1295  }
1296 
1297  if ( $undoMsg === null ) {
1298  $oldContent = $this->page->getContent( RevisionRecord::RAW );
1300  $user, MediaWikiServices::getInstance()->getContentLanguage() );
1301  $newContent = $content->preSaveTransform( $this->mTitle, $user, $popts );
1302  if ( $newContent->getModel() !== $oldContent->getModel() ) {
1303  // The undo may change content
1304  // model if its reverting the top
1305  // edit. This can result in
1306  // mismatched content model/format.
1307  $this->contentModel = $newContent->getModel();
1308  $this->contentFormat = $oldrev->getContentFormat();
1309  }
1310 
1311  if ( $newContent->equals( $oldContent ) ) {
1312  # Tell the user that the undo results in no change,
1313  # i.e. the revisions were already undone.
1314  $undoMsg = 'nochange';
1315  $content = false;
1316  } else {
1317  # Inform the user of our success and set an automatic edit summary
1318  $undoMsg = 'success';
1319 
1320  # If we just undid one rev, use an autosummary
1321  $firstrev = $oldrev->getNext();
1322  if ( $firstrev && $firstrev->getId() == $undo ) {
1323  $userText = $undorev->getUserText();
1324  if ( $userText === '' ) {
1325  $undoSummary = $this->context->msg(
1326  'undo-summary-username-hidden',
1327  $undo
1328  )->inContentLanguage()->text();
1329  } else {
1330  $undoMessage = ( $undorev->getUser() === 0 && $wgDisableAnonTalk ) ?
1331  'undo-summary-anon' :
1332  'undo-summary';
1333  $undoSummary = $this->context->msg(
1334  $undoMessage,
1335  $undo,
1336  $userText
1337  )->inContentLanguage()->text();
1338  }
1339  if ( $this->summary === '' ) {
1340  $this->summary = $undoSummary;
1341  } else {
1342  $this->summary = $undoSummary . $this->context->msg( 'colon-separator' )
1343  ->inContentLanguage()->text() . $this->summary;
1344  }
1345  $this->undidRev = $undo;
1346  }
1347  $this->formtype = 'diff';
1348  }
1349  }
1350  } else {
1351  // Failed basic sanity checks.
1352  // Older revisions may have been removed since the link
1353  // was created, or we may simply have got bogus input.
1354  $undoMsg = 'norev';
1355  }
1356 
1357  $out = $this->context->getOutput();
1358  // Messages: undo-success, undo-failure, undo-main-slot-only, undo-norev,
1359  // undo-nochange.
1360  $class = ( $undoMsg == 'success' ? '' : 'error ' ) . "mw-undo-{$undoMsg}";
1361  $this->editFormPageTop .= Html::rawElement(
1362  'div', [ 'class' => $class ],
1363  $out->parseAsInterface(
1364  $this->context->msg( 'undo-' . $undoMsg )->plain()
1365  )
1366  );
1367  }
1368 
1369  if ( $content === false ) {
1370  // Hack for restoring old revisions while EditPage
1371  // can't handle multi-slot editing.
1372 
1373  $curRevision = $this->page->getRevision();
1374  $oldRevision = $this->mArticle->getRevisionFetched();
1375 
1376  if ( $curRevision
1377  && $oldRevision
1378  && $curRevision->getId() !== $oldRevision->getId()
1379  && ( WikiPage::hasDifferencesOutsideMainSlot( $oldRevision, $curRevision )
1380  || !$this->isSupportedContentModel( $oldRevision->getContentModel() ) )
1381  ) {
1382  $this->context->getOutput()->redirect(
1383  $this->mTitle->getFullURL(
1384  [
1385  'action' => 'mcrrestore',
1386  'restore' => $oldRevision->getId(),
1387  ]
1388  )
1389  );
1390 
1391  return false;
1392  }
1393  }
1394 
1395  if ( $content === false ) {
1396  $content = $this->getOriginalContent( $user );
1397  }
1398  }
1399 
1400  return $content;
1401  }
1402 
1418  private function getOriginalContent( User $user ) {
1419  if ( $this->section == 'new' ) {
1420  return $this->getCurrentContent();
1421  }
1422  $revision = $this->mArticle->getRevisionFetched();
1423  if ( $revision === null ) {
1424  return $this->contentHandlerFactory
1425  ->getContentHandler( $this->contentModel )
1426  ->makeEmptyContent();
1427  }
1428  $content = $revision->getContent( RevisionRecord::FOR_THIS_USER, $user );
1429  return $content;
1430  }
1431 
1444  public function getParentRevId() {
1445  if ( $this->parentRevId ) {
1446  return $this->parentRevId;
1447  } else {
1448  return $this->mArticle->getRevIdFetched();
1449  }
1450  }
1451 
1460  protected function getCurrentContent() {
1461  $rev = $this->page->getRevision();
1462  $content = $rev ? $rev->getContent( RevisionRecord::RAW ) : null;
1463 
1464  if ( $content === false || $content === null ) {
1465  return $this->contentHandlerFactory
1466  ->getContentHandler( $this->contentModel )
1467  ->makeEmptyContent();
1468  } elseif ( !$this->undidRev ) {
1469  // Content models should always be the same since we error
1470  // out if they are different before this point (in ->edit()).
1471  // The exception being, during an undo, the current revision might
1472  // differ from the prior revision.
1473  $logger = LoggerFactory::getInstance( 'editpage' );
1474  if ( $this->contentModel !== $rev->getContentModel() ) {
1475  $logger->warning( "Overriding content model from current edit {prev} to {new}", [
1476  'prev' => $this->contentModel,
1477  'new' => $rev->getContentModel(),
1478  'title' => $this->getTitle()->getPrefixedDBkey(),
1479  'method' => __METHOD__
1480  ] );
1481  $this->contentModel = $rev->getContentModel();
1482  }
1483 
1484  // Given that the content models should match, the current selected
1485  // format should be supported.
1486  if ( !$content->isSupportedFormat( $this->contentFormat ) ) {
1487  $logger->warning( "Current revision content format unsupported. Overriding {prev} to {new}", [
1488 
1489  'prev' => $this->contentFormat,
1490  'new' => $rev->getContentFormat(),
1491  'title' => $this->getTitle()->getPrefixedDBkey(),
1492  'method' => __METHOD__
1493  ] );
1494  $this->contentFormat = $rev->getContentFormat();
1495  }
1496  }
1497  return $content;
1498  }
1499 
1507  public function setPreloadedContent( Content $content ) {
1508  $this->mPreloadContent = $content;
1509  }
1510 
1522  protected function getPreloadedContent( $preload, $params = [] ) {
1523  if ( !empty( $this->mPreloadContent ) ) {
1524  return $this->mPreloadContent;
1525  }
1526 
1527  $handler = $this->contentHandlerFactory->getContentHandler( $this->contentModel );
1528 
1529  if ( $preload === '' ) {
1530  return $handler->makeEmptyContent();
1531  }
1532 
1533  $user = $this->context->getUser();
1534  $title = Title::newFromText( $preload );
1535 
1536  # Check for existence to avoid getting MediaWiki:Noarticletext
1537  if ( !$this->isPageExistingAndViewable( $title, $user ) ) {
1538  // TODO: somehow show a warning to the user!
1539  return $handler->makeEmptyContent();
1540  }
1541 
1543  if ( $page->isRedirect() ) {
1545  # Same as before
1546  if ( !$this->isPageExistingAndViewable( $title, $user ) ) {
1547  // TODO: somehow show a warning to the user!
1548  return $handler->makeEmptyContent();
1549  }
1551  }
1552 
1553  $parserOptions = ParserOptions::newFromUser( $user );
1554  $content = $page->getContent( RevisionRecord::RAW );
1555 
1556  if ( !$content ) {
1557  // TODO: somehow show a warning to the user!
1558  return $handler->makeEmptyContent();
1559  }
1560 
1561  if ( $content->getModel() !== $handler->getModelID() ) {
1562  $converted = $content->convert( $handler->getModelID() );
1563 
1564  if ( !$converted ) {
1565  // TODO: somehow show a warning to the user!
1566  wfDebug( "Attempt to preload incompatible content: " .
1567  "can't convert " . $content->getModel() .
1568  " to " . $handler->getModelID() );
1569 
1570  return $handler->makeEmptyContent();
1571  }
1572 
1573  $content = $converted;
1574  }
1575 
1576  return $content->preloadTransform( $title, $parserOptions, $params );
1577  }
1578 
1588  private function isPageExistingAndViewable( $title, User $user ) {
1589  return $title && $title->exists() && $this->permManager->userCan( 'read', $user, $title );
1590  }
1591 
1599  public function tokenOk( &$request ) {
1600  $token = $request->getVal( 'wpEditToken' );
1601  $user = $this->context->getUser();
1602  $this->mTokenOk = $user->matchEditToken( $token );
1603  $this->mTokenOkExceptSuffix = $user->matchEditTokenNoSuffix( $token );
1604  return $this->mTokenOk;
1605  }
1606 
1621  protected function setPostEditCookie( $statusValue ) {
1622  $revisionId = $this->page->getLatest();
1623  $postEditKey = self::POST_EDIT_COOKIE_KEY_PREFIX . $revisionId;
1624 
1625  $val = 'saved';
1626  if ( $statusValue == self::AS_SUCCESS_NEW_ARTICLE ) {
1627  $val = 'created';
1628  } elseif ( $this->oldid ) {
1629  $val = 'restored';
1630  }
1631 
1632  $response = $this->context->getRequest()->response();
1633  $response->setCookie( $postEditKey, $val, time() + self::POST_EDIT_COOKIE_DURATION );
1634  }
1635 
1642  public function attemptSave( &$resultDetails = false ) {
1643  // TODO: MCR: treat $this->minoredit like $this->bot and check isAllowed( 'minoredit' )!
1644  // Also, add $this->autopatrol like $this->bot and check isAllowed( 'autopatrol' )!
1645  // This is needed since PageUpdater no longer checks these rights!
1646 
1647  // Allow bots to exempt some edits from bot flagging
1648  $bot = $this->permManager->userHasRight( $this->context->getUser(), 'bot' ) && $this->bot;
1649  $status = $this->internalAttemptSave( $resultDetails, $bot );
1650 
1651  Hooks::run( 'EditPage::attemptSave:after', [ $this, $status, $resultDetails ] );
1652 
1653  return $status;
1654  }
1655 
1659  private function incrementResolvedConflicts() {
1660  if ( $this->context->getRequest()->getText( 'mode' ) !== 'conflict' ) {
1661  return;
1662  }
1663 
1664  $this->getEditConflictHelper()->incrementResolvedStats( $this->context->getUser() );
1665  }
1666 
1676  private function handleStatus( Status $status, $resultDetails ) {
1681  if ( $status->value == self::AS_SUCCESS_UPDATE
1682  || $status->value == self::AS_SUCCESS_NEW_ARTICLE
1683  ) {
1684  $this->incrementResolvedConflicts();
1685 
1686  $this->didSave = true;
1687  if ( !$resultDetails['nullEdit'] ) {
1688  $this->setPostEditCookie( $status->value );
1689  }
1690  }
1691 
1692  $out = $this->context->getOutput();
1693 
1694  // "wpExtraQueryRedirect" is a hidden input to modify
1695  // after save URL and is not used by actual edit form
1696  $request = $this->context->getRequest();
1697  $extraQueryRedirect = $request->getVal( 'wpExtraQueryRedirect' );
1698 
1699  switch ( $status->value ) {
1707  case self::AS_END:
1710  return true;
1711 
1712  case self::AS_HOOK_ERROR:
1713  return false;
1714 
1716  case self::AS_PARSE_ERROR:
1718  $out->wrapWikiTextAsInterface( 'error',
1719  $status->getWikiText( false, false, $this->context->getLanguage() )
1720  );
1721  return true;
1722 
1724  $query = $resultDetails['redirect'] ? 'redirect=no' : '';
1725  if ( $extraQueryRedirect ) {
1726  if ( $query !== '' ) {
1727  $query .= '&';
1728  }
1729  $query .= $extraQueryRedirect;
1730  }
1731  $anchor = $resultDetails['sectionanchor'] ?? '';
1732  $out->redirect( $this->mTitle->getFullURL( $query ) . $anchor );
1733  return false;
1734 
1736  $extraQuery = '';
1737  $sectionanchor = $resultDetails['sectionanchor'];
1738 
1739  // Give extensions a chance to modify URL query on update
1740  Hooks::run(
1741  'ArticleUpdateBeforeRedirect',
1742  [ $this->mArticle, &$sectionanchor, &$extraQuery ]
1743  );
1744 
1745  if ( $resultDetails['redirect'] ) {
1746  if ( $extraQuery !== '' ) {
1747  $extraQuery = '&' . $extraQuery;
1748  }
1749  $extraQuery = 'redirect=no' . $extraQuery;
1750  }
1751  if ( $extraQueryRedirect ) {
1752  if ( $extraQuery !== '' ) {
1753  $extraQuery .= '&';
1754  }
1755  $extraQuery .= $extraQueryRedirect;
1756  }
1757 
1758  $out->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor );
1759  return false;
1760 
1761  case self::AS_SPAM_ERROR:
1762  $this->spamPageWithContent( $resultDetails['spam'] );
1763  return false;
1764 
1766  throw new UserBlockedError(
1767  $this->context->getUser()->getBlock(),
1768  $this->context->getUser(),
1769  $this->context->getLanguage(),
1770  $request->getIP()
1771  );
1772 
1775  throw new PermissionsError( 'upload' );
1776 
1779  throw new PermissionsError( 'edit' );
1780 
1782  throw new ReadOnlyError;
1783 
1784  case self::AS_RATE_LIMITED:
1785  throw new ThrottledError();
1786 
1788  $permission = $this->mTitle->isTalkPage() ? 'createtalk' : 'createpage';
1789  throw new PermissionsError( $permission );
1790 
1792  throw new PermissionsError( 'editcontentmodel' );
1793 
1794  default:
1795  // We don't recognize $status->value. The only way that can happen
1796  // is if an extension hook aborted from inside ArticleSave.
1797  // Render the status object into $this->hookError
1798  // FIXME this sucks, we should just use the Status object throughout
1799  $this->hookError = '<div class="error">' . "\n" .
1800  $status->getWikiText( false, false, $this->context->getLanguage() ) .
1801  '</div>';
1802  return true;
1803  }
1804  }
1805 
1815  protected function runPostMergeFilters( Content $content, Status $status, User $user ) {
1816  // Run old style post-section-merge edit filter
1817  if ( $this->hookError != '' ) {
1818  # ...or the hook could be expecting us to produce an error
1819  $status->fatal( 'hookaborted' );
1820  $status->value = self::AS_HOOK_ERROR_EXPECTED;
1821  return false;
1822  }
1823 
1824  // Run new style post-section-merge edit filter
1825  if ( !Hooks::run( 'EditFilterMergedContent',
1826  [ $this->context, $content, $status, $this->summary,
1827  $user, $this->minoredit ] )
1828  ) {
1829  # Error messages etc. could be handled within the hook...
1830  if ( $status->isGood() ) {
1831  $status->fatal( 'hookaborted' );
1832  // Not setting $this->hookError here is a hack to allow the hook
1833  // to cause a return to the edit page without $this->hookError
1834  // being set. This is used by ConfirmEdit to display a captcha
1835  // without any error message cruft.
1836  } else {
1837  $this->hookError = $this->formatStatusErrors( $status );
1838  }
1839  // Use the existing $status->value if the hook set it
1840  if ( !$status->value ) {
1841  $status->value = self::AS_HOOK_ERROR;
1842  }
1843  return false;
1844  } elseif ( !$status->isOK() ) {
1845  # ...or the hook could be expecting us to produce an error
1846  // FIXME this sucks, we should just use the Status object throughout
1847  if ( !$status->getErrors() ) {
1848  // Provide a fallback error message if none was set
1849  $status->fatal( 'hookaborted' );
1850  }
1851  $this->hookError = $this->formatStatusErrors( $status );
1852  $status->value = self::AS_HOOK_ERROR_EXPECTED;
1853  return false;
1854  }
1855 
1856  return true;
1857  }
1858 
1865  private function formatStatusErrors( Status $status ) {
1866  $errmsg = $status->getWikiText(
1867  'edit-error-short',
1868  'edit-error-long',
1869  $this->context->getLanguage()
1870  );
1871  return <<<ERROR
1872 <div class="errorbox">
1873 {$errmsg}
1874 </div>
1875 <br clear="all" />
1876 ERROR;
1877  }
1878 
1885  private function newSectionSummary( &$sectionanchor = null ) {
1886  if ( $this->sectiontitle !== '' ) {
1887  $sectionanchor = $this->guessSectionName( $this->sectiontitle );
1888  // If no edit summary was specified, create one automatically from the section
1889  // title and have it link to the new section. Otherwise, respect the summary as
1890  // passed.
1891  if ( $this->summary === '' ) {
1892  $cleanSectionTitle = MediaWikiServices::getInstance()->getParser()
1893  ->stripSectionName( $this->sectiontitle );
1894  return $this->context->msg( 'newsectionsummary' )
1895  ->plaintextParams( $cleanSectionTitle )->inContentLanguage()->text();
1896  }
1897  } elseif ( $this->summary !== '' ) {
1898  $sectionanchor = $this->guessSectionName( $this->summary );
1899  # This is a new section, so create a link to the new section
1900  # in the revision summary.
1901  $cleanSummary = MediaWikiServices::getInstance()->getParser()
1902  ->stripSectionName( $this->summary );
1903  return $this->context->msg( 'newsectionsummary' )
1904  ->plaintextParams( $cleanSummary )->inContentLanguage()->text();
1905  }
1906  return $this->summary;
1907  }
1908 
1933  public function internalAttemptSave( &$result, $bot = false ) {
1934  $status = Status::newGood();
1935  $user = $this->context->getUser();
1936 
1937  if ( !Hooks::run( 'EditPage::attemptSave', [ $this ] ) ) {
1938  wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
1939  $status->fatal( 'hookaborted' );
1940  $status->value = self::AS_HOOK_ERROR;
1941  return $status;
1942  }
1943 
1944  if ( $this->unicodeCheck !== self::UNICODE_CHECK ) {
1945  $status->fatal( 'unicode-support-fail' );
1946  $status->value = self::AS_UNICODE_NOT_SUPPORTED;
1947  return $status;
1948  }
1949 
1950  $request = $this->context->getRequest();
1951  $spam = $request->getText( 'wpAntispam' );
1952  if ( $spam !== '' ) {
1953  wfDebugLog(
1954  'SimpleAntiSpam',
1955  $user->getName() .
1956  ' editing "' .
1957  $this->mTitle->getPrefixedText() .
1958  '" submitted bogus field "' .
1959  $spam .
1960  '"'
1961  );
1962  $status->fatal( 'spamprotectionmatch', false );
1963  $status->value = self::AS_SPAM_ERROR;
1964  return $status;
1965  }
1966 
1967  try {
1968  # Construct Content object
1969  $textbox_content = $this->toEditContent( $this->textbox1 );
1970  } catch ( MWContentSerializationException $ex ) {
1971  $status->fatal(
1972  'content-failed-to-parse',
1973  $this->contentModel,
1974  $this->contentFormat,
1975  $ex->getMessage()
1976  );
1977  $status->value = self::AS_PARSE_ERROR;
1978  return $status;
1979  }
1980 
1981  # Check image redirect
1982  if ( $this->mTitle->getNamespace() == NS_FILE &&
1983  $textbox_content->isRedirect() &&
1984  !$this->permManager->userHasRight( $user, 'upload' )
1985  ) {
1987  $status->setResult( false, $code );
1988 
1989  return $status;
1990  }
1991 
1992  # Check for spam
1993  $match = self::matchSummarySpamRegex( $this->summary );
1994  if ( $match === false && $this->section == 'new' ) {
1995  # $wgSpamRegex is enforced on this new heading/summary because, unlike
1996  # regular summaries, it is added to the actual wikitext.
1997  if ( $this->sectiontitle !== '' ) {
1998  # This branch is taken when the API is used with the 'sectiontitle' parameter.
1999  $match = self::matchSpamRegex( $this->sectiontitle );
2000  } else {
2001  # This branch is taken when the "Add Topic" user interface is used, or the API
2002  # is used with the 'summary' parameter.
2003  $match = self::matchSpamRegex( $this->summary );
2004  }
2005  }
2006  if ( $match === false ) {
2007  $match = self::matchSpamRegex( $this->textbox1 );
2008  }
2009  if ( $match !== false ) {
2010  $result['spam'] = $match;
2011  $ip = $request->getIP();
2012  $pdbk = $this->mTitle->getPrefixedDBkey();
2013  $match = str_replace( "\n", '', $match );
2014  wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
2015  $status->fatal( 'spamprotectionmatch', $match );
2016  $status->value = self::AS_SPAM_ERROR;
2017  return $status;
2018  }
2019  if ( !Hooks::run(
2020  'EditFilter',
2021  [ $this, $this->textbox1, $this->section, &$this->hookError, $this->summary ] )
2022  ) {
2023  # Error messages etc. could be handled within the hook...
2024  $status->fatal( 'hookaborted' );
2025  $status->value = self::AS_HOOK_ERROR;
2026  return $status;
2027  } elseif ( $this->hookError != '' ) {
2028  # ...or the hook could be expecting us to produce an error
2029  $status->fatal( 'hookaborted' );
2030  $status->value = self::AS_HOOK_ERROR_EXPECTED;
2031  return $status;
2032  }
2033 
2034  if ( $this->permManager->isBlockedFrom( $user, $this->mTitle ) ) {
2035  // Auto-block user's IP if the account was "hard" blocked
2036  if ( !wfReadOnly() ) {
2037  $user->spreadAnyEditBlock();
2038  }
2039  # Check block state against master, thus 'false'.
2040  $status->setResult( false, self::AS_BLOCKED_PAGE_FOR_USER );
2041  return $status;
2042  }
2043 
2044  $this->contentLength = strlen( $this->textbox1 );
2045  $config = $this->context->getConfig();
2046  $maxArticleSize = $config->get( 'MaxArticleSize' );
2047  if ( $this->contentLength > $maxArticleSize * 1024 ) {
2048  // Error will be displayed by showEditForm()
2049  $this->tooBig = true;
2050  $status->setResult( false, self::AS_CONTENT_TOO_BIG );
2051  return $status;
2052  }
2053 
2054  if ( !$this->permManager->userHasRight( $user, 'edit' ) ) {
2055  if ( $user->isAnon() ) {
2056  $status->setResult( false, self::AS_READ_ONLY_PAGE_ANON );
2057  return $status;
2058  } else {
2059  $status->fatal( 'readonlytext' );
2060  $status->value = self::AS_READ_ONLY_PAGE_LOGGED;
2061  return $status;
2062  }
2063  }
2064 
2065  $changingContentModel = false;
2066  if ( $this->contentModel !== $this->mTitle->getContentModel() ) {
2067  if ( !$config->get( 'ContentHandlerUseDB' ) ) {
2068  $status->fatal( 'editpage-cannot-use-custom-model' );
2069  $status->value = self::AS_CANNOT_USE_CUSTOM_MODEL;
2070  return $status;
2071  } elseif ( !$this->permManager->userHasRight( $user, 'editcontentmodel' ) ) {
2072  $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL );
2073  return $status;
2074  }
2075  // Make sure the user can edit the page under the new content model too
2076  $titleWithNewContentModel = clone $this->mTitle;
2077  $titleWithNewContentModel->setContentModel( $this->contentModel );
2078 
2079  $canEditModel = $this->permManager->userCan(
2080  'editcontentmodel',
2081  $user,
2082  $titleWithNewContentModel
2083  );
2084 
2085  if (
2086  !$canEditModel
2087  || !$this->permManager->userCan( 'edit', $user, $titleWithNewContentModel )
2088  ) {
2089  $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL );
2090 
2091  return $status;
2092  }
2093 
2094  $changingContentModel = true;
2095  $oldContentModel = $this->mTitle->getContentModel();
2096  }
2097 
2098  if ( $this->changeTags ) {
2099  $changeTagsStatus = ChangeTags::canAddTagsAccompanyingChange(
2100  $this->changeTags, $user );
2101  if ( !$changeTagsStatus->isOK() ) {
2102  $changeTagsStatus->value = self::AS_CHANGE_TAG_ERROR;
2103  return $changeTagsStatus;
2104  }
2105  }
2106 
2107  if ( wfReadOnly() ) {
2108  $status->fatal( 'readonlytext' );
2109  $status->value = self::AS_READ_ONLY_PAGE;
2110  return $status;
2111  }
2112  if ( $user->pingLimiter() || $user->pingLimiter( 'linkpurge', 0 )
2113  || ( $changingContentModel && $user->pingLimiter( 'editcontentmodel' ) )
2114  ) {
2115  $status->fatal( 'actionthrottledtext' );
2116  $status->value = self::AS_RATE_LIMITED;
2117  return $status;
2118  }
2119 
2120  # If the article has been deleted while editing, don't save it without
2121  # confirmation
2122  if ( $this->wasDeletedSinceLastEdit() && !$this->recreate ) {
2123  $status->setResult( false, self::AS_ARTICLE_WAS_DELETED );
2124  return $status;
2125  }
2126 
2127  # Load the page data from the master. If anything changes in the meantime,
2128  # we detect it by using page_latest like a token in a 1 try compare-and-swap.
2129  $this->page->loadPageData( 'fromdbmaster' );
2130  $new = !$this->page->exists();
2131 
2132  if ( $new ) {
2133  // Late check for create permission, just in case *PARANOIA*
2134  if ( !$this->permManager->userCan( 'create', $user, $this->mTitle ) ) {
2135  $status->fatal( 'nocreatetext' );
2136  $status->value = self::AS_NO_CREATE_PERMISSION;
2137  wfDebug( __METHOD__ . ": no create permission\n" );
2138  return $status;
2139  }
2140 
2141  // Don't save a new page if it's blank or if it's a MediaWiki:
2142  // message with content equivalent to default (allow empty pages
2143  // in this case to disable messages, see T52124)
2144  $defaultMessageText = $this->mTitle->getDefaultMessageText();
2145  if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI && $defaultMessageText !== false ) {
2146  $defaultText = $defaultMessageText;
2147  } else {
2148  $defaultText = '';
2149  }
2150 
2151  if ( !$this->allowBlankArticle && $this->textbox1 === $defaultText ) {
2152  $this->blankArticle = true;
2153  $status->fatal( 'blankarticle' );
2154  $status->setResult( false, self::AS_BLANK_ARTICLE );
2155  return $status;
2156  }
2157 
2158  if ( !$this->runPostMergeFilters( $textbox_content, $status, $user ) ) {
2159  return $status;
2160  }
2161 
2162  $content = $textbox_content;
2163 
2164  $result['sectionanchor'] = '';
2165  if ( $this->section == 'new' ) {
2166  if ( $this->sectiontitle !== '' ) {
2167  // Insert the section title above the content.
2168  $content = $content->addSectionHeader( $this->sectiontitle );
2169  } elseif ( $this->summary !== '' ) {
2170  // Insert the section title above the content.
2171  $content = $content->addSectionHeader( $this->summary );
2172  }
2173  $this->summary = $this->newSectionSummary( $result['sectionanchor'] );
2174  }
2175 
2176  $status->value = self::AS_SUCCESS_NEW_ARTICLE;
2177 
2178  } else { # not $new
2179 
2180  # Article exists. Check for edit conflict.
2181 
2182  $this->page->clear(); # Force reload of dates, etc.
2183  $timestamp = $this->page->getTimestamp();
2184  $latest = $this->page->getLatest();
2185 
2186  wfDebug( "timestamp: {$timestamp}, edittime: {$this->edittime}\n" );
2187 
2188  // An edit conflict is detected if the current revision is different from the
2189  // revision that was current when editing was initiated on the client.
2190  // This is checked based on the timestamp and revision ID.
2191  // TODO: the timestamp based check can probably go away now.
2192  if ( $timestamp != $this->edittime
2193  || ( $this->editRevId !== null && $this->editRevId != $latest )
2194  ) {
2195  $this->isConflict = true;
2196  if ( $this->section == 'new' ) {
2197  if ( $this->page->getUserText() == $user->getName() &&
2198  $this->page->getComment() == $this->newSectionSummary()
2199  ) {
2200  // Probably a duplicate submission of a new comment.
2201  // This can happen when CDN resends a request after
2202  // a timeout but the first one actually went through.
2203  wfDebug( __METHOD__
2204  . ": duplicate new section submission; trigger edit conflict!\n" );
2205  } else {
2206  // New comment; suppress conflict.
2207  $this->isConflict = false;
2208  wfDebug( __METHOD__ . ": conflict suppressed; new section\n" );
2209  }
2210  } elseif ( $this->section == ''
2212  DB_MASTER, $this->mTitle->getArticleID(),
2213  $user->getId(), $this->edittime
2214  )
2215  ) {
2216  # Suppress edit conflict with self, except for section edits where merging is required.
2217  wfDebug( __METHOD__ . ": Suppressing edit conflict, same user.\n" );
2218  $this->isConflict = false;
2219  }
2220  }
2221 
2222  // If sectiontitle is set, use it, otherwise use the summary as the section title.
2223  if ( $this->sectiontitle !== '' ) {
2224  $sectionTitle = $this->sectiontitle;
2225  } else {
2226  $sectionTitle = $this->summary;
2227  }
2228 
2229  $content = null;
2230 
2231  if ( $this->isConflict ) {
2232  wfDebug( __METHOD__
2233  . ": conflict! getting section '{$this->section}' for time '{$this->edittime}'"
2234  . " (id '{$this->editRevId}') (article time '{$timestamp}')\n" );
2235  // @TODO: replaceSectionAtRev() with base ID (not prior current) for ?oldid=X case
2236  // ...or disable section editing for non-current revisions (not exposed anyway).
2237  if ( $this->editRevId !== null ) {
2238  $content = $this->page->replaceSectionAtRev(
2239  $this->section,
2240  $textbox_content,
2241  $sectionTitle,
2242  $this->editRevId
2243  );
2244  } else {
2245  $content = $this->page->replaceSectionContent(
2246  $this->section,
2247  $textbox_content,
2248  $sectionTitle,
2249  $this->edittime
2250  );
2251  }
2252  } else {
2253  wfDebug( __METHOD__ . ": getting section '{$this->section}'\n" );
2254  $content = $this->page->replaceSectionContent(
2255  $this->section,
2256  $textbox_content,
2257  $sectionTitle
2258  );
2259  }
2260 
2261  if ( $content === null ) {
2262  wfDebug( __METHOD__ . ": activating conflict; section replace failed.\n" );
2263  $this->isConflict = true;
2264  $content = $textbox_content; // do not try to merge here!
2265  } elseif ( $this->isConflict ) {
2266  # Attempt merge
2267  if ( $this->mergeChangesIntoContent( $content ) ) {
2268  // Successful merge! Maybe we should tell the user the good news?
2269  $this->isConflict = false;
2270  wfDebug( __METHOD__ . ": Suppressing edit conflict, successful merge.\n" );
2271  } else {
2272  $this->section = '';
2273  $this->textbox1 = ContentHandler::getContentText( $content );
2274  wfDebug( __METHOD__ . ": Keeping edit conflict, failed merge.\n" );
2275  }
2276  }
2277 
2278  if ( $this->isConflict ) {
2279  $status->setResult( false, self::AS_CONFLICT_DETECTED );
2280  return $status;
2281  }
2282 
2283  if ( !$this->runPostMergeFilters( $content, $status, $user ) ) {
2284  return $status;
2285  }
2286 
2287  if ( $this->section == 'new' ) {
2288  // Handle the user preference to force summaries here
2289  if ( !$this->allowBlankSummary && trim( $this->summary ) == '' ) {
2290  $this->missingSummary = true;
2291  $status->fatal( 'missingsummary' ); // or 'missingcommentheader' if $section == 'new'. Blegh
2292  $status->value = self::AS_SUMMARY_NEEDED;
2293  return $status;
2294  }
2295 
2296  // Do not allow the user to post an empty comment
2297  if ( $this->textbox1 == '' ) {
2298  $this->missingComment = true;
2299  $status->fatal( 'missingcommenttext' );
2300  $status->value = self::AS_TEXTBOX_EMPTY;
2301  return $status;
2302  }
2303  } elseif ( !$this->allowBlankSummary
2304  && !$content->equals( $this->getOriginalContent( $user ) )
2305  && !$content->isRedirect()
2306  && md5( $this->summary ) == $this->autoSumm
2307  ) {
2308  $this->missingSummary = true;
2309  $status->fatal( 'missingsummary' );
2310  $status->value = self::AS_SUMMARY_NEEDED;
2311  return $status;
2312  }
2313 
2314  # All's well
2315  $sectionanchor = '';
2316  if ( $this->section == 'new' ) {
2317  $this->summary = $this->newSectionSummary( $sectionanchor );
2318  } elseif ( $this->section != '' ) {
2319  # Try to get a section anchor from the section source, redirect
2320  # to edited section if header found.
2321  # XXX: Might be better to integrate this into Article::replaceSectionAtRev
2322  # for duplicate heading checking and maybe parsing.
2323  $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );
2324  # We can't deal with anchors, includes, html etc in the header for now,
2325  # headline would need to be parsed to improve this.
2326  if ( $hasmatch && strlen( $matches[2] ) > 0 ) {
2327  $sectionanchor = $this->guessSectionName( $matches[2] );
2328  }
2329  }
2330  $result['sectionanchor'] = $sectionanchor;
2331 
2332  // Save errors may fall down to the edit form, but we've now
2333  // merged the section into full text. Clear the section field
2334  // so that later submission of conflict forms won't try to
2335  // replace that into a duplicated mess.
2336  $this->textbox1 = $this->toEditText( $content );
2337  $this->section = '';
2338 
2339  $status->value = self::AS_SUCCESS_UPDATE;
2340  }
2341 
2342  if ( !$this->allowSelfRedirect
2343  && $content->isRedirect()
2344  && $content->getRedirectTarget()->equals( $this->getTitle() )
2345  ) {
2346  // If the page already redirects to itself, don't warn.
2347  $currentTarget = $this->getCurrentContent()->getRedirectTarget();
2348  if ( !$currentTarget || !$currentTarget->equals( $this->getTitle() ) ) {
2349  $this->selfRedirect = true;
2350  $status->fatal( 'selfredirect' );
2351  $status->value = self::AS_SELF_REDIRECT;
2352  return $status;
2353  }
2354  }
2355 
2356  // Check for length errors again now that the section is merged in
2357  $this->contentLength = strlen( $this->toEditText( $content ) );
2358  if ( $this->contentLength > $maxArticleSize * 1024 ) {
2359  $this->tooBig = true;
2360  $status->setResult( false, self::AS_MAX_ARTICLE_SIZE_EXCEEDED );
2361  return $status;
2362  }
2363 
2364  $flags = EDIT_AUTOSUMMARY |
2365  ( $new ? EDIT_NEW : EDIT_UPDATE ) |
2366  ( ( $this->minoredit && !$this->isNew ) ? EDIT_MINOR : 0 ) |
2367  ( $bot ? EDIT_FORCE_BOT : 0 );
2368 
2369  $doEditStatus = $this->page->doEditContent(
2370  $content,
2371  $this->summary,
2372  $flags,
2373  false,
2374  $user,
2375  $content->getDefaultFormat(),
2378  );
2379 
2380  if ( !$doEditStatus->isOK() ) {
2381  // Failure from doEdit()
2382  // Show the edit conflict page for certain recognized errors from doEdit(),
2383  // but don't show it for errors from extension hooks
2384  $errors = $doEditStatus->getErrorsArray();
2385  if ( in_array( $errors[0][0],
2386  [ 'edit-gone-missing', 'edit-conflict', 'edit-already-exists' ] )
2387  ) {
2388  $this->isConflict = true;
2389  // Destroys data doEdit() put in $status->value but who cares
2390  $doEditStatus->value = self::AS_END;
2391  }
2392  return $doEditStatus;
2393  }
2394 
2395  $result['nullEdit'] = $doEditStatus->hasMessage( 'edit-no-change' );
2396  if ( $result['nullEdit'] ) {
2397  // We don't know if it was a null edit until now, so increment here
2398  $user->pingLimiter( 'linkpurge' );
2399  }
2400  $result['redirect'] = $content->isRedirect();
2401 
2402  $this->updateWatchlist();
2403 
2404  // If the content model changed, add a log entry
2405  if ( $changingContentModel ) {
2407  $user,
2408  $new ? false : $oldContentModel,
2409  $this->contentModel,
2410  $this->summary
2411  );
2412  }
2413 
2414  return $status;
2415  }
2416 
2423  protected function addContentModelChangeLogEntry( User $user, $oldModel, $newModel, $reason ) {
2424  $new = $oldModel === false;
2425  $log = new ManualLogEntry( 'contentmodel', $new ? 'new' : 'change' );
2426  $log->setPerformer( $user );
2427  $log->setTarget( $this->mTitle );
2428  $log->setComment( $reason );
2429  $log->setParameters( [
2430  '4::oldmodel' => $oldModel,
2431  '5::newmodel' => $newModel
2432  ] );
2433  $logid = $log->insert();
2434  $log->publish( $logid );
2435  }
2436 
2440  protected function updateWatchlist() {
2441  $user = $this->context->getUser();
2442  if ( !$user->isLoggedIn() ) {
2443  return;
2444  }
2445 
2447  $watch = $this->watchthis;
2448  // Do this in its own transaction to reduce contention...
2449  DeferredUpdates::addCallableUpdate( function () use ( $user, $title, $watch ) {
2450  if ( $watch == $user->isWatched( $title, User::IGNORE_USER_RIGHTS ) ) {
2451  return; // nothing to change
2452  }
2453  WatchAction::doWatchOrUnwatch( $watch, $title, $user );
2454  } );
2455  }
2456 
2468  private function mergeChangesIntoContent( &$editContent ) {
2469  $db = wfGetDB( DB_MASTER );
2470 
2471  // This is the revision that was current at the time editing was initiated on the client,
2472  // even if the edit was based on an old revision.
2473  $baseRevision = $this->getBaseRevision();
2474  $baseContent = $baseRevision ? $baseRevision->getContent() : null;
2475 
2476  if ( $baseContent === null ) {
2477  return false;
2478  }
2479 
2480  // The current state, we want to merge updates into it
2481  $currentRevision = Revision::loadFromTitle( $db, $this->mTitle );
2482  $currentContent = $currentRevision ? $currentRevision->getContent() : null;
2483 
2484  if ( $currentContent === null ) {
2485  return false;
2486  }
2487 
2488  $result = $this->contentHandlerFactory
2489  ->getContentHandler( $baseContent->getModel() )
2490  ->merge3( $baseContent, $editContent, $currentContent );
2491 
2492  if ( $result ) {
2493  $editContent = $result;
2494  // Update parentRevId to what we just merged.
2495  $this->parentRevId = $currentRevision->getId();
2496  return true;
2497  }
2498 
2499  return false;
2500  }
2501 
2514  public function getBaseRevision() {
2515  if ( !$this->mBaseRevision ) {
2516  $db = wfGetDB( DB_MASTER );
2517  $this->mBaseRevision = $this->editRevId
2518  ? Revision::newFromId( $this->editRevId, Revision::READ_LATEST )
2519  : Revision::loadFromTimestamp( $db, $this->mTitle, $this->edittime );
2520  }
2521  return $this->mBaseRevision;
2522  }
2523 
2531  public static function matchSpamRegex( $text ) {
2532  global $wgSpamRegex;
2533  // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
2534  $regexes = (array)$wgSpamRegex;
2535  return self::matchSpamRegexInternal( $text, $regexes );
2536  }
2537 
2545  public static function matchSummarySpamRegex( $text ) {
2546  global $wgSummarySpamRegex;
2547  $regexes = (array)$wgSummarySpamRegex;
2548  return self::matchSpamRegexInternal( $text, $regexes );
2549  }
2550 
2556  protected static function matchSpamRegexInternal( $text, $regexes ) {
2557  foreach ( $regexes as $regex ) {
2558  $matches = [];
2559  if ( preg_match( $regex, $text, $matches ) ) {
2560  return $matches[0];
2561  }
2562  }
2563  return false;
2564  }
2565 
2566  public function setHeaders() {
2567  $out = $this->context->getOutput();
2568 
2569  $out->addModules( 'mediawiki.action.edit' );
2570  $out->addModuleStyles( 'mediawiki.action.edit.styles' );
2571  $out->addModuleStyles( 'mediawiki.editfont.styles' );
2572 
2573  $user = $this->context->getUser();
2574 
2575  if ( $user->getOption( 'uselivepreview' ) ) {
2576  $out->addModules( 'mediawiki.action.edit.preview' );
2577  }
2578 
2579  if ( $user->getOption( 'useeditwarning' ) ) {
2580  $out->addModules( 'mediawiki.action.edit.editWarning' );
2581  }
2582 
2583  # Enabled article-related sidebar, toplinks, etc.
2584  $out->setArticleRelated( true );
2585 
2586  $contextTitle = $this->getContextTitle();
2587  if ( $this->isConflict ) {
2588  $msg = 'editconflict';
2589  } elseif ( $contextTitle->exists() && $this->section != '' ) {
2590  $msg = $this->section == 'new' ? 'editingcomment' : 'editingsection';
2591  } else {
2592  $msg = $contextTitle->exists()
2593  || ( $contextTitle->getNamespace() == NS_MEDIAWIKI
2594  && $contextTitle->getDefaultMessageText() !== false
2595  )
2596  ? 'editing'
2597  : 'creating';
2598  }
2599 
2600  # Use the title defined by DISPLAYTITLE magic word when present
2601  # NOTE: getDisplayTitle() returns HTML while getPrefixedText() returns plain text.
2602  # setPageTitle() treats the input as wikitext, which should be safe in either case.
2603  $displayTitle = isset( $this->mParserOutput ) ? $this->mParserOutput->getDisplayTitle() : false;
2604  if ( $displayTitle === false ) {
2605  $displayTitle = $contextTitle->getPrefixedText();
2606  } else {
2607  $out->setDisplayTitle( $displayTitle );
2608  }
2609  $out->setPageTitle( $this->context->msg( $msg, $displayTitle ) );
2610 
2611  $config = $this->context->getConfig();
2612 
2613  # Transmit the name of the message to JavaScript for live preview
2614  # Keep Resources.php/mediawiki.action.edit.preview in sync with the possible keys
2615  $out->addJsConfigVars( [
2616  'wgEditMessage' => $msg,
2617  'wgAjaxEditStash' => $config->get( 'AjaxEditStash' ),
2618  ] );
2619 
2620  // Add whether to use 'save' or 'publish' messages to JavaScript for post-edit, other
2621  // editors, etc.
2622  $out->addJsConfigVars(
2623  'wgEditSubmitButtonLabelPublish',
2624  $config->get( 'EditSubmitButtonLabelPublish' )
2625  );
2626  }
2627 
2631  protected function showIntro() {
2632  if ( $this->suppressIntro ) {
2633  return;
2634  }
2635 
2636  $out = $this->context->getOutput();
2637  $namespace = $this->mTitle->getNamespace();
2638 
2639  if ( $namespace == NS_MEDIAWIKI ) {
2640  # Show a warning if editing an interface message
2641  $out->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1\n</div>", 'editinginterface' );
2642  # If this is a default message (but not css, json, or js),
2643  # show a hint that it is translatable on translatewiki.net
2644  if (
2645  !$this->mTitle->hasContentModel( CONTENT_MODEL_CSS )
2646  && !$this->mTitle->hasContentModel( CONTENT_MODEL_JSON )
2647  && !$this->mTitle->hasContentModel( CONTENT_MODEL_JAVASCRIPT )
2648  ) {
2649  $defaultMessageText = $this->mTitle->getDefaultMessageText();
2650  if ( $defaultMessageText !== false ) {
2651  $out->wrapWikiMsg( "<div class='mw-translateinterface'>\n$1\n</div>",
2652  'translateinterface' );
2653  }
2654  }
2655  } elseif ( $namespace == NS_FILE ) {
2656  # Show a hint to shared repo
2657  $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $this->mTitle );
2658  if ( $file && !$file->isLocal() ) {
2659  $descUrl = $file->getDescriptionUrl();
2660  # there must be a description url to show a hint to shared repo
2661  if ( $descUrl ) {
2662  if ( !$this->mTitle->exists() ) {
2663  $out->wrapWikiMsg( "<div class=\"mw-sharedupload-desc-create\">\n$1\n</div>", [
2664  'sharedupload-desc-create', $file->getRepo()->getDisplayName(), $descUrl
2665  ] );
2666  } else {
2667  $out->wrapWikiMsg( "<div class=\"mw-sharedupload-desc-edit\">\n$1\n</div>", [
2668  'sharedupload-desc-edit', $file->getRepo()->getDisplayName(), $descUrl
2669  ] );
2670  }
2671  }
2672  }
2673  }
2674 
2675  # Show a warning message when someone creates/edits a user (talk) page but the user does not exist
2676  # Show log extract when the user is currently blocked
2677  if ( $namespace == NS_USER || $namespace == NS_USER_TALK ) {
2678  $username = explode( '/', $this->mTitle->getText(), 2 )[0];
2679  $user = User::newFromName( $username, false /* allow IP users */ );
2680  $ip = User::isIP( $username );
2681  $block = DatabaseBlock::newFromTarget( $user, $user );
2682  if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
2683  $out->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
2684  [ 'userpage-userdoesnotexist', wfEscapeWikiText( $username ) ] );
2685  } elseif (
2686  $block !== null &&
2687  $block->getType() != DatabaseBlock::TYPE_AUTO &&
2688  ( $block->isSitewide() || $user->isBlockedFrom( $this->mTitle ) )
2689  ) {
2690  // Show log extract if the user is sitewide blocked or is partially
2691  // blocked and not allowed to edit their user page or user talk page
2693  $out,
2694  'block',
2695  MediaWikiServices::getInstance()->getNamespaceInfo()->
2696  getCanonicalName( NS_USER ) . ':' . $block->getTarget(),
2697  '',
2698  [
2699  'lim' => 1,
2700  'showIfEmpty' => false,
2701  'msgKey' => [
2702  'blocked-notice-logextract',
2703  $user->getName() # Support GENDER in notice
2704  ]
2705  ]
2706  );
2707  }
2708  }
2709  # Try to add a custom edit intro, or use the standard one if this is not possible.
2710  if ( !$this->showCustomIntro() && !$this->mTitle->exists() ) {
2712  $this->context->msg( 'helppage' )->inContentLanguage()->text()
2713  ) );
2714  if ( $this->context->getUser()->isLoggedIn() ) {
2715  $out->wrapWikiMsg(
2716  // Suppress the external link icon, consider the help url an internal one
2717  "<div class=\"mw-newarticletext plainlinks\">\n$1\n</div>",
2718  [
2719  'newarticletext',
2720  $helpLink
2721  ]
2722  );
2723  } else {
2724  $out->wrapWikiMsg(
2725  // Suppress the external link icon, consider the help url an internal one
2726  "<div class=\"mw-newarticletextanon plainlinks\">\n$1\n</div>",
2727  [
2728  'newarticletextanon',
2729  $helpLink
2730  ]
2731  );
2732  }
2733  }
2734  # Give a notice if the user is editing a deleted/moved page...
2735  if ( !$this->mTitle->exists() ) {
2736  $dbr = wfGetDB( DB_REPLICA );
2737 
2738  LogEventsList::showLogExtract( $out, [ 'delete', 'move' ], $this->mTitle,
2739  '',
2740  [
2741  'lim' => 10,
2742  'conds' => [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ],
2743  'showIfEmpty' => false,
2744  'msgKey' => [ 'recreate-moveddeleted-warn' ]
2745  ]
2746  );
2747  }
2748  }
2749 
2755  protected function showCustomIntro() {
2756  if ( $this->editintro ) {
2757  $title = Title::newFromText( $this->editintro );
2758  if ( $this->isPageExistingAndViewable( $title, $this->context->getUser() ) ) {
2759  // Added using template syntax, to take <noinclude>'s into account.
2760  $this->context->getOutput()->addWikiTextAsContent(
2761  '<div class="mw-editintro">{{:' . $title->getFullText() . '}}</div>',
2762  /*linestart*/true,
2764  );
2765  return true;
2766  }
2767  }
2768  return false;
2769  }
2770 
2789  protected function toEditText( $content ) {
2790  if ( $content === null || $content === false || is_string( $content ) ) {
2791  return $content;
2792  }
2793 
2794  if ( !$this->isSupportedContentModel( $content->getModel() ) ) {
2795  throw new MWException( 'This content model is not supported: ' . $content->getModel() );
2796  }
2797 
2798  return $content->serialize( $this->contentFormat );
2799  }
2800 
2817  protected function toEditContent( $text ) {
2818  if ( $text === false || $text === null ) {
2819  return $text;
2820  }
2821 
2822  $content = ContentHandler::makeContent( $text, $this->getTitle(),
2823  $this->contentModel, $this->contentFormat );
2824 
2825  if ( !$this->isSupportedContentModel( $content->getModel() ) ) {
2826  throw new MWException( 'This content model is not supported: ' . $content->getModel() );
2827  }
2828 
2829  return $content;
2830  }
2831 
2840  public function showEditForm( $formCallback = null ) {
2841  # need to parse the preview early so that we know which templates are used,
2842  # otherwise users with "show preview after edit box" will get a blank list
2843  # we parse this near the beginning so that setHeaders can do the title
2844  # setting work instead of leaving it in getPreviewText
2845  $previewOutput = '';
2846  if ( $this->formtype == 'preview' ) {
2847  $previewOutput = $this->getPreviewText();
2848  }
2849 
2850  $out = $this->context->getOutput();
2851 
2852  // Avoid PHP 7.1 warning of passing $this by reference
2853  $editPage = $this;
2854  Hooks::run( 'EditPage::showEditForm:initial', [ &$editPage, &$out ] );
2855 
2856  $this->setHeaders();
2857 
2858  $this->addTalkPageText();
2859  $this->addEditNotices();
2860 
2861  if ( !$this->isConflict &&
2862  $this->section != '' &&
2863  !$this->isSectionEditSupported() ) {
2864  // We use $this->section to much before this and getVal('wgSection') directly in other places
2865  // at this point we can't reset $this->section to '' to fallback to non-section editing.
2866  // Someone is welcome to try refactoring though
2867  $out->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
2868  return;
2869  }
2870 
2871  $this->showHeader();
2872 
2873  $out->addHTML( $this->editFormPageTop );
2874 
2875  $user = $this->context->getUser();
2876  if ( $user->getOption( 'previewontop' ) ) {
2877  $this->displayPreviewArea( $previewOutput, true );
2878  }
2879 
2880  $out->addHTML( $this->editFormTextTop );
2881 
2882  if ( $this->wasDeletedSinceLastEdit() && $this->formtype !== 'save' ) {
2883  $out->wrapWikiMsg( "<div class='error mw-deleted-while-editing'>\n$1\n</div>",
2884  'deletedwhileediting' );
2885  }
2886 
2887  // @todo add EditForm plugin interface and use it here!
2888  // search for textarea1 and textarea2, and allow EditForm to override all uses.
2889  $out->addHTML( Html::openElement(
2890  'form',
2891  [
2892  'class' => 'mw-editform',
2893  'id' => self::EDITFORM_ID,
2894  'name' => self::EDITFORM_ID,
2895  'method' => 'post',
2896  'action' => $this->getActionURL( $this->getContextTitle() ),
2897  'enctype' => 'multipart/form-data'
2898  ]
2899  ) );
2900 
2901  if ( is_callable( $formCallback ) ) {
2902  wfWarn( 'The $formCallback parameter to ' . __METHOD__ . 'is deprecated' );
2903  call_user_func_array( $formCallback, [ &$out ] );
2904  }
2905 
2906  // Add a check for Unicode support
2907  $out->addHTML( Html::hidden( 'wpUnicodeCheck', self::UNICODE_CHECK ) );
2908 
2909  // Add an empty field to trip up spambots
2910  $out->addHTML(
2911  Xml::openElement( 'div', [ 'id' => 'antispam-container', 'style' => 'display: none;' ] )
2912  . Html::rawElement(
2913  'label',
2914  [ 'for' => 'wpAntispam' ],
2915  $this->context->msg( 'simpleantispam-label' )->parse()
2916  )
2917  . Xml::element(
2918  'input',
2919  [
2920  'type' => 'text',
2921  'name' => 'wpAntispam',
2922  'id' => 'wpAntispam',
2923  'value' => ''
2924  ]
2925  )
2926  . Xml::closeElement( 'div' )
2927  );
2928 
2929  // Avoid PHP 7.1 warning of passing $this by reference
2930  $editPage = $this;
2931  Hooks::run( 'EditPage::showEditForm:fields', [ &$editPage, &$out ] );
2932 
2933  // Put these up at the top to ensure they aren't lost on early form submission
2934  $this->showFormBeforeText();
2935 
2936  if ( $this->wasDeletedSinceLastEdit() && $this->formtype == 'save' ) {
2937  $username = $this->lastDelete->user_name;
2938  $comment = CommentStore::getStore()
2939  ->getComment( 'log_comment', $this->lastDelete )->text;
2940 
2941  // It is better to not parse the comment at all than to have templates expanded in the middle
2942  // TODO: can the checkLabel be moved outside of the div so that wrapWikiMsg could be used?
2943  $key = $comment === ''
2944  ? 'confirmrecreate-noreason'
2945  : 'confirmrecreate';
2946  $out->addHTML(
2947  '<div class="mw-confirm-recreate">' .
2948  $this->context->msg( $key, $username, "<nowiki>$comment</nowiki>" )->parse() .
2949  Xml::checkLabel( $this->context->msg( 'recreate' )->text(), 'wpRecreate', 'wpRecreate', false,
2950  [ 'title' => Linker::titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' ]
2951  ) .
2952  '</div>'
2953  );
2954  }
2955 
2956  # When the summary is hidden, also hide them on preview/show changes
2957  if ( $this->nosummary ) {
2958  $out->addHTML( Html::hidden( 'nosummary', true ) );
2959  }
2960 
2961  # If a blank edit summary was previously provided, and the appropriate
2962  # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
2963  # user being bounced back more than once in the event that a summary
2964  # is not required.
2965  # ####
2966  # For a bit more sophisticated detection of blank summaries, hash the
2967  # automatic one and pass that in the hidden field wpAutoSummary.
2968  if ( $this->missingSummary || ( $this->section == 'new' && $this->nosummary ) ) {
2969  $out->addHTML( Html::hidden( 'wpIgnoreBlankSummary', true ) );
2970  }
2971 
2972  if ( $this->undidRev ) {
2973  $out->addHTML( Html::hidden( 'wpUndidRevision', $this->undidRev ) );
2974  }
2975 
2976  if ( $this->selfRedirect ) {
2977  $out->addHTML( Html::hidden( 'wpIgnoreSelfRedirect', true ) );
2978  }
2979 
2980  if ( $this->hasPresetSummary ) {
2981  // If a summary has been preset using &summary= we don't want to prompt for
2982  // a different summary. Only prompt for a summary if the summary is blanked.
2983  // (T19416)
2984  $this->autoSumm = md5( '' );
2985  }
2986 
2987  $autosumm = $this->autoSumm !== '' ? $this->autoSumm : md5( $this->summary );
2988  $out->addHTML( Html::hidden( 'wpAutoSummary', $autosumm ) );
2989 
2990  $out->addHTML( Html::hidden( 'oldid', $this->oldid ) );
2991  $out->addHTML( Html::hidden( 'parentRevId', $this->getParentRevId() ) );
2992 
2993  $out->addHTML( Html::hidden( 'format', $this->contentFormat ) );
2994  $out->addHTML( Html::hidden( 'model', $this->contentModel ) );
2995 
2996  $out->enableOOUI();
2997 
2998  if ( $this->section == 'new' ) {
2999  $this->showSummaryInput( true, $this->summary );
3000  $out->addHTML( $this->getSummaryPreview( true, $this->summary ) );
3001  }
3002 
3003  $out->addHTML( $this->editFormTextBeforeContent );
3004  if ( $this->isConflict ) {
3005  // In an edit conflict, we turn textbox2 into the user's text,
3006  // and textbox1 into the stored version
3007  $this->textbox2 = $this->textbox1;
3008 
3009  $content = $this->getCurrentContent();
3010  $this->textbox1 = $this->toEditText( $content );
3011 
3013  $editConflictHelper->setTextboxes( $this->textbox2, $this->textbox1 );
3014  $editConflictHelper->setContentModel( $this->contentModel );
3015  $editConflictHelper->setContentFormat( $this->contentFormat );
3017  }
3018 
3019  if ( !$this->mTitle->isUserConfigPage() ) {
3020  $out->addHTML( self::getEditToolbar() );
3021  }
3022 
3023  if ( $this->blankArticle ) {
3024  $out->addHTML( Html::hidden( 'wpIgnoreBlankArticle', true ) );
3025  }
3026 
3027  if ( $this->isConflict ) {
3028  // In an edit conflict bypass the overridable content form method
3029  // and fallback to the raw wpTextbox1 since editconflicts can't be
3030  // resolved between page source edits and custom ui edits using the
3031  // custom edit ui.
3032  $conflictTextBoxAttribs = [];
3033  if ( $this->wasDeletedSinceLastEdit() ) {
3034  $conflictTextBoxAttribs['style'] = 'display:none;';
3035  } elseif ( $this->isOldRev ) {
3036  $conflictTextBoxAttribs['class'] = 'mw-textarea-oldrev';
3037  }
3038 
3039  $out->addHTML( $editConflictHelper->getEditConflictMainTextBox( $conflictTextBoxAttribs ) );
3041  } else {
3042  $this->showContentForm();
3043  }
3044 
3045  $out->addHTML( $this->editFormTextAfterContent );
3046 
3047  $this->showStandardInputs();
3048 
3049  $this->showFormAfterText();
3050 
3051  $this->showTosSummary();
3052 
3053  $this->showEditTools();
3054 
3055  $out->addHTML( $this->editFormTextAfterTools . "\n" );
3056 
3057  $out->addHTML( $this->makeTemplatesOnThisPageList( $this->getTemplates() ) );
3058 
3059  $out->addHTML( Html::rawElement( 'div', [ 'class' => 'hiddencats' ],
3060  Linker::formatHiddenCategories( $this->page->getHiddenCategories() ) ) );
3061 
3062  $out->addHTML( Html::rawElement( 'div', [ 'class' => 'limitreport' ],
3063  self::getPreviewLimitReport( $this->mParserOutput ) ) );
3064 
3065  $out->addModules( 'mediawiki.action.edit.collapsibleFooter' );
3066 
3067  if ( $this->isConflict ) {
3068  try {
3069  $this->showConflict();
3070  } catch ( MWContentSerializationException $ex ) {
3071  // this can't really happen, but be nice if it does.
3072  $msg = $this->context->msg(
3073  'content-failed-to-parse',
3074  $this->contentModel,
3075  $this->contentFormat,
3076  $ex->getMessage()
3077  );
3078  $out->wrapWikiTextAsInterface( 'error', $msg->plain() );
3079  }
3080  }
3081 
3082  // Set a hidden field so JS knows what edit form mode we are in
3083  if ( $this->isConflict ) {
3084  $mode = 'conflict';
3085  } elseif ( $this->preview ) {
3086  $mode = 'preview';
3087  } elseif ( $this->diff ) {
3088  $mode = 'diff';
3089  } else {
3090  $mode = 'text';
3091  }
3092  $out->addHTML( Html::hidden( 'mode', $mode, [ 'id' => 'mw-edit-mode' ] ) );
3093 
3094  // Marker for detecting truncated form data. This must be the last
3095  // parameter sent in order to be of use, so do not move me.
3096  $out->addHTML( Html::hidden( 'wpUltimateParam', true ) );
3097  $out->addHTML( $this->editFormTextBottom . "\n</form>\n" );
3098 
3099  if ( !$user->getOption( 'previewontop' ) ) {
3100  $this->displayPreviewArea( $previewOutput, false );
3101  }
3102  }
3103 
3111  public function makeTemplatesOnThisPageList( array $templates ) {
3112  $templateListFormatter = new TemplatesOnThisPageFormatter(
3113  $this->context, MediaWikiServices::getInstance()->getLinkRenderer()
3114  );
3115 
3116  // preview if preview, else section if section, else false
3117  $type = false;
3118  if ( $this->preview ) {
3119  $type = 'preview';
3120  } elseif ( $this->section != '' ) {
3121  $type = 'section';
3122  }
3123 
3124  return Html::rawElement( 'div', [ 'class' => 'templatesUsed' ],
3125  $templateListFormatter->format( $templates, $type )
3126  );
3127  }
3128 
3135  public static function extractSectionTitle( $text ) {
3136  preg_match( "/^(=+)(.+)\\1\\s*(\n|$)/i", $text, $matches );
3137  if ( !empty( $matches[2] ) ) {
3138  return MediaWikiServices::getInstance()->getParser()
3139  ->stripSectionName( trim( $matches[2] ) );
3140  } else {
3141  return false;
3142  }
3143  }
3144 
3145  protected function showHeader() {
3146  $out = $this->context->getOutput();
3147  $user = $this->context->getUser();
3148  if ( $this->isConflict ) {
3149  $this->addExplainConflictHeader( $out );
3150  $this->editRevId = $this->page->getLatest();
3151  } else {
3152  if ( $this->section != '' && $this->section != 'new' && !$this->summary &&
3153  !$this->preview && !$this->diff
3154  ) {
3155  $sectionTitle = self::extractSectionTitle( $this->textbox1 ); // FIXME: use Content object
3156  if ( $sectionTitle !== false ) {
3157  $this->summary = "/* $sectionTitle */ ";
3158  }
3159  }
3160 
3161  $buttonLabel = $this->context->msg( $this->getSubmitButtonLabel() )->text();
3162 
3163  if ( $this->missingComment ) {
3164  $out->wrapWikiMsg( "<div id='mw-missingcommenttext'>\n$1\n</div>", 'missingcommenttext' );
3165  }
3166 
3167  if ( $this->missingSummary && $this->section != 'new' ) {
3168  $out->wrapWikiMsg(
3169  "<div id='mw-missingsummary'>\n$1\n</div>",
3170  [ 'missingsummary', $buttonLabel ]
3171  );
3172  }
3173 
3174  if ( $this->missingSummary && $this->section == 'new' ) {
3175  $out->wrapWikiMsg(
3176  "<div id='mw-missingcommentheader'>\n$1\n</div>",
3177  [ 'missingcommentheader', $buttonLabel ]
3178  );
3179  }
3180 
3181  if ( $this->blankArticle ) {
3182  $out->wrapWikiMsg(
3183  "<div id='mw-blankarticle'>\n$1\n</div>",
3184  [ 'blankarticle', $buttonLabel ]
3185  );
3186  }
3187 
3188  if ( $this->selfRedirect ) {
3189  $out->wrapWikiMsg(
3190  "<div id='mw-selfredirect'>\n$1\n</div>",
3191  [ 'selfredirect', $buttonLabel ]
3192  );
3193  }
3194 
3195  if ( $this->hookError !== '' ) {
3196  $out->addWikiTextAsInterface( $this->hookError );
3197  }
3198 
3199  if ( $this->section != 'new' ) {
3200  $revision = $this->mArticle->getRevisionFetched();
3201  if ( $revision ) {
3202  // Let sysop know that this will make private content public if saved
3203 
3204  if ( !$revision->userCan( RevisionRecord::DELETED_TEXT, $user ) ) {
3205  $out->wrapWikiMsg(
3206  "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
3207  'rev-deleted-text-permission'
3208  );
3209  } elseif ( $revision->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
3210  $out->wrapWikiMsg(
3211  "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
3212  'rev-deleted-text-view'
3213  );
3214  }
3215 
3216  if ( !$revision->isCurrent() ) {
3217  $this->mArticle->setOldSubtitle( $revision->getId() );
3218  $out->wrapWikiMsg(
3219  Html::warningBox( "\n$1\n" ),
3220  'editingold'
3221  );
3222  $this->isOldRev = true;
3223  }
3224  } elseif ( $this->mTitle->exists() ) {
3225  // Something went wrong
3226 
3227  $out->wrapWikiMsg( "<div class='errorbox'>\n$1\n</div>\n",
3228  [ 'missing-revision', $this->oldid ] );
3229  }
3230  }
3231  }
3232 
3233  if ( wfReadOnly() ) {
3234  $out->wrapWikiMsg(
3235  "<div id=\"mw-read-only-warning\">\n$1\n</div>",
3236  [ 'readonlywarning', wfReadOnlyReason() ]
3237  );
3238  } elseif ( $user->isAnon() ) {
3239  if ( $this->formtype != 'preview' ) {
3240  $returntoquery = array_diff_key(
3241  $this->context->getRequest()->getValues(),
3242  [ 'title' => true, 'returnto' => true, 'returntoquery' => true ]
3243  );
3244  $out->wrapWikiMsg(
3245  "<div id='mw-anon-edit-warning' class='warningbox'>\n$1\n</div>",
3246  [ 'anoneditwarning',
3247  // Log-in link
3248  SpecialPage::getTitleFor( 'Userlogin' )->getFullURL( [
3249  'returnto' => $this->getTitle()->getPrefixedDBkey(),
3250  'returntoquery' => wfArrayToCgi( $returntoquery ),
3251  ] ),
3252  // Sign-up link
3253  SpecialPage::getTitleFor( 'CreateAccount' )->getFullURL( [
3254  'returnto' => $this->getTitle()->getPrefixedDBkey(),
3255  'returntoquery' => wfArrayToCgi( $returntoquery ),
3256  ] )
3257  ]
3258  );
3259  } else {
3260  $out->wrapWikiMsg( "<div id=\"mw-anon-preview-warning\" class=\"warningbox\">\n$1</div>",
3261  'anonpreviewwarning'
3262  );
3263  }
3264  } elseif ( $this->mTitle->isUserConfigPage() ) {
3265  # Check the skin exists
3266  if ( $this->isWrongCaseUserConfigPage() ) {
3267  $out->wrapWikiMsg(
3268  "<div class='error' id='mw-userinvalidconfigtitle'>\n$1\n</div>",
3269  [ 'userinvalidconfigtitle', $this->mTitle->getSkinFromConfigSubpage() ]
3270  );
3271  }
3272  if ( $this->getTitle()->isSubpageOf( $user->getUserPage() ) ) {
3273  $isUserCssConfig = $this->mTitle->isUserCssConfigPage();
3274  $isUserJsonConfig = $this->mTitle->isUserJsonConfigPage();
3275  $isUserJsConfig = $this->mTitle->isUserJsConfigPage();
3276 
3277  $warning = $isUserCssConfig
3278  ? 'usercssispublic'
3279  : ( $isUserJsonConfig ? 'userjsonispublic' : 'userjsispublic' );
3280 
3281  $out->wrapWikiMsg( '<div class="mw-userconfigpublic">$1</div>', $warning );
3282 
3283  if ( $isUserJsConfig ) {
3284  $out->wrapWikiMsg( '<div class="mw-userconfigdangerous">$1</div>', 'userjsdangerous' );
3285  }
3286 
3287  if ( $this->formtype !== 'preview' ) {
3288  $config = $this->context->getConfig();
3289  if ( $isUserCssConfig && $config->get( 'AllowUserCss' ) ) {
3290  $out->wrapWikiMsg(
3291  "<div id='mw-usercssyoucanpreview'>\n$1\n</div>",
3292  [ 'usercssyoucanpreview' ]
3293  );
3294  } elseif ( $isUserJsonConfig /* No comparable 'AllowUserJson' */ ) {
3295  $out->wrapWikiMsg(
3296  "<div id='mw-userjsonyoucanpreview'>\n$1\n</div>",
3297  [ 'userjsonyoucanpreview' ]
3298  );
3299  } elseif ( $isUserJsConfig && $config->get( 'AllowUserJs' ) ) {
3300  $out->wrapWikiMsg(
3301  "<div id='mw-userjsyoucanpreview'>\n$1\n</div>",
3302  [ 'userjsyoucanpreview' ]
3303  );
3304  }
3305  }
3306  }
3307  }
3308 
3310 
3311  $this->addLongPageWarningHeader();
3312 
3313  # Add header copyright warning
3314  $this->showHeaderCopyrightWarning();
3315  }
3316 
3324  private function getSummaryInputAttributes( array $inputAttrs = null ) {
3325  // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
3326  // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
3327  // Unicode codepoints.
3328  return ( is_array( $inputAttrs ) ? $inputAttrs : [] ) + [
3329  'id' => 'wpSummary',
3330  'name' => 'wpSummary',
3332  'tabindex' => 1,
3333  'size' => 60,
3334  'spellcheck' => 'true',
3335  ];
3336  }
3337 
3347  public function getSummaryInputWidget( $summary = "", $labelText = null, $inputAttrs = null ) {
3348  $inputAttrs = OOUI\Element::configFromHtmlAttributes(
3349  $this->getSummaryInputAttributes( $inputAttrs )
3350  );
3351  $inputAttrs += [
3352  'title' => Linker::titleAttrib( 'summary' ),
3353  'accessKey' => Linker::accesskey( 'summary' ),
3354  ];
3355 
3356  // For compatibility with old scripts and extensions, we want the legacy 'id' on the `<input>`
3357  $inputAttrs['inputId'] = $inputAttrs['id'];
3358  $inputAttrs['id'] = 'wpSummaryWidget';
3359 
3360  return new OOUI\FieldLayout(
3361  new OOUI\TextInputWidget( [
3362  'value' => $summary,
3363  'infusable' => true,
3364  ] + $inputAttrs ),
3365  [
3366  'label' => new OOUI\HtmlSnippet( $labelText ),
3367  'align' => 'top',
3368  'id' => 'wpSummaryLabel',
3369  'classes' => [ $this->missingSummary ? 'mw-summarymissed' : 'mw-summary' ],
3370  ]
3371  );
3372  }
3373 
3380  protected function showSummaryInput( $isSubjectPreview, $summary = "" ) {
3381  # Add a class if 'missingsummary' is triggered to allow styling of the summary line
3382  $summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary';
3383  if ( $isSubjectPreview ) {
3384  if ( $this->nosummary ) {
3385  return;
3386  }
3387  } elseif ( !$this->mShowSummaryField ) {
3388  return;
3389  }
3390 
3391  $labelText = $this->context->msg( $isSubjectPreview ? 'subject' : 'summary' )->parse();
3392  $this->context->getOutput()->addHTML( $this->getSummaryInputWidget(
3393  $summary,
3394  $labelText,
3395  [ 'class' => $summaryClass ]
3396  ) );
3397  }
3398 
3406  protected function getSummaryPreview( $isSubjectPreview, $summary = "" ) {
3407  // avoid spaces in preview, gets always trimmed on save
3408  $summary = trim( $summary );
3409  if ( !$summary || ( !$this->preview && !$this->diff ) ) {
3410  return "";
3411  }
3412 
3413  if ( $isSubjectPreview ) {
3414  $summary = $this->context->msg( 'newsectionsummary' )
3415  ->rawParams( MediaWikiServices::getInstance()->getParser()
3416  ->stripSectionName( $summary ) )
3417  ->inContentLanguage()->text();
3418  }
3419 
3420  $message = $isSubjectPreview ? 'subject-preview' : 'summary-preview';
3421 
3422  $summary = $this->context->msg( $message )->parse()
3423  . Linker::commentBlock( $summary, $this->mTitle, $isSubjectPreview );
3424  return Xml::tags( 'div', [ 'class' => 'mw-summary-preview' ], $summary );
3425  }
3426 
3427  protected function showFormBeforeText() {
3428  $out = $this->context->getOutput();
3429  $out->addHTML( Html::hidden( 'wpSection', $this->section ) );
3430  $out->addHTML( Html::hidden( 'wpStarttime', $this->starttime ) );
3431  $out->addHTML( Html::hidden( 'wpEdittime', $this->edittime ) );
3432  $out->addHTML( Html::hidden( 'editRevId', $this->editRevId ) );
3433  $out->addHTML( Html::hidden( 'wpScrolltop', $this->scrolltop, [ 'id' => 'wpScrolltop' ] ) );
3434  }
3435 
3436  protected function showFormAfterText() {
3449  $this->context->getOutput()->addHTML(
3450  "\n" .
3451  Html::hidden( "wpEditToken", $this->context->getUser()->getEditToken() ) .
3452  "\n"
3453  );
3454  }
3455 
3464  protected function showContentForm() {
3465  $this->showTextbox1();
3466  }
3467 
3476  protected function showTextbox1( $customAttribs = null, $textoverride = null ) {
3477  if ( $this->wasDeletedSinceLastEdit() && $this->formtype == 'save' ) {
3478  $attribs = [ 'style' => 'display:none;' ];
3479  } else {
3480  $builder = new TextboxBuilder();
3481  $classes = $builder->getTextboxProtectionCSSClasses( $this->getTitle() );
3482 
3483  # Is an old revision being edited?
3484  if ( $this->isOldRev ) {
3485  $classes[] = 'mw-textarea-oldrev';
3486  }
3487 
3488  $attribs = [ 'tabindex' => 1 ];
3489 
3490  if ( is_array( $customAttribs ) ) {
3491  $attribs += $customAttribs;
3492  }
3493 
3494  $attribs = $builder->mergeClassesIntoAttributes( $classes, $attribs );
3495  }
3496 
3497  $this->showTextbox(
3498  $textoverride ?? $this->textbox1,
3499  'wpTextbox1',
3500  $attribs
3501  );
3502  }
3503 
3504  protected function showTextbox2() {
3505  $this->showTextbox( $this->textbox2, 'wpTextbox2', [ 'tabindex' => 6, 'readonly' ] );
3506  }
3507 
3508  protected function showTextbox( $text, $name, $customAttribs = [] ) {
3509  $builder = new TextboxBuilder();
3510  $attribs = $builder->buildTextboxAttribs(
3511  $name,
3512  $customAttribs,
3513  $this->context->getUser(),
3515  );
3516 
3517  $this->context->getOutput()->addHTML(
3518  Html::textarea( $name, $builder->addNewLineAtEnd( $text ), $attribs )
3519  );
3520  }
3521 
3522  protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
3523  $classes = [];
3524  if ( $isOnTop ) {
3525  $classes[] = 'ontop';
3526  }
3527 
3528  $attribs = [ 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) ];
3529 
3530  if ( $this->formtype != 'preview' ) {
3531  $attribs['style'] = 'display: none;';
3532  }
3533 
3534  $out = $this->context->getOutput();
3535  $out->addHTML( Xml::openElement( 'div', $attribs ) );
3536 
3537  if ( $this->formtype == 'preview' ) {
3538  $this->showPreview( $previewOutput );
3539  } else {
3540  // Empty content container for LivePreview
3541  $pageViewLang = $this->mTitle->getPageViewLanguage();
3542  $attribs = [ 'lang' => $pageViewLang->getHtmlCode(), 'dir' => $pageViewLang->getDir(),
3543  'class' => 'mw-content-' . $pageViewLang->getDir() ];
3544  $out->addHTML( Html::rawElement( 'div', $attribs ) );
3545  }
3546 
3547  $out->addHTML( '</div>' );
3548 
3549  if ( $this->formtype == 'diff' ) {
3550  try {
3551  $this->showDiff();
3552  } catch ( MWContentSerializationException $ex ) {
3553  $msg = $this->context->msg(
3554  'content-failed-to-parse',
3555  $this->contentModel,
3556  $this->contentFormat,
3557  $ex->getMessage()
3558  );
3559  $out->wrapWikiTextAsInterface( 'error', $msg->plain() );
3560  }
3561  }
3562  }
3563 
3570  protected function showPreview( $text ) {
3571  if ( $this->mArticle instanceof CategoryPage ) {
3572  $this->mArticle->openShowCategory();
3573  }
3574  # This hook seems slightly odd here, but makes things more
3575  # consistent for extensions.
3576  $out = $this->context->getOutput();
3577  Hooks::run( 'OutputPageBeforeHTML', [ &$out, &$text ] );
3578  $out->addHTML( $text );
3579  if ( $this->mArticle instanceof CategoryPage ) {
3580  $this->mArticle->closeShowCategory();
3581  }
3582  }
3583 
3591  public function showDiff() {
3592  $oldtitlemsg = 'currentrev';
3593  # if message does not exist, show diff against the preloaded default
3594  if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI && !$this->mTitle->exists() ) {
3595  $oldtext = $this->mTitle->getDefaultMessageText();
3596  if ( $oldtext !== false ) {
3597  $oldtitlemsg = 'defaultmessagetext';
3598  $oldContent = $this->toEditContent( $oldtext );
3599  } else {
3600  $oldContent = null;
3601  }
3602  } else {
3603  $oldContent = $this->getCurrentContent();
3604  }
3605 
3606  $textboxContent = $this->toEditContent( $this->textbox1 );
3607  if ( $this->editRevId !== null ) {
3608  $newContent = $this->page->replaceSectionAtRev(
3609  $this->section, $textboxContent, $this->summary, $this->editRevId
3610  );
3611  } else {
3612  $newContent = $this->page->replaceSectionContent(
3613  $this->section, $textboxContent, $this->summary, $this->edittime
3614  );
3615  }
3616 
3617  if ( $newContent ) {
3618  Hooks::run( 'EditPageGetDiffContent', [ $this, &$newContent ] );
3619 
3620  $user = $this->context->getUser();
3621  $popts = ParserOptions::newFromUserAndLang( $user,
3622  MediaWikiServices::getInstance()->getContentLanguage() );
3623  $newContent = $newContent->preSaveTransform( $this->mTitle, $user, $popts );
3624  }
3625 
3626  if ( ( $oldContent && !$oldContent->isEmpty() ) || ( $newContent && !$newContent->isEmpty() ) ) {
3627  $oldtitle = $this->context->msg( $oldtitlemsg )->parse();
3628  $newtitle = $this->context->msg( 'yourtext' )->parse();
3629 
3630  if ( !$oldContent ) {
3631  $oldContent = $newContent->getContentHandler()->makeEmptyContent();
3632  }
3633 
3634  if ( !$newContent ) {
3635  $newContent = $oldContent->getContentHandler()->makeEmptyContent();
3636  }
3637 
3638  $de = $oldContent->getContentHandler()->createDifferenceEngine( $this->context );
3639  $de->setContent( $oldContent, $newContent );
3640 
3641  $difftext = $de->getDiff( $oldtitle, $newtitle );
3642  $de->showDiffStyle();
3643  } else {
3644  $difftext = '';
3645  }
3646 
3647  $this->context->getOutput()->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
3648  }
3649 
3653  protected function showHeaderCopyrightWarning() {
3654  $msg = 'editpage-head-copy-warn';
3655  if ( !$this->context->msg( $msg )->isDisabled() ) {
3656  $this->context->getOutput()->wrapWikiMsg( "<div class='editpage-head-copywarn'>\n$1\n</div>",
3657  'editpage-head-copy-warn' );
3658  }
3659  }
3660 
3669  protected function showTosSummary() {
3670  $msg = 'editpage-tos-summary';
3671  Hooks::run( 'EditPageTosSummary', [ $this->mTitle, &$msg ] );
3672  if ( !$this->context->msg( $msg )->isDisabled() ) {
3673  $out = $this->context->getOutput();
3674  $out->addHTML( '<div class="mw-tos-summary">' );
3675  $out->addWikiMsg( $msg );
3676  $out->addHTML( '</div>' );
3677  }
3678  }
3679 
3684  protected function showEditTools() {
3685  $this->context->getOutput()->addHTML( '<div class="mw-editTools">' .
3686  $this->context->msg( 'edittools' )->inContentLanguage()->parse() .
3687  '</div>' );
3688  }
3689 
3696  protected function getCopywarn() {
3697  return self::getCopyrightWarning( $this->mTitle );
3698  }
3699 
3708  public static function getCopyrightWarning( $title, $format = 'plain', $langcode = null ) {
3709  global $wgRightsText;
3710  if ( $wgRightsText ) {
3711  $copywarnMsg = [ 'copyrightwarning',
3712  '[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]',
3713  $wgRightsText ];
3714  } else {
3715  $copywarnMsg = [ 'copyrightwarning2',
3716  '[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]' ];
3717  }
3718  // Allow for site and per-namespace customization of contribution/copyright notice.
3719  Hooks::run( 'EditPageCopyrightWarning', [ $title, &$copywarnMsg ] );
3720 
3721  $msg = wfMessage( ...$copywarnMsg )->title( $title );
3722  if ( $langcode ) {
3723  $msg->inLanguage( $langcode );
3724  }
3725  return "<div id=\"editpage-copywarn\">\n" .
3726  $msg->$format() . "\n</div>";
3727  }
3728 
3736  public static function getPreviewLimitReport( ParserOutput $output = null ) {
3737  global $wgLang;
3738 
3739  if ( !$output || !$output->getLimitReportData() ) {
3740  return '';
3741  }
3742 
3743  $limitReport = Html::rawElement( 'div', [ 'class' => 'mw-limitReportExplanation' ],
3744  wfMessage( 'limitreport-title' )->parseAsBlock()
3745  );
3746 
3747  // Show/hide animation doesn't work correctly on a table, so wrap it in a div.
3748  $limitReport .= Html::openElement( 'div', [ 'class' => 'preview-limit-report-wrapper' ] );
3749 
3750  $limitReport .= Html::openElement( 'table', [
3751  'class' => 'preview-limit-report wikitable'
3752  ] ) .
3753  Html::openElement( 'tbody' );
3754 
3755  foreach ( $output->getLimitReportData() as $key => $value ) {
3756  if ( Hooks::run( 'ParserLimitReportFormat',
3757  [ $key, &$value, &$limitReport, true, true ]
3758  ) ) {
3759  $keyMsg = wfMessage( $key );
3760  $valueMsg = wfMessage( [ "$key-value-html", "$key-value" ] );
3761  if ( !$valueMsg->exists() ) {
3762  $valueMsg = new RawMessage( '$1' );
3763  }
3764  if ( !$keyMsg->isDisabled() && !$valueMsg->isDisabled() ) {
3765  $limitReport .= Html::openElement( 'tr' ) .
3766  Html::rawElement( 'th', null, $keyMsg->parse() ) .
3767  Html::rawElement( 'td', null,
3768  $wgLang->formatNum( $valueMsg->params( $value )->parse() )
3769  ) .
3770  Html::closeElement( 'tr' );
3771  }
3772  }
3773  }
3774 
3775  $limitReport .= Html::closeElement( 'tbody' ) .
3776  Html::closeElement( 'table' ) .
3777  Html::closeElement( 'div' );
3778 
3779  return $limitReport;
3780  }
3781 
3782  protected function showStandardInputs( &$tabindex = 2 ) {
3783  $out = $this->context->getOutput();
3784  $out->addHTML( "<div class='editOptions'>\n" );
3785 
3786  if ( $this->section != 'new' ) {
3787  $this->showSummaryInput( false, $this->summary );
3788  $out->addHTML( $this->getSummaryPreview( false, $this->summary ) );
3789  }
3790 
3791  $checkboxes = $this->getCheckboxesWidget(
3792  $tabindex,
3793  [ 'minor' => $this->minoredit, 'watch' => $this->watchthis ]
3794  );
3795  $checkboxesHTML = new OOUI\HorizontalLayout( [ 'items' => $checkboxes ] );
3796 
3797  $out->addHTML( "<div class='editCheckboxes'>" . $checkboxesHTML . "</div>\n" );
3798 
3799  // Show copyright warning.
3800  $out->addWikiTextAsInterface( $this->getCopywarn() );
3801  $out->addHTML( $this->editFormTextAfterWarn );
3802 
3803  $out->addHTML( "<div class='editButtons'>\n" );
3804  $out->addHTML( implode( "\n", $this->getEditButtons( $tabindex ) ) . "\n" );
3805 
3806  $cancel = $this->getCancelLink( $tabindex++ );
3807 
3808  $message = $this->context->msg( 'edithelppage' )->inContentLanguage()->text();
3809  $edithelpurl = Skin::makeInternalOrExternalUrl( $message );
3810  $edithelp =
3811  Html::linkButton(
3812  $this->context->msg( 'edithelp' )->text(),
3813  [ 'target' => 'helpwindow', 'href' => $edithelpurl ],
3814  [ 'mw-ui-quiet' ]
3815  ) .
3816  $this->context->msg( 'word-separator' )->escaped() .
3817  $this->context->msg( 'newwindow' )->parse();
3818 
3819  $out->addHTML( " <span class='cancelLink'>{$cancel}</span>\n" );
3820  $out->addHTML( " <span class='editHelp'>{$edithelp}</span>\n" );
3821  $out->addHTML( "</div><!-- editButtons -->\n" );
3822 
3823  Hooks::run( 'EditPage::showStandardInputs:options', [ $this, $out, &$tabindex ] );
3824 
3825  $out->addHTML( "</div><!-- editOptions -->\n" );
3826  }
3827 
3832  protected function showConflict() {
3833  $out = $this->context->getOutput();
3834  // Avoid PHP 7.1 warning of passing $this by reference
3835  $editPage = $this;
3836  if ( Hooks::run( 'EditPageBeforeConflictDiff', [ &$editPage, &$out ] ) ) {
3837  $this->incrementConflictStats();
3838 
3839  $this->getEditConflictHelper()->showEditFormTextAfterFooters();
3840  }
3841  }
3842 
3843  protected function incrementConflictStats() {
3844  $this->getEditConflictHelper()->incrementConflictStats( $this->context->getUser() );
3845  }
3846 
3851  public function getCancelLink( $tabindex = 0 ) {
3852  $cancelParams = [];
3853  if ( !$this->isConflict && $this->oldid > 0 ) {
3854  $cancelParams['oldid'] = $this->oldid;
3855  } elseif ( $this->getContextTitle()->isRedirect() ) {
3856  $cancelParams['redirect'] = 'no';
3857  }
3858 
3859  return new OOUI\ButtonWidget( [
3860  'id' => 'mw-editform-cancel',
3861  'tabIndex' => $tabindex,
3862  'href' => $this->getContextTitle()->getLinkURL( $cancelParams ),
3863  'label' => new OOUI\HtmlSnippet( $this->context->msg( 'cancel' )->parse() ),
3864  'framed' => false,
3865  'infusable' => true,
3866  'flags' => 'destructive',
3867  ] );
3868  }
3869 
3879  protected function getActionURL( Title $title ) {
3880  return $title->getLocalURL( [ 'action' => $this->action ] );
3881  }
3882 
3890  protected function wasDeletedSinceLastEdit() {
3891  if ( $this->deletedSinceEdit !== null ) {
3892  return $this->deletedSinceEdit;
3893  }
3894 
3895  $this->deletedSinceEdit = false;
3896 
3897  if ( !$this->mTitle->exists() && $this->mTitle->isDeletedQuick() ) {
3898  $this->lastDelete = $this->getLastDelete();
3899  if ( $this->lastDelete ) {
3900  $deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp );
3901  if ( $deleteTime > $this->starttime ) {
3902  $this->deletedSinceEdit = true;
3903  }
3904  }
3905  }
3906 
3907  return $this->deletedSinceEdit;
3908  }
3909 
3915  protected function getLastDelete() {
3916  $dbr = wfGetDB( DB_REPLICA );
3917  $commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
3918  $actorQuery = ActorMigration::newMigration()->getJoin( 'log_user' );
3919  $data = $dbr->selectRow(
3920  array_merge( [ 'logging' ], $commentQuery['tables'], $actorQuery['tables'], [ 'user' ] ),
3921  [
3922  'log_type',
3923  'log_action',
3924  'log_timestamp',
3925  'log_namespace',
3926  'log_title',
3927  'log_params',
3928  'log_deleted',
3929  'user_name'
3930  ] + $commentQuery['fields'] + $actorQuery['fields'],
3931  [
3932  'log_namespace' => $this->mTitle->getNamespace(),
3933  'log_title' => $this->mTitle->getDBkey(),
3934  'log_type' => 'delete',
3935  'log_action' => 'delete',
3936  ],
3937  __METHOD__,
3938  [ 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ],
3939  [
3940  'user' => [ 'JOIN', 'user_id=' . $actorQuery['fields']['log_user'] ],
3941  ] + $commentQuery['joins'] + $actorQuery['joins']
3942  );
3943  // Quick paranoid permission checks...
3944  if ( is_object( $data ) ) {
3945  if ( $data->log_deleted & LogPage::DELETED_USER ) {
3946  $data->user_name = $this->context->msg( 'rev-deleted-user' )->escaped();
3947  }
3948 
3949  if ( $data->log_deleted & LogPage::DELETED_COMMENT ) {
3950  $data->log_comment_text = $this->context->msg( 'rev-deleted-comment' )->escaped();
3951  $data->log_comment_data = null;
3952  }
3953  }
3954 
3955  return $data;
3956  }
3957 
3963  public function getPreviewText() {
3964  $out = $this->context->getOutput();
3965  $config = $this->context->getConfig();
3966 
3967  if ( $config->get( 'RawHtml' ) && !$this->mTokenOk ) {
3968  // Could be an offsite preview attempt. This is very unsafe if
3969  // HTML is enabled, as it could be an attack.
3970  $parsedNote = '';
3971  if ( $this->textbox1 !== '' ) {
3972  // Do not put big scary notice, if previewing the empty
3973  // string, which happens when you initially edit
3974  // a category page, due to automatic preview-on-open.
3975  $parsedNote = Html::rawElement( 'div', [ 'class' => 'previewnote' ],
3976  $out->parseAsInterface(
3977  $this->context->msg( 'session_fail_preview_html' )->plain()
3978  ) );
3979  }
3980  $this->incrementEditFailureStats( 'session_loss' );
3981  return $parsedNote;
3982  }
3983 
3984  $note = '';
3985 
3986  try {
3987  $content = $this->toEditContent( $this->textbox1 );
3988 
3989  $previewHTML = '';
3990  if ( !Hooks::run(
3991  'AlternateEditPreview',
3992  [ $this, &$content, &$previewHTML, &$this->mParserOutput ] )
3993  ) {
3994  return $previewHTML;
3995  }
3996 
3997  # provide a anchor link to the editform
3998  $continueEditing = '<span class="mw-continue-editing">' .
3999  '[[#' . self::EDITFORM_ID . '|' .
4000  $this->context->getLanguage()->getArrow() . ' ' .
4001  $this->context->msg( 'continue-editing' )->text() . ']]</span>';
4002  if ( $this->mTriedSave && !$this->mTokenOk ) {
4003  if ( $this->mTokenOkExceptSuffix ) {
4004  $note = $this->context->msg( 'token_suffix_mismatch' )->plain();
4005  $this->incrementEditFailureStats( 'bad_token' );
4006  } else {
4007  $note = $this->context->msg( 'session_fail_preview' )->plain();
4008  $this->incrementEditFailureStats( 'session_loss' );
4009  }
4010  } elseif ( $this->incompleteForm ) {
4011  $note = $this->context->msg( 'edit_form_incomplete' )->plain();
4012  if ( $this->mTriedSave ) {
4013  $this->incrementEditFailureStats( 'incomplete_form' );
4014  }
4015  } else {
4016  $note = $this->context->msg( 'previewnote' )->plain() . ' ' . $continueEditing;
4017  }
4018 
4019  # don't parse non-wikitext pages, show message about preview
4020  if ( $this->mTitle->isUserConfigPage() || $this->mTitle->isSiteConfigPage() ) {
4021  if ( $this->mTitle->isUserConfigPage() ) {
4022  $level = 'user';
4023  } elseif ( $this->mTitle->isSiteConfigPage() ) {
4024  $level = 'site';
4025  } else {
4026  $level = false;
4027  }
4028 
4029  if ( $content->getModel() == CONTENT_MODEL_CSS ) {
4030  $format = 'css';
4031  if ( $level === 'user' && !$config->get( 'AllowUserCss' ) ) {
4032  $format = false;
4033  }
4034  } elseif ( $content->getModel() == CONTENT_MODEL_JSON ) {
4035  $format = 'json';
4036  if ( $level === 'user' /* No comparable 'AllowUserJson' */ ) {
4037  $format = false;
4038  }
4039  } elseif ( $content->getModel() == CONTENT_MODEL_JAVASCRIPT ) {
4040  $format = 'js';
4041  if ( $level === 'user' && !$config->get( 'AllowUserJs' ) ) {
4042  $format = false;
4043  }
4044  } else {
4045  $format = false;
4046  }
4047 
4048  # Used messages to make sure grep find them:
4049  # Messages: usercsspreview, userjsonpreview, userjspreview,
4050  # sitecsspreview, sitejsonpreview, sitejspreview
4051  if ( $level && $format ) {
4052  $note = "<div id='mw-{$level}{$format}preview'>" .
4053  $this->context->msg( "{$level}{$format}preview" )->plain() .
4054  ' ' . $continueEditing . "</div>";
4055  }
4056  }
4057 
4058  # If we're adding a comment, we need to show the
4059  # summary as the headline
4060  if ( $this->section === "new" && $this->summary !== "" ) {
4061  $content = $content->addSectionHeader( $this->summary );
4062  }
4063 
4064  $hook_args = [ $this, &$content ];
4065  Hooks::run( 'EditPageGetPreviewContent', $hook_args );
4066 
4067  $parserResult = $this->doPreviewParse( $content );
4068  $parserOutput = $parserResult['parserOutput'];
4069  $previewHTML = $parserResult['html'];
4070  $this->mParserOutput = $parserOutput;
4071  $out->addParserOutputMetadata( $parserOutput );
4072  if ( $out->userCanPreview() ) {
4073  $out->addContentOverride( $this->getTitle(), $content );
4074  }
4075 
4076  if ( count( $parserOutput->getWarnings() ) ) {
4077  $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
4078  }
4079 
4080  } catch ( MWContentSerializationException $ex ) {
4081  $m = $this->context->msg(
4082  'content-failed-to-parse',
4083  $this->contentModel,
4084  $this->contentFormat,
4085  $ex->getMessage()
4086  );
4087  $note .= "\n\n" . $m->plain(); # gets parsed down below
4088  $previewHTML = '';
4089  }
4090 
4091  if ( $this->isConflict ) {
4092  $conflict = Html::rawElement(
4093  'div', [ 'id' => 'mw-previewconflict', 'class' => 'warningbox' ],
4094  $this->context->msg( 'previewconflict' )->escaped()
4095  );
4096  } else {
4097  $conflict = '';
4098  }
4099 
4100  $previewhead = Html::rawElement(
4101  'div', [ 'class' => 'previewnote' ],
4102  Html::rawElement(
4103  'h2', [ 'id' => 'mw-previewheader' ],
4104  $this->context->msg( 'preview' )->escaped()
4105  ) .
4106  Html::rawElement( 'div', [ 'class' => 'warningbox' ],
4107  $out->parseAsInterface( $note )
4108  ) . $conflict
4109  );
4110 
4111  $pageViewLang = $this->mTitle->getPageViewLanguage();
4112  $attribs = [ 'lang' => $pageViewLang->getHtmlCode(), 'dir' => $pageViewLang->getDir(),
4113  'class' => 'mw-content-' . $pageViewLang->getDir() ];
4114  $previewHTML = Html::rawElement( 'div', $attribs, $previewHTML );
4115 
4116  return $previewhead . $previewHTML . $this->previewTextAfterContent;
4117  }
4118 
4119  private function incrementEditFailureStats( $failureType ) {
4120  $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
4121  $stats->increment( 'edit.failures.' . $failureType );
4122  }
4123 
4128  protected function getPreviewParserOptions() {
4129  $parserOptions = $this->page->makeParserOptions( $this->context );
4130  $parserOptions->setIsPreview( true );
4131  $parserOptions->setIsSectionPreview( $this->section !== null && $this->section !== '' );
4132  $parserOptions->enableLimitReport();
4133 
4134  // XXX: we could call $parserOptions->setCurrentRevisionCallback here to force the
4135  // current revision to be null during PST, until setupFakeRevision is called on
4136  // the ParserOptions. Currently, we rely on Parser::getRevisionObject() to ignore
4137  // existing revisions in preview mode.
4138 
4139  return $parserOptions;
4140  }
4141 
4151  protected function doPreviewParse( Content $content ) {
4152  $user = $this->context->getUser();
4153  $parserOptions = $this->getPreviewParserOptions();
4154 
4155  // NOTE: preSaveTransform doesn't have a fake revision to operate on.
4156  // Parser::getRevisionObject() will return null in preview mode,
4157  // causing the context user to be used for {{subst:REVISIONUSER}}.
4158  // XXX: Alternatively, we could also call setupFakeRevision() a second time:
4159  // once before PST with $content, and then after PST with $pstContent.
4160  $pstContent = $content->preSaveTransform( $this->mTitle, $user, $parserOptions );
4161  $scopedCallback = $parserOptions->setupFakeRevision( $this->mTitle, $pstContent, $user );
4162  $parserOutput = $pstContent->getParserOutput( $this->mTitle, null, $parserOptions );
4163  ScopedCallback::consume( $scopedCallback );
4164  return [
4165  'parserOutput' => $parserOutput,
4166  'html' => $parserOutput->getText( [
4167  'enableSectionEditLinks' => false
4168  ] )
4169  ];
4170  }
4171 
4175  public function getTemplates() {
4176  if ( $this->preview || $this->section != '' ) {
4177  $templates = [];
4178  if ( !isset( $this->mParserOutput ) ) {
4179  return $templates;
4180  }
4181  foreach ( $this->mParserOutput->getTemplates() as $ns => $template ) {
4182  foreach ( array_keys( $template ) as $dbk ) {
4183  $templates[] = Title::makeTitle( $ns, $dbk );
4184  }
4185  }
4186  return $templates;
4187  } else {
4188  return $this->mTitle->getTemplateLinksFrom();
4189  }
4190  }
4191 
4197  public static function getEditToolbar() {
4198  $startingToolbar = '<div id="toolbar"></div>';
4199  $toolbar = $startingToolbar;
4200 
4201  if ( !Hooks::run( 'EditPageBeforeEditToolbar', [ &$toolbar ] ) ) {
4202  return null;
4203  }
4204  // Don't add a pointless `<div>` to the page unless a hook caller populated it
4205  return ( $toolbar === $startingToolbar ) ? null : $toolbar;
4206  }
4207 
4226  public function getCheckboxesDefinition( $checked ) {
4227  $checkboxes = [];
4228 
4229  $user = $this->context->getUser();
4230  // don't show the minor edit checkbox if it's a new page or section
4231  if ( !$this->isNew && $this->permManager->userHasRight( $user, 'minoredit' ) ) {
4232  $checkboxes['wpMinoredit'] = [
4233  'id' => 'wpMinoredit',
4234  'label-message' => 'minoredit',
4235  // Uses messages: tooltip-minoredit, accesskey-minoredit
4236  'tooltip' => 'minoredit',
4237  'label-id' => 'mw-editpage-minoredit',
4238  'legacy-name' => 'minor',
4239  'default' => $checked['minor'],
4240  ];
4241  }
4242 
4243  if ( $user->isLoggedIn() ) {
4244  $checkboxes['wpWatchthis'] = [
4245  'id' => 'wpWatchthis',
4246  'label-message' => 'watchthis',
4247  // Uses messages: tooltip-watch, accesskey-watch
4248  'tooltip' => 'watch',
4249  'label-id' => 'mw-editpage-watch',
4250  'legacy-name' => 'watch',
4251  'default' => $checked['watch'],
4252  ];
4253  }
4254 
4255  $editPage = $this;
4256  Hooks::run( 'EditPageGetCheckboxesDefinition', [ $editPage, &$checkboxes ] );
4257 
4258  return $checkboxes;
4259  }
4260 
4271  public function getCheckboxesWidget( &$tabindex, $checked ) {
4272  $checkboxes = [];
4273  $checkboxesDef = $this->getCheckboxesDefinition( $checked );
4274 
4275  foreach ( $checkboxesDef as $name => $options ) {
4276  $legacyName = $options['legacy-name'] ?? $name;
4277 
4278  $title = null;
4279  $accesskey = null;
4280  if ( isset( $options['tooltip'] ) ) {
4281  $accesskey = $this->context->msg( "accesskey-{$options['tooltip']}" )->text();
4282  $title = Linker::titleAttrib( $options['tooltip'] );
4283  }
4284  if ( isset( $options['title-message'] ) ) {
4285  $title = $this->context->msg( $options['title-message'] )->text();
4286  }
4287 
4288  $checkboxes[ $legacyName ] = new OOUI\FieldLayout(
4289  new OOUI\CheckboxInputWidget( [
4290  'tabIndex' => ++$tabindex,
4291  'accessKey' => $accesskey,
4292  'id' => $options['id'] . 'Widget',
4293  'inputId' => $options['id'],
4294  'name' => $name,
4295  'selected' => $options['default'],
4296  'infusable' => true,
4297  ] ),
4298  [
4299  'align' => 'inline',
4300  'label' => new OOUI\HtmlSnippet( $this->context->msg( $options['label-message'] )->parse() ),
4301  'title' => $title,
4302  'id' => $options['label-id'] ?? null,
4303  ]
4304  );
4305  }
4306 
4307  return $checkboxes;
4308  }
4309 
4316  protected function getSubmitButtonLabel() {
4317  $labelAsPublish =
4318  $this->context->getConfig()->get( 'EditSubmitButtonLabelPublish' );
4319 
4320  // Can't use $this->isNew as that's also true if we're adding a new section to an extant page
4321  $newPage = !$this->mTitle->exists();
4322 
4323  if ( $labelAsPublish ) {
4324  $buttonLabelKey = $newPage ? 'publishpage' : 'publishchanges';
4325  } else {
4326  $buttonLabelKey = $newPage ? 'savearticle' : 'savechanges';
4327  }
4328 
4329  return $buttonLabelKey;
4330  }
4331 
4340  public function getEditButtons( &$tabindex ) {
4341  $buttons = [];
4342 
4343  $labelAsPublish =
4344  $this->context->getConfig()->get( 'EditSubmitButtonLabelPublish' );
4345 
4346  $buttonLabel = $this->context->msg( $this->getSubmitButtonLabel() )->text();
4347  $buttonTooltip = $labelAsPublish ? 'publish' : 'save';
4348 
4349  $buttons['save'] = new OOUI\ButtonInputWidget( [
4350  'name' => 'wpSave',
4351  'tabIndex' => ++$tabindex,
4352  'id' => 'wpSaveWidget',
4353  'inputId' => 'wpSave',
4354  // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
4355  'useInputTag' => true,
4356  'flags' => [ 'progressive', 'primary' ],
4357  'label' => $buttonLabel,
4358  'infusable' => true,
4359  'type' => 'submit',
4360  // Messages used: tooltip-save, tooltip-publish
4361  'title' => Linker::titleAttrib( $buttonTooltip ),
4362  // Messages used: accesskey-save, accesskey-publish
4363  'accessKey' => Linker::accesskey( $buttonTooltip ),
4364  ] );
4365 
4366  $buttons['preview'] = new OOUI\ButtonInputWidget( [
4367  'name' => 'wpPreview',
4368  'tabIndex' => ++$tabindex,
4369  'id' => 'wpPreviewWidget',
4370  'inputId' => 'wpPreview',
4371  // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
4372  'useInputTag' => true,
4373  'label' => $this->context->msg( 'showpreview' )->text(),
4374  'infusable' => true,
4375  'type' => 'submit',
4376  // Message used: tooltip-preview
4377  'title' => Linker::titleAttrib( 'preview' ),
4378  // Message used: accesskey-preview
4379  'accessKey' => Linker::accesskey( 'preview' ),
4380  ] );
4381 
4382  $buttons['diff'] = new OOUI\ButtonInputWidget( [
4383  'name' => 'wpDiff',
4384  'tabIndex' => ++$tabindex,
4385  'id' => 'wpDiffWidget',
4386  'inputId' => 'wpDiff',
4387  // Support: IE 6 – Use <input>, otherwise it can't distinguish which button was clicked
4388  'useInputTag' => true,
4389  'label' => $this->context->msg( 'showdiff' )->text(),
4390  'infusable' => true,
4391  'type' => 'submit',
4392  // Message used: tooltip-diff
4393  'title' => Linker::titleAttrib( 'diff' ),
4394  // Message used: accesskey-diff
4395  'accessKey' => Linker::accesskey( 'diff' ),
4396  ] );
4397 
4398  // Avoid PHP 7.1 warning of passing $this by reference
4399  $editPage = $this;
4400  Hooks::run( 'EditPageBeforeEditButtons', [ &$editPage, &$buttons, &$tabindex ] );
4401 
4402  return $buttons;
4403  }
4404 
4409  public function noSuchSectionPage() {
4410  $out = $this->context->getOutput();
4411  $out->prepareErrorPage( $this->context->msg( 'nosuchsectiontitle' ) );
4412 
4413  $res = $this->context->msg( 'nosuchsectiontext', $this->section )->parseAsBlock();
4414 
4415  // Avoid PHP 7.1 warning of passing $this by reference
4416  $editPage = $this;
4417  Hooks::run( 'EditPageNoSuchSection', [ &$editPage, &$res ] );
4418  $out->addHTML( $res );
4419 
4420  $out->returnToMain( false, $this->mTitle );
4421  }
4422 
4428  public function spamPageWithContent( $match = false ) {
4429  $this->textbox2 = $this->textbox1;
4430 
4431  if ( is_array( $match ) ) {
4432  $match = $this->context->getLanguage()->listToText( $match );
4433  }
4434  $out = $this->context->getOutput();
4435  $out->prepareErrorPage( $this->context->msg( 'spamprotectiontitle' ) );
4436 
4437  $out->addHTML( '<div id="spamprotected">' );
4438  $out->addWikiMsg( 'spamprotectiontext' );
4439  if ( $match ) {
4440  $out->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
4441  }
4442  $out->addHTML( '</div>' );
4443 
4444  $out->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
4445  $this->showDiff();
4446 
4447  $out->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
4448  $this->showTextbox2();
4449 
4450  $out->addReturnTo( $this->getContextTitle(), [ 'action' => 'edit' ] );
4451  }
4452 
4456  protected function addEditNotices() {
4457  $out = $this->context->getOutput();
4458  $editNotices = $this->mTitle->getEditNotices( $this->oldid );
4459  if ( count( $editNotices ) ) {
4460  $out->addHTML( implode( "\n", $editNotices ) );
4461  } else {
4462  $msg = $this->context->msg( 'editnotice-notext' );
4463  if ( !$msg->isDisabled() ) {
4464  $out->addHTML(
4465  '<div class="mw-editnotice-notext">'
4466  . $msg->parseAsBlock()
4467  . '</div>'
4468  );
4469  }
4470  }
4471  }
4472 
4476  protected function addTalkPageText() {
4477  if ( $this->mTitle->isTalkPage() ) {
4478  $this->context->getOutput()->addWikiMsg( 'talkpagetext' );
4479  }
4480  }
4481 
4485  protected function addLongPageWarningHeader() {
4486  if ( $this->contentLength === false ) {
4487  $this->contentLength = strlen( $this->textbox1 );
4488  }
4489 
4490  $out = $this->context->getOutput();
4491  $lang = $this->context->getLanguage();
4492  $maxArticleSize = $this->context->getConfig()->get( 'MaxArticleSize' );
4493  if ( $this->tooBig || $this->contentLength > $maxArticleSize * 1024 ) {
4494  $out->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
4495  [
4496  'longpageerror',
4497  $lang->formatNum( round( $this->contentLength / 1024, 3 ) ),
4498  $lang->formatNum( $maxArticleSize )
4499  ]
4500  );
4501  } elseif ( !$this->context->msg( 'longpage-hint' )->isDisabled() ) {
4502  $out->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
4503  [
4504  'longpage-hint',
4505  $lang->formatSize( strlen( $this->textbox1 ) ),
4506  strlen( $this->textbox1 )
4507  ]
4508  );
4509  }
4510  }
4511 
4515  protected function addPageProtectionWarningHeaders() {
4516  $out = $this->context->getOutput();
4517  if ( $this->mTitle->isProtected( 'edit' ) &&
4518  $this->permManager->getNamespaceRestrictionLevels(
4519  $this->getTitle()->getNamespace()
4520  ) !== [ '' ]
4521  ) {
4522  # Is the title semi-protected?
4523  if ( $this->mTitle->isSemiProtected() ) {
4524  $noticeMsg = 'semiprotectedpagewarning';
4525  } else {
4526  # Then it must be protected based on static groups (regular)
4527  $noticeMsg = 'protectedpagewarning';
4528  }
4529  LogEventsList::showLogExtract( $out, 'protect', $this->mTitle, '',
4530  [ 'lim' => 1, 'msgKey' => [ $noticeMsg ] ] );
4531  }
4532  if ( $this->mTitle->isCascadeProtected() ) {
4533  # Is this page under cascading protection from some source pages?
4534 
4535  list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources();
4536  $notice = "<div class='warningbox mw-cascadeprotectedwarning'>\n$1\n";
4537  $cascadeSourcesCount = count( $cascadeSources );
4538  if ( $cascadeSourcesCount > 0 ) {
4539  # Explain, and list the titles responsible
4540  foreach ( $cascadeSources as $page ) {
4541  $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
4542  }
4543  }
4544  $notice .= '</div>';
4545  $out->wrapWikiMsg( $notice, [ 'cascadeprotectedwarning', $cascadeSourcesCount ] );
4546  }
4547  if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
4548  LogEventsList::showLogExtract( $out, 'protect', $this->mTitle, '',
4549  [ 'lim' => 1,
4550  'showIfEmpty' => false,
4551  'msgKey' => [ 'titleprotectedwarning' ],
4552  'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ] );
4553  }
4554  }
4555 
4560  protected function addExplainConflictHeader( OutputPage $out ) {
4561  $out->addHTML(
4562  $this->getEditConflictHelper()->getExplainHeader()
4563  );
4564  }
4565 
4573  protected function buildTextboxAttribs( $name, array $customAttribs, User $user ) {
4574  return ( new TextboxBuilder() )->buildTextboxAttribs(
4575  $name, $customAttribs, $user, $this->mTitle
4576  );
4577  }
4578 
4584  protected function addNewLineAtEnd( $wikitext ) {
4585  return ( new TextboxBuilder() )->addNewLineAtEnd( $wikitext );
4586  }
4587 
4598  private function guessSectionName( $text ) {
4599  // Detect Microsoft browsers
4600  $userAgent = $this->context->getRequest()->getHeader( 'User-Agent' );
4601  $parser = MediaWikiServices::getInstance()->getParser();
4602  if ( $userAgent && preg_match( '/MSIE|Edge/', $userAgent ) ) {
4603  // ...and redirect them to legacy encoding, if available
4604  return $parser->guessLegacySectionNameFromWikiText( $text );
4605  }
4606  // Meanwhile, real browsers get real anchors
4607  $name = $parser->guessSectionNameFromWikiText( $text );
4608  // With one little caveat: per T216029, fragments in HTTP redirects need to be urlencoded,
4609  // otherwise Chrome double-escapes the rest of the URL.
4610  return '#' . urlencode( mb_substr( $name, 1 ) );
4611  }
4612 
4619  public function setEditConflictHelperFactory( callable $factory ) {
4620  $this->editConflictHelperFactory = $factory;
4621  $this->editConflictHelper = null;
4622  }
4623 
4627  private function getEditConflictHelper() {
4628  if ( !$this->editConflictHelper ) {
4629  $this->editConflictHelper = call_user_func(
4630  $this->editConflictHelperFactory,
4631  $this->getSubmitButtonLabel()
4632  );
4633  }
4634 
4636  }
4637 
4643  private function newTextConflictHelper( $submitButtonLabel ) {
4644  return new TextConflictHelper(
4645  $this->getTitle(),
4646  $this->getContext()->getOutput(),
4647  MediaWikiServices::getInstance()->getStatsdDataFactory(),
4648  $submitButtonLabel,
4649  MediaWikiServices::getInstance()->getContentHandlerFactory()
4650  );
4651  }
4652 }
ReadOnlyError
Show an error when the wiki is locked/read-only and the user tries to do something that requires writ...
Definition: ReadOnlyError.php:28
EditPage\__construct
__construct(Article $article)
Definition: EditPage.php:489
EditPage\$editFormTextBeforeContent
$editFormTextBeforeContent
Definition: EditPage.php:424
EditPage\$mTriedSave
bool $mTriedSave
Definition: EditPage.php:273
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:228
EditPage\AS_SELF_REDIRECT
const AS_SELF_REDIRECT
Status: user tried to create self-redirect (redirect to the same article) and wpIgnoreSelfRedirect ==...
Definition: EditPage.php:172
EditPage\$contentModel
string $contentModel
Definition: EditPage.php:410
EditPage\showFormBeforeText
showFormBeforeText()
Definition: EditPage.php:3427
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:335
EditPage\internalAttemptSave
internalAttemptSave(&$result, $bot=false)
Attempt submission (no UI)
Definition: EditPage.php:1933
EditPage\$lastDelete
bool stdClass $lastDelete
Definition: EditPage.php:264
EditPage\tokenOk
tokenOk(&$request)
Make sure the form isn't faking a user's credentials.
Definition: EditPage.php:1599
EditPage\$editFormPageTop
string $editFormPageTop
Before even the preview.
Definition: EditPage.php:422
EditPage\AS_BLANK_ARTICLE
const AS_BLANK_ARTICLE
Status: user tried to create a blank page and wpIgnoreBlankArticle == false.
Definition: EditPage.php:119
EditPage\showContentForm
showContentForm()
Subpage overridable method for printing the form for page content editing By default this simply outp...
Definition: EditPage.php:3464
EditPage\$mTitle
Title $mTitle
Definition: EditPage.php:234
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
EditPage\spamPageWithContent
spamPageWithContent( $match=false)
Show "your edit contains spam" page with your diff and text.
Definition: EditPage.php:4428
EditPage\$section
string $section
Definition: EditPage.php:376
ParserOutput
Definition: ParserOutput.php:25
WikiPage\getRedirectTarget
getRedirectTarget()
If this page is a redirect, get its target.
Definition: WikiPage.php:1008
UserBlockedError
Show an error when the user tries to do something whilst blocked.
Definition: UserBlockedError.php:30
Revision\newFromId
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:119
EditPage\mergeChangesIntoContent
mergeChangesIntoContent(&$editContent)
Attempts to do 3-way merge of edit content with a base revision and current content,...
Definition: EditPage.php:2468
EditPage\displayPermissionsError
displayPermissionsError(array $permErrors)
Display a permissions error page, like OutputPage::showPermissionsErrorPage(), but with the following...
Definition: EditPage.php:777
EditPage\$editFormTextAfterContent
$editFormTextAfterContent
Definition: EditPage.php:428
EditPage\displayPreviewArea
displayPreviewArea( $previewOutput, $isOnTop=false)
Definition: EditPage.php:3522
EditPage\$blankArticle
bool $blankArticle
Definition: EditPage.php:291
EditPage\$allowBlankSummary
bool $allowBlankSummary
Definition: EditPage.php:288
$response
$response
Definition: opensearch_desc.php:44
$wgRightsText
$wgRightsText
If either $wgRightsUrl or $wgRightsPage is specified then this variable gives the text for the link.
Definition: DefaultSettings.php:7146
EditPage\$editFormTextBottom
$editFormTextBottom
Definition: EditPage.php:427
EditPage\getSummaryInputAttributes
getSummaryInputAttributes(array $inputAttrs=null)
Helper function for summary input functions, which returns the necessary attributes for the input.
Definition: EditPage.php:3324
EditPage\$editFormTextTop
$editFormTextTop
Definition: EditPage.php:423
EditPage\$editintro
string $editintro
Definition: EditPage.php:401
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:134
EditPage\showTextbox2
showTextbox2()
Definition: EditPage.php:3504
EDIT_FORCE_BOT
const EDIT_FORCE_BOT
Definition: Defines.php:145
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:35
EditPage\$summary
string $summary
Definition: EditPage.php:349
EditPage\AS_READ_ONLY_PAGE_ANON
const AS_READ_ONLY_PAGE_ANON
Status: this anonymous user is not allowed to edit this page.
Definition: EditPage.php:87
EditPage\buildTextboxAttribs
buildTextboxAttribs( $name, array $customAttribs, User $user)
Definition: EditPage.php:4573
EditPage\$textbox2
string $textbox2
Definition: EditPage.php:346
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:1522
EditPage\$mTokenOk
bool $mTokenOk
Definition: EditPage.php:267
EditPage\$contentHandlerFactory
IContentHandlerFactory $contentHandlerFactory
Definition: EditPage.php:479
true
return true
Definition: router.php:92
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:1873
EditPage\$oldid
int $oldid
Revision ID the edit is based on, or 0 if it's the current revision.
Definition: EditPage.php:391
MediaWiki\EditPage\TextboxBuilder
Helps EditPage build textboxes.
Definition: TextboxBuilder.php:37
EditPage\getContextTitle
getContextTitle()
Get the context title object.
Definition: EditPage.php:554
EditPage\getEditToolbar
static getEditToolbar()
Allow extensions to provide a toolbar.
Definition: EditPage.php:4197
EditPage\showTosSummary
showTosSummary()
Give a chance for site and per-namespace customizations of terms of service summary link that might e...
Definition: EditPage.php:3669
EditPage\AS_UNICODE_NOT_SUPPORTED
const AS_UNICODE_NOT_SUPPORTED
Status: edit rejected because browser doesn't support Unicode.
Definition: EditPage.php:194
CategoryPage
Definition: CategoryPage.php:30
EditPage\$page
WikiPage $page
Definition: EditPage.php:228
EditPage\$save
bool $save
Definition: EditPage.php:323
DerivativeContext\setWikiPage
setWikiPage(WikiPage $wikiPage)
Definition: DerivativeContext.php:165
EditPage\addPageProtectionWarningHeaders
addPageProtectionWarningHeaders()
Definition: EditPage.php:4515
EditPage\setContextTitle
setContextTitle( $title)
Set the context Title object.
Definition: EditPage.php:542
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:48
EditPage\edit
edit()
This is the function that gets called for "action=edit".
Definition: EditPage.php:597
EditPage\$autoSumm
string $autoSumm
Definition: EditPage.php:303
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:3915
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1171
EditPage\incrementConflictStats
incrementConflictStats()
Definition: EditPage.php:3843
EditPage\addEditNotices
addEditNotices()
Definition: EditPage.php:4456
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:208
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:537
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1265
EditPage\$editFormTextAfterTools
$editFormTextAfterTools
Definition: EditPage.php:426
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:83
EditPage\AS_HOOK_ERROR
const AS_HOOK_ERROR
Status: Article update aborted by a hook function.
Definition: EditPage.php:67
EditPage\getEditPermissionErrors
getEditPermissionErrors( $rigor=PermissionManager::RIGOR_SECURE)
Definition: EditPage.php:724
EditPage\$editFormTextAfterWarn
$editFormTextAfterWarn
Definition: EditPage.php:425
EditPage\setPreloadedContent
setPreloadedContent(Content $content)
Use this method before edit() to preload some content into the edit box.
Definition: EditPage.php:1507
EditPage\AS_CONTENT_TOO_BIG
const AS_CONTENT_TOO_BIG
Status: Content too big (> $wgMaxArticleSize)
Definition: EditPage.php:82
$wgTitle
if(isset( $_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] !='') $wgTitle
Definition: api.php:59
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition: PermissionsError.php:30
MediaWiki\EditPage\TextConflictHelper\setContentFormat
setContentFormat( $contentFormat)
Definition: TextConflictHelper.php:144
EditPage\showHeaderCopyrightWarning
showHeaderCopyrightWarning()
Show the header copyright warning.
Definition: EditPage.php:3653
EditPage\addLongPageWarningHeader
addLongPageWarningHeader()
Definition: EditPage.php:4485
EditPage\$context
IContextSource $context
Definition: EditPage.php:452
$res
$res
Definition: testCompression.php:54
EditPage\$didSave
$didSave
Definition: EditPage.php:433
EditPage\AS_BLOCKED_PAGE_FOR_USER
const AS_BLOCKED_PAGE_FOR_USER
Status: User is blocked from editing this page.
Definition: EditPage.php:77
EditPage\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: EditPage.php:130
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:108
EditPage\AS_NO_CREATE_PERMISSION
const AS_NO_CREATE_PERMISSION
Status: user tried to create this page, but is not allowed to do that ( Title->userCan('create') == f...
Definition: EditPage.php:114
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:1007
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:139
Linker\formatHiddenCategories
static formatHiddenCategories( $hiddencats)
Returns HTML for the "hidden categories on this page" list.
Definition: Linker.php:1989
EditPage\$mArticle
Article $mArticle
Definition: EditPage.php:226
EditPage\$contentFormat
null string $contentFormat
Definition: EditPage.php:413
Skin\getSkinNames
static getSkinNames()
Fetch the set of available skins.
Definition: Skin.php:57
EditPage\POST_EDIT_COOKIE_DURATION
const POST_EDIT_COOKIE_DURATION
Duration of PostEdit cookie, in seconds.
Definition: EditPage.php:220
$dbr
$dbr
Definition: testCompression.php:52
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
EditPage\$editConflictHelper
TextConflictHelper null $editConflictHelper
Definition: EditPage.php:474
Revision
Definition: Revision.php:40
EditPage\$watchthis
bool $watchthis
Definition: EditPage.php:335
EditPage\$previewTextAfterContent
$previewTextAfterContent
Definition: EditPage.php:429
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:3591
EditPage\$tooBig
bool $tooBig
Definition: EditPage.php:279
Status\getWikiText
getWikiText( $shortContext=false, $longContext=false, $lang=null)
Get the error list as a wikitext formatted list.
Definition: Status.php:185
MediaWiki\Block\DatabaseBlock
A DatabaseBlock (unlike a SystemBlock) is stored in the database, may give rise to autoblocks and may...
Definition: DatabaseBlock.php:54
StatusValue\isGood
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Definition: StatusValue.php:121
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:30
EditPage\AS_SUCCESS_NEW_ARTICLE
const AS_SUCCESS_NEW_ARTICLE
Status: Article successfully created.
Definition: EditPage.php:62
EditPage\UNICODE_CHECK
const UNICODE_CHECK
Used for Unicode support checks.
Definition: EditPage.php:52
MWException
MediaWiki exception.
Definition: MWException.php:26
EditPage\addContentModelChangeLogEntry
addContentModelChangeLogEntry(User $user, $oldModel, $newModel, $reason)
Definition: EditPage.php:2423
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:143
EditPage\toEditContent
toEditContent( $text)
Turns the given text into a Content object by unserializing it.
Definition: EditPage.php:2817
Article\getTitle
getTitle()
Get the title object of the article.
Definition: Article.php:242
EditPage\getEditButtons
getEditButtons(&$tabindex)
Returns an array of html code of the following buttons: save, diff and preview.
Definition: EditPage.php:4340
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1045
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
EditPage\AS_END
const AS_END
Status: WikiPage::doEdit() was unsuccessful.
Definition: EditPage.php:145
LogPage\DELETED_COMMENT
const DELETED_COMMENT
Definition: LogPage.php:35
EditPage\$editRevId
int $editRevId
Revision ID of the latest revision of the page when editing was initiated on the client.
Definition: EditPage.php:373
EditPage\showSummaryInput
showSummaryInput( $isSubjectPreview, $summary="")
Definition: EditPage.php:3380
EditPage\getParentRevId
getParentRevId()
Get the edit's parent revision ID.
Definition: EditPage.php:1444
ParserOptions\newFromUserAndLang
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
Definition: ParserOptions.php:1023
wfArrayDiff2
wfArrayDiff2( $a, $b)
Like array_diff( $a, $b ) except that it works with two-dimensional arrays.
Definition: GlobalFunctions.php:113
EditPage\isSectionEditSupported
isSectionEditSupported()
Returns whether section editing is supported for the current page.
Definition: EditPage.php:922
EditPage\importFormData
importFormData(&$request)
This function collects the form data and uses it to populate various member variables.
Definition: EditPage.php:933
EditPage\getActionURL
getActionURL(Title $title)
Returns the URL to use in the form's action attribute.
Definition: EditPage.php:3879
EditPage\addExplainConflictHeader
addExplainConflictHeader(OutputPage $out)
Definition: EditPage.php:4560
LogPage\DELETED_USER
const DELETED_USER
Definition: LogPage.php:36
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2564
EditPage\showIntro
showIntro()
Show all applicable editing introductions.
Definition: EditPage.php:2631
EditPage\$firsttime
bool $firsttime
True the first time the edit form is rendered, false after re-rendering with diff,...
Definition: EditPage.php:261
$matches
$matches
Definition: NoLocalSettings.php:24
StatusValue\isOK
isOK()
Returns whether the operation completed.
Definition: StatusValue.php:130
EditPage\$missingComment
bool $missingComment
Definition: EditPage.php:282
EditPage\getPreviewLimitReport
static getPreviewLimitReport(ParserOutput $output=null)
Get the Limit report for page previews.
Definition: EditPage.php:3736
EditPage\$editConflictHelperFactory
callable $editConflictHelperFactory
Factory function to create an edit conflict helper.
Definition: EditPage.php:469
$wgLang
$wgLang
Definition: Setup.php:852
MWContentSerializationException
Exception representing a failure to serialize or unserialize a content object.
Definition: MWContentSerializationException.php:7
EditPage\attemptSave
attemptSave(&$resultDetails=false)
Attempt submission.
Definition: EditPage.php:1642
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:252
Article\getContext
getContext()
Gets the context this Article is executed in.
Definition: Article.php:2295
User\isIP
static isIP( $name)
Does the string match an anonymous IP address?
Definition: User.php:948
EditPage\getArticle
getArticle()
Definition: EditPage.php:517
EditPage\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: EditPage.php:189
ThrottledError
Show an error when the user hits a rate limit.
Definition: ThrottledError.php:27
EditPage\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: EditPage.php:166
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:4271
EditPage\previewOnOpen
previewOnOpen()
Should we show a preview when the edit form is first shown?
Definition: EditPage.php:860
WatchAction\doWatchOrUnwatch
static doWatchOrUnwatch( $watch, Title $title, User $user)
Watch or unwatch a page.
Definition: WatchAction.php:91
EditPage\incrementEditFailureStats
incrementEditFailureStats( $failureType)
Definition: EditPage.php:4119
EditPage\AS_READ_ONLY_PAGE
const AS_READ_ONLY_PAGE
Status: wiki is in readonly mode (wfReadOnly() == true)
Definition: EditPage.php:97
EditPage\AS_SPAM_ERROR
const AS_SPAM_ERROR
Status: summary contained spam according to one of the regexes in $wgSummarySpamRegex.
Definition: EditPage.php:150
$title
$title
Definition: testCompression.php:36
EditPage\$allowSelfRedirect
bool $allowSelfRedirect
Definition: EditPage.php:300
EditPage\showEditForm
showEditForm( $formCallback=null)
Send the edit form and related headers to OutputPage.
Definition: EditPage.php:2840
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:602
LogEventsList\showLogExtract
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Definition: LogEventsList.php:631
EditPage\wasDeletedSinceLastEdit
wasDeletedSinceLastEdit()
Check if a page was deleted while the user was editing it, before submit.
Definition: EditPage.php:3890
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
EditPage\getTemplates
getTemplates()
Definition: EditPage.php:4175
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1902
EditPage\getPreviewParserOptions
getPreviewParserOptions()
Get parser options for a preview.
Definition: EditPage.php:4128
EditPage\runPostMergeFilters
runPostMergeFilters(Content $content, Status $status, User $user)
Run hooks that can filter edits just before they get saved.
Definition: EditPage.php:1815
EditPage\AS_MAX_ARTICLE_SIZE_EXCEEDED
const AS_MAX_ARTICLE_SIZE_EXCEEDED
Status: article is too big (> $wgMaxArticleSize), after merging in the new section.
Definition: EditPage.php:140
DB_MASTER
const DB_MASTER
Definition: defines.php:26
EditPage\$mContextTitle
null Title $mContextTitle
Definition: EditPage.php:237
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:913
EditPage\showFormAfterText
showFormAfterText()
Definition: EditPage.php:3436
EditPage\getCancelLink
getCancelLink( $tabindex=0)
Definition: EditPage.php:3851
EditPage\showPreview
showPreview( $text)
Append preview output to OutputPage.
Definition: EditPage.php:3570
EditPage\initialiseForm
initialiseForm()
Initialise form fields in the object Called on the first invocation, e.g.
Definition: EditPage.php:1162
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:136
MediaWiki\EditPage\TextConflictHelper\setTextboxes
setTextboxes( $yourtext, $storedversion)
Definition: TextConflictHelper.php:129
MediaWiki\EditPage\TextConflictHelper
Helper for displaying edit conflicts in text content models to users.
Definition: TextConflictHelper.php:45
EditPage\isPageExistingAndViewable
isPageExistingAndViewable( $title, User $user)
Verify if a given title exists and the given user is allowed to view it.
Definition: EditPage.php:1588
EditPage\matchSpamRegex
static matchSpamRegex( $text)
Check given input text against $wgSpamRegex, and return the text of the first match.
Definition: EditPage.php:2531
EditPage\$recreate
bool $recreate
Definition: EditPage.php:338
Revision\userWasLastToEdit
static userWasLastToEdit( $db, $pageId, $userId, $since)
Check if no edits were made by other users since the time a user started editing the page.
Definition: Revision.php:1110
EditPage\$contentLength
bool int $contentLength
Definition: EditPage.php:442
EditPage\AS_SUCCESS_UPDATE
const AS_SUCCESS_UPDATE
Status: Article successfully updated.
Definition: EditPage.php:57
EditPage\showTextbox1
showTextbox1( $customAttribs=null, $textoverride=null)
Method to output wpTextbox1 The $textoverride method can be used by subclasses overriding showContent...
Definition: EditPage.php:3476
EditPage\addTalkPageText
addTalkPageText()
Definition: EditPage.php:4476
MediaWiki\Permissions\PermissionManager
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
Definition: PermissionManager.php:48
$content
$content
Definition: router.php:78
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:72
EditPage\getSummaryPreview
getSummaryPreview( $isSubjectPreview, $summary="")
Definition: EditPage.php:3406
EditPage\importContentFormData
importContentFormData(&$request)
Subpage overridable method for extracting the page content data from the posted form to be placed in ...
Definition: EditPage.php:1153
EditPage\$minoredit
bool $minoredit
Definition: EditPage.php:332
EditPage\$isOldRev
bool $isOldRev
Whether an old revision is edited.
Definition: EditPage.php:457
TemplatesOnThisPageFormatter
Handles formatting for the "templates used on this page" lists.
Definition: TemplatesOnThisPageFormatter.php:31
EditPage\$enableApiEditOverride
bool $enableApiEditOverride
Set in ApiEditPage, based on ContentHandler::allowsDirectApiEditing.
Definition: EditPage.php:447
EDIT_UPDATE
const EDIT_UPDATE
Definition: Defines.php:142
EditPage\showHeader
showHeader()
Definition: EditPage.php:3145
MediaWiki\EditPage\TextConflictHelper\getEditFormHtmlAfterContent
getEditFormHtmlAfterContent()
Content to go in the edit form after textbox1.
Definition: TextConflictHelper.php:263
EditPage\getBaseRevision
getBaseRevision()
Returns the revision that was current at the time editing was initiated on the client,...
Definition: EditPage.php:2514
ContentHandler\getLocalizedName
static getLocalizedName( $name, Language $lang=null)
Returns the localized name for a given content model.
Definition: ContentHandler.php:293
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:1545
EditPage\addNewLineAtEnd
addNewLineAtEnd( $wikitext)
Definition: EditPage.php:4584
MediaWiki\Content\IContentHandlerFactory
Definition: IContentHandlerFactory.php:10
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
EditPage\incrementResolvedConflicts
incrementResolvedConflicts()
Log when a page was successfully saved after the edit conflict view.
Definition: EditPage.php:1659
StatusValue\getErrors
getErrors()
Get the list of errors.
Definition: StatusValue.php:148
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:360
EditPage\matchSummarySpamRegex
static matchSummarySpamRegex( $text)
Check given input text against $wgSummarySpamRegex, and return the text of the first match.
Definition: EditPage.php:2545
EditPage\$mTokenOkExceptSuffix
bool $mTokenOkExceptSuffix
Definition: EditPage.php:270
EditPage\showEditTools
showEditTools()
Inserts optional text shown below edit and upload forms.
Definition: EditPage.php:3684
EditPage\$preview
bool $preview
Definition: EditPage.php:326
EditPage\$isNew
bool $isNew
New page or new section.
Definition: EditPage.php:249
EditPage\getCheckboxesDefinition
getCheckboxesDefinition( $checked)
Return an array of checkbox definitions.
Definition: EditPage.php:4226
$wgSummarySpamRegex
$wgSummarySpamRegex
Same as the above except for edit summaries.
Definition: DefaultSettings.php:5593
EditPage\$mBaseRevision
Revision bool null $mBaseRevision
A revision object corresponding to $this->editRevId.
Definition: EditPage.php:315
EditPage\getCopywarn
getCopywarn()
Get the copyright warning.
Definition: EditPage.php:3696
EditPage\setApiEditOverride
setApiEditOverride( $enableOverride)
Allow editing of content that supports API direct editing, but not general direct editing.
Definition: EditPage.php:582
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1552
EditPage\AS_IMAGE_REDIRECT_LOGGED
const AS_IMAGE_REDIRECT_LOGGED
Status: logged in user is not allowed to upload (User::isAllowed('upload') == false)
Definition: EditPage.php:160
EditPage\newTextConflictHelper
newTextConflictHelper( $submitButtonLabel)
Definition: EditPage.php:4643
EditPage\showCustomIntro
showCustomIntro()
Attempt to show a custom editing introduction, if supplied.
Definition: EditPage.php:2755
EditPage\getContext
getContext()
Definition: EditPage.php:525
EditPage\AS_PARSE_ERROR
const AS_PARSE_ERROR
Status: can't parse content.
Definition: EditPage.php:183
EditPage\EDITFORM_ID
const EDITFORM_ID
HTML id and name for the beginning of the edit form.
Definition: EditPage.php:199
EditPage\extractSectionTitle
static extractSectionTitle( $text)
Extract the section title from current section text, if any.
Definition: EditPage.php:3135
EditPage\makeTemplatesOnThisPageList
makeTemplatesOnThisPageList(array $templates)
Wrapper around TemplatesOnThisPageFormatter to make a "templates on this page" list.
Definition: EditPage.php:3111
EditPage\$textbox1
string $textbox1
Page content input field.
Definition: EditPage.php:343
EditPage\$parentRevId
int $parentRevId
Revision ID the edit is based on, adjusted when an edit conflict is resolved.
Definition: EditPage.php:398
MediaWiki\EditPage\TextConflictHelper\setContentModel
setContentModel( $contentModel)
Definition: TextConflictHelper.php:137
EditPage\$undidRev
$undidRev
Definition: EditPage.php:434
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:2024
EditPage\$changeTags
null array $changeTags
Definition: EditPage.php:416
EditPage
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Definition: EditPage.php:48
EditPage\noSuchSectionPage
noSuchSectionPage()
Creates a basic error page which informs the user that they have attempted to edit a nonexistent sect...
Definition: EditPage.php:4409
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:53
EditPage\$formtype
string $formtype
Definition: EditPage.php:255
Content
Base interface for content objects.
Definition: Content.php:34
EditPage\getSummaryInputWidget
getSummaryInputWidget( $summary="", $labelText=null, $inputAttrs=null)
Builds a standard summary input with a label.
Definition: EditPage.php:3347
CommentStore\COMMENT_CHARACTER_LIMIT
const COMMENT_CHARACTER_LIMIT
Maximum length of a comment in UTF-8 characters.
Definition: CommentStore.php:37
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:312
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:528
EditPage\$mParserOutput
ParserOutput $mParserOutput
Definition: EditPage.php:309
Title
Represents a title within MediaWiki.
Definition: Title.php:42
EDIT_AUTOSUMMARY
const EDIT_AUTOSUMMARY
Definition: Defines.php:147
EditPage\$mShowSummaryField
bool $mShowSummaryField
Definition: EditPage.php:318
EditPage\$sectiontitle
string $sectiontitle
Definition: EditPage.php:379
EditPage\$starttime
string $starttime
Timestamp from the first time the edit form was rendered.
Definition: EditPage.php:384
EditPage\$suppressIntro
$suppressIntro
Definition: EditPage.php:436
ContentHandler\getContentText
static getContentText(Content $content=null)
Convenience function for getting flat text from a Content object.
Definition: ContentHandler.php:85
EditPage\$permManager
PermissionManager $permManager
Definition: EditPage.php:484
MediaWiki\EditPage\TextConflictHelper\getEditFormHtmlBeforeContent
getEditFormHtmlBeforeContent()
Content to go in the edit form before textbox1.
Definition: TextConflictHelper.php:253
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:1184
EditPage\$scrolltop
int null $scrolltop
Definition: EditPage.php:404
EditPage\formatStatusErrors
formatStatusErrors(Status $status)
Wrap status errors in an errorbox for increased visibility.
Definition: EditPage.php:1865
EditPage\$deletedSinceEdit
bool $deletedSinceEdit
Definition: EditPage.php:252
EditPage\$selfRedirect
bool $selfRedirect
Definition: EditPage.php:297
EditPage\$edit
bool $edit
Definition: EditPage.php:439
EditPage\isSupportedContentModel
isSupportedContentModel( $modelId)
Returns if the given content model is editable.
Definition: EditPage.php:571
EditPage\$mPreloadContent
$mPreloadContent
Definition: EditPage.php:430
EditPage\showConflict
showConflict()
Show an edit conflict.
Definition: EditPage.php:3832
EditPage\getSubmitButtonLabel
getSubmitButtonLabel()
Get the message key of the label for the button to save the page.
Definition: EditPage.php:4316
EditPage\$unicodeCheck
string null $unicodeCheck
What the user submitted in the 'wpUnicodeCheck' field.
Definition: EditPage.php:462
EditPage\$diff
bool $diff
Definition: EditPage.php:329
EditPage\doPreviewParse
doPreviewParse(Content $content)
Parse the page for a preview.
Definition: EditPage.php:4151
EditPage\newSectionSummary
newSectionSummary(&$sectionanchor=null)
Return the summary to be used for a new section.
Definition: EditPage.php:1885
EditPage\$action
string $action
Definition: EditPage.php:240
EditPage\setEditConflictHelperFactory
setEditConflictHelperFactory(callable $factory)
Set a factory function to create an EditConflictHelper.
Definition: EditPage.php:4619
Revision\loadFromTimestamp
static loadFromTimestamp( $db, $title, $timestamp)
Load the revision for the given title with the given timestamp.
Definition: Revision.php:296
EditPage\AS_READ_ONLY_PAGE_LOGGED
const AS_READ_ONLY_PAGE_LOGGED
Status: this logged in user is not allowed to edit this page.
Definition: EditPage.php:92
NS_USER
const NS_USER
Definition: Defines.php:71
EditPage\showTextbox
showTextbox( $text, $name, $customAttribs=[])
Definition: EditPage.php:3508
EditPage\getTitle
getTitle()
Definition: EditPage.php:533
ManualLogEntry
Class for creating new log entries and inserting them into the database.
Definition: ManualLogEntry.php:38
EditPage\AS_CONFLICT_DETECTED
const AS_CONFLICT_DETECTED
Status: (non-resolvable) edit conflict.
Definition: EditPage.php:124
EditPage\AS_RATE_LIMITED
const AS_RATE_LIMITED
Status: rate limiter for action 'edit' was tripped.
Definition: EditPage.php:102
MWUnknownContentModelException
Exception thrown when an unregistered content model is requested.
Definition: MWUnknownContentModelException.php:10
EditPage\getCurrentContent
getCurrentContent()
Get the current content of the page.
Definition: EditPage.php:1460
Title\setContentModel
setContentModel( $model)
Set a proposed content model for the page for permissions checking.
Definition: Title.php:1115
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:1066
EditPage\$isConflict
bool $isConflict
Whether an edit conflict needs to be resolved.
Definition: EditPage.php:246
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:807
EDIT_MINOR
const EDIT_MINOR
Definition: Defines.php:143
Article
Class for viewing MediaWiki article and history.
Definition: Article.php:45
EditPage\getContentObject
getContentObject( $def_content=null)
Definition: EditPage.php:1228
User\IGNORE_USER_RIGHTS
const IGNORE_USER_RIGHTS
Definition: User.php:84
EditPage\AS_IMAGE_REDIRECT_ANON
const AS_IMAGE_REDIRECT_ANON
Status: anonymous user is not allowed to upload (User::isAllowed('upload') == false)
Definition: EditPage.php:155
EditPage\showStandardInputs
showStandardInputs(&$tabindex=2)
Definition: EditPage.php:3782
MediaWiki\EditPage\TextConflictHelper\getEditConflictMainTextBox
getEditConflictMainTextBox(array $customAttribs=[])
HTML to build the textbox1 on edit conflicts.
Definition: TextConflictHelper.php:226
RawMessage
Variant of the Message class.
Definition: RawMessage.php:34
EditPage\matchSpamRegexInternal
static matchSpamRegexInternal( $text, $regexes)
Definition: EditPage.php:2556
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:27
WikiPage\isRedirect
isRedirect()
Tests if the article content represents a redirect.
Definition: WikiPage.php:643
Revision\loadFromTitle
static loadFromTitle( $db, $title, $id=0)
Load either the current, or a specified, revision that's attached to a given page.
Definition: Revision.php:278
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:205
EditPage\getOriginalContent
getOriginalContent(User $user)
Get the content of the wanted revision, without section extraction.
Definition: EditPage.php:1418
EditPage\AS_ARTICLE_WAS_DELETED
const AS_ARTICLE_WAS_DELETED
Status: article was deleted while editing and param wpRecreate == false or form was not posted.
Definition: EditPage.php:108
EditPage\setPostEditCookie
setPostEditCookie( $statusValue)
Sets post-edit cookie indicating the user just saved a particular revision.
Definition: EditPage.php:1621
Linker\accesskey
static accesskey( $name)
Given the id of an interface element, constructs the appropriate accesskey attribute from the system ...
Definition: Linker.php:2072
CommentStore\getStore
static getStore()
Definition: CommentStore.php:116
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:52
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add a callable update.
Definition: DeferredUpdates.php:125
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
EditPage\isWrongCaseUserConfigPage
isWrongCaseUserConfigPage()
Checks whether the user entered a skin name in uppercase, e.g.
Definition: EditPage.php:901
EditPage\$incompleteForm
bool $incompleteForm
Definition: EditPage.php:276
EditPage\$missingSummary
bool $missingSummary
Definition: EditPage.php:285
EditPage\getEditConflictHelper
getEditConflictHelper()
Definition: EditPage.php:4627
WikiPage\getContent
getContent( $audience=RevisionRecord::FOR_PUBLIC, User $user=null)
Get the content of the current revision.
Definition: WikiPage.php:829
WikiPage\hasDifferencesOutsideMainSlot
static hasDifferencesOutsideMainSlot(Revision $a, Revision $b)
Helper method for checking whether two revisions have differences that go beyond the main slot.
Definition: WikiPage.php:1546
EditPage\$bot
bool $bot
Definition: EditPage.php:407
EditPage\getCopyrightWarning
static getCopyrightWarning( $title, $format='plain', $langcode=null)
Get the copyright warning, by default returns wikitext.
Definition: EditPage.php:3708
EditPage\AS_HOOK_ERROR_EXPECTED
const AS_HOOK_ERROR_EXPECTED
Status: A hook function returned an error.
Definition: EditPage.php:72
$wgDisableAnonTalk
$wgDisableAnonTalk
Disable links to talk pages of anonymous users (IPs) in listings on special pages like page history,...
Definition: DefaultSettings.php:7022
Skin\makeInternalOrExternalUrl
static makeInternalOrExternalUrl( $name)
If url string starts with http, consider as external URL, else internal.
Definition: Skin.php:1223
EditPage\updateWatchlist
updateWatchlist()
Register the change of watch status.
Definition: EditPage.php:2440
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:491
EditPage\handleStatus
handleStatus(Status $status, $resultDetails)
Handle status, such as after attempt save.
Definition: EditPage.php:1676
ParserOptions\newFromUser
static newFromUser( $user)
Get a ParserOptions object from a given user.
Definition: ParserOptions.php:1010
EditPage\$hookError
string $hookError
Definition: EditPage.php:306
EditPage\$allowBlankArticle
bool $allowBlankArticle
Definition: EditPage.php:294
EditPage\toEditText
toEditText( $content)
Gets an editable textual representation of $content.
Definition: EditPage.php:2789
Xml\checkLabel
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:421
EditPage\setHeaders
setHeaders()
Definition: EditPage.php:2566
EditPage\AS_TEXTBOX_EMPTY
const AS_TEXTBOX_EMPTY
Status: user tried to create a new section without content.
Definition: EditPage.php:135
EditPage\AS_CHANGE_TAG_ERROR
const AS_CHANGE_TAG_ERROR
Status: an error relating to change tagging.
Definition: EditPage.php:178
EditPage\guessSectionName
guessSectionName( $text)
Turns section name wikitext into anchors for use in HTTP redirects.
Definition: EditPage.php:4598
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:347
$wgSpamRegex
$wgSpamRegex
Edits matching these regular expressions in body text will be recognised as spam and rejected automat...
Definition: DefaultSettings.php:5588
$type
$type
Definition: testCompression.php:50
EditPage\$nosummary
bool $nosummary
If true, hide the summary field.
Definition: EditPage.php:354
EditPage\getPreviewText
getPreviewText()
Get the rendered text for previewing.
Definition: EditPage.php:3963