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 * $wgTitle 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;
48 var $isConflict = false;
49 var $isCssJsSubpage = false;
50 var $isCssSubpage = false;
51 var $isJsSubpage = false;
52 var $deletedSinceEdit = false;
56 var $mTokenOk = false;
57 var $mTokenOkExceptSuffix = false;
58 var $mTriedSave = false;
60 var $kblength = false;
61 var $missingComment = false;
62 var $missingSummary = false;
63 var $allowBlankSummary = false;
66 #var $mPreviewTemplates;
68 var $mBaseRevision = false;
69 var $mShowSummaryField = true;
72 var $save = false, $preview = false, $diff = false;
73 var $minoredit = false, $watchthis = false, $recreate = false;
74 var $textbox1 = '', $textbox2 = '', $summary = '', $nosummary = false;
75 var $edittime = '', $section = '', $starttime = '';
76 var $oldid = 0, $editintro = '', $scrolltop = null, $bot = true;
78 # Placeholders for text injection by hooks (must be HTML)
79 # extensions should take care to _append_ to the present value
80 public $editFormPageTop; // Before even the preview
81 public $editFormTextTop;
82 public $editFormTextBeforeContent;
83 public $editFormTextAfterWarn;
84 public $editFormTextAfterTools;
85 public $editFormTextBottom;
86 public $editFormTextAfterContent;
87 public $previewTextAfterContent;
89 /* $didSave should be set to true whenever an article was succesfully altered. */
90 public $didSave = false;
93 public $suppressIntro = false;
99 function EditPage( $article ) {
100 $this->mArticle
=& $article;
101 $this->mTitle
= $article->getTitle();
102 $this->action
= 'submit';
104 # Placeholders for text injection by hooks (empty per default)
105 $this->editFormPageTop
=
106 $this->editFormTextTop
=
107 $this->editFormTextBeforeContent
=
108 $this->editFormTextAfterWarn
=
109 $this->editFormTextAfterTools
=
110 $this->editFormTextBottom
=
111 $this->editFormTextAfterContent
=
112 $this->previewTextAfterContent
=
113 $this->mPreloadText
= "";
116 function getArticle() {
117 return $this->mArticle
;
122 * Fetch initial editing page content.
123 * @returns mixed string on success, $def_text for invalid sections
126 function getContent( $def_text = '' ) {
127 global $wgOut, $wgRequest, $wgParser, $wgContLang, $wgMessageCache;
129 wfProfileIn( __METHOD__
);
130 # Get variables from query string :P
131 $section = $wgRequest->getVal( 'section' );
133 $preload = $wgRequest->getVal( 'preload',
134 // Custom preload text for new sections
135 $section === 'new' ?
'MediaWiki:addsection-preload' : '' );
136 $undoafter = $wgRequest->getVal( 'undoafter' );
137 $undo = $wgRequest->getVal( 'undo' );
140 // For message page not locally set, use the i18n message.
141 // For other non-existent articles, use preload text if any.
142 if ( !$this->mTitle
->exists() ) {
143 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
144 # If this is a system message, get the default text.
145 list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle
->getText() ) );
146 $wgMessageCache->loadAllMessages( $lang );
147 $text = wfMsgGetKey( $message, false, $lang, false );
148 if( wfEmptyMsg( $message, $text ) )
149 $text = $this->getPreloadedText( $preload );
151 # If requested, preload some text.
152 $text = $this->getPreloadedText( $preload );
154 // For existing pages, get text based on "undo" or section parameters.
156 $text = $this->mArticle
->getContent();
157 if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
158 # If they got undoafter and undo round the wrong way, switch them
159 list( $undo, $undoafter ) = array( $undoafter, $undo );
161 if ( $undo > 0 && $undo > $undoafter ) {
162 # Undoing a specific edit overrides section editing; section-editing
163 # doesn't work with undoing.
165 $undorev = Revision
::newFromId( $undo );
166 $oldrev = Revision
::newFromId( $undoafter );
168 $undorev = Revision
::newFromId( $undo );
169 $oldrev = $undorev ?
$undorev->getPrevious() : null;
172 # Sanity check, make sure it's the right page,
173 # the revisions exist and they were not deleted.
174 # Otherwise, $text will be left as-is.
175 if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
176 $undorev->getPage() == $oldrev->getPage() &&
177 $undorev->getPage() == $this->mArticle
->getID() &&
178 !$undorev->isDeleted( Revision
::DELETED_TEXT
) &&
179 !$oldrev->isDeleted( Revision
::DELETED_TEXT
) ) {
181 $undotext = $this->mArticle
->getUndoText( $undorev, $oldrev );
182 if ( $undotext === false ) {
183 # Warn the user that something went wrong
184 $this->editFormPageTop
.= $wgOut->parse( '<div class="error mw-undo-failure">' . wfMsgNoTrans( 'undo-failure' ) . '</div>' );
187 # Inform the user of our success and set an automatic edit summary
188 $this->editFormPageTop
.= $wgOut->parse( '<div class="mw-undo-success">' . wfMsgNoTrans( 'undo-success' ) . '</div>' );
189 $firstrev = $oldrev->getNext();
190 # If we just undid one rev, use an autosummary
191 if ( $firstrev->mId
== $undo ) {
192 $this->summary
= wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
193 $this->undidRev
= $undo;
195 $this->formtype
= 'diff';
198 // Failed basic sanity checks.
199 // Older revisions may have been removed since the link
200 // was created, or we may simply have got bogus input.
201 $this->editFormPageTop
.= $wgOut->parse( '<div class="error mw-undo-norev">' . wfMsgNoTrans( 'undo-norev' ) . '</div>' );
203 } else if ( $section != '' ) {
204 if ( $section == 'new' ) {
205 $text = $this->getPreloadedText( $preload );
207 // Get section edit text (returns $def_text for invalid sections)
208 $text = $wgParser->getSection( $text, $section, $def_text );
213 wfProfileOut( __METHOD__
);
217 /** Use this method before edit() to preload some text into the edit box */
218 public function setPreloadedText( $text ) {
219 $this->mPreloadText
= $text;
223 * Get the contents of a page from its title and remove includeonly tags
225 * @param $preload String: the title of the page.
226 * @return string The contents of the page.
228 protected function getPreloadedText( $preload ) {
229 if ( !empty( $this->mPreloadText
) ) {
230 return $this->mPreloadText
;
231 } elseif ( $preload === '' ) {
234 $preloadTitle = Title
::newFromText( $preload );
235 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
236 $rev = Revision
::newFromTitle( $preloadTitle );
237 if ( is_object( $rev ) ) {
238 $text = $rev->getText();
239 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
240 // its own mini-parser! -ævar
241 $text = preg_replace( '~</?includeonly>~', '', $text );
250 * Check if a page was deleted while the user was editing it, before submit.
251 * Note that we rely on the logging table, which hasn't been always there,
252 * but that doesn't matter, because this only applies to brand new
255 protected function wasDeletedSinceLastEdit() {
256 if ( $this->deletedSinceEdit
)
258 if ( $this->mTitle
->isDeletedQuick() ) {
259 $this->lastDelete
= $this->getLastDelete();
260 if ( $this->lastDelete
) {
261 $deleteTime = wfTimestamp( TS_MW
, $this->lastDelete
->log_timestamp
);
262 if ( $deleteTime > $this->starttime
) {
263 $this->deletedSinceEdit
= true;
267 return $this->deletedSinceEdit
;
275 * This is the function that gets called for "action=edit". It
276 * sets up various member variables, then passes execution to
277 * another function, usually showEditForm()
279 * The edit form is self-submitting, so that when things like
280 * preview and edit conflicts occur, we get the same form back
281 * with the extra stuff added. Only when the final submission
282 * is made and all is well do we actually save and redirect to
283 * the newly-edited page.
286 global $wgOut, $wgRequest, $wgUser;
287 // Allow extensions to modify/prevent this form or submission
288 if ( !wfRunHooks( 'AlternateEdit', array( $this ) ) ) {
292 wfProfileIn( __METHOD__
);
293 wfDebug( __METHOD__
.": enter\n" );
295 // This is not an article
296 $wgOut->setArticleFlag( false );
298 $this->importFormData( $wgRequest );
299 $this->firsttime
= false;
302 $this->livePreview();
303 wfProfileOut( __METHOD__
);
307 if ( wfReadOnly() && $this->save
) {
310 $this->preview
= true;
313 $wgOut->addScriptFile( 'edit.js' );
315 if ( $wgUser->getOption( 'uselivepreview', false ) ) {
316 $wgOut->includeJQuery();
317 $wgOut->addScriptFile( 'preview.js' );
319 // Bug #19334: textarea jumps when editing articles in IE8
320 $wgOut->addStyle( 'common/IE80Fixes.css', 'screen', 'IE 8' );
322 $permErrors = $this->getEditPermissionErrors();
324 wfDebug( __METHOD__
. ": User can't edit\n" );
325 $this->readOnlyPage( $this->getContent( false ), true, $permErrors, 'edit' );
326 wfProfileOut( __METHOD__
);
330 $this->formtype
= 'save';
331 } else if ( $this->preview
) {
332 $this->formtype
= 'preview';
333 } else if ( $this->diff
) {
334 $this->formtype
= 'diff';
335 } else { # First time through
336 $this->firsttime
= true;
337 if ( $this->previewOnOpen() ) {
338 $this->formtype
= 'preview';
340 $this->formtype
= 'initial';
345 // If they used redlink=1 and the page exists, redirect to the main article
346 if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle
->exists() ) {
347 $wgOut->redirect( $this->mTitle
->getFullURL() );
350 wfProfileIn( __METHOD__
."-business-end" );
352 $this->isConflict
= false;
353 // css / js subpages of user pages get a special treatment
354 $this->isCssJsSubpage
= $this->mTitle
->isCssJsSubpage();
355 $this->isCssSubpage
= $this->mTitle
->isCssSubpage();
356 $this->isJsSubpage
= $this->mTitle
->isJsSubpage();
357 $this->isValidCssJsSubpage
= $this->mTitle
->isValidCssJsSubpage();
359 # Show applicable editing introductions
360 if ( $this->formtype
== 'initial' ||
$this->firsttime
)
363 if ( $this->mTitle
->isTalkPage() ) {
364 $wgOut->addWikiMsg( 'talkpagetext' );
367 # Optional notices on a per-namespace and per-page basis
368 $editnotice_ns = 'editnotice-'.$this->mTitle
->getNamespace();
369 if ( !wfEmptyMsg( $editnotice_ns, wfMsgForContent( $editnotice_ns ) ) ) {
370 $wgOut->addWikiText( wfMsgForContent( $editnotice_ns ) );
372 if ( MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
373 $parts = explode( '/', $this->mTitle
->getDBkey() );
374 $editnotice_base = $editnotice_ns;
375 while ( count( $parts ) > 0 ) {
376 $editnotice_base .= '-'.array_shift( $parts );
377 if ( !wfEmptyMsg( $editnotice_base, wfMsgForContent( $editnotice_base ) ) ) {
378 $wgOut->addWikiText( wfMsgForContent( $editnotice_base ) );
383 # Attempt submission here. This will check for edit conflicts,
384 # and redundantly check for locked database, blocked IPs, etc.
385 # that edit() already checked just in case someone tries to sneak
386 # in the back door with a hand-edited submission URL.
388 if ( 'save' == $this->formtype
) {
389 if ( !$this->attemptSave() ) {
390 wfProfileOut( __METHOD__
."-business-end" );
391 wfProfileOut( __METHOD__
);
396 # First time through: get contents, set time for conflict
398 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
399 if ( $this->initialiseForm() === false ) {
400 $this->noSuchSectionPage();
401 wfProfileOut( __METHOD__
."-business-end" );
402 wfProfileOut( __METHOD__
);
405 if ( !$this->mTitle
->getArticleId() )
406 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1
, &$this->mTitle
) );
408 wfRunHooks( 'EditFormInitialText', array( $this ) );
411 $this->showEditForm();
412 wfProfileOut( __METHOD__
."-business-end" );
413 wfProfileOut( __METHOD__
);
416 protected function getEditPermissionErrors() {
418 $permErrors = $this->mTitle
->getUserPermissionsErrors( 'edit', $wgUser );
419 # Can this title be created?
420 if ( !$this->mTitle
->exists() ) {
421 $permErrors = array_merge( $permErrors,
422 wfArrayDiff2( $this->mTitle
->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) );
424 # Ignore some permissions errors when a user is just previewing/viewing diffs
426 foreach( $permErrors as $error ) {
427 if ( ( $this->preview ||
$this->diff
) &&
428 ( $error[0] == 'blockedtext' ||
$error[0] == 'autoblockedtext' ) )
433 $permErrors = wfArrayDiff2( $permErrors, $remove );
438 * Show a read-only error
439 * Parameters are the same as OutputPage:readOnlyPage()
440 * Redirect to the article page if redlink=1
442 function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
443 global $wgRequest, $wgOut;
444 if ( $wgRequest->getBool( 'redlink' ) ) {
445 // The edit page was reached via a red link.
446 // Redirect to the article page and let them click the edit tab if
447 // they really want a permission error.
448 $wgOut->redirect( $this->mTitle
->getFullUrl() );
450 $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
455 * Should we show a preview when the edit form is first shown?
459 protected function previewOnOpen() {
460 global $wgRequest, $wgUser, $wgPreviewOnOpenNamespaces;
461 if ( $wgRequest->getVal( 'preview' ) == 'yes' ) {
462 // Explicit override from request
464 } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) {
465 // Explicit override from request
467 } elseif ( $this->section
== 'new' ) {
468 // Nothing *to* preview for new sections
470 } elseif ( ( $wgRequest->getVal( 'preload' ) !== null ||
$this->mTitle
->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
471 // Standard preference behaviour
473 } elseif ( !$this->mTitle
->exists() &&
474 isset($wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()]) &&
475 $wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()] )
477 // Categories are special
485 * Does this EditPage class support section editing?
486 * This is used by EditPage subclasses to indicate their ui cannot handle section edits
490 protected function isSectionEditSupported() {
495 * Returns the URL to use in the form's action attribute.
496 * This is used by EditPage subclasses when simply customizing the action
497 * variable in the constructor is not enough. This can be used when the
498 * EditPage lives inside of a Special page rather than a custom page action.
500 * @param Title $title The title for which is being edited (where we go to for &action= links)
503 protected function getActionURL( Title
$title ) {
504 return $title->getLocalURL( array( 'action' => $this->action
) );
511 function importFormData( &$request ) {
512 global $wgLang, $wgUser;
514 wfProfileIn( __METHOD__
);
516 # Section edit can come from either the form or a link
517 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
519 if ( $request->wasPosted() ) {
520 # These fields need to be checked for encoding.
521 # Also remove trailing whitespace, but don't remove _initial_
522 # whitespace from the text boxes. This may be significant formatting.
523 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
524 if ( !$request->getCheck('wpTextbox2') ) {
525 // Skip this if wpTextbox2 has input, it indicates that we came
526 // from a conflict page with raw page text, not a custom form
527 // modified by subclasses
528 wfProfileIn( get_class($this)."::importContentFormData" );
529 $textbox1 = $this->importContentFormData( $request );
530 if ( isset($textbox1) )
531 $this->textbox1
= $textbox1;
532 wfProfileOut( get_class($this)."::importContentFormData" );
535 # Truncate for whole multibyte characters. +5 bytes for ellipsis
536 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250, '' );
538 # Remove extra headings from summaries and new sections.
539 $this->summary
= preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary
);
541 $this->edittime
= $request->getVal( 'wpEdittime' );
542 $this->starttime
= $request->getVal( 'wpStarttime' );
544 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
546 if ( is_null( $this->edittime
) ) {
547 # If the form is incomplete, force to preview.
548 wfDebug( __METHOD__
. ": Form data appears to be incomplete\n" );
549 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
550 $this->preview
= true;
552 /* Fallback for live preview */
553 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
554 $this->diff
= $request->getCheck( 'wpDiff' );
556 // Remember whether a save was requested, so we can indicate
557 // if we forced preview due to session failure.
558 $this->mTriedSave
= !$this->preview
;
560 if ( $this->tokenOk( $request ) ) {
561 # Some browsers will not report any submit button
562 # if the user hits enter in the comment box.
563 # The unmarked state will be assumed to be a save,
564 # if the form seems otherwise complete.
565 wfDebug( __METHOD__
. ": Passed token check.\n" );
566 } else if ( $this->diff
) {
567 # Failed token check, but only requested "Show Changes".
568 wfDebug( __METHOD__
. ": Failed token check; Show Changes requested.\n" );
570 # Page might be a hack attempt posted from
571 # an external site. Preview instead of saving.
572 wfDebug( __METHOD__
. ": Failed token check; forcing preview\n" );
573 $this->preview
= true;
576 $this->save
= !$this->preview
&& !$this->diff
;
577 if ( !preg_match( '/^\d{14}$/', $this->edittime
) ) {
578 $this->edittime
= null;
581 if ( !preg_match( '/^\d{14}$/', $this->starttime
) ) {
582 $this->starttime
= null;
585 $this->recreate
= $request->getCheck( 'wpRecreate' );
587 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
588 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
590 # Don't force edit summaries when a user is editing their own user or talk page
591 if ( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) &&
592 $this->mTitle
->getText() == $wgUser->getName() )
594 $this->allowBlankSummary
= true;
596 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' ) ||
!$wgUser->getOption( 'forceeditsummary');
599 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
601 # Not a posted form? Start with nothing.
602 wfDebug( __METHOD__
. ": Not a posted form.\n" );
603 $this->textbox1
= '';
605 $this->edittime
= '';
606 $this->starttime
= wfTimestampNow();
608 $this->preview
= false;
611 $this->minoredit
= false;
612 $this->watchthis
= $request->getBool( 'watchthis', false ); // Watch may be overriden by request parameters
613 $this->recreate
= false;
615 if ( $this->section
== 'new' && $request->getVal( 'preloadtitle' ) ) {
616 $this->summary
= $request->getVal( 'preloadtitle' );
618 elseif ( $this->section
!= 'new' && $request->getVal( 'summary' ) ) {
619 $this->summary
= $request->getText( 'summary' );
622 if ( $request->getVal( 'minor' ) ) {
623 $this->minoredit
= true;
627 $this->bot
= $request->getBool( 'bot', true );
628 $this->nosummary
= $request->getBool( 'nosummary' );
630 // FIXME: unused variable?
631 $this->oldid
= $request->getInt( 'oldid' );
633 $this->live
= $request->getCheck( 'live' );
634 $this->editintro
= $request->getText( 'editintro',
635 // Custom edit intro for new sections
636 $this->section
=== 'new' ?
'MediaWiki:addsection-editintro' : '' );
638 wfProfileOut( __METHOD__
);
640 // Allow extensions to modify form data
641 wfRunHooks( 'EditPage::importFormData', array( $this, $request ) );
645 * Subpage overridable method for extracting the page content data from the
646 * posted form to be placed in $this->textbox1, if using customized input
647 * this method should be overrided and return the page text that will be used
648 * for saving, preview parsing and so on...
650 * @praram WebRequest $request
652 protected function importContentFormData( &$request ) {
653 return; // Don't do anything, EditPage already extracted wpTextbox1
657 * Make sure the form isn't faking a user's credentials.
659 * @param $request WebRequest
663 function tokenOk( &$request ) {
665 $token = $request->getVal( 'wpEditToken' );
666 $this->mTokenOk
= $wgUser->matchEditToken( $token );
667 $this->mTokenOkExceptSuffix
= $wgUser->matchEditTokenNoSuffix( $token );
668 return $this->mTokenOk
;
672 * Show all applicable editing introductions
674 protected function showIntro() {
675 global $wgOut, $wgUser;
676 if ( $this->suppressIntro
) {
680 $namespace = $this->mTitle
->getNamespace();
682 if ( $namespace == NS_MEDIAWIKI
) {
683 # Show a warning if editing an interface message
684 $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1</div>", 'editinginterface' );
687 # Show a warning message when someone creates/edits a user (talk) page but the user does not exist
688 # Show log extract when the user is currently blocked
689 if ( $namespace == NS_USER ||
$namespace == NS_USER_TALK
) {
690 $parts = explode( '/', $this->mTitle
->getText(), 2 );
691 $username = $parts[0];
692 $user = User
::newFromName( $username, false /* allow IP users*/ );
693 $ip = User
::isIP( $username );
694 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
695 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n$1</div>",
696 array( 'userpage-userdoesnotexist', $username ) );
697 } else if ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
698 LogEventsList
::showLogExtract(
701 $user->getUserPage()->getPrefixedText(),
705 'showIfEmpty' => false,
707 'blocked-notice-logextract',
708 $user->getName() # Support GENDER in notice
714 # Try to add a custom edit intro, or use the standard one if this is not possible.
715 if ( !$this->showCustomIntro() && !$this->mTitle
->exists() ) {
716 if ( $wgUser->isLoggedIn() ) {
717 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletext\">\n$1</div>", 'newarticletext' );
719 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletextanon\">\n$1</div>", 'newarticletextanon' );
722 # Give a notice if the user is editing a deleted/moved page...
723 if ( !$this->mTitle
->exists() ) {
724 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle
->getPrefixedText(),
725 '', array( 'lim' => 10,
726 'conds' => array( "log_action != 'revision'" ),
727 'showIfEmpty' => false,
728 'msgKey' => array( 'recreate-moveddeleted-warn') )
734 * Attempt to show a custom editing introduction, if supplied
738 protected function showCustomIntro() {
739 if ( $this->editintro
) {
740 $title = Title
::newFromText( $this->editintro
);
741 if ( $title instanceof Title
&& $title->exists() && $title->userCanRead() ) {
743 $revision = Revision
::newFromTitle( $title );
744 $wgOut->addWikiTextTitleTidy( $revision->getText(), $this->mTitle
);
755 * Attempt submission (no UI)
756 * @return one of the constants describing the result
758 function internalAttemptSave( &$result, $bot = false ) {
759 global $wgFilterCallback, $wgUser, $wgOut, $wgParser;
760 global $wgMaxArticleSize;
762 wfProfileIn( __METHOD__
);
763 wfProfileIn( __METHOD__
. '-checks' );
765 if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) ) {
766 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
767 return self
::AS_HOOK_ERROR
;
770 # Check image redirect
771 if ( $this->mTitle
->getNamespace() == NS_FILE
&&
772 Title
::newFromRedirect( $this->textbox1
) instanceof Title
&&
773 !$wgUser->isAllowed( 'upload' ) ) {
774 if ( $wgUser->isAnon() ) {
775 return self
::AS_IMAGE_REDIRECT_ANON
;
777 return self
::AS_IMAGE_REDIRECT_LOGGED
;
782 $match = self
::matchSummarySpamRegex( $this->summary
);
783 if ( $match === false ) {
784 $match = self
::matchSpamRegex( $this->textbox1
);
786 if ( $match !== false ) {
787 $result['spam'] = $match;
789 $pdbk = $this->mTitle
->getPrefixedDBkey();
790 $match = str_replace( "\n", '', $match );
791 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
792 wfProfileOut( __METHOD__
. '-checks' );
793 wfProfileOut( __METHOD__
);
794 return self
::AS_SPAM_ERROR
;
796 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
, $this->hookError
, $this->summary
) ) {
797 # Error messages or other handling should be performed by the filter function
798 wfProfileOut( __METHOD__
. '-checks' );
799 wfProfileOut( __METHOD__
);
800 return self
::AS_FILTERING
;
802 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1
, $this->section
, &$this->hookError
, $this->summary
) ) ) {
803 # Error messages etc. could be handled within the hook...
804 wfProfileOut( __METHOD__
. '-checks' );
805 wfProfileOut( __METHOD__
);
806 return self
::AS_HOOK_ERROR
;
807 } elseif ( $this->hookError
!= '' ) {
808 # ...or the hook could be expecting us to produce an error
809 wfProfileOut( __METHOD__
. '-checks' );
810 wfProfileOut( __METHOD__
);
811 return self
::AS_HOOK_ERROR_EXPECTED
;
813 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
814 # Check block state against master, thus 'false'.
815 wfProfileOut( __METHOD__
. '-checks' );
816 wfProfileOut( __METHOD__
);
817 return self
::AS_BLOCKED_PAGE_FOR_USER
;
819 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
820 if ( $this->kblength
> $wgMaxArticleSize ) {
821 // Error will be displayed by showEditForm()
822 $this->tooBig
= true;
823 wfProfileOut( __METHOD__
. '-checks' );
824 wfProfileOut( __METHOD__
);
825 return self
::AS_CONTENT_TOO_BIG
;
828 if ( !$wgUser->isAllowed( 'edit' ) ) {
829 if ( $wgUser->isAnon() ) {
830 wfProfileOut( __METHOD__
. '-checks' );
831 wfProfileOut( __METHOD__
);
832 return self
::AS_READ_ONLY_PAGE_ANON
;
834 wfProfileOut( __METHOD__
. '-checks' );
835 wfProfileOut( __METHOD__
);
836 return self
::AS_READ_ONLY_PAGE_LOGGED
;
840 if ( wfReadOnly() ) {
841 wfProfileOut( __METHOD__
. '-checks' );
842 wfProfileOut( __METHOD__
);
843 return self
::AS_READ_ONLY_PAGE
;
845 if ( $wgUser->pingLimiter() ) {
846 wfProfileOut( __METHOD__
. '-checks' );
847 wfProfileOut( __METHOD__
);
848 return self
::AS_RATE_LIMITED
;
851 # If the article has been deleted while editing, don't save it without
853 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate
) {
854 wfProfileOut( __METHOD__
. '-checks' );
855 wfProfileOut( __METHOD__
);
856 return self
::AS_ARTICLE_WAS_DELETED
;
859 wfProfileOut( __METHOD__
. '-checks' );
861 # If article is new, insert it.
862 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
864 // Late check for create permission, just in case *PARANOIA*
865 if ( !$this->mTitle
->userCan( 'create' ) ) {
866 wfDebug( __METHOD__
. ": no create permission\n" );
867 wfProfileOut( __METHOD__
);
868 return self
::AS_NO_CREATE_PERMISSION
;
871 # Don't save a new article if it's blank.
872 if ( $this->textbox1
== '' ) {
873 wfProfileOut( __METHOD__
);
874 return self
::AS_BLANK_ARTICLE
;
877 // Run post-section-merge edit filter
878 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1
, &$this->hookError
, $this->summary
) ) ) {
879 # Error messages etc. could be handled within the hook...
880 wfProfileOut( __METHOD__
);
881 return self
::AS_HOOK_ERROR
;
882 } elseif ( $this->hookError
!= '' ) {
883 # ...or the hook could be expecting us to produce an error
884 wfProfileOut( __METHOD__
);
885 return self
::AS_HOOK_ERROR_EXPECTED
;
888 # Handle the user preference to force summaries here. Check if it's not a redirect.
889 if ( !$this->allowBlankSummary
&& !Title
::newFromRedirect( $this->textbox1
) ) {
890 if ( md5( $this->summary
) == $this->autoSumm
) {
891 $this->missingSummary
= true;
892 wfProfileOut( __METHOD__
);
893 return self
::AS_SUMMARY_NEEDED
;
897 $isComment = ( $this->section
== 'new' );
899 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
900 $this->minoredit
, $this->watchthis
, false, $isComment, $bot );
902 wfProfileOut( __METHOD__
);
903 return self
::AS_SUCCESS_NEW_ARTICLE
;
906 # Article exists. Check for edit conflict.
908 $this->mArticle
->clear(); # Force reload of dates, etc.
909 $this->mArticle
->forUpdate( true ); # Lock the article
911 wfDebug( "timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n" );
913 if ( $this->mArticle
->getTimestamp() != $this->edittime
) {
914 $this->isConflict
= true;
915 if ( $this->section
== 'new' ) {
916 if ( $this->mArticle
->getUserText() == $wgUser->getName() &&
917 $this->mArticle
->getComment() == $this->summary
) {
918 // Probably a duplicate submission of a new comment.
919 // This can happen when squid resends a request after
920 // a timeout but the first one actually went through.
921 wfDebug( __METHOD__
. ": duplicate new section submission; trigger edit conflict!\n" );
923 // New comment; suppress conflict.
924 $this->isConflict
= false;
925 wfDebug( __METHOD__
.": conflict suppressed; new section\n" );
929 $userid = $wgUser->getId();
931 # Suppress edit conflict with self, except for section edits where merging is required.
932 if ( $this->isConflict
&& $this->section
== '' && $this->userWasLastToEdit( $userid, $this->edittime
) ) {
933 wfDebug( __METHOD__
. ": Suppressing edit conflict, same user.\n" );
934 $this->isConflict
= false;
937 if ( $this->isConflict
) {
938 wfDebug( __METHOD__
. ": conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
939 $this->mArticle
->getTimestamp() . "')\n" );
940 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
942 wfDebug( __METHOD__
. ": getting section '$this->section'\n" );
943 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
945 if ( is_null( $text ) ) {
946 wfDebug( __METHOD__
. ": activating conflict; section replace failed.\n" );
947 $this->isConflict
= true;
948 $text = $this->textbox1
; // do not try to merge here!
949 } else if ( $this->isConflict
) {
951 if ( $this->mergeChangesInto( $text ) ) {
952 // Successful merge! Maybe we should tell the user the good news?
953 $this->isConflict
= false;
954 wfDebug( __METHOD__
. ": Suppressing edit conflict, successful merge.\n" );
957 $this->textbox1
= $text;
958 wfDebug( __METHOD__
. ": Keeping edit conflict, failed merge.\n" );
962 if ( $this->isConflict
) {
963 wfProfileOut( __METHOD__
);
964 return self
::AS_CONFLICT_DETECTED
;
967 $oldtext = $this->mArticle
->getContent();
969 // Run post-section-merge edit filter
970 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError
, $this->summary
) ) ) {
971 # Error messages etc. could be handled within the hook...
972 wfProfileOut( __METHOD__
);
973 return self
::AS_HOOK_ERROR
;
974 } elseif ( $this->hookError
!= '' ) {
975 # ...or the hook could be expecting us to produce an error
976 wfProfileOut( __METHOD__
);
977 return self
::AS_HOOK_ERROR_EXPECTED
;
980 # Handle the user preference to force summaries here, but not for null edits
981 if ( $this->section
!= 'new' && !$this->allowBlankSummary
&& 0 != strcmp( $oldtext, $text )
982 && !Title
::newFromRedirect( $text ) ) # check if it's not a redirect
984 if ( md5( $this->summary
) == $this->autoSumm
) {
985 $this->missingSummary
= true;
986 wfProfileOut( __METHOD__
);
987 return self
::AS_SUMMARY_NEEDED
;
991 # And a similar thing for new sections
992 if ( $this->section
== 'new' && !$this->allowBlankSummary
) {
993 if ( trim( $this->summary
) == '' ) {
994 $this->missingSummary
= true;
995 wfProfileOut( __METHOD__
);
996 return self
::AS_SUMMARY_NEEDED
;
1001 wfProfileIn( __METHOD__
. '-sectionanchor' );
1002 $sectionanchor = '';
1003 if ( $this->section
== 'new' ) {
1004 if ( $this->textbox1
== '' ) {
1005 $this->missingComment
= true;
1006 wfProfileOut( __METHOD__
. '-sectionanchor' );
1007 wfProfileOut( __METHOD__
);
1008 return self
::AS_TEXTBOX_EMPTY
;
1010 if ( $this->summary
!= '' ) {
1011 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $this->summary
);
1012 # This is a new section, so create a link to the new section
1013 # in the revision summary.
1014 $cleanSummary = $wgParser->stripSectionName( $this->summary
);
1015 $this->summary
= wfMsgForContent( 'newsectionsummary', $cleanSummary );
1017 } elseif ( $this->section
!= '' ) {
1018 # Try to get a section anchor from the section source, redirect to edited section if header found
1019 # XXX: might be better to integrate this into Article::replaceSection
1020 # for duplicate heading checking and maybe parsing
1021 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
1022 # we can't deal with anchors, includes, html etc in the header for now,
1023 # headline would need to be parsed to improve this
1024 if ( $hasmatch and strlen( $matches[2] ) > 0 ) {
1025 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $matches[2] );
1028 wfProfileOut( __METHOD__
. '-sectionanchor' );
1030 // Save errors may fall down to the edit form, but we've now
1031 // merged the section into full text. Clear the section field
1032 // so that later submission of conflict forms won't try to
1033 // replace that into a duplicated mess.
1034 $this->textbox1
= $text;
1035 $this->section
= '';
1037 // Check for length errors again now that the section is merged in
1038 $this->kblength
= (int)( strlen( $text ) / 1024 );
1039 if ( $this->kblength
> $wgMaxArticleSize ) {
1040 $this->tooBig
= true;
1041 wfProfileOut( __METHOD__
);
1042 return self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
;
1045 # update the article here
1046 if ( $this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
1047 $this->watchthis
, $bot, $sectionanchor ) )
1049 wfProfileOut( __METHOD__
);
1050 return self
::AS_SUCCESS_UPDATE
;
1052 $this->isConflict
= true;
1054 wfProfileOut( __METHOD__
);
1055 return self
::AS_END
;
1059 * Check if no edits were made by other users since
1060 * the time a user started editing the page. Limit to
1061 * 50 revisions for the sake of performance.
1063 protected function userWasLastToEdit( $id, $edittime ) {
1064 if( !$id ) return false;
1065 $dbw = wfGetDB( DB_MASTER
);
1066 $res = $dbw->select( 'revision',
1069 'rev_page' => $this->mArticle
->getId(),
1070 'rev_timestamp > '.$dbw->addQuotes( $dbw->timestamp($edittime) )
1073 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
1074 while( $row = $res->fetchObject() ) {
1075 if( $row->rev_user
!= $id ) {
1083 * Check given input text against $wgSpamRegex, and return the text of the first match.
1084 * @return mixed -- matching string or false
1086 public static function matchSpamRegex( $text ) {
1087 global $wgSpamRegex;
1088 // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
1089 $regexes = (array)$wgSpamRegex;
1090 return self
::matchSpamRegexInternal( $text, $regexes );
1094 * Check given input text against $wgSpamRegex, and return the text of the first match.
1095 * @return mixed -- matching string or false
1097 public static function matchSummarySpamRegex( $text ) {
1098 global $wgSummarySpamRegex;
1099 $regexes = (array)$wgSummarySpamRegex;
1100 return self
::matchSpamRegexInternal( $text, $regexes );
1103 protected static function matchSpamRegexInternal( $text, $regexes ) {
1104 foreach( $regexes as $regex ) {
1106 if( preg_match( $regex, $text, $matches ) ) {
1114 * Initialise form fields in the object
1115 * Called on the first invocation, e.g. when a user clicks an edit link
1116 * @returns bool -- if the requested section is valid
1118 function initialiseForm() {
1120 $this->edittime
= $this->mArticle
->getTimestamp();
1121 $this->textbox1
= $this->getContent( false );
1122 // activate checkboxes if user wants them to be always active
1123 # Sort out the "watch" checkbox
1124 if ( $wgUser->getOption( 'watchdefault' ) ) {
1126 $this->watchthis
= true;
1127 } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
1129 $this->watchthis
= true;
1130 } elseif ( $this->mTitle
->userIsWatching() ) {
1132 $this->watchthis
= true;
1134 if ( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
1135 if ( $this->textbox1
=== false ) return false;
1140 function setHeaders() {
1141 global $wgOut, $wgTitle;
1142 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1143 if ( $this->formtype
== 'preview' ) {
1144 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
1146 if ( $this->isConflict
) {
1147 $wgOut->setPageTitle( wfMsg( 'editconflict', $wgTitle->getPrefixedText() ) );
1148 } elseif ( $this->section
!= '' ) {
1149 $msg = $this->section
== 'new' ?
'editingcomment' : 'editingsection';
1150 $wgOut->setPageTitle( wfMsg( $msg, $wgTitle->getPrefixedText() ) );
1152 # Use the title defined by DISPLAYTITLE magic word when present
1153 if ( isset( $this->mParserOutput
)
1154 && ( $dt = $this->mParserOutput
->getDisplayTitle() ) !== false ) {
1157 $title = $wgTitle->getPrefixedText();
1159 $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
1164 * Send the edit form and related headers to $wgOut
1165 * @param $formCallback Optional callable that takes an OutputPage
1166 * parameter; will be called during form output
1167 * near the top, for captchas and the like.
1169 function showEditForm( $formCallback=null ) {
1170 global $wgOut, $wgUser, $wgTitle;
1172 # If $wgTitle is null, that means we're in API mode.
1173 # Some hook probably called this function without checking
1174 # for is_null($wgTitle) first. Bail out right here so we don't
1175 # do lots of work just to discard it right after.
1176 if ( is_null( $wgTitle ) )
1179 wfProfileIn( __METHOD__
);
1181 $sk = $wgUser->getSkin();
1183 #need to parse the preview early so that we know which templates are used,
1184 #otherwise users with "show preview after edit box" will get a blank list
1185 #we parse this near the beginning so that setHeaders can do the title
1186 #setting work instead of leaving it in getPreviewText
1187 $previewOutput = '';
1188 if ( $this->formtype
== 'preview' ) {
1189 $previewOutput = $this->getPreviewText();
1192 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) );
1194 $this->setHeaders();
1196 # Enabled article-related sidebar, toplinks, etc.
1197 $wgOut->setArticleRelated( true );
1199 if ( $this->showHeader() === false )
1202 $action = htmlspecialchars($this->getActionURL($wgTitle));
1204 if ( $wgUser->getOption( 'showtoolbar' ) and !$this->isCssJsSubpage
) {
1205 # prepare toolbar for edit buttons
1206 $toolbar = EditPage
::getEditToolbar();
1212 $wgOut->addHTML( $this->editFormPageTop
);
1214 if ( $wgUser->getOption( 'previewontop' ) ) {
1215 $this->displayPreviewArea( $previewOutput, true );
1218 $wgOut->addHTML( $this->editFormTextTop
);
1220 $templates = $this->getTemplates();
1221 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview
, $this->section
!= '');
1223 $hiddencats = $this->mArticle
->getHiddenCategories();
1224 $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
1226 if ( $this->wasDeletedSinceLastEdit() && 'save' != $this->formtype
) {
1227 $wgOut->wrapWikiMsg(
1228 "<div class='error mw-deleted-while-editing'>\n$1</div>",
1229 'deletedwhileediting' );
1230 } elseif ( $this->wasDeletedSinceLastEdit() ) {
1231 // Hide the toolbar and edit area, user can click preview to get it back
1232 // Add an confirmation checkbox and explanation.
1234 // @todo move this to a cleaner conditional instead of blanking a variable
1236 $wgOut->addHTML( <<<HTML
1238 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1242 if ( is_callable( $formCallback ) ) {
1243 call_user_func_array( $formCallback, array( &$wgOut ) );
1246 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1248 // Put these up at the top to ensure they aren't lost on early form submission
1249 $this->showFormBeforeText();
1251 if ( $this->wasDeletedSinceLastEdit() && 'save' == $this->formtype
) {
1253 '<div class="mw-confirm-recreate">' .
1254 $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete
->user_name
, $this->lastDelete
->log_comment
) ) .
1255 Xml
::checkLabel( wfMsg( 'recreate' ), 'wpRecreate', 'wpRecreate', false,
1256 array( 'title' => $sk->titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' )
1262 # If a blank edit summary was previously provided, and the appropriate
1263 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1264 # user being bounced back more than once in the event that a summary
1267 # For a bit more sophisticated detection of blank summaries, hash the
1268 # automatic one and pass that in the hidden field wpAutoSummary.
1269 if ( $this->missingSummary ||
1270 ( $this->section
== 'new' && $this->nosummary
) )
1271 $wgOut->addHTML( Xml
::hidden( 'wpIgnoreBlankSummary', true ) );
1272 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
1273 $wgOut->addHTML( Xml
::hidden( 'wpAutoSummary', $autosumm ) );
1275 $wgOut->addHTML( Xml
::hidden( 'oldid', $this->mArticle
->getOldID() ) );
1277 if ( $this->section
== 'new' ) {
1278 $this->showSummaryInput( true, $this->summary
);
1279 $wgOut->addHTML( $this->getSummaryPreview( true, $this->summary
) );
1282 $wgOut->addHTML( $this->editFormTextBeforeContent
);
1284 if ( $this->isConflict
) {
1285 // In an edit conflict bypass the overrideable content form method
1286 // and fallback to the raw wpTextbox1 since editconflicts can't be
1287 // resolved between page source edits and custom ui edits using the
1289 $this->showTextbox1();
1291 $this->showContentForm();
1294 $wgOut->addHTML( $this->editFormTextAfterContent
);
1296 $wgOut->addWikiText( $this->getCopywarn() );
1297 if ( isset($this->editFormTextAfterWarn
) && $this->editFormTextAfterWarn
!== '' )
1298 $wgOut->addHTML( $this->editFormTextAfterWarn
);
1300 $this->showStandardInputs();
1302 $this->showFormAfterText();
1304 $this->showTosSummary();
1305 $this->showEditTools();
1307 $wgOut->addHTML( <<<HTML
1308 {$this->editFormTextAfterTools}
1309 <div class='templatesUsed'>
1310 {$formattedtemplates}
1312 <div class='hiddencats'>
1313 {$formattedhiddencats}
1318 if ( $this->isConflict
)
1319 $this->showConflict();
1321 $wgOut->addHTML( $this->editFormTextBottom
);
1322 $wgOut->addHTML( "</form>\n" );
1323 if ( !$wgUser->getOption( 'previewontop' ) ) {
1324 $this->displayPreviewArea( $previewOutput, false );
1327 wfProfileOut( __METHOD__
);
1330 protected function showHeader() {
1331 global $wgOut, $wgUser, $wgTitle, $wgMaxArticleSize, $wgLang;
1332 if ( $this->isConflict
) {
1333 $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1</div>", 'explainconflict' );
1334 $this->edittime
= $this->mArticle
->getTimestamp();
1336 if ( $this->section
!= '' && !$this->isSectionEditSupported() ) {
1337 // We use $this->section to much before this and getVal('wgSection') directly in other places
1338 // at this point we can't reset $this->section to '' to fallback to non-section editing.
1339 // Someone is welcome to try refactoring though
1340 $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
1344 if ( $this->section
!= '' && $this->section
!= 'new' ) {
1346 if ( !$this->summary
&& !$this->preview
&& !$this->diff
) {
1347 preg_match( "/^(=+)(.+)\\1/mi", $this->textbox1
, $matches );
1348 if ( !empty( $matches[2] ) ) {
1350 $this->summary
= "/* " .
1351 $wgParser->stripSectionName(trim($matches[2])) .
1357 if ( $this->missingComment
) {
1358 $wgOut->wrapWikiMsg( "<div id='mw-missingcommenttext'>\n$1</div>", 'missingcommenttext' );
1361 if ( $this->missingSummary
&& $this->section
!= 'new' ) {
1362 $wgOut->wrapWikiMsg( "<div id='mw-missingsummary'>\n$1</div>", 'missingsummary' );
1365 if ( $this->missingSummary
&& $this->section
== 'new' ) {
1366 $wgOut->wrapWikiMsg( "<div id='mw-missingcommentheader'>\n$1</div>", 'missingcommentheader' );
1369 if ( $this->hookError
!== '' ) {
1370 $wgOut->addWikiText( $this->hookError
);
1373 if ( !$this->checkUnicodeCompliantBrowser() ) {
1374 $wgOut->addWikiMsg( 'nonunicodebrowser' );
1377 if ( isset( $this->mArticle
) && isset( $this->mArticle
->mRevision
) ) {
1378 // Let sysop know that this will make private content public if saved
1380 if ( !$this->mArticle
->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1381 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-permission' );
1382 } else if ( $this->mArticle
->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1383 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-view' );
1386 if ( !$this->mArticle
->mRevision
->isCurrent() ) {
1387 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
1388 $wgOut->addWikiMsg( 'editingold' );
1393 if ( wfReadOnly() ) {
1394 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
1395 } elseif ( $wgUser->isAnon() && $this->formtype
!= 'preview' ) {
1396 $wgOut->wrapWikiMsg( "<div id=\"mw-anon-edit-warning\">\n$1</div>", 'anoneditwarning' );
1398 if ( $this->isCssJsSubpage
) {
1399 # Check the skin exists
1400 if ( !$this->isValidCssJsSubpage
) {
1401 $wgOut->addWikiMsg( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() );
1403 if ( $this->formtype
!== 'preview' ) {
1404 if ( $this->isCssSubpage
)
1405 $wgOut->addWikiMsg( 'usercssyoucanpreview' );
1406 if ( $this->isJsSubpage
)
1407 $wgOut->addWikiMsg( 'userjsyoucanpreview' );
1412 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
1413 # Is the title semi-protected?
1414 if ( $this->mTitle
->isSemiProtected() ) {
1415 $noticeMsg = 'semiprotectedpagewarning';
1417 # Then it must be protected based on static groups (regular)
1418 $noticeMsg = 'protectedpagewarning';
1420 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
->getPrefixedText(), '',
1421 array( 'lim' => 1, 'msgKey' => array( $noticeMsg ) ) );
1423 if ( $this->mTitle
->isCascadeProtected() ) {
1424 # Is this page under cascading protection from some source pages?
1425 list($cascadeSources, /* $restrictions */) = $this->mTitle
->getCascadeProtectionSources();
1426 $notice = "<div class='mw-cascadeprotectedwarning'>\n$1\n";
1427 $cascadeSourcesCount = count( $cascadeSources );
1428 if ( $cascadeSourcesCount > 0 ) {
1429 # Explain, and list the titles responsible
1430 foreach( $cascadeSources as $page ) {
1431 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1434 $notice .= '</div>';
1435 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', $cascadeSourcesCount ) );
1437 if ( !$this->mTitle
->exists() && $this->mTitle
->getRestrictions( 'create' ) ) {
1438 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
->getPrefixedText(), '',
1440 'showIfEmpty' => false,
1441 'msgKey' => array( 'titleprotectedwarning' ),
1442 'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ) );
1445 if ( $this->kblength
=== false ) {
1446 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
1449 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
1450 $wgOut->addHTML( "<div class='error' id='mw-edit-longpageerror'>\n" );
1451 $wgOut->addWikiMsg( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgLang->formatNum( $wgMaxArticleSize ) );
1452 $wgOut->addHTML( "</div>\n" );
1453 } elseif ( $this->kblength
> 29 ) {
1454 $wgOut->addHTML( "<div id='mw-edit-longpagewarning'>\n" );
1455 $wgOut->addWikiMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength
) );
1456 $wgOut->addHTML( "</div>\n" );
1461 * Standard summary input and label (wgSummary), abstracted so EditPage
1462 * subclasses may reorganize the form.
1463 * Note that you do not need to worry about the label's for=, it will be
1464 * inferred by the id given to the input. You can remove them both by
1465 * passing array( 'id' => false ) to $userInputAttrs.
1467 * @param $summary The value of the summary input
1468 * @param $labelText The html to place inside the label
1469 * @param $userInputAttrs An array of attrs to use on the input
1470 * @param $userSpanAttrs An array of attrs to use on the span inside the label
1472 * @return array An array in the format array( $label, $input )
1474 function getSummaryInput($summary = "", $labelText = null, $inputAttrs = null, $spanLabelAttrs = null) {
1475 $inputAttrs = ( is_array($inputAttrs) ?
$inputAttrs : array() ) +
array(
1476 'id' => 'wpSummary',
1477 'maxlength' => '200',
1480 'spellcheck' => 'true',
1483 $spanLabelAttrs = ( is_array($spanLabelAttrs) ?
$spanLabelAttrs : array() ) +
array(
1484 'class' => $this->missingSummary ?
'mw-summarymissed' : 'mw-summary',
1485 'id' => "wpSummaryLabel"
1490 $label = Xml
::tags( 'label', $inputAttrs['id'] ?
array( 'for' => $inputAttrs['id'] ) : null, $labelText );
1491 $label = Xml
::tags( 'span', $spanLabelAttrs, $label );
1494 $input = Html
::input( 'wpSummary', $summary, 'text', $inputAttrs );
1496 return array( $label, $input );
1500 * @param bool $isSubjectPreview true if this is the section subject/title
1501 * up top, or false if this is the comment
1502 * summary down below the textarea
1503 * @param string $summary The text of the summary to display
1506 protected function showSummaryInput( $isSubjectPreview, $summary = "" ) {
1507 global $wgOut, $wgContLang;
1508 # Add a class if 'missingsummary' is triggered to allow styling of the summary line
1509 $summaryClass = $this->missingSummary ?
'mw-summarymissed' : 'mw-summary';
1510 if ( $isSubjectPreview ) {
1511 if ( $this->nosummary
)
1514 if ( !$this->mShowSummaryField
)
1517 $summary = $wgContLang->recodeForEdit( $summary );
1518 $labelText = wfMsgExt( $isSubjectPreview ?
'subject' : 'summary', 'parseinline' );
1519 list($label, $input) = $this->getSummaryInput($summary, $labelText, array( 'class' => $summaryClass ), array());
1520 $wgOut->addHTML("{$label} {$input}");
1524 * @param bool $isSubjectPreview true if this is the section subject/title
1525 * up top, or false if this is the comment
1526 * summary down below the textarea
1527 * @param string $summary The text of the summary to display
1530 protected function getSummaryPreview( $isSubjectPreview, $summary = "" ) {
1531 if ( !$summary ||
( !$this->preview
&& !$this->diff
) )
1534 global $wgParser, $wgUser;
1535 $sk = $wgUser->getSkin();
1537 if ( $isSubjectPreview )
1538 $summary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $summary ) );
1540 $summary = wfMsgExt( 'subject-preview', 'parseinline' ) . $sk->commentBlock( $summary, $this->mTitle
, !!$isSubjectPreview );
1541 return Xml
::tags( 'div', array( 'class' => 'mw-summary-preview' ), $summary );
1544 protected function showFormBeforeText() {
1546 $section = htmlspecialchars( $this->section
);
1547 $wgOut->addHTML( <<<INPUTS
1548 <input type='hidden' value="{$section}" name="wpSection" />
1549 <input type='hidden' value="{$this->starttime}" name="wpStarttime" />
1550 <input type='hidden' value="{$this->edittime}" name="wpEdittime" />
1551 <input type='hidden' value="{$this->scrolltop}" name="wpScrolltop" id="wpScrolltop" />
1555 if ( !$this->checkUnicodeCompliantBrowser() )
1556 $wgOut->addHTML(Xml
::hidden( 'safemode', '1' ));
1559 protected function showFormAfterText() {
1560 global $wgOut, $wgUser;
1562 * To make it harder for someone to slip a user a page
1563 * which submits an edit form to the wiki without their
1564 * knowledge, a random token is associated with the login
1565 * session. If it's not passed back with the submission,
1566 * we won't save the page, or render user JavaScript and
1569 * For anon editors, who may not have a session, we just
1570 * include the constant suffix to prevent editing from
1571 * broken text-mangling proxies.
1573 $wgOut->addHTML( "\n" . Xml
::hidden( "wpEditToken", $wgUser->editToken() ) . "\n" );
1577 * Subpage overridable method for printing the form for page content editing
1578 * By default this simply outputs wpTextbox1
1579 * Subclasses can override this to provide a custom UI for editing;
1580 * be it a form, or simply wpTextbox1 with a modified content that will be
1581 * reverse modified when extracted from the post data.
1582 * Note that this is basically the inverse for importContentFormData
1584 * @praram WebRequest $request
1586 protected function showContentForm() {
1587 $this->showTextbox1();
1591 * Method to output wpTextbox1
1592 * The $textoverride method can be used by subclasses overriding showContentForm
1593 * to pass back to this method.
1595 * @param array $customAttribs An array of html attributes to use in the textarea
1596 * @param string $textoverride Optional text to override $this->textarea1 with
1598 protected function showTextbox1($customAttribs = null, $textoverride = null) {
1599 $classes = array(); // Textarea CSS
1600 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
1601 # Is the title semi-protected?
1602 if ( $this->mTitle
->isSemiProtected() ) {
1603 $classes[] = 'mw-textarea-sprotected';
1605 # Then it must be protected based on static groups (regular)
1606 $classes[] = 'mw-textarea-protected';
1609 $attribs = array( 'tabindex' => 1 );
1610 if ( is_array($customAttribs) )
1611 $attribs +
= $customAttribs;
1613 if ( $this->wasDeletedSinceLastEdit() )
1614 $attribs['type'] = 'hidden';
1615 if ( !empty( $classes ) ) {
1616 if ( isset($attribs['class']) )
1617 $classes[] = $attribs['class'];
1618 $attribs['class'] = implode( ' ', $classes );
1621 $this->showTextbox( isset($textoverride) ?
$textoverride : $this->textbox1
, 'wpTextbox1', $attribs );
1624 protected function showTextbox2() {
1625 $this->showTextbox( $this->textbox2
, 'wpTextbox2', array( 'tabindex' => 6 ) );
1628 protected function showTextbox( $content, $name, $customAttribs = array() ) {
1629 global $wgOut, $wgUser;
1631 $wikitext = $this->safeUnicodeOutput( $content );
1632 if ( $wikitext !== '' ) {
1633 // Ensure there's a newline at the end, otherwise adding lines
1635 // But don't add a newline if the ext is empty, or Firefox in XHTML
1636 // mode will show an extra newline. A bit annoying.
1640 $attribs = $customAttribs +
array(
1643 'cols' => $wgUser->getIntOption( 'cols' ),
1644 'rows' => $wgUser->getIntOption( 'rows' ),
1645 'style' => '' // avoid php notices when appending for editwidth preference (appending allows customAttribs['style'] to still work
1648 if ( $wgUser->getOption( 'editwidth' ) )
1649 $attribs['style'] .= 'width: 100%';
1651 $wgOut->addHTML( Html
::textarea( $name, $wikitext, $attribs ) );
1654 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
1658 $classes[] = 'ontop';
1660 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
1662 if ( $this->formtype
!= 'preview' )
1663 $attribs['style'] = 'display: none;';
1665 $wgOut->addHTML( Xml
::openElement( 'div', $attribs ) );
1667 if ( $this->formtype
== 'preview' ) {
1668 $this->showPreview( $previewOutput );
1671 $wgOut->addHTML( '</div>' );
1673 if ( $this->formtype
== 'diff') {
1679 * Append preview output to $wgOut.
1680 * Includes category rendering if this is a category page.
1682 * @param string $text The HTML to be output for the preview.
1684 protected function showPreview( $text ) {
1686 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1687 $this->mArticle
->openShowCategory();
1689 # This hook seems slightly odd here, but makes things more
1690 # consistent for extensions.
1691 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1692 $wgOut->addHTML( $text );
1693 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1694 $this->mArticle
->closeShowCategory();
1698 protected function showTosSummary() {
1699 $msg = 'editpage-tos-summary';
1700 // Give a chance for site and per-namespace customizations of
1701 // terms of service summary link that might exist separately
1702 // from the copyright notice.
1704 // This will display between the save button and the edit tools,
1705 // so should remain short!
1706 wfRunHooks( 'EditPageTosSummary', array( $this->mTitle
, &$msg ) );
1707 $text = wfMsg( $msg );
1708 if( !wfEmptyMsg( $msg, $text ) && $text !== '-' ) {
1710 $wgOut->addHTML( '<div class="mw-tos-summary">' );
1711 $wgOut->addWikiMsgArray( $msg, array() );
1712 $wgOut->addHTML( '</div>' );
1716 protected function showEditTools() {
1718 $wgOut->addHTML( '<div class="mw-editTools">' );
1719 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
1720 $wgOut->addHTML( '</div>' );
1723 protected function getCopywarn() {
1724 global $wgRightsText;
1725 if ( $wgRightsText ) {
1726 $copywarnMsg = array( 'copyrightwarning',
1727 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1730 $copywarnMsg = array( 'copyrightwarning2',
1731 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
1733 // Allow for site and per-namespace customization of contribution/copyright notice.
1734 wfRunHooks( 'EditPageCopyrightWarning', array( $this->mTitle
, &$copywarnMsg ) );
1736 return "<div id=\"editpage-copywarn\">\n" . call_user_func_array("wfMsgNoTrans", $copywarnMsg) . "\n</div>";
1739 protected function showStandardInputs( &$tabindex = 2 ) {
1740 global $wgOut, $wgUser;
1741 $wgOut->addHTML( "<div class='editOptions'>\n" );
1743 if ( $this->section
!= 'new' ) {
1744 $this->showSummaryInput( false, $this->summary
);
1745 $wgOut->addHTML( $this->getSummaryPreview( false, $this->summary
) );
1748 $checkboxes = $this->getCheckboxes( $tabindex, $wgUser->getSkin(),
1749 array( 'minor' => $this->minoredit
, 'watch' => $this->watchthis
) );
1750 $wgOut->addHTML( "<div class='editCheckboxes'>" . implode( $checkboxes, "\n" ) . "</div>\n" );
1751 $wgOut->addHTML( "<div class='editButtons'>\n" );
1752 $wgOut->addHTML( implode( $this->getEditButtons( $tabindex ), "\n" ) . "\n" );
1754 $cancel = $this->getCancelLink();
1755 $separator = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1756 $edithelpurl = Skin
::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ) );
1757 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1758 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1759 htmlspecialchars( wfMsg( 'newwindow' ) );
1760 $wgOut->addHTML( " <span class='editHelp'>{$cancel}{$separator}{$edithelp}</span>\n" );
1761 $wgOut->addHTML( "</div><!-- editButtons -->\n</div><!-- editOptions -->\n" );
1764 protected function showConflict() {
1766 $this->textbox2
= $this->textbox1
;
1767 $this->textbox1
= $this->getContent();
1768 if ( wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
1769 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
1771 $de = new DifferenceEngine( $this->mTitle
);
1772 $de->setText( $this->textbox2
, $this->textbox1
);
1773 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1775 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
1776 $this->showTextbox2();
1780 protected function getLastDelete() {
1781 $dbr = wfGetDB( DB_SLAVE
);
1782 $data = $dbr->selectRow(
1783 array( 'logging', 'user' ),
1794 array( 'log_namespace' => $this->mTitle
->getNamespace(),
1795 'log_title' => $this->mTitle
->getDBkey(),
1796 'log_type' => 'delete',
1797 'log_action' => 'delete',
1798 'user_id=log_user' ),
1800 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' )
1802 // Quick paranoid permission checks...
1803 if( is_object( $data ) ) {
1804 if( $data->log_deleted
& LogPage
::DELETED_USER
)
1805 $data->user_name
= wfMsgHtml( 'rev-deleted-user' );
1806 if( $data->log_deleted
& LogPage
::DELETED_COMMENT
)
1807 $data->log_comment
= wfMsgHtml( 'rev-deleted-comment' );
1813 * Get the rendered text for previewing.
1816 function getPreviewText() {
1817 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang, $wgMessageCache;
1819 wfProfileIn( __METHOD__
);
1821 if ( $this->mTriedSave
&& !$this->mTokenOk
) {
1822 if ( $this->mTokenOkExceptSuffix
) {
1823 $note = wfMsg( 'token_suffix_mismatch' );
1825 $note = wfMsg( 'session_fail_preview' );
1828 $note = wfMsg( 'previewnote' );
1831 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1832 $parserOptions->setEditSection( false );
1833 $parserOptions->setIsPreview( true );
1834 $parserOptions->setIsSectionPreview( !is_null($this->section
) && $this->section
!== '' );
1837 if ( $wgRawHtml && !$this->mTokenOk
) {
1838 // Could be an offsite preview attempt. This is very unsafe if
1839 // HTML is enabled, as it could be an attack.
1840 return $wgOut->parse( "<div class='previewnote'>" .
1841 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1844 # don't parse user css/js, show message about preview
1845 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1847 if ( $this->isCssJsSubpage
) {
1848 if (preg_match( "/\\.css$/", $this->mTitle
->getText() ) ) {
1849 $previewtext = wfMsg( 'usercsspreview' );
1850 } else if (preg_match( "/\\.js$/", $this->mTitle
->getText() ) ) {
1851 $previewtext = wfMsg( 'userjspreview' );
1853 $parserOptions->setTidy( true );
1854 $parserOutput = $wgParser->parse( $previewtext, $this->mTitle
, $parserOptions );
1855 $previewHTML = $parserOutput->mText
;
1856 } elseif ( $rt = Title
::newFromRedirectArray( $this->textbox1
) ) {
1857 $previewHTML = $this->mArticle
->viewRedirect( $rt, false );
1859 $toparse = $this->textbox1
;
1861 # If we're adding a comment, we need to show the
1862 # summary as the headline
1863 if ( $this->section
== "new" && $this->summary
!= "" ) {
1864 $toparse = "== {$this->summary} ==\n\n" . $toparse;
1867 wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
1869 // Parse mediawiki messages with correct target language
1870 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
1871 list( /* $unused */, $lang ) = $wgMessageCache->figureMessage( $this->mTitle
->getText() );
1872 $obj = wfGetLangObj( $lang );
1873 $parserOptions->setTargetLanguage( $obj );
1877 $parserOptions->setTidy( true );
1878 $parserOptions->enableLimitReport();
1879 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ),
1880 $this->mTitle
, $parserOptions );
1882 $previewHTML = $parserOutput->getText();
1883 $this->mParserOutput
= $parserOutput;
1884 $wgOut->addParserOutputNoText( $parserOutput );
1886 if ( count( $parserOutput->getWarnings() ) ) {
1887 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
1891 if( $this->isConflict
) {
1892 $conflict = '<h2 id="mw-previewconflict">' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1894 $conflict = '<hr />';
1897 $previewhead = "<div class='previewnote'>\n" .
1898 '<h2 id="mw-previewheader">' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>" .
1899 $wgOut->parse( $note ) . $conflict . "</div>\n";
1901 wfProfileOut( __METHOD__
);
1902 return $previewhead . $previewHTML . $this->previewTextAfterContent
;
1905 function getTemplates() {
1906 if ( $this->preview ||
$this->section
!= '' ) {
1907 $templates = array();
1908 if ( !isset( $this->mParserOutput
) ) return $templates;
1909 foreach( $this->mParserOutput
->getTemplates() as $ns => $template) {
1910 foreach( array_keys( $template ) as $dbk ) {
1911 $templates[] = Title
::makeTitle($ns, $dbk);
1916 return $this->mArticle
->getUsedTemplates();
1921 * Call the stock "user is blocked" page
1923 function blockedPage() {
1925 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
1927 # If the user made changes, preserve them when showing the markup
1928 # (This happens when a user is blocked during edit, for instance)
1929 $first = $this->firsttime ||
( !$this->save
&& $this->textbox1
== '' );
1931 $source = $this->mTitle
->exists() ?
$this->getContent() : false;
1933 $source = $this->textbox1
;
1936 # Spit out the source or the user's modified version
1937 if ( $source !== false ) {
1938 $wgOut->addHTML( '<hr />' );
1939 $wgOut->addWikiMsg( $first ?
'blockedoriginalsource' : 'blockededitsource', $this->mTitle
->getPrefixedText() );
1940 $this->showTextbox1( array( 'readonly' ), $source );
1945 * Produce the stock "please login to edit pages" page
1947 function userNotLoggedInPage() {
1948 global $wgUser, $wgOut, $wgTitle;
1949 $skin = $wgUser->getSkin();
1951 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1952 $loginLink = $skin->link(
1954 wfMsgHtml( 'loginreqlink' ),
1956 array( 'returnto' => $wgTitle->getPrefixedText() ),
1957 array( 'known', 'noclasses' )
1960 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1961 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1962 $wgOut->setArticleRelated( false );
1964 $wgOut->addHTML( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1965 $wgOut->returnToMain( false, $wgTitle );
1969 * Creates a basic error page which informs the user that
1970 * they have attempted to edit a nonexistent section.
1972 function noSuchSectionPage() {
1975 $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
1976 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1977 $wgOut->setArticleRelated( false );
1979 $res = wfMsgExt( 'nosuchsectiontext', 'parse', $this->section
);
1980 wfRunHooks( 'EditPageNoSuchSection', array( &$this, &$res ) );
1981 $wgOut->addHTML( $res );
1983 $wgOut->returnToMain( false, $this->mTitle
);
1987 * Produce the stock "your edit contains spam" page
1989 * @param $match Text which triggered one or more filters
1991 function spamPage( $match = false ) {
1992 global $wgOut, $wgTitle;
1994 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1995 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1996 $wgOut->setArticleRelated( false );
1998 $wgOut->addHTML( '<div id="spamprotected">' );
1999 $wgOut->addWikiMsg( 'spamprotectiontext' );
2001 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
2002 $wgOut->addHTML( '</div>' );
2004 $wgOut->returnToMain( false, $wgTitle );
2011 function mergeChangesInto( &$editText ){
2012 wfProfileIn( __METHOD__
);
2014 $db = wfGetDB( DB_MASTER
);
2016 // This is the revision the editor started from
2017 $baseRevision = $this->getBaseRevision();
2018 if ( is_null( $baseRevision ) ) {
2019 wfProfileOut( __METHOD__
);
2022 $baseText = $baseRevision->getText();
2024 // The current state, we want to merge updates into it
2025 $currentRevision = Revision
::loadFromTitle( $db, $this->mTitle
);
2026 if ( is_null( $currentRevision ) ) {
2027 wfProfileOut( __METHOD__
);
2030 $currentText = $currentRevision->getText();
2033 if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
2034 $editText = $result;
2035 wfProfileOut( __METHOD__
);
2038 wfProfileOut( __METHOD__
);
2044 * Check if the browser is on a blacklist of user-agents known to
2045 * mangle UTF-8 data on form submission. Returns true if Unicode
2046 * should make it through, false if it's known to be a problem.
2050 function checkUnicodeCompliantBrowser() {
2051 global $wgBrowserBlackList;
2052 if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
2053 // No User-Agent header sent? Trust it by default...
2056 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
2057 foreach ( $wgBrowserBlackList as $browser ) {
2058 if ( preg_match($browser, $currentbrowser) ) {
2066 * @deprecated use $wgParser->stripSectionName()
2068 function pseudoParseSectionAnchor( $text ) {
2070 return $wgParser->stripSectionName( $text );
2074 * Format an anchor fragment as it would appear for a given section name
2075 * @param string $text
2079 function sectionAnchor( $text ) {
2081 return $wgParser->guessSectionNameFromWikiText( $text );
2085 * Shows a bulletin board style toolbar for common editing functions.
2086 * It can be disabled in the user preferences.
2087 * The necessary JavaScript code can be found in skins/common/edit.js.
2091 static function getEditToolbar() {
2092 global $wgStylePath, $wgContLang, $wgLang;
2096 * toolarray an array of arrays which each include the filename of
2097 * the button image (without path), the opening tag, the closing tag,
2098 * and optionally a sample text that is inserted between the two when no
2099 * selection is highlighted.
2100 * The tip text is shown when the user moves the mouse over the button.
2102 * Already here are accesskeys (key), which are not used yet until someone
2103 * can figure out a way to make them work in IE. However, we should make
2104 * sure these keys are not defined on the edit page.
2108 'image' => $wgLang->getImageFile( 'button-bold' ),
2109 'id' => 'mw-editbutton-bold',
2111 'close' => '\'\'\'',
2112 'sample' => wfMsg( 'bold_sample' ),
2113 'tip' => wfMsg( 'bold_tip' ),
2117 'image' => $wgLang->getImageFile( 'button-italic' ),
2118 'id' => 'mw-editbutton-italic',
2121 'sample' => wfMsg( 'italic_sample' ),
2122 'tip' => wfMsg( 'italic_tip' ),
2126 'image' => $wgLang->getImageFile( 'button-link' ),
2127 'id' => 'mw-editbutton-link',
2130 'sample' => wfMsg( 'link_sample' ),
2131 'tip' => wfMsg( 'link_tip' ),
2135 'image' => $wgLang->getImageFile( 'button-extlink' ),
2136 'id' => 'mw-editbutton-extlink',
2139 'sample' => wfMsg( 'extlink_sample' ),
2140 'tip' => wfMsg( 'extlink_tip' ),
2144 'image' => $wgLang->getImageFile( 'button-headline' ),
2145 'id' => 'mw-editbutton-headline',
2148 'sample' => wfMsg( 'headline_sample' ),
2149 'tip' => wfMsg( 'headline_tip' ),
2153 'image' => $wgLang->getImageFile( 'button-image' ),
2154 'id' => 'mw-editbutton-image',
2155 'open' => '[[' . $wgContLang->getNsText( NS_FILE
) . ':',
2157 'sample' => wfMsg( 'image_sample' ),
2158 'tip' => wfMsg( 'image_tip' ),
2162 'image' => $wgLang->getImageFile( 'button-media' ),
2163 'id' => 'mw-editbutton-media',
2164 'open' => '[[' . $wgContLang->getNsText( NS_MEDIA
) . ':',
2166 'sample' => wfMsg( 'media_sample' ),
2167 'tip' => wfMsg( 'media_tip' ),
2171 'image' => $wgLang->getImageFile( 'button-math' ),
2172 'id' => 'mw-editbutton-math',
2174 'close' => "</math>",
2175 'sample' => wfMsg( 'math_sample' ),
2176 'tip' => wfMsg( 'math_tip' ),
2180 'image' => $wgLang->getImageFile( 'button-nowiki' ),
2181 'id' => 'mw-editbutton-nowiki',
2182 'open' => "<nowiki>",
2183 'close' => "</nowiki>",
2184 'sample' => wfMsg( 'nowiki_sample' ),
2185 'tip' => wfMsg( 'nowiki_tip' ),
2189 'image' => $wgLang->getImageFile( 'button-sig' ),
2190 'id' => 'mw-editbutton-signature',
2194 'tip' => wfMsg( 'sig_tip' ),
2198 'image' => $wgLang->getImageFile( 'button-hr' ),
2199 'id' => 'mw-editbutton-hr',
2200 'open' => "\n----\n",
2203 'tip' => wfMsg( 'hr_tip' ),
2207 $toolbar = "<div id='toolbar'>\n";
2210 foreach ( $toolarray as $tool ) {
2212 $image = $wgStylePath . '/common/images/' . $tool['image'],
2213 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2214 // Older browsers show a "speedtip" type message only for ALT.
2215 // Ideally these should be different, realistically they
2216 // probably don't need to be.
2217 $tip = $tool['tip'],
2218 $open = $tool['open'],
2219 $close = $tool['close'],
2220 $sample = $tool['sample'],
2221 $cssId = $tool['id'],
2224 $paramList = implode( ',',
2225 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
2226 $script .= "addButton($paramList);\n";
2228 $toolbar .= Html
::inlineScript( "\n$script\n" );
2230 $toolbar .= "\n</div>";
2232 wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
2238 * Returns an array of html code of the following checkboxes:
2241 * @param $tabindex Current tabindex
2242 * @param $skin Skin object
2243 * @param $checked Array of checkbox => bool, where bool indicates the checked
2244 * status of the checkbox
2248 public function getCheckboxes( &$tabindex, $skin, $checked ) {
2251 $checkboxes = array();
2253 $checkboxes['minor'] = '';
2254 $minorLabel = wfMsgExt( 'minoredit', array( 'parseinline' ) );
2255 if ( $wgUser->isAllowed( 'minoredit' ) ) {
2257 'tabindex' => ++
$tabindex,
2258 'accesskey' => wfMsg( 'accesskey-minoredit' ),
2259 'id' => 'wpMinoredit',
2261 $checkboxes['minor'] =
2262 Xml
::check( 'wpMinoredit', $checked['minor'], $attribs ) .
2263 " <label for='wpMinoredit'" . $skin->tooltip( 'minoredit', 'withaccess' ) . ">{$minorLabel}</label>";
2266 $watchLabel = wfMsgExt( 'watchthis', array( 'parseinline' ) );
2267 $checkboxes['watch'] = '';
2268 if ( $wgUser->isLoggedIn() ) {
2270 'tabindex' => ++
$tabindex,
2271 'accesskey' => wfMsg( 'accesskey-watch' ),
2272 'id' => 'wpWatchthis',
2274 $checkboxes['watch'] =
2275 Xml
::check( 'wpWatchthis', $checked['watch'], $attribs ) .
2276 " <label for='wpWatchthis'" . $skin->tooltip( 'watch', 'withaccess' ) . ">{$watchLabel}</label>";
2278 wfRunHooks( 'EditPageBeforeEditChecks', array( &$this, &$checkboxes, &$tabindex ) );
2283 * Returns an array of html code of the following buttons:
2284 * save, diff, preview and live
2286 * @param $tabindex Current tabindex
2290 public function getEditButtons(&$tabindex) {
2297 'tabindex' => ++
$tabindex,
2298 'value' => wfMsg( 'savearticle' ),
2299 'accesskey' => wfMsg( 'accesskey-save' ),
2300 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
2302 $buttons['save'] = Xml
::element('input', $temp, '');
2304 ++
$tabindex; // use the same for preview and live preview
2306 'id' => 'wpPreview',
2307 'name' => 'wpPreview',
2309 'tabindex' => $tabindex,
2310 'value' => wfMsg( 'showpreview' ),
2311 'accesskey' => wfMsg( 'accesskey-preview' ),
2312 'title' => wfMsg( 'tooltip-preview' ) . ' [' . wfMsg( 'accesskey-preview' ) . ']',
2314 $buttons['preview'] = Xml
::element( 'input', $temp, '' );
2315 $buttons['live'] = '';
2321 'tabindex' => ++
$tabindex,
2322 'value' => wfMsg( 'showdiff' ),
2323 'accesskey' => wfMsg( 'accesskey-diff' ),
2324 'title' => wfMsg( 'tooltip-diff' ) . ' [' . wfMsg( 'accesskey-diff' ) . ']',
2326 $buttons['diff'] = Xml
::element( 'input', $temp, '' );
2328 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
2333 * Output preview text only. This can be sucked into the edit page
2334 * via JavaScript, and saves the server time rendering the skin as
2335 * well as theoretically being more robust on the client (doesn't
2336 * disturb the edit box's undo history, won't eat your text on
2339 * @todo This doesn't include category or interlanguage links.
2340 * Would need to enhance it a bit, <s>maybe wrap them in XML
2341 * or something...</s> that might also require more skin
2342 * initialization, so check whether that's a problem.
2344 function livePreview() {
2347 header( 'Content-type: text/xml; charset=utf-8' );
2348 header( 'Cache-control: no-cache' );
2350 $previewText = $this->getPreviewText();
2351 #$categories = $skin->getCategoryLinks();
2354 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2355 Xml
::tags( 'livepreview', null,
2356 Xml
::element( 'preview', null, $previewText )
2357 #. Xml::element( 'category', null, $categories )
2363 public function getCancelLink() {
2364 global $wgUser, $wgTitle;
2366 $cancelParams = array();
2367 if ( !$this->isConflict
&& $this->mArticle
->getOldID() > 0 ) {
2368 $cancelParams['oldid'] = $this->mArticle
->getOldID();
2371 return $wgUser->getSkin()->link(
2373 wfMsgExt( 'cancel', array( 'parseinline' ) ),
2374 array( 'id' => 'mw-editform-cancel' ),
2376 array( 'known', 'noclasses' )
2381 * Get a diff between the current contents of the edit box and the
2382 * version of the page we're editing from.
2384 * If this is a section edit, we'll replace the section as for final
2385 * save and then make a comparison.
2387 function showDiff() {
2388 $oldtext = $this->mArticle
->fetchContent();
2389 $newtext = $this->mArticle
->replaceSection(
2390 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
2392 wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
2394 $newtext = $this->mArticle
->preSaveTransform( $newtext );
2395 $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
2396 $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
2397 if ( $oldtext !== false ||
$newtext != '' ) {
2398 $de = new DifferenceEngine( $this->mTitle
);
2399 $de->setText( $oldtext, $newtext );
2400 $difftext = $de->getDiff( $oldtitle, $newtitle );
2401 $de->showDiffStyle();
2407 $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
2411 * Filter an input field through a Unicode de-armoring process if it
2412 * came from an old browser with known broken Unicode editing issues.
2414 * @param WebRequest $request
2415 * @param string $field
2419 function safeUnicodeInput( $request, $field ) {
2420 $text = rtrim( $request->getText( $field ) );
2421 return $request->getBool( 'safemode' )
2422 ?
$this->unmakesafe( $text )
2426 function safeUnicodeText( $request, $text ) {
2427 $text = rtrim( $text );
2428 return $request->getBool( 'safemode' )
2429 ?
$this->unmakesafe( $text )
2434 * Filter an output field through a Unicode armoring process if it is
2435 * going to an old browser with known broken Unicode editing issues.
2437 * @param string $text
2441 function safeUnicodeOutput( $text ) {
2443 $codedText = $wgContLang->recodeForEdit( $text );
2444 return $this->checkUnicodeCompliantBrowser()
2446 : $this->makesafe( $codedText );
2450 * A number of web browsers are known to corrupt non-ASCII characters
2451 * in a UTF-8 text editing environment. To protect against this,
2452 * detected browsers will be served an armored version of the text,
2453 * with non-ASCII chars converted to numeric HTML character references.
2455 * Preexisting such character references will have a 0 added to them
2456 * to ensure that round-trips do not alter the original data.
2458 * @param string $invalue
2462 function makesafe( $invalue ) {
2463 // Armor existing references for reversability.
2464 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
2469 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2470 $bytevalue = ord( $invalue{$i} );
2471 if ( $bytevalue <= 0x7F ) { //0xxx xxxx
2472 $result .= chr( $bytevalue );
2474 } elseif ( $bytevalue <= 0xBF ) { //10xx xxxx
2475 $working = $working << 6;
2476 $working +
= ($bytevalue & 0x3F);
2478 if ( $bytesleft <= 0 ) {
2479 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2481 } elseif ( $bytevalue <= 0xDF ) { //110x xxxx
2482 $working = $bytevalue & 0x1F;
2484 } elseif ( $bytevalue <= 0xEF ) { //1110 xxxx
2485 $working = $bytevalue & 0x0F;
2487 } else { //1111 0xxx
2488 $working = $bytevalue & 0x07;
2496 * Reverse the previously applied transliteration of non-ASCII characters
2497 * back to UTF-8. Used to protect data from corruption by broken web browsers
2498 * as listed in $wgBrowserBlackList.
2500 * @param string $invalue
2504 function unmakesafe( $invalue ) {
2506 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2507 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+
3} != '0' ) ) {
2511 $hexstring .= $invalue{$i};
2513 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
2515 // Do some sanity checks. These aren't needed for reversability,
2516 // but should help keep the breakage down if the editor
2517 // breaks one of the entities whilst editing.
2518 if ( (substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6) ) {
2519 $codepoint = hexdec($hexstring);
2520 $result .= codepointToUtf8( $codepoint );
2522 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2525 $result .= substr( $invalue, $i, 1 );
2528 // reverse the transform that we made for reversability reasons.
2529 return strtr( $result, array( "�" => "&#x" ) );
2532 function noCreatePermission() {
2534 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
2535 $wgOut->addWikiMsg( 'nocreatetext' );
2539 * Attempt submission
2540 * @return bool false if output is done, true if the rest of the form should be displayed
2542 function attemptSave() {
2543 global $wgUser, $wgOut, $wgTitle;
2545 $resultDetails = false;
2546 # Allow bots to exempt some edits from bot flagging
2547 $bot = $wgUser->isAllowed( 'bot' ) && $this->bot
;
2548 $value = $this->internalAttemptSave( $resultDetails, $bot );
2550 if ( $value == self
::AS_SUCCESS_UPDATE ||
$value == self
::AS_SUCCESS_NEW_ARTICLE
) {
2551 $this->didSave
= true;
2555 case self
::AS_HOOK_ERROR_EXPECTED
:
2556 case self
::AS_CONTENT_TOO_BIG
:
2557 case self
::AS_ARTICLE_WAS_DELETED
:
2558 case self
::AS_CONFLICT_DETECTED
:
2559 case self
::AS_SUMMARY_NEEDED
:
2560 case self
::AS_TEXTBOX_EMPTY
:
2561 case self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
:
2565 case self
::AS_HOOK_ERROR
:
2566 case self
::AS_FILTERING
:
2567 case self
::AS_SUCCESS_NEW_ARTICLE
:
2568 case self
::AS_SUCCESS_UPDATE
:
2571 case self
::AS_SPAM_ERROR
:
2572 $this->spamPage( $resultDetails['spam'] );
2575 case self
::AS_BLOCKED_PAGE_FOR_USER
:
2576 $this->blockedPage();
2579 case self
::AS_IMAGE_REDIRECT_ANON
:
2580 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2583 case self
::AS_READ_ONLY_PAGE_ANON
:
2584 $this->userNotLoggedInPage();
2587 case self
::AS_READ_ONLY_PAGE_LOGGED
:
2588 case self
::AS_READ_ONLY_PAGE
:
2589 $wgOut->readOnlyPage();
2592 case self
::AS_RATE_LIMITED
:
2593 $wgOut->rateLimited();
2596 case self
::AS_NO_CREATE_PERMISSION
:
2597 $this->noCreatePermission();
2600 case self
::AS_BLANK_ARTICLE
:
2601 $wgOut->redirect( $wgTitle->getFullURL() );
2604 case self
::AS_IMAGE_REDIRECT_LOGGED
:
2605 $wgOut->permissionRequired( 'upload' );
2610 function getBaseRevision() {
2611 if ( $this->mBaseRevision
== false ) {
2612 $db = wfGetDB( DB_MASTER
);
2613 $baseRevision = Revision
::loadFromTimestamp(
2614 $db, $this->mTitle
, $this->edittime
);
2615 return $this->mBaseRevision
= $baseRevision;
2617 return $this->mBaseRevision
;