3 * Contains the EditPage class
8 * The edit page/HTML interface (split from Article)
9 * The actual database and text munging is still in Article,
10 * but it should get easier to call those from alternate
13 * EditPage cares about two distinct titles:
14 * $this->mContextTitle is the page that forms submit to, links point to,
15 * redirects go to, etc. $this->mTitle (as well as $mArticle) is the
16 * page in the database that is actually being edited. These are
17 * usually the same, but they are now allowed to be different.
19 * Surgeon General's Warning: prolonged exposure to this class is known to cause
20 * headaches, which may be fatal.
23 const AS_SUCCESS_UPDATE
= 200;
24 const AS_SUCCESS_NEW_ARTICLE
= 201;
25 const AS_HOOK_ERROR
= 210;
26 const AS_FILTERING
= 211;
27 const AS_HOOK_ERROR_EXPECTED
= 212;
28 const AS_BLOCKED_PAGE_FOR_USER
= 215;
29 const AS_CONTENT_TOO_BIG
= 216;
30 const AS_USER_CANNOT_EDIT
= 217;
31 const AS_READ_ONLY_PAGE_ANON
= 218;
32 const AS_READ_ONLY_PAGE_LOGGED
= 219;
33 const AS_READ_ONLY_PAGE
= 220;
34 const AS_RATE_LIMITED
= 221;
35 const AS_ARTICLE_WAS_DELETED
= 222;
36 const AS_NO_CREATE_PERMISSION
= 223;
37 const AS_BLANK_ARTICLE
= 224;
38 const AS_CONFLICT_DETECTED
= 225;
39 const AS_SUMMARY_NEEDED
= 226;
40 const AS_TEXTBOX_EMPTY
= 228;
41 const AS_MAX_ARTICLE_SIZE_EXCEEDED
= 229;
44 const AS_SPAM_ERROR
= 232;
45 const AS_IMAGE_REDIRECT_ANON
= 233;
46 const AS_IMAGE_REDIRECT_LOGGED
= 234;
57 private $mContextTitle = null;
58 var $action = 'submit';
59 var $isConflict = false;
60 var $isCssJsSubpage = false;
61 var $isCssSubpage = false;
62 var $isJsSubpage = false;
63 var $isWrongCaseCssJsPage = false;
64 var $isNew = false; // new page or new section
65 var $deletedSinceEdit;
69 var $mTokenOk = false;
70 var $mTokenOkExceptSuffix = false;
71 var $mTriedSave = false;
72 var $incompleteForm = false;
74 var $kblength = false;
75 var $missingComment = false;
76 var $missingSummary = false;
77 var $allowBlankSummary = false;
80 #var $mPreviewTemplates;
87 var $mBaseRevision = false;
88 var $mShowSummaryField = true;
91 var $save = false, $preview = false, $diff = false;
92 var $minoredit = false, $watchthis = false, $recreate = false;
93 var $textbox1 = '', $textbox2 = '', $summary = '', $nosummary = false;
94 var $edittime = '', $section = '', $starttime = '';
95 var $oldid = 0, $editintro = '', $scrolltop = null, $bot = true;
97 # Placeholders for text injection by hooks (must be HTML)
98 # extensions should take care to _append_ to the present value
99 public $editFormPageTop = ''; // Before even the preview
100 public $editFormTextTop = '';
101 public $editFormTextBeforeContent = '';
102 public $editFormTextAfterWarn = '';
103 public $editFormTextAfterTools = '';
104 public $editFormTextBottom = '';
105 public $editFormTextAfterContent = '';
106 public $previewTextAfterContent = '';
107 public $mPreloadText = '';
109 /* $didSave should be set to true whenever an article was succesfully altered. */
110 public $didSave = false;
111 public $undidRev = 0;
113 public $suppressIntro = false;
117 * @param $article Article
119 public function __construct( $article ) {
120 $this->mArticle
= $article;
121 $this->mTitle
= $article->getTitle();
127 public function getArticle() {
128 return $this->mArticle
;
135 public function getTitle() {
136 return $this->mTitle
;
140 * Set the context Title object
142 * @param $title Title object or null
144 public function setContextTitle( $title ) {
145 $this->mContextTitle
= $title;
149 * Get the context title object.
150 * If not set, $wgTitle will be returned. This behavior might changed in
151 * the future to return $this->mTitle instead.
153 * @return Title object
155 public function getContextTitle() {
156 if ( is_null( $this->mContextTitle
) ) {
160 return $this->mContextTitle
;
165 * Fetch initial editing page content.
167 * @param $def_text string
168 * @return mixed string on success, $def_text for invalid sections
171 function getContent( $def_text = '' ) {
172 global $wgOut, $wgRequest, $wgParser;
174 wfProfileIn( __METHOD__
);
175 # Get variables from query string :P
176 $section = $wgRequest->getVal( 'section' );
178 $preload = $wgRequest->getVal( 'preload',
179 // Custom preload text for new sections
180 $section === 'new' ?
'MediaWiki:addsection-preload' : '' );
181 $undoafter = $wgRequest->getVal( 'undoafter' );
182 $undo = $wgRequest->getVal( 'undo' );
184 // For message page not locally set, use the i18n message.
185 // For other non-existent articles, use preload text if any.
186 if ( !$this->mTitle
->exists() ) {
187 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
188 # If this is a system message, get the default text.
189 $text = $this->mTitle
->getDefaultMessageText();
190 if( $text === false ) {
191 $text = $this->getPreloadedText( $preload );
194 # If requested, preload some text.
195 $text = $this->getPreloadedText( $preload );
197 // For existing pages, get text based on "undo" or section parameters.
199 $text = $this->mArticle
->getContent();
200 if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
201 # If they got undoafter and undo round the wrong way, switch them
202 list( $undo, $undoafter ) = array( $undoafter, $undo );
204 if ( $undo > 0 && $undo > $undoafter ) {
205 # Undoing a specific edit overrides section editing; section-editing
206 # doesn't work with undoing.
208 $undorev = Revision
::newFromId( $undo );
209 $oldrev = Revision
::newFromId( $undoafter );
211 $undorev = Revision
::newFromId( $undo );
212 $oldrev = $undorev ?
$undorev->getPrevious() : null;
215 # Sanity check, make sure it's the right page,
216 # the revisions exist and they were not deleted.
217 # Otherwise, $text will be left as-is.
218 if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
219 $undorev->getPage() == $oldrev->getPage() &&
220 $undorev->getPage() == $this->mArticle
->getID() &&
221 !$undorev->isDeleted( Revision
::DELETED_TEXT
) &&
222 !$oldrev->isDeleted( Revision
::DELETED_TEXT
) ) {
224 $undotext = $this->mArticle
->getUndoText( $undorev, $oldrev );
225 if ( $undotext === false ) {
226 # Warn the user that something went wrong
227 $this->editFormPageTop
.= $wgOut->parse( '<div class="error mw-undo-failure">' .
228 wfMsgNoTrans( 'undo-failure' ) . '</div>', true, /* interface */true );
231 # Inform the user of our success and set an automatic edit summary
232 $this->editFormPageTop
.= $wgOut->parse( '<div class="mw-undo-success">' .
233 wfMsgNoTrans( 'undo-success' ) . '</div>', true, /* interface */true );
234 $firstrev = $oldrev->getNext();
235 # If we just undid one rev, use an autosummary
236 if ( $firstrev->getId() == $undo ) {
237 $undoSummary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
238 if ( $this->summary
=== '' ) {
239 $this->summary
= $undoSummary;
241 $this->summary
= $undoSummary . wfMsgForContent( 'colon-separator' ) . $this->summary
;
243 $this->undidRev
= $undo;
245 $this->formtype
= 'diff';
248 // Failed basic sanity checks.
249 // Older revisions may have been removed since the link
250 // was created, or we may simply have got bogus input.
251 $this->editFormPageTop
.= $wgOut->parse( '<div class="error mw-undo-norev">' .
252 wfMsgNoTrans( 'undo-norev' ) . '</div>', true, /* interface */true );
254 } elseif ( $section != '' ) {
255 if ( $section == 'new' ) {
256 $text = $this->getPreloadedText( $preload );
258 // Get section edit text (returns $def_text for invalid sections)
259 $text = $wgParser->getSection( $text, $section, $def_text );
264 wfProfileOut( __METHOD__
);
269 * Use this method before edit() to preload some text into the edit box
271 * @param $text string
273 public function setPreloadedText( $text ) {
274 $this->mPreloadText
= $text;
278 * Get the contents to be preloaded into the box, either set by
279 * an earlier setPreloadText() or by loading the given page.
281 * @param $preload String: representing the title to preload from.
284 protected function getPreloadedText( $preload ) {
285 global $wgUser, $wgParser;
286 if ( !empty( $this->mPreloadText
) ) {
287 return $this->mPreloadText
;
288 } elseif ( $preload !== '' ) {
289 $title = Title
::newFromText( $preload );
290 # Check for existence to avoid getting MediaWiki:Noarticletext
291 if ( isset( $title ) && $title->exists() && $title->userCanRead() ) {
292 $article = new Article( $title );
294 if ( $article->isRedirect() ) {
295 $title = Title
::newFromRedirectRecurse( $article->getContent() );
296 # Redirects to missing titles are displayed, to hidden pages are followed
297 # Copying observed behaviour from ?action=view
298 if ( $title->exists() ) {
299 if ($title->userCanRead() ) {
300 $article = new Article( $title );
306 $parserOptions = ParserOptions
::newFromUser( $wgUser );
307 return $wgParser->getPreloadText( $article->getContent(), $title, $parserOptions );
314 * Check if a page was deleted while the user was editing it, before submit.
315 * Note that we rely on the logging table, which hasn't been always there,
316 * but that doesn't matter, because this only applies to brand new
319 protected function wasDeletedSinceLastEdit() {
320 if ( $this->deletedSinceEdit
!== null ) {
321 return $this->deletedSinceEdit
;
324 $this->deletedSinceEdit
= false;
326 if ( $this->mTitle
->isDeletedQuick() ) {
327 $this->lastDelete
= $this->getLastDelete();
328 if ( $this->lastDelete
) {
329 $deleteTime = wfTimestamp( TS_MW
, $this->lastDelete
->log_timestamp
);
330 if ( $deleteTime > $this->starttime
) {
331 $this->deletedSinceEdit
= true;
336 return $this->deletedSinceEdit
;
340 * Checks whether the user entered a skin name in uppercase,
341 * e.g. "User:Example/Monobook.css" instead of "monobook.css"
345 protected function isWrongCaseCssJsPage() {
346 if( $this->mTitle
->isCssJsSubpage() ) {
347 $name = $this->mTitle
->getSkinFromCssJsSubpage();
348 $skins = array_merge(
349 array_keys( Skin
::getSkinNames() ),
352 return !in_array( $name, $skins )
353 && in_array( strtolower( $name ), $skins );
364 * This is the function that gets called for "action=edit". It
365 * sets up various member variables, then passes execution to
366 * another function, usually showEditForm()
368 * The edit form is self-submitting, so that when things like
369 * preview and edit conflicts occur, we get the same form back
370 * with the extra stuff added. Only when the final submission
371 * is made and all is well do we actually save and redirect to
372 * the newly-edited page.
375 global $wgOut, $wgRequest, $wgUser;
376 // Allow extensions to modify/prevent this form or submission
377 if ( !wfRunHooks( 'AlternateEdit', array( $this ) ) ) {
381 wfProfileIn( __METHOD__
);
382 wfDebug( __METHOD__
.": enter\n" );
384 // If they used redlink=1 and the page exists, redirect to the main article
385 if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle
->exists() ) {
386 $wgOut->redirect( $this->mTitle
->getFullURL() );
387 wfProfileOut( __METHOD__
);
391 $this->importFormData( $wgRequest );
392 $this->firsttime
= false;
395 $this->livePreview();
396 wfProfileOut( __METHOD__
);
400 if ( wfReadOnly() && $this->save
) {
403 $this->preview
= true;
406 $wgOut->addModules( array( 'mediawiki.action.edit' ) );
408 if ( $wgUser->getOption( 'uselivepreview', false ) ) {
409 $wgOut->addModules( 'mediawiki.legacy.preview' );
411 // Bug #19334: textarea jumps when editing articles in IE8
412 $wgOut->addStyle( 'common/IE80Fixes.css', 'screen', 'IE 8' );
414 $permErrors = $this->getEditPermissionErrors();
416 // Auto-block user's IP if the account was "hard" blocked
417 $wgUser->spreadAnyEditBlock();
419 wfDebug( __METHOD__
. ": User can't edit\n" );
420 $content = $this->getContent( null );
421 $content = $content === '' ?
null : $content;
422 $this->readOnlyPage( $content, true, $permErrors, 'edit' );
423 wfProfileOut( __METHOD__
);
428 $this->formtype
= 'save';
429 } elseif ( $this->preview
) {
430 $this->formtype
= 'preview';
431 } elseif ( $this->diff
) {
432 $this->formtype
= 'diff';
433 } else { # First time through
434 $this->firsttime
= true;
435 if ( $this->previewOnOpen() ) {
436 $this->formtype
= 'preview';
438 $this->formtype
= 'initial';
442 wfProfileIn( __METHOD__
."-business-end" );
444 $this->isConflict
= false;
445 // css / js subpages of user pages get a special treatment
446 $this->isCssJsSubpage
= $this->mTitle
->isCssJsSubpage();
447 $this->isCssSubpage
= $this->mTitle
->isCssSubpage();
448 $this->isJsSubpage
= $this->mTitle
->isJsSubpage();
449 $this->isWrongCaseCssJsPage
= $this->isWrongCaseCssJsPage();
450 $this->isNew
= !$this->mTitle
->exists() ||
$this->section
== 'new';
452 # Show applicable editing introductions
453 if ( $this->formtype
== 'initial' ||
$this->firsttime
)
456 if ( $this->mTitle
->isTalkPage() ) {
457 $wgOut->addWikiMsg( 'talkpagetext' );
460 # Optional notices on a per-namespace and per-page basis
461 $editnotice_ns = 'editnotice-'.$this->mTitle
->getNamespace();
462 $editnotice_ns_message = wfMessage( $editnotice_ns )->inContentLanguage();
463 if ( $editnotice_ns_message->exists() ) {
464 $wgOut->addWikiText( $editnotice_ns_message->plain() );
466 if ( MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
467 $parts = explode( '/', $this->mTitle
->getDBkey() );
468 $editnotice_base = $editnotice_ns;
469 while ( count( $parts ) > 0 ) {
470 $editnotice_base .= '-'.array_shift( $parts );
471 $editnotice_base_msg = wfMessage( $editnotice_base )->inContentLanguage();
472 if ( $editnotice_base_msg->exists() ) {
473 $wgOut->addWikiText( $editnotice_base_msg->plain() );
477 # Even if there are no subpages in namespace, we still don't want / in MW ns.
478 $editnoticeText = $editnotice_ns . '-' . str_replace( '/', '-', $this->mTitle
->getDBkey() );
479 $editnoticeMsg = wfMessage( $editnoticeText )->inContentLanguage();
480 if ( $editnoticeMsg->exists() ) {
481 $wgOut->addWikiText( $editnoticeMsg->plain() );
485 # Attempt submission here. This will check for edit conflicts,
486 # and redundantly check for locked database, blocked IPs, etc.
487 # that edit() already checked just in case someone tries to sneak
488 # in the back door with a hand-edited submission URL.
490 if ( 'save' == $this->formtype
) {
491 if ( !$this->attemptSave() ) {
492 wfProfileOut( __METHOD__
."-business-end" );
493 wfProfileOut( __METHOD__
);
498 # First time through: get contents, set time for conflict
500 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
501 if ( $this->initialiseForm() === false ) {
502 $this->noSuchSectionPage();
503 wfProfileOut( __METHOD__
."-business-end" );
504 wfProfileOut( __METHOD__
);
507 if ( !$this->mTitle
->getArticleId() )
508 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1
, &$this->mTitle
) );
510 wfRunHooks( 'EditFormInitialText', array( $this ) );
513 $this->showEditForm();
514 wfProfileOut( __METHOD__
."-business-end" );
515 wfProfileOut( __METHOD__
);
521 protected function getEditPermissionErrors() {
523 $permErrors = $this->mTitle
->getUserPermissionsErrors( 'edit', $wgUser );
524 # Can this title be created?
525 if ( !$this->mTitle
->exists() ) {
526 $permErrors = array_merge( $permErrors,
527 wfArrayDiff2( $this->mTitle
->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) );
529 # Ignore some permissions errors when a user is just previewing/viewing diffs
531 foreach( $permErrors as $error ) {
532 if ( ( $this->preview ||
$this->diff
) &&
533 ( $error[0] == 'blockedtext' ||
$error[0] == 'autoblockedtext' ) )
538 $permErrors = wfArrayDiff2( $permErrors, $remove );
543 * Show a read-only error
544 * Parameters are the same as OutputPage:readOnlyPage()
545 * Redirect to the article page if redlink=1
547 function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
548 global $wgRequest, $wgOut;
549 if ( $wgRequest->getBool( 'redlink' ) ) {
550 // The edit page was reached via a red link.
551 // Redirect to the article page and let them click the edit tab if
552 // they really want a permission error.
553 $wgOut->redirect( $this->mTitle
->getFullUrl() );
555 $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
560 * Should we show a preview when the edit form is first shown?
564 protected function previewOnOpen() {
565 global $wgRequest, $wgUser, $wgPreviewOnOpenNamespaces;
566 if ( $wgRequest->getVal( 'preview' ) == 'yes' ) {
567 // Explicit override from request
569 } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) {
570 // Explicit override from request
572 } elseif ( $this->section
== 'new' ) {
573 // Nothing *to* preview for new sections
575 } elseif ( ( $wgRequest->getVal( 'preload' ) !== null ||
$this->mTitle
->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
576 // Standard preference behaviour
578 } elseif ( !$this->mTitle
->exists() &&
579 isset($wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()]) &&
580 $wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()] )
582 // Categories are special
590 * Does this EditPage class support section editing?
591 * This is used by EditPage subclasses to indicate their ui cannot handle section edits
595 protected function isSectionEditSupported() {
600 * Returns the URL to use in the form's action attribute.
601 * This is used by EditPage subclasses when simply customizing the action
602 * variable in the constructor is not enough. This can be used when the
603 * EditPage lives inside of a Special page rather than a custom page action.
605 * @param $title Title object for which is being edited (where we go to for &action= links)
608 protected function getActionURL( Title
$title ) {
609 return $title->getLocalURL( array( 'action' => $this->action
) );
614 * @param $request WebRequest
616 function importFormData( &$request ) {
617 global $wgLang, $wgUser;
619 wfProfileIn( __METHOD__
);
621 # Section edit can come from either the form or a link
622 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
624 if ( $request->wasPosted() ) {
625 # These fields need to be checked for encoding.
626 # Also remove trailing whitespace, but don't remove _initial_
627 # whitespace from the text boxes. This may be significant formatting.
628 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
629 if ( !$request->getCheck('wpTextbox2') ) {
630 // Skip this if wpTextbox2 has input, it indicates that we came
631 // from a conflict page with raw page text, not a custom form
632 // modified by subclasses
633 wfProfileIn( get_class($this)."::importContentFormData" );
634 $textbox1 = $this->importContentFormData( $request );
635 if ( isset($textbox1) )
636 $this->textbox1
= $textbox1;
637 wfProfileOut( get_class($this)."::importContentFormData" );
640 # Truncate for whole multibyte characters. +5 bytes for ellipsis
641 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
643 # Remove extra headings from summaries and new sections.
644 $this->summary
= preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary
);
646 $this->edittime
= $request->getVal( 'wpEdittime' );
647 $this->starttime
= $request->getVal( 'wpStarttime' );
649 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
651 if ($this->textbox1
=== '' && $request->getVal( 'wpTextbox1' ) === null) {
652 // wpTextbox1 field is missing, possibly due to being "too big"
653 // according to some filter rules such as Suhosin's setting for
654 // suhosin.request.max_value_length (d'oh)
655 $this->incompleteForm
= true;
657 // edittime should be one of our last fields; if it's missing,
658 // the submission probably broke somewhere in the middle.
659 $this->incompleteForm
= is_null( $this->edittime
);
661 if ( $this->incompleteForm
) {
662 # If the form is incomplete, force to preview.
663 wfDebug( __METHOD__
. ": Form data appears to be incomplete\n" );
664 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
665 $this->preview
= true;
667 /* Fallback for live preview */
668 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
669 $this->diff
= $request->getCheck( 'wpDiff' );
671 // Remember whether a save was requested, so we can indicate
672 // if we forced preview due to session failure.
673 $this->mTriedSave
= !$this->preview
;
675 if ( $this->tokenOk( $request ) ) {
676 # Some browsers will not report any submit button
677 # if the user hits enter in the comment box.
678 # The unmarked state will be assumed to be a save,
679 # if the form seems otherwise complete.
680 wfDebug( __METHOD__
. ": Passed token check.\n" );
681 } elseif ( $this->diff
) {
682 # Failed token check, but only requested "Show Changes".
683 wfDebug( __METHOD__
. ": Failed token check; Show Changes requested.\n" );
685 # Page might be a hack attempt posted from
686 # an external site. Preview instead of saving.
687 wfDebug( __METHOD__
. ": Failed token check; forcing preview\n" );
688 $this->preview
= true;
691 $this->save
= !$this->preview
&& !$this->diff
;
692 if ( !preg_match( '/^\d{14}$/', $this->edittime
) ) {
693 $this->edittime
= null;
696 if ( !preg_match( '/^\d{14}$/', $this->starttime
) ) {
697 $this->starttime
= null;
700 $this->recreate
= $request->getCheck( 'wpRecreate' );
702 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
703 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
705 # Don't force edit summaries when a user is editing their own user or talk page
706 if ( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) &&
707 $this->mTitle
->getText() == $wgUser->getName() )
709 $this->allowBlankSummary
= true;
711 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' ) ||
!$wgUser->getOption( 'forceeditsummary');
714 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
716 # Not a posted form? Start with nothing.
717 wfDebug( __METHOD__
. ": Not a posted form.\n" );
718 $this->textbox1
= '';
720 $this->edittime
= '';
721 $this->starttime
= wfTimestampNow();
723 $this->preview
= false;
726 $this->minoredit
= false;
727 $this->watchthis
= $request->getBool( 'watchthis', false ); // Watch may be overriden by request parameters
728 $this->recreate
= false;
730 if ( $this->section
== 'new' && $request->getVal( 'preloadtitle' ) ) {
731 $this->summary
= $request->getVal( 'preloadtitle' );
733 elseif ( $this->section
!= 'new' && $request->getVal( 'summary' ) ) {
734 $this->summary
= $request->getText( 'summary' );
737 if ( $request->getVal( 'minor' ) ) {
738 $this->minoredit
= true;
742 $this->bot
= $request->getBool( 'bot', true );
743 $this->nosummary
= $request->getBool( 'nosummary' );
745 // @todo FIXME: Unused variable?
746 $this->oldid
= $request->getInt( 'oldid' );
748 $this->live
= $request->getCheck( 'live' );
749 $this->editintro
= $request->getText( 'editintro',
750 // Custom edit intro for new sections
751 $this->section
=== 'new' ?
'MediaWiki:addsection-editintro' : '' );
753 // Allow extensions to modify form data
754 wfRunHooks( 'EditPage::importFormData', array( $this, $request ) );
756 wfProfileOut( __METHOD__
);
760 * Subpage overridable method for extracting the page content data from the
761 * posted form to be placed in $this->textbox1, if using customized input
762 * this method should be overrided and return the page text that will be used
763 * for saving, preview parsing and so on...
765 * @param $request WebRequest
767 protected function importContentFormData( &$request ) {
768 return; // Don't do anything, EditPage already extracted wpTextbox1
772 * Make sure the form isn't faking a user's credentials.
774 * @param $request WebRequest
778 function tokenOk( &$request ) {
780 $token = $request->getVal( 'wpEditToken' );
781 $this->mTokenOk
= $wgUser->matchEditToken( $token );
782 $this->mTokenOkExceptSuffix
= $wgUser->matchEditTokenNoSuffix( $token );
783 return $this->mTokenOk
;
787 * Show all applicable editing introductions
789 protected function showIntro() {
790 global $wgOut, $wgUser;
791 if ( $this->suppressIntro
) {
795 $namespace = $this->mTitle
->getNamespace();
797 if ( $namespace == NS_MEDIAWIKI
) {
798 # Show a warning if editing an interface message
799 $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1\n</div>", 'editinginterface' );
802 # Show a warning message when someone creates/edits a user (talk) page but the user does not exist
803 # Show log extract when the user is currently blocked
804 if ( $namespace == NS_USER ||
$namespace == NS_USER_TALK
) {
805 $parts = explode( '/', $this->mTitle
->getText(), 2 );
806 $username = $parts[0];
807 $user = User
::newFromName( $username, false /* allow IP users*/ );
808 $ip = User
::isIP( $username );
809 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
810 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
811 array( 'userpage-userdoesnotexist', wfEscapeWikiText( $username ) ) );
812 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
813 LogEventsList
::showLogExtract(
816 $user->getUserPage(),
820 'showIfEmpty' => false,
822 'blocked-notice-logextract',
823 $user->getName() # Support GENDER in notice
829 # Try to add a custom edit intro, or use the standard one if this is not possible.
830 if ( !$this->showCustomIntro() && !$this->mTitle
->exists() ) {
831 if ( $wgUser->isLoggedIn() ) {
832 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletext\">\n$1\n</div>", 'newarticletext' );
834 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletextanon\">\n$1\n</div>", 'newarticletextanon' );
837 # Give a notice if the user is editing a deleted/moved page...
838 if ( !$this->mTitle
->exists() ) {
839 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle
,
840 '', array( 'lim' => 10,
841 'conds' => array( "log_action != 'revision'" ),
842 'showIfEmpty' => false,
843 'msgKey' => array( 'recreate-moveddeleted-warn') )
849 * Attempt to show a custom editing introduction, if supplied
853 protected function showCustomIntro() {
854 if ( $this->editintro
) {
855 $title = Title
::newFromText( $this->editintro
);
856 if ( $title instanceof Title
&& $title->exists() && $title->userCanRead() ) {
858 // Added using template syntax, to take <noinclude>'s into account.
859 $wgOut->addWikiTextTitleTidy( '{{:' . $title->getFullText() . '}}', $this->mTitle
);
870 * Attempt submission (no UI)
875 * @return Status object, possibly with a message, but always with one of the AS_* constants in $status->value,
877 * FIXME: This interface is TERRIBLE, but hard to get rid of due to various error display idiosyncrasies. There are
878 * also lots of cases where error metadata is set in the object and retrieved later instead of being returned, e.g.
879 * AS_CONTENT_TOO_BIG and AS_BLOCKED_PAGE_FOR_USER. All that stuff needs to be cleaned up some time.
881 function internalAttemptSave( &$result, $bot = false ) {
882 global $wgFilterCallback, $wgUser, $wgRequest, $wgParser;
883 global $wgMaxArticleSize;
885 $status = Status
::newGood();
887 wfProfileIn( __METHOD__
);
888 wfProfileIn( __METHOD__
. '-checks' );
890 if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) ) {
891 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
892 $status->fatal( 'hookaborted' );
893 $status->value
= self
::AS_HOOK_ERROR
;
894 wfProfileOut( __METHOD__
. '-checks' );
895 wfProfileOut( __METHOD__
);
899 # Check image redirect
900 if ( $this->mTitle
->getNamespace() == NS_FILE
&&
901 Title
::newFromRedirect( $this->textbox1
) instanceof Title
&&
902 !$wgUser->isAllowed( 'upload' ) ) {
903 $code = $wgUser->isAnon() ? self
::AS_IMAGE_REDIRECT_ANON
: self
::AS_IMAGE_REDIRECT_LOGGED
;
904 $status->setResult( false, $code );
906 wfProfileOut( __METHOD__
. '-checks' );
907 wfProfileOut( __METHOD__
);
913 $match = self
::matchSummarySpamRegex( $this->summary
);
914 if ( $match === false ) {
915 $match = self
::matchSpamRegex( $this->textbox1
);
917 if ( $match !== false ) {
918 $result['spam'] = $match;
919 $ip = $wgRequest->getIP();
920 $pdbk = $this->mTitle
->getPrefixedDBkey();
921 $match = str_replace( "\n", '', $match );
922 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
923 $status->fatal( 'spamprotectionmatch', $match );
924 $status->value
= self
::AS_SPAM_ERROR
;
925 wfProfileOut( __METHOD__
. '-checks' );
926 wfProfileOut( __METHOD__
);
929 if ( $wgFilterCallback && is_callable( $wgFilterCallback ) && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
, $this->hookError
, $this->summary
) ) {
930 # Error messages or other handling should be performed by the filter function
931 $status->setResult( false, self
::AS_FILTERING
);
932 wfProfileOut( __METHOD__
. '-checks' );
933 wfProfileOut( __METHOD__
);
936 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1
, $this->section
, &$this->hookError
, $this->summary
) ) ) {
937 # Error messages etc. could be handled within the hook...
938 $status->fatal( 'hookaborted' );
939 $status->value
= self
::AS_HOOK_ERROR
;
940 wfProfileOut( __METHOD__
. '-checks' );
941 wfProfileOut( __METHOD__
);
943 } elseif ( $this->hookError
!= '' ) {
944 # ...or the hook could be expecting us to produce an error
945 $status->fatal( 'hookaborted' );
946 $status->value
= self
::AS_HOOK_ERROR_EXPECTED
;
947 wfProfileOut( __METHOD__
. '-checks' );
948 wfProfileOut( __METHOD__
);
952 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
953 // Auto-block user's IP if the account was "hard" blocked
954 $wgUser->spreadAnyEditBlock();
955 # Check block state against master, thus 'false'.
956 $status->setResult( false, self
::AS_BLOCKED_PAGE_FOR_USER
);
957 wfProfileOut( __METHOD__
. '-checks' );
958 wfProfileOut( __METHOD__
);
962 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
963 if ( $this->kblength
> $wgMaxArticleSize ) {
964 // Error will be displayed by showEditForm()
965 $this->tooBig
= true;
966 $status->setResult( false, self
::AS_CONTENT_TOO_BIG
);
967 wfProfileOut( __METHOD__
. '-checks' );
968 wfProfileOut( __METHOD__
);
972 if ( !$wgUser->isAllowed( 'edit' ) ) {
973 if ( $wgUser->isAnon() ) {
974 $status->setResult( false, self
::AS_READ_ONLY_PAGE_ANON
);
975 wfProfileOut( __METHOD__
. '-checks' );
976 wfProfileOut( __METHOD__
);
979 $status->fatal( 'readonlytext' );
980 $status->value
= self
::AS_READ_ONLY_PAGE_LOGGED
;
981 wfProfileOut( __METHOD__
. '-checks' );
982 wfProfileOut( __METHOD__
);
987 if ( wfReadOnly() ) {
988 $status->fatal( 'readonlytext' );
989 $status->value
= self
::AS_READ_ONLY_PAGE
;
990 wfProfileOut( __METHOD__
. '-checks' );
991 wfProfileOut( __METHOD__
);
994 if ( $wgUser->pingLimiter() ) {
995 $status->fatal( 'actionthrottledtext' );
996 $status->value
= self
::AS_RATE_LIMITED
;
997 wfProfileOut( __METHOD__
. '-checks' );
998 wfProfileOut( __METHOD__
);
1002 # If the article has been deleted while editing, don't save it without
1004 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate
) {
1005 $status->setResult( false, self
::AS_ARTICLE_WAS_DELETED
);
1006 wfProfileOut( __METHOD__
. '-checks' );
1007 wfProfileOut( __METHOD__
);
1011 wfProfileOut( __METHOD__
. '-checks' );
1013 # If article is new, insert it.
1014 $aid = $this->mTitle
->getArticleID( Title
::GAID_FOR_UPDATE
);
1015 $new = ( $aid == 0 );
1018 // Late check for create permission, just in case *PARANOIA*
1019 if ( !$this->mTitle
->userCan( 'create' ) ) {
1020 $status->fatal( 'nocreatetext' );
1021 $status->value
= self
::AS_NO_CREATE_PERMISSION
;
1022 wfDebug( __METHOD__
. ": no create permission\n" );
1023 wfProfileOut( __METHOD__
);
1027 # Don't save a new article if it's blank.
1028 if ( $this->textbox1
== '' ) {
1029 $status->setResult( false, self
::AS_BLANK_ARTICLE
);
1030 wfProfileOut( __METHOD__
);
1034 // Run post-section-merge edit filter
1035 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1
, &$this->hookError
, $this->summary
) ) ) {
1036 # Error messages etc. could be handled within the hook...
1037 $status->fatal( 'hookaborted' );
1038 $status->value
= self
::AS_HOOK_ERROR
;
1039 wfProfileOut( __METHOD__
);
1041 } elseif ( $this->hookError
!= '' ) {
1042 # ...or the hook could be expecting us to produce an error
1043 $status->fatal( 'hookaborted' );
1044 $status->value
= self
::AS_HOOK_ERROR_EXPECTED
;
1045 wfProfileOut( __METHOD__
);
1049 # Handle the user preference to force summaries here. Check if it's not a redirect.
1050 if ( !$this->allowBlankSummary
&& !Title
::newFromRedirect( $this->textbox1
) ) {
1051 if ( md5( $this->summary
) == $this->autoSumm
) {
1052 $this->missingSummary
= true;
1053 $status->fatal( 'missingsummary' ); // or 'missingcommentheader' if $section == 'new'. Blegh
1054 $status->value
= self
::AS_SUMMARY_NEEDED
;
1055 wfProfileOut( __METHOD__
);
1060 $text = $this->textbox1
;
1061 if ( $this->section
== 'new' && $this->summary
!= '' ) {
1062 $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary
) . "\n\n" . $text;
1065 $status->value
= self
::AS_SUCCESS_NEW_ARTICLE
;
1069 # Article exists. Check for edit conflict.
1071 $this->mArticle
->clear(); # Force reload of dates, etc.
1073 wfDebug( "timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n" );
1075 if ( $this->mArticle
->getTimestamp() != $this->edittime
) {
1076 $this->isConflict
= true;
1077 if ( $this->section
== 'new' ) {
1078 if ( $this->mArticle
->getUserText() == $wgUser->getName() &&
1079 $this->mArticle
->getComment() == $this->summary
) {
1080 // Probably a duplicate submission of a new comment.
1081 // This can happen when squid resends a request after
1082 // a timeout but the first one actually went through.
1083 wfDebug( __METHOD__
. ": duplicate new section submission; trigger edit conflict!\n" );
1085 // New comment; suppress conflict.
1086 $this->isConflict
= false;
1087 wfDebug( __METHOD__
.": conflict suppressed; new section\n" );
1089 } elseif ( $this->section
== '' && $this->userWasLastToEdit( $wgUser->getId(), $this->edittime
) ) {
1090 # Suppress edit conflict with self, except for section edits where merging is required.
1091 wfDebug( __METHOD__
. ": Suppressing edit conflict, same user.\n" );
1092 $this->isConflict
= false;
1096 if ( $this->isConflict
) {
1097 wfDebug( __METHOD__
. ": conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
1098 $this->mArticle
->getTimestamp() . "')\n" );
1099 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1101 wfDebug( __METHOD__
. ": getting section '$this->section'\n" );
1102 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
1104 if ( is_null( $text ) ) {
1105 wfDebug( __METHOD__
. ": activating conflict; section replace failed.\n" );
1106 $this->isConflict
= true;
1107 $text = $this->textbox1
; // do not try to merge here!
1108 } elseif ( $this->isConflict
) {
1110 if ( $this->mergeChangesInto( $text ) ) {
1111 // Successful merge! Maybe we should tell the user the good news?
1112 $this->isConflict
= false;
1113 wfDebug( __METHOD__
. ": Suppressing edit conflict, successful merge.\n" );
1115 $this->section
= '';
1116 $this->textbox1
= $text;
1117 wfDebug( __METHOD__
. ": Keeping edit conflict, failed merge.\n" );
1121 if ( $this->isConflict
) {
1122 $status->setResult( false, self
::AS_CONFLICT_DETECTED
);
1123 wfProfileOut( __METHOD__
);
1127 // Run post-section-merge edit filter
1128 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError
, $this->summary
) ) ) {
1129 # Error messages etc. could be handled within the hook...
1130 $status->fatal( 'hookaborted' );
1131 $status->value
= self
::AS_HOOK_ERROR
;
1132 wfProfileOut( __METHOD__
);
1134 } elseif ( $this->hookError
!= '' ) {
1135 # ...or the hook could be expecting us to produce an error
1136 $status->fatal( 'hookaborted' );
1137 $status->value
= self
::AS_HOOK_ERROR_EXPECTED
;
1138 wfProfileOut( __METHOD__
);
1142 # Handle the user preference to force summaries here, but not for null edits
1143 if ( $this->section
!= 'new' && !$this->allowBlankSummary
1144 && 0 != strcmp( $this->mArticle
->getContent(), $text )
1145 && !Title
::newFromRedirect( $text ) ) # check if it's not a redirect
1147 if ( md5( $this->summary
) == $this->autoSumm
) {
1148 $this->missingSummary
= true;
1149 $status->fatal( 'missingsummary' );
1150 $status->value
= self
::AS_SUMMARY_NEEDED
;
1151 wfProfileOut( __METHOD__
);
1156 # And a similar thing for new sections
1157 if ( $this->section
== 'new' && !$this->allowBlankSummary
) {
1158 if ( trim( $this->summary
) == '' ) {
1159 $this->missingSummary
= true;
1160 $status->fatal( 'missingsummary' ); // or 'missingcommentheader' if $section == 'new'. Blegh
1161 $status->value
= self
::AS_SUMMARY_NEEDED
;
1162 wfProfileOut( __METHOD__
);
1168 wfProfileIn( __METHOD__
. '-sectionanchor' );
1169 $sectionanchor = '';
1170 if ( $this->section
== 'new' ) {
1171 if ( $this->textbox1
== '' ) {
1172 $this->missingComment
= true;
1173 $status->fatal( 'missingcommenttext' );
1174 $status->value
= self
::AS_TEXTBOX_EMPTY
;
1175 wfProfileOut( __METHOD__
. '-sectionanchor' );
1176 wfProfileOut( __METHOD__
);
1179 if ( $this->summary
!= '' ) {
1180 $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->summary
);
1181 # This is a new section, so create a link to the new section
1182 # in the revision summary.
1183 $cleanSummary = $wgParser->stripSectionName( $this->summary
);
1184 $this->summary
= wfMsgForContent( 'newsectionsummary', $cleanSummary );
1186 } elseif ( $this->section
!= '' ) {
1187 # Try to get a section anchor from the section source, redirect to edited section if header found
1188 # XXX: might be better to integrate this into Article::replaceSection
1189 # for duplicate heading checking and maybe parsing
1190 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
1191 # we can't deal with anchors, includes, html etc in the header for now,
1192 # headline would need to be parsed to improve this
1193 if ( $hasmatch && strlen( $matches[2] ) > 0 ) {
1194 $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $matches[2] );
1197 $result['sectionanchor'] = $sectionanchor;
1198 wfProfileOut( __METHOD__
. '-sectionanchor' );
1200 // Save errors may fall down to the edit form, but we've now
1201 // merged the section into full text. Clear the section field
1202 // so that later submission of conflict forms won't try to
1203 // replace that into a duplicated mess.
1204 $this->textbox1
= $text;
1205 $this->section
= '';
1207 $status->value
= self
::AS_SUCCESS_UPDATE
;
1210 // Check for length errors again now that the section is merged in
1211 $this->kblength
= (int)( strlen( $text ) / 1024 );
1212 if ( $this->kblength
> $wgMaxArticleSize ) {
1213 $this->tooBig
= true;
1214 $status->setResult( false, self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
);
1215 wfProfileOut( __METHOD__
);
1219 $flags = EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
1220 ( $new ? EDIT_NEW
: EDIT_UPDATE
) |
1221 ( ( $this->minoredit
&& !$this->isNew
) ? EDIT_MINOR
: 0 ) |
1222 ( $bot ? EDIT_FORCE_BOT
: 0 );
1224 $doEditStatus = $this->mArticle
->doEdit( $text, $this->summary
, $flags );
1226 if ( $doEditStatus->isOK() ) {
1227 $result['redirect'] = Title
::newFromRedirect( $text ) !== null;
1228 $this->commitWatch();
1229 wfProfileOut( __METHOD__
);
1232 $this->isConflict
= true;
1233 $doEditStatus->value
= self
::AS_END
; // Destroys data doEdit() put in $status->value but who cares
1234 wfProfileOut( __METHOD__
);
1235 return $doEditStatus;
1240 * Commit the change of watch status
1242 protected function commitWatch() {
1244 if ( $this->watchthis
xor $this->mTitle
->userIsWatching() ) {
1245 $dbw = wfGetDB( DB_MASTER
);
1247 if ( $this->watchthis
) {
1248 WatchAction
::doWatch( $this->mTitle
, $wgUser );
1250 WatchAction
::doUnwatch( $this->mTitle
, $wgUser );
1257 * Check if no edits were made by other users since
1258 * the time a user started editing the page. Limit to
1259 * 50 revisions for the sake of performance.
1262 * @param $edittime string
1266 protected function userWasLastToEdit( $id, $edittime ) {
1267 if( !$id ) return false;
1268 $dbw = wfGetDB( DB_MASTER
);
1269 $res = $dbw->select( 'revision',
1272 'rev_page' => $this->mArticle
->getId(),
1273 'rev_timestamp > '.$dbw->addQuotes( $dbw->timestamp($edittime) )
1276 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
1277 foreach ( $res as $row ) {
1278 if( $row->rev_user
!= $id ) {
1286 * Check given input text against $wgSpamRegex, and return the text of the first match.
1288 * @param $text string
1290 * @return string|false matching string or false
1292 public static function matchSpamRegex( $text ) {
1293 global $wgSpamRegex;
1294 // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
1295 $regexes = (array)$wgSpamRegex;
1296 return self
::matchSpamRegexInternal( $text, $regexes );
1300 * Check given input text against $wgSpamRegex, and return the text of the first match.
1302 * @parma $text string
1304 * @return string|false matching string or false
1306 public static function matchSummarySpamRegex( $text ) {
1307 global $wgSummarySpamRegex;
1308 $regexes = (array)$wgSummarySpamRegex;
1309 return self
::matchSpamRegexInternal( $text, $regexes );
1313 * @param $text string
1314 * @param $regexes array
1315 * @return bool|string
1317 protected static function matchSpamRegexInternal( $text, $regexes ) {
1318 foreach( $regexes as $regex ) {
1320 if( preg_match( $regex, $text, $matches ) ) {
1328 * Initialise form fields in the object
1329 * Called on the first invocation, e.g. when a user clicks an edit link
1330 * @return bool -- if the requested section is valid
1332 function initialiseForm() {
1334 $this->edittime
= $this->mArticle
->getTimestamp();
1335 $this->textbox1
= $this->getContent( false );
1336 // activate checkboxes if user wants them to be always active
1337 # Sort out the "watch" checkbox
1338 if ( $wgUser->getOption( 'watchdefault' ) ) {
1340 $this->watchthis
= true;
1341 } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
1343 $this->watchthis
= true;
1344 } elseif ( $this->mTitle
->userIsWatching() ) {
1346 $this->watchthis
= true;
1348 if ( $wgUser->getOption( 'minordefault' ) && !$this->isNew
) {
1349 $this->minoredit
= true;
1351 if ( $this->textbox1
=== false ) {
1358 function setHeaders() {
1360 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1361 if ( $this->isConflict
) {
1362 $wgOut->setPageTitle( wfMessage( 'editconflict', $this->getContextTitle()->getPrefixedText() ) );
1363 } elseif ( $this->section
!= '' ) {
1364 $msg = $this->section
== 'new' ?
'editingcomment' : 'editingsection';
1365 $wgOut->setPageTitle( wfMessage( $msg, $this->getContextTitle()->getPrefixedText() ) );
1367 # Use the title defined by DISPLAYTITLE magic word when present
1368 if ( isset( $this->mParserOutput
)
1369 && ( $dt = $this->mParserOutput
->getDisplayTitle() ) !== false ) {
1372 $title = $this->getContextTitle()->getPrefixedText();
1374 $wgOut->setPageTitle( wfMessage( 'editing', $title ) );
1379 * Send the edit form and related headers to $wgOut
1380 * @param $formCallback Callback that takes an OutputPage parameter; will be called
1381 * during form output near the top, for captchas and the like.
1383 function showEditForm( $formCallback = null ) {
1384 global $wgOut, $wgUser;
1386 wfProfileIn( __METHOD__
);
1388 #need to parse the preview early so that we know which templates are used,
1389 #otherwise users with "show preview after edit box" will get a blank list
1390 #we parse this near the beginning so that setHeaders can do the title
1391 #setting work instead of leaving it in getPreviewText
1392 $previewOutput = '';
1393 if ( $this->formtype
== 'preview' ) {
1394 $previewOutput = $this->getPreviewText();
1397 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) );
1399 $this->setHeaders();
1401 # Enabled article-related sidebar, toplinks, etc.
1402 $wgOut->setArticleRelated( true );
1404 if ( $this->showHeader() === false ) {
1405 wfProfileOut( __METHOD__
);
1409 $action = htmlspecialchars( $this->getActionURL( $this->getContextTitle() ) );
1411 if ( $wgUser->getOption( 'showtoolbar' ) and !$this->isCssJsSubpage
) {
1412 # prepare toolbar for edit buttons
1413 $toolbar = EditPage
::getEditToolbar();
1419 $wgOut->addHTML( $this->editFormPageTop
);
1421 if ( $wgUser->getOption( 'previewontop' ) ) {
1422 $this->displayPreviewArea( $previewOutput, true );
1425 $wgOut->addHTML( $this->editFormTextTop
);
1427 $templates = $this->getTemplates();
1428 $formattedtemplates = Linker
::formatTemplates( $templates, $this->preview
, $this->section
!= '');
1430 $hiddencats = $this->mArticle
->getHiddenCategories();
1431 $formattedhiddencats = Linker
::formatHiddenCategories( $hiddencats );
1433 if ( $this->wasDeletedSinceLastEdit() && 'save' != $this->formtype
) {
1434 $wgOut->wrapWikiMsg(
1435 "<div class='error mw-deleted-while-editing'>\n$1\n</div>",
1436 'deletedwhileediting' );
1437 } elseif ( $this->wasDeletedSinceLastEdit() ) {
1438 // Hide the toolbar and edit area, user can click preview to get it back
1439 // Add an confirmation checkbox and explanation.
1441 // @todo move this to a cleaner conditional instead of blanking a variable
1443 $wgOut->addHTML( <<<HTML
1444 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1448 if ( is_callable( $formCallback ) ) {
1449 call_user_func_array( $formCallback, array( &$wgOut ) );
1452 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1454 // Put these up at the top to ensure they aren't lost on early form submission
1455 $this->showFormBeforeText();
1457 if ( $this->wasDeletedSinceLastEdit() && 'save' == $this->formtype
) {
1458 $username = $this->lastDelete
->user_name
;
1459 $comment = $this->lastDelete
->log_comment
;
1461 // It is better to not parse the comment at all than to have templates expanded in the middle
1462 // TODO: can the checkLabel be moved outside of the div so that wrapWikiMsg could be used?
1463 $key = $comment === ''
1464 ?
'confirmrecreate-noreason'
1465 : 'confirmrecreate';
1467 '<div class="mw-confirm-recreate">' .
1468 wfMsgExt( $key, 'parseinline', $username, "<nowiki>$comment</nowiki>" ) .
1469 Xml
::checkLabel( wfMsg( 'recreate' ), 'wpRecreate', 'wpRecreate', false,
1470 array( 'title' => Linker
::titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' )
1476 # If a blank edit summary was previously provided, and the appropriate
1477 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1478 # user being bounced back more than once in the event that a summary
1481 # For a bit more sophisticated detection of blank summaries, hash the
1482 # automatic one and pass that in the hidden field wpAutoSummary.
1483 if ( $this->missingSummary ||
1484 ( $this->section
== 'new' && $this->nosummary
) )
1485 $wgOut->addHTML( Html
::hidden( 'wpIgnoreBlankSummary', true ) );
1486 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
1487 $wgOut->addHTML( Html
::hidden( 'wpAutoSummary', $autosumm ) );
1489 $wgOut->addHTML( Html
::hidden( 'oldid', $this->mArticle
->getOldID() ) );
1491 if ( $this->section
== 'new' ) {
1492 $this->showSummaryInput( true, $this->summary
);
1493 $wgOut->addHTML( $this->getSummaryPreview( true, $this->summary
) );
1496 $wgOut->addHTML( $this->editFormTextBeforeContent
);
1498 $wgOut->addHTML( $toolbar );
1500 if ( $this->isConflict
) {
1501 // In an edit conflict bypass the overrideable content form method
1502 // and fallback to the raw wpTextbox1 since editconflicts can't be
1503 // resolved between page source edits and custom ui edits using the
1505 $this->showTextbox1( null, $this->getContent() );
1507 $this->showContentForm();
1510 $wgOut->addHTML( $this->editFormTextAfterContent
);
1512 $wgOut->addWikiText( $this->getCopywarn() );
1513 if ( isset($this->editFormTextAfterWarn
) && $this->editFormTextAfterWarn
!== '' )
1514 $wgOut->addHTML( $this->editFormTextAfterWarn
);
1516 $this->showStandardInputs();
1518 $this->showFormAfterText();
1520 $this->showTosSummary();
1521 $this->showEditTools();
1523 $wgOut->addHTML( <<<HTML
1524 {$this->editFormTextAfterTools}
1525 <div class='templatesUsed'>
1526 {$formattedtemplates}
1528 <div class='hiddencats'>
1529 {$formattedhiddencats}
1534 if ( $this->isConflict
)
1535 $this->showConflict();
1537 $wgOut->addHTML( $this->editFormTextBottom
);
1538 $wgOut->addHTML( "</form>\n" );
1539 if ( !$wgUser->getOption( 'previewontop' ) ) {
1540 $this->displayPreviewArea( $previewOutput, false );
1543 wfProfileOut( __METHOD__
);
1546 protected function showHeader() {
1547 global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang;
1548 if ( $this->isConflict
) {
1549 $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
1550 $this->edittime
= $this->mArticle
->getTimestamp();
1552 if ( $this->section
!= '' && !$this->isSectionEditSupported() ) {
1553 // We use $this->section to much before this and getVal('wgSection') directly in other places
1554 // at this point we can't reset $this->section to '' to fallback to non-section editing.
1555 // Someone is welcome to try refactoring though
1556 $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
1560 if ( $this->section
!= '' && $this->section
!= 'new' ) {
1562 if ( !$this->summary
&& !$this->preview
&& !$this->diff
) {
1563 preg_match( "/^(=+)(.+)\\1/mi", $this->textbox1
, $matches );
1564 if ( !empty( $matches[2] ) ) {
1566 $this->summary
= "/* " .
1567 $wgParser->stripSectionName(trim($matches[2])) .
1573 if ( $this->missingComment
) {
1574 $wgOut->wrapWikiMsg( "<div id='mw-missingcommenttext'>\n$1\n</div>", 'missingcommenttext' );
1577 if ( $this->missingSummary
&& $this->section
!= 'new' ) {
1578 $wgOut->wrapWikiMsg( "<div id='mw-missingsummary'>\n$1\n</div>", 'missingsummary' );
1581 if ( $this->missingSummary
&& $this->section
== 'new' ) {
1582 $wgOut->wrapWikiMsg( "<div id='mw-missingcommentheader'>\n$1\n</div>", 'missingcommentheader' );
1585 if ( $this->hookError
!== '' ) {
1586 $wgOut->addWikiText( $this->hookError
);
1589 if ( !$this->checkUnicodeCompliantBrowser() ) {
1590 $wgOut->addWikiMsg( 'nonunicodebrowser' );
1593 if ( isset( $this->mArticle
) && isset( $this->mArticle
->mRevision
) ) {
1594 // Let sysop know that this will make private content public if saved
1596 if ( !$this->mArticle
->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1597 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-permission' );
1598 } elseif ( $this->mArticle
->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1599 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-view' );
1602 if ( !$this->mArticle
->mRevision
->isCurrent() ) {
1603 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
1604 $wgOut->addWikiMsg( 'editingold' );
1609 if ( wfReadOnly() ) {
1610 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
1611 } elseif ( $wgUser->isAnon() ) {
1612 if ( $this->formtype
!= 'preview' ) {
1613 $wgOut->wrapWikiMsg( "<div id=\"mw-anon-edit-warning\">\n$1</div>", 'anoneditwarning' );
1615 $wgOut->wrapWikiMsg( "<div id=\"mw-anon-preview-warning\">\n$1</div>", 'anonpreviewwarning' );
1618 if ( $this->isCssJsSubpage
) {
1619 # Check the skin exists
1620 if ( $this->isWrongCaseCssJsPage
) {
1621 $wgOut->wrapWikiMsg( "<div class='error' id='mw-userinvalidcssjstitle'>\n$1\n</div>", array( 'userinvalidcssjstitle', $this->mTitle
->getSkinFromCssJsSubpage() ) );
1623 if ( $this->formtype
!== 'preview' ) {
1624 if ( $this->isCssSubpage
)
1625 $wgOut->wrapWikiMsg( "<div id='mw-usercssyoucanpreview'>\n$1\n</div>", array( 'usercssyoucanpreview' ) );
1626 if ( $this->isJsSubpage
)
1627 $wgOut->wrapWikiMsg( "<div id='mw-userjsyoucanpreview'>\n$1\n</div>", array( 'userjsyoucanpreview' ) );
1632 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
1633 # Is the title semi-protected?
1634 if ( $this->mTitle
->isSemiProtected() ) {
1635 $noticeMsg = 'semiprotectedpagewarning';
1637 # Then it must be protected based on static groups (regular)
1638 $noticeMsg = 'protectedpagewarning';
1640 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
, '',
1641 array( 'lim' => 1, 'msgKey' => array( $noticeMsg ) ) );
1643 if ( $this->mTitle
->isCascadeProtected() ) {
1644 # Is this page under cascading protection from some source pages?
1645 list($cascadeSources, /* $restrictions */) = $this->mTitle
->getCascadeProtectionSources();
1646 $notice = "<div class='mw-cascadeprotectedwarning'>\n$1\n";
1647 $cascadeSourcesCount = count( $cascadeSources );
1648 if ( $cascadeSourcesCount > 0 ) {
1649 # Explain, and list the titles responsible
1650 foreach( $cascadeSources as $page ) {
1651 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1654 $notice .= '</div>';
1655 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', $cascadeSourcesCount ) );
1657 if ( !$this->mTitle
->exists() && $this->mTitle
->getRestrictions( 'create' ) ) {
1658 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
, '',
1660 'showIfEmpty' => false,
1661 'msgKey' => array( 'titleprotectedwarning' ),
1662 'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ) );
1665 if ( $this->kblength
=== false ) {
1666 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
1669 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
1670 $wgOut->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
1671 array( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgLang->formatNum( $wgMaxArticleSize ) ) );
1673 if( !wfMessage('longpage-hint')->isDisabled() ) {
1674 $wgOut->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
1675 array( 'longpage-hint', $wgLang->formatSize( strlen( $this->textbox1
) ), strlen( $this->textbox1
) )
1682 * Standard summary input and label (wgSummary), abstracted so EditPage
1683 * subclasses may reorganize the form.
1684 * Note that you do not need to worry about the label's for=, it will be
1685 * inferred by the id given to the input. You can remove them both by
1686 * passing array( 'id' => false ) to $userInputAttrs.
1688 * @param $summary string The value of the summary input
1689 * @param $labelText string The html to place inside the label
1690 * @param $inputAttrs array of attrs to use on the input
1691 * @param $spanLabelAttrs array of attrs to use on the span inside the label
1693 * @return array An array in the format array( $label, $input )
1695 function getSummaryInput($summary = "", $labelText = null, $inputAttrs = null, $spanLabelAttrs = null) {
1696 //Note: the maxlength is overriden in JS to 250 and to make it use UTF-8 bytes, not characters.
1697 $inputAttrs = ( is_array($inputAttrs) ?
$inputAttrs : array() ) +
array(
1698 'id' => 'wpSummary',
1699 'maxlength' => '200',
1702 'spellcheck' => 'true',
1703 ) + Linker
::tooltipAndAccesskeyAttribs( 'summary' );
1705 $spanLabelAttrs = ( is_array($spanLabelAttrs) ?
$spanLabelAttrs : array() ) +
array(
1706 'class' => $this->missingSummary ?
'mw-summarymissed' : 'mw-summary',
1707 'id' => "wpSummaryLabel"
1712 $label = Xml
::tags( 'label', $inputAttrs['id'] ?
array( 'for' => $inputAttrs['id'] ) : null, $labelText );
1713 $label = Xml
::tags( 'span', $spanLabelAttrs, $label );
1716 $input = Html
::input( 'wpSummary', $summary, 'text', $inputAttrs );
1718 return array( $label, $input );
1722 * @param $isSubjectPreview Boolean: true if this is the section subject/title
1723 * up top, or false if this is the comment summary
1724 * down below the textarea
1725 * @param $summary String: The text of the summary to display
1728 protected function showSummaryInput( $isSubjectPreview, $summary = "" ) {
1729 global $wgOut, $wgContLang;
1730 # Add a class if 'missingsummary' is triggered to allow styling of the summary line
1731 $summaryClass = $this->missingSummary ?
'mw-summarymissed' : 'mw-summary';
1732 if ( $isSubjectPreview ) {
1733 if ( $this->nosummary
) {
1737 if ( !$this->mShowSummaryField
) {
1741 $summary = $wgContLang->recodeForEdit( $summary );
1742 $labelText = wfMsgExt( $isSubjectPreview ?
'subject' : 'summary', 'parseinline' );
1743 list($label, $input) = $this->getSummaryInput($summary, $labelText, array( 'class' => $summaryClass ), array());
1744 $wgOut->addHTML("{$label} {$input}");
1748 * @param $isSubjectPreview Boolean: true if this is the section subject/title
1749 * up top, or false if this is the comment summary
1750 * down below the textarea
1751 * @param $summary String: the text of the summary to display
1754 protected function getSummaryPreview( $isSubjectPreview, $summary = "" ) {
1755 if ( !$summary ||
( !$this->preview
&& !$this->diff
) )
1760 if ( $isSubjectPreview )
1761 $summary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $summary ) );
1763 $message = $isSubjectPreview ?
'subject-preview' : 'summary-preview';
1765 $summary = wfMsgExt( $message, 'parseinline' ) . Linker
::commentBlock( $summary, $this->mTitle
, $isSubjectPreview );
1766 return Xml
::tags( 'div', array( 'class' => 'mw-summary-preview' ), $summary );
1769 protected function showFormBeforeText() {
1771 $section = htmlspecialchars( $this->section
);
1772 $wgOut->addHTML( <<<HTML
1773 <input type='hidden' value="{$section}" name="wpSection" />
1774 <input type='hidden' value="{$this->starttime}" name="wpStarttime" />
1775 <input type='hidden' value="{$this->edittime}" name="wpEdittime" />
1776 <input type='hidden' value="{$this->scrolltop}" name="wpScrolltop" id="wpScrolltop" />
1780 if ( !$this->checkUnicodeCompliantBrowser() )
1781 $wgOut->addHTML(Html
::hidden( 'safemode', '1' ));
1784 protected function showFormAfterText() {
1785 global $wgOut, $wgUser;
1787 * To make it harder for someone to slip a user a page
1788 * which submits an edit form to the wiki without their
1789 * knowledge, a random token is associated with the login
1790 * session. If it's not passed back with the submission,
1791 * we won't save the page, or render user JavaScript and
1794 * For anon editors, who may not have a session, we just
1795 * include the constant suffix to prevent editing from
1796 * broken text-mangling proxies.
1798 $wgOut->addHTML( "\n" . Html
::hidden( "wpEditToken", $wgUser->editToken() ) . "\n" );
1802 * Subpage overridable method for printing the form for page content editing
1803 * By default this simply outputs wpTextbox1
1804 * Subclasses can override this to provide a custom UI for editing;
1805 * be it a form, or simply wpTextbox1 with a modified content that will be
1806 * reverse modified when extracted from the post data.
1807 * Note that this is basically the inverse for importContentFormData
1809 protected function showContentForm() {
1810 $this->showTextbox1();
1814 * Method to output wpTextbox1
1815 * The $textoverride method can be used by subclasses overriding showContentForm
1816 * to pass back to this method.
1818 * @param $customAttribs An array of html attributes to use in the textarea
1819 * @param $textoverride String: optional text to override $this->textarea1 with
1821 protected function showTextbox1($customAttribs = null, $textoverride = null) {
1822 $classes = array(); // Textarea CSS
1823 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
1824 # Is the title semi-protected?
1825 if ( $this->mTitle
->isSemiProtected() ) {
1826 $classes[] = 'mw-textarea-sprotected';
1828 # Then it must be protected based on static groups (regular)
1829 $classes[] = 'mw-textarea-protected';
1831 # Is the title cascade-protected?
1832 if ( $this->mTitle
->isCascadeProtected() ) {
1833 $classes[] = 'mw-textarea-cprotected';
1836 $attribs = array( 'tabindex' => 1 );
1837 if ( is_array($customAttribs) )
1838 $attribs +
= $customAttribs;
1840 if ( $this->wasDeletedSinceLastEdit() )
1841 $attribs['type'] = 'hidden';
1842 if ( !empty( $classes ) ) {
1843 if ( isset($attribs['class']) )
1844 $classes[] = $attribs['class'];
1845 $attribs['class'] = implode( ' ', $classes );
1848 $this->showTextbox( isset($textoverride) ?
$textoverride : $this->textbox1
, 'wpTextbox1', $attribs );
1851 protected function showTextbox2() {
1852 $this->showTextbox( $this->textbox2
, 'wpTextbox2', array( 'tabindex' => 6, 'readonly' ) );
1855 protected function showTextbox( $content, $name, $customAttribs = array() ) {
1856 global $wgOut, $wgUser;
1858 $wikitext = $this->safeUnicodeOutput( $content );
1859 if ( strval($wikitext) !== '' ) {
1860 // Ensure there's a newline at the end, otherwise adding lines
1862 // But don't add a newline if the ext is empty, or Firefox in XHTML
1863 // mode will show an extra newline. A bit annoying.
1867 $attribs = $customAttribs +
array(
1870 'cols' => $wgUser->getIntOption( 'cols' ),
1871 'rows' => $wgUser->getIntOption( 'rows' ),
1872 'style' => '' // avoid php notices when appending preferences (appending allows customAttribs['style'] to still work
1875 $pageLang = $this->mTitle
->getPageLanguage();
1876 $attribs['lang'] = $pageLang->getCode();
1877 $attribs['dir'] = $pageLang->getDir();
1879 $wgOut->addHTML( Html
::textarea( $name, $wikitext, $attribs ) );
1882 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
1886 $classes[] = 'ontop';
1888 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
1890 if ( $this->formtype
!= 'preview' )
1891 $attribs['style'] = 'display: none;';
1893 $wgOut->addHTML( Xml
::openElement( 'div', $attribs ) );
1895 if ( $this->formtype
== 'preview' ) {
1896 $this->showPreview( $previewOutput );
1899 $wgOut->addHTML( '</div>' );
1901 if ( $this->formtype
== 'diff') {
1907 * Append preview output to $wgOut.
1908 * Includes category rendering if this is a category page.
1910 * @param $text String: the HTML to be output for the preview.
1912 protected function showPreview( $text ) {
1914 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1915 $this->mArticle
->openShowCategory();
1917 # This hook seems slightly odd here, but makes things more
1918 # consistent for extensions.
1919 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1920 $wgOut->addHTML( $text );
1921 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1922 $this->mArticle
->closeShowCategory();
1927 * Give a chance for site and per-namespace customizations of
1928 * terms of service summary link that might exist separately
1929 * from the copyright notice.
1931 * This will display between the save button and the edit tools,
1932 * so should remain short!
1934 protected function showTosSummary() {
1935 $msg = 'editpage-tos-summary';
1936 wfRunHooks( 'EditPageTosSummary', array( $this->mTitle
, &$msg ) );
1937 if( !wfMessage( $msg )->isDisabled() ) {
1939 $wgOut->addHTML( '<div class="mw-tos-summary">' );
1940 $wgOut->addWikiMsg( $msg );
1941 $wgOut->addHTML( '</div>' );
1945 protected function showEditTools() {
1947 $wgOut->addHTML( '<div class="mw-editTools">' .
1948 wfMessage( 'edittools' )->inContentLanguage()->parse() .
1952 protected function getCopywarn() {
1953 global $wgRightsText;
1954 if ( $wgRightsText ) {
1955 $copywarnMsg = array( 'copyrightwarning',
1956 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1959 $copywarnMsg = array( 'copyrightwarning2',
1960 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
1962 // Allow for site and per-namespace customization of contribution/copyright notice.
1963 wfRunHooks( 'EditPageCopyrightWarning', array( $this->mTitle
, &$copywarnMsg ) );
1965 return "<div id=\"editpage-copywarn\">\n" .
1966 call_user_func_array("wfMsgNoTrans", $copywarnMsg) . "\n</div>";
1969 protected function showStandardInputs( &$tabindex = 2 ) {
1971 $wgOut->addHTML( "<div class='editOptions'>\n" );
1973 if ( $this->section
!= 'new' ) {
1974 $this->showSummaryInput( false, $this->summary
);
1975 $wgOut->addHTML( $this->getSummaryPreview( false, $this->summary
) );
1978 $checkboxes = $this->getCheckboxes( $tabindex,
1979 array( 'minor' => $this->minoredit
, 'watch' => $this->watchthis
) );
1980 $wgOut->addHTML( "<div class='editCheckboxes'>" . implode( $checkboxes, "\n" ) . "</div>\n" );
1981 $wgOut->addHTML( "<div class='editButtons'>\n" );
1982 $wgOut->addHTML( implode( $this->getEditButtons( $tabindex ), "\n" ) . "\n" );
1984 $cancel = $this->getCancelLink();
1985 if ( $cancel !== '' ) {
1986 $cancel .= wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1988 $edithelpurl = Skin
::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ) );
1989 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1990 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1991 htmlspecialchars( wfMsg( 'newwindow' ) );
1992 $wgOut->addHTML( " <span class='editHelp'>{$cancel}{$edithelp}</span>\n" );
1993 $wgOut->addHTML( "</div><!-- editButtons -->\n</div><!-- editOptions -->\n" );
1997 * Show an edit conflict. textbox1 is already shown in showEditForm().
1998 * If you want to use another entry point to this function, be careful.
2000 protected function showConflict() {
2002 $this->textbox2
= $this->textbox1
;
2003 $this->textbox1
= $this->getContent();
2004 if ( wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
2005 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
2007 $de = new DifferenceEngine( $this->mTitle
);
2008 $de->setText( $this->textbox2
, $this->textbox1
);
2009 $de->showDiff( wfMsgExt( 'yourtext', 'parseinline' ), wfMsg( 'storedversion' ) );
2011 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
2012 $this->showTextbox2();
2016 protected function getLastDelete() {
2017 $dbr = wfGetDB( DB_SLAVE
);
2018 $data = $dbr->selectRow(
2019 array( 'logging', 'user' ),
2030 array( 'log_namespace' => $this->mTitle
->getNamespace(),
2031 'log_title' => $this->mTitle
->getDBkey(),
2032 'log_type' => 'delete',
2033 'log_action' => 'delete',
2034 'user_id=log_user' ),
2036 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' )
2038 // Quick paranoid permission checks...
2039 if( is_object( $data ) ) {
2040 if( $data->log_deleted
& LogPage
::DELETED_USER
)
2041 $data->user_name
= wfMsgHtml( 'rev-deleted-user' );
2042 if( $data->log_deleted
& LogPage
::DELETED_COMMENT
)
2043 $data->log_comment
= wfMsgHtml( 'rev-deleted-comment' );
2049 * Get the rendered text for previewing.
2052 function getPreviewText() {
2053 global $wgOut, $wgUser, $wgParser;
2055 wfProfileIn( __METHOD__
);
2057 if ( $this->mTriedSave
&& !$this->mTokenOk
) {
2058 if ( $this->mTokenOkExceptSuffix
) {
2059 $note = wfMsg( 'token_suffix_mismatch' );
2061 $note = wfMsg( 'session_fail_preview' );
2063 } elseif ( $this->incompleteForm
) {
2064 $note = wfMsg( 'edit_form_incomplete' );
2066 $note = wfMsg( 'previewnote' );
2069 $parserOptions = ParserOptions
::newFromUser( $wgUser );
2070 $parserOptions->setEditSection( false );
2071 $parserOptions->setIsPreview( true );
2072 $parserOptions->setIsSectionPreview( !is_null($this->section
) && $this->section
!== '' );
2075 if ( $wgRawHtml && !$this->mTokenOk
) {
2076 // Could be an offsite preview attempt. This is very unsafe if
2077 // HTML is enabled, as it could be an attack.
2079 if ( $this->textbox1
!== '' ) {
2080 // Do not put big scary notice, if previewing the empty
2081 // string, which happens when you initially edit
2082 // a category page, due to automatic preview-on-open.
2083 $parsedNote = $wgOut->parse( "<div class='previewnote'>" .
2084 wfMsg( 'session_fail_preview_html' ) . "</div>", true, /* interface */true );
2086 wfProfileOut( __METHOD__
);
2090 # don't parse non-wikitext pages, show message about preview
2091 # XXX: stupid php bug won't let us use $this->getContextTitle()->isCssJsSubpage() here -- This note has been there since r3530. Sure the bug was fixed time ago?
2093 if ( $this->isCssJsSubpage ||
!$this->mTitle
->isWikitextPage() ) {
2094 if( $this->mTitle
->isCssJsSubpage() ) {
2096 } elseif( $this->mTitle
->isCssOrJsPage() ) {
2102 # Used messages to make sure grep find them:
2103 # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
2105 if (preg_match( "/\\.css$/", $this->mTitle
->getText() ) ) {
2106 $previewtext = "<div id='mw-{$level}csspreview'>\n" . wfMsg( "{$level}csspreview" ) . "\n</div>";
2107 $class = "mw-code mw-css";
2108 } elseif (preg_match( "/\\.js$/", $this->mTitle
->getText() ) ) {
2109 $previewtext = "<div id='mw-{$level}jspreview'>\n" . wfMsg( "{$level}jspreview" ) . "\n</div>";
2110 $class = "mw-code mw-js";
2112 throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' );
2116 $parserOptions->setTidy( true );
2117 $parserOutput = $wgParser->parse( $previewtext, $this->mTitle
, $parserOptions );
2118 $previewHTML = $parserOutput->mText
;
2119 $previewHTML .= "<pre class=\"$class\" dir=\"ltr\">\n" . htmlspecialchars( $this->textbox1
) . "\n</pre>\n";
2121 $rt = Title
::newFromRedirectArray( $this->textbox1
);
2123 $previewHTML = $this->mArticle
->viewRedirect( $rt, false );
2125 $toparse = $this->textbox1
;
2127 # If we're adding a comment, we need to show the
2128 # summary as the headline
2129 if ( $this->section
== "new" && $this->summary
!= "" ) {
2130 $toparse = "== {$this->summary} ==\n\n" . $toparse;
2133 wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
2135 $parserOptions->setTidy( true );
2136 $parserOptions->enableLimitReport();
2137 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ),
2138 $this->mTitle
, $parserOptions );
2140 $previewHTML = $parserOutput->getText();
2141 $this->mParserOutput
= $parserOutput;
2142 $wgOut->addParserOutputNoText( $parserOutput );
2144 if ( count( $parserOutput->getWarnings() ) ) {
2145 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
2150 if( $this->isConflict
) {
2151 $conflict = '<h2 id="mw-previewconflict">' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
2153 $conflict = '<hr />';
2156 $previewhead = "<div class='previewnote'>\n" .
2157 '<h2 id="mw-previewheader">' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>" .
2158 $wgOut->parse( $note, true, /* interface */true ) . $conflict . "</div>\n";
2160 $pageLang = $this->mTitle
->getPageLanguage();
2161 $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
2162 'class' => 'mw-content-'.$pageLang->getDir() );
2163 $previewHTML = Html
::rawElement( 'div', $attribs, $previewHTML );
2165 wfProfileOut( __METHOD__
);
2166 return $previewhead . $previewHTML . $this->previewTextAfterContent
;
2172 function getTemplates() {
2173 if ( $this->preview ||
$this->section
!= '' ) {
2174 $templates = array();
2175 if ( !isset( $this->mParserOutput
) ) {
2178 foreach( $this->mParserOutput
->getTemplates() as $ns => $template) {
2179 foreach( array_keys( $template ) as $dbk ) {
2180 $templates[] = Title
::makeTitle($ns, $dbk);
2185 return $this->mArticle
->getUsedTemplates();
2190 * Call the stock "user is blocked" page
2192 function blockedPage() {
2194 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
2196 # If the user made changes, preserve them when showing the markup
2197 # (This happens when a user is blocked during edit, for instance)
2198 $first = $this->firsttime ||
( !$this->save
&& $this->textbox1
== '' );
2200 $source = $this->mTitle
->exists() ?
$this->getContent() : false;
2202 $source = $this->textbox1
;
2205 # Spit out the source or the user's modified version
2206 if ( $source !== false ) {
2207 $wgOut->addHTML( '<hr />' );
2208 $wgOut->addWikiMsg( $first ?
'blockedoriginalsource' : 'blockededitsource', $this->mTitle
->getPrefixedText() );
2209 $this->showTextbox1( array( 'readonly' ), $source );
2214 * Produce the stock "please login to edit pages" page
2216 function userNotLoggedInPage() {
2219 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
2220 $loginLink = Linker
::linkKnown(
2222 wfMsgHtml( 'loginreqlink' ),
2224 array( 'returnto' => $this->getContextTitle()->getPrefixedText() )
2227 $wgOut->setPageTitle( wfMessage( 'whitelistedittitle' ) );
2228 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2229 $wgOut->setArticleRelated( false );
2231 $wgOut->addHTML( wfMessage( 'whitelistedittext' )->rawParams( $loginLink )->parse() );
2232 $wgOut->returnToMain( false, $this->getContextTitle() );
2236 * Creates a basic error page which informs the user that
2237 * they have attempted to edit a nonexistent section.
2239 function noSuchSectionPage() {
2242 $wgOut->setPageTitle( wfMessage( 'nosuchsectiontitle' ) );
2243 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2244 $wgOut->setArticleRelated( false );
2246 $res = wfMsgExt( 'nosuchsectiontext', 'parse', $this->section
);
2247 wfRunHooks( 'EditPageNoSuchSection', array( &$this, &$res ) );
2248 $wgOut->addHTML( $res );
2250 $wgOut->returnToMain( false, $this->mTitle
);
2254 * Produce the stock "your edit contains spam" page
2256 * @param $match Text which triggered one or more filters
2257 * @deprecated since 1.17 Use method spamPageWithContent() instead
2259 static function spamPage( $match = false ) {
2260 global $wgOut, $wgTitle;
2262 $wgOut->setPageTitle( wfMessage( 'spamprotectiontitle' ) );
2263 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2264 $wgOut->setArticleRelated( false );
2266 $wgOut->addHTML( '<div id="spamprotected">' );
2267 $wgOut->addWikiMsg( 'spamprotectiontext' );
2269 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
2271 $wgOut->addHTML( '</div>' );
2273 $wgOut->returnToMain( false, $wgTitle );
2277 * Show "your edit contains spam" page with your diff and text
2279 * @param $match Text which triggered one or more filters
2281 public function spamPageWithContent( $match = false ) {
2283 $this->textbox2
= $this->textbox1
;
2285 $wgOut->setPageTitle( wfMessage( 'spamprotectiontitle' ) );
2286 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2287 $wgOut->setArticleRelated( false );
2289 $wgOut->addHTML( '<div id="spamprotected">' );
2290 $wgOut->addWikiMsg( 'spamprotectiontext' );
2292 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
2294 $wgOut->addHTML( '</div>' );
2296 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
2297 $de = new DifferenceEngine( $this->mTitle
);
2298 $de->setText( $this->getContent(), $this->textbox2
);
2299 $de->showDiff( wfMsg( "storedversion" ), wfMsgExt( 'yourtext', 'parseinline' ) );
2301 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
2302 $this->showTextbox2();
2304 $wgOut->addReturnTo( $this->getContextTitle(), array( 'action' => 'edit' ) );
2312 * @parma $editText string
2316 function mergeChangesInto( &$editText ){
2317 wfProfileIn( __METHOD__
);
2319 $db = wfGetDB( DB_MASTER
);
2321 // This is the revision the editor started from
2322 $baseRevision = $this->getBaseRevision();
2323 if ( is_null( $baseRevision ) ) {
2324 wfProfileOut( __METHOD__
);
2327 $baseText = $baseRevision->getText();
2329 // The current state, we want to merge updates into it
2330 $currentRevision = Revision
::loadFromTitle( $db, $this->mTitle
);
2331 if ( is_null( $currentRevision ) ) {
2332 wfProfileOut( __METHOD__
);
2335 $currentText = $currentRevision->getText();
2338 if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
2339 $editText = $result;
2340 wfProfileOut( __METHOD__
);
2343 wfProfileOut( __METHOD__
);
2349 * Check if the browser is on a blacklist of user-agents known to
2350 * mangle UTF-8 data on form submission. Returns true if Unicode
2351 * should make it through, false if it's known to be a problem.
2355 function checkUnicodeCompliantBrowser() {
2356 global $wgBrowserBlackList;
2357 if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
2358 // No User-Agent header sent? Trust it by default...
2361 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
2362 foreach ( $wgBrowserBlackList as $browser ) {
2363 if ( preg_match($browser, $currentbrowser) ) {
2371 * Format an anchor fragment as it would appear for a given section name
2372 * @param $text String
2376 function sectionAnchor( $text ) {
2378 return $wgParser->guessSectionNameFromWikiText( $text );
2382 * Shows a bulletin board style toolbar for common editing functions.
2383 * It can be disabled in the user preferences.
2384 * The necessary JavaScript code can be found in skins/common/edit.js.
2388 static function getEditToolbar() {
2389 global $wgStylePath, $wgContLang, $wgLang, $wgOut;
2390 global $wgUseTeX, $wgEnableUploads, $wgForeignFileRepos;
2392 $imagesAvailable = $wgEnableUploads ||
count( $wgForeignFileRepos );
2395 * $toolarray is an array of arrays each of which includes the
2396 * filename of the button image (without path), the opening
2397 * tag, the closing tag, optionally a sample text that is
2398 * inserted between the two when no selection is highlighted
2399 * and. The tip text is shown when the user moves the mouse
2402 * Also here: accesskeys (key), which are not used yet until
2403 * someone can figure out a way to make them work in
2404 * IE. However, we should make sure these keys are not defined
2409 'image' => $wgLang->getImageFile( 'button-bold' ),
2410 'id' => 'mw-editbutton-bold',
2412 'close' => '\'\'\'',
2413 'sample' => wfMsg( 'bold_sample' ),
2414 'tip' => wfMsg( 'bold_tip' ),
2418 'image' => $wgLang->getImageFile( 'button-italic' ),
2419 'id' => 'mw-editbutton-italic',
2422 'sample' => wfMsg( 'italic_sample' ),
2423 'tip' => wfMsg( 'italic_tip' ),
2427 'image' => $wgLang->getImageFile( 'button-link' ),
2428 'id' => 'mw-editbutton-link',
2431 'sample' => wfMsg( 'link_sample' ),
2432 'tip' => wfMsg( 'link_tip' ),
2436 'image' => $wgLang->getImageFile( 'button-extlink' ),
2437 'id' => 'mw-editbutton-extlink',
2440 'sample' => wfMsg( 'extlink_sample' ),
2441 'tip' => wfMsg( 'extlink_tip' ),
2445 'image' => $wgLang->getImageFile( 'button-headline' ),
2446 'id' => 'mw-editbutton-headline',
2449 'sample' => wfMsg( 'headline_sample' ),
2450 'tip' => wfMsg( 'headline_tip' ),
2453 $imagesAvailable ?
array(
2454 'image' => $wgLang->getImageFile( 'button-image' ),
2455 'id' => 'mw-editbutton-image',
2456 'open' => '[[' . $wgContLang->getNsText( NS_FILE
) . ':',
2458 'sample' => wfMsg( 'image_sample' ),
2459 'tip' => wfMsg( 'image_tip' ),
2462 $imagesAvailable ?
array(
2463 'image' => $wgLang->getImageFile( 'button-media' ),
2464 'id' => 'mw-editbutton-media',
2465 'open' => '[[' . $wgContLang->getNsText( NS_MEDIA
) . ':',
2467 'sample' => wfMsg( 'media_sample' ),
2468 'tip' => wfMsg( 'media_tip' ),
2472 'image' => $wgLang->getImageFile( 'button-math' ),
2473 'id' => 'mw-editbutton-math',
2475 'close' => "</math>",
2476 'sample' => wfMsg( 'math_sample' ),
2477 'tip' => wfMsg( 'math_tip' ),
2481 'image' => $wgLang->getImageFile( 'button-nowiki' ),
2482 'id' => 'mw-editbutton-nowiki',
2483 'open' => "<nowiki>",
2484 'close' => "</nowiki>",
2485 'sample' => wfMsg( 'nowiki_sample' ),
2486 'tip' => wfMsg( 'nowiki_tip' ),
2490 'image' => $wgLang->getImageFile( 'button-sig' ),
2491 'id' => 'mw-editbutton-signature',
2495 'tip' => wfMsg( 'sig_tip' ),
2499 'image' => $wgLang->getImageFile( 'button-hr' ),
2500 'id' => 'mw-editbutton-hr',
2501 'open' => "\n----\n",
2504 'tip' => wfMsg( 'hr_tip' ),
2510 foreach ( $toolarray as $tool ) {
2516 $image = $wgStylePath . '/common/images/' . $tool['image'],
2517 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2518 // Older browsers show a "speedtip" type message only for ALT.
2519 // Ideally these should be different, realistically they
2520 // probably don't need to be.
2521 $tip = $tool['tip'],
2522 $open = $tool['open'],
2523 $close = $tool['close'],
2524 $sample = $tool['sample'],
2525 $cssId = $tool['id'],
2528 $script .= Xml
::encodeJsCall( 'mw.toolbar.addButton', $params );
2530 $wgOut->addScript( Html
::inlineScript( ResourceLoader
::makeLoaderConditionalScript( $script ) ) );
2532 $toolbar = '<div id="toolbar"></div>';
2534 wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
2540 * Returns an array of html code of the following checkboxes:
2543 * @param $tabindex Current tabindex
2544 * @param $checked Array of checkbox => bool, where bool indicates the checked
2545 * status of the checkbox
2549 public function getCheckboxes( &$tabindex, $checked ) {
2552 $checkboxes = array();
2554 // don't show the minor edit checkbox if it's a new page or section
2555 if ( !$this->isNew
) {
2556 $checkboxes['minor'] = '';
2557 $minorLabel = wfMsgExt( 'minoredit', array( 'parseinline' ) );
2558 if ( $wgUser->isAllowed( 'minoredit' ) ) {
2560 'tabindex' => ++
$tabindex,
2561 'accesskey' => wfMsg( 'accesskey-minoredit' ),
2562 'id' => 'wpMinoredit',
2564 $checkboxes['minor'] =
2565 Xml
::check( 'wpMinoredit', $checked['minor'], $attribs ) .
2566 " <label for='wpMinoredit' id='mw-editpage-minoredit'" .
2567 Xml
::expandAttributes( array( 'title' => Linker
::titleAttrib( 'minoredit', 'withaccess' ) ) ) .
2568 ">{$minorLabel}</label>";
2572 $watchLabel = wfMsgExt( 'watchthis', array( 'parseinline' ) );
2573 $checkboxes['watch'] = '';
2574 if ( $wgUser->isLoggedIn() ) {
2576 'tabindex' => ++
$tabindex,
2577 'accesskey' => wfMsg( 'accesskey-watch' ),
2578 'id' => 'wpWatchthis',
2580 $checkboxes['watch'] =
2581 Xml
::check( 'wpWatchthis', $checked['watch'], $attribs ) .
2582 " <label for='wpWatchthis' id='mw-editpage-watch'" .
2583 Xml
::expandAttributes( array( 'title' => Linker
::titleAttrib( 'watch', 'withaccess' ) ) ) .
2584 ">{$watchLabel}</label>";
2586 wfRunHooks( 'EditPageBeforeEditChecks', array( &$this, &$checkboxes, &$tabindex ) );
2591 * Returns an array of html code of the following buttons:
2592 * save, diff, preview and live
2594 * @param $tabindex Current tabindex
2598 public function getEditButtons( &$tabindex ) {
2605 'tabindex' => ++
$tabindex,
2606 'value' => wfMsg( 'savearticle' ),
2607 'accesskey' => wfMsg( 'accesskey-save' ),
2608 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
2610 $buttons['save'] = Xml
::element('input', $temp, '');
2612 ++
$tabindex; // use the same for preview and live preview
2614 'id' => 'wpPreview',
2615 'name' => 'wpPreview',
2617 'tabindex' => $tabindex,
2618 'value' => wfMsg( 'showpreview' ),
2619 'accesskey' => wfMsg( 'accesskey-preview' ),
2620 'title' => wfMsg( 'tooltip-preview' ) . ' [' . wfMsg( 'accesskey-preview' ) . ']',
2622 $buttons['preview'] = Xml
::element( 'input', $temp, '' );
2623 $buttons['live'] = '';
2629 'tabindex' => ++
$tabindex,
2630 'value' => wfMsg( 'showdiff' ),
2631 'accesskey' => wfMsg( 'accesskey-diff' ),
2632 'title' => wfMsg( 'tooltip-diff' ) . ' [' . wfMsg( 'accesskey-diff' ) . ']',
2634 $buttons['diff'] = Xml
::element( 'input', $temp, '' );
2636 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
2641 * Output preview text only. This can be sucked into the edit page
2642 * via JavaScript, and saves the server time rendering the skin as
2643 * well as theoretically being more robust on the client (doesn't
2644 * disturb the edit box's undo history, won't eat your text on
2647 * @todo This doesn't include category or interlanguage links.
2648 * Would need to enhance it a bit, <s>maybe wrap them in XML
2649 * or something...</s> that might also require more skin
2650 * initialization, so check whether that's a problem.
2652 function livePreview() {
2655 header( 'Content-type: text/xml; charset=utf-8' );
2656 header( 'Cache-control: no-cache' );
2658 $previewText = $this->getPreviewText();
2659 #$categories = $skin->getCategoryLinks();
2662 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2663 Xml
::tags( 'livepreview', null,
2664 Xml
::element( 'preview', null, $previewText )
2665 #. Xml::element( 'category', null, $categories )
2673 public function getCancelLink() {
2674 $cancelParams = array();
2675 if ( !$this->isConflict
&& $this->mArticle
->getOldID() > 0 ) {
2676 $cancelParams['oldid'] = $this->mArticle
->getOldID();
2679 return Linker
::linkKnown(
2680 $this->getContextTitle(),
2681 wfMsgExt( 'cancel', array( 'parseinline' ) ),
2682 array( 'id' => 'mw-editform-cancel' ),
2688 * Get a diff between the current contents of the edit box and the
2689 * version of the page we're editing from.
2691 * If this is a section edit, we'll replace the section as for final
2692 * save and then make a comparison.
2694 function showDiff() {
2695 $oldtext = $this->mArticle
->fetchContent();
2696 $newtext = $this->mArticle
->replaceSection(
2697 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
2699 wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
2701 $newtext = $this->mArticle
->preSaveTransform( $newtext );
2702 $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
2703 $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
2704 if ( $oldtext !== false ||
$newtext != '' ) {
2705 $de = new DifferenceEngine( $this->mTitle
);
2706 $de->setText( $oldtext, $newtext );
2707 $difftext = $de->getDiff( $oldtitle, $newtitle );
2708 $de->showDiffStyle();
2714 $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
2718 * Filter an input field through a Unicode de-armoring process if it
2719 * came from an old browser with known broken Unicode editing issues.
2721 * @param $request WebRequest
2722 * @param $field String
2726 function safeUnicodeInput( $request, $field ) {
2727 $text = rtrim( $request->getText( $field ) );
2728 return $request->getBool( 'safemode' )
2729 ?
$this->unmakesafe( $text )
2734 * @param $request WebRequest
2735 * @param $text string
2738 function safeUnicodeText( $request, $text ) {
2739 $text = rtrim( $text );
2740 return $request->getBool( 'safemode' )
2741 ?
$this->unmakesafe( $text )
2746 * Filter an output field through a Unicode armoring process if it is
2747 * going to an old browser with known broken Unicode editing issues.
2749 * @param $text String
2753 function safeUnicodeOutput( $text ) {
2755 $codedText = $wgContLang->recodeForEdit( $text );
2756 return $this->checkUnicodeCompliantBrowser()
2758 : $this->makesafe( $codedText );
2762 * A number of web browsers are known to corrupt non-ASCII characters
2763 * in a UTF-8 text editing environment. To protect against this,
2764 * detected browsers will be served an armored version of the text,
2765 * with non-ASCII chars converted to numeric HTML character references.
2767 * Preexisting such character references will have a 0 added to them
2768 * to ensure that round-trips do not alter the original data.
2770 * @param $invalue String
2774 function makesafe( $invalue ) {
2775 // Armor existing references for reversability.
2776 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
2781 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2782 $bytevalue = ord( $invalue[$i] );
2783 if ( $bytevalue <= 0x7F ) { //0xxx xxxx
2784 $result .= chr( $bytevalue );
2786 } elseif ( $bytevalue <= 0xBF ) { //10xx xxxx
2787 $working = $working << 6;
2788 $working +
= ($bytevalue & 0x3F);
2790 if ( $bytesleft <= 0 ) {
2791 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2793 } elseif ( $bytevalue <= 0xDF ) { //110x xxxx
2794 $working = $bytevalue & 0x1F;
2796 } elseif ( $bytevalue <= 0xEF ) { //1110 xxxx
2797 $working = $bytevalue & 0x0F;
2799 } else { //1111 0xxx
2800 $working = $bytevalue & 0x07;
2808 * Reverse the previously applied transliteration of non-ASCII characters
2809 * back to UTF-8. Used to protect data from corruption by broken web browsers
2810 * as listed in $wgBrowserBlackList.
2812 * @param $invalue String
2816 function unmakesafe( $invalue ) {
2818 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2819 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue[$i+
3] != '0' ) ) {
2823 $hexstring .= $invalue[$i];
2825 } while( ctype_xdigit( $invalue[$i] ) && ( $i < strlen( $invalue ) ) );
2827 // Do some sanity checks. These aren't needed for reversability,
2828 // but should help keep the breakage down if the editor
2829 // breaks one of the entities whilst editing.
2830 if ( (substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6) ) {
2831 $codepoint = hexdec($hexstring);
2832 $result .= codepointToUtf8( $codepoint );
2834 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2837 $result .= substr( $invalue, $i, 1 );
2840 // reverse the transform that we made for reversability reasons.
2841 return strtr( $result, array( "�" => "&#x" ) );
2844 function noCreatePermission() {
2846 $wgOut->setPageTitle( wfMessage( 'nocreatetitle' ) );
2847 $wgOut->addWikiMsg( 'nocreatetext' );
2851 * Attempt submission
2852 * @return bool false if output is done, true if the rest of the form should be displayed
2854 function attemptSave() {
2855 global $wgUser, $wgOut;
2857 $resultDetails = false;
2858 # Allow bots to exempt some edits from bot flagging
2859 $bot = $wgUser->isAllowed( 'bot' ) && $this->bot
;
2860 $status = $this->internalAttemptSave( $resultDetails, $bot );
2861 // FIXME: once the interface for internalAttemptSave() is made nicer, this should use the message in $status
2863 if ( $status->value
== self
::AS_SUCCESS_UPDATE ||
$status->value
== self
::AS_SUCCESS_NEW_ARTICLE
) {
2864 $this->didSave
= true;
2867 switch ( $status->value
) {
2868 case self
::AS_HOOK_ERROR_EXPECTED
:
2869 case self
::AS_CONTENT_TOO_BIG
:
2870 case self
::AS_ARTICLE_WAS_DELETED
:
2871 case self
::AS_CONFLICT_DETECTED
:
2872 case self
::AS_SUMMARY_NEEDED
:
2873 case self
::AS_TEXTBOX_EMPTY
:
2874 case self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
:
2878 case self
::AS_HOOK_ERROR
:
2879 case self
::AS_FILTERING
:
2882 case self
::AS_SUCCESS_NEW_ARTICLE
:
2883 $query = $resultDetails['redirect'] ?
'redirect=no' : '';
2884 $wgOut->redirect( $this->mTitle
->getFullURL( $query ) );
2887 case self
::AS_SUCCESS_UPDATE
:
2889 $sectionanchor = $resultDetails['sectionanchor'];
2891 // Give extensions a chance to modify URL query on update
2892 wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this->mArticle
, &$sectionanchor, &$extraQuery ) );
2894 if ( $resultDetails['redirect'] ) {
2895 if ( $extraQuery == '' ) {
2896 $extraQuery = 'redirect=no';
2898 $extraQuery = 'redirect=no&' . $extraQuery;
2901 $wgOut->redirect( $this->mTitle
->getFullURL( $extraQuery ) . $sectionanchor );
2904 case self
::AS_SPAM_ERROR
:
2905 $this->spamPageWithContent( $resultDetails['spam'] );
2908 case self
::AS_BLOCKED_PAGE_FOR_USER
:
2909 $this->blockedPage();
2912 case self
::AS_IMAGE_REDIRECT_ANON
:
2913 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2916 case self
::AS_READ_ONLY_PAGE_ANON
:
2917 $this->userNotLoggedInPage();
2920 case self
::AS_READ_ONLY_PAGE_LOGGED
:
2921 case self
::AS_READ_ONLY_PAGE
:
2922 $wgOut->readOnlyPage();
2925 case self
::AS_RATE_LIMITED
:
2926 $wgOut->rateLimited();
2929 case self
::AS_NO_CREATE_PERMISSION
:
2930 $this->noCreatePermission();
2933 case self
::AS_BLANK_ARTICLE
:
2934 $wgOut->redirect( $this->getContextTitle()->getFullURL() );
2937 case self
::AS_IMAGE_REDIRECT_LOGGED
:
2938 $wgOut->permissionRequired( 'upload' );
2947 function getBaseRevision() {
2948 if ( !$this->mBaseRevision
) {
2949 $db = wfGetDB( DB_MASTER
);
2950 $baseRevision = Revision
::loadFromTimestamp(
2951 $db, $this->mTitle
, $this->edittime
);
2952 return $this->mBaseRevision
= $baseRevision;
2954 return $this->mBaseRevision
;