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.
20 const AS_SUCCESS_UPDATE
= 200;
21 const AS_SUCCESS_NEW_ARTICLE
= 201;
22 const AS_HOOK_ERROR
= 210;
23 const AS_FILTERING
= 211;
24 const AS_HOOK_ERROR_EXPECTED
= 212;
25 const AS_BLOCKED_PAGE_FOR_USER
= 215;
26 const AS_CONTENT_TOO_BIG
= 216;
27 const AS_USER_CANNOT_EDIT
= 217;
28 const AS_READ_ONLY_PAGE_ANON
= 218;
29 const AS_READ_ONLY_PAGE_LOGGED
= 219;
30 const AS_READ_ONLY_PAGE
= 220;
31 const AS_RATE_LIMITED
= 221;
32 const AS_ARTICLE_WAS_DELETED
= 222;
33 const AS_NO_CREATE_PERMISSION
= 223;
34 const AS_BLANK_ARTICLE
= 224;
35 const AS_CONFLICT_DETECTED
= 225;
36 const AS_SUMMARY_NEEDED
= 226;
37 const AS_TEXTBOX_EMPTY
= 228;
38 const AS_MAX_ARTICLE_SIZE_EXCEEDED
= 229;
41 const AS_SPAM_ERROR
= 232;
42 const AS_IMAGE_REDIRECT_ANON
= 233;
43 const AS_IMAGE_REDIRECT_LOGGED
= 234;
54 private $mContextTitle = null;
56 var $isConflict = false;
57 var $isCssJsSubpage = false;
58 var $isCssSubpage = false;
59 var $isJsSubpage = false;
60 var $isWrongCaseCssJsPage = false;
61 var $isNew = false; // new page or new section
62 var $deletedSinceEdit;
66 var $mTokenOk = false;
67 var $mTokenOkExceptSuffix = false;
68 var $mTriedSave = false;
69 var $incompleteForm = false;
71 var $kblength = false;
72 var $missingComment = false;
73 var $missingSummary = false;
74 var $allowBlankSummary = false;
77 #var $mPreviewTemplates;
84 var $mBaseRevision = false;
85 var $mShowSummaryField = true;
88 var $save = false, $preview = false, $diff = false;
89 var $minoredit = false, $watchthis = false, $recreate = false;
90 var $textbox1 = '', $textbox2 = '', $summary = '', $nosummary = false;
91 var $edittime = '', $section = '', $starttime = '';
92 var $oldid = 0, $editintro = '', $scrolltop = null, $bot = true;
94 # Placeholders for text injection by hooks (must be HTML)
95 # extensions should take care to _append_ to the present value
96 public $editFormPageTop; // Before even the preview
97 public $editFormTextTop;
98 public $editFormTextBeforeContent;
99 public $editFormTextAfterWarn;
100 public $editFormTextAfterTools;
101 public $editFormTextBottom;
102 public $editFormTextAfterContent;
103 public $previewTextAfterContent;
104 public $mPreloadText;
106 /* $didSave should be set to true whenever an article was succesfully altered. */
107 public $didSave = false;
108 public $undidRev = 0;
110 public $suppressIntro = false;
114 * @param $article Article
116 function __construct( $article ) {
117 $this->mArticle
=& $article;
118 $this->mTitle
= $article->getTitle();
119 $this->action
= 'submit';
121 # Placeholders for text injection by hooks (empty per default)
122 $this->editFormPageTop
=
123 $this->editFormTextTop
=
124 $this->editFormTextBeforeContent
=
125 $this->editFormTextAfterWarn
=
126 $this->editFormTextAfterTools
=
127 $this->editFormTextBottom
=
128 $this->editFormTextAfterContent
=
129 $this->previewTextAfterContent
=
130 $this->mPreloadText
= "";
136 function getArticle() {
137 return $this->mArticle
;
141 * Set the context Title object
143 * @param $title Title object or null
145 public function setContextTitle( $title ) {
146 $this->mContextTitle
= $title;
150 * Get the context title object.
151 * If not set, $wgTitle will be returned. This behavior might changed in
152 * the future to return $this->mTitle instead.
154 * @return Title object
156 public function getContextTitle() {
157 if ( is_null( $this->mContextTitle
) ) {
161 return $this->mContextTitle
;
166 * Fetch initial editing page content.
168 * @param $def_text string
169 * @returns mixed string on success, $def_text for invalid sections
172 function getContent( $def_text = '' ) {
173 global $wgOut, $wgRequest, $wgParser;
175 wfProfileIn( __METHOD__
);
176 # Get variables from query string :P
177 $section = $wgRequest->getVal( 'section' );
179 $preload = $wgRequest->getVal( 'preload',
180 // Custom preload text for new sections
181 $section === 'new' ?
'MediaWiki:addsection-preload' : '' );
182 $undoafter = $wgRequest->getVal( 'undoafter' );
183 $undo = $wgRequest->getVal( 'undo' );
185 // For message page not locally set, use the i18n message.
186 // For other non-existent articles, use preload text if any.
187 if ( !$this->mTitle
->exists() ) {
188 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
189 # If this is a system message, get the default text.
190 $text = $this->mTitle
->getDefaultMessageText();
191 if( $text === false ) {
192 $text = $this->getPreloadedText( $preload );
195 # If requested, preload some text.
196 $text = $this->getPreloadedText( $preload );
198 // For existing pages, get text based on "undo" or section parameters.
200 $text = $this->mArticle
->getContent();
201 if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
202 # If they got undoafter and undo round the wrong way, switch them
203 list( $undo, $undoafter ) = array( $undoafter, $undo );
205 if ( $undo > 0 && $undo > $undoafter ) {
206 # Undoing a specific edit overrides section editing; section-editing
207 # doesn't work with undoing.
209 $undorev = Revision
::newFromId( $undo );
210 $oldrev = Revision
::newFromId( $undoafter );
212 $undorev = Revision
::newFromId( $undo );
213 $oldrev = $undorev ?
$undorev->getPrevious() : null;
216 # Sanity check, make sure it's the right page,
217 # the revisions exist and they were not deleted.
218 # Otherwise, $text will be left as-is.
219 if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
220 $undorev->getPage() == $oldrev->getPage() &&
221 $undorev->getPage() == $this->mArticle
->getID() &&
222 !$undorev->isDeleted( Revision
::DELETED_TEXT
) &&
223 !$oldrev->isDeleted( Revision
::DELETED_TEXT
) ) {
225 $undotext = $this->mArticle
->getUndoText( $undorev, $oldrev );
226 if ( $undotext === false ) {
227 # Warn the user that something went wrong
228 $this->editFormPageTop
.= $wgOut->parse( '<div class="error mw-undo-failure">' . wfMsgNoTrans( 'undo-failure' ) . '</div>' );
231 # Inform the user of our success and set an automatic edit summary
232 $this->editFormPageTop
.= $wgOut->parse( '<div class="mw-undo-success">' . wfMsgNoTrans( 'undo-success' ) . '</div>' );
233 $firstrev = $oldrev->getNext();
234 # If we just undid one rev, use an autosummary
235 if ( $firstrev->mId
== $undo ) {
236 $this->summary
= wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
237 $this->undidRev
= $undo;
239 $this->formtype
= 'diff';
242 // Failed basic sanity checks.
243 // Older revisions may have been removed since the link
244 // was created, or we may simply have got bogus input.
245 $this->editFormPageTop
.= $wgOut->parse( '<div class="error mw-undo-norev">' . wfMsgNoTrans( 'undo-norev' ) . '</div>' );
247 } elseif ( $section != '' ) {
248 if ( $section == 'new' ) {
249 $text = $this->getPreloadedText( $preload );
251 // Get section edit text (returns $def_text for invalid sections)
252 $text = $wgParser->getSection( $text, $section, $def_text );
257 wfProfileOut( __METHOD__
);
262 * Use this method before edit() to preload some text into the edit box
264 * @param $text string
266 public function setPreloadedText( $text ) {
267 $this->mPreloadText
= $text;
271 * Get the contents to be preloaded into the box, either set by
272 * an earlier setPreloadText() or by loading the given page.
274 * @param $preload String: representing the title to preload from.
277 protected function getPreloadedText( $preload ) {
278 global $wgUser, $wgParser;
279 if ( !empty( $this->mPreloadText
) ) {
280 return $this->mPreloadText
;
281 } elseif ( $preload !== '' ) {
282 $title = Title
::newFromText( $preload );
283 # Check for existence to avoid getting MediaWiki:Noarticletext
284 if ( isset( $title ) && $title->exists() && $title->userCanRead() ) {
285 $article = new Article( $title );
287 if ( $article->isRedirect() ) {
288 $title = Title
::newFromRedirectRecurse( $article->getContent() );
289 # Redirects to missing titles are displayed, to hidden pages are followed
290 # Copying observed behaviour from ?action=view
291 if ( $title->exists() ) {
292 if ($title->userCanRead() ) {
293 $article = new Article( $title );
299 $parserOptions = ParserOptions
::newFromUser( $wgUser );
300 return $wgParser->getPreloadText( $article->getContent(), $title, $parserOptions );
307 * Check if a page was deleted while the user was editing it, before submit.
308 * Note that we rely on the logging table, which hasn't been always there,
309 * but that doesn't matter, because this only applies to brand new
312 protected function wasDeletedSinceLastEdit() {
313 if ( $this->deletedSinceEdit
!== null ) {
314 return $this->deletedSinceEdit
;
317 $this->deletedSinceEdit
= false;
319 if ( $this->mTitle
->isDeletedQuick() ) {
320 $this->lastDelete
= $this->getLastDelete();
321 if ( $this->lastDelete
) {
322 $deleteTime = wfTimestamp( TS_MW
, $this->lastDelete
->log_timestamp
);
323 if ( $deleteTime > $this->starttime
) {
324 $this->deletedSinceEdit
= true;
329 return $this->deletedSinceEdit
;
333 * Checks whether the user entered a skin name in uppercase,
334 * e.g. "User:Example/Monobook.css" instead of "monobook.css"
338 protected function isWrongCaseCssJsPage() {
339 if( $this->mTitle
->isCssJsSubpage() ) {
340 $name = $this->mTitle
->getSkinFromCssJsSubpage();
341 $skins = array_merge(
342 array_keys( Skin
::getSkinNames() ),
345 return !in_array( $name, $skins )
346 && in_array( strtolower( $name ), $skins );
357 * This is the function that gets called for "action=edit". It
358 * sets up various member variables, then passes execution to
359 * another function, usually showEditForm()
361 * The edit form is self-submitting, so that when things like
362 * preview and edit conflicts occur, we get the same form back
363 * with the extra stuff added. Only when the final submission
364 * is made and all is well do we actually save and redirect to
365 * the newly-edited page.
368 global $wgOut, $wgRequest, $wgUser;
369 // Allow extensions to modify/prevent this form or submission
370 if ( !wfRunHooks( 'AlternateEdit', array( $this ) ) ) {
374 wfProfileIn( __METHOD__
);
375 wfDebug( __METHOD__
.": enter\n" );
377 $this->importFormData( $wgRequest );
378 $this->firsttime
= false;
381 $this->livePreview();
382 wfProfileOut( __METHOD__
);
386 if ( wfReadOnly() && $this->save
) {
389 $this->preview
= true;
392 $wgOut->addModules( array( 'mediawiki.action.edit' ) );
394 if ( $wgUser->getOption( 'uselivepreview', false ) ) {
395 $wgOut->addModules( 'mediawiki.legacy.preview' );
397 // Bug #19334: textarea jumps when editing articles in IE8
398 $wgOut->addStyle( 'common/IE80Fixes.css', 'screen', 'IE 8' );
400 $permErrors = $this->getEditPermissionErrors();
402 wfDebug( __METHOD__
. ": User can't edit\n" );
403 $content = $this->getContent( null );
404 $content = $content === '' ?
null : $content;
405 $this->readOnlyPage( $content, true, $permErrors, 'edit' );
406 wfProfileOut( __METHOD__
);
410 $this->formtype
= 'save';
411 } elseif ( $this->preview
) {
412 $this->formtype
= 'preview';
413 } elseif ( $this->diff
) {
414 $this->formtype
= 'diff';
415 } else { # First time through
416 $this->firsttime
= true;
417 if ( $this->previewOnOpen() ) {
418 $this->formtype
= 'preview';
420 $this->formtype
= 'initial';
425 // If they used redlink=1 and the page exists, redirect to the main article
426 if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle
->exists() ) {
427 $wgOut->redirect( $this->mTitle
->getFullURL() );
430 wfProfileIn( __METHOD__
."-business-end" );
432 $this->isConflict
= false;
433 // css / js subpages of user pages get a special treatment
434 $this->isCssJsSubpage
= $this->mTitle
->isCssJsSubpage();
435 $this->isCssSubpage
= $this->mTitle
->isCssSubpage();
436 $this->isJsSubpage
= $this->mTitle
->isJsSubpage();
437 $this->isWrongCaseCssJsPage
= $this->isWrongCaseCssJsPage();
438 $this->isNew
= !$this->mTitle
->exists() ||
$this->section
== 'new';
440 # Show applicable editing introductions
441 if ( $this->formtype
== 'initial' ||
$this->firsttime
)
444 if ( $this->mTitle
->isTalkPage() ) {
445 $wgOut->addWikiMsg( 'talkpagetext' );
448 # Optional notices on a per-namespace and per-page basis
449 $editnotice_ns = 'editnotice-'.$this->mTitle
->getNamespace();
450 $editnotice_ns_message = wfMessage( $editnotice_ns )->inContentLanguage();
451 if ( $editnotice_ns_message->exists() ) {
452 $wgOut->addWikiText( $editnotice_ns_message->plain() );
454 if ( MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
455 $parts = explode( '/', $this->mTitle
->getDBkey() );
456 $editnotice_base = $editnotice_ns;
457 while ( count( $parts ) > 0 ) {
458 $editnotice_base .= '-'.array_shift( $parts );
459 $editnotice_base_msg = wfMessage( $editnotice_base )->inContentLanguage();
460 if ( $editnotice_base_msg->exists() ) {
461 $wgOut->addWikiText( $editnotice_base_msg->plain() );
466 # Attempt submission here. This will check for edit conflicts,
467 # and redundantly check for locked database, blocked IPs, etc.
468 # that edit() already checked just in case someone tries to sneak
469 # in the back door with a hand-edited submission URL.
471 if ( 'save' == $this->formtype
) {
472 if ( !$this->attemptSave() ) {
473 wfProfileOut( __METHOD__
."-business-end" );
474 wfProfileOut( __METHOD__
);
479 # First time through: get contents, set time for conflict
481 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
482 if ( $this->initialiseForm() === false ) {
483 $this->noSuchSectionPage();
484 wfProfileOut( __METHOD__
."-business-end" );
485 wfProfileOut( __METHOD__
);
488 if ( !$this->mTitle
->getArticleId() )
489 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1
, &$this->mTitle
) );
491 wfRunHooks( 'EditFormInitialText', array( $this ) );
494 $this->showEditForm();
495 wfProfileOut( __METHOD__
."-business-end" );
496 wfProfileOut( __METHOD__
);
502 protected function getEditPermissionErrors() {
504 $permErrors = $this->mTitle
->getUserPermissionsErrors( 'edit', $wgUser );
505 # Can this title be created?
506 if ( !$this->mTitle
->exists() ) {
507 $permErrors = array_merge( $permErrors,
508 wfArrayDiff2( $this->mTitle
->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) );
510 # Ignore some permissions errors when a user is just previewing/viewing diffs
512 foreach( $permErrors as $error ) {
513 if ( ( $this->preview ||
$this->diff
) &&
514 ( $error[0] == 'blockedtext' ||
$error[0] == 'autoblockedtext' ) )
519 $permErrors = wfArrayDiff2( $permErrors, $remove );
524 * Show a read-only error
525 * Parameters are the same as OutputPage:readOnlyPage()
526 * Redirect to the article page if redlink=1
528 function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
529 global $wgRequest, $wgOut;
530 if ( $wgRequest->getBool( 'redlink' ) ) {
531 // The edit page was reached via a red link.
532 // Redirect to the article page and let them click the edit tab if
533 // they really want a permission error.
534 $wgOut->redirect( $this->mTitle
->getFullUrl() );
536 $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
541 * Should we show a preview when the edit form is first shown?
545 protected function previewOnOpen() {
546 global $wgRequest, $wgUser, $wgPreviewOnOpenNamespaces;
547 if ( $wgRequest->getVal( 'preview' ) == 'yes' ) {
548 // Explicit override from request
550 } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) {
551 // Explicit override from request
553 } elseif ( $this->section
== 'new' ) {
554 // Nothing *to* preview for new sections
556 } elseif ( ( $wgRequest->getVal( 'preload' ) !== null ||
$this->mTitle
->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
557 // Standard preference behaviour
559 } elseif ( !$this->mTitle
->exists() &&
560 isset($wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()]) &&
561 $wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()] )
563 // Categories are special
571 * Does this EditPage class support section editing?
572 * This is used by EditPage subclasses to indicate their ui cannot handle section edits
576 protected function isSectionEditSupported() {
581 * Returns the URL to use in the form's action attribute.
582 * This is used by EditPage subclasses when simply customizing the action
583 * variable in the constructor is not enough. This can be used when the
584 * EditPage lives inside of a Special page rather than a custom page action.
586 * @param $title Title object for which is being edited (where we go to for &action= links)
589 protected function getActionURL( Title
$title ) {
590 return $title->getLocalURL( array( 'action' => $this->action
) );
595 * @param $request WebRequest
597 function importFormData( &$request ) {
598 global $wgLang, $wgUser;
600 wfProfileIn( __METHOD__
);
602 # Section edit can come from either the form or a link
603 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
605 if ( $request->wasPosted() ) {
606 # These fields need to be checked for encoding.
607 # Also remove trailing whitespace, but don't remove _initial_
608 # whitespace from the text boxes. This may be significant formatting.
609 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
610 if ( !$request->getCheck('wpTextbox2') ) {
611 // Skip this if wpTextbox2 has input, it indicates that we came
612 // from a conflict page with raw page text, not a custom form
613 // modified by subclasses
614 wfProfileIn( get_class($this)."::importContentFormData" );
615 $textbox1 = $this->importContentFormData( $request );
616 if ( isset($textbox1) )
617 $this->textbox1
= $textbox1;
618 wfProfileOut( get_class($this)."::importContentFormData" );
621 # Truncate for whole multibyte characters. +5 bytes for ellipsis
622 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
624 # Remove extra headings from summaries and new sections.
625 $this->summary
= preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary
);
627 $this->edittime
= $request->getVal( 'wpEdittime' );
628 $this->starttime
= $request->getVal( 'wpStarttime' );
630 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
632 if ($this->textbox1
=== '' && $request->getVal( 'wpTextbox1' ) === null) {
633 // wpTextbox1 field is missing, possibly due to being "too big"
634 // according to some filter rules such as Suhosin's setting for
635 // suhosin.request.max_value_length (d'oh)
636 $this->incompleteForm
= true;
638 // edittime should be one of our last fields; if it's missing,
639 // the submission probably broke somewhere in the middle.
640 $this->incompleteForm
= is_null( $this->edittime
);
642 if ( $this->incompleteForm
) {
643 # If the form is incomplete, force to preview.
644 wfDebug( __METHOD__
. ": Form data appears to be incomplete\n" );
645 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
646 $this->preview
= true;
648 /* Fallback for live preview */
649 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
650 $this->diff
= $request->getCheck( 'wpDiff' );
652 // Remember whether a save was requested, so we can indicate
653 // if we forced preview due to session failure.
654 $this->mTriedSave
= !$this->preview
;
656 if ( $this->tokenOk( $request ) ) {
657 # Some browsers will not report any submit button
658 # if the user hits enter in the comment box.
659 # The unmarked state will be assumed to be a save,
660 # if the form seems otherwise complete.
661 wfDebug( __METHOD__
. ": Passed token check.\n" );
662 } elseif ( $this->diff
) {
663 # Failed token check, but only requested "Show Changes".
664 wfDebug( __METHOD__
. ": Failed token check; Show Changes requested.\n" );
666 # Page might be a hack attempt posted from
667 # an external site. Preview instead of saving.
668 wfDebug( __METHOD__
. ": Failed token check; forcing preview\n" );
669 $this->preview
= true;
672 $this->save
= !$this->preview
&& !$this->diff
;
673 if ( !preg_match( '/^\d{14}$/', $this->edittime
) ) {
674 $this->edittime
= null;
677 if ( !preg_match( '/^\d{14}$/', $this->starttime
) ) {
678 $this->starttime
= null;
681 $this->recreate
= $request->getCheck( 'wpRecreate' );
683 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
684 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
686 # Don't force edit summaries when a user is editing their own user or talk page
687 if ( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) &&
688 $this->mTitle
->getText() == $wgUser->getName() )
690 $this->allowBlankSummary
= true;
692 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' ) ||
!$wgUser->getOption( 'forceeditsummary');
695 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
697 # Not a posted form? Start with nothing.
698 wfDebug( __METHOD__
. ": Not a posted form.\n" );
699 $this->textbox1
= '';
701 $this->edittime
= '';
702 $this->starttime
= wfTimestampNow();
704 $this->preview
= false;
707 $this->minoredit
= false;
708 $this->watchthis
= $request->getBool( 'watchthis', false ); // Watch may be overriden by request parameters
709 $this->recreate
= false;
711 if ( $this->section
== 'new' && $request->getVal( 'preloadtitle' ) ) {
712 $this->summary
= $request->getVal( 'preloadtitle' );
714 elseif ( $this->section
!= 'new' && $request->getVal( 'summary' ) ) {
715 $this->summary
= $request->getText( 'summary' );
718 if ( $request->getVal( 'minor' ) ) {
719 $this->minoredit
= true;
723 $this->bot
= $request->getBool( 'bot', true );
724 $this->nosummary
= $request->getBool( 'nosummary' );
726 // @todo FIXME: Unused variable?
727 $this->oldid
= $request->getInt( 'oldid' );
729 $this->live
= $request->getCheck( 'live' );
730 $this->editintro
= $request->getText( 'editintro',
731 // Custom edit intro for new sections
732 $this->section
=== 'new' ?
'MediaWiki:addsection-editintro' : '' );
734 // Allow extensions to modify form data
735 wfRunHooks( 'EditPage::importFormData', array( $this, $request ) );
737 wfProfileOut( __METHOD__
);
741 * Subpage overridable method for extracting the page content data from the
742 * posted form to be placed in $this->textbox1, if using customized input
743 * this method should be overrided and return the page text that will be used
744 * for saving, preview parsing and so on...
746 * @param $request WebRequest
748 protected function importContentFormData( &$request ) {
749 return; // Don't do anything, EditPage already extracted wpTextbox1
753 * Make sure the form isn't faking a user's credentials.
755 * @param $request WebRequest
759 function tokenOk( &$request ) {
761 $token = $request->getVal( 'wpEditToken' );
762 $this->mTokenOk
= $wgUser->matchEditToken( $token );
763 $this->mTokenOkExceptSuffix
= $wgUser->matchEditTokenNoSuffix( $token );
764 return $this->mTokenOk
;
768 * Show all applicable editing introductions
770 protected function showIntro() {
771 global $wgOut, $wgUser;
772 if ( $this->suppressIntro
) {
776 $namespace = $this->mTitle
->getNamespace();
778 if ( $namespace == NS_MEDIAWIKI
) {
779 # Show a warning if editing an interface message
780 $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1\n</div>", 'editinginterface' );
783 # Show a warning message when someone creates/edits a user (talk) page but the user does not exist
784 # Show log extract when the user is currently blocked
785 if ( $namespace == NS_USER ||
$namespace == NS_USER_TALK
) {
786 $parts = explode( '/', $this->mTitle
->getText(), 2 );
787 $username = $parts[0];
788 $user = User
::newFromName( $username, false /* allow IP users*/ );
789 $ip = User
::isIP( $username );
790 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
791 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
792 array( 'userpage-userdoesnotexist', wfEscapeWikiText( $username ) ) );
793 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
794 LogEventsList
::showLogExtract(
797 $user->getUserPage()->getPrefixedText(),
801 'showIfEmpty' => false,
803 'blocked-notice-logextract',
804 $user->getName() # Support GENDER in notice
810 # Try to add a custom edit intro, or use the standard one if this is not possible.
811 if ( !$this->showCustomIntro() && !$this->mTitle
->exists() ) {
812 if ( $wgUser->isLoggedIn() ) {
813 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletext\">\n$1\n</div>", 'newarticletext' );
815 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletextanon\">\n$1\n</div>", 'newarticletextanon' );
818 # Give a notice if the user is editing a deleted/moved page...
819 if ( !$this->mTitle
->exists() ) {
820 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle
->getPrefixedText(),
821 '', array( 'lim' => 10,
822 'conds' => array( "log_action != 'revision'" ),
823 'showIfEmpty' => false,
824 'msgKey' => array( 'recreate-moveddeleted-warn') )
830 * Attempt to show a custom editing introduction, if supplied
834 protected function showCustomIntro() {
835 if ( $this->editintro
) {
836 $title = Title
::newFromText( $this->editintro
);
837 if ( $title instanceof Title
&& $title->exists() && $title->userCanRead() ) {
839 // Added using template syntax, to take <noinclude>'s into account.
840 $wgOut->addWikiTextTitleTidy( '{{:' . $title->getFullText() . '}}', $this->mTitle
);
851 * Attempt submission (no UI)
856 * @return int one of the constants describing the result
858 function internalAttemptSave( &$result, $bot = false ) {
859 global $wgFilterCallback, $wgUser, $wgParser;
860 global $wgMaxArticleSize;
862 wfProfileIn( __METHOD__
);
863 wfProfileIn( __METHOD__
. '-checks' );
865 if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) ) {
866 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
867 wfProfileOut( __METHOD__
. '-checks' );
868 wfProfileOut( __METHOD__
);
869 return self
::AS_HOOK_ERROR
;
872 # Check image redirect
873 if ( $this->mTitle
->getNamespace() == NS_FILE
&&
874 Title
::newFromRedirect( $this->textbox1
) instanceof Title
&&
875 !$wgUser->isAllowed( 'upload' ) ) {
876 $isAnon = $wgUser->isAnon();
878 wfProfileOut( __METHOD__
. '-checks' );
879 wfProfileOut( __METHOD__
);
881 return $isAnon ? self
::AS_IMAGE_REDIRECT_ANON
: self
::AS_IMAGE_REDIRECT_LOGGED
;
885 $match = self
::matchSummarySpamRegex( $this->summary
);
886 if ( $match === false ) {
887 $match = self
::matchSpamRegex( $this->textbox1
);
889 if ( $match !== false ) {
890 $result['spam'] = $match;
892 $pdbk = $this->mTitle
->getPrefixedDBkey();
893 $match = str_replace( "\n", '', $match );
894 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
895 wfProfileOut( __METHOD__
. '-checks' );
896 wfProfileOut( __METHOD__
);
897 return self
::AS_SPAM_ERROR
;
899 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
, $this->hookError
, $this->summary
) ) {
900 # Error messages or other handling should be performed by the filter function
901 wfProfileOut( __METHOD__
. '-checks' );
902 wfProfileOut( __METHOD__
);
903 return self
::AS_FILTERING
;
905 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1
, $this->section
, &$this->hookError
, $this->summary
) ) ) {
906 # Error messages etc. could be handled within the hook...
907 wfProfileOut( __METHOD__
. '-checks' );
908 wfProfileOut( __METHOD__
);
909 return self
::AS_HOOK_ERROR
;
910 } elseif ( $this->hookError
!= '' ) {
911 # ...or the hook could be expecting us to produce an error
912 wfProfileOut( __METHOD__
. '-checks' );
913 wfProfileOut( __METHOD__
);
914 return self
::AS_HOOK_ERROR_EXPECTED
;
916 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
917 # Check block state against master, thus 'false'.
918 wfProfileOut( __METHOD__
. '-checks' );
919 wfProfileOut( __METHOD__
);
920 return self
::AS_BLOCKED_PAGE_FOR_USER
;
922 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
923 if ( $this->kblength
> $wgMaxArticleSize ) {
924 // Error will be displayed by showEditForm()
925 $this->tooBig
= true;
926 wfProfileOut( __METHOD__
. '-checks' );
927 wfProfileOut( __METHOD__
);
928 return self
::AS_CONTENT_TOO_BIG
;
931 if ( !$wgUser->isAllowed( 'edit' ) ) {
932 if ( $wgUser->isAnon() ) {
933 wfProfileOut( __METHOD__
. '-checks' );
934 wfProfileOut( __METHOD__
);
935 return self
::AS_READ_ONLY_PAGE_ANON
;
937 wfProfileOut( __METHOD__
. '-checks' );
938 wfProfileOut( __METHOD__
);
939 return self
::AS_READ_ONLY_PAGE_LOGGED
;
943 if ( wfReadOnly() ) {
944 wfProfileOut( __METHOD__
. '-checks' );
945 wfProfileOut( __METHOD__
);
946 return self
::AS_READ_ONLY_PAGE
;
948 if ( $wgUser->pingLimiter() ) {
949 wfProfileOut( __METHOD__
. '-checks' );
950 wfProfileOut( __METHOD__
);
951 return self
::AS_RATE_LIMITED
;
954 # If the article has been deleted while editing, don't save it without
956 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate
) {
957 wfProfileOut( __METHOD__
. '-checks' );
958 wfProfileOut( __METHOD__
);
959 return self
::AS_ARTICLE_WAS_DELETED
;
962 wfProfileOut( __METHOD__
. '-checks' );
964 # If article is new, insert it.
965 $aid = $this->mTitle
->getArticleID( Title
::GAID_FOR_UPDATE
);
966 $new = ( $aid == 0 );
969 // Late check for create permission, just in case *PARANOIA*
970 if ( !$this->mTitle
->userCan( 'create' ) ) {
971 wfDebug( __METHOD__
. ": no create permission\n" );
972 wfProfileOut( __METHOD__
);
973 return self
::AS_NO_CREATE_PERMISSION
;
976 # Don't save a new article if it's blank.
977 if ( $this->textbox1
== '' ) {
978 wfProfileOut( __METHOD__
);
979 return self
::AS_BLANK_ARTICLE
;
982 // Run post-section-merge edit filter
983 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1
, &$this->hookError
, $this->summary
) ) ) {
984 # Error messages etc. could be handled within the hook...
985 wfProfileOut( __METHOD__
);
986 return self
::AS_HOOK_ERROR
;
987 } elseif ( $this->hookError
!= '' ) {
988 # ...or the hook could be expecting us to produce an error
989 wfProfileOut( __METHOD__
);
990 return self
::AS_HOOK_ERROR_EXPECTED
;
993 # Handle the user preference to force summaries here. Check if it's not a redirect.
994 if ( !$this->allowBlankSummary
&& !Title
::newFromRedirect( $this->textbox1
) ) {
995 if ( md5( $this->summary
) == $this->autoSumm
) {
996 $this->missingSummary
= true;
997 wfProfileOut( __METHOD__
);
998 return self
::AS_SUMMARY_NEEDED
;
1002 $text = $this->textbox1
;
1003 if ( $this->section
== 'new' && $this->summary
!= '' ) {
1004 $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary
) . "\n\n" . $text;
1007 $retval = self
::AS_SUCCESS_NEW_ARTICLE
;
1011 # Article exists. Check for edit conflict.
1013 $this->mArticle
->clear(); # Force reload of dates, etc.
1015 wfDebug( "timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n" );
1017 if ( $this->mArticle
->getTimestamp() != $this->edittime
) {
1018 $this->isConflict
= true;
1019 if ( $this->section
== 'new' ) {
1020 if ( $this->mArticle
->getUserText() == $wgUser->getName() &&
1021 $this->mArticle
->getComment() == $this->summary
) {
1022 // Probably a duplicate submission of a new comment.
1023 // This can happen when squid resends a request after
1024 // a timeout but the first one actually went through.
1025 wfDebug( __METHOD__
. ": duplicate new section submission; trigger edit conflict!\n" );
1027 // New comment; suppress conflict.
1028 $this->isConflict
= false;
1029 wfDebug( __METHOD__
.": conflict suppressed; new section\n" );
1031 } elseif ( $this->section
== '' && $this->userWasLastToEdit( $wgUser->getId(), $this->edittime
) ) {
1032 # Suppress edit conflict with self, except for section edits where merging is required.
1033 wfDebug( __METHOD__
. ": Suppressing edit conflict, same user.\n" );
1034 $this->isConflict
= false;
1038 if ( $this->isConflict
) {
1039 wfDebug( __METHOD__
. ": conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
1040 $this->mArticle
->getTimestamp() . "')\n" );
1041 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1043 wfDebug( __METHOD__
. ": getting section '$this->section'\n" );
1044 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
1046 if ( is_null( $text ) ) {
1047 wfDebug( __METHOD__
. ": activating conflict; section replace failed.\n" );
1048 $this->isConflict
= true;
1049 $text = $this->textbox1
; // do not try to merge here!
1050 } elseif ( $this->isConflict
) {
1052 if ( $this->mergeChangesInto( $text ) ) {
1053 // Successful merge! Maybe we should tell the user the good news?
1054 $this->isConflict
= false;
1055 wfDebug( __METHOD__
. ": Suppressing edit conflict, successful merge.\n" );
1057 $this->section
= '';
1058 $this->textbox1
= $text;
1059 wfDebug( __METHOD__
. ": Keeping edit conflict, failed merge.\n" );
1063 if ( $this->isConflict
) {
1064 wfProfileOut( __METHOD__
);
1065 return self
::AS_CONFLICT_DETECTED
;
1068 // Run post-section-merge edit filter
1069 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError
, $this->summary
) ) ) {
1070 # Error messages etc. could be handled within the hook...
1071 wfProfileOut( __METHOD__
);
1072 return self
::AS_HOOK_ERROR
;
1073 } elseif ( $this->hookError
!= '' ) {
1074 # ...or the hook could be expecting us to produce an error
1075 wfProfileOut( __METHOD__
);
1076 return self
::AS_HOOK_ERROR_EXPECTED
;
1079 # Handle the user preference to force summaries here, but not for null edits
1080 if ( $this->section
!= 'new' && !$this->allowBlankSummary
1081 && 0 != strcmp( $this->mArticle
->getContent(), $text )
1082 && !Title
::newFromRedirect( $text ) ) # check if it's not a redirect
1084 if ( md5( $this->summary
) == $this->autoSumm
) {
1085 $this->missingSummary
= true;
1086 wfProfileOut( __METHOD__
);
1087 return self
::AS_SUMMARY_NEEDED
;
1091 # And a similar thing for new sections
1092 if ( $this->section
== 'new' && !$this->allowBlankSummary
) {
1093 if ( trim( $this->summary
) == '' ) {
1094 $this->missingSummary
= true;
1095 wfProfileOut( __METHOD__
);
1096 return self
::AS_SUMMARY_NEEDED
;
1101 wfProfileIn( __METHOD__
. '-sectionanchor' );
1102 $sectionanchor = '';
1103 if ( $this->section
== 'new' ) {
1104 if ( $this->textbox1
== '' ) {
1105 $this->missingComment
= true;
1106 wfProfileOut( __METHOD__
. '-sectionanchor' );
1107 wfProfileOut( __METHOD__
);
1108 return self
::AS_TEXTBOX_EMPTY
;
1110 if ( $this->summary
!= '' ) {
1111 $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->summary
);
1112 # This is a new section, so create a link to the new section
1113 # in the revision summary.
1114 $cleanSummary = $wgParser->stripSectionName( $this->summary
);
1115 $this->summary
= wfMsgForContent( 'newsectionsummary', $cleanSummary );
1117 } elseif ( $this->section
!= '' ) {
1118 # Try to get a section anchor from the section source, redirect to edited section if header found
1119 # XXX: might be better to integrate this into Article::replaceSection
1120 # for duplicate heading checking and maybe parsing
1121 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
1122 # we can't deal with anchors, includes, html etc in the header for now,
1123 # headline would need to be parsed to improve this
1124 if ( $hasmatch && strlen( $matches[2] ) > 0 ) {
1125 $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $matches[2] );
1128 $result['sectionanchor'] = $sectionanchor;
1129 wfProfileOut( __METHOD__
. '-sectionanchor' );
1131 // Save errors may fall down to the edit form, but we've now
1132 // merged the section into full text. Clear the section field
1133 // so that later submission of conflict forms won't try to
1134 // replace that into a duplicated mess.
1135 $this->textbox1
= $text;
1136 $this->section
= '';
1138 $retval = self
::AS_SUCCESS_UPDATE
;
1141 // Check for length errors again now that the section is merged in
1142 $this->kblength
= (int)( strlen( $text ) / 1024 );
1143 if ( $this->kblength
> $wgMaxArticleSize ) {
1144 $this->tooBig
= true;
1145 wfProfileOut( __METHOD__
);
1146 return self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
;
1149 $flags = EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
1150 ( $new ? EDIT_NEW
: EDIT_UPDATE
) |
1151 ( ( $this->minoredit
&& !$this->isNew
) ? EDIT_MINOR
: 0 ) |
1152 ( $bot ? EDIT_FORCE_BOT
: 0 );
1154 $status = $this->mArticle
->doEdit( $text, $this->summary
, $flags );
1156 if ( $status->isOK() ) {
1157 $result['redirect'] = Title
::newFromRedirect( $text ) !== null;
1158 $this->commitWatch();
1159 wfProfileOut( __METHOD__
);
1162 $this->isConflict
= true;
1163 wfProfileOut( __METHOD__
);
1164 return self
::AS_END
;
1169 * Commit the change of watch status
1171 protected function commitWatch() {
1173 if ( $this->watchthis
xor $this->mTitle
->userIsWatching() ) {
1174 $dbw = wfGetDB( DB_MASTER
);
1176 if ( $this->watchthis
) {
1177 WatchAction
::doWatch( $this->mTitle
, $wgUser );
1179 WatchAction
::doUnwatch( $this->mTitle
, $wgUser );
1186 * Check if no edits were made by other users since
1187 * the time a user started editing the page. Limit to
1188 * 50 revisions for the sake of performance.
1191 * @param $edittime string
1195 protected function userWasLastToEdit( $id, $edittime ) {
1196 if( !$id ) return false;
1197 $dbw = wfGetDB( DB_MASTER
);
1198 $res = $dbw->select( 'revision',
1201 'rev_page' => $this->mArticle
->getId(),
1202 'rev_timestamp > '.$dbw->addQuotes( $dbw->timestamp($edittime) )
1205 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
1206 foreach ( $res as $row ) {
1207 if( $row->rev_user
!= $id ) {
1215 * Check given input text against $wgSpamRegex, and return the text of the first match.
1217 * @param $text string
1219 * @return string|false matching string or false
1221 public static function matchSpamRegex( $text ) {
1222 global $wgSpamRegex;
1223 // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
1224 $regexes = (array)$wgSpamRegex;
1225 return self
::matchSpamRegexInternal( $text, $regexes );
1229 * Check given input text against $wgSpamRegex, and return the text of the first match.
1231 * @parma $text string
1233 * @return string|false matching string or false
1235 public static function matchSummarySpamRegex( $text ) {
1236 global $wgSummarySpamRegex;
1237 $regexes = (array)$wgSummarySpamRegex;
1238 return self
::matchSpamRegexInternal( $text, $regexes );
1242 * @param $text string
1243 * @param $regexes array
1244 * @return bool|string
1246 protected static function matchSpamRegexInternal( $text, $regexes ) {
1247 foreach( $regexes as $regex ) {
1249 if( preg_match( $regex, $text, $matches ) ) {
1257 * Initialise form fields in the object
1258 * Called on the first invocation, e.g. when a user clicks an edit link
1259 * @return bool -- if the requested section is valid
1261 function initialiseForm() {
1263 $this->edittime
= $this->mArticle
->getTimestamp();
1264 $this->textbox1
= $this->getContent( false );
1265 // activate checkboxes if user wants them to be always active
1266 # Sort out the "watch" checkbox
1267 if ( $wgUser->getOption( 'watchdefault' ) ) {
1269 $this->watchthis
= true;
1270 } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
1272 $this->watchthis
= true;
1273 } elseif ( $this->mTitle
->userIsWatching() ) {
1275 $this->watchthis
= true;
1277 if ( $wgUser->getOption( 'minordefault' ) && !$this->isNew
) {
1278 $this->minoredit
= true;
1280 if ( $this->textbox1
=== false ) {
1287 function setHeaders() {
1289 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1290 if ( $this->formtype
== 'preview' ) {
1291 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
1293 if ( $this->isConflict
) {
1294 $wgOut->setPageTitle( wfMsg( 'editconflict', $this->getContextTitle()->getPrefixedText() ) );
1295 } elseif ( $this->section
!= '' ) {
1296 $msg = $this->section
== 'new' ?
'editingcomment' : 'editingsection';
1297 $wgOut->setPageTitle( wfMsg( $msg, $this->getContextTitle()->getPrefixedText() ) );
1299 # Use the title defined by DISPLAYTITLE magic word when present
1300 if ( isset( $this->mParserOutput
)
1301 && ( $dt = $this->mParserOutput
->getDisplayTitle() ) !== false ) {
1304 $title = $this->getContextTitle()->getPrefixedText();
1306 $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
1311 * Send the edit form and related headers to $wgOut
1312 * @param $formCallback Callback that takes an OutputPage parameter; will be called
1313 * during form output near the top, for captchas and the like.
1315 function showEditForm( $formCallback = null ) {
1316 global $wgOut, $wgUser;
1318 wfProfileIn( __METHOD__
);
1320 #need to parse the preview early so that we know which templates are used,
1321 #otherwise users with "show preview after edit box" will get a blank list
1322 #we parse this near the beginning so that setHeaders can do the title
1323 #setting work instead of leaving it in getPreviewText
1324 $previewOutput = '';
1325 if ( $this->formtype
== 'preview' ) {
1326 $previewOutput = $this->getPreviewText();
1329 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) );
1331 $this->setHeaders();
1333 # Enabled article-related sidebar, toplinks, etc.
1334 $wgOut->setArticleRelated( true );
1336 if ( $this->showHeader() === false ) {
1337 wfProfileOut( __METHOD__
);
1341 $action = htmlspecialchars( $this->getActionURL( $this->getContextTitle() ) );
1343 if ( $wgUser->getOption( 'showtoolbar' ) and !$this->isCssJsSubpage
) {
1344 # prepare toolbar for edit buttons
1345 $toolbar = EditPage
::getEditToolbar();
1351 $wgOut->addHTML( $this->editFormPageTop
);
1353 if ( $wgUser->getOption( 'previewontop' ) ) {
1354 $this->displayPreviewArea( $previewOutput, true );
1357 $wgOut->addHTML( $this->editFormTextTop
);
1359 $templates = $this->getTemplates();
1360 $formattedtemplates = Linker
::formatTemplates( $templates, $this->preview
, $this->section
!= '');
1362 $hiddencats = $this->mArticle
->getHiddenCategories();
1363 $formattedhiddencats = Linker
::formatHiddenCategories( $hiddencats );
1365 if ( $this->wasDeletedSinceLastEdit() && 'save' != $this->formtype
) {
1366 $wgOut->wrapWikiMsg(
1367 "<div class='error mw-deleted-while-editing'>\n$1\n</div>",
1368 'deletedwhileediting' );
1369 } elseif ( $this->wasDeletedSinceLastEdit() ) {
1370 // Hide the toolbar and edit area, user can click preview to get it back
1371 // Add an confirmation checkbox and explanation.
1373 // @todo move this to a cleaner conditional instead of blanking a variable
1375 $wgOut->addHTML( <<<HTML
1376 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1380 if ( is_callable( $formCallback ) ) {
1381 call_user_func_array( $formCallback, array( &$wgOut ) );
1384 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1386 // Put these up at the top to ensure they aren't lost on early form submission
1387 $this->showFormBeforeText();
1389 if ( $this->wasDeletedSinceLastEdit() && 'save' == $this->formtype
) {
1390 $username = $this->lastDelete
->user_name
;
1391 $comment = $this->lastDelete
->log_comment
;
1393 // It is better to not parse the comment at all than to have templates expanded in the middle
1394 // TODO: can the checkLabel be moved outside of the div so that wrapWikiMsg could be used?
1395 $key = $comment === ''
1396 ?
'confirmrecreate-noreason'
1397 : 'confirmrecreate';
1399 '<div class="mw-confirm-recreate">' .
1400 wfMsgExt( $key, 'parseinline', $username, "<nowiki>$comment</nowiki>" ) .
1401 Xml
::checkLabel( wfMsg( 'recreate' ), 'wpRecreate', 'wpRecreate', false,
1402 array( 'title' => Linker
::titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' )
1408 # If a blank edit summary was previously provided, and the appropriate
1409 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1410 # user being bounced back more than once in the event that a summary
1413 # For a bit more sophisticated detection of blank summaries, hash the
1414 # automatic one and pass that in the hidden field wpAutoSummary.
1415 if ( $this->missingSummary ||
1416 ( $this->section
== 'new' && $this->nosummary
) )
1417 $wgOut->addHTML( Html
::hidden( 'wpIgnoreBlankSummary', true ) );
1418 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
1419 $wgOut->addHTML( Html
::hidden( 'wpAutoSummary', $autosumm ) );
1421 $wgOut->addHTML( Html
::hidden( 'oldid', $this->mArticle
->getOldID() ) );
1423 if ( $this->section
== 'new' ) {
1424 $this->showSummaryInput( true, $this->summary
);
1425 $wgOut->addHTML( $this->getSummaryPreview( true, $this->summary
) );
1428 $wgOut->addHTML( $this->editFormTextBeforeContent
);
1430 $wgOut->addHTML( $toolbar );
1432 if ( $this->isConflict
) {
1433 // In an edit conflict bypass the overrideable content form method
1434 // and fallback to the raw wpTextbox1 since editconflicts can't be
1435 // resolved between page source edits and custom ui edits using the
1437 $this->showTextbox1( null, $this->getContent() );
1439 $this->showContentForm();
1442 $wgOut->addHTML( $this->editFormTextAfterContent
);
1444 $wgOut->addWikiText( $this->getCopywarn() );
1445 if ( isset($this->editFormTextAfterWarn
) && $this->editFormTextAfterWarn
!== '' )
1446 $wgOut->addHTML( $this->editFormTextAfterWarn
);
1448 $this->showStandardInputs();
1450 $this->showFormAfterText();
1452 $this->showTosSummary();
1453 $this->showEditTools();
1455 $wgOut->addHTML( <<<HTML
1456 {$this->editFormTextAfterTools}
1457 <div class='templatesUsed'>
1458 {$formattedtemplates}
1460 <div class='hiddencats'>
1461 {$formattedhiddencats}
1466 if ( $this->isConflict
)
1467 $this->showConflict();
1469 $wgOut->addHTML( $this->editFormTextBottom
);
1470 $wgOut->addHTML( "</form>\n" );
1471 if ( !$wgUser->getOption( 'previewontop' ) ) {
1472 $this->displayPreviewArea( $previewOutput, false );
1475 wfProfileOut( __METHOD__
);
1478 protected function showHeader() {
1479 global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang;
1480 if ( $this->isConflict
) {
1481 $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
1482 $this->edittime
= $this->mArticle
->getTimestamp();
1484 if ( $this->section
!= '' && !$this->isSectionEditSupported() ) {
1485 // We use $this->section to much before this and getVal('wgSection') directly in other places
1486 // at this point we can't reset $this->section to '' to fallback to non-section editing.
1487 // Someone is welcome to try refactoring though
1488 $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
1492 if ( $this->section
!= '' && $this->section
!= 'new' ) {
1494 if ( !$this->summary
&& !$this->preview
&& !$this->diff
) {
1495 preg_match( "/^(=+)(.+)\\1/mi", $this->textbox1
, $matches );
1496 if ( !empty( $matches[2] ) ) {
1498 $this->summary
= "/* " .
1499 $wgParser->stripSectionName(trim($matches[2])) .
1505 if ( $this->missingComment
) {
1506 $wgOut->wrapWikiMsg( "<div id='mw-missingcommenttext'>\n$1\n</div>", 'missingcommenttext' );
1509 if ( $this->missingSummary
&& $this->section
!= 'new' ) {
1510 $wgOut->wrapWikiMsg( "<div id='mw-missingsummary'>\n$1\n</div>", 'missingsummary' );
1513 if ( $this->missingSummary
&& $this->section
== 'new' ) {
1514 $wgOut->wrapWikiMsg( "<div id='mw-missingcommentheader'>\n$1\n</div>", 'missingcommentheader' );
1517 if ( $this->hookError
!== '' ) {
1518 $wgOut->addWikiText( $this->hookError
);
1521 if ( !$this->checkUnicodeCompliantBrowser() ) {
1522 $wgOut->addWikiMsg( 'nonunicodebrowser' );
1525 if ( isset( $this->mArticle
) && isset( $this->mArticle
->mRevision
) ) {
1526 // Let sysop know that this will make private content public if saved
1528 if ( !$this->mArticle
->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1529 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-permission' );
1530 } elseif ( $this->mArticle
->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1531 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-view' );
1534 if ( !$this->mArticle
->mRevision
->isCurrent() ) {
1535 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
1536 $wgOut->addWikiMsg( 'editingold' );
1541 if ( wfReadOnly() ) {
1542 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
1543 } elseif ( $wgUser->isAnon() ) {
1544 if ( $this->formtype
!= 'preview' ) {
1545 $wgOut->wrapWikiMsg( "<div id=\"mw-anon-edit-warning\">\n$1</div>", 'anoneditwarning' );
1547 $wgOut->wrapWikiMsg( "<div id=\"mw-anon-preview-warning\">\n$1</div>", 'anonpreviewwarning' );
1550 if ( $this->isCssJsSubpage
) {
1551 # Check the skin exists
1552 if ( $this->isWrongCaseCssJsPage
) {
1553 $wgOut->wrapWikiMsg( "<div class='error' id='mw-userinvalidcssjstitle'>\n$1\n</div>", array( 'userinvalidcssjstitle', $this->getContextTitle()->getSkinFromCssJsSubpage() ) );
1555 if ( $this->formtype
!== 'preview' ) {
1556 if ( $this->isCssSubpage
)
1557 $wgOut->wrapWikiMsg( "<div id='mw-usercssyoucanpreview'>\n$1\n</div>", array( 'usercssyoucanpreview' ) );
1558 if ( $this->isJsSubpage
)
1559 $wgOut->wrapWikiMsg( "<div id='mw-userjsyoucanpreview'>\n$1\n</div>", array( 'userjsyoucanpreview' ) );
1564 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
1565 # Is the title semi-protected?
1566 if ( $this->mTitle
->isSemiProtected() ) {
1567 $noticeMsg = 'semiprotectedpagewarning';
1569 # Then it must be protected based on static groups (regular)
1570 $noticeMsg = 'protectedpagewarning';
1572 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
->getPrefixedText(), '',
1573 array( 'lim' => 1, 'msgKey' => array( $noticeMsg ) ) );
1575 if ( $this->mTitle
->isCascadeProtected() ) {
1576 # Is this page under cascading protection from some source pages?
1577 list($cascadeSources, /* $restrictions */) = $this->mTitle
->getCascadeProtectionSources();
1578 $notice = "<div class='mw-cascadeprotectedwarning'>\n$1\n";
1579 $cascadeSourcesCount = count( $cascadeSources );
1580 if ( $cascadeSourcesCount > 0 ) {
1581 # Explain, and list the titles responsible
1582 foreach( $cascadeSources as $page ) {
1583 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1586 $notice .= '</div>';
1587 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', $cascadeSourcesCount ) );
1589 if ( !$this->mTitle
->exists() && $this->mTitle
->getRestrictions( 'create' ) ) {
1590 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
->getPrefixedText(), '',
1592 'showIfEmpty' => false,
1593 'msgKey' => array( 'titleprotectedwarning' ),
1594 'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ) );
1597 if ( $this->kblength
=== false ) {
1598 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
1601 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
1602 $wgOut->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
1603 array( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgLang->formatNum( $wgMaxArticleSize ) ) );
1605 if( !wfMessage('longpage-hint')->isDisabled() ) {
1606 $wgOut->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
1607 array( 'longpage-hint', $wgLang->formatSize( strlen( $this->textbox1
) ), strlen( $this->textbox1
) )
1614 * Standard summary input and label (wgSummary), abstracted so EditPage
1615 * subclasses may reorganize the form.
1616 * Note that you do not need to worry about the label's for=, it will be
1617 * inferred by the id given to the input. You can remove them both by
1618 * passing array( 'id' => false ) to $userInputAttrs.
1620 * @param $summary string The value of the summary input
1621 * @param $labelText string The html to place inside the label
1622 * @param $inputAttrs array of attrs to use on the input
1623 * @param $spanLabelAttrs array of attrs to use on the span inside the label
1625 * @return array An array in the format array( $label, $input )
1627 function getSummaryInput($summary = "", $labelText = null, $inputAttrs = null, $spanLabelAttrs = null) {
1628 //Note: the maxlength is overriden in JS to 250 and to make it use UTF-8 bytes, not characters.
1629 $inputAttrs = ( is_array($inputAttrs) ?
$inputAttrs : array() ) +
array(
1630 'id' => 'wpSummary',
1631 'maxlength' => '200',
1634 'spellcheck' => 'true',
1635 ) + Linker
::tooltipAndAccesskeyAttribs( 'summary' );
1637 $spanLabelAttrs = ( is_array($spanLabelAttrs) ?
$spanLabelAttrs : array() ) +
array(
1638 'class' => $this->missingSummary ?
'mw-summarymissed' : 'mw-summary',
1639 'id' => "wpSummaryLabel"
1644 $label = Xml
::tags( 'label', $inputAttrs['id'] ?
array( 'for' => $inputAttrs['id'] ) : null, $labelText );
1645 $label = Xml
::tags( 'span', $spanLabelAttrs, $label );
1648 $input = Html
::input( 'wpSummary', $summary, 'text', $inputAttrs );
1650 return array( $label, $input );
1654 * @param $isSubjectPreview Boolean: true if this is the section subject/title
1655 * up top, or false if this is the comment summary
1656 * down below the textarea
1657 * @param $summary String: The text of the summary to display
1660 protected function showSummaryInput( $isSubjectPreview, $summary = "" ) {
1661 global $wgOut, $wgContLang;
1662 # Add a class if 'missingsummary' is triggered to allow styling of the summary line
1663 $summaryClass = $this->missingSummary ?
'mw-summarymissed' : 'mw-summary';
1664 if ( $isSubjectPreview ) {
1665 if ( $this->nosummary
) {
1669 if ( !$this->mShowSummaryField
) {
1673 $summary = $wgContLang->recodeForEdit( $summary );
1674 $labelText = wfMsgExt( $isSubjectPreview ?
'subject' : 'summary', 'parseinline' );
1675 list($label, $input) = $this->getSummaryInput($summary, $labelText, array( 'class' => $summaryClass ), array());
1676 $wgOut->addHTML("{$label} {$input}");
1680 * @param $isSubjectPreview Boolean: true if this is the section subject/title
1681 * up top, or false if this is the comment summary
1682 * down below the textarea
1683 * @param $summary String: the text of the summary to display
1686 protected function getSummaryPreview( $isSubjectPreview, $summary = "" ) {
1687 if ( !$summary ||
( !$this->preview
&& !$this->diff
) )
1692 if ( $isSubjectPreview )
1693 $summary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $summary ) );
1695 $message = $isSubjectPreview ?
'subject-preview' : 'summary-preview';
1697 $summary = wfMsgExt( $message, 'parseinline' ) . Linker
::commentBlock( $summary, $this->mTitle
, $isSubjectPreview );
1698 return Xml
::tags( 'div', array( 'class' => 'mw-summary-preview' ), $summary );
1701 protected function showFormBeforeText() {
1703 $section = htmlspecialchars( $this->section
);
1704 $wgOut->addHTML( <<<HTML
1705 <input type='hidden' value="{$section}" name="wpSection" />
1706 <input type='hidden' value="{$this->starttime}" name="wpStarttime" />
1707 <input type='hidden' value="{$this->edittime}" name="wpEdittime" />
1708 <input type='hidden' value="{$this->scrolltop}" name="wpScrolltop" id="wpScrolltop" />
1712 if ( !$this->checkUnicodeCompliantBrowser() )
1713 $wgOut->addHTML(Html
::hidden( 'safemode', '1' ));
1716 protected function showFormAfterText() {
1717 global $wgOut, $wgUser;
1719 * To make it harder for someone to slip a user a page
1720 * which submits an edit form to the wiki without their
1721 * knowledge, a random token is associated with the login
1722 * session. If it's not passed back with the submission,
1723 * we won't save the page, or render user JavaScript and
1726 * For anon editors, who may not have a session, we just
1727 * include the constant suffix to prevent editing from
1728 * broken text-mangling proxies.
1730 $wgOut->addHTML( "\n" . Html
::hidden( "wpEditToken", $wgUser->editToken() ) . "\n" );
1734 * Subpage overridable method for printing the form for page content editing
1735 * By default this simply outputs wpTextbox1
1736 * Subclasses can override this to provide a custom UI for editing;
1737 * be it a form, or simply wpTextbox1 with a modified content that will be
1738 * reverse modified when extracted from the post data.
1739 * Note that this is basically the inverse for importContentFormData
1741 protected function showContentForm() {
1742 $this->showTextbox1();
1746 * Method to output wpTextbox1
1747 * The $textoverride method can be used by subclasses overriding showContentForm
1748 * to pass back to this method.
1750 * @param $customAttribs An array of html attributes to use in the textarea
1751 * @param $textoverride String: optional text to override $this->textarea1 with
1753 protected function showTextbox1($customAttribs = null, $textoverride = null) {
1754 $classes = array(); // Textarea CSS
1755 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
1756 # Is the title semi-protected?
1757 if ( $this->mTitle
->isSemiProtected() ) {
1758 $classes[] = 'mw-textarea-sprotected';
1760 # Then it must be protected based on static groups (regular)
1761 $classes[] = 'mw-textarea-protected';
1763 # Is the title cascade-protected?
1764 if ( $this->mTitle
->isCascadeProtected() ) {
1765 $classes[] = 'mw-textarea-cprotected';
1768 $attribs = array( 'tabindex' => 1 );
1769 if ( is_array($customAttribs) )
1770 $attribs +
= $customAttribs;
1772 if ( $this->wasDeletedSinceLastEdit() )
1773 $attribs['type'] = 'hidden';
1774 if ( !empty( $classes ) ) {
1775 if ( isset($attribs['class']) )
1776 $classes[] = $attribs['class'];
1777 $attribs['class'] = implode( ' ', $classes );
1780 $this->showTextbox( isset($textoverride) ?
$textoverride : $this->textbox1
, 'wpTextbox1', $attribs );
1783 protected function showTextbox2() {
1784 $this->showTextbox( $this->textbox2
, 'wpTextbox2', array( 'tabindex' => 6, 'readonly' ) );
1787 protected function showTextbox( $content, $name, $customAttribs = array() ) {
1788 global $wgOut, $wgUser;
1790 $wikitext = $this->safeUnicodeOutput( $content );
1791 if ( $wikitext !== '' ) {
1792 // Ensure there's a newline at the end, otherwise adding lines
1794 // But don't add a newline if the ext is empty, or Firefox in XHTML
1795 // mode will show an extra newline. A bit annoying.
1799 $attribs = $customAttribs +
array(
1802 'cols' => $wgUser->getIntOption( 'cols' ),
1803 'rows' => $wgUser->getIntOption( 'rows' ),
1804 'style' => '' // avoid php notices when appending preferences (appending allows customAttribs['style'] to still work
1807 $pageLang = $this->mTitle
->getPageLanguage();
1808 $attribs['lang'] = $pageLang->getCode();
1809 $attribs['dir'] = $pageLang->getDir();
1811 $wgOut->addHTML( Html
::textarea( $name, $wikitext, $attribs ) );
1814 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
1818 $classes[] = 'ontop';
1820 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
1822 if ( $this->formtype
!= 'preview' )
1823 $attribs['style'] = 'display: none;';
1825 $wgOut->addHTML( Xml
::openElement( 'div', $attribs ) );
1827 if ( $this->formtype
== 'preview' ) {
1828 $this->showPreview( $previewOutput );
1831 $wgOut->addHTML( '</div>' );
1833 if ( $this->formtype
== 'diff') {
1839 * Append preview output to $wgOut.
1840 * Includes category rendering if this is a category page.
1842 * @param $text String: the HTML to be output for the preview.
1844 protected function showPreview( $text ) {
1846 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1847 $this->mArticle
->openShowCategory();
1849 # This hook seems slightly odd here, but makes things more
1850 # consistent for extensions.
1851 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1852 $wgOut->addHTML( $text );
1853 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1854 $this->mArticle
->closeShowCategory();
1859 * Give a chance for site and per-namespace customizations of
1860 * terms of service summary link that might exist separately
1861 * from the copyright notice.
1863 * This will display between the save button and the edit tools,
1864 * so should remain short!
1866 protected function showTosSummary() {
1867 $msg = 'editpage-tos-summary';
1868 wfRunHooks( 'EditPageTosSummary', array( $this->mTitle
, &$msg ) );
1869 if( !wfMessage( $msg )->isDisabled() ) {
1871 $wgOut->addHTML( '<div class="mw-tos-summary">' );
1872 $wgOut->addWikiMsg( $msg );
1873 $wgOut->addHTML( '</div>' );
1877 protected function showEditTools() {
1879 $wgOut->addHTML( '<div class="mw-editTools">' .
1880 wfMessage( 'edittools' )->inContentLanguage()->parse() .
1884 protected function getCopywarn() {
1885 global $wgRightsText;
1886 if ( $wgRightsText ) {
1887 $copywarnMsg = array( 'copyrightwarning',
1888 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1891 $copywarnMsg = array( 'copyrightwarning2',
1892 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
1894 // Allow for site and per-namespace customization of contribution/copyright notice.
1895 wfRunHooks( 'EditPageCopyrightWarning', array( $this->mTitle
, &$copywarnMsg ) );
1897 return "<div id=\"editpage-copywarn\">\n" .
1898 call_user_func_array("wfMsgNoTrans", $copywarnMsg) . "\n</div>";
1901 protected function showStandardInputs( &$tabindex = 2 ) {
1903 $wgOut->addHTML( "<div class='editOptions'>\n" );
1905 if ( $this->section
!= 'new' ) {
1906 $this->showSummaryInput( false, $this->summary
);
1907 $wgOut->addHTML( $this->getSummaryPreview( false, $this->summary
) );
1910 $checkboxes = $this->getCheckboxes( $tabindex,
1911 array( 'minor' => $this->minoredit
, 'watch' => $this->watchthis
) );
1912 $wgOut->addHTML( "<div class='editCheckboxes'>" . implode( $checkboxes, "\n" ) . "</div>\n" );
1913 $wgOut->addHTML( "<div class='editButtons'>\n" );
1914 $wgOut->addHTML( implode( $this->getEditButtons( $tabindex ), "\n" ) . "\n" );
1916 $cancel = $this->getCancelLink();
1917 if ( $cancel !== '' ) {
1918 $cancel .= wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1920 $edithelpurl = Skin
::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ) );
1921 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1922 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1923 htmlspecialchars( wfMsg( 'newwindow' ) );
1924 $wgOut->addHTML( " <span class='editHelp'>{$cancel}{$edithelp}</span>\n" );
1925 $wgOut->addHTML( "</div><!-- editButtons -->\n</div><!-- editOptions -->\n" );
1929 * Show an edit conflict. textbox1 is already shown in showEditForm().
1930 * If you want to use another entry point to this function, be careful.
1932 protected function showConflict() {
1934 $this->textbox2
= $this->textbox1
;
1935 $this->textbox1
= $this->getContent();
1936 if ( wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
1937 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
1939 $de = new DifferenceEngine( $this->mTitle
);
1940 $de->setText( $this->textbox2
, $this->textbox1
);
1941 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1943 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
1944 $this->showTextbox2();
1948 protected function getLastDelete() {
1949 $dbr = wfGetDB( DB_SLAVE
);
1950 $data = $dbr->selectRow(
1951 array( 'logging', 'user' ),
1962 array( 'log_namespace' => $this->mTitle
->getNamespace(),
1963 'log_title' => $this->mTitle
->getDBkey(),
1964 'log_type' => 'delete',
1965 'log_action' => 'delete',
1966 'user_id=log_user' ),
1968 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' )
1970 // Quick paranoid permission checks...
1971 if( is_object( $data ) ) {
1972 if( $data->log_deleted
& LogPage
::DELETED_USER
)
1973 $data->user_name
= wfMsgHtml( 'rev-deleted-user' );
1974 if( $data->log_deleted
& LogPage
::DELETED_COMMENT
)
1975 $data->log_comment
= wfMsgHtml( 'rev-deleted-comment' );
1981 * Get the rendered text for previewing.
1984 function getPreviewText() {
1985 global $wgOut, $wgUser, $wgParser;
1987 wfProfileIn( __METHOD__
);
1989 if ( $this->mTriedSave
&& !$this->mTokenOk
) {
1990 if ( $this->mTokenOkExceptSuffix
) {
1991 $note = wfMsg( 'token_suffix_mismatch' );
1993 $note = wfMsg( 'session_fail_preview' );
1995 } elseif ( $this->incompleteForm
) {
1996 $note = wfMsg( 'edit_form_incomplete' );
1998 $note = wfMsg( 'previewnote' );
2001 $parserOptions = ParserOptions
::newFromUser( $wgUser );
2002 $parserOptions->setEditSection( false );
2003 $parserOptions->setIsPreview( true );
2004 $parserOptions->setIsSectionPreview( !is_null($this->section
) && $this->section
!== '' );
2007 if ( $wgRawHtml && !$this->mTokenOk
) {
2008 // Could be an offsite preview attempt. This is very unsafe if
2009 // HTML is enabled, as it could be an attack.
2011 if ( $this->textbox1
!== '' ) {
2012 // Do not put big scary notice, if previewing the empty
2013 // string, which happens when you initially edit
2014 // a category page, due to automatic preview-on-open.
2015 $parsedNote = $wgOut->parse( "<div class='previewnote'>" .
2016 wfMsg( 'session_fail_preview_html' ) . "</div>" );
2018 wfProfileOut( __METHOD__
);
2022 # don't parse user css/js, show message about preview
2023 # 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?
2025 if ( $this->isCssJsSubpage ||
$this->mTitle
->isCssOrJsPage() ) {
2027 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2031 # Used messages to make sure grep find them:
2032 # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
2033 if (preg_match( "/\\.css$/", $this->mTitle
->getText() ) ) {
2034 $previewtext = "<div id='mw-{$level}csspreview'>\n" . wfMsg( "{$level}csspreview" ) . "\n</div>";
2035 $class = "mw-code mw-css";
2036 } elseif (preg_match( "/\\.js$/", $this->mTitle
->getText() ) ) {
2037 $previewtext = "<div id='mw-{$level}jspreview'>\n" . wfMsg( "{$level}jspreview" ) . "\n</div>";
2038 $class = "mw-code mw-js";
2040 throw new MWException( 'A CSS/JS (sub)page but which is not css nor js!' );
2043 $parserOptions->setTidy( true );
2044 $parserOutput = $wgParser->parse( $previewtext, $this->mTitle
, $parserOptions );
2045 $previewHTML = $parserOutput->mText
;
2046 $previewHTML .= "<pre class=\"$class\" dir=\"ltr\">\n" . htmlspecialchars( $this->textbox1
) . "\n</pre>\n";
2048 $rt = Title
::newFromRedirectArray( $this->textbox1
);
2050 $previewHTML = $this->mArticle
->viewRedirect( $rt, false );
2052 $toparse = $this->textbox1
;
2054 # If we're adding a comment, we need to show the
2055 # summary as the headline
2056 if ( $this->section
== "new" && $this->summary
!= "" ) {
2057 $toparse = "== {$this->summary} ==\n\n" . $toparse;
2060 wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
2062 $parserOptions->setTidy( true );
2063 $parserOptions->enableLimitReport();
2064 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ),
2065 $this->mTitle
, $parserOptions );
2067 $previewHTML = $parserOutput->getText();
2068 $this->mParserOutput
= $parserOutput;
2069 $wgOut->addParserOutputNoText( $parserOutput );
2071 if ( count( $parserOutput->getWarnings() ) ) {
2072 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
2077 if( $this->isConflict
) {
2078 $conflict = '<h2 id="mw-previewconflict">' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
2080 $conflict = '<hr />';
2083 $previewhead = "<div class='previewnote'>\n" .
2084 '<h2 id="mw-previewheader">' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>" .
2085 $wgOut->parse( $note ) . $conflict . "</div>\n";
2087 $pageLang = $this->mTitle
->getPageLanguage();
2088 $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
2089 'class' => 'mw-content-'.$pageLang->getDir() );
2090 $previewHTML = Html
::rawElement( 'div', $attribs, $previewHTML );
2092 wfProfileOut( __METHOD__
);
2093 return $previewhead . $previewHTML . $this->previewTextAfterContent
;
2099 function getTemplates() {
2100 if ( $this->preview ||
$this->section
!= '' ) {
2101 $templates = array();
2102 if ( !isset( $this->mParserOutput
) ) {
2105 foreach( $this->mParserOutput
->getTemplates() as $ns => $template) {
2106 foreach( array_keys( $template ) as $dbk ) {
2107 $templates[] = Title
::makeTitle($ns, $dbk);
2112 return $this->mArticle
->getUsedTemplates();
2117 * Call the stock "user is blocked" page
2119 function blockedPage() {
2121 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
2123 # If the user made changes, preserve them when showing the markup
2124 # (This happens when a user is blocked during edit, for instance)
2125 $first = $this->firsttime ||
( !$this->save
&& $this->textbox1
== '' );
2127 $source = $this->mTitle
->exists() ?
$this->getContent() : false;
2129 $source = $this->textbox1
;
2132 # Spit out the source or the user's modified version
2133 if ( $source !== false ) {
2134 $wgOut->addHTML( '<hr />' );
2135 $wgOut->addWikiMsg( $first ?
'blockedoriginalsource' : 'blockededitsource', $this->mTitle
->getPrefixedText() );
2136 $this->showTextbox1( array( 'readonly' ), $source );
2141 * Produce the stock "please login to edit pages" page
2143 function userNotLoggedInPage() {
2146 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
2147 $loginLink = Linker
::linkKnown(
2149 wfMsgHtml( 'loginreqlink' ),
2151 array( 'returnto' => $this->getContextTitle()->getPrefixedText() )
2154 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
2155 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2156 $wgOut->setArticleRelated( false );
2158 $wgOut->addHTML( wfMessage( 'whitelistedittext' )->rawParams( $loginLink )->parse() );
2159 $wgOut->returnToMain( false, $this->getContextTitle() );
2163 * Creates a basic error page which informs the user that
2164 * they have attempted to edit a nonexistent section.
2166 function noSuchSectionPage() {
2169 $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
2170 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2171 $wgOut->setArticleRelated( false );
2173 $res = wfMsgExt( 'nosuchsectiontext', 'parse', $this->section
);
2174 wfRunHooks( 'EditPageNoSuchSection', array( &$this, &$res ) );
2175 $wgOut->addHTML( $res );
2177 $wgOut->returnToMain( false, $this->mTitle
);
2181 * Produce the stock "your edit contains spam" page
2183 * @param $match Text which triggered one or more filters
2184 * @deprecated since 1.17 Use method spamPageWithContent() instead
2186 static function spamPage( $match = false ) {
2187 global $wgOut, $wgTitle;
2189 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
2190 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2191 $wgOut->setArticleRelated( false );
2193 $wgOut->addHTML( '<div id="spamprotected">' );
2194 $wgOut->addWikiMsg( 'spamprotectiontext' );
2196 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
2198 $wgOut->addHTML( '</div>' );
2200 $wgOut->returnToMain( false, $wgTitle );
2204 * Show "your edit contains spam" page with your diff and text
2206 * @param $match Text which triggered one or more filters
2208 public function spamPageWithContent( $match = false ) {
2210 $this->textbox2
= $this->textbox1
;
2212 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
2213 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2214 $wgOut->setArticleRelated( false );
2216 $wgOut->addHTML( '<div id="spamprotected">' );
2217 $wgOut->addWikiMsg( 'spamprotectiontext' );
2219 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
2221 $wgOut->addHTML( '</div>' );
2223 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
2224 $de = new DifferenceEngine( $this->mTitle
);
2225 $de->setText( $this->getContent(), $this->textbox2
);
2226 $de->showDiff( wfMsg( "storedversion" ), wfMsg( "yourtext" ) );
2228 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
2229 $this->showTextbox2();
2231 $wgOut->addReturnTo( $this->getContextTitle(), array( 'action' => 'edit' ) );
2239 * @parma $editText string
2243 function mergeChangesInto( &$editText ){
2244 wfProfileIn( __METHOD__
);
2246 $db = wfGetDB( DB_MASTER
);
2248 // This is the revision the editor started from
2249 $baseRevision = $this->getBaseRevision();
2250 if ( is_null( $baseRevision ) ) {
2251 wfProfileOut( __METHOD__
);
2254 $baseText = $baseRevision->getText();
2256 // The current state, we want to merge updates into it
2257 $currentRevision = Revision
::loadFromTitle( $db, $this->mTitle
);
2258 if ( is_null( $currentRevision ) ) {
2259 wfProfileOut( __METHOD__
);
2262 $currentText = $currentRevision->getText();
2265 if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
2266 $editText = $result;
2267 wfProfileOut( __METHOD__
);
2270 wfProfileOut( __METHOD__
);
2276 * Check if the browser is on a blacklist of user-agents known to
2277 * mangle UTF-8 data on form submission. Returns true if Unicode
2278 * should make it through, false if it's known to be a problem.
2282 function checkUnicodeCompliantBrowser() {
2283 global $wgBrowserBlackList;
2284 if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
2285 // No User-Agent header sent? Trust it by default...
2288 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
2289 foreach ( $wgBrowserBlackList as $browser ) {
2290 if ( preg_match($browser, $currentbrowser) ) {
2298 * Format an anchor fragment as it would appear for a given section name
2299 * @param $text String
2303 function sectionAnchor( $text ) {
2305 return $wgParser->guessSectionNameFromWikiText( $text );
2309 * Shows a bulletin board style toolbar for common editing functions.
2310 * It can be disabled in the user preferences.
2311 * The necessary JavaScript code can be found in skins/common/edit.js.
2315 static function getEditToolbar() {
2316 global $wgStylePath, $wgContLang, $wgLang, $wgOut;
2317 global $wgUseTeX, $wgEnableUploads, $wgForeignFileRepos;
2319 $imagesAvailable = $wgEnableUploads ||
count( $wgForeignFileRepos );
2322 * $toolarray is an array of arrays each of which includes the
2323 * filename of the button image (without path), the opening
2324 * tag, the closing tag, optionally a sample text that is
2325 * inserted between the two when no selection is highlighted
2326 * and. The tip text is shown when the user moves the mouse
2329 * Also here: accesskeys (key), which are not used yet until
2330 * someone can figure out a way to make them work in
2331 * IE. However, we should make sure these keys are not defined
2336 'image' => $wgLang->getImageFile( 'button-bold' ),
2337 'id' => 'mw-editbutton-bold',
2339 'close' => '\'\'\'',
2340 'sample' => wfMsg( 'bold_sample' ),
2341 'tip' => wfMsg( 'bold_tip' ),
2345 'image' => $wgLang->getImageFile( 'button-italic' ),
2346 'id' => 'mw-editbutton-italic',
2349 'sample' => wfMsg( 'italic_sample' ),
2350 'tip' => wfMsg( 'italic_tip' ),
2354 'image' => $wgLang->getImageFile( 'button-link' ),
2355 'id' => 'mw-editbutton-link',
2358 'sample' => wfMsg( 'link_sample' ),
2359 'tip' => wfMsg( 'link_tip' ),
2363 'image' => $wgLang->getImageFile( 'button-extlink' ),
2364 'id' => 'mw-editbutton-extlink',
2367 'sample' => wfMsg( 'extlink_sample' ),
2368 'tip' => wfMsg( 'extlink_tip' ),
2372 'image' => $wgLang->getImageFile( 'button-headline' ),
2373 'id' => 'mw-editbutton-headline',
2376 'sample' => wfMsg( 'headline_sample' ),
2377 'tip' => wfMsg( 'headline_tip' ),
2380 $imagesAvailable ?
array(
2381 'image' => $wgLang->getImageFile( 'button-image' ),
2382 'id' => 'mw-editbutton-image',
2383 'open' => '[[' . $wgContLang->getNsText( NS_FILE
) . ':',
2385 'sample' => wfMsg( 'image_sample' ),
2386 'tip' => wfMsg( 'image_tip' ),
2389 $imagesAvailable ?
array(
2390 'image' => $wgLang->getImageFile( 'button-media' ),
2391 'id' => 'mw-editbutton-media',
2392 'open' => '[[' . $wgContLang->getNsText( NS_MEDIA
) . ':',
2394 'sample' => wfMsg( 'media_sample' ),
2395 'tip' => wfMsg( 'media_tip' ),
2399 'image' => $wgLang->getImageFile( 'button-math' ),
2400 'id' => 'mw-editbutton-math',
2402 'close' => "</math>",
2403 'sample' => wfMsg( 'math_sample' ),
2404 'tip' => wfMsg( 'math_tip' ),
2408 'image' => $wgLang->getImageFile( 'button-nowiki' ),
2409 'id' => 'mw-editbutton-nowiki',
2410 'open' => "<nowiki>",
2411 'close' => "</nowiki>",
2412 'sample' => wfMsg( 'nowiki_sample' ),
2413 'tip' => wfMsg( 'nowiki_tip' ),
2417 'image' => $wgLang->getImageFile( 'button-sig' ),
2418 'id' => 'mw-editbutton-signature',
2422 'tip' => wfMsg( 'sig_tip' ),
2426 'image' => $wgLang->getImageFile( 'button-hr' ),
2427 'id' => 'mw-editbutton-hr',
2428 'open' => "\n----\n",
2431 'tip' => wfMsg( 'hr_tip' ),
2435 $toolbar = "<div id='toolbar'>\n";
2438 foreach ( $toolarray as $tool ) {
2444 $image = $wgStylePath . '/common/images/' . $tool['image'],
2445 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2446 // Older browsers show a "speedtip" type message only for ALT.
2447 // Ideally these should be different, realistically they
2448 // probably don't need to be.
2449 $tip = $tool['tip'],
2450 $open = $tool['open'],
2451 $close = $tool['close'],
2452 $sample = $tool['sample'],
2453 $cssId = $tool['id'],
2456 $paramList = implode( ',',
2457 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
2458 $script .= "mw.toolbar.addButton($paramList);\n";
2460 $wgOut->addScript( Html
::inlineScript(
2461 "if ( window.mediaWiki ) {{$script}}"
2464 $toolbar .= "\n</div>";
2466 wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
2472 * Returns an array of html code of the following checkboxes:
2475 * @param $tabindex Current tabindex
2476 * @param $checked Array of checkbox => bool, where bool indicates the checked
2477 * status of the checkbox
2481 public function getCheckboxes( &$tabindex, $checked ) {
2484 $checkboxes = array();
2486 // don't show the minor edit checkbox if it's a new page or section
2487 if ( !$this->isNew
) {
2488 $checkboxes['minor'] = '';
2489 $minorLabel = wfMsgExt( 'minoredit', array( 'parseinline' ) );
2490 if ( $wgUser->isAllowed( 'minoredit' ) ) {
2492 'tabindex' => ++
$tabindex,
2493 'accesskey' => wfMsg( 'accesskey-minoredit' ),
2494 'id' => 'wpMinoredit',
2496 $checkboxes['minor'] =
2497 Xml
::check( 'wpMinoredit', $checked['minor'], $attribs ) .
2498 " <label for='wpMinoredit' id='mw-editpage-minoredit'" .
2499 Xml
::expandAttributes( array( 'title' => Linker
::titleAttrib( 'minoredit', 'withaccess' ) ) ) .
2500 ">{$minorLabel}</label>";
2504 $watchLabel = wfMsgExt( 'watchthis', array( 'parseinline' ) );
2505 $checkboxes['watch'] = '';
2506 if ( $wgUser->isLoggedIn() ) {
2508 'tabindex' => ++
$tabindex,
2509 'accesskey' => wfMsg( 'accesskey-watch' ),
2510 'id' => 'wpWatchthis',
2512 $checkboxes['watch'] =
2513 Xml
::check( 'wpWatchthis', $checked['watch'], $attribs ) .
2514 " <label for='wpWatchthis' id='mw-editpage-watch'" .
2515 Xml
::expandAttributes( array( 'title' => Linker
::titleAttrib( 'watch', 'withaccess' ) ) ) .
2516 ">{$watchLabel}</label>";
2518 wfRunHooks( 'EditPageBeforeEditChecks', array( &$this, &$checkboxes, &$tabindex ) );
2523 * Returns an array of html code of the following buttons:
2524 * save, diff, preview and live
2526 * @param $tabindex Current tabindex
2530 public function getEditButtons( &$tabindex ) {
2537 'tabindex' => ++
$tabindex,
2538 'value' => wfMsg( 'savearticle' ),
2539 'accesskey' => wfMsg( 'accesskey-save' ),
2540 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
2542 $buttons['save'] = Xml
::element('input', $temp, '');
2544 ++
$tabindex; // use the same for preview and live preview
2546 'id' => 'wpPreview',
2547 'name' => 'wpPreview',
2549 'tabindex' => $tabindex,
2550 'value' => wfMsg( 'showpreview' ),
2551 'accesskey' => wfMsg( 'accesskey-preview' ),
2552 'title' => wfMsg( 'tooltip-preview' ) . ' [' . wfMsg( 'accesskey-preview' ) . ']',
2554 $buttons['preview'] = Xml
::element( 'input', $temp, '' );
2555 $buttons['live'] = '';
2561 'tabindex' => ++
$tabindex,
2562 'value' => wfMsg( 'showdiff' ),
2563 'accesskey' => wfMsg( 'accesskey-diff' ),
2564 'title' => wfMsg( 'tooltip-diff' ) . ' [' . wfMsg( 'accesskey-diff' ) . ']',
2566 $buttons['diff'] = Xml
::element( 'input', $temp, '' );
2568 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
2573 * Output preview text only. This can be sucked into the edit page
2574 * via JavaScript, and saves the server time rendering the skin as
2575 * well as theoretically being more robust on the client (doesn't
2576 * disturb the edit box's undo history, won't eat your text on
2579 * @todo This doesn't include category or interlanguage links.
2580 * Would need to enhance it a bit, <s>maybe wrap them in XML
2581 * or something...</s> that might also require more skin
2582 * initialization, so check whether that's a problem.
2584 function livePreview() {
2587 header( 'Content-type: text/xml; charset=utf-8' );
2588 header( 'Cache-control: no-cache' );
2590 $previewText = $this->getPreviewText();
2591 #$categories = $skin->getCategoryLinks();
2594 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2595 Xml
::tags( 'livepreview', null,
2596 Xml
::element( 'preview', null, $previewText )
2597 #. Xml::element( 'category', null, $categories )
2605 public function getCancelLink() {
2606 $cancelParams = array();
2607 if ( !$this->isConflict
&& $this->mArticle
->getOldID() > 0 ) {
2608 $cancelParams['oldid'] = $this->mArticle
->getOldID();
2611 return Linker
::linkKnown(
2612 $this->getContextTitle(),
2613 wfMsgExt( 'cancel', array( 'parseinline' ) ),
2614 array( 'id' => 'mw-editform-cancel' ),
2620 * Get a diff between the current contents of the edit box and the
2621 * version of the page we're editing from.
2623 * If this is a section edit, we'll replace the section as for final
2624 * save and then make a comparison.
2626 function showDiff() {
2627 $oldtext = $this->mArticle
->fetchContent();
2628 $newtext = $this->mArticle
->replaceSection(
2629 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
2631 wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
2633 $newtext = $this->mArticle
->preSaveTransform( $newtext );
2634 $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
2635 $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
2636 if ( $oldtext !== false ||
$newtext != '' ) {
2637 $de = new DifferenceEngine( $this->mTitle
);
2638 $de->setText( $oldtext, $newtext );
2639 $difftext = $de->getDiff( $oldtitle, $newtitle );
2640 $de->showDiffStyle();
2646 $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
2650 * Filter an input field through a Unicode de-armoring process if it
2651 * came from an old browser with known broken Unicode editing issues.
2653 * @param $request WebRequest
2654 * @param $field String
2658 function safeUnicodeInput( $request, $field ) {
2659 $text = rtrim( $request->getText( $field ) );
2660 return $request->getBool( 'safemode' )
2661 ?
$this->unmakesafe( $text )
2666 * @param $request WebRequest
2667 * @param $text string
2670 function safeUnicodeText( $request, $text ) {
2671 $text = rtrim( $text );
2672 return $request->getBool( 'safemode' )
2673 ?
$this->unmakesafe( $text )
2678 * Filter an output field through a Unicode armoring process if it is
2679 * going to an old browser with known broken Unicode editing issues.
2681 * @param $text String
2685 function safeUnicodeOutput( $text ) {
2687 $codedText = $wgContLang->recodeForEdit( $text );
2688 return $this->checkUnicodeCompliantBrowser()
2690 : $this->makesafe( $codedText );
2694 * A number of web browsers are known to corrupt non-ASCII characters
2695 * in a UTF-8 text editing environment. To protect against this,
2696 * detected browsers will be served an armored version of the text,
2697 * with non-ASCII chars converted to numeric HTML character references.
2699 * Preexisting such character references will have a 0 added to them
2700 * to ensure that round-trips do not alter the original data.
2702 * @param $invalue String
2706 function makesafe( $invalue ) {
2707 // Armor existing references for reversability.
2708 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
2713 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2714 $bytevalue = ord( $invalue[$i] );
2715 if ( $bytevalue <= 0x7F ) { //0xxx xxxx
2716 $result .= chr( $bytevalue );
2718 } elseif ( $bytevalue <= 0xBF ) { //10xx xxxx
2719 $working = $working << 6;
2720 $working +
= ($bytevalue & 0x3F);
2722 if ( $bytesleft <= 0 ) {
2723 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2725 } elseif ( $bytevalue <= 0xDF ) { //110x xxxx
2726 $working = $bytevalue & 0x1F;
2728 } elseif ( $bytevalue <= 0xEF ) { //1110 xxxx
2729 $working = $bytevalue & 0x0F;
2731 } else { //1111 0xxx
2732 $working = $bytevalue & 0x07;
2740 * Reverse the previously applied transliteration of non-ASCII characters
2741 * back to UTF-8. Used to protect data from corruption by broken web browsers
2742 * as listed in $wgBrowserBlackList.
2744 * @param $invalue String
2748 function unmakesafe( $invalue ) {
2750 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2751 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue[$i+
3] != '0' ) ) {
2755 $hexstring .= $invalue[$i];
2757 } while( ctype_xdigit( $invalue[$i] ) && ( $i < strlen( $invalue ) ) );
2759 // Do some sanity checks. These aren't needed for reversability,
2760 // but should help keep the breakage down if the editor
2761 // breaks one of the entities whilst editing.
2762 if ( (substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6) ) {
2763 $codepoint = hexdec($hexstring);
2764 $result .= codepointToUtf8( $codepoint );
2766 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2769 $result .= substr( $invalue, $i, 1 );
2772 // reverse the transform that we made for reversability reasons.
2773 return strtr( $result, array( "�" => "&#x" ) );
2776 function noCreatePermission() {
2778 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
2779 $wgOut->addWikiMsg( 'nocreatetext' );
2783 * Attempt submission
2784 * @return bool false if output is done, true if the rest of the form should be displayed
2786 function attemptSave() {
2787 global $wgUser, $wgOut;
2789 $resultDetails = false;
2790 # Allow bots to exempt some edits from bot flagging
2791 $bot = $wgUser->isAllowed( 'bot' ) && $this->bot
;
2792 $value = $this->internalAttemptSave( $resultDetails, $bot );
2794 if ( $value == self
::AS_SUCCESS_UPDATE ||
$value == self
::AS_SUCCESS_NEW_ARTICLE
) {
2795 $this->didSave
= true;
2799 case self
::AS_HOOK_ERROR_EXPECTED
:
2800 case self
::AS_CONTENT_TOO_BIG
:
2801 case self
::AS_ARTICLE_WAS_DELETED
:
2802 case self
::AS_CONFLICT_DETECTED
:
2803 case self
::AS_SUMMARY_NEEDED
:
2804 case self
::AS_TEXTBOX_EMPTY
:
2805 case self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
:
2809 case self
::AS_HOOK_ERROR
:
2810 case self
::AS_FILTERING
:
2813 case self
::AS_SUCCESS_NEW_ARTICLE
:
2814 $query = $resultDetails['redirect'] ?
'redirect=no' : '';
2815 $wgOut->redirect( $this->mTitle
->getFullURL( $query ) );
2818 case self
::AS_SUCCESS_UPDATE
:
2820 $sectionanchor = $resultDetails['sectionanchor'];
2822 // Give extensions a chance to modify URL query on update
2823 wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this->mArticle
, &$sectionanchor, &$extraQuery ) );
2825 if ( $resultDetails['redirect'] ) {
2826 if ( $extraQuery == '' ) {
2827 $extraQuery = 'redirect=no';
2829 $extraQuery = 'redirect=no&' . $extraQuery;
2832 $wgOut->redirect( $this->mTitle
->getFullURL( $extraQuery ) . $sectionanchor );
2835 case self
::AS_SPAM_ERROR
:
2836 $this->spamPageWithContent( $resultDetails['spam'] );
2839 case self
::AS_BLOCKED_PAGE_FOR_USER
:
2840 $this->blockedPage();
2843 case self
::AS_IMAGE_REDIRECT_ANON
:
2844 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2847 case self
::AS_READ_ONLY_PAGE_ANON
:
2848 $this->userNotLoggedInPage();
2851 case self
::AS_READ_ONLY_PAGE_LOGGED
:
2852 case self
::AS_READ_ONLY_PAGE
:
2853 $wgOut->readOnlyPage();
2856 case self
::AS_RATE_LIMITED
:
2857 $wgOut->rateLimited();
2860 case self
::AS_NO_CREATE_PERMISSION
:
2861 $this->noCreatePermission();
2864 case self
::AS_BLANK_ARTICLE
:
2865 $wgOut->redirect( $this->getContextTitle()->getFullURL() );
2868 case self
::AS_IMAGE_REDIRECT_LOGGED
:
2869 $wgOut->permissionRequired( 'upload' );
2877 function getBaseRevision() {
2878 if ( !$this->mBaseRevision
) {
2879 $db = wfGetDB( DB_MASTER
);
2880 $baseRevision = Revision
::loadFromTimestamp(
2881 $db, $this->mTitle
, $this->edittime
);
2882 return $this->mBaseRevision
= $baseRevision;
2884 return $this->mBaseRevision
;