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;
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 function __construct( $article ) {
120 $this->mArticle
=& $article;
121 $this->mTitle
= $article->getTitle();
122 $this->action
= 'submit';
124 # Placeholders for text injection by hooks (empty per default)
125 $this->editFormPageTop
=
126 $this->editFormTextTop
=
127 $this->editFormTextBeforeContent
=
128 $this->editFormTextAfterWarn
=
129 $this->editFormTextAfterTools
=
130 $this->editFormTextBottom
=
131 $this->editFormTextAfterContent
=
132 $this->previewTextAfterContent
=
133 $this->mPreloadText
= "";
139 function getArticle() {
140 return $this->mArticle
;
144 * Set the context Title object
146 * @param $title Title object or null
148 public function setContextTitle( $title ) {
149 $this->mContextTitle
= $title;
153 * Get the context title object.
154 * If not set, $wgTitle will be returned. This behavior might changed in
155 * the future to return $this->mTitle instead.
157 * @return Title object
159 public function getContextTitle() {
160 if ( is_null( $this->mContextTitle
) ) {
164 return $this->mContextTitle
;
169 * Fetch initial editing page content.
171 * @param $def_text string
172 * @return mixed string on success, $def_text for invalid sections
175 function getContent( $def_text = '' ) {
176 global $wgOut, $wgRequest, $wgParser;
178 wfProfileIn( __METHOD__
);
179 # Get variables from query string :P
180 $section = $wgRequest->getVal( 'section' );
182 $preload = $wgRequest->getVal( 'preload',
183 // Custom preload text for new sections
184 $section === 'new' ?
'MediaWiki:addsection-preload' : '' );
185 $undoafter = $wgRequest->getVal( 'undoafter' );
186 $undo = $wgRequest->getVal( 'undo' );
188 // For message page not locally set, use the i18n message.
189 // For other non-existent articles, use preload text if any.
190 if ( !$this->mTitle
->exists() ) {
191 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
192 # If this is a system message, get the default text.
193 $text = $this->mTitle
->getDefaultMessageText();
194 if( $text === false ) {
195 $text = $this->getPreloadedText( $preload );
198 # If requested, preload some text.
199 $text = $this->getPreloadedText( $preload );
201 // For existing pages, get text based on "undo" or section parameters.
203 $text = $this->mArticle
->getContent();
204 if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
205 # If they got undoafter and undo round the wrong way, switch them
206 list( $undo, $undoafter ) = array( $undoafter, $undo );
208 if ( $undo > 0 && $undo > $undoafter ) {
209 # Undoing a specific edit overrides section editing; section-editing
210 # doesn't work with undoing.
212 $undorev = Revision
::newFromId( $undo );
213 $oldrev = Revision
::newFromId( $undoafter );
215 $undorev = Revision
::newFromId( $undo );
216 $oldrev = $undorev ?
$undorev->getPrevious() : null;
219 # Sanity check, make sure it's the right page,
220 # the revisions exist and they were not deleted.
221 # Otherwise, $text will be left as-is.
222 if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
223 $undorev->getPage() == $oldrev->getPage() &&
224 $undorev->getPage() == $this->mArticle
->getID() &&
225 !$undorev->isDeleted( Revision
::DELETED_TEXT
) &&
226 !$oldrev->isDeleted( Revision
::DELETED_TEXT
) ) {
228 $undotext = $this->mArticle
->getUndoText( $undorev, $oldrev );
229 if ( $undotext === false ) {
230 # Warn the user that something went wrong
231 $this->editFormPageTop
.= $wgOut->parse( '<div class="error mw-undo-failure">' .
232 wfMsgNoTrans( 'undo-failure' ) . '</div>', true, /* interface */true );
235 # Inform the user of our success and set an automatic edit summary
236 $this->editFormPageTop
.= $wgOut->parse( '<div class="mw-undo-success">' .
237 wfMsgNoTrans( 'undo-success' ) . '</div>', true, /* interface */true );
238 $firstrev = $oldrev->getNext();
239 # If we just undid one rev, use an autosummary
240 if ( $firstrev->getId() == $undo ) {
241 $undoSummary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
242 if ( $this->summary
=== '' ) {
243 $this->summary
= $undoSummary;
245 $this->summary
= $undoSummary . wfMsgForContent( 'colon-separator' ) . $this->summary
;
247 $this->undidRev
= $undo;
249 $this->formtype
= 'diff';
252 // Failed basic sanity checks.
253 // Older revisions may have been removed since the link
254 // was created, or we may simply have got bogus input.
255 $this->editFormPageTop
.= $wgOut->parse( '<div class="error mw-undo-norev">' .
256 wfMsgNoTrans( 'undo-norev' ) . '</div>', true, /* interface */true );
258 } elseif ( $section != '' ) {
259 if ( $section == 'new' ) {
260 $text = $this->getPreloadedText( $preload );
262 // Get section edit text (returns $def_text for invalid sections)
263 $text = $wgParser->getSection( $text, $section, $def_text );
268 wfProfileOut( __METHOD__
);
273 * Use this method before edit() to preload some text into the edit box
275 * @param $text string
277 public function setPreloadedText( $text ) {
278 $this->mPreloadText
= $text;
282 * Get the contents to be preloaded into the box, either set by
283 * an earlier setPreloadText() or by loading the given page.
285 * @param $preload String: representing the title to preload from.
288 protected function getPreloadedText( $preload ) {
289 global $wgUser, $wgParser;
290 if ( !empty( $this->mPreloadText
) ) {
291 return $this->mPreloadText
;
292 } elseif ( $preload !== '' ) {
293 $title = Title
::newFromText( $preload );
294 # Check for existence to avoid getting MediaWiki:Noarticletext
295 if ( isset( $title ) && $title->exists() && $title->userCanRead() ) {
296 $article = new Article( $title );
298 if ( $article->isRedirect() ) {
299 $title = Title
::newFromRedirectRecurse( $article->getContent() );
300 # Redirects to missing titles are displayed, to hidden pages are followed
301 # Copying observed behaviour from ?action=view
302 if ( $title->exists() ) {
303 if ($title->userCanRead() ) {
304 $article = new Article( $title );
310 $parserOptions = ParserOptions
::newFromUser( $wgUser );
311 return $wgParser->getPreloadText( $article->getContent(), $title, $parserOptions );
318 * Check if a page was deleted while the user was editing it, before submit.
319 * Note that we rely on the logging table, which hasn't been always there,
320 * but that doesn't matter, because this only applies to brand new
323 protected function wasDeletedSinceLastEdit() {
324 if ( $this->deletedSinceEdit
!== null ) {
325 return $this->deletedSinceEdit
;
328 $this->deletedSinceEdit
= false;
330 if ( $this->mTitle
->isDeletedQuick() ) {
331 $this->lastDelete
= $this->getLastDelete();
332 if ( $this->lastDelete
) {
333 $deleteTime = wfTimestamp( TS_MW
, $this->lastDelete
->log_timestamp
);
334 if ( $deleteTime > $this->starttime
) {
335 $this->deletedSinceEdit
= true;
340 return $this->deletedSinceEdit
;
344 * Checks whether the user entered a skin name in uppercase,
345 * e.g. "User:Example/Monobook.css" instead of "monobook.css"
349 protected function isWrongCaseCssJsPage() {
350 if( $this->mTitle
->isCssJsSubpage() ) {
351 $name = $this->mTitle
->getSkinFromCssJsSubpage();
352 $skins = array_merge(
353 array_keys( Skin
::getSkinNames() ),
356 return !in_array( $name, $skins )
357 && in_array( strtolower( $name ), $skins );
368 * This is the function that gets called for "action=edit". It
369 * sets up various member variables, then passes execution to
370 * another function, usually showEditForm()
372 * The edit form is self-submitting, so that when things like
373 * preview and edit conflicts occur, we get the same form back
374 * with the extra stuff added. Only when the final submission
375 * is made and all is well do we actually save and redirect to
376 * the newly-edited page.
379 global $wgOut, $wgRequest, $wgUser;
380 // Allow extensions to modify/prevent this form or submission
381 if ( !wfRunHooks( 'AlternateEdit', array( $this ) ) ) {
385 wfProfileIn( __METHOD__
);
386 wfDebug( __METHOD__
.": enter\n" );
388 $this->importFormData( $wgRequest );
389 $this->firsttime
= false;
392 $this->livePreview();
393 wfProfileOut( __METHOD__
);
397 if ( wfReadOnly() && $this->save
) {
400 $this->preview
= true;
403 $wgOut->addModules( array( 'mediawiki.action.edit' ) );
405 if ( $wgUser->getOption( 'uselivepreview', false ) ) {
406 $wgOut->addModules( 'mediawiki.legacy.preview' );
408 // Bug #19334: textarea jumps when editing articles in IE8
409 $wgOut->addStyle( 'common/IE80Fixes.css', 'screen', 'IE 8' );
411 $permErrors = $this->getEditPermissionErrors();
413 // Auto-block user's IP if the account was "hard" blocked
414 $wgUser->spreadAnyEditBlock();
416 wfDebug( __METHOD__
. ": User can't edit\n" );
417 $content = $this->getContent( null );
418 $content = $content === '' ?
null : $content;
419 $this->readOnlyPage( $content, true, $permErrors, 'edit' );
420 wfProfileOut( __METHOD__
);
424 $this->formtype
= 'save';
425 } elseif ( $this->preview
) {
426 $this->formtype
= 'preview';
427 } elseif ( $this->diff
) {
428 $this->formtype
= 'diff';
429 } else { # First time through
430 $this->firsttime
= true;
431 if ( $this->previewOnOpen() ) {
432 $this->formtype
= 'preview';
434 $this->formtype
= 'initial';
439 // If they used redlink=1 and the page exists, redirect to the main article
440 if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle
->exists() ) {
441 $wgOut->redirect( $this->mTitle
->getFullURL() );
444 wfProfileIn( __METHOD__
."-business-end" );
446 $this->isConflict
= false;
447 // css / js subpages of user pages get a special treatment
448 $this->isCssJsSubpage
= $this->mTitle
->isCssJsSubpage();
449 $this->isCssSubpage
= $this->mTitle
->isCssSubpage();
450 $this->isJsSubpage
= $this->mTitle
->isJsSubpage();
451 $this->isWrongCaseCssJsPage
= $this->isWrongCaseCssJsPage();
452 $this->isNew
= !$this->mTitle
->exists() ||
$this->section
== 'new';
454 # Show applicable editing introductions
455 if ( $this->formtype
== 'initial' ||
$this->firsttime
)
458 if ( $this->mTitle
->isTalkPage() ) {
459 $wgOut->addWikiMsg( 'talkpagetext' );
462 # Optional notices on a per-namespace and per-page basis
463 $editnotice_ns = 'editnotice-'.$this->mTitle
->getNamespace();
464 $editnotice_ns_message = wfMessage( $editnotice_ns )->inContentLanguage();
465 if ( $editnotice_ns_message->exists() ) {
466 $wgOut->addWikiText( $editnotice_ns_message->plain() );
468 if ( MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
469 $parts = explode( '/', $this->mTitle
->getDBkey() );
470 $editnotice_base = $editnotice_ns;
471 while ( count( $parts ) > 0 ) {
472 $editnotice_base .= '-'.array_shift( $parts );
473 $editnotice_base_msg = wfMessage( $editnotice_base )->inContentLanguage();
474 if ( $editnotice_base_msg->exists() ) {
475 $wgOut->addWikiText( $editnotice_base_msg->plain() );
479 # Even if there are no subpages in namespace, we still don't want / in MW ns.
480 $editnoticeText = $editnotice_ns . '-' . str_replace( '/', '-', $this->mTitle
->getDBkey() );
481 $editnoticeMsg = wfMessage( $editnoticeText )->inContentLanguage();
482 if ( $editnoticeMsg->exists() ) {
483 $wgOut->addWikiText( $editnoticeMsg->plain() );
487 # Attempt submission here. This will check for edit conflicts,
488 # and redundantly check for locked database, blocked IPs, etc.
489 # that edit() already checked just in case someone tries to sneak
490 # in the back door with a hand-edited submission URL.
492 if ( 'save' == $this->formtype
) {
493 if ( !$this->attemptSave() ) {
494 wfProfileOut( __METHOD__
."-business-end" );
495 wfProfileOut( __METHOD__
);
500 # First time through: get contents, set time for conflict
502 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
503 if ( $this->initialiseForm() === false ) {
504 $this->noSuchSectionPage();
505 wfProfileOut( __METHOD__
."-business-end" );
506 wfProfileOut( __METHOD__
);
509 if ( !$this->mTitle
->getArticleId() )
510 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1
, &$this->mTitle
) );
512 wfRunHooks( 'EditFormInitialText', array( $this ) );
515 $this->showEditForm();
516 wfProfileOut( __METHOD__
."-business-end" );
517 wfProfileOut( __METHOD__
);
523 protected function getEditPermissionErrors() {
525 $permErrors = $this->mTitle
->getUserPermissionsErrors( 'edit', $wgUser );
526 # Can this title be created?
527 if ( !$this->mTitle
->exists() ) {
528 $permErrors = array_merge( $permErrors,
529 wfArrayDiff2( $this->mTitle
->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) );
531 # Ignore some permissions errors when a user is just previewing/viewing diffs
533 foreach( $permErrors as $error ) {
534 if ( ( $this->preview ||
$this->diff
) &&
535 ( $error[0] == 'blockedtext' ||
$error[0] == 'autoblockedtext' ) )
540 $permErrors = wfArrayDiff2( $permErrors, $remove );
545 * Show a read-only error
546 * Parameters are the same as OutputPage:readOnlyPage()
547 * Redirect to the article page if redlink=1
549 function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
550 global $wgRequest, $wgOut;
551 if ( $wgRequest->getBool( 'redlink' ) ) {
552 // The edit page was reached via a red link.
553 // Redirect to the article page and let them click the edit tab if
554 // they really want a permission error.
555 $wgOut->redirect( $this->mTitle
->getFullUrl() );
557 $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
562 * Should we show a preview when the edit form is first shown?
566 protected function previewOnOpen() {
567 global $wgRequest, $wgUser, $wgPreviewOnOpenNamespaces;
568 if ( $wgRequest->getVal( 'preview' ) == 'yes' ) {
569 // Explicit override from request
571 } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) {
572 // Explicit override from request
574 } elseif ( $this->section
== 'new' ) {
575 // Nothing *to* preview for new sections
577 } elseif ( ( $wgRequest->getVal( 'preload' ) !== null ||
$this->mTitle
->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
578 // Standard preference behaviour
580 } elseif ( !$this->mTitle
->exists() &&
581 isset($wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()]) &&
582 $wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()] )
584 // Categories are special
592 * Does this EditPage class support section editing?
593 * This is used by EditPage subclasses to indicate their ui cannot handle section edits
597 protected function isSectionEditSupported() {
602 * Returns the URL to use in the form's action attribute.
603 * This is used by EditPage subclasses when simply customizing the action
604 * variable in the constructor is not enough. This can be used when the
605 * EditPage lives inside of a Special page rather than a custom page action.
607 * @param $title Title object for which is being edited (where we go to for &action= links)
610 protected function getActionURL( Title
$title ) {
611 return $title->getLocalURL( array( 'action' => $this->action
) );
616 * @param $request WebRequest
618 function importFormData( &$request ) {
619 global $wgLang, $wgUser;
621 wfProfileIn( __METHOD__
);
623 # Section edit can come from either the form or a link
624 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
626 if ( $request->wasPosted() ) {
627 # These fields need to be checked for encoding.
628 # Also remove trailing whitespace, but don't remove _initial_
629 # whitespace from the text boxes. This may be significant formatting.
630 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
631 if ( !$request->getCheck('wpTextbox2') ) {
632 // Skip this if wpTextbox2 has input, it indicates that we came
633 // from a conflict page with raw page text, not a custom form
634 // modified by subclasses
635 wfProfileIn( get_class($this)."::importContentFormData" );
636 $textbox1 = $this->importContentFormData( $request );
637 if ( isset($textbox1) )
638 $this->textbox1
= $textbox1;
639 wfProfileOut( get_class($this)."::importContentFormData" );
642 # Truncate for whole multibyte characters. +5 bytes for ellipsis
643 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
645 # Remove extra headings from summaries and new sections.
646 $this->summary
= preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary
);
648 $this->edittime
= $request->getVal( 'wpEdittime' );
649 $this->starttime
= $request->getVal( 'wpStarttime' );
651 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
653 if ($this->textbox1
=== '' && $request->getVal( 'wpTextbox1' ) === null) {
654 // wpTextbox1 field is missing, possibly due to being "too big"
655 // according to some filter rules such as Suhosin's setting for
656 // suhosin.request.max_value_length (d'oh)
657 $this->incompleteForm
= true;
659 // edittime should be one of our last fields; if it's missing,
660 // the submission probably broke somewhere in the middle.
661 $this->incompleteForm
= is_null( $this->edittime
);
663 if ( $this->incompleteForm
) {
664 # If the form is incomplete, force to preview.
665 wfDebug( __METHOD__
. ": Form data appears to be incomplete\n" );
666 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
667 $this->preview
= true;
669 /* Fallback for live preview */
670 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
671 $this->diff
= $request->getCheck( 'wpDiff' );
673 // Remember whether a save was requested, so we can indicate
674 // if we forced preview due to session failure.
675 $this->mTriedSave
= !$this->preview
;
677 if ( $this->tokenOk( $request ) ) {
678 # Some browsers will not report any submit button
679 # if the user hits enter in the comment box.
680 # The unmarked state will be assumed to be a save,
681 # if the form seems otherwise complete.
682 wfDebug( __METHOD__
. ": Passed token check.\n" );
683 } elseif ( $this->diff
) {
684 # Failed token check, but only requested "Show Changes".
685 wfDebug( __METHOD__
. ": Failed token check; Show Changes requested.\n" );
687 # Page might be a hack attempt posted from
688 # an external site. Preview instead of saving.
689 wfDebug( __METHOD__
. ": Failed token check; forcing preview\n" );
690 $this->preview
= true;
693 $this->save
= !$this->preview
&& !$this->diff
;
694 if ( !preg_match( '/^\d{14}$/', $this->edittime
) ) {
695 $this->edittime
= null;
698 if ( !preg_match( '/^\d{14}$/', $this->starttime
) ) {
699 $this->starttime
= null;
702 $this->recreate
= $request->getCheck( 'wpRecreate' );
704 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
705 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
707 # Don't force edit summaries when a user is editing their own user or talk page
708 if ( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) &&
709 $this->mTitle
->getText() == $wgUser->getName() )
711 $this->allowBlankSummary
= true;
713 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' ) ||
!$wgUser->getOption( 'forceeditsummary');
716 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
718 # Not a posted form? Start with nothing.
719 wfDebug( __METHOD__
. ": Not a posted form.\n" );
720 $this->textbox1
= '';
722 $this->edittime
= '';
723 $this->starttime
= wfTimestampNow();
725 $this->preview
= false;
728 $this->minoredit
= false;
729 $this->watchthis
= $request->getBool( 'watchthis', false ); // Watch may be overriden by request parameters
730 $this->recreate
= false;
732 if ( $this->section
== 'new' && $request->getVal( 'preloadtitle' ) ) {
733 $this->summary
= $request->getVal( 'preloadtitle' );
735 elseif ( $this->section
!= 'new' && $request->getVal( 'summary' ) ) {
736 $this->summary
= $request->getText( 'summary' );
739 if ( $request->getVal( 'minor' ) ) {
740 $this->minoredit
= true;
744 $this->bot
= $request->getBool( 'bot', true );
745 $this->nosummary
= $request->getBool( 'nosummary' );
747 // @todo FIXME: Unused variable?
748 $this->oldid
= $request->getInt( 'oldid' );
750 $this->live
= $request->getCheck( 'live' );
751 $this->editintro
= $request->getText( 'editintro',
752 // Custom edit intro for new sections
753 $this->section
=== 'new' ?
'MediaWiki:addsection-editintro' : '' );
755 // Allow extensions to modify form data
756 wfRunHooks( 'EditPage::importFormData', array( $this, $request ) );
758 wfProfileOut( __METHOD__
);
762 * Subpage overridable method for extracting the page content data from the
763 * posted form to be placed in $this->textbox1, if using customized input
764 * this method should be overrided and return the page text that will be used
765 * for saving, preview parsing and so on...
767 * @param $request WebRequest
769 protected function importContentFormData( &$request ) {
770 return; // Don't do anything, EditPage already extracted wpTextbox1
774 * Make sure the form isn't faking a user's credentials.
776 * @param $request WebRequest
780 function tokenOk( &$request ) {
782 $token = $request->getVal( 'wpEditToken' );
783 $this->mTokenOk
= $wgUser->matchEditToken( $token );
784 $this->mTokenOkExceptSuffix
= $wgUser->matchEditTokenNoSuffix( $token );
785 return $this->mTokenOk
;
789 * Show all applicable editing introductions
791 protected function showIntro() {
792 global $wgOut, $wgUser;
793 if ( $this->suppressIntro
) {
797 $namespace = $this->mTitle
->getNamespace();
799 if ( $namespace == NS_MEDIAWIKI
) {
800 # Show a warning if editing an interface message
801 $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1\n</div>", 'editinginterface' );
804 # Show a warning message when someone creates/edits a user (talk) page but the user does not exist
805 # Show log extract when the user is currently blocked
806 if ( $namespace == NS_USER ||
$namespace == NS_USER_TALK
) {
807 $parts = explode( '/', $this->mTitle
->getText(), 2 );
808 $username = $parts[0];
809 $user = User
::newFromName( $username, false /* allow IP users*/ );
810 $ip = User
::isIP( $username );
811 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
812 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
813 array( 'userpage-userdoesnotexist', wfEscapeWikiText( $username ) ) );
814 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
815 LogEventsList
::showLogExtract(
818 $user->getUserPage(),
822 'showIfEmpty' => false,
824 'blocked-notice-logextract',
825 $user->getName() # Support GENDER in notice
831 # Try to add a custom edit intro, or use the standard one if this is not possible.
832 if ( !$this->showCustomIntro() && !$this->mTitle
->exists() ) {
833 if ( $wgUser->isLoggedIn() ) {
834 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletext\">\n$1\n</div>", 'newarticletext' );
836 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletextanon\">\n$1\n</div>", 'newarticletextanon' );
839 # Give a notice if the user is editing a deleted/moved page...
840 if ( !$this->mTitle
->exists() ) {
841 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle
,
842 '', array( 'lim' => 10,
843 'conds' => array( "log_action != 'revision'" ),
844 'showIfEmpty' => false,
845 'msgKey' => array( 'recreate-moveddeleted-warn') )
851 * Attempt to show a custom editing introduction, if supplied
855 protected function showCustomIntro() {
856 if ( $this->editintro
) {
857 $title = Title
::newFromText( $this->editintro
);
858 if ( $title instanceof Title
&& $title->exists() && $title->userCanRead() ) {
860 // Added using template syntax, to take <noinclude>'s into account.
861 $wgOut->addWikiTextTitleTidy( '{{:' . $title->getFullText() . '}}', $this->mTitle
);
872 * Attempt submission (no UI)
877 * @return Status object, possibly with a message, but always with one of the AS_* constants in $status->value,
879 * FIXME: This interface is TERRIBLE, but hard to get rid of due to various error display idiosyncrasies. There are
880 * also lots of cases where error metadata is set in the object and retrieved later instead of being returned, e.g.
881 * AS_CONTENT_TOO_BIG and AS_BLOCKED_PAGE_FOR_USER. All that stuff needs to be cleaned up some time.
883 function internalAttemptSave( &$result, $bot = false ) {
884 global $wgFilterCallback, $wgUser, $wgRequest, $wgParser;
885 global $wgMaxArticleSize;
887 $status = Status
::newGood();
889 wfProfileIn( __METHOD__
);
890 wfProfileIn( __METHOD__
. '-checks' );
892 if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) ) {
893 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
894 $status->fatal( 'hookaborted' );
895 $status->value
= self
::AS_HOOK_ERROR
;
896 wfProfileOut( __METHOD__
. '-checks' );
897 wfProfileOut( __METHOD__
);
901 # Check image redirect
902 if ( $this->mTitle
->getNamespace() == NS_FILE
&&
903 Title
::newFromRedirect( $this->textbox1
) instanceof Title
&&
904 !$wgUser->isAllowed( 'upload' ) ) {
905 $code = $wgUser->isAnon() ? self
::AS_IMAGE_REDIRECT_ANON
: self
::AS_IMAGE_REDIRECT_LOGGED
;
906 $status->setResult( false, $code );
908 wfProfileOut( __METHOD__
. '-checks' );
909 wfProfileOut( __METHOD__
);
915 $match = self
::matchSummarySpamRegex( $this->summary
);
916 if ( $match === false ) {
917 $match = self
::matchSpamRegex( $this->textbox1
);
919 if ( $match !== false ) {
920 $result['spam'] = $match;
921 $ip = $wgRequest->getIP();
922 $pdbk = $this->mTitle
->getPrefixedDBkey();
923 $match = str_replace( "\n", '', $match );
924 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
925 $status->fatal( 'spamprotectionmatch', $match );
926 $status->value
= self
::AS_SPAM_ERROR
;
927 wfProfileOut( __METHOD__
. '-checks' );
928 wfProfileOut( __METHOD__
);
931 if ( $wgFilterCallback && is_callable( $wgFilterCallback ) && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
, $this->hookError
, $this->summary
) ) {
932 # Error messages or other handling should be performed by the filter function
933 $status->setResult( false, self
::AS_FILTERING
);
934 wfProfileOut( __METHOD__
. '-checks' );
935 wfProfileOut( __METHOD__
);
938 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1
, $this->section
, &$this->hookError
, $this->summary
) ) ) {
939 # Error messages etc. could be handled within the hook...
940 $status->fatal( 'hookaborted' );
941 $status->value
= self
::AS_HOOK_ERROR
;
942 wfProfileOut( __METHOD__
. '-checks' );
943 wfProfileOut( __METHOD__
);
945 } elseif ( $this->hookError
!= '' ) {
946 # ...or the hook could be expecting us to produce an error
947 $status->fatal( 'hookaborted' );
948 $status->value
= self
::AS_HOOK_ERROR_EXPECTED
;
949 wfProfileOut( __METHOD__
. '-checks' );
950 wfProfileOut( __METHOD__
);
954 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
955 // Auto-block user's IP if the account was "hard" blocked
956 $wgUser->spreadAnyEditBlock();
957 # Check block state against master, thus 'false'.
958 $status->setResult( false, self
::AS_BLOCKED_PAGE_FOR_USER
);
959 wfProfileOut( __METHOD__
. '-checks' );
960 wfProfileOut( __METHOD__
);
964 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
965 if ( $this->kblength
> $wgMaxArticleSize ) {
966 // Error will be displayed by showEditForm()
967 $this->tooBig
= true;
968 $status->setResult( false, self
::AS_CONTENT_TOO_BIG
);
969 wfProfileOut( __METHOD__
. '-checks' );
970 wfProfileOut( __METHOD__
);
974 if ( !$wgUser->isAllowed( 'edit' ) ) {
975 if ( $wgUser->isAnon() ) {
976 $status->setResult( false, self
::AS_READ_ONLY_PAGE_ANON
);
977 wfProfileOut( __METHOD__
. '-checks' );
978 wfProfileOut( __METHOD__
);
981 $status->fatal( 'readonlytext' );
982 $status->value
= self
::AS_READ_ONLY_PAGE_LOGGED
;
983 wfProfileOut( __METHOD__
. '-checks' );
984 wfProfileOut( __METHOD__
);
989 if ( wfReadOnly() ) {
990 $status->fatal( 'readonlytext' );
991 $status->value
= self
::AS_READ_ONLY_PAGE
;
992 wfProfileOut( __METHOD__
. '-checks' );
993 wfProfileOut( __METHOD__
);
996 if ( $wgUser->pingLimiter() ) {
997 $status->fatal( 'actionthrottledtext' );
998 $status->value
= self
::AS_RATE_LIMITED
;
999 wfProfileOut( __METHOD__
. '-checks' );
1000 wfProfileOut( __METHOD__
);
1004 # If the article has been deleted while editing, don't save it without
1006 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate
) {
1007 $status->setResult( false, self
::AS_ARTICLE_WAS_DELETED
);
1008 wfProfileOut( __METHOD__
. '-checks' );
1009 wfProfileOut( __METHOD__
);
1013 wfProfileOut( __METHOD__
. '-checks' );
1015 # If article is new, insert it.
1016 $aid = $this->mTitle
->getArticleID( Title
::GAID_FOR_UPDATE
);
1017 $new = ( $aid == 0 );
1020 // Late check for create permission, just in case *PARANOIA*
1021 if ( !$this->mTitle
->userCan( 'create' ) ) {
1022 $status->fatal( 'nocreatetext' );
1023 $status->value
= self
::AS_NO_CREATE_PERMISSION
;
1024 wfDebug( __METHOD__
. ": no create permission\n" );
1025 wfProfileOut( __METHOD__
);
1029 # Don't save a new article if it's blank.
1030 if ( $this->textbox1
== '' ) {
1031 $status->setResult( false, self
::AS_BLANK_ARTICLE
);
1032 wfProfileOut( __METHOD__
);
1036 // Run post-section-merge edit filter
1037 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1
, &$this->hookError
, $this->summary
) ) ) {
1038 # Error messages etc. could be handled within the hook...
1039 $status->fatal( 'hookaborted' );
1040 $status->value
= self
::AS_HOOK_ERROR
;
1041 wfProfileOut( __METHOD__
);
1043 } elseif ( $this->hookError
!= '' ) {
1044 # ...or the hook could be expecting us to produce an error
1045 $status->fatal( 'hookaborted' );
1046 $status->value
= self
::AS_HOOK_ERROR_EXPECTED
;
1047 wfProfileOut( __METHOD__
);
1051 # Handle the user preference to force summaries here. Check if it's not a redirect.
1052 if ( !$this->allowBlankSummary
&& !Title
::newFromRedirect( $this->textbox1
) ) {
1053 if ( md5( $this->summary
) == $this->autoSumm
) {
1054 $this->missingSummary
= true;
1055 $status->fatal( 'missingsummary' ); // or 'missingcommentheader' if $section == 'new'. Blegh
1056 $status->value
= self
::AS_SUMMARY_NEEDED
;
1057 wfProfileOut( __METHOD__
);
1062 $text = $this->textbox1
;
1063 if ( $this->section
== 'new' && $this->summary
!= '' ) {
1064 $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary
) . "\n\n" . $text;
1067 $status->value
= self
::AS_SUCCESS_NEW_ARTICLE
;
1071 # Article exists. Check for edit conflict.
1073 $this->mArticle
->clear(); # Force reload of dates, etc.
1075 wfDebug( "timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n" );
1077 if ( $this->mArticle
->getTimestamp() != $this->edittime
) {
1078 $this->isConflict
= true;
1079 if ( $this->section
== 'new' ) {
1080 if ( $this->mArticle
->getUserText() == $wgUser->getName() &&
1081 $this->mArticle
->getComment() == $this->summary
) {
1082 // Probably a duplicate submission of a new comment.
1083 // This can happen when squid resends a request after
1084 // a timeout but the first one actually went through.
1085 wfDebug( __METHOD__
. ": duplicate new section submission; trigger edit conflict!\n" );
1087 // New comment; suppress conflict.
1088 $this->isConflict
= false;
1089 wfDebug( __METHOD__
.": conflict suppressed; new section\n" );
1091 } elseif ( $this->section
== '' && $this->userWasLastToEdit( $wgUser->getId(), $this->edittime
) ) {
1092 # Suppress edit conflict with self, except for section edits where merging is required.
1093 wfDebug( __METHOD__
. ": Suppressing edit conflict, same user.\n" );
1094 $this->isConflict
= false;
1098 if ( $this->isConflict
) {
1099 wfDebug( __METHOD__
. ": conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
1100 $this->mArticle
->getTimestamp() . "')\n" );
1101 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1103 wfDebug( __METHOD__
. ": getting section '$this->section'\n" );
1104 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
1106 if ( is_null( $text ) ) {
1107 wfDebug( __METHOD__
. ": activating conflict; section replace failed.\n" );
1108 $this->isConflict
= true;
1109 $text = $this->textbox1
; // do not try to merge here!
1110 } elseif ( $this->isConflict
) {
1112 if ( $this->mergeChangesInto( $text ) ) {
1113 // Successful merge! Maybe we should tell the user the good news?
1114 $this->isConflict
= false;
1115 wfDebug( __METHOD__
. ": Suppressing edit conflict, successful merge.\n" );
1117 $this->section
= '';
1118 $this->textbox1
= $text;
1119 wfDebug( __METHOD__
. ": Keeping edit conflict, failed merge.\n" );
1123 if ( $this->isConflict
) {
1124 $status->setResult( false, self
::AS_CONFLICT_DETECTED
);
1125 wfProfileOut( __METHOD__
);
1129 // Run post-section-merge edit filter
1130 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError
, $this->summary
) ) ) {
1131 # Error messages etc. could be handled within the hook...
1132 $status->fatal( 'hookaborted' );
1133 $status->value
= self
::AS_HOOK_ERROR
;
1134 wfProfileOut( __METHOD__
);
1136 } elseif ( $this->hookError
!= '' ) {
1137 # ...or the hook could be expecting us to produce an error
1138 $status->fatal( 'hookaborted' );
1139 $status->value
= self
::AS_HOOK_ERROR_EXPECTED
;
1140 wfProfileOut( __METHOD__
);
1144 # Handle the user preference to force summaries here, but not for null edits
1145 if ( $this->section
!= 'new' && !$this->allowBlankSummary
1146 && 0 != strcmp( $this->mArticle
->getContent(), $text )
1147 && !Title
::newFromRedirect( $text ) ) # check if it's not a redirect
1149 if ( md5( $this->summary
) == $this->autoSumm
) {
1150 $this->missingSummary
= true;
1151 $status->fatal( 'missingsummary' );
1152 $status->value
= self
::AS_SUMMARY_NEEDED
;
1153 wfProfileOut( __METHOD__
);
1158 # And a similar thing for new sections
1159 if ( $this->section
== 'new' && !$this->allowBlankSummary
) {
1160 if ( trim( $this->summary
) == '' ) {
1161 $this->missingSummary
= true;
1162 $status->fatal( 'missingsummary' ); // or 'missingcommentheader' if $section == 'new'. Blegh
1163 $status->value
= self
::AS_SUMMARY_NEEDED
;
1164 wfProfileOut( __METHOD__
);
1170 wfProfileIn( __METHOD__
. '-sectionanchor' );
1171 $sectionanchor = '';
1172 if ( $this->section
== 'new' ) {
1173 if ( $this->textbox1
== '' ) {
1174 $this->missingComment
= true;
1175 $status->fatal( 'missingcommenttext' );
1176 $status->value
= self
::AS_TEXTBOX_EMPTY
;
1177 wfProfileOut( __METHOD__
. '-sectionanchor' );
1178 wfProfileOut( __METHOD__
);
1181 if ( $this->summary
!= '' ) {
1182 $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->summary
);
1183 # This is a new section, so create a link to the new section
1184 # in the revision summary.
1185 $cleanSummary = $wgParser->stripSectionName( $this->summary
);
1186 $this->summary
= wfMsgForContent( 'newsectionsummary', $cleanSummary );
1188 } elseif ( $this->section
!= '' ) {
1189 # Try to get a section anchor from the section source, redirect to edited section if header found
1190 # XXX: might be better to integrate this into Article::replaceSection
1191 # for duplicate heading checking and maybe parsing
1192 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
1193 # we can't deal with anchors, includes, html etc in the header for now,
1194 # headline would need to be parsed to improve this
1195 if ( $hasmatch && strlen( $matches[2] ) > 0 ) {
1196 $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $matches[2] );
1199 $result['sectionanchor'] = $sectionanchor;
1200 wfProfileOut( __METHOD__
. '-sectionanchor' );
1202 // Save errors may fall down to the edit form, but we've now
1203 // merged the section into full text. Clear the section field
1204 // so that later submission of conflict forms won't try to
1205 // replace that into a duplicated mess.
1206 $this->textbox1
= $text;
1207 $this->section
= '';
1209 $status->value
= self
::AS_SUCCESS_UPDATE
;
1212 // Check for length errors again now that the section is merged in
1213 $this->kblength
= (int)( strlen( $text ) / 1024 );
1214 if ( $this->kblength
> $wgMaxArticleSize ) {
1215 $this->tooBig
= true;
1216 $status->setResult( false, self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
);
1217 wfProfileOut( __METHOD__
);
1221 $flags = EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
1222 ( $new ? EDIT_NEW
: EDIT_UPDATE
) |
1223 ( ( $this->minoredit
&& !$this->isNew
) ? EDIT_MINOR
: 0 ) |
1224 ( $bot ? EDIT_FORCE_BOT
: 0 );
1226 $doEditStatus = $this->mArticle
->doEdit( $text, $this->summary
, $flags );
1228 if ( $doEditStatus->isOK() ) {
1229 $result['redirect'] = Title
::newFromRedirect( $text ) !== null;
1230 $this->commitWatch();
1231 wfProfileOut( __METHOD__
);
1234 $this->isConflict
= true;
1235 $doEditStatus->value
= self
::AS_END
; // Destroys data doEdit() put in $status->value but who cares
1236 wfProfileOut( __METHOD__
);
1237 return $doEditStatus;
1242 * Commit the change of watch status
1244 protected function commitWatch() {
1246 if ( $this->watchthis
xor $this->mTitle
->userIsWatching() ) {
1247 $dbw = wfGetDB( DB_MASTER
);
1249 if ( $this->watchthis
) {
1250 WatchAction
::doWatch( $this->mTitle
, $wgUser );
1252 WatchAction
::doUnwatch( $this->mTitle
, $wgUser );
1259 * Check if no edits were made by other users since
1260 * the time a user started editing the page. Limit to
1261 * 50 revisions for the sake of performance.
1264 * @param $edittime string
1268 protected function userWasLastToEdit( $id, $edittime ) {
1269 if( !$id ) return false;
1270 $dbw = wfGetDB( DB_MASTER
);
1271 $res = $dbw->select( 'revision',
1274 'rev_page' => $this->mArticle
->getId(),
1275 'rev_timestamp > '.$dbw->addQuotes( $dbw->timestamp($edittime) )
1278 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
1279 foreach ( $res as $row ) {
1280 if( $row->rev_user
!= $id ) {
1288 * Check given input text against $wgSpamRegex, and return the text of the first match.
1290 * @param $text string
1292 * @return string|false matching string or false
1294 public static function matchSpamRegex( $text ) {
1295 global $wgSpamRegex;
1296 // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
1297 $regexes = (array)$wgSpamRegex;
1298 return self
::matchSpamRegexInternal( $text, $regexes );
1302 * Check given input text against $wgSpamRegex, and return the text of the first match.
1304 * @parma $text string
1306 * @return string|false matching string or false
1308 public static function matchSummarySpamRegex( $text ) {
1309 global $wgSummarySpamRegex;
1310 $regexes = (array)$wgSummarySpamRegex;
1311 return self
::matchSpamRegexInternal( $text, $regexes );
1315 * @param $text string
1316 * @param $regexes array
1317 * @return bool|string
1319 protected static function matchSpamRegexInternal( $text, $regexes ) {
1320 foreach( $regexes as $regex ) {
1322 if( preg_match( $regex, $text, $matches ) ) {
1330 * Initialise form fields in the object
1331 * Called on the first invocation, e.g. when a user clicks an edit link
1332 * @return bool -- if the requested section is valid
1334 function initialiseForm() {
1336 $this->edittime
= $this->mArticle
->getTimestamp();
1337 $this->textbox1
= $this->getContent( false );
1338 // activate checkboxes if user wants them to be always active
1339 # Sort out the "watch" checkbox
1340 if ( $wgUser->getOption( 'watchdefault' ) ) {
1342 $this->watchthis
= true;
1343 } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
1345 $this->watchthis
= true;
1346 } elseif ( $this->mTitle
->userIsWatching() ) {
1348 $this->watchthis
= true;
1350 if ( $wgUser->getOption( 'minordefault' ) && !$this->isNew
) {
1351 $this->minoredit
= true;
1353 if ( $this->textbox1
=== false ) {
1360 function setHeaders() {
1362 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1363 if ( $this->isConflict
) {
1364 $wgOut->setPageTitle( wfMessage( 'editconflict', $this->getContextTitle()->getPrefixedText() ) );
1365 } elseif ( $this->section
!= '' ) {
1366 $msg = $this->section
== 'new' ?
'editingcomment' : 'editingsection';
1367 $wgOut->setPageTitle( wfMessage( $msg, $this->getContextTitle()->getPrefixedText() ) );
1369 # Use the title defined by DISPLAYTITLE magic word when present
1370 if ( isset( $this->mParserOutput
)
1371 && ( $dt = $this->mParserOutput
->getDisplayTitle() ) !== false ) {
1374 $title = $this->getContextTitle()->getPrefixedText();
1376 $wgOut->setPageTitle( wfMessage( 'editing', $title ) );
1381 * Send the edit form and related headers to $wgOut
1382 * @param $formCallback Callback that takes an OutputPage parameter; will be called
1383 * during form output near the top, for captchas and the like.
1385 function showEditForm( $formCallback = null ) {
1386 global $wgOut, $wgUser;
1388 wfProfileIn( __METHOD__
);
1390 #need to parse the preview early so that we know which templates are used,
1391 #otherwise users with "show preview after edit box" will get a blank list
1392 #we parse this near the beginning so that setHeaders can do the title
1393 #setting work instead of leaving it in getPreviewText
1394 $previewOutput = '';
1395 if ( $this->formtype
== 'preview' ) {
1396 $previewOutput = $this->getPreviewText();
1399 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) );
1401 $this->setHeaders();
1403 # Enabled article-related sidebar, toplinks, etc.
1404 $wgOut->setArticleRelated( true );
1406 if ( $this->showHeader() === false ) {
1407 wfProfileOut( __METHOD__
);
1411 $action = htmlspecialchars( $this->getActionURL( $this->getContextTitle() ) );
1413 if ( $wgUser->getOption( 'showtoolbar' ) and !$this->isCssJsSubpage
) {
1414 # prepare toolbar for edit buttons
1415 $toolbar = EditPage
::getEditToolbar();
1421 $wgOut->addHTML( $this->editFormPageTop
);
1423 if ( $wgUser->getOption( 'previewontop' ) ) {
1424 $this->displayPreviewArea( $previewOutput, true );
1427 $wgOut->addHTML( $this->editFormTextTop
);
1429 $templates = $this->getTemplates();
1430 $formattedtemplates = Linker
::formatTemplates( $templates, $this->preview
, $this->section
!= '');
1432 $hiddencats = $this->mArticle
->getHiddenCategories();
1433 $formattedhiddencats = Linker
::formatHiddenCategories( $hiddencats );
1435 if ( $this->wasDeletedSinceLastEdit() && 'save' != $this->formtype
) {
1436 $wgOut->wrapWikiMsg(
1437 "<div class='error mw-deleted-while-editing'>\n$1\n</div>",
1438 'deletedwhileediting' );
1439 } elseif ( $this->wasDeletedSinceLastEdit() ) {
1440 // Hide the toolbar and edit area, user can click preview to get it back
1441 // Add an confirmation checkbox and explanation.
1443 // @todo move this to a cleaner conditional instead of blanking a variable
1445 $wgOut->addHTML( <<<HTML
1446 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1450 if ( is_callable( $formCallback ) ) {
1451 call_user_func_array( $formCallback, array( &$wgOut ) );
1454 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1456 // Put these up at the top to ensure they aren't lost on early form submission
1457 $this->showFormBeforeText();
1459 if ( $this->wasDeletedSinceLastEdit() && 'save' == $this->formtype
) {
1460 $username = $this->lastDelete
->user_name
;
1461 $comment = $this->lastDelete
->log_comment
;
1463 // It is better to not parse the comment at all than to have templates expanded in the middle
1464 // TODO: can the checkLabel be moved outside of the div so that wrapWikiMsg could be used?
1465 $key = $comment === ''
1466 ?
'confirmrecreate-noreason'
1467 : 'confirmrecreate';
1469 '<div class="mw-confirm-recreate">' .
1470 wfMsgExt( $key, 'parseinline', $username, "<nowiki>$comment</nowiki>" ) .
1471 Xml
::checkLabel( wfMsg( 'recreate' ), 'wpRecreate', 'wpRecreate', false,
1472 array( 'title' => Linker
::titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' )
1478 # If a blank edit summary was previously provided, and the appropriate
1479 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1480 # user being bounced back more than once in the event that a summary
1483 # For a bit more sophisticated detection of blank summaries, hash the
1484 # automatic one and pass that in the hidden field wpAutoSummary.
1485 if ( $this->missingSummary ||
1486 ( $this->section
== 'new' && $this->nosummary
) )
1487 $wgOut->addHTML( Html
::hidden( 'wpIgnoreBlankSummary', true ) );
1488 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
1489 $wgOut->addHTML( Html
::hidden( 'wpAutoSummary', $autosumm ) );
1491 $wgOut->addHTML( Html
::hidden( 'oldid', $this->mArticle
->getOldID() ) );
1493 if ( $this->section
== 'new' ) {
1494 $this->showSummaryInput( true, $this->summary
);
1495 $wgOut->addHTML( $this->getSummaryPreview( true, $this->summary
) );
1498 $wgOut->addHTML( $this->editFormTextBeforeContent
);
1500 $wgOut->addHTML( $toolbar );
1502 if ( $this->isConflict
) {
1503 // In an edit conflict bypass the overrideable content form method
1504 // and fallback to the raw wpTextbox1 since editconflicts can't be
1505 // resolved between page source edits and custom ui edits using the
1507 $this->showTextbox1( null, $this->getContent() );
1509 $this->showContentForm();
1512 $wgOut->addHTML( $this->editFormTextAfterContent
);
1514 $wgOut->addWikiText( $this->getCopywarn() );
1515 if ( isset($this->editFormTextAfterWarn
) && $this->editFormTextAfterWarn
!== '' )
1516 $wgOut->addHTML( $this->editFormTextAfterWarn
);
1518 $this->showStandardInputs();
1520 $this->showFormAfterText();
1522 $this->showTosSummary();
1523 $this->showEditTools();
1525 $wgOut->addHTML( <<<HTML
1526 {$this->editFormTextAfterTools}
1527 <div class='templatesUsed'>
1528 {$formattedtemplates}
1530 <div class='hiddencats'>
1531 {$formattedhiddencats}
1536 if ( $this->isConflict
)
1537 $this->showConflict();
1539 $wgOut->addHTML( $this->editFormTextBottom
);
1540 $wgOut->addHTML( "</form>\n" );
1541 if ( !$wgUser->getOption( 'previewontop' ) ) {
1542 $this->displayPreviewArea( $previewOutput, false );
1545 wfProfileOut( __METHOD__
);
1548 protected function showHeader() {
1549 global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang;
1550 if ( $this->isConflict
) {
1551 $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
1552 $this->edittime
= $this->mArticle
->getTimestamp();
1554 if ( $this->section
!= '' && !$this->isSectionEditSupported() ) {
1555 // We use $this->section to much before this and getVal('wgSection') directly in other places
1556 // at this point we can't reset $this->section to '' to fallback to non-section editing.
1557 // Someone is welcome to try refactoring though
1558 $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
1562 if ( $this->section
!= '' && $this->section
!= 'new' ) {
1564 if ( !$this->summary
&& !$this->preview
&& !$this->diff
) {
1565 preg_match( "/^(=+)(.+)\\1/mi", $this->textbox1
, $matches );
1566 if ( !empty( $matches[2] ) ) {
1568 $this->summary
= "/* " .
1569 $wgParser->stripSectionName(trim($matches[2])) .
1575 if ( $this->missingComment
) {
1576 $wgOut->wrapWikiMsg( "<div id='mw-missingcommenttext'>\n$1\n</div>", 'missingcommenttext' );
1579 if ( $this->missingSummary
&& $this->section
!= 'new' ) {
1580 $wgOut->wrapWikiMsg( "<div id='mw-missingsummary'>\n$1\n</div>", 'missingsummary' );
1583 if ( $this->missingSummary
&& $this->section
== 'new' ) {
1584 $wgOut->wrapWikiMsg( "<div id='mw-missingcommentheader'>\n$1\n</div>", 'missingcommentheader' );
1587 if ( $this->hookError
!== '' ) {
1588 $wgOut->addWikiText( $this->hookError
);
1591 if ( !$this->checkUnicodeCompliantBrowser() ) {
1592 $wgOut->addWikiMsg( 'nonunicodebrowser' );
1595 if ( isset( $this->mArticle
) && isset( $this->mArticle
->mRevision
) ) {
1596 // Let sysop know that this will make private content public if saved
1598 if ( !$this->mArticle
->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1599 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-permission' );
1600 } elseif ( $this->mArticle
->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1601 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-view' );
1604 if ( !$this->mArticle
->mRevision
->isCurrent() ) {
1605 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
1606 $wgOut->addWikiMsg( 'editingold' );
1611 if ( wfReadOnly() ) {
1612 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
1613 } elseif ( $wgUser->isAnon() ) {
1614 if ( $this->formtype
!= 'preview' ) {
1615 $wgOut->wrapWikiMsg( "<div id=\"mw-anon-edit-warning\">\n$1</div>", 'anoneditwarning' );
1617 $wgOut->wrapWikiMsg( "<div id=\"mw-anon-preview-warning\">\n$1</div>", 'anonpreviewwarning' );
1620 if ( $this->isCssJsSubpage
) {
1621 # Check the skin exists
1622 if ( $this->isWrongCaseCssJsPage
) {
1623 $wgOut->wrapWikiMsg( "<div class='error' id='mw-userinvalidcssjstitle'>\n$1\n</div>", array( 'userinvalidcssjstitle', $this->mTitle
->getSkinFromCssJsSubpage() ) );
1625 if ( $this->formtype
!== 'preview' ) {
1626 if ( $this->isCssSubpage
)
1627 $wgOut->wrapWikiMsg( "<div id='mw-usercssyoucanpreview'>\n$1\n</div>", array( 'usercssyoucanpreview' ) );
1628 if ( $this->isJsSubpage
)
1629 $wgOut->wrapWikiMsg( "<div id='mw-userjsyoucanpreview'>\n$1\n</div>", array( 'userjsyoucanpreview' ) );
1634 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
1635 # Is the title semi-protected?
1636 if ( $this->mTitle
->isSemiProtected() ) {
1637 $noticeMsg = 'semiprotectedpagewarning';
1639 # Then it must be protected based on static groups (regular)
1640 $noticeMsg = 'protectedpagewarning';
1642 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
, '',
1643 array( 'lim' => 1, 'msgKey' => array( $noticeMsg ) ) );
1645 if ( $this->mTitle
->isCascadeProtected() ) {
1646 # Is this page under cascading protection from some source pages?
1647 list($cascadeSources, /* $restrictions */) = $this->mTitle
->getCascadeProtectionSources();
1648 $notice = "<div class='mw-cascadeprotectedwarning'>\n$1\n";
1649 $cascadeSourcesCount = count( $cascadeSources );
1650 if ( $cascadeSourcesCount > 0 ) {
1651 # Explain, and list the titles responsible
1652 foreach( $cascadeSources as $page ) {
1653 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1656 $notice .= '</div>';
1657 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', $cascadeSourcesCount ) );
1659 if ( !$this->mTitle
->exists() && $this->mTitle
->getRestrictions( 'create' ) ) {
1660 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
, '',
1662 'showIfEmpty' => false,
1663 'msgKey' => array( 'titleprotectedwarning' ),
1664 'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ) );
1667 if ( $this->kblength
=== false ) {
1668 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
1671 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
1672 $wgOut->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
1673 array( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgLang->formatNum( $wgMaxArticleSize ) ) );
1675 if( !wfMessage('longpage-hint')->isDisabled() ) {
1676 $wgOut->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
1677 array( 'longpage-hint', $wgLang->formatSize( strlen( $this->textbox1
) ), strlen( $this->textbox1
) )
1684 * Standard summary input and label (wgSummary), abstracted so EditPage
1685 * subclasses may reorganize the form.
1686 * Note that you do not need to worry about the label's for=, it will be
1687 * inferred by the id given to the input. You can remove them both by
1688 * passing array( 'id' => false ) to $userInputAttrs.
1690 * @param $summary string The value of the summary input
1691 * @param $labelText string The html to place inside the label
1692 * @param $inputAttrs array of attrs to use on the input
1693 * @param $spanLabelAttrs array of attrs to use on the span inside the label
1695 * @return array An array in the format array( $label, $input )
1697 function getSummaryInput($summary = "", $labelText = null, $inputAttrs = null, $spanLabelAttrs = null) {
1698 //Note: the maxlength is overriden in JS to 250 and to make it use UTF-8 bytes, not characters.
1699 $inputAttrs = ( is_array($inputAttrs) ?
$inputAttrs : array() ) +
array(
1700 'id' => 'wpSummary',
1701 'maxlength' => '200',
1704 'spellcheck' => 'true',
1705 ) + Linker
::tooltipAndAccesskeyAttribs( 'summary' );
1707 $spanLabelAttrs = ( is_array($spanLabelAttrs) ?
$spanLabelAttrs : array() ) +
array(
1708 'class' => $this->missingSummary ?
'mw-summarymissed' : 'mw-summary',
1709 'id' => "wpSummaryLabel"
1714 $label = Xml
::tags( 'label', $inputAttrs['id'] ?
array( 'for' => $inputAttrs['id'] ) : null, $labelText );
1715 $label = Xml
::tags( 'span', $spanLabelAttrs, $label );
1718 $input = Html
::input( 'wpSummary', $summary, 'text', $inputAttrs );
1720 return array( $label, $input );
1724 * @param $isSubjectPreview Boolean: true if this is the section subject/title
1725 * up top, or false if this is the comment summary
1726 * down below the textarea
1727 * @param $summary String: The text of the summary to display
1730 protected function showSummaryInput( $isSubjectPreview, $summary = "" ) {
1731 global $wgOut, $wgContLang;
1732 # Add a class if 'missingsummary' is triggered to allow styling of the summary line
1733 $summaryClass = $this->missingSummary ?
'mw-summarymissed' : 'mw-summary';
1734 if ( $isSubjectPreview ) {
1735 if ( $this->nosummary
) {
1739 if ( !$this->mShowSummaryField
) {
1743 $summary = $wgContLang->recodeForEdit( $summary );
1744 $labelText = wfMsgExt( $isSubjectPreview ?
'subject' : 'summary', 'parseinline' );
1745 list($label, $input) = $this->getSummaryInput($summary, $labelText, array( 'class' => $summaryClass ), array());
1746 $wgOut->addHTML("{$label} {$input}");
1750 * @param $isSubjectPreview Boolean: true if this is the section subject/title
1751 * up top, or false if this is the comment summary
1752 * down below the textarea
1753 * @param $summary String: the text of the summary to display
1756 protected function getSummaryPreview( $isSubjectPreview, $summary = "" ) {
1757 if ( !$summary ||
( !$this->preview
&& !$this->diff
) )
1762 if ( $isSubjectPreview )
1763 $summary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $summary ) );
1765 $message = $isSubjectPreview ?
'subject-preview' : 'summary-preview';
1767 $summary = wfMsgExt( $message, 'parseinline' ) . Linker
::commentBlock( $summary, $this->mTitle
, $isSubjectPreview );
1768 return Xml
::tags( 'div', array( 'class' => 'mw-summary-preview' ), $summary );
1771 protected function showFormBeforeText() {
1773 $section = htmlspecialchars( $this->section
);
1774 $wgOut->addHTML( <<<HTML
1775 <input type='hidden' value="{$section}" name="wpSection" />
1776 <input type='hidden' value="{$this->starttime}" name="wpStarttime" />
1777 <input type='hidden' value="{$this->edittime}" name="wpEdittime" />
1778 <input type='hidden' value="{$this->scrolltop}" name="wpScrolltop" id="wpScrolltop" />
1782 if ( !$this->checkUnicodeCompliantBrowser() )
1783 $wgOut->addHTML(Html
::hidden( 'safemode', '1' ));
1786 protected function showFormAfterText() {
1787 global $wgOut, $wgUser;
1789 * To make it harder for someone to slip a user a page
1790 * which submits an edit form to the wiki without their
1791 * knowledge, a random token is associated with the login
1792 * session. If it's not passed back with the submission,
1793 * we won't save the page, or render user JavaScript and
1796 * For anon editors, who may not have a session, we just
1797 * include the constant suffix to prevent editing from
1798 * broken text-mangling proxies.
1800 $wgOut->addHTML( "\n" . Html
::hidden( "wpEditToken", $wgUser->editToken() ) . "\n" );
1804 * Subpage overridable method for printing the form for page content editing
1805 * By default this simply outputs wpTextbox1
1806 * Subclasses can override this to provide a custom UI for editing;
1807 * be it a form, or simply wpTextbox1 with a modified content that will be
1808 * reverse modified when extracted from the post data.
1809 * Note that this is basically the inverse for importContentFormData
1811 protected function showContentForm() {
1812 $this->showTextbox1();
1816 * Method to output wpTextbox1
1817 * The $textoverride method can be used by subclasses overriding showContentForm
1818 * to pass back to this method.
1820 * @param $customAttribs An array of html attributes to use in the textarea
1821 * @param $textoverride String: optional text to override $this->textarea1 with
1823 protected function showTextbox1($customAttribs = null, $textoverride = null) {
1824 $classes = array(); // Textarea CSS
1825 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
1826 # Is the title semi-protected?
1827 if ( $this->mTitle
->isSemiProtected() ) {
1828 $classes[] = 'mw-textarea-sprotected';
1830 # Then it must be protected based on static groups (regular)
1831 $classes[] = 'mw-textarea-protected';
1833 # Is the title cascade-protected?
1834 if ( $this->mTitle
->isCascadeProtected() ) {
1835 $classes[] = 'mw-textarea-cprotected';
1838 $attribs = array( 'tabindex' => 1 );
1839 if ( is_array($customAttribs) )
1840 $attribs +
= $customAttribs;
1842 if ( $this->wasDeletedSinceLastEdit() )
1843 $attribs['type'] = 'hidden';
1844 if ( !empty( $classes ) ) {
1845 if ( isset($attribs['class']) )
1846 $classes[] = $attribs['class'];
1847 $attribs['class'] = implode( ' ', $classes );
1850 $this->showTextbox( isset($textoverride) ?
$textoverride : $this->textbox1
, 'wpTextbox1', $attribs );
1853 protected function showTextbox2() {
1854 $this->showTextbox( $this->textbox2
, 'wpTextbox2', array( 'tabindex' => 6, 'readonly' ) );
1857 protected function showTextbox( $content, $name, $customAttribs = array() ) {
1858 global $wgOut, $wgUser;
1860 $wikitext = $this->safeUnicodeOutput( $content );
1861 if ( strval($wikitext) !== '' ) {
1862 // Ensure there's a newline at the end, otherwise adding lines
1864 // But don't add a newline if the ext is empty, or Firefox in XHTML
1865 // mode will show an extra newline. A bit annoying.
1869 $attribs = $customAttribs +
array(
1872 'cols' => $wgUser->getIntOption( 'cols' ),
1873 'rows' => $wgUser->getIntOption( 'rows' ),
1874 'style' => '' // avoid php notices when appending preferences (appending allows customAttribs['style'] to still work
1877 $pageLang = $this->mTitle
->getPageLanguage();
1878 $attribs['lang'] = $pageLang->getCode();
1879 $attribs['dir'] = $pageLang->getDir();
1881 $wgOut->addHTML( Html
::textarea( $name, $wikitext, $attribs ) );
1884 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
1888 $classes[] = 'ontop';
1890 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
1892 if ( $this->formtype
!= 'preview' )
1893 $attribs['style'] = 'display: none;';
1895 $wgOut->addHTML( Xml
::openElement( 'div', $attribs ) );
1897 if ( $this->formtype
== 'preview' ) {
1898 $this->showPreview( $previewOutput );
1901 $wgOut->addHTML( '</div>' );
1903 if ( $this->formtype
== 'diff') {
1909 * Append preview output to $wgOut.
1910 * Includes category rendering if this is a category page.
1912 * @param $text String: the HTML to be output for the preview.
1914 protected function showPreview( $text ) {
1916 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1917 $this->mArticle
->openShowCategory();
1919 # This hook seems slightly odd here, but makes things more
1920 # consistent for extensions.
1921 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1922 $wgOut->addHTML( $text );
1923 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1924 $this->mArticle
->closeShowCategory();
1929 * Give a chance for site and per-namespace customizations of
1930 * terms of service summary link that might exist separately
1931 * from the copyright notice.
1933 * This will display between the save button and the edit tools,
1934 * so should remain short!
1936 protected function showTosSummary() {
1937 $msg = 'editpage-tos-summary';
1938 wfRunHooks( 'EditPageTosSummary', array( $this->mTitle
, &$msg ) );
1939 if( !wfMessage( $msg )->isDisabled() ) {
1941 $wgOut->addHTML( '<div class="mw-tos-summary">' );
1942 $wgOut->addWikiMsg( $msg );
1943 $wgOut->addHTML( '</div>' );
1947 protected function showEditTools() {
1949 $wgOut->addHTML( '<div class="mw-editTools">' .
1950 wfMessage( 'edittools' )->inContentLanguage()->parse() .
1954 protected function getCopywarn() {
1955 global $wgRightsText;
1956 if ( $wgRightsText ) {
1957 $copywarnMsg = array( 'copyrightwarning',
1958 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1961 $copywarnMsg = array( 'copyrightwarning2',
1962 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
1964 // Allow for site and per-namespace customization of contribution/copyright notice.
1965 wfRunHooks( 'EditPageCopyrightWarning', array( $this->mTitle
, &$copywarnMsg ) );
1967 return "<div id=\"editpage-copywarn\">\n" .
1968 call_user_func_array("wfMsgNoTrans", $copywarnMsg) . "\n</div>";
1971 protected function showStandardInputs( &$tabindex = 2 ) {
1973 $wgOut->addHTML( "<div class='editOptions'>\n" );
1975 if ( $this->section
!= 'new' ) {
1976 $this->showSummaryInput( false, $this->summary
);
1977 $wgOut->addHTML( $this->getSummaryPreview( false, $this->summary
) );
1980 $checkboxes = $this->getCheckboxes( $tabindex,
1981 array( 'minor' => $this->minoredit
, 'watch' => $this->watchthis
) );
1982 $wgOut->addHTML( "<div class='editCheckboxes'>" . implode( $checkboxes, "\n" ) . "</div>\n" );
1983 $wgOut->addHTML( "<div class='editButtons'>\n" );
1984 $wgOut->addHTML( implode( $this->getEditButtons( $tabindex ), "\n" ) . "\n" );
1986 $cancel = $this->getCancelLink();
1987 if ( $cancel !== '' ) {
1988 $cancel .= wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1990 $edithelpurl = Skin
::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ) );
1991 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1992 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1993 htmlspecialchars( wfMsg( 'newwindow' ) );
1994 $wgOut->addHTML( " <span class='editHelp'>{$cancel}{$edithelp}</span>\n" );
1995 $wgOut->addHTML( "</div><!-- editButtons -->\n</div><!-- editOptions -->\n" );
1999 * Show an edit conflict. textbox1 is already shown in showEditForm().
2000 * If you want to use another entry point to this function, be careful.
2002 protected function showConflict() {
2004 $this->textbox2
= $this->textbox1
;
2005 $this->textbox1
= $this->getContent();
2006 if ( wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
2007 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
2009 $de = new DifferenceEngine( $this->mTitle
);
2010 $de->setText( $this->textbox2
, $this->textbox1
);
2011 $de->showDiff( wfMsgExt( 'yourtext', 'parseinline' ), wfMsg( 'storedversion' ) );
2013 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
2014 $this->showTextbox2();
2018 protected function getLastDelete() {
2019 $dbr = wfGetDB( DB_SLAVE
);
2020 $data = $dbr->selectRow(
2021 array( 'logging', 'user' ),
2032 array( 'log_namespace' => $this->mTitle
->getNamespace(),
2033 'log_title' => $this->mTitle
->getDBkey(),
2034 'log_type' => 'delete',
2035 'log_action' => 'delete',
2036 'user_id=log_user' ),
2038 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' )
2040 // Quick paranoid permission checks...
2041 if( is_object( $data ) ) {
2042 if( $data->log_deleted
& LogPage
::DELETED_USER
)
2043 $data->user_name
= wfMsgHtml( 'rev-deleted-user' );
2044 if( $data->log_deleted
& LogPage
::DELETED_COMMENT
)
2045 $data->log_comment
= wfMsgHtml( 'rev-deleted-comment' );
2051 * Get the rendered text for previewing.
2054 function getPreviewText() {
2055 global $wgOut, $wgUser, $wgParser;
2057 wfProfileIn( __METHOD__
);
2059 if ( $this->mTriedSave
&& !$this->mTokenOk
) {
2060 if ( $this->mTokenOkExceptSuffix
) {
2061 $note = wfMsg( 'token_suffix_mismatch' );
2063 $note = wfMsg( 'session_fail_preview' );
2065 } elseif ( $this->incompleteForm
) {
2066 $note = wfMsg( 'edit_form_incomplete' );
2068 $note = wfMsg( 'previewnote' );
2071 $parserOptions = ParserOptions
::newFromUser( $wgUser );
2072 $parserOptions->setEditSection( false );
2073 $parserOptions->setIsPreview( true );
2074 $parserOptions->setIsSectionPreview( !is_null($this->section
) && $this->section
!== '' );
2077 if ( $wgRawHtml && !$this->mTokenOk
) {
2078 // Could be an offsite preview attempt. This is very unsafe if
2079 // HTML is enabled, as it could be an attack.
2081 if ( $this->textbox1
!== '' ) {
2082 // Do not put big scary notice, if previewing the empty
2083 // string, which happens when you initially edit
2084 // a category page, due to automatic preview-on-open.
2085 $parsedNote = $wgOut->parse( "<div class='previewnote'>" .
2086 wfMsg( 'session_fail_preview_html' ) . "</div>", true, /* interface */true );
2088 wfProfileOut( __METHOD__
);
2092 # don't parse non-wikitext pages, show message about preview
2093 # 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?
2095 if ( $this->isCssJsSubpage ||
!$this->mTitle
->isWikitextPage() ) {
2096 if( $this->mTitle
->isCssJsSubpage() ) {
2098 } elseif( $this->mTitle
->isCssOrJsPage() ) {
2104 # Used messages to make sure grep find them:
2105 # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
2107 if (preg_match( "/\\.css$/", $this->mTitle
->getText() ) ) {
2108 $previewtext = "<div id='mw-{$level}csspreview'>\n" . wfMsg( "{$level}csspreview" ) . "\n</div>";
2109 $class = "mw-code mw-css";
2110 } elseif (preg_match( "/\\.js$/", $this->mTitle
->getText() ) ) {
2111 $previewtext = "<div id='mw-{$level}jspreview'>\n" . wfMsg( "{$level}jspreview" ) . "\n</div>";
2112 $class = "mw-code mw-js";
2114 throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' );
2118 $parserOptions->setTidy( true );
2119 $parserOutput = $wgParser->parse( $previewtext, $this->mTitle
, $parserOptions );
2120 $previewHTML = $parserOutput->mText
;
2121 $previewHTML .= "<pre class=\"$class\" dir=\"ltr\">\n" . htmlspecialchars( $this->textbox1
) . "\n</pre>\n";
2123 $rt = Title
::newFromRedirectArray( $this->textbox1
);
2125 $previewHTML = $this->mArticle
->viewRedirect( $rt, false );
2127 $toparse = $this->textbox1
;
2129 # If we're adding a comment, we need to show the
2130 # summary as the headline
2131 if ( $this->section
== "new" && $this->summary
!= "" ) {
2132 $toparse = "== {$this->summary} ==\n\n" . $toparse;
2135 wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
2137 $parserOptions->setTidy( true );
2138 $parserOptions->enableLimitReport();
2139 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ),
2140 $this->mTitle
, $parserOptions );
2142 $previewHTML = $parserOutput->getText();
2143 $this->mParserOutput
= $parserOutput;
2144 $wgOut->addParserOutputNoText( $parserOutput );
2146 if ( count( $parserOutput->getWarnings() ) ) {
2147 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
2152 if( $this->isConflict
) {
2153 $conflict = '<h2 id="mw-previewconflict">' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
2155 $conflict = '<hr />';
2158 $previewhead = "<div class='previewnote'>\n" .
2159 '<h2 id="mw-previewheader">' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>" .
2160 $wgOut->parse( $note, true, /* interface */true ) . $conflict . "</div>\n";
2162 $pageLang = $this->mTitle
->getPageLanguage();
2163 $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
2164 'class' => 'mw-content-'.$pageLang->getDir() );
2165 $previewHTML = Html
::rawElement( 'div', $attribs, $previewHTML );
2167 wfProfileOut( __METHOD__
);
2168 return $previewhead . $previewHTML . $this->previewTextAfterContent
;
2174 function getTemplates() {
2175 if ( $this->preview ||
$this->section
!= '' ) {
2176 $templates = array();
2177 if ( !isset( $this->mParserOutput
) ) {
2180 foreach( $this->mParserOutput
->getTemplates() as $ns => $template) {
2181 foreach( array_keys( $template ) as $dbk ) {
2182 $templates[] = Title
::makeTitle($ns, $dbk);
2187 return $this->mArticle
->getUsedTemplates();
2192 * Call the stock "user is blocked" page
2194 function blockedPage() {
2196 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
2198 # If the user made changes, preserve them when showing the markup
2199 # (This happens when a user is blocked during edit, for instance)
2200 $first = $this->firsttime ||
( !$this->save
&& $this->textbox1
== '' );
2202 $source = $this->mTitle
->exists() ?
$this->getContent() : false;
2204 $source = $this->textbox1
;
2207 # Spit out the source or the user's modified version
2208 if ( $source !== false ) {
2209 $wgOut->addHTML( '<hr />' );
2210 $wgOut->addWikiMsg( $first ?
'blockedoriginalsource' : 'blockededitsource', $this->mTitle
->getPrefixedText() );
2211 $this->showTextbox1( array( 'readonly' ), $source );
2216 * Produce the stock "please login to edit pages" page
2218 function userNotLoggedInPage() {
2221 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
2222 $loginLink = Linker
::linkKnown(
2224 wfMsgHtml( 'loginreqlink' ),
2226 array( 'returnto' => $this->getContextTitle()->getPrefixedText() )
2229 $wgOut->setPageTitle( wfMessage( 'whitelistedittitle' ) );
2230 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2231 $wgOut->setArticleRelated( false );
2233 $wgOut->addHTML( wfMessage( 'whitelistedittext' )->rawParams( $loginLink )->parse() );
2234 $wgOut->returnToMain( false, $this->getContextTitle() );
2238 * Creates a basic error page which informs the user that
2239 * they have attempted to edit a nonexistent section.
2241 function noSuchSectionPage() {
2244 $wgOut->setPageTitle( wfMessage( 'nosuchsectiontitle' ) );
2245 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2246 $wgOut->setArticleRelated( false );
2248 $res = wfMsgExt( 'nosuchsectiontext', 'parse', $this->section
);
2249 wfRunHooks( 'EditPageNoSuchSection', array( &$this, &$res ) );
2250 $wgOut->addHTML( $res );
2252 $wgOut->returnToMain( false, $this->mTitle
);
2256 * Produce the stock "your edit contains spam" page
2258 * @param $match Text which triggered one or more filters
2259 * @deprecated since 1.17 Use method spamPageWithContent() instead
2261 static function spamPage( $match = false ) {
2262 global $wgOut, $wgTitle;
2264 $wgOut->setPageTitle( wfMessage( 'spamprotectiontitle' ) );
2265 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2266 $wgOut->setArticleRelated( false );
2268 $wgOut->addHTML( '<div id="spamprotected">' );
2269 $wgOut->addWikiMsg( 'spamprotectiontext' );
2271 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
2273 $wgOut->addHTML( '</div>' );
2275 $wgOut->returnToMain( false, $wgTitle );
2279 * Show "your edit contains spam" page with your diff and text
2281 * @param $match Text which triggered one or more filters
2283 public function spamPageWithContent( $match = false ) {
2285 $this->textbox2
= $this->textbox1
;
2287 $wgOut->setPageTitle( wfMessage( 'spamprotectiontitle' ) );
2288 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2289 $wgOut->setArticleRelated( false );
2291 $wgOut->addHTML( '<div id="spamprotected">' );
2292 $wgOut->addWikiMsg( 'spamprotectiontext' );
2294 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
2296 $wgOut->addHTML( '</div>' );
2298 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
2299 $de = new DifferenceEngine( $this->mTitle
);
2300 $de->setText( $this->getContent(), $this->textbox2
);
2301 $de->showDiff( wfMsg( "storedversion" ), wfMsgExt( 'yourtext', 'parseinline' ) );
2303 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
2304 $this->showTextbox2();
2306 $wgOut->addReturnTo( $this->getContextTitle(), array( 'action' => 'edit' ) );
2314 * @parma $editText string
2318 function mergeChangesInto( &$editText ){
2319 wfProfileIn( __METHOD__
);
2321 $db = wfGetDB( DB_MASTER
);
2323 // This is the revision the editor started from
2324 $baseRevision = $this->getBaseRevision();
2325 if ( is_null( $baseRevision ) ) {
2326 wfProfileOut( __METHOD__
);
2329 $baseText = $baseRevision->getText();
2331 // The current state, we want to merge updates into it
2332 $currentRevision = Revision
::loadFromTitle( $db, $this->mTitle
);
2333 if ( is_null( $currentRevision ) ) {
2334 wfProfileOut( __METHOD__
);
2337 $currentText = $currentRevision->getText();
2340 if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
2341 $editText = $result;
2342 wfProfileOut( __METHOD__
);
2345 wfProfileOut( __METHOD__
);
2351 * Check if the browser is on a blacklist of user-agents known to
2352 * mangle UTF-8 data on form submission. Returns true if Unicode
2353 * should make it through, false if it's known to be a problem.
2357 function checkUnicodeCompliantBrowser() {
2358 global $wgBrowserBlackList;
2359 if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
2360 // No User-Agent header sent? Trust it by default...
2363 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
2364 foreach ( $wgBrowserBlackList as $browser ) {
2365 if ( preg_match($browser, $currentbrowser) ) {
2373 * Format an anchor fragment as it would appear for a given section name
2374 * @param $text String
2378 function sectionAnchor( $text ) {
2380 return $wgParser->guessSectionNameFromWikiText( $text );
2384 * Shows a bulletin board style toolbar for common editing functions.
2385 * It can be disabled in the user preferences.
2386 * The necessary JavaScript code can be found in skins/common/edit.js.
2390 static function getEditToolbar() {
2391 global $wgStylePath, $wgContLang, $wgLang, $wgOut;
2392 global $wgUseTeX, $wgEnableUploads, $wgForeignFileRepos;
2394 $imagesAvailable = $wgEnableUploads ||
count( $wgForeignFileRepos );
2397 * $toolarray is an array of arrays each of which includes the
2398 * filename of the button image (without path), the opening
2399 * tag, the closing tag, optionally a sample text that is
2400 * inserted between the two when no selection is highlighted
2401 * and. The tip text is shown when the user moves the mouse
2404 * Also here: accesskeys (key), which are not used yet until
2405 * someone can figure out a way to make them work in
2406 * IE. However, we should make sure these keys are not defined
2411 'image' => $wgLang->getImageFile( 'button-bold' ),
2412 'id' => 'mw-editbutton-bold',
2414 'close' => '\'\'\'',
2415 'sample' => wfMsg( 'bold_sample' ),
2416 'tip' => wfMsg( 'bold_tip' ),
2420 'image' => $wgLang->getImageFile( 'button-italic' ),
2421 'id' => 'mw-editbutton-italic',
2424 'sample' => wfMsg( 'italic_sample' ),
2425 'tip' => wfMsg( 'italic_tip' ),
2429 'image' => $wgLang->getImageFile( 'button-link' ),
2430 'id' => 'mw-editbutton-link',
2433 'sample' => wfMsg( 'link_sample' ),
2434 'tip' => wfMsg( 'link_tip' ),
2438 'image' => $wgLang->getImageFile( 'button-extlink' ),
2439 'id' => 'mw-editbutton-extlink',
2442 'sample' => wfMsg( 'extlink_sample' ),
2443 'tip' => wfMsg( 'extlink_tip' ),
2447 'image' => $wgLang->getImageFile( 'button-headline' ),
2448 'id' => 'mw-editbutton-headline',
2451 'sample' => wfMsg( 'headline_sample' ),
2452 'tip' => wfMsg( 'headline_tip' ),
2455 $imagesAvailable ?
array(
2456 'image' => $wgLang->getImageFile( 'button-image' ),
2457 'id' => 'mw-editbutton-image',
2458 'open' => '[[' . $wgContLang->getNsText( NS_FILE
) . ':',
2460 'sample' => wfMsg( 'image_sample' ),
2461 'tip' => wfMsg( 'image_tip' ),
2464 $imagesAvailable ?
array(
2465 'image' => $wgLang->getImageFile( 'button-media' ),
2466 'id' => 'mw-editbutton-media',
2467 'open' => '[[' . $wgContLang->getNsText( NS_MEDIA
) . ':',
2469 'sample' => wfMsg( 'media_sample' ),
2470 'tip' => wfMsg( 'media_tip' ),
2474 'image' => $wgLang->getImageFile( 'button-math' ),
2475 'id' => 'mw-editbutton-math',
2477 'close' => "</math>",
2478 'sample' => wfMsg( 'math_sample' ),
2479 'tip' => wfMsg( 'math_tip' ),
2483 'image' => $wgLang->getImageFile( 'button-nowiki' ),
2484 'id' => 'mw-editbutton-nowiki',
2485 'open' => "<nowiki>",
2486 'close' => "</nowiki>",
2487 'sample' => wfMsg( 'nowiki_sample' ),
2488 'tip' => wfMsg( 'nowiki_tip' ),
2492 'image' => $wgLang->getImageFile( 'button-sig' ),
2493 'id' => 'mw-editbutton-signature',
2497 'tip' => wfMsg( 'sig_tip' ),
2501 'image' => $wgLang->getImageFile( 'button-hr' ),
2502 'id' => 'mw-editbutton-hr',
2503 'open' => "\n----\n",
2506 'tip' => wfMsg( 'hr_tip' ),
2512 foreach ( $toolarray as $tool ) {
2518 $image = $wgStylePath . '/common/images/' . $tool['image'],
2519 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2520 // Older browsers show a "speedtip" type message only for ALT.
2521 // Ideally these should be different, realistically they
2522 // probably don't need to be.
2523 $tip = $tool['tip'],
2524 $open = $tool['open'],
2525 $close = $tool['close'],
2526 $sample = $tool['sample'],
2527 $cssId = $tool['id'],
2530 $script .= Xml
::encodeJsCall( 'mw.toolbar.addButton', $params );
2532 $wgOut->addScript( Html
::inlineScript( ResourceLoader
::makeLoaderConditionalScript( $script ) ) );
2534 $toolbar = '<div id="toolbar"></div>';
2536 wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
2542 * Returns an array of html code of the following checkboxes:
2545 * @param $tabindex Current tabindex
2546 * @param $checked Array of checkbox => bool, where bool indicates the checked
2547 * status of the checkbox
2551 public function getCheckboxes( &$tabindex, $checked ) {
2554 $checkboxes = array();
2556 // don't show the minor edit checkbox if it's a new page or section
2557 if ( !$this->isNew
) {
2558 $checkboxes['minor'] = '';
2559 $minorLabel = wfMsgExt( 'minoredit', array( 'parseinline' ) );
2560 if ( $wgUser->isAllowed( 'minoredit' ) ) {
2562 'tabindex' => ++
$tabindex,
2563 'accesskey' => wfMsg( 'accesskey-minoredit' ),
2564 'id' => 'wpMinoredit',
2566 $checkboxes['minor'] =
2567 Xml
::check( 'wpMinoredit', $checked['minor'], $attribs ) .
2568 " <label for='wpMinoredit' id='mw-editpage-minoredit'" .
2569 Xml
::expandAttributes( array( 'title' => Linker
::titleAttrib( 'minoredit', 'withaccess' ) ) ) .
2570 ">{$minorLabel}</label>";
2574 $watchLabel = wfMsgExt( 'watchthis', array( 'parseinline' ) );
2575 $checkboxes['watch'] = '';
2576 if ( $wgUser->isLoggedIn() ) {
2578 'tabindex' => ++
$tabindex,
2579 'accesskey' => wfMsg( 'accesskey-watch' ),
2580 'id' => 'wpWatchthis',
2582 $checkboxes['watch'] =
2583 Xml
::check( 'wpWatchthis', $checked['watch'], $attribs ) .
2584 " <label for='wpWatchthis' id='mw-editpage-watch'" .
2585 Xml
::expandAttributes( array( 'title' => Linker
::titleAttrib( 'watch', 'withaccess' ) ) ) .
2586 ">{$watchLabel}</label>";
2588 wfRunHooks( 'EditPageBeforeEditChecks', array( &$this, &$checkboxes, &$tabindex ) );
2593 * Returns an array of html code of the following buttons:
2594 * save, diff, preview and live
2596 * @param $tabindex Current tabindex
2600 public function getEditButtons( &$tabindex ) {
2607 'tabindex' => ++
$tabindex,
2608 'value' => wfMsg( 'savearticle' ),
2609 'accesskey' => wfMsg( 'accesskey-save' ),
2610 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
2612 $buttons['save'] = Xml
::element('input', $temp, '');
2614 ++
$tabindex; // use the same for preview and live preview
2616 'id' => 'wpPreview',
2617 'name' => 'wpPreview',
2619 'tabindex' => $tabindex,
2620 'value' => wfMsg( 'showpreview' ),
2621 'accesskey' => wfMsg( 'accesskey-preview' ),
2622 'title' => wfMsg( 'tooltip-preview' ) . ' [' . wfMsg( 'accesskey-preview' ) . ']',
2624 $buttons['preview'] = Xml
::element( 'input', $temp, '' );
2625 $buttons['live'] = '';
2631 'tabindex' => ++
$tabindex,
2632 'value' => wfMsg( 'showdiff' ),
2633 'accesskey' => wfMsg( 'accesskey-diff' ),
2634 'title' => wfMsg( 'tooltip-diff' ) . ' [' . wfMsg( 'accesskey-diff' ) . ']',
2636 $buttons['diff'] = Xml
::element( 'input', $temp, '' );
2638 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
2643 * Output preview text only. This can be sucked into the edit page
2644 * via JavaScript, and saves the server time rendering the skin as
2645 * well as theoretically being more robust on the client (doesn't
2646 * disturb the edit box's undo history, won't eat your text on
2649 * @todo This doesn't include category or interlanguage links.
2650 * Would need to enhance it a bit, <s>maybe wrap them in XML
2651 * or something...</s> that might also require more skin
2652 * initialization, so check whether that's a problem.
2654 function livePreview() {
2657 header( 'Content-type: text/xml; charset=utf-8' );
2658 header( 'Cache-control: no-cache' );
2660 $previewText = $this->getPreviewText();
2661 #$categories = $skin->getCategoryLinks();
2664 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2665 Xml
::tags( 'livepreview', null,
2666 Xml
::element( 'preview', null, $previewText )
2667 #. Xml::element( 'category', null, $categories )
2675 public function getCancelLink() {
2676 $cancelParams = array();
2677 if ( !$this->isConflict
&& $this->mArticle
->getOldID() > 0 ) {
2678 $cancelParams['oldid'] = $this->mArticle
->getOldID();
2681 return Linker
::linkKnown(
2682 $this->getContextTitle(),
2683 wfMsgExt( 'cancel', array( 'parseinline' ) ),
2684 array( 'id' => 'mw-editform-cancel' ),
2690 * Get a diff between the current contents of the edit box and the
2691 * version of the page we're editing from.
2693 * If this is a section edit, we'll replace the section as for final
2694 * save and then make a comparison.
2696 function showDiff() {
2697 $oldtext = $this->mArticle
->fetchContent();
2698 $newtext = $this->mArticle
->replaceSection(
2699 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
2701 wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
2703 $newtext = $this->mArticle
->preSaveTransform( $newtext );
2704 $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
2705 $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
2706 if ( $oldtext !== false ||
$newtext != '' ) {
2707 $de = new DifferenceEngine( $this->mTitle
);
2708 $de->setText( $oldtext, $newtext );
2709 $difftext = $de->getDiff( $oldtitle, $newtitle );
2710 $de->showDiffStyle();
2716 $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
2720 * Filter an input field through a Unicode de-armoring process if it
2721 * came from an old browser with known broken Unicode editing issues.
2723 * @param $request WebRequest
2724 * @param $field String
2728 function safeUnicodeInput( $request, $field ) {
2729 $text = rtrim( $request->getText( $field ) );
2730 return $request->getBool( 'safemode' )
2731 ?
$this->unmakesafe( $text )
2736 * @param $request WebRequest
2737 * @param $text string
2740 function safeUnicodeText( $request, $text ) {
2741 $text = rtrim( $text );
2742 return $request->getBool( 'safemode' )
2743 ?
$this->unmakesafe( $text )
2748 * Filter an output field through a Unicode armoring process if it is
2749 * going to an old browser with known broken Unicode editing issues.
2751 * @param $text String
2755 function safeUnicodeOutput( $text ) {
2757 $codedText = $wgContLang->recodeForEdit( $text );
2758 return $this->checkUnicodeCompliantBrowser()
2760 : $this->makesafe( $codedText );
2764 * A number of web browsers are known to corrupt non-ASCII characters
2765 * in a UTF-8 text editing environment. To protect against this,
2766 * detected browsers will be served an armored version of the text,
2767 * with non-ASCII chars converted to numeric HTML character references.
2769 * Preexisting such character references will have a 0 added to them
2770 * to ensure that round-trips do not alter the original data.
2772 * @param $invalue String
2776 function makesafe( $invalue ) {
2777 // Armor existing references for reversability.
2778 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
2783 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2784 $bytevalue = ord( $invalue[$i] );
2785 if ( $bytevalue <= 0x7F ) { //0xxx xxxx
2786 $result .= chr( $bytevalue );
2788 } elseif ( $bytevalue <= 0xBF ) { //10xx xxxx
2789 $working = $working << 6;
2790 $working +
= ($bytevalue & 0x3F);
2792 if ( $bytesleft <= 0 ) {
2793 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2795 } elseif ( $bytevalue <= 0xDF ) { //110x xxxx
2796 $working = $bytevalue & 0x1F;
2798 } elseif ( $bytevalue <= 0xEF ) { //1110 xxxx
2799 $working = $bytevalue & 0x0F;
2801 } else { //1111 0xxx
2802 $working = $bytevalue & 0x07;
2810 * Reverse the previously applied transliteration of non-ASCII characters
2811 * back to UTF-8. Used to protect data from corruption by broken web browsers
2812 * as listed in $wgBrowserBlackList.
2814 * @param $invalue String
2818 function unmakesafe( $invalue ) {
2820 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2821 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue[$i+
3] != '0' ) ) {
2825 $hexstring .= $invalue[$i];
2827 } while( ctype_xdigit( $invalue[$i] ) && ( $i < strlen( $invalue ) ) );
2829 // Do some sanity checks. These aren't needed for reversability,
2830 // but should help keep the breakage down if the editor
2831 // breaks one of the entities whilst editing.
2832 if ( (substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6) ) {
2833 $codepoint = hexdec($hexstring);
2834 $result .= codepointToUtf8( $codepoint );
2836 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2839 $result .= substr( $invalue, $i, 1 );
2842 // reverse the transform that we made for reversability reasons.
2843 return strtr( $result, array( "�" => "&#x" ) );
2846 function noCreatePermission() {
2848 $wgOut->setPageTitle( wfMessage( 'nocreatetitle' ) );
2849 $wgOut->addWikiMsg( 'nocreatetext' );
2853 * Attempt submission
2854 * @return bool false if output is done, true if the rest of the form should be displayed
2856 function attemptSave() {
2857 global $wgUser, $wgOut;
2859 $resultDetails = false;
2860 # Allow bots to exempt some edits from bot flagging
2861 $bot = $wgUser->isAllowed( 'bot' ) && $this->bot
;
2862 $status = $this->internalAttemptSave( $resultDetails, $bot );
2863 // FIXME: once the interface for internalAttemptSave() is made nicer, this should use the message in $status
2865 if ( $status->value
== self
::AS_SUCCESS_UPDATE ||
$status->value
== self
::AS_SUCCESS_NEW_ARTICLE
) {
2866 $this->didSave
= true;
2869 switch ( $status->value
) {
2870 case self
::AS_HOOK_ERROR_EXPECTED
:
2871 case self
::AS_CONTENT_TOO_BIG
:
2872 case self
::AS_ARTICLE_WAS_DELETED
:
2873 case self
::AS_CONFLICT_DETECTED
:
2874 case self
::AS_SUMMARY_NEEDED
:
2875 case self
::AS_TEXTBOX_EMPTY
:
2876 case self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
:
2880 case self
::AS_HOOK_ERROR
:
2881 case self
::AS_FILTERING
:
2884 case self
::AS_SUCCESS_NEW_ARTICLE
:
2885 $query = $resultDetails['redirect'] ?
'redirect=no' : '';
2886 $wgOut->redirect( $this->mTitle
->getFullURL( $query ) );
2889 case self
::AS_SUCCESS_UPDATE
:
2891 $sectionanchor = $resultDetails['sectionanchor'];
2893 // Give extensions a chance to modify URL query on update
2894 wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this->mArticle
, &$sectionanchor, &$extraQuery ) );
2896 if ( $resultDetails['redirect'] ) {
2897 if ( $extraQuery == '' ) {
2898 $extraQuery = 'redirect=no';
2900 $extraQuery = 'redirect=no&' . $extraQuery;
2903 $wgOut->redirect( $this->mTitle
->getFullURL( $extraQuery ) . $sectionanchor );
2906 case self
::AS_SPAM_ERROR
:
2907 $this->spamPageWithContent( $resultDetails['spam'] );
2910 case self
::AS_BLOCKED_PAGE_FOR_USER
:
2911 $this->blockedPage();
2914 case self
::AS_IMAGE_REDIRECT_ANON
:
2915 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2918 case self
::AS_READ_ONLY_PAGE_ANON
:
2919 $this->userNotLoggedInPage();
2922 case self
::AS_READ_ONLY_PAGE_LOGGED
:
2923 case self
::AS_READ_ONLY_PAGE
:
2924 $wgOut->readOnlyPage();
2927 case self
::AS_RATE_LIMITED
:
2928 $wgOut->rateLimited();
2931 case self
::AS_NO_CREATE_PERMISSION
:
2932 $this->noCreatePermission();
2935 case self
::AS_BLANK_ARTICLE
:
2936 $wgOut->redirect( $this->getContextTitle()->getFullURL() );
2939 case self
::AS_IMAGE_REDIRECT_LOGGED
:
2940 $wgOut->permissionRequired( 'upload' );
2949 function getBaseRevision() {
2950 if ( !$this->mBaseRevision
) {
2951 $db = wfGetDB( DB_MASTER
);
2952 $baseRevision = Revision
::loadFromTimestamp(
2953 $db, $this->mTitle
, $this->edittime
);
2954 return $this->mBaseRevision
= $baseRevision;
2956 return $this->mBaseRevision
;