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 * @returns 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->mId
== $undo ) {
241 $this->summary
= wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
242 $this->undidRev
= $undo;
244 $this->formtype
= 'diff';
247 // Failed basic sanity checks.
248 // Older revisions may have been removed since the link
249 // was created, or we may simply have got bogus input.
250 $this->editFormPageTop
.= $wgOut->parse( '<div class="error mw-undo-norev">' .
251 wfMsgNoTrans( 'undo-norev' ) . '</div>', true, /* interface */true );
253 } elseif ( $section != '' ) {
254 if ( $section == 'new' ) {
255 $text = $this->getPreloadedText( $preload );
257 // Get section edit text (returns $def_text for invalid sections)
258 $text = $wgParser->getSection( $text, $section, $def_text );
263 wfProfileOut( __METHOD__
);
268 * Use this method before edit() to preload some text into the edit box
270 * @param $text string
272 public function setPreloadedText( $text ) {
273 $this->mPreloadText
= $text;
277 * Get the contents to be preloaded into the box, either set by
278 * an earlier setPreloadText() or by loading the given page.
280 * @param $preload String: representing the title to preload from.
283 protected function getPreloadedText( $preload ) {
284 global $wgUser, $wgParser;
285 if ( !empty( $this->mPreloadText
) ) {
286 return $this->mPreloadText
;
287 } elseif ( $preload !== '' ) {
288 $title = Title
::newFromText( $preload );
289 # Check for existence to avoid getting MediaWiki:Noarticletext
290 if ( isset( $title ) && $title->exists() && $title->userCanRead() ) {
291 $article = new Article( $title );
293 if ( $article->isRedirect() ) {
294 $title = Title
::newFromRedirectRecurse( $article->getContent() );
295 # Redirects to missing titles are displayed, to hidden pages are followed
296 # Copying observed behaviour from ?action=view
297 if ( $title->exists() ) {
298 if ($title->userCanRead() ) {
299 $article = new Article( $title );
305 $parserOptions = ParserOptions
::newFromUser( $wgUser );
306 return $wgParser->getPreloadText( $article->getContent(), $title, $parserOptions );
313 * Check if a page was deleted while the user was editing it, before submit.
314 * Note that we rely on the logging table, which hasn't been always there,
315 * but that doesn't matter, because this only applies to brand new
318 protected function wasDeletedSinceLastEdit() {
319 if ( $this->deletedSinceEdit
!== null ) {
320 return $this->deletedSinceEdit
;
323 $this->deletedSinceEdit
= false;
325 if ( $this->mTitle
->isDeletedQuick() ) {
326 $this->lastDelete
= $this->getLastDelete();
327 if ( $this->lastDelete
) {
328 $deleteTime = wfTimestamp( TS_MW
, $this->lastDelete
->log_timestamp
);
329 if ( $deleteTime > $this->starttime
) {
330 $this->deletedSinceEdit
= true;
335 return $this->deletedSinceEdit
;
339 * Checks whether the user entered a skin name in uppercase,
340 * e.g. "User:Example/Monobook.css" instead of "monobook.css"
344 protected function isWrongCaseCssJsPage() {
345 if( $this->mTitle
->isCssJsSubpage() ) {
346 $name = $this->mTitle
->getSkinFromCssJsSubpage();
347 $skins = array_merge(
348 array_keys( Skin
::getSkinNames() ),
351 return !in_array( $name, $skins )
352 && in_array( strtolower( $name ), $skins );
363 * This is the function that gets called for "action=edit". It
364 * sets up various member variables, then passes execution to
365 * another function, usually showEditForm()
367 * The edit form is self-submitting, so that when things like
368 * preview and edit conflicts occur, we get the same form back
369 * with the extra stuff added. Only when the final submission
370 * is made and all is well do we actually save and redirect to
371 * the newly-edited page.
374 global $wgOut, $wgRequest, $wgUser;
375 // Allow extensions to modify/prevent this form or submission
376 if ( !wfRunHooks( 'AlternateEdit', array( $this ) ) ) {
380 wfProfileIn( __METHOD__
);
381 wfDebug( __METHOD__
.": enter\n" );
383 $this->importFormData( $wgRequest );
384 $this->firsttime
= false;
387 $this->livePreview();
388 wfProfileOut( __METHOD__
);
392 if ( wfReadOnly() && $this->save
) {
395 $this->preview
= true;
398 $wgOut->addModules( array( 'mediawiki.action.edit' ) );
400 if ( $wgUser->getOption( 'uselivepreview', false ) ) {
401 $wgOut->addModules( 'mediawiki.legacy.preview' );
403 // Bug #19334: textarea jumps when editing articles in IE8
404 $wgOut->addStyle( 'common/IE80Fixes.css', 'screen', 'IE 8' );
406 $permErrors = $this->getEditPermissionErrors();
408 wfDebug( __METHOD__
. ": User can't edit\n" );
409 $content = $this->getContent( null );
410 $content = $content === '' ?
null : $content;
411 $this->readOnlyPage( $content, true, $permErrors, 'edit' );
412 wfProfileOut( __METHOD__
);
416 $this->formtype
= 'save';
417 } elseif ( $this->preview
) {
418 $this->formtype
= 'preview';
419 } elseif ( $this->diff
) {
420 $this->formtype
= 'diff';
421 } else { # First time through
422 $this->firsttime
= true;
423 if ( $this->previewOnOpen() ) {
424 $this->formtype
= 'preview';
426 $this->formtype
= 'initial';
431 // If they used redlink=1 and the page exists, redirect to the main article
432 if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle
->exists() ) {
433 $wgOut->redirect( $this->mTitle
->getFullURL() );
436 wfProfileIn( __METHOD__
."-business-end" );
438 $this->isConflict
= false;
439 // css / js subpages of user pages get a special treatment
440 $this->isCssJsSubpage
= $this->mTitle
->isCssJsSubpage();
441 $this->isCssSubpage
= $this->mTitle
->isCssSubpage();
442 $this->isJsSubpage
= $this->mTitle
->isJsSubpage();
443 $this->isWrongCaseCssJsPage
= $this->isWrongCaseCssJsPage();
444 $this->isNew
= !$this->mTitle
->exists() ||
$this->section
== 'new';
446 # Show applicable editing introductions
447 if ( $this->formtype
== 'initial' ||
$this->firsttime
)
450 if ( $this->mTitle
->isTalkPage() ) {
451 $wgOut->addWikiMsg( 'talkpagetext' );
454 # Optional notices on a per-namespace and per-page basis
455 $editnotice_ns = 'editnotice-'.$this->mTitle
->getNamespace();
456 $editnotice_ns_message = wfMessage( $editnotice_ns )->inContentLanguage();
457 if ( $editnotice_ns_message->exists() ) {
458 $wgOut->addWikiText( $editnotice_ns_message->plain() );
460 if ( MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
461 $parts = explode( '/', $this->mTitle
->getDBkey() );
462 $editnotice_base = $editnotice_ns;
463 while ( count( $parts ) > 0 ) {
464 $editnotice_base .= '-'.array_shift( $parts );
465 $editnotice_base_msg = wfMessage( $editnotice_base )->inContentLanguage();
466 if ( $editnotice_base_msg->exists() ) {
467 $wgOut->addWikiText( $editnotice_base_msg->plain() );
472 # Attempt submission here. This will check for edit conflicts,
473 # and redundantly check for locked database, blocked IPs, etc.
474 # that edit() already checked just in case someone tries to sneak
475 # in the back door with a hand-edited submission URL.
477 if ( 'save' == $this->formtype
) {
478 if ( !$this->attemptSave() ) {
479 wfProfileOut( __METHOD__
."-business-end" );
480 wfProfileOut( __METHOD__
);
485 # First time through: get contents, set time for conflict
487 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
488 if ( $this->initialiseForm() === false ) {
489 $this->noSuchSectionPage();
490 wfProfileOut( __METHOD__
."-business-end" );
491 wfProfileOut( __METHOD__
);
494 if ( !$this->mTitle
->getArticleId() )
495 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1
, &$this->mTitle
) );
497 wfRunHooks( 'EditFormInitialText', array( $this ) );
500 $this->showEditForm();
501 wfProfileOut( __METHOD__
."-business-end" );
502 wfProfileOut( __METHOD__
);
508 protected function getEditPermissionErrors() {
510 $permErrors = $this->mTitle
->getUserPermissionsErrors( 'edit', $wgUser );
511 # Can this title be created?
512 if ( !$this->mTitle
->exists() ) {
513 $permErrors = array_merge( $permErrors,
514 wfArrayDiff2( $this->mTitle
->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) );
516 # Ignore some permissions errors when a user is just previewing/viewing diffs
518 foreach( $permErrors as $error ) {
519 if ( ( $this->preview ||
$this->diff
) &&
520 ( $error[0] == 'blockedtext' ||
$error[0] == 'autoblockedtext' ) )
525 $permErrors = wfArrayDiff2( $permErrors, $remove );
530 * Show a read-only error
531 * Parameters are the same as OutputPage:readOnlyPage()
532 * Redirect to the article page if redlink=1
534 function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
535 global $wgRequest, $wgOut;
536 if ( $wgRequest->getBool( 'redlink' ) ) {
537 // The edit page was reached via a red link.
538 // Redirect to the article page and let them click the edit tab if
539 // they really want a permission error.
540 $wgOut->redirect( $this->mTitle
->getFullUrl() );
542 $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
547 * Should we show a preview when the edit form is first shown?
551 protected function previewOnOpen() {
552 global $wgRequest, $wgUser, $wgPreviewOnOpenNamespaces;
553 if ( $wgRequest->getVal( 'preview' ) == 'yes' ) {
554 // Explicit override from request
556 } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) {
557 // Explicit override from request
559 } elseif ( $this->section
== 'new' ) {
560 // Nothing *to* preview for new sections
562 } elseif ( ( $wgRequest->getVal( 'preload' ) !== null ||
$this->mTitle
->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
563 // Standard preference behaviour
565 } elseif ( !$this->mTitle
->exists() &&
566 isset($wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()]) &&
567 $wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()] )
569 // Categories are special
577 * Does this EditPage class support section editing?
578 * This is used by EditPage subclasses to indicate their ui cannot handle section edits
582 protected function isSectionEditSupported() {
587 * Returns the URL to use in the form's action attribute.
588 * This is used by EditPage subclasses when simply customizing the action
589 * variable in the constructor is not enough. This can be used when the
590 * EditPage lives inside of a Special page rather than a custom page action.
592 * @param $title Title object for which is being edited (where we go to for &action= links)
595 protected function getActionURL( Title
$title ) {
596 return $title->getLocalURL( array( 'action' => $this->action
) );
601 * @param $request WebRequest
603 function importFormData( &$request ) {
604 global $wgLang, $wgUser;
606 wfProfileIn( __METHOD__
);
608 # Section edit can come from either the form or a link
609 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
611 if ( $request->wasPosted() ) {
612 # These fields need to be checked for encoding.
613 # Also remove trailing whitespace, but don't remove _initial_
614 # whitespace from the text boxes. This may be significant formatting.
615 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
616 if ( !$request->getCheck('wpTextbox2') ) {
617 // Skip this if wpTextbox2 has input, it indicates that we came
618 // from a conflict page with raw page text, not a custom form
619 // modified by subclasses
620 wfProfileIn( get_class($this)."::importContentFormData" );
621 $textbox1 = $this->importContentFormData( $request );
622 if ( isset($textbox1) )
623 $this->textbox1
= $textbox1;
624 wfProfileOut( get_class($this)."::importContentFormData" );
627 # Truncate for whole multibyte characters. +5 bytes for ellipsis
628 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
630 # Remove extra headings from summaries and new sections.
631 $this->summary
= preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary
);
633 $this->edittime
= $request->getVal( 'wpEdittime' );
634 $this->starttime
= $request->getVal( 'wpStarttime' );
636 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
638 if ($this->textbox1
=== '' && $request->getVal( 'wpTextbox1' ) === null) {
639 // wpTextbox1 field is missing, possibly due to being "too big"
640 // according to some filter rules such as Suhosin's setting for
641 // suhosin.request.max_value_length (d'oh)
642 $this->incompleteForm
= true;
644 // edittime should be one of our last fields; if it's missing,
645 // the submission probably broke somewhere in the middle.
646 $this->incompleteForm
= is_null( $this->edittime
);
648 if ( $this->incompleteForm
) {
649 # If the form is incomplete, force to preview.
650 wfDebug( __METHOD__
. ": Form data appears to be incomplete\n" );
651 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
652 $this->preview
= true;
654 /* Fallback for live preview */
655 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
656 $this->diff
= $request->getCheck( 'wpDiff' );
658 // Remember whether a save was requested, so we can indicate
659 // if we forced preview due to session failure.
660 $this->mTriedSave
= !$this->preview
;
662 if ( $this->tokenOk( $request ) ) {
663 # Some browsers will not report any submit button
664 # if the user hits enter in the comment box.
665 # The unmarked state will be assumed to be a save,
666 # if the form seems otherwise complete.
667 wfDebug( __METHOD__
. ": Passed token check.\n" );
668 } elseif ( $this->diff
) {
669 # Failed token check, but only requested "Show Changes".
670 wfDebug( __METHOD__
. ": Failed token check; Show Changes requested.\n" );
672 # Page might be a hack attempt posted from
673 # an external site. Preview instead of saving.
674 wfDebug( __METHOD__
. ": Failed token check; forcing preview\n" );
675 $this->preview
= true;
678 $this->save
= !$this->preview
&& !$this->diff
;
679 if ( !preg_match( '/^\d{14}$/', $this->edittime
) ) {
680 $this->edittime
= null;
683 if ( !preg_match( '/^\d{14}$/', $this->starttime
) ) {
684 $this->starttime
= null;
687 $this->recreate
= $request->getCheck( 'wpRecreate' );
689 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
690 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
692 # Don't force edit summaries when a user is editing their own user or talk page
693 if ( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) &&
694 $this->mTitle
->getText() == $wgUser->getName() )
696 $this->allowBlankSummary
= true;
698 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' ) ||
!$wgUser->getOption( 'forceeditsummary');
701 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
703 # Not a posted form? Start with nothing.
704 wfDebug( __METHOD__
. ": Not a posted form.\n" );
705 $this->textbox1
= '';
707 $this->edittime
= '';
708 $this->starttime
= wfTimestampNow();
710 $this->preview
= false;
713 $this->minoredit
= false;
714 $this->watchthis
= $request->getBool( 'watchthis', false ); // Watch may be overriden by request parameters
715 $this->recreate
= false;
717 if ( $this->section
== 'new' && $request->getVal( 'preloadtitle' ) ) {
718 $this->summary
= $request->getVal( 'preloadtitle' );
720 elseif ( $this->section
!= 'new' && $request->getVal( 'summary' ) ) {
721 $this->summary
= $request->getText( 'summary' );
724 if ( $request->getVal( 'minor' ) ) {
725 $this->minoredit
= true;
729 $this->bot
= $request->getBool( 'bot', true );
730 $this->nosummary
= $request->getBool( 'nosummary' );
732 // @todo FIXME: Unused variable?
733 $this->oldid
= $request->getInt( 'oldid' );
735 $this->live
= $request->getCheck( 'live' );
736 $this->editintro
= $request->getText( 'editintro',
737 // Custom edit intro for new sections
738 $this->section
=== 'new' ?
'MediaWiki:addsection-editintro' : '' );
740 // Allow extensions to modify form data
741 wfRunHooks( 'EditPage::importFormData', array( $this, $request ) );
743 wfProfileOut( __METHOD__
);
747 * Subpage overridable method for extracting the page content data from the
748 * posted form to be placed in $this->textbox1, if using customized input
749 * this method should be overrided and return the page text that will be used
750 * for saving, preview parsing and so on...
752 * @param $request WebRequest
754 protected function importContentFormData( &$request ) {
755 return; // Don't do anything, EditPage already extracted wpTextbox1
759 * Make sure the form isn't faking a user's credentials.
761 * @param $request WebRequest
765 function tokenOk( &$request ) {
767 $token = $request->getVal( 'wpEditToken' );
768 $this->mTokenOk
= $wgUser->matchEditToken( $token );
769 $this->mTokenOkExceptSuffix
= $wgUser->matchEditTokenNoSuffix( $token );
770 return $this->mTokenOk
;
774 * Show all applicable editing introductions
776 protected function showIntro() {
777 global $wgOut, $wgUser;
778 if ( $this->suppressIntro
) {
782 $namespace = $this->mTitle
->getNamespace();
784 if ( $namespace == NS_MEDIAWIKI
) {
785 # Show a warning if editing an interface message
786 $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1\n</div>", 'editinginterface' );
789 # Show a warning message when someone creates/edits a user (talk) page but the user does not exist
790 # Show log extract when the user is currently blocked
791 if ( $namespace == NS_USER ||
$namespace == NS_USER_TALK
) {
792 $parts = explode( '/', $this->mTitle
->getText(), 2 );
793 $username = $parts[0];
794 $user = User
::newFromName( $username, false /* allow IP users*/ );
795 $ip = User
::isIP( $username );
796 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
797 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
798 array( 'userpage-userdoesnotexist', wfEscapeWikiText( $username ) ) );
799 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
800 LogEventsList
::showLogExtract(
803 $user->getUserPage()->getPrefixedText(),
807 'showIfEmpty' => false,
809 'blocked-notice-logextract',
810 $user->getName() # Support GENDER in notice
816 # Try to add a custom edit intro, or use the standard one if this is not possible.
817 if ( !$this->showCustomIntro() && !$this->mTitle
->exists() ) {
818 if ( $wgUser->isLoggedIn() ) {
819 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletext\">\n$1\n</div>", 'newarticletext' );
821 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletextanon\">\n$1\n</div>", 'newarticletextanon' );
824 # Give a notice if the user is editing a deleted/moved page...
825 if ( !$this->mTitle
->exists() ) {
826 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle
->getPrefixedText(),
827 '', array( 'lim' => 10,
828 'conds' => array( "log_action != 'revision'" ),
829 'showIfEmpty' => false,
830 'msgKey' => array( 'recreate-moveddeleted-warn') )
836 * Attempt to show a custom editing introduction, if supplied
840 protected function showCustomIntro() {
841 if ( $this->editintro
) {
842 $title = Title
::newFromText( $this->editintro
);
843 if ( $title instanceof Title
&& $title->exists() && $title->userCanRead() ) {
845 // Added using template syntax, to take <noinclude>'s into account.
846 $wgOut->addWikiTextTitleTidy( '{{:' . $title->getFullText() . '}}', $this->mTitle
);
857 * Attempt submission (no UI)
862 * @return Status object, possibly with a message, but always with one of the AS_* constants in $status->value,
864 * FIXME: This interface is TERRIBLE, but hard to get rid of due to various error display idiosyncrasies. There are
865 * also lots of cases where error metadata is set in the object and retrieved later instead of being returned, e.g.
866 * AS_CONTENT_TOO_BIG and AS_BLOCKED_PAGE_FOR_USER. All that stuff needs to be cleaned up some time.
868 function internalAttemptSave( &$result, $bot = false ) {
869 global $wgFilterCallback, $wgUser, $wgRequest, $wgParser;
870 global $wgMaxArticleSize;
872 $status = Status
::newGood();
874 wfProfileIn( __METHOD__
);
875 wfProfileIn( __METHOD__
. '-checks' );
877 if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) ) {
878 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
879 $status->fatal( 'hookaborted' );
880 $status->value
= self
::AS_HOOK_ERROR
;
881 wfProfileOut( __METHOD__
. '-checks' );
882 wfProfileOut( __METHOD__
);
886 # Check image redirect
887 if ( $this->mTitle
->getNamespace() == NS_FILE
&&
888 Title
::newFromRedirect( $this->textbox1
) instanceof Title
&&
889 !$wgUser->isAllowed( 'upload' ) ) {
890 $code = $wgUser->isAnon() ? self
::AS_IMAGE_REDIRECT_ANON
: self
::AS_IMAGE_REDIRECT_LOGGED
;
891 $status->setResult( false, $code );
893 wfProfileOut( __METHOD__
. '-checks' );
894 wfProfileOut( __METHOD__
);
900 $match = self
::matchSummarySpamRegex( $this->summary
);
901 if ( $match === false ) {
902 $match = self
::matchSpamRegex( $this->textbox1
);
904 if ( $match !== false ) {
905 $result['spam'] = $match;
906 $ip = $wgRequest->getIP();
907 $pdbk = $this->mTitle
->getPrefixedDBkey();
908 $match = str_replace( "\n", '', $match );
909 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
910 $status->fatal( 'spamprotectionmatch', $match );
911 $status->value
= self
::AS_SPAM_ERROR
;
912 wfProfileOut( __METHOD__
. '-checks' );
913 wfProfileOut( __METHOD__
);
916 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
, $this->hookError
, $this->summary
) ) {
917 # Error messages or other handling should be performed by the filter function
918 $status->setResult( false, self
::AS_FILTERING
);
919 wfProfileOut( __METHOD__
. '-checks' );
920 wfProfileOut( __METHOD__
);
923 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1
, $this->section
, &$this->hookError
, $this->summary
) ) ) {
924 # Error messages etc. could be handled within the hook...
925 $status->fatal( 'hookaborted' );
926 $status->value
= self
::AS_HOOK_ERROR
;
927 wfProfileOut( __METHOD__
. '-checks' );
928 wfProfileOut( __METHOD__
);
930 } elseif ( $this->hookError
!= '' ) {
931 # ...or the hook could be expecting us to produce an error
932 $status->fatal( 'hookaborted' );
933 $status->value
= self
::AS_HOOK_ERROR_EXPECTED
;
934 wfProfileOut( __METHOD__
. '-checks' );
935 wfProfileOut( __METHOD__
);
939 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
940 # Check block state against master, thus 'false'.
941 $status->setResult( false, self
::AS_BLOCKED_PAGE_FOR_USER
);
942 wfProfileOut( __METHOD__
. '-checks' );
943 wfProfileOut( __METHOD__
);
947 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
948 if ( $this->kblength
> $wgMaxArticleSize ) {
949 // Error will be displayed by showEditForm()
950 $this->tooBig
= true;
951 $status->setResult( false, self
::AS_CONTENT_TOO_BIG
);
952 wfProfileOut( __METHOD__
. '-checks' );
953 wfProfileOut( __METHOD__
);
957 if ( !$wgUser->isAllowed( 'edit' ) ) {
958 if ( $wgUser->isAnon() ) {
959 $status->setResult( false, self
::AS_READ_ONLY_PAGE_ANON
);
960 wfProfileOut( __METHOD__
. '-checks' );
961 wfProfileOut( __METHOD__
);
964 $status->fatal( 'readonlytext' );
965 $status->value
= self
::AS_READ_ONLY_PAGE_LOGGED
;
966 wfProfileOut( __METHOD__
. '-checks' );
967 wfProfileOut( __METHOD__
);
972 if ( wfReadOnly() ) {
973 $status->fatal( 'readonlytext' );
974 $status->value
= self
::AS_READ_ONLY_PAGE
;
975 wfProfileOut( __METHOD__
. '-checks' );
976 wfProfileOut( __METHOD__
);
979 if ( $wgUser->pingLimiter() ) {
980 $status->fatal( 'actionthrottledtext' );
981 $status->value
= self
::AS_RATE_LIMITED
;
982 wfProfileOut( __METHOD__
. '-checks' );
983 wfProfileOut( __METHOD__
);
987 # If the article has been deleted while editing, don't save it without
989 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate
) {
990 $status->setResult( false, self
::AS_ARTICLE_WAS_DELETED
);
991 wfProfileOut( __METHOD__
. '-checks' );
992 wfProfileOut( __METHOD__
);
996 wfProfileOut( __METHOD__
. '-checks' );
998 # If article is new, insert it.
999 $aid = $this->mTitle
->getArticleID( Title
::GAID_FOR_UPDATE
);
1000 $new = ( $aid == 0 );
1003 // Late check for create permission, just in case *PARANOIA*
1004 if ( !$this->mTitle
->userCan( 'create' ) ) {
1005 $status->fatal( 'nocreatetext' );
1006 $status->value
= self
::AS_NO_CREATE_PERMISSION
;
1007 wfDebug( __METHOD__
. ": no create permission\n" );
1008 wfProfileOut( __METHOD__
);
1012 # Don't save a new article if it's blank.
1013 if ( $this->textbox1
== '' ) {
1014 $status->setResult( false, self
::AS_BLANK_ARTICLE
);
1015 wfProfileOut( __METHOD__
);
1019 // Run post-section-merge edit filter
1020 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1
, &$this->hookError
, $this->summary
) ) ) {
1021 # Error messages etc. could be handled within the hook...
1022 $status->fatal( 'hookaborted' );
1023 $status->value
= self
::AS_HOOK_ERROR
;
1024 wfProfileOut( __METHOD__
);
1026 } elseif ( $this->hookError
!= '' ) {
1027 # ...or the hook could be expecting us to produce an error
1028 $status->fatal( 'hookaborted' );
1029 $status->value
= self
::AS_HOOK_ERROR_EXPECTED
;
1030 wfProfileOut( __METHOD__
);
1034 # Handle the user preference to force summaries here. Check if it's not a redirect.
1035 if ( !$this->allowBlankSummary
&& !Title
::newFromRedirect( $this->textbox1
) ) {
1036 if ( md5( $this->summary
) == $this->autoSumm
) {
1037 $this->missingSummary
= true;
1038 $status->fatal( 'missingsummary' ); // or 'missingcommentheader' if $section == 'new'. Blegh
1039 $status->value
= self
::AS_SUMMARY_NEEDED
;
1040 wfProfileOut( __METHOD__
);
1045 $text = $this->textbox1
;
1046 if ( $this->section
== 'new' && $this->summary
!= '' ) {
1047 $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary
) . "\n\n" . $text;
1050 $status->value
= self
::AS_SUCCESS_NEW_ARTICLE
;
1054 # Article exists. Check for edit conflict.
1056 $this->mArticle
->clear(); # Force reload of dates, etc.
1058 wfDebug( "timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n" );
1060 if ( $this->mArticle
->getTimestamp() != $this->edittime
) {
1061 $this->isConflict
= true;
1062 if ( $this->section
== 'new' ) {
1063 if ( $this->mArticle
->getUserText() == $wgUser->getName() &&
1064 $this->mArticle
->getComment() == $this->summary
) {
1065 // Probably a duplicate submission of a new comment.
1066 // This can happen when squid resends a request after
1067 // a timeout but the first one actually went through.
1068 wfDebug( __METHOD__
. ": duplicate new section submission; trigger edit conflict!\n" );
1070 // New comment; suppress conflict.
1071 $this->isConflict
= false;
1072 wfDebug( __METHOD__
.": conflict suppressed; new section\n" );
1074 } elseif ( $this->section
== '' && $this->userWasLastToEdit( $wgUser->getId(), $this->edittime
) ) {
1075 # Suppress edit conflict with self, except for section edits where merging is required.
1076 wfDebug( __METHOD__
. ": Suppressing edit conflict, same user.\n" );
1077 $this->isConflict
= false;
1081 if ( $this->isConflict
) {
1082 wfDebug( __METHOD__
. ": conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
1083 $this->mArticle
->getTimestamp() . "')\n" );
1084 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1086 wfDebug( __METHOD__
. ": getting section '$this->section'\n" );
1087 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
1089 if ( is_null( $text ) ) {
1090 wfDebug( __METHOD__
. ": activating conflict; section replace failed.\n" );
1091 $this->isConflict
= true;
1092 $text = $this->textbox1
; // do not try to merge here!
1093 } elseif ( $this->isConflict
) {
1095 if ( $this->mergeChangesInto( $text ) ) {
1096 // Successful merge! Maybe we should tell the user the good news?
1097 $this->isConflict
= false;
1098 wfDebug( __METHOD__
. ": Suppressing edit conflict, successful merge.\n" );
1100 $this->section
= '';
1101 $this->textbox1
= $text;
1102 wfDebug( __METHOD__
. ": Keeping edit conflict, failed merge.\n" );
1106 if ( $this->isConflict
) {
1107 $status->setResult( false, self
::AS_CONFLICT_DETECTED
);
1108 wfProfileOut( __METHOD__
);
1112 // Run post-section-merge edit filter
1113 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError
, $this->summary
) ) ) {
1114 # Error messages etc. could be handled within the hook...
1115 $status->fatal( 'hookaborted' );
1116 $status->value
= self
::AS_HOOK_ERROR
;
1117 wfProfileOut( __METHOD__
);
1119 } elseif ( $this->hookError
!= '' ) {
1120 # ...or the hook could be expecting us to produce an error
1121 $status->fatal( 'hookaborted' );
1122 $status->value
= self
::AS_HOOK_ERROR_EXPECTED
;
1123 wfProfileOut( __METHOD__
);
1127 # Handle the user preference to force summaries here, but not for null edits
1128 if ( $this->section
!= 'new' && !$this->allowBlankSummary
1129 && 0 != strcmp( $this->mArticle
->getContent(), $text )
1130 && !Title
::newFromRedirect( $text ) ) # check if it's not a redirect
1132 if ( md5( $this->summary
) == $this->autoSumm
) {
1133 $this->missingSummary
= true;
1134 $status->fatal( 'missingsummary' );
1135 $status->value
= self
::AS_SUMMARY_NEEDED
;
1136 wfProfileOut( __METHOD__
);
1141 # And a similar thing for new sections
1142 if ( $this->section
== 'new' && !$this->allowBlankSummary
) {
1143 if ( trim( $this->summary
) == '' ) {
1144 $this->missingSummary
= true;
1145 $status->fatal( 'missingsummary' ); // or 'missingcommentheader' if $section == 'new'. Blegh
1146 $status->value
= self
::AS_SUMMARY_NEEDED
;
1147 wfProfileOut( __METHOD__
);
1153 wfProfileIn( __METHOD__
. '-sectionanchor' );
1154 $sectionanchor = '';
1155 if ( $this->section
== 'new' ) {
1156 if ( $this->textbox1
== '' ) {
1157 $this->missingComment
= true;
1158 $status->fatal( 'missingcommenttext' );
1159 $status->value
= self
::AS_TEXTBOX_EMPTY
;
1160 wfProfileOut( __METHOD__
. '-sectionanchor' );
1161 wfProfileOut( __METHOD__
);
1164 if ( $this->summary
!= '' ) {
1165 $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->summary
);
1166 # This is a new section, so create a link to the new section
1167 # in the revision summary.
1168 $cleanSummary = $wgParser->stripSectionName( $this->summary
);
1169 $this->summary
= wfMsgForContent( 'newsectionsummary', $cleanSummary );
1171 } elseif ( $this->section
!= '' ) {
1172 # Try to get a section anchor from the section source, redirect to edited section if header found
1173 # XXX: might be better to integrate this into Article::replaceSection
1174 # for duplicate heading checking and maybe parsing
1175 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
1176 # we can't deal with anchors, includes, html etc in the header for now,
1177 # headline would need to be parsed to improve this
1178 if ( $hasmatch && strlen( $matches[2] ) > 0 ) {
1179 $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $matches[2] );
1182 $result['sectionanchor'] = $sectionanchor;
1183 wfProfileOut( __METHOD__
. '-sectionanchor' );
1185 // Save errors may fall down to the edit form, but we've now
1186 // merged the section into full text. Clear the section field
1187 // so that later submission of conflict forms won't try to
1188 // replace that into a duplicated mess.
1189 $this->textbox1
= $text;
1190 $this->section
= '';
1192 $status->value
= self
::AS_SUCCESS_UPDATE
;
1195 // Check for length errors again now that the section is merged in
1196 $this->kblength
= (int)( strlen( $text ) / 1024 );
1197 if ( $this->kblength
> $wgMaxArticleSize ) {
1198 $this->tooBig
= true;
1199 $status->setResult( false, self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
);
1200 wfProfileOut( __METHOD__
);
1204 $flags = EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
1205 ( $new ? EDIT_NEW
: EDIT_UPDATE
) |
1206 ( ( $this->minoredit
&& !$this->isNew
) ? EDIT_MINOR
: 0 ) |
1207 ( $bot ? EDIT_FORCE_BOT
: 0 );
1209 $doEditStatus = $this->mArticle
->doEdit( $text, $this->summary
, $flags );
1211 if ( $doEditStatus->isOK() ) {
1212 $result['redirect'] = Title
::newFromRedirect( $text ) !== null;
1213 $this->commitWatch();
1214 wfProfileOut( __METHOD__
);
1217 $this->isConflict
= true;
1218 $doEditStatus->value
= self
::AS_END
; // Destroys data doEdit() put in $status->value but who cares
1219 wfProfileOut( __METHOD__
);
1220 return $doEditStatus;
1225 * Commit the change of watch status
1227 protected function commitWatch() {
1229 if ( $this->watchthis
xor $this->mTitle
->userIsWatching() ) {
1230 $dbw = wfGetDB( DB_MASTER
);
1232 if ( $this->watchthis
) {
1233 WatchAction
::doWatch( $this->mTitle
, $wgUser );
1235 WatchAction
::doUnwatch( $this->mTitle
, $wgUser );
1242 * Check if no edits were made by other users since
1243 * the time a user started editing the page. Limit to
1244 * 50 revisions for the sake of performance.
1247 * @param $edittime string
1251 protected function userWasLastToEdit( $id, $edittime ) {
1252 if( !$id ) return false;
1253 $dbw = wfGetDB( DB_MASTER
);
1254 $res = $dbw->select( 'revision',
1257 'rev_page' => $this->mArticle
->getId(),
1258 'rev_timestamp > '.$dbw->addQuotes( $dbw->timestamp($edittime) )
1261 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
1262 foreach ( $res as $row ) {
1263 if( $row->rev_user
!= $id ) {
1271 * Check given input text against $wgSpamRegex, and return the text of the first match.
1273 * @param $text string
1275 * @return string|false matching string or false
1277 public static function matchSpamRegex( $text ) {
1278 global $wgSpamRegex;
1279 // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
1280 $regexes = (array)$wgSpamRegex;
1281 return self
::matchSpamRegexInternal( $text, $regexes );
1285 * Check given input text against $wgSpamRegex, and return the text of the first match.
1287 * @parma $text string
1289 * @return string|false matching string or false
1291 public static function matchSummarySpamRegex( $text ) {
1292 global $wgSummarySpamRegex;
1293 $regexes = (array)$wgSummarySpamRegex;
1294 return self
::matchSpamRegexInternal( $text, $regexes );
1298 * @param $text string
1299 * @param $regexes array
1300 * @return bool|string
1302 protected static function matchSpamRegexInternal( $text, $regexes ) {
1303 foreach( $regexes as $regex ) {
1305 if( preg_match( $regex, $text, $matches ) ) {
1313 * Initialise form fields in the object
1314 * Called on the first invocation, e.g. when a user clicks an edit link
1315 * @return bool -- if the requested section is valid
1317 function initialiseForm() {
1319 $this->edittime
= $this->mArticle
->getTimestamp();
1320 $this->textbox1
= $this->getContent( false );
1321 // activate checkboxes if user wants them to be always active
1322 # Sort out the "watch" checkbox
1323 if ( $wgUser->getOption( 'watchdefault' ) ) {
1325 $this->watchthis
= true;
1326 } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
1328 $this->watchthis
= true;
1329 } elseif ( $this->mTitle
->userIsWatching() ) {
1331 $this->watchthis
= true;
1333 if ( $wgUser->getOption( 'minordefault' ) && !$this->isNew
) {
1334 $this->minoredit
= true;
1336 if ( $this->textbox1
=== false ) {
1343 function setHeaders() {
1345 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1346 if ( $this->formtype
== 'preview' ) {
1347 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
1349 if ( $this->isConflict
) {
1350 $wgOut->setPageTitle( wfMsg( 'editconflict', $this->getContextTitle()->getPrefixedText() ) );
1351 } elseif ( $this->section
!= '' ) {
1352 $msg = $this->section
== 'new' ?
'editingcomment' : 'editingsection';
1353 $wgOut->setPageTitle( wfMsg( $msg, $this->getContextTitle()->getPrefixedText() ) );
1355 # Use the title defined by DISPLAYTITLE magic word when present
1356 if ( isset( $this->mParserOutput
)
1357 && ( $dt = $this->mParserOutput
->getDisplayTitle() ) !== false ) {
1360 $title = $this->getContextTitle()->getPrefixedText();
1362 $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
1367 * Send the edit form and related headers to $wgOut
1368 * @param $formCallback Callback that takes an OutputPage parameter; will be called
1369 * during form output near the top, for captchas and the like.
1371 function showEditForm( $formCallback = null ) {
1372 global $wgOut, $wgUser, $wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
1374 wfProfileIn( __METHOD__
);
1376 #need to parse the preview early so that we know which templates are used,
1377 #otherwise users with "show preview after edit box" will get a blank list
1378 #we parse this near the beginning so that setHeaders can do the title
1379 #setting work instead of leaving it in getPreviewText
1380 $previewOutput = '';
1381 if ( $this->formtype
== 'preview' ) {
1382 $previewOutput = $this->getPreviewText();
1385 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) );
1387 $this->setHeaders();
1389 # Enabled article-related sidebar, toplinks, etc.
1390 $wgOut->setArticleRelated( true );
1392 if ( $this->showHeader() === false ) {
1393 wfProfileOut( __METHOD__
);
1397 $action = htmlspecialchars( $this->getActionURL( $this->getContextTitle() ) );
1399 if ( $wgUser->getOption( 'showtoolbar' ) and !$this->isCssJsSubpage
) {
1400 # prepare toolbar for edit buttons
1401 $toolbar = EditPage
::getEditToolbar();
1406 $wgOut->addHTML( $this->editFormPageTop
);
1408 if ( $wgUser->getOption( 'previewontop' ) ) {
1409 $this->displayPreviewArea( $previewOutput, true );
1412 $wgOut->addHTML( $this->editFormTextTop
);
1414 $templates = $this->getTemplates();
1415 $formattedtemplates = Linker
::formatTemplates( $templates, $this->preview
, $this->section
!= '');
1417 $distantTemplates = $this->getDistantTemplates();
1418 $formattedDistantTemplates = Linker
::formatDistantTemplates( $distantTemplates, $this->preview
, $this->section
!= '' );
1420 $hiddencats = $this->mArticle
->getHiddenCategories();
1421 $formattedhiddencats = Linker
::formatHiddenCategories( $hiddencats );
1423 if ( $this->wasDeletedSinceLastEdit() && 'save' != $this->formtype
) {
1424 $wgOut->wrapWikiMsg(
1425 "<div class='error mw-deleted-while-editing'>\n$1\n</div>",
1426 'deletedwhileediting' );
1427 } elseif ( $this->wasDeletedSinceLastEdit() ) {
1428 // Hide the toolbar and edit area, user can click preview to get it back
1429 // Add an confirmation checkbox and explanation.
1431 // @todo move this to a cleaner conditional instead of blanking a variable
1433 $wgOut->addHTML( <<<HTML
1434 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1438 if ( is_callable( $formCallback ) ) {
1439 call_user_func_array( $formCallback, array( &$wgOut ) );
1442 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1444 // Put these up at the top to ensure they aren't lost on early form submission
1445 $this->showFormBeforeText();
1447 if ( $this->wasDeletedSinceLastEdit() && 'save' == $this->formtype
) {
1448 $username = $this->lastDelete
->user_name
;
1449 $comment = $this->lastDelete
->log_comment
;
1451 // It is better to not parse the comment at all than to have templates expanded in the middle
1452 // TODO: can the checkLabel be moved outside of the div so that wrapWikiMsg could be used?
1453 $key = $comment === ''
1454 ?
'confirmrecreate-noreason'
1455 : 'confirmrecreate';
1457 '<div class="mw-confirm-recreate">' .
1458 wfMsgExt( $key, 'parseinline', $username, "<nowiki>$comment</nowiki>" ) .
1459 Xml
::checkLabel( wfMsg( 'recreate' ), 'wpRecreate', 'wpRecreate', false,
1460 array( 'title' => Linker
::titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' )
1466 # If a blank edit summary was previously provided, and the appropriate
1467 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1468 # user being bounced back more than once in the event that a summary
1471 # For a bit more sophisticated detection of blank summaries, hash the
1472 # automatic one and pass that in the hidden field wpAutoSummary.
1473 if ( $this->missingSummary ||
1474 ( $this->section
== 'new' && $this->nosummary
) )
1475 $wgOut->addHTML( Html
::hidden( 'wpIgnoreBlankSummary', true ) );
1476 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
1477 $wgOut->addHTML( Html
::hidden( 'wpAutoSummary', $autosumm ) );
1479 $wgOut->addHTML( Html
::hidden( 'oldid', $this->mArticle
->getOldID() ) );
1481 if ( $this->section
== 'new' ) {
1482 $this->showSummaryInput( true, $this->summary
);
1483 $wgOut->addHTML( $this->getSummaryPreview( true, $this->summary
) );
1486 $wgOut->addHTML( $this->editFormTextBeforeContent
);
1488 $wgOut->addHTML( $toolbar );
1490 if ( $this->isConflict
) {
1491 // In an edit conflict bypass the overrideable content form method
1492 // and fallback to the raw wpTextbox1 since editconflicts can't be
1493 // resolved between page source edits and custom ui edits using the
1495 $this->showTextbox1( null, $this->getContent() );
1497 $this->showContentForm();
1500 $wgOut->addHTML( $this->editFormTextAfterContent
);
1502 $wgOut->addWikiText( $this->getCopywarn() );
1503 if ( isset($this->editFormTextAfterWarn
) && $this->editFormTextAfterWarn
!== '' )
1504 $wgOut->addHTML( $this->editFormTextAfterWarn
);
1506 $this->showStandardInputs();
1508 $this->showFormAfterText();
1510 $this->showTosSummary();
1511 $this->showEditTools();
1513 $wgOut->addHTML( <<<HTML
1514 {$this->editFormTextAfterTools}
1515 <div class='templatesUsed'>
1516 {$formattedtemplates}
1521 if ( $wgEnableInterwikiTranscluding && $wgEnableInterwikiTemplatesTracking ) {
1522 $wgOut->addHTML( <<<HTML
1523 {$this->editFormTextAfterTools}
1524 <div class='distantTemplatesUsed'>
1525 {$formattedDistantTemplates}
1531 $wgOut->addHTML( <<<HTML
1532 {$this->editFormTextAfterTools}
1533 <div class='hiddencats'>
1534 {$formattedhiddencats}
1539 if ( $this->isConflict
)
1540 $this->showConflict();
1542 $wgOut->addHTML( $this->editFormTextBottom
);
1543 $wgOut->addHTML( "</form>\n" );
1544 if ( !$wgUser->getOption( 'previewontop' ) ) {
1545 $this->displayPreviewArea( $previewOutput, false );
1548 wfProfileOut( __METHOD__
);
1551 protected function showHeader() {
1552 global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang;
1553 if ( $this->isConflict
) {
1554 $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
1555 $this->edittime
= $this->mArticle
->getTimestamp();
1557 if ( $this->section
!= '' && !$this->isSectionEditSupported() ) {
1558 // We use $this->section to much before this and getVal('wgSection') directly in other places
1559 // at this point we can't reset $this->section to '' to fallback to non-section editing.
1560 // Someone is welcome to try refactoring though
1561 $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
1565 if ( $this->section
!= '' && $this->section
!= 'new' ) {
1567 if ( !$this->summary
&& !$this->preview
&& !$this->diff
) {
1568 preg_match( "/^(=+)(.+)\\1/mi", $this->textbox1
, $matches );
1569 if ( !empty( $matches[2] ) ) {
1571 $this->summary
= "/* " .
1572 $wgParser->stripSectionName(trim($matches[2])) .
1578 if ( $this->missingComment
) {
1579 $wgOut->wrapWikiMsg( "<div id='mw-missingcommenttext'>\n$1\n</div>", 'missingcommenttext' );
1582 if ( $this->missingSummary
&& $this->section
!= 'new' ) {
1583 $wgOut->wrapWikiMsg( "<div id='mw-missingsummary'>\n$1\n</div>", 'missingsummary' );
1586 if ( $this->missingSummary
&& $this->section
== 'new' ) {
1587 $wgOut->wrapWikiMsg( "<div id='mw-missingcommentheader'>\n$1\n</div>", 'missingcommentheader' );
1590 if ( $this->hookError
!== '' ) {
1591 $wgOut->addWikiText( $this->hookError
);
1594 if ( !$this->checkUnicodeCompliantBrowser() ) {
1595 $wgOut->addWikiMsg( 'nonunicodebrowser' );
1598 if ( isset( $this->mArticle
) && isset( $this->mArticle
->mRevision
) ) {
1599 // Let sysop know that this will make private content public if saved
1601 if ( !$this->mArticle
->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1602 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-permission' );
1603 } elseif ( $this->mArticle
->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1604 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-view' );
1607 if ( !$this->mArticle
->mRevision
->isCurrent() ) {
1608 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
1609 $wgOut->addWikiMsg( 'editingold' );
1614 if ( wfReadOnly() ) {
1615 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
1616 } elseif ( $wgUser->isAnon() ) {
1617 if ( $this->formtype
!= 'preview' ) {
1618 $wgOut->wrapWikiMsg( "<div id=\"mw-anon-edit-warning\">\n$1</div>", 'anoneditwarning' );
1620 $wgOut->wrapWikiMsg( "<div id=\"mw-anon-preview-warning\">\n$1</div>", 'anonpreviewwarning' );
1623 if ( $this->isCssJsSubpage
) {
1624 # Check the skin exists
1625 if ( $this->isWrongCaseCssJsPage
) {
1626 $wgOut->wrapWikiMsg( "<div class='error' id='mw-userinvalidcssjstitle'>\n$1\n</div>", array( 'userinvalidcssjstitle', $this->getContextTitle()->getSkinFromCssJsSubpage() ) );
1628 if ( $this->formtype
!== 'preview' ) {
1629 if ( $this->isCssSubpage
)
1630 $wgOut->wrapWikiMsg( "<div id='mw-usercssyoucanpreview'>\n$1\n</div>", array( 'usercssyoucanpreview' ) );
1631 if ( $this->isJsSubpage
)
1632 $wgOut->wrapWikiMsg( "<div id='mw-userjsyoucanpreview'>\n$1\n</div>", array( 'userjsyoucanpreview' ) );
1637 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
1638 # Is the title semi-protected?
1639 if ( $this->mTitle
->isSemiProtected() ) {
1640 $noticeMsg = 'semiprotectedpagewarning';
1642 # Then it must be protected based on static groups (regular)
1643 $noticeMsg = 'protectedpagewarning';
1645 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
->getPrefixedText(), '',
1646 array( 'lim' => 1, 'msgKey' => array( $noticeMsg ) ) );
1648 if ( $this->mTitle
->isCascadeProtected() ) {
1649 # Is this page under cascading protection from some source pages?
1650 list($cascadeSources, /* $restrictions */) = $this->mTitle
->getCascadeProtectionSources();
1651 $notice = "<div class='mw-cascadeprotectedwarning'>\n$1\n";
1652 $cascadeSourcesCount = count( $cascadeSources );
1653 if ( $cascadeSourcesCount > 0 ) {
1654 # Explain, and list the titles responsible
1655 foreach( $cascadeSources as $page ) {
1656 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1659 $notice .= '</div>';
1660 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', $cascadeSourcesCount ) );
1662 if ( !$this->mTitle
->exists() && $this->mTitle
->getRestrictions( 'create' ) ) {
1663 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
->getPrefixedText(), '',
1665 'showIfEmpty' => false,
1666 'msgKey' => array( 'titleprotectedwarning' ),
1667 'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ) );
1670 if ( $this->kblength
=== false ) {
1671 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
1674 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
1675 $wgOut->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
1676 array( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgLang->formatNum( $wgMaxArticleSize ) ) );
1678 if( !wfMessage('longpage-hint')->isDisabled() ) {
1679 $wgOut->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
1680 array( 'longpage-hint', $wgLang->formatSize( strlen( $this->textbox1
) ), strlen( $this->textbox1
) )
1687 * Standard summary input and label (wgSummary), abstracted so EditPage
1688 * subclasses may reorganize the form.
1689 * Note that you do not need to worry about the label's for=, it will be
1690 * inferred by the id given to the input. You can remove them both by
1691 * passing array( 'id' => false ) to $userInputAttrs.
1693 * @param $summary string The value of the summary input
1694 * @param $labelText string The html to place inside the label
1695 * @param $inputAttrs array of attrs to use on the input
1696 * @param $spanLabelAttrs array of attrs to use on the span inside the label
1698 * @return array An array in the format array( $label, $input )
1700 function getSummaryInput($summary = "", $labelText = null, $inputAttrs = null, $spanLabelAttrs = null) {
1701 //Note: the maxlength is overriden in JS to 250 and to make it use UTF-8 bytes, not characters.
1702 $inputAttrs = ( is_array($inputAttrs) ?
$inputAttrs : array() ) +
array(
1703 'id' => 'wpSummary',
1704 'maxlength' => '200',
1707 'spellcheck' => 'true',
1708 ) + Linker
::tooltipAndAccesskeyAttribs( 'summary' );
1710 $spanLabelAttrs = ( is_array($spanLabelAttrs) ?
$spanLabelAttrs : array() ) +
array(
1711 'class' => $this->missingSummary ?
'mw-summarymissed' : 'mw-summary',
1712 'id' => "wpSummaryLabel"
1717 $label = Xml
::tags( 'label', $inputAttrs['id'] ?
array( 'for' => $inputAttrs['id'] ) : null, $labelText );
1718 $label = Xml
::tags( 'span', $spanLabelAttrs, $label );
1721 $input = Html
::input( 'wpSummary', $summary, 'text', $inputAttrs );
1723 return array( $label, $input );
1727 * @param $isSubjectPreview Boolean: true if this is the section subject/title
1728 * up top, or false if this is the comment summary
1729 * down below the textarea
1730 * @param $summary String: The text of the summary to display
1733 protected function showSummaryInput( $isSubjectPreview, $summary = "" ) {
1734 global $wgOut, $wgContLang;
1735 # Add a class if 'missingsummary' is triggered to allow styling of the summary line
1736 $summaryClass = $this->missingSummary ?
'mw-summarymissed' : 'mw-summary';
1737 if ( $isSubjectPreview ) {
1738 if ( $this->nosummary
) {
1742 if ( !$this->mShowSummaryField
) {
1746 $summary = $wgContLang->recodeForEdit( $summary );
1747 $labelText = wfMsgExt( $isSubjectPreview ?
'subject' : 'summary', 'parseinline' );
1748 list($label, $input) = $this->getSummaryInput($summary, $labelText, array( 'class' => $summaryClass ), array());
1749 $wgOut->addHTML("{$label} {$input}");
1753 * @param $isSubjectPreview Boolean: true if this is the section subject/title
1754 * up top, or false if this is the comment summary
1755 * down below the textarea
1756 * @param $summary String: the text of the summary to display
1759 protected function getSummaryPreview( $isSubjectPreview, $summary = "" ) {
1760 if ( !$summary ||
( !$this->preview
&& !$this->diff
) )
1765 if ( $isSubjectPreview )
1766 $summary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $summary ) );
1768 $message = $isSubjectPreview ?
'subject-preview' : 'summary-preview';
1770 $summary = wfMsgExt( $message, 'parseinline' ) . Linker
::commentBlock( $summary, $this->mTitle
, $isSubjectPreview );
1771 return Xml
::tags( 'div', array( 'class' => 'mw-summary-preview' ), $summary );
1774 protected function showFormBeforeText() {
1776 $section = htmlspecialchars( $this->section
);
1777 $wgOut->addHTML( <<<HTML
1778 <input type='hidden' value="{$section}" name="wpSection" />
1779 <input type='hidden' value="{$this->starttime}" name="wpStarttime" />
1780 <input type='hidden' value="{$this->edittime}" name="wpEdittime" />
1781 <input type='hidden' value="{$this->scrolltop}" name="wpScrolltop" id="wpScrolltop" />
1785 if ( !$this->checkUnicodeCompliantBrowser() )
1786 $wgOut->addHTML(Html
::hidden( 'safemode', '1' ));
1789 protected function showFormAfterText() {
1790 global $wgOut, $wgUser;
1792 * To make it harder for someone to slip a user a page
1793 * which submits an edit form to the wiki without their
1794 * knowledge, a random token is associated with the login
1795 * session. If it's not passed back with the submission,
1796 * we won't save the page, or render user JavaScript and
1799 * For anon editors, who may not have a session, we just
1800 * include the constant suffix to prevent editing from
1801 * broken text-mangling proxies.
1803 $wgOut->addHTML( "\n" . Html
::hidden( "wpEditToken", $wgUser->editToken() ) . "\n" );
1807 * Subpage overridable method for printing the form for page content editing
1808 * By default this simply outputs wpTextbox1
1809 * Subclasses can override this to provide a custom UI for editing;
1810 * be it a form, or simply wpTextbox1 with a modified content that will be
1811 * reverse modified when extracted from the post data.
1812 * Note that this is basically the inverse for importContentFormData
1814 protected function showContentForm() {
1815 $this->showTextbox1();
1819 * Method to output wpTextbox1
1820 * The $textoverride method can be used by subclasses overriding showContentForm
1821 * to pass back to this method.
1823 * @param $customAttribs An array of html attributes to use in the textarea
1824 * @param $textoverride String: optional text to override $this->textarea1 with
1826 protected function showTextbox1($customAttribs = null, $textoverride = null) {
1827 $classes = array(); // Textarea CSS
1828 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
1829 # Is the title semi-protected?
1830 if ( $this->mTitle
->isSemiProtected() ) {
1831 $classes[] = 'mw-textarea-sprotected';
1833 # Then it must be protected based on static groups (regular)
1834 $classes[] = 'mw-textarea-protected';
1836 # Is the title cascade-protected?
1837 if ( $this->mTitle
->isCascadeProtected() ) {
1838 $classes[] = 'mw-textarea-cprotected';
1841 $attribs = array( 'tabindex' => 1 );
1842 if ( is_array($customAttribs) )
1843 $attribs +
= $customAttribs;
1845 if ( $this->wasDeletedSinceLastEdit() )
1846 $attribs['type'] = 'hidden';
1847 if ( !empty( $classes ) ) {
1848 if ( isset($attribs['class']) )
1849 $classes[] = $attribs['class'];
1850 $attribs['class'] = implode( ' ', $classes );
1853 $this->showTextbox( isset($textoverride) ?
$textoverride : $this->textbox1
, 'wpTextbox1', $attribs );
1856 protected function showTextbox2() {
1857 $this->showTextbox( $this->textbox2
, 'wpTextbox2', array( 'tabindex' => 6, 'readonly' ) );
1860 protected function showTextbox( $content, $name, $customAttribs = array() ) {
1861 global $wgOut, $wgUser;
1863 $wikitext = $this->safeUnicodeOutput( $content );
1864 if ( $wikitext !== '' ) {
1865 // Ensure there's a newline at the end, otherwise adding lines
1867 // But don't add a newline if the ext is empty, or Firefox in XHTML
1868 // mode will show an extra newline. A bit annoying.
1872 $attribs = $customAttribs +
array(
1875 'cols' => $wgUser->getIntOption( 'cols' ),
1876 'rows' => $wgUser->getIntOption( 'rows' ),
1877 'style' => '' // avoid php notices when appending preferences (appending allows customAttribs['style'] to still work
1880 $pageLang = $this->mTitle
->getPageLanguage();
1881 $attribs['lang'] = $pageLang->getCode();
1882 $attribs['dir'] = $pageLang->getDir();
1884 $wgOut->addHTML( Html
::textarea( $name, $wikitext, $attribs ) );
1887 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
1891 $classes[] = 'ontop';
1893 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
1895 if ( $this->formtype
!= 'preview' )
1896 $attribs['style'] = 'display: none;';
1898 $wgOut->addHTML( Xml
::openElement( 'div', $attribs ) );
1900 if ( $this->formtype
== 'preview' ) {
1901 $this->showPreview( $previewOutput );
1904 $wgOut->addHTML( '</div>' );
1906 if ( $this->formtype
== 'diff') {
1912 * Append preview output to $wgOut.
1913 * Includes category rendering if this is a category page.
1915 * @param $text String: the HTML to be output for the preview.
1917 protected function showPreview( $text ) {
1919 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1920 $this->mArticle
->openShowCategory();
1922 # This hook seems slightly odd here, but makes things more
1923 # consistent for extensions.
1924 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1925 $wgOut->addHTML( $text );
1926 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1927 $this->mArticle
->closeShowCategory();
1932 * Give a chance for site and per-namespace customizations of
1933 * terms of service summary link that might exist separately
1934 * from the copyright notice.
1936 * This will display between the save button and the edit tools,
1937 * so should remain short!
1939 protected function showTosSummary() {
1940 $msg = 'editpage-tos-summary';
1941 wfRunHooks( 'EditPageTosSummary', array( $this->mTitle
, &$msg ) );
1942 if( !wfMessage( $msg )->isDisabled() ) {
1944 $wgOut->addHTML( '<div class="mw-tos-summary">' );
1945 $wgOut->addWikiMsg( $msg );
1946 $wgOut->addHTML( '</div>' );
1950 protected function showEditTools() {
1952 $wgOut->addHTML( '<div class="mw-editTools">' .
1953 wfMessage( 'edittools' )->inContentLanguage()->parse() .
1957 protected function getCopywarn() {
1958 global $wgRightsText;
1959 if ( $wgRightsText ) {
1960 $copywarnMsg = array( 'copyrightwarning',
1961 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1964 $copywarnMsg = array( 'copyrightwarning2',
1965 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
1967 // Allow for site and per-namespace customization of contribution/copyright notice.
1968 wfRunHooks( 'EditPageCopyrightWarning', array( $this->mTitle
, &$copywarnMsg ) );
1970 return "<div id=\"editpage-copywarn\">\n" .
1971 call_user_func_array("wfMsgNoTrans", $copywarnMsg) . "\n</div>";
1974 protected function showStandardInputs( &$tabindex = 2 ) {
1976 $wgOut->addHTML( "<div class='editOptions'>\n" );
1978 if ( $this->section
!= 'new' ) {
1979 $this->showSummaryInput( false, $this->summary
);
1980 $wgOut->addHTML( $this->getSummaryPreview( false, $this->summary
) );
1983 $checkboxes = $this->getCheckboxes( $tabindex,
1984 array( 'minor' => $this->minoredit
, 'watch' => $this->watchthis
) );
1985 $wgOut->addHTML( "<div class='editCheckboxes'>" . implode( $checkboxes, "\n" ) . "</div>\n" );
1986 $wgOut->addHTML( "<div class='editButtons'>\n" );
1987 $wgOut->addHTML( implode( $this->getEditButtons( $tabindex ), "\n" ) . "\n" );
1989 $cancel = $this->getCancelLink();
1990 if ( $cancel !== '' ) {
1991 $cancel .= wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1993 $edithelpurl = Skin
::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ) );
1994 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1995 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1996 htmlspecialchars( wfMsg( 'newwindow' ) );
1997 $wgOut->addHTML( " <span class='editHelp'>{$cancel}{$edithelp}</span>\n" );
1998 $wgOut->addHTML( "</div><!-- editButtons -->\n</div><!-- editOptions -->\n" );
2002 * Show an edit conflict. textbox1 is already shown in showEditForm().
2003 * If you want to use another entry point to this function, be careful.
2005 protected function showConflict() {
2007 $this->textbox2
= $this->textbox1
;
2008 $this->textbox1
= $this->getContent();
2009 if ( wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
2010 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
2012 $de = new DifferenceEngine( $this->mTitle
);
2013 $de->setText( $this->textbox2
, $this->textbox1
);
2014 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
2016 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
2017 $this->showTextbox2();
2021 protected function getLastDelete() {
2022 $dbr = wfGetDB( DB_SLAVE
);
2023 $data = $dbr->selectRow(
2024 array( 'logging', 'user' ),
2035 array( 'log_namespace' => $this->mTitle
->getNamespace(),
2036 'log_title' => $this->mTitle
->getDBkey(),
2037 'log_type' => 'delete',
2038 'log_action' => 'delete',
2039 'user_id=log_user' ),
2041 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' )
2043 // Quick paranoid permission checks...
2044 if( is_object( $data ) ) {
2045 if( $data->log_deleted
& LogPage
::DELETED_USER
)
2046 $data->user_name
= wfMsgHtml( 'rev-deleted-user' );
2047 if( $data->log_deleted
& LogPage
::DELETED_COMMENT
)
2048 $data->log_comment
= wfMsgHtml( 'rev-deleted-comment' );
2054 * Get the rendered text for previewing.
2057 function getPreviewText() {
2058 global $wgOut, $wgUser, $wgParser;
2060 wfProfileIn( __METHOD__
);
2062 if ( $this->mTriedSave
&& !$this->mTokenOk
) {
2063 if ( $this->mTokenOkExceptSuffix
) {
2064 $note = wfMsg( 'token_suffix_mismatch' );
2066 $note = wfMsg( 'session_fail_preview' );
2068 } elseif ( $this->incompleteForm
) {
2069 $note = wfMsg( 'edit_form_incomplete' );
2071 $note = wfMsg( 'previewnote' );
2074 $parserOptions = ParserOptions
::newFromUser( $wgUser );
2075 $parserOptions->setEditSection( false );
2076 $parserOptions->setIsPreview( true );
2077 $parserOptions->setIsSectionPreview( !is_null($this->section
) && $this->section
!== '' );
2080 if ( $wgRawHtml && !$this->mTokenOk
) {
2081 // Could be an offsite preview attempt. This is very unsafe if
2082 // HTML is enabled, as it could be an attack.
2084 if ( $this->textbox1
!== '' ) {
2085 // Do not put big scary notice, if previewing the empty
2086 // string, which happens when you initially edit
2087 // a category page, due to automatic preview-on-open.
2088 $parsedNote = $wgOut->parse( "<div class='previewnote'>" .
2089 wfMsg( 'session_fail_preview_html' ) . "</div>", true, /* interface */true );
2091 wfProfileOut( __METHOD__
);
2095 # don't parse non-wikitext pages, show message about preview
2096 # 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?
2098 if ( $this->isCssJsSubpage ||
!$this->mTitle
->isWikitextPage() ) {
2099 if( $this->mTitle
->isCssJsSubpage() ) {
2101 } elseif( $this->mTitle
->isCssOrJsPage() ) {
2107 # Used messages to make sure grep find them:
2108 # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
2110 if (preg_match( "/\\.css$/", $this->mTitle
->getText() ) ) {
2111 $previewtext = "<div id='mw-{$level}csspreview'>\n" . wfMsg( "{$level}csspreview" ) . "\n</div>";
2112 $class = "mw-code mw-css";
2113 } elseif (preg_match( "/\\.js$/", $this->mTitle
->getText() ) ) {
2114 $previewtext = "<div id='mw-{$level}jspreview'>\n" . wfMsg( "{$level}jspreview" ) . "\n</div>";
2115 $class = "mw-code mw-js";
2117 throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' );
2121 $parserOptions->setTidy( true );
2122 $parserOutput = $wgParser->parse( $previewtext, $this->mTitle
, $parserOptions );
2123 $previewHTML = $parserOutput->mText
;
2124 $previewHTML .= "<pre class=\"$class\" dir=\"ltr\">\n" . htmlspecialchars( $this->textbox1
) . "\n</pre>\n";
2126 $rt = Title
::newFromRedirectArray( $this->textbox1
);
2128 $previewHTML = $this->mArticle
->viewRedirect( $rt, false );
2130 $toparse = $this->textbox1
;
2132 # If we're adding a comment, we need to show the
2133 # summary as the headline
2134 if ( $this->section
== "new" && $this->summary
!= "" ) {
2135 $toparse = "== {$this->summary} ==\n\n" . $toparse;
2138 wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
2140 $parserOptions->setTidy( true );
2141 $parserOptions->enableLimitReport();
2142 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ),
2143 $this->mTitle
, $parserOptions );
2145 $previewHTML = $parserOutput->getText();
2146 $this->mParserOutput
= $parserOutput;
2147 $wgOut->addParserOutputNoText( $parserOutput );
2149 if ( count( $parserOutput->getWarnings() ) ) {
2150 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
2155 if( $this->isConflict
) {
2156 $conflict = '<h2 id="mw-previewconflict">' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
2158 $conflict = '<hr />';
2161 $previewhead = "<div class='previewnote'>\n" .
2162 '<h2 id="mw-previewheader">' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>" .
2163 $wgOut->parse( $note, true, /* interface */true ) . $conflict . "</div>\n";
2165 $pageLang = $this->mTitle
->getPageLanguage();
2166 $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
2167 'class' => 'mw-content-'.$pageLang->getDir() );
2168 $previewHTML = Html
::rawElement( 'div', $attribs, $previewHTML );
2170 wfProfileOut( __METHOD__
);
2171 return $previewhead . $previewHTML . $this->previewTextAfterContent
;
2177 function getTemplates() {
2178 if ( $this->preview ||
$this->section
!= '' ) {
2179 $templates = array();
2180 if ( !isset( $this->mParserOutput
) ) {
2183 foreach( $this->mParserOutput
->getTemplates() as $ns => $template) {
2184 foreach( array_keys( $template ) as $dbk ) {
2185 $templates[] = Title
::makeTitle($ns, $dbk);
2190 return $this->mArticle
->getUsedTemplates();
2194 function getDistantTemplates() {
2195 global $wgEnableInterwikiTemplatesTracking;
2196 if ( !$wgEnableInterwikiTemplatesTracking ) {
2199 if ( $this->preview ||
$this->section
!= '' ) {
2200 $templates = array();
2201 if ( !isset( $this->mParserOutput
) ) return $templates;
2202 $templatesList = $this->mParserOutput
->getDistantTemplates();
2203 foreach( $templatesList as $prefix => $templatesbyns ) {
2204 foreach( $templatesbyns as $ns => $template ) {
2205 foreach( array_keys( $template ) as $dbk ) {
2206 $templates[] = Title
::makeTitle( $ns, $dbk, null, $prefix );
2212 return $this->mArticle
->getUsedDistantTemplates();
2217 * Call the stock "user is blocked" page
2219 function blockedPage() {
2221 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
2223 # If the user made changes, preserve them when showing the markup
2224 # (This happens when a user is blocked during edit, for instance)
2225 $first = $this->firsttime ||
( !$this->save
&& $this->textbox1
== '' );
2227 $source = $this->mTitle
->exists() ?
$this->getContent() : false;
2229 $source = $this->textbox1
;
2232 # Spit out the source or the user's modified version
2233 if ( $source !== false ) {
2234 $wgOut->addHTML( '<hr />' );
2235 $wgOut->addWikiMsg( $first ?
'blockedoriginalsource' : 'blockededitsource', $this->mTitle
->getPrefixedText() );
2236 $this->showTextbox1( array( 'readonly' ), $source );
2241 * Produce the stock "please login to edit pages" page
2243 function userNotLoggedInPage() {
2246 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
2247 $loginLink = Linker
::linkKnown(
2249 wfMsgHtml( 'loginreqlink' ),
2251 array( 'returnto' => $this->getContextTitle()->getPrefixedText() )
2254 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
2255 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2256 $wgOut->setArticleRelated( false );
2258 $wgOut->addHTML( wfMessage( 'whitelistedittext' )->rawParams( $loginLink )->parse() );
2259 $wgOut->returnToMain( false, $this->getContextTitle() );
2263 * Creates a basic error page which informs the user that
2264 * they have attempted to edit a nonexistent section.
2266 function noSuchSectionPage() {
2269 $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
2270 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2271 $wgOut->setArticleRelated( false );
2273 $res = wfMsgExt( 'nosuchsectiontext', 'parse', $this->section
);
2274 wfRunHooks( 'EditPageNoSuchSection', array( &$this, &$res ) );
2275 $wgOut->addHTML( $res );
2277 $wgOut->returnToMain( false, $this->mTitle
);
2281 * Produce the stock "your edit contains spam" page
2283 * @param $match Text which triggered one or more filters
2284 * @deprecated since 1.17 Use method spamPageWithContent() instead
2286 static function spamPage( $match = false ) {
2287 global $wgOut, $wgTitle;
2289 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
2290 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2291 $wgOut->setArticleRelated( false );
2293 $wgOut->addHTML( '<div id="spamprotected">' );
2294 $wgOut->addWikiMsg( 'spamprotectiontext' );
2296 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
2298 $wgOut->addHTML( '</div>' );
2300 $wgOut->returnToMain( false, $wgTitle );
2304 * Show "your edit contains spam" page with your diff and text
2306 * @param $match Text which triggered one or more filters
2308 public function spamPageWithContent( $match = false ) {
2310 $this->textbox2
= $this->textbox1
;
2312 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
2313 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2314 $wgOut->setArticleRelated( false );
2316 $wgOut->addHTML( '<div id="spamprotected">' );
2317 $wgOut->addWikiMsg( 'spamprotectiontext' );
2319 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
2321 $wgOut->addHTML( '</div>' );
2323 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
2324 $de = new DifferenceEngine( $this->mTitle
);
2325 $de->setText( $this->getContent(), $this->textbox2
);
2326 $de->showDiff( wfMsg( "storedversion" ), wfMsg( "yourtext" ) );
2328 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
2329 $this->showTextbox2();
2331 $wgOut->addReturnTo( $this->getContextTitle(), array( 'action' => 'edit' ) );
2339 * @parma $editText string
2343 function mergeChangesInto( &$editText ){
2344 wfProfileIn( __METHOD__
);
2346 $db = wfGetDB( DB_MASTER
);
2348 // This is the revision the editor started from
2349 $baseRevision = $this->getBaseRevision();
2350 if ( is_null( $baseRevision ) ) {
2351 wfProfileOut( __METHOD__
);
2354 $baseText = $baseRevision->getText();
2356 // The current state, we want to merge updates into it
2357 $currentRevision = Revision
::loadFromTitle( $db, $this->mTitle
);
2358 if ( is_null( $currentRevision ) ) {
2359 wfProfileOut( __METHOD__
);
2362 $currentText = $currentRevision->getText();
2365 if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
2366 $editText = $result;
2367 wfProfileOut( __METHOD__
);
2370 wfProfileOut( __METHOD__
);
2376 * Check if the browser is on a blacklist of user-agents known to
2377 * mangle UTF-8 data on form submission. Returns true if Unicode
2378 * should make it through, false if it's known to be a problem.
2382 function checkUnicodeCompliantBrowser() {
2383 global $wgBrowserBlackList;
2384 if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
2385 // No User-Agent header sent? Trust it by default...
2388 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
2389 foreach ( $wgBrowserBlackList as $browser ) {
2390 if ( preg_match($browser, $currentbrowser) ) {
2398 * Format an anchor fragment as it would appear for a given section name
2399 * @param $text String
2403 function sectionAnchor( $text ) {
2405 return $wgParser->guessSectionNameFromWikiText( $text );
2409 * Shows a bulletin board style toolbar for common editing functions.
2410 * It can be disabled in the user preferences.
2411 * The necessary JavaScript code can be found in skins/common/edit.js.
2415 static function getEditToolbar() {
2416 global $wgStylePath, $wgContLang, $wgLang, $wgOut;
2417 global $wgUseTeX, $wgEnableUploads, $wgForeignFileRepos;
2419 $imagesAvailable = $wgEnableUploads ||
count( $wgForeignFileRepos );
2422 * $toolarray is an array of arrays each of which includes the
2423 * filename of the button image (without path), the opening
2424 * tag, the closing tag, optionally a sample text that is
2425 * inserted between the two when no selection is highlighted
2426 * and. The tip text is shown when the user moves the mouse
2429 * Also here: accesskeys (key), which are not used yet until
2430 * someone can figure out a way to make them work in
2431 * IE. However, we should make sure these keys are not defined
2436 'image' => $wgLang->getImageFile( 'button-bold' ),
2437 'id' => 'mw-editbutton-bold',
2439 'close' => '\'\'\'',
2440 'sample' => wfMsg( 'bold_sample' ),
2441 'tip' => wfMsg( 'bold_tip' ),
2445 'image' => $wgLang->getImageFile( 'button-italic' ),
2446 'id' => 'mw-editbutton-italic',
2449 'sample' => wfMsg( 'italic_sample' ),
2450 'tip' => wfMsg( 'italic_tip' ),
2454 'image' => $wgLang->getImageFile( 'button-link' ),
2455 'id' => 'mw-editbutton-link',
2458 'sample' => wfMsg( 'link_sample' ),
2459 'tip' => wfMsg( 'link_tip' ),
2463 'image' => $wgLang->getImageFile( 'button-extlink' ),
2464 'id' => 'mw-editbutton-extlink',
2467 'sample' => wfMsg( 'extlink_sample' ),
2468 'tip' => wfMsg( 'extlink_tip' ),
2472 'image' => $wgLang->getImageFile( 'button-headline' ),
2473 'id' => 'mw-editbutton-headline',
2476 'sample' => wfMsg( 'headline_sample' ),
2477 'tip' => wfMsg( 'headline_tip' ),
2480 $imagesAvailable ?
array(
2481 'image' => $wgLang->getImageFile( 'button-image' ),
2482 'id' => 'mw-editbutton-image',
2483 'open' => '[[' . $wgContLang->getNsText( NS_FILE
) . ':',
2485 'sample' => wfMsg( 'image_sample' ),
2486 'tip' => wfMsg( 'image_tip' ),
2489 $imagesAvailable ?
array(
2490 'image' => $wgLang->getImageFile( 'button-media' ),
2491 'id' => 'mw-editbutton-media',
2492 'open' => '[[' . $wgContLang->getNsText( NS_MEDIA
) . ':',
2494 'sample' => wfMsg( 'media_sample' ),
2495 'tip' => wfMsg( 'media_tip' ),
2499 'image' => $wgLang->getImageFile( 'button-math' ),
2500 'id' => 'mw-editbutton-math',
2502 'close' => "</math>",
2503 'sample' => wfMsg( 'math_sample' ),
2504 'tip' => wfMsg( 'math_tip' ),
2508 'image' => $wgLang->getImageFile( 'button-nowiki' ),
2509 'id' => 'mw-editbutton-nowiki',
2510 'open' => "<nowiki>",
2511 'close' => "</nowiki>",
2512 'sample' => wfMsg( 'nowiki_sample' ),
2513 'tip' => wfMsg( 'nowiki_tip' ),
2517 'image' => $wgLang->getImageFile( 'button-sig' ),
2518 'id' => 'mw-editbutton-signature',
2522 'tip' => wfMsg( 'sig_tip' ),
2526 'image' => $wgLang->getImageFile( 'button-hr' ),
2527 'id' => 'mw-editbutton-hr',
2528 'open' => "\n----\n",
2531 'tip' => wfMsg( 'hr_tip' ),
2535 $toolbar = "<div id='toolbar'>\n";
2538 foreach ( $toolarray as $tool ) {
2544 $image = $wgStylePath . '/common/images/' . $tool['image'],
2545 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2546 // Older browsers show a "speedtip" type message only for ALT.
2547 // Ideally these should be different, realistically they
2548 // probably don't need to be.
2549 $tip = $tool['tip'],
2550 $open = $tool['open'],
2551 $close = $tool['close'],
2552 $sample = $tool['sample'],
2553 $cssId = $tool['id'],
2556 $paramList = implode( ',',
2557 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
2558 $script .= "mw.toolbar.addButton($paramList);\n";
2560 $wgOut->addScript( Html
::inlineScript(
2561 "if ( window.mediaWiki ) {{$script}}"
2564 $toolbar .= "\n</div>";
2566 wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
2572 * Returns an array of html code of the following checkboxes:
2575 * @param $tabindex Current tabindex
2576 * @param $checked Array of checkbox => bool, where bool indicates the checked
2577 * status of the checkbox
2581 public function getCheckboxes( &$tabindex, $checked ) {
2584 $checkboxes = array();
2586 // don't show the minor edit checkbox if it's a new page or section
2587 if ( !$this->isNew
) {
2588 $checkboxes['minor'] = '';
2589 $minorLabel = wfMsgExt( 'minoredit', array( 'parseinline' ) );
2590 if ( $wgUser->isAllowed( 'minoredit' ) ) {
2592 'tabindex' => ++
$tabindex,
2593 'accesskey' => wfMsg( 'accesskey-minoredit' ),
2594 'id' => 'wpMinoredit',
2596 $checkboxes['minor'] =
2597 Xml
::check( 'wpMinoredit', $checked['minor'], $attribs ) .
2598 " <label for='wpMinoredit' id='mw-editpage-minoredit'" .
2599 Xml
::expandAttributes( array( 'title' => Linker
::titleAttrib( 'minoredit', 'withaccess' ) ) ) .
2600 ">{$minorLabel}</label>";
2604 $watchLabel = wfMsgExt( 'watchthis', array( 'parseinline' ) );
2605 $checkboxes['watch'] = '';
2606 if ( $wgUser->isLoggedIn() ) {
2608 'tabindex' => ++
$tabindex,
2609 'accesskey' => wfMsg( 'accesskey-watch' ),
2610 'id' => 'wpWatchthis',
2612 $checkboxes['watch'] =
2613 Xml
::check( 'wpWatchthis', $checked['watch'], $attribs ) .
2614 " <label for='wpWatchthis' id='mw-editpage-watch'" .
2615 Xml
::expandAttributes( array( 'title' => Linker
::titleAttrib( 'watch', 'withaccess' ) ) ) .
2616 ">{$watchLabel}</label>";
2618 wfRunHooks( 'EditPageBeforeEditChecks', array( &$this, &$checkboxes, &$tabindex ) );
2623 * Returns an array of html code of the following buttons:
2624 * save, diff, preview and live
2626 * @param $tabindex Current tabindex
2630 public function getEditButtons( &$tabindex ) {
2637 'tabindex' => ++
$tabindex,
2638 'value' => wfMsg( 'savearticle' ),
2639 'accesskey' => wfMsg( 'accesskey-save' ),
2640 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
2642 $buttons['save'] = Xml
::element('input', $temp, '');
2644 ++
$tabindex; // use the same for preview and live preview
2646 'id' => 'wpPreview',
2647 'name' => 'wpPreview',
2649 'tabindex' => $tabindex,
2650 'value' => wfMsg( 'showpreview' ),
2651 'accesskey' => wfMsg( 'accesskey-preview' ),
2652 'title' => wfMsg( 'tooltip-preview' ) . ' [' . wfMsg( 'accesskey-preview' ) . ']',
2654 $buttons['preview'] = Xml
::element( 'input', $temp, '' );
2655 $buttons['live'] = '';
2661 'tabindex' => ++
$tabindex,
2662 'value' => wfMsg( 'showdiff' ),
2663 'accesskey' => wfMsg( 'accesskey-diff' ),
2664 'title' => wfMsg( 'tooltip-diff' ) . ' [' . wfMsg( 'accesskey-diff' ) . ']',
2666 $buttons['diff'] = Xml
::element( 'input', $temp, '' );
2668 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
2673 * Output preview text only. This can be sucked into the edit page
2674 * via JavaScript, and saves the server time rendering the skin as
2675 * well as theoretically being more robust on the client (doesn't
2676 * disturb the edit box's undo history, won't eat your text on
2679 * @todo This doesn't include category or interlanguage links.
2680 * Would need to enhance it a bit, <s>maybe wrap them in XML
2681 * or something...</s> that might also require more skin
2682 * initialization, so check whether that's a problem.
2684 function livePreview() {
2687 header( 'Content-type: text/xml; charset=utf-8' );
2688 header( 'Cache-control: no-cache' );
2690 $previewText = $this->getPreviewText();
2691 #$categories = $skin->getCategoryLinks();
2694 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2695 Xml
::tags( 'livepreview', null,
2696 Xml
::element( 'preview', null, $previewText )
2697 #. Xml::element( 'category', null, $categories )
2705 public function getCancelLink() {
2706 $cancelParams = array();
2707 if ( !$this->isConflict
&& $this->mArticle
->getOldID() > 0 ) {
2708 $cancelParams['oldid'] = $this->mArticle
->getOldID();
2711 return Linker
::linkKnown(
2712 $this->getContextTitle(),
2713 wfMsgExt( 'cancel', array( 'parseinline' ) ),
2714 array( 'id' => 'mw-editform-cancel' ),
2720 * Get a diff between the current contents of the edit box and the
2721 * version of the page we're editing from.
2723 * If this is a section edit, we'll replace the section as for final
2724 * save and then make a comparison.
2726 function showDiff() {
2727 $oldtext = $this->mArticle
->fetchContent();
2728 $newtext = $this->mArticle
->replaceSection(
2729 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
2731 wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
2733 $newtext = $this->mArticle
->preSaveTransform( $newtext );
2734 $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
2735 $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
2736 if ( $oldtext !== false ||
$newtext != '' ) {
2737 $de = new DifferenceEngine( $this->mTitle
);
2738 $de->setText( $oldtext, $newtext );
2739 $difftext = $de->getDiff( $oldtitle, $newtitle );
2740 $de->showDiffStyle();
2746 $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
2750 * Filter an input field through a Unicode de-armoring process if it
2751 * came from an old browser with known broken Unicode editing issues.
2753 * @param $request WebRequest
2754 * @param $field String
2758 function safeUnicodeInput( $request, $field ) {
2759 $text = rtrim( $request->getText( $field ) );
2760 return $request->getBool( 'safemode' )
2761 ?
$this->unmakesafe( $text )
2766 * @param $request WebRequest
2767 * @param $text string
2770 function safeUnicodeText( $request, $text ) {
2771 $text = rtrim( $text );
2772 return $request->getBool( 'safemode' )
2773 ?
$this->unmakesafe( $text )
2778 * Filter an output field through a Unicode armoring process if it is
2779 * going to an old browser with known broken Unicode editing issues.
2781 * @param $text String
2785 function safeUnicodeOutput( $text ) {
2787 $codedText = $wgContLang->recodeForEdit( $text );
2788 return $this->checkUnicodeCompliantBrowser()
2790 : $this->makesafe( $codedText );
2794 * A number of web browsers are known to corrupt non-ASCII characters
2795 * in a UTF-8 text editing environment. To protect against this,
2796 * detected browsers will be served an armored version of the text,
2797 * with non-ASCII chars converted to numeric HTML character references.
2799 * Preexisting such character references will have a 0 added to them
2800 * to ensure that round-trips do not alter the original data.
2802 * @param $invalue String
2806 function makesafe( $invalue ) {
2807 // Armor existing references for reversability.
2808 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
2813 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2814 $bytevalue = ord( $invalue[$i] );
2815 if ( $bytevalue <= 0x7F ) { //0xxx xxxx
2816 $result .= chr( $bytevalue );
2818 } elseif ( $bytevalue <= 0xBF ) { //10xx xxxx
2819 $working = $working << 6;
2820 $working +
= ($bytevalue & 0x3F);
2822 if ( $bytesleft <= 0 ) {
2823 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2825 } elseif ( $bytevalue <= 0xDF ) { //110x xxxx
2826 $working = $bytevalue & 0x1F;
2828 } elseif ( $bytevalue <= 0xEF ) { //1110 xxxx
2829 $working = $bytevalue & 0x0F;
2831 } else { //1111 0xxx
2832 $working = $bytevalue & 0x07;
2840 * Reverse the previously applied transliteration of non-ASCII characters
2841 * back to UTF-8. Used to protect data from corruption by broken web browsers
2842 * as listed in $wgBrowserBlackList.
2844 * @param $invalue String
2848 function unmakesafe( $invalue ) {
2850 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2851 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue[$i+
3] != '0' ) ) {
2855 $hexstring .= $invalue[$i];
2857 } while( ctype_xdigit( $invalue[$i] ) && ( $i < strlen( $invalue ) ) );
2859 // Do some sanity checks. These aren't needed for reversability,
2860 // but should help keep the breakage down if the editor
2861 // breaks one of the entities whilst editing.
2862 if ( (substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6) ) {
2863 $codepoint = hexdec($hexstring);
2864 $result .= codepointToUtf8( $codepoint );
2866 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2869 $result .= substr( $invalue, $i, 1 );
2872 // reverse the transform that we made for reversability reasons.
2873 return strtr( $result, array( "�" => "&#x" ) );
2876 function noCreatePermission() {
2878 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
2879 $wgOut->addWikiMsg( 'nocreatetext' );
2883 * Attempt submission
2884 * @return bool false if output is done, true if the rest of the form should be displayed
2886 function attemptSave() {
2887 global $wgUser, $wgOut;
2889 $resultDetails = false;
2890 # Allow bots to exempt some edits from bot flagging
2891 $bot = $wgUser->isAllowed( 'bot' ) && $this->bot
;
2892 $status = $this->internalAttemptSave( $resultDetails, $bot );
2893 // FIXME: once the interface for internalAttemptSave() is made nicer, this should use the message in $status
2895 if ( $status->value
== self
::AS_SUCCESS_UPDATE ||
$status->value
== self
::AS_SUCCESS_NEW_ARTICLE
) {
2896 $this->didSave
= true;
2899 switch ( $status->value
) {
2900 case self
::AS_HOOK_ERROR_EXPECTED
:
2901 case self
::AS_CONTENT_TOO_BIG
:
2902 case self
::AS_ARTICLE_WAS_DELETED
:
2903 case self
::AS_CONFLICT_DETECTED
:
2904 case self
::AS_SUMMARY_NEEDED
:
2905 case self
::AS_TEXTBOX_EMPTY
:
2906 case self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
:
2910 case self
::AS_HOOK_ERROR
:
2911 case self
::AS_FILTERING
:
2914 case self
::AS_SUCCESS_NEW_ARTICLE
:
2915 $query = $resultDetails['redirect'] ?
'redirect=no' : '';
2916 $wgOut->redirect( $this->mTitle
->getFullURL( $query ) );
2919 case self
::AS_SUCCESS_UPDATE
:
2921 $sectionanchor = $resultDetails['sectionanchor'];
2923 // Give extensions a chance to modify URL query on update
2924 wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this->mArticle
, &$sectionanchor, &$extraQuery ) );
2926 if ( $resultDetails['redirect'] ) {
2927 if ( $extraQuery == '' ) {
2928 $extraQuery = 'redirect=no';
2930 $extraQuery = 'redirect=no&' . $extraQuery;
2933 $wgOut->redirect( $this->mTitle
->getFullURL( $extraQuery ) . $sectionanchor );
2936 case self
::AS_SPAM_ERROR
:
2937 $this->spamPageWithContent( $resultDetails['spam'] );
2940 case self
::AS_BLOCKED_PAGE_FOR_USER
:
2941 $this->blockedPage();
2944 case self
::AS_IMAGE_REDIRECT_ANON
:
2945 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2948 case self
::AS_READ_ONLY_PAGE_ANON
:
2949 $this->userNotLoggedInPage();
2952 case self
::AS_READ_ONLY_PAGE_LOGGED
:
2953 case self
::AS_READ_ONLY_PAGE
:
2954 $wgOut->readOnlyPage();
2957 case self
::AS_RATE_LIMITED
:
2958 $wgOut->rateLimited();
2961 case self
::AS_NO_CREATE_PERMISSION
:
2962 $this->noCreatePermission();
2965 case self
::AS_BLANK_ARTICLE
:
2966 $wgOut->redirect( $this->getContextTitle()->getFullURL() );
2969 case self
::AS_IMAGE_REDIRECT_LOGGED
:
2970 $wgOut->permissionRequired( 'upload' );
2978 function getBaseRevision() {
2979 if ( !$this->mBaseRevision
) {
2980 $db = wfGetDB( DB_MASTER
);
2981 $baseRevision = Revision
::loadFromTimestamp(
2982 $db, $this->mTitle
, $this->edittime
);
2983 return $this->mBaseRevision
= $baseRevision;
2985 return $this->mBaseRevision
;