3 * Contain the EditPage class
8 * Splitting edit page/HTML interface from Article...
9 * The actual database and text munging is still in Article,
10 * but it should get easier to call those from alternate
20 var $isConflict = false;
21 var $isCssJsSubpage = false;
22 var $deletedSinceEdit = false;
26 var $mTokenOk = false;
27 var $mTriedSave = false;
29 var $kblength = false;
30 var $missingComment = false;
31 var $missingSummary = false;
32 var $allowBlankSummary = false;
35 var $mPreviewTemplates;
38 var $save = false, $preview = false, $diff = false;
39 var $minoredit = false, $watchthis = false, $recreate = false;
40 var $textbox1 = '', $textbox2 = '', $summary = '';
41 var $edittime = '', $section = '', $starttime = '';
42 var $oldid = 0, $editintro = '', $scrolltop = null;
44 # Placeholders for text injection by hooks (must be HTML)
45 # extensions should take care to _append_ to the present value
46 public $editFormPageTop; // Before even the preview
47 public $editFormTextTop;
48 public $editFormTextAfterWarn;
49 public $editFormTextAfterTools;
50 public $editFormTextBottom;
56 function EditPage( $article ) {
57 $this->mArticle
=& $article;
59 $this->mTitle
=& $wgTitle;
61 # Placeholders for text injection by hooks (empty per default)
62 $this->editFormPageTop
=
63 $this->editFormTextTop
=
64 $this->editFormTextAfterWarn
=
65 $this->editFormTextAfterTools
=
66 $this->editFormTextBottom
= "";
70 * Fetch initial editing page content.
72 private function getContent() {
73 global $wgOut, $wgRequest, $wgParser;
75 # Get variables from query string :P
76 $section = $wgRequest->getVal( 'section' );
77 $preload = $wgRequest->getVal( 'preload' );
78 $undo = $wgRequest->getVal( 'undo' );
80 wfProfileIn( __METHOD__
);
83 if( !$this->mTitle
->exists() ) {
85 # If requested, preload some text.
86 $text = $this->getPreloadedText( $preload );
88 # We used to put MediaWiki:Newarticletext here if
89 # $text was empty at this point.
90 # This is now shown above the edit box instead.
92 // FIXME: may be better to use Revision class directly
93 // But don't mess with it just yet. Article knows how to
94 // fetch the page record from the high-priority server,
95 // which is needed to guarantee we don't pick up lagged
98 $text = $this->mArticle
->getContent();
101 #Undoing a specific edit overrides section editing; section-editing
102 # doesn't work with undoing.
103 $undorev = Revision
::newFromId($undo);
105 #Sanity check, make sure it's the right page.
106 # Otherwise, $text will be left as-is.
107 if (!is_null($undorev) && $undorev->getPage() == $this->mArticle
->getID()) {
108 $oldrev = $undorev->getPrevious();
109 $undorev_text = $undorev->getText();
110 $oldrev_text = $oldrev->getText();
111 $currev_text = $text;
113 #No use doing a merge if it's just a straight revert.
114 if ($currev_text != $undorev_text) {
115 $result = wfMerge($undorev_text, $oldrev_text, $currev_text, $text);
117 $text = $oldrev_text;
122 # Inform the user of our success and set an automatic edit summary
123 $this->editFormPageTop
.= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) );
124 $this->summary
= wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
126 # Warn the user that something went wrong
127 $this->editFormPageTop
.= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) );
132 else if( $section != '' ) {
133 if( $section == 'new' ) {
134 $text = $this->getPreloadedText( $preload );
136 $text = $wgParser->getSection( $text, $section );
141 wfProfileOut( __METHOD__
);
146 * Get the contents of a page from its title and remove includeonly tags
148 * @param $preload String: the title of the page.
149 * @return string The contents of the page.
151 private function getPreloadedText($preload) {
152 if ( $preload === '' )
155 $preloadTitle = Title
::newFromText( $preload );
156 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
157 $rev=Revision
::newFromTitle($preloadTitle);
158 if ( is_object( $rev ) ) {
159 $text = $rev->getText();
160 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
161 // its own mini-parser! -ævar
162 $text = preg_replace( '~</?includeonly>~', '', $text );
171 * This is the function that extracts metadata from the article body on the first view.
172 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
173 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
175 function extractMetaDataFromArticle () {
176 global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
177 $this->mMetaData
= '' ;
178 if ( !$wgUseMetadataEdit ) return ;
179 if ( $wgMetadataWhitelist == '' ) return ;
181 $t = $this->getContent();
183 # MISSING : <nowiki> filtering
185 # Categories and language links
186 $t = explode ( "\n" , $t ) ;
187 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY
) ) ;
188 $cat = $ll = array() ;
189 foreach ( $t AS $key => $x )
191 $y = trim ( strtolower ( $x ) ) ;
192 while ( substr ( $y , 0 , 2 ) == '[[' )
194 $y = explode ( ']]' , trim ( $x ) ) ;
195 $first = array_shift ( $y ) ;
196 $first = explode ( ':' , $first ) ;
197 $ns = array_shift ( $first ) ;
198 $ns = trim ( str_replace ( '[' , '' , $ns ) ) ;
199 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
201 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]' ;
202 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
204 $x = implode ( ']]' , $y ) ;
206 $y = trim ( strtolower ( $x ) ) ;
210 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n" ;
211 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n" ;
212 $t = implode ( "\n" , $t ) ;
215 $sat = array () ; # stand-alone-templates; must be lowercase
216 $wl_title = Title
::newFromText ( $wgMetadataWhitelist ) ;
217 $wl_article = new Article ( $wl_title ) ;
218 $wl = explode ( "\n" , $wl_article->getContent() ) ;
219 foreach ( $wl AS $x )
223 while ( substr ( $x , 0 , 1 ) == '*' )
226 $x = trim ( substr ( $x , 1 ) ) ;
230 $sat[] = strtolower ( $x ) ;
235 # Templates, but only some
236 $t = explode ( '{{' , $t ) ;
238 foreach ( $t AS $key => $x )
240 $y = explode ( '}}' , $x , 2 ) ;
241 if ( count ( $y ) == 2 )
244 $z = explode ( '|' , $z ) ;
245 $tn = array_shift ( $z ) ;
246 if ( in_array ( strtolower ( $tn ) , $sat ) )
248 $tl[] = '{{' . $y[0] . '}}' ;
250 $y = explode ( '}}' , $y[1] , 2 ) ;
252 else $t[$key] = '{{' . $x ;
254 else if ( $key != 0 ) $t[$key] = '{{' . $x ;
257 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl ) ;
258 $t = implode ( '' , $t ) ;
260 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
261 $this->mArticle
->mContent
= $t ;
262 $this->mMetaData
= $s ;
270 * This is the function that gets called for "action=edit". It
271 * sets up various member variables, then passes execution to
272 * another function, usually showEditForm()
274 * The edit form is self-submitting, so that when things like
275 * preview and edit conflicts occur, we get the same form back
276 * with the extra stuff added. Only when the final submission
277 * is made and all is well do we actually save and redirect to
278 * the newly-edited page.
281 global $wgOut, $wgUser, $wgRequest, $wgTitle;
282 global $wgEmailConfirmToEdit;
284 if ( ! wfRunHooks( 'AlternateEdit', array( &$this ) ) )
287 $fname = 'EditPage::edit';
288 wfProfileIn( $fname );
289 wfDebug( "$fname: enter\n" );
291 // this is not an article
292 $wgOut->setArticleFlag(false);
294 $this->importFormData( $wgRequest );
295 $this->firsttime
= false;
298 $this->livePreview();
299 wfProfileOut( $fname );
303 if ( ! $this->mTitle
->userCanEdit() ) {
304 wfDebug( "$fname: user can't edit\n" );
305 $wgOut->readOnlyPage( $this->getContent(), true );
306 wfProfileOut( $fname );
309 wfDebug( "$fname: Checking blocks\n" );
310 if ( !$this->preview
&& !$this->diff
&& $wgUser->isBlockedFrom( $this->mTitle
, !$this->save
) ) {
311 # When previewing, don't check blocked state - will get caught at save time.
312 # Also, check when starting edition is done against slave to improve performance.
313 wfDebug( "$fname: user is blocked\n" );
314 $this->blockedPage();
315 wfProfileOut( $fname );
318 if ( !$wgUser->isAllowed('edit') ) {
319 if ( $wgUser->isAnon() ) {
320 wfDebug( "$fname: user must log in\n" );
321 $this->userNotLoggedInPage();
322 wfProfileOut( $fname );
325 wfDebug( "$fname: read-only page\n" );
326 $wgOut->readOnlyPage( $this->getContent(), true );
327 wfProfileOut( $fname );
331 if ($wgEmailConfirmToEdit && !$wgUser->isEmailConfirmed()) {
332 wfDebug("$fname: user must confirm e-mail address\n");
333 $this->userNotConfirmedPage();
334 wfProfileOut($fname);
337 if ( !$this->mTitle
->userCanCreate() && !$this->mTitle
->exists() ) {
338 wfDebug( "$fname: no create permission\n" );
339 $this->noCreatePermission();
340 wfProfileOut( $fname );
343 if ( wfReadOnly() ) {
344 wfDebug( "$fname: read-only mode is engaged\n" );
345 if( $this->save ||
$this->preview
) {
346 $this->formtype
= 'preview';
347 } else if ( $this->diff
) {
348 $this->formtype
= 'diff';
350 $wgOut->readOnlyPage( $this->getContent() );
351 wfProfileOut( $fname );
356 $this->formtype
= 'save';
357 } else if ( $this->preview
) {
358 $this->formtype
= 'preview';
359 } else if ( $this->diff
) {
360 $this->formtype
= 'diff';
361 } else { # First time through
362 $this->firsttime
= true;
363 if( $this->previewOnOpen() ) {
364 $this->formtype
= 'preview';
366 $this->extractMetaDataFromArticle () ;
367 $this->formtype
= 'initial';
372 wfProfileIn( "$fname-business-end" );
374 $this->isConflict
= false;
375 // css / js subpages of user pages get a special treatment
376 $this->isCssJsSubpage
= $wgTitle->isCssJsSubpage();
377 $this->isValidCssJsSubpage
= $wgTitle->isValidCssJsSubpage();
379 /* Notice that we can't use isDeleted, because it returns true if article is ever deleted
380 * no matter it's current state
382 $this->deletedSinceEdit
= false;
383 if ( $this->edittime
!= '' ) {
384 /* Note that we rely on logging table, which hasn't been always there,
385 * but that doesn't matter, because this only applies to brand new
386 * deletes. This is done on every preview and save request. Move it further down
387 * to only perform it on saves
389 if ( $this->mTitle
->isDeleted() ) {
390 $this->lastDelete
= $this->getLastDelete();
391 if ( !is_null($this->lastDelete
) ) {
392 $deletetime = $this->lastDelete
->log_timestamp
;
393 if ( ($deletetime - $this->starttime
) > 0 ) {
394 $this->deletedSinceEdit
= true;
400 if(!$this->mTitle
->getArticleID() && ('initial' == $this->formtype ||
$this->firsttime
)) { # new article
403 if( $this->mTitle
->isTalkPage() ) {
404 $wgOut->addWikiText( wfMsg( 'talkpagetext' ) );
407 # Attempt submission here. This will check for edit conflicts,
408 # and redundantly check for locked database, blocked IPs, etc.
409 # that edit() already checked just in case someone tries to sneak
410 # in the back door with a hand-edited submission URL.
412 if ( 'save' == $this->formtype
) {
413 if ( !$this->attemptSave() ) {
414 wfProfileOut( "$fname-business-end" );
415 wfProfileOut( $fname );
420 # First time through: get contents, set time for conflict
422 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
423 $this->initialiseForm();
424 if( !$this->mTitle
->getArticleId() )
425 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1
, &$this->mTitle
) );
428 $this->showEditForm();
429 wfProfileOut( "$fname-business-end" );
430 wfProfileOut( $fname );
434 * Return true if this page should be previewed when the edit form
435 * is initially opened.
439 function previewOnOpen() {
441 return $this->section
!= 'new' &&
442 ( ( $wgUser->getOption( 'previewonfirst' ) && $this->mTitle
->exists() ) ||
443 ( $this->mTitle
->getNamespace() == NS_CATEGORY
&&
444 !$this->mTitle
->exists() ) );
451 function importFormData( &$request ) {
452 global $wgLang, $wgUser;
453 $fname = 'EditPage::importFormData';
454 wfProfileIn( $fname );
456 if( $request->wasPosted() ) {
457 # These fields need to be checked for encoding.
458 # Also remove trailing whitespace, but don't remove _initial_
459 # whitespace from the text boxes. This may be significant formatting.
460 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
461 $this->textbox2
= $this->safeUnicodeInput( $request, 'wpTextbox2' );
462 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
463 # Truncate for whole multibyte characters. +5 bytes for ellipsis
464 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
466 $this->edittime
= $request->getVal( 'wpEdittime' );
467 $this->starttime
= $request->getVal( 'wpStarttime' );
469 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
471 if( is_null( $this->edittime
) ) {
472 # If the form is incomplete, force to preview.
473 wfDebug( "$fname: Form data appears to be incomplete\n" );
474 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
475 $this->preview
= true;
477 /* Fallback for live preview */
478 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
479 $this->diff
= $request->getCheck( 'wpDiff' );
481 // Remember whether a save was requested, so we can indicate
482 // if we forced preview due to session failure.
483 $this->mTriedSave
= !$this->preview
;
485 if ( $this->tokenOk( $request ) ) {
486 # Some browsers will not report any submit button
487 # if the user hits enter in the comment box.
488 # The unmarked state will be assumed to be a save,
489 # if the form seems otherwise complete.
490 wfDebug( "$fname: Passed token check.\n" );
491 } else if ( $this->diff
) {
492 # Failed token check, but only requested "Show Changes".
493 wfDebug( "$fname: Failed token check; Show Changes requested.\n" );
495 # Page might be a hack attempt posted from
496 # an external site. Preview instead of saving.
497 wfDebug( "$fname: Failed token check; forcing preview\n" );
498 $this->preview
= true;
501 $this->save
= ! ( $this->preview
OR $this->diff
);
502 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
503 $this->edittime
= null;
506 if( !preg_match( '/^\d{14}$/', $this->starttime
)) {
507 $this->starttime
= null;
510 $this->recreate
= $request->getCheck( 'wpRecreate' );
512 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
513 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
515 # Don't force edit summaries when a user is editing their own user or talk page
516 if( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) && $this->mTitle
->getText() == $wgUser->getName() ) {
517 $this->allowBlankSummary
= true;
519 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' );
522 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
524 # Not a posted form? Start with nothing.
525 wfDebug( "$fname: Not a posted form.\n" );
526 $this->textbox1
= '';
527 $this->textbox2
= '';
528 $this->mMetaData
= '';
530 $this->edittime
= '';
531 $this->starttime
= wfTimestampNow();
532 $this->preview
= false;
535 $this->minoredit
= false;
536 $this->watchthis
= false;
537 $this->recreate
= false;
540 $this->oldid
= $request->getInt( 'oldid' );
542 # Section edit can come from either the form or a link
543 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
545 $this->live
= $request->getCheck( 'live' );
546 $this->editintro
= $request->getText( 'editintro' );
548 wfProfileOut( $fname );
552 * Make sure the form isn't faking a user's credentials.
554 * @param $request WebRequest
558 function tokenOk( &$request ) {
560 if( $wgUser->isAnon() ) {
561 # Anonymous users may not have a session
562 # open. Check for suffix anyway.
563 $this->mTokenOk
= ( EDIT_TOKEN_SUFFIX
== $request->getVal( 'wpEditToken' ) );
565 $this->mTokenOk
= $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
567 return $this->mTokenOk
;
571 function showIntro() {
572 global $wgOut, $wgUser;
573 $addstandardintro=true;
574 if($this->editintro
) {
575 $introtitle=Title
::newFromText($this->editintro
);
576 if(isset($introtitle) && $introtitle->userCanRead()) {
577 $rev=Revision
::newFromTitle($introtitle);
579 $wgOut->addSecondaryWikiText($rev->getText());
580 $addstandardintro=false;
584 if($addstandardintro) {
585 if ( $wgUser->isLoggedIn() )
586 $wgOut->addWikiText( wfMsg( 'newarticletext' ) );
588 $wgOut->addWikiText( wfMsg( 'newarticletextanon' ) );
594 * @return bool false if output is done, true if the rest of the form should be displayed
596 function attemptSave() {
597 global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut;
598 global $wgMaxArticleSize;
600 $fname = 'EditPage::attemptSave';
601 wfProfileIn( $fname );
602 wfProfileIn( "$fname-checks" );
604 if( !wfRunHooks( 'EditPage::attemptSave', array( &$this ) ) )
606 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" );
610 # Reintegrate metadata
611 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
612 $this->mMetaData
= '' ;
616 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
617 $this->spamPage ( $matches[0] );
618 wfProfileOut( "$fname-checks" );
619 wfProfileOut( $fname );
622 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
623 # Error messages or other handling should be performed by the filter function
624 wfProfileOut( $fname );
625 wfProfileOut( "$fname-checks" );
628 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1
, $this->section
, &$this->hookError
) ) ) {
629 # Error messages etc. could be handled within the hook...
630 wfProfileOut( $fname );
631 wfProfileOut( "$fname-checks" );
633 } elseif( $this->hookError
!= '' ) {
634 # ...or the hook could be expecting us to produce an error
635 wfProfileOut( "$fname-checks " );
636 wfProfileOut( $fname );
639 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
640 # Check block state against master, thus 'false'.
641 $this->blockedPage();
642 wfProfileOut( "$fname-checks" );
643 wfProfileOut( $fname );
646 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
647 if ( $this->kblength
> $wgMaxArticleSize ) {
648 // Error will be displayed by showEditForm()
649 $this->tooBig
= true;
650 wfProfileOut( "$fname-checks" );
651 wfProfileOut( $fname );
655 if ( !$wgUser->isAllowed('edit') ) {
656 if ( $wgUser->isAnon() ) {
657 $this->userNotLoggedInPage();
658 wfProfileOut( "$fname-checks" );
659 wfProfileOut( $fname );
663 $wgOut->readOnlyPage();
664 wfProfileOut( "$fname-checks" );
665 wfProfileOut( $fname );
670 if ( wfReadOnly() ) {
671 $wgOut->readOnlyPage();
672 wfProfileOut( "$fname-checks" );
673 wfProfileOut( $fname );
676 if ( $wgUser->pingLimiter() ) {
677 $wgOut->rateLimited();
678 wfProfileOut( "$fname-checks" );
679 wfProfileOut( $fname );
683 # If the article has been deleted while editing, don't save it without
685 if ( $this->deletedSinceEdit
&& !$this->recreate
) {
686 wfProfileOut( "$fname-checks" );
687 wfProfileOut( $fname );
691 wfProfileOut( "$fname-checks" );
693 # If article is new, insert it.
694 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
697 // Late check for create permission, just in case *PARANOIA*
698 if ( !$this->mTitle
->userCanCreate() ) {
699 wfDebug( "$fname: no create permission\n" );
700 $this->noCreatePermission();
701 wfProfileOut( $fname );
705 # Don't save a new article if it's blank.
706 if ( ( '' == $this->textbox1
) ) {
707 $wgOut->redirect( $this->mTitle
->getFullURL() );
708 wfProfileOut( $fname );
712 $isComment=($this->section
=='new');
713 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
714 $this->minoredit
, $this->watchthis
, false, $isComment);
716 wfProfileOut( $fname );
720 # Article exists. Check for edit conflict.
722 $this->mArticle
->clear(); # Force reload of dates, etc.
723 $this->mArticle
->forUpdate( true ); # Lock the article
725 if( $this->mArticle
->getTimestamp() != $this->edittime
) {
726 $this->isConflict
= true;
727 if( $this->section
== 'new' ) {
728 if( $this->mArticle
->getUserText() == $wgUser->getName() &&
729 $this->mArticle
->getComment() == $this->summary
) {
730 // Probably a duplicate submission of a new comment.
731 // This can happen when squid resends a request after
732 // a timeout but the first one actually went through.
733 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
735 // New comment; suppress conflict.
736 $this->isConflict
= false;
737 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
741 $userid = $wgUser->getID();
743 if ( $this->isConflict
) {
744 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
745 $this->mArticle
->getTimestamp() . "'\n" );
746 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
749 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
750 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
752 if( is_null( $text ) ) {
753 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
754 $this->isConflict
= true;
755 $text = $this->textbox1
;
758 # Suppress edit conflict with self, except for section edits where merging is required.
759 if ( ( $this->section
== '' ) && ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
760 wfDebug( "Suppressing edit conflict, same user.\n" );
761 $this->isConflict
= false;
763 # switch from section editing to normal editing in edit conflict
764 if($this->isConflict
) {
766 if( $this->mergeChangesInto( $text ) ){
767 // Successful merge! Maybe we should tell the user the good news?
768 $this->isConflict
= false;
769 wfDebug( "Suppressing edit conflict, successful merge.\n" );
772 $this->textbox1
= $text;
773 wfDebug( "Keeping edit conflict, failed merge.\n" );
778 if ( $this->isConflict
) {
779 wfProfileOut( $fname );
783 $oldtext = $this->mArticle
->getContent();
785 # Handle the user preference to force summaries here, but not for null edits
786 if( $this->section
!= 'new' && !$this->allowBlankSummary
&& $wgUser->getOption( 'forceeditsummary')
787 && 0 != strcmp($oldtext, $text) && !Article
::getRedirectAutosummary( $text )) {
788 if( md5( $this->summary
) == $this->autoSumm
) {
789 $this->missingSummary
= true;
790 wfProfileOut( $fname );
795 #And a similar thing for new sections
796 if( $this->section
== 'new' && !$this->allowBlankSummary
&& $wgUser->getOption( 'forceeditsummary' ) ) {
797 if (trim($this->summary
) == '') {
798 $this->missingSummary
= true;
799 wfProfileOut( $fname );
805 wfProfileIn( "$fname-sectionanchor" );
807 if( $this->section
== 'new' ) {
808 if ( $this->textbox1
== '' ) {
809 $this->missingComment
= true;
812 if( $this->summary
!= '' ) {
813 $sectionanchor = $this->sectionAnchor( $this->summary
);
815 } elseif( $this->section
!= '' ) {
816 # Try to get a section anchor from the section source, redirect to edited section if header found
817 # XXX: might be better to integrate this into Article::replaceSection
818 # for duplicate heading checking and maybe parsing
819 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
820 # we can't deal with anchors, includes, html etc in the header for now,
821 # headline would need to be parsed to improve this
822 if($hasmatch and strlen($matches[2]) > 0) {
823 $sectionanchor = $this->sectionAnchor( $matches[2] );
826 wfProfileOut( "$fname-sectionanchor" );
828 // Save errors may fall down to the edit form, but we've now
829 // merged the section into full text. Clear the section field
830 // so that later submission of conflict forms won't try to
831 // replace that into a duplicated mess.
832 $this->textbox1
= $text;
835 // Check for length errors again now that the section is merged in
836 $this->kblength
= (int)(strlen( $text ) / 1024);
837 if ( $this->kblength
> $wgMaxArticleSize ) {
838 $this->tooBig
= true;
839 wfProfileOut( $fname );
843 # update the article here
844 if( $this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
845 $this->watchthis
, '', $sectionanchor ) ) {
846 wfProfileOut( $fname );
849 $this->isConflict
= true;
851 wfProfileOut( $fname );
856 * Initialise form fields in the object
857 * Called on the first invocation, e.g. when a user clicks an edit link
859 function initialiseForm() {
860 $this->edittime
= $this->mArticle
->getTimestamp();
862 $this->textbox1
= $this->getContent();
863 if ( !$this->mArticle
->exists() && $this->mArticle
->mTitle
->getNamespace() == NS_MEDIAWIKI
)
864 $this->textbox1
= wfMsgWeirdKey( $this->mArticle
->mTitle
->getText() ) ;
869 * Send the edit form and related headers to $wgOut
870 * @param $formCallback Optional callable that takes an OutputPage
871 * parameter; will be called during form output
872 * near the top, for captchas and the like.
874 function showEditForm( $formCallback=null ) {
875 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize;
877 $fname = 'EditPage::showEditForm';
878 wfProfileIn( $fname );
880 $sk =& $wgUser->getSkin();
882 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
884 $wgOut->setRobotpolicy( 'noindex,nofollow' );
886 # Enabled article-related sidebar, toplinks, etc.
887 $wgOut->setArticleRelated( true );
889 if ( $this->isConflict
) {
890 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
891 $wgOut->setPageTitle( $s );
892 $wgOut->addWikiText( wfMsg( 'explainconflict' ) );
894 $this->textbox2
= $this->textbox1
;
895 $this->textbox1
= $this->getContent();
896 $this->edittime
= $this->mArticle
->getTimestamp();
899 if( $this->section
!= '' ) {
900 if( $this->section
== 'new' ) {
901 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
903 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
905 if( !$this->summary
&& !$this->preview
&& !$this->diff
) {
906 preg_match( "/^(=+)(.+)\\1/mi",
909 if( !empty( $matches[2] ) ) {
910 $this->summary
= "/* ". trim($matches[2])." */ ";
915 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
917 $wgOut->setPageTitle( $s );
919 if ( $this->missingComment
) {
920 $wgOut->addWikiText( wfMsg( 'missingcommenttext' ) );
923 if( $this->missingSummary
&& $this->section
!= 'new' ) {
924 $wgOut->addWikiText( wfMsg( 'missingsummary' ) );
927 if( $this->missingSummary
&& $this->section
== 'new' ) {
928 $wgOut->addWikiText( wfMsg( 'missingcommentheader' ) );
931 if( !$this->hookError
== '' ) {
932 $wgOut->addWikiText( $this->hookError
);
935 if ( !$this->checkUnicodeCompliantBrowser() ) {
936 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
938 if ( isset( $this->mArticle
)
939 && isset( $this->mArticle
->mRevision
)
940 && !$this->mArticle
->mRevision
->isCurrent() ) {
941 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
942 $wgOut->addWikiText( wfMsg( 'editingold' ) );
947 $wgOut->addWikiText( wfMsg( 'readonlywarning' ) );
948 } elseif( $wgUser->isAnon() && $this->formtype
!= 'preview' ) {
949 $wgOut->addWikiText( wfMsg( 'anoneditwarning' ) );
951 if( $this->isCssJsSubpage
&& $this->formtype
!= 'preview' ) {
952 # Check the skin exists
953 if( $this->isValidCssJsSubpage
) {
954 $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ) );
956 $wgOut->addWikiText( wfMsg( 'userinvalidcssjstitle', $this->mTitle
->getSkinFromCssJsSubpage() ) );
961 if( $this->mTitle
->isProtected( 'edit' ) ) {
962 # Is the protection due to the namespace, e.g. interface text?
963 if( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
964 # Yes; remind the user
965 $notice = wfMsg( 'editinginterface' );
966 } elseif( $this->mTitle
->isSemiProtected() ) {
968 $notice = wfMsg( 'semiprotectedpagewarning' );
969 if( wfEmptyMsg( 'semiprotectedpagewarning', $notice ) ||
$notice == '-' ) {
973 # No; regular protection
974 $notice = wfMsg( 'protectedpagewarning' );
976 $wgOut->addWikiText( $notice );
979 if ( $this->kblength
=== false ) {
980 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
982 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
983 $wgOut->addWikiText( wfMsg( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgMaxArticleSize ) );
984 } elseif( $this->kblength
> 29 ) {
985 $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength
) ) );
988 #need to parse the preview early so that we know which templates are used,
989 #otherwise users with "show preview after edit box" will get a blank list
990 $previewOutput = $this->getPreviewText();
992 $rows = $wgUser->getIntOption( 'rows' );
993 $cols = $wgUser->getIntOption( 'cols' );
995 $ew = $wgUser->getOption( 'editwidth' );
996 if ( $ew ) $ew = " style=\"width:100%\"";
999 $q = 'action=submit';
1000 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
1001 $action = $this->mTitle
->escapeLocalURL( $q );
1003 $summary = wfMsg('summary');
1004 $subject = wfMsg('subject');
1005 $minor = wfMsgExt('minoredit', array('parseinline'));
1006 $watchthis = wfMsgExt('watchthis', array('parseinline'));
1008 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
1009 wfMsgExt('cancel', array('parseinline')) );
1010 $edithelpurl = Skin
::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
1011 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1012 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1013 htmlspecialchars( wfMsg( 'newwindow' ) );
1015 global $wgRightsText;
1016 $copywarn = "<div id=\"editpage-copywarn\">\n" .
1017 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
1018 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1019 $wgRightsText ) . "\n</div>";
1021 if( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage
) {
1022 # prepare toolbar for edit buttons
1023 $toolbar = $this->getEditToolbar();
1028 // activate checkboxes if user wants them to be always active
1029 if( !$this->preview
&& !$this->diff
) {
1030 # Sort out the "watch" checkbox
1031 if( $wgUser->getOption( 'watchdefault' ) ) {
1033 $this->watchthis
= true;
1034 } elseif( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
1036 $this->watchthis
= true;
1037 } elseif( $this->mTitle
->userIsWatching() ) {
1039 $this->watchthis
= true;
1042 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
1045 $minoredithtml = '';
1047 if ( $wgUser->isAllowed('minoredit') ) {
1049 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
1050 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />\n".
1051 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>\n";
1056 if ( $wgUser->isLoggedIn() ) {
1057 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".
1058 ($this->watchthis?
" checked='checked'":"").
1059 " accesskey=\"".htmlspecialchars(wfMsg('accesskey-watch'))."\" id='wpWatchthis' />\n".
1060 "<label for='wpWatchthis' title=\"" .
1061 htmlspecialchars(wfMsg('tooltip-watch'))."\">{$watchthis}</label>\n";
1064 $checkboxhtml = $minoredithtml . $watchhtml;
1066 $wgOut->addHTML( $this->editFormPageTop
);
1068 if ( $wgUser->getOption( 'previewontop' ) ) {
1070 if ( 'preview' == $this->formtype
) {
1071 $this->showPreview( $previewOutput );
1073 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
1076 if ( 'diff' == $this->formtype
) {
1077 $wgOut->addHTML( $this->getDiff() );
1082 $wgOut->addHTML( $this->editFormTextTop
);
1084 # if this is a comment, show a subject line at the top, which is also the edit summary.
1085 # Otherwise, show a summary field at the bottom
1086 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
1087 if( $this->section
== 'new' ) {
1088 $commentsubject="<span id='wpSummaryLabel'><label for='wpSummary'>{$subject}:</label></span>\n<div class='editOptions'>\n<input tabindex='1' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' /><br />";
1090 $subjectpreview = $summarytext && $this->preview ?
"<div class=\"mw-summary-preview\">".wfMsg('subject-preview').':'.$sk->commentBlock( $this->summary
, $this->mTitle
)."</div>\n" : '';
1091 $summarypreview = '';
1093 $commentsubject = '';
1094 $editsummary="<span id='wpSummaryLabel'><label for='wpSummary'>{$summary}:</label></span>\n<div class='editOptions'>\n<input tabindex='2' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' /><br />";
1095 $summarypreview = $summarytext && $this->preview ?
"<div class=\"mw-summary-preview\">".wfMsg('summary-preview').':'.$sk->commentBlock( $this->summary
, $this->mTitle
)."</div>\n" : '';
1096 $subjectpreview = '';
1099 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
1100 if( !$this->preview
&& !$this->diff
) {
1101 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
1103 $templates = ($this->preview ||
$this->section
) ?
$this->mPreviewTemplates
: $this->mArticle
->getUsedTemplates();
1104 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview
, $this->section
!= '');
1106 global $wgUseMetadataEdit ;
1107 if ( $wgUseMetadataEdit ) {
1108 $metadata = $this->mMetaData
;
1109 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
1110 $top = wfMsgWikiHtml( 'metadata_help' );
1111 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
1113 else $metadata = "" ;
1117 if ($this->deletedSinceEdit
) {
1118 if ( 'save' != $this->formtype
) {
1119 $wgOut->addWikiText( wfMsg('deletedwhileediting'));
1121 // Hide the toolbar and edit area, use can click preview to get it back
1122 // Add an confirmation checkbox and explanation.
1124 $hidden = 'type="hidden" style="display:none;"';
1125 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete
->user_name
, $this->lastDelete
->log_comment
));
1127 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
1128 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
1137 'value' => wfMsg('savearticle'),
1138 'accesskey' => wfMsg('accesskey-save'),
1139 'title' => wfMsg('tooltip-save'),
1141 $buttons['save'] = wfElement('input', $temp, '');
1147 'value' => wfMsg('showdiff'),
1148 'accesskey' => wfMsg('accesskey-diff'),
1149 'title' => wfMsg('tooltip-diff'),
1151 $buttons['diff'] = wfElement('input', $temp, '');
1153 global $wgLivePreview;
1154 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
1156 'id' => 'wpPreview',
1157 'name' => 'wpPreview',
1160 'value' => wfMsg('showpreview'),
1162 'title' => wfMsg('tooltip-preview'),
1163 'style' => 'display: none;',
1165 $buttons['preview'] = wfElement('input', $temp, '');
1167 'id' => 'wpLivePreview',
1168 'name' => 'wpLivePreview',
1171 'value' => wfMsg('showlivepreview'),
1172 'accesskey' => wfMsg('accesskey-preview'),
1174 'onclick' => $this->doLivePreviewScript(),
1176 $buttons['live'] = wfElement('input', $temp, '');
1179 'id' => 'wpPreview',
1180 'name' => 'wpPreview',
1183 'value' => wfMsg('showpreview'),
1184 'accesskey' => wfMsg('accesskey-preview'),
1185 'title' => wfMsg('tooltip-preview'),
1187 $buttons['preview'] = wfElement('input', $temp, '');
1188 $buttons['live'] = '';
1191 $safemodehtml = $this->checkUnicodeCompliantBrowser()
1193 : "<input type='hidden' name=\"safemode\" value='1' />\n";
1195 $wgOut->addHTML( <<<END
1197 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1201 if( is_callable( $formCallback ) ) {
1202 call_user_func_array( $formCallback, array( &$wgOut ) );
1205 // Put these up at the top to ensure they aren't lost on early form submission
1207 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
1208 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1209 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1210 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
1212 $wgOut->addHTML( <<<END
1216 <textarea tabindex='1' accesskey="," name="wpTextbox1" id="wpTextbox1" rows='{$rows}'
1217 cols='{$cols}'{$ew} $hidden>
1219 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1
) ) .
1224 $wgOut->addWikiText( $copywarn );
1225 $wgOut->addHTML( $this->editFormTextAfterWarn
);
1235 "<div class='editButtons'>
1237 {$buttons['preview']}
1240 <span class='editHelp'>{$cancel} | {$edithelp}</span>
1241 </div><!-- editButtons -->
1242 </div><!-- editOptions -->");
1244 $wgOut->addHtml( '<div class="mw-editTools">' );
1245 $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
1246 $wgOut->addHtml( '</div>' );
1248 $wgOut->addHTML( $this->editFormTextAfterTools
);
1251 <div class='templatesUsed'>
1252 {$formattedtemplates}
1257 * To make it harder for someone to slip a user a page
1258 * which submits an edit form to the wiki without their
1259 * knowledge, a random token is associated with the login
1260 * session. If it's not passed back with the submission,
1261 * we won't save the page, or render user JavaScript and
1264 * For anon editors, who may not have a session, we just
1265 * include the constant suffix to prevent editing from
1266 * broken text-mangling proxies.
1268 if ( $wgUser->isLoggedIn() )
1269 $token = htmlspecialchars( $wgUser->editToken() );
1271 $token = EDIT_TOKEN_SUFFIX
;
1272 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1275 # If a blank edit summary was previously provided, and the appropriate
1276 # user preference is active, pass a hidden tag here. This will stop the
1277 # user being bounced back more than once in the event that a summary
1279 if( $this->missingSummary
) {
1280 $wgOut->addHTML( "<input type=\"hidden\" name=\"wpIgnoreBlankSummary\" value=\"1\" />\n" );
1283 # For a bit more sophisticated detection of blank summaries, hash the
1284 # automatic one and pass that in a hidden field.
1285 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
1286 $wgOut->addHtml( wfHidden( 'wpAutoSummary', $autosumm ) );
1288 if ( $this->isConflict
) {
1289 $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' );
1291 $de = new DifferenceEngine( $this->mTitle
);
1292 $de->setText( $this->textbox2
, $this->textbox1
);
1293 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1295 $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
1296 $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
1297 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2
) ) . "\n</textarea>" );
1299 $wgOut->addHTML( $this->editFormTextBottom
);
1300 $wgOut->addHTML( "</form>\n" );
1301 if ( !$wgUser->getOption( 'previewontop' ) ) {
1303 if ( $this->formtype
== 'preview') {
1304 $this->showPreview( $previewOutput );
1306 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
1309 if ( $this->formtype
== 'diff') {
1310 $wgOut->addHTML( $this->getDiff() );
1315 wfProfileOut( $fname );
1319 * Append preview output to $wgOut.
1320 * Includes category rendering if this is a category page.
1322 * @param string $text The HTML to be output for the preview.
1324 private function showPreview( $text ) {
1327 $wgOut->addHTML( '<div id="wikiPreview">' );
1328 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1329 $this->mArticle
->openShowCategory();
1331 $wgOut->addHTML( $text );
1332 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1333 $this->mArticle
->closeShowCategory();
1335 $wgOut->addHTML( '</div>' );
1339 * Live Preview lets us fetch rendered preview page content and
1340 * add it to the page without refreshing the whole page.
1341 * If not supported by the browser it will fall through to the normal form
1342 * submission method.
1344 * This function outputs a script tag to support live preview, and
1345 * returns an onclick handler which should be added to the attributes
1346 * of the preview button
1348 function doLivePreviewScript() {
1349 global $wgStylePath, $wgJsMimeType, $wgStyleVersion, $wgOut, $wgTitle;
1350 $wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' .
1351 htmlspecialchars( "$wgStylePath/common/preview.js?$wgStyleVersion" ) .
1352 '"></script>' . "\n" );
1353 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
1354 return "return !livePreview(" .
1355 "getElementById('wikiPreview')," .
1356 "editform.wpTextbox1.value," .
1357 '"' . $liveAction . '"' . ")";
1360 function getLastDelete() {
1361 $dbr =& wfGetDB( DB_SLAVE
);
1362 $fname = 'EditPage::getLastDelete';
1363 $res = $dbr->select(
1364 array( 'logging', 'user' ),
1374 array( 'log_namespace' => $this->mTitle
->getNamespace(),
1375 'log_title' => $this->mTitle
->getDBkey(),
1376 'log_type' => 'delete',
1377 'log_action' => 'delete',
1378 'user_id=log_user' ),
1380 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1382 if($dbr->numRows($res) == 1) {
1383 while ( $x = $dbr->fetchObject ( $res ) )
1385 $dbr->freeResult ( $res ) ;
1395 function getPreviewText() {
1396 global $wgOut, $wgUser, $wgTitle, $wgParser;
1398 $fname = 'EditPage::getPreviewText';
1399 wfProfileIn( $fname );
1401 if ( $this->mTriedSave
&& !$this->mTokenOk
) {
1402 $msg = 'session_fail_preview';
1404 $msg = 'previewnote';
1406 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1407 "<div class='previewnote'>" . $wgOut->parse( wfMsg( $msg ) ) . "</div>\n";
1408 if ( $this->isConflict
) {
1409 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1412 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1413 $parserOptions->setEditSection( false );
1416 if( $wgRawHtml && !$this->mTokenOk
) {
1417 // Could be an offsite preview attempt. This is very unsafe if
1418 // HTML is enabled, as it could be an attack.
1419 return $wgOut->parse( "<div class='previewnote'>" .
1420 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1423 # don't parse user css/js, show message about preview
1424 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1426 if ( $this->isCssJsSubpage
) {
1427 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
1428 $previewtext = wfMsg('usercsspreview');
1429 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
1430 $previewtext = wfMsg('userjspreview');
1432 $parserOptions->setTidy(true);
1433 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
1434 $wgOut->addHTML( $parserOutput->mText
);
1435 wfProfileOut( $fname );
1436 return $previewhead;
1438 $toparse = $this->textbox1
;
1440 # If we're adding a comment, we need to show the
1441 # summary as the headline
1442 if($this->section
=="new" && $this->summary
!="") {
1443 $toparse="== {$this->summary} ==\n\n".$toparse;
1446 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
1447 $parserOptions->setTidy(true);
1448 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
1449 $wgTitle, $parserOptions );
1451 $previewHTML = $parserOutput->getText();
1452 $wgOut->addParserOutputNoText( $parserOutput );
1454 foreach ( $parserOutput->getTemplates() as $ns => $template)
1455 foreach ( array_keys( $template ) as $dbk)
1456 $this->mPreviewTemplates
[] = Title
::makeTitle($ns, $dbk);
1458 wfProfileOut( $fname );
1459 return $previewhead . $previewHTML;
1464 * Call the stock "user is blocked" page
1466 function blockedPage() {
1467 global $wgOut, $wgUser;
1468 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
1470 # If the user made changes, preserve them when showing the markup
1471 # (This happens when a user is blocked during edit, for instance)
1472 $first = $this->firsttime ||
( !$this->save
&& $this->textbox1
== '' );
1474 $source = $this->mTitle
->exists() ?
$this->getContent() : false;
1476 $source = $this->textbox1
;
1479 # Spit out the source or the user's modified version
1480 if( $source !== false ) {
1481 $rows = $wgUser->getOption( 'rows' );
1482 $cols = $wgUser->getOption( 'cols' );
1483 $attribs = array( 'id' => 'wpTextbox1', 'name' => 'wpTextbox1', 'cols' => $cols, 'rows' => $rows, 'readonly' => 'readonly' );
1484 $wgOut->addHtml( '<hr />' );
1485 $wgOut->addWikiText( wfMsg( $first ?
'blockedoriginalsource' : 'blockededitsource', $this->mTitle
->getPrefixedText() ) );
1486 $wgOut->addHtml( wfOpenElement( 'textarea', $attribs ) . htmlspecialchars( $source ) . wfCloseElement( 'textarea' ) );
1491 * Produce the stock "please login to edit pages" page
1493 function userNotLoggedInPage() {
1494 global $wgUser, $wgOut;
1495 $skin = $wgUser->getSkin();
1497 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1498 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $this->mTitle
->getPrefixedUrl() );
1500 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1501 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1502 $wgOut->setArticleRelated( false );
1504 $wgOut->addHtml( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1505 $wgOut->returnToMain( false, $this->mTitle
->getPrefixedUrl() );
1509 * Creates a basic error page which informs the user that
1510 * they have to validate their email address before being
1513 function userNotConfirmedPage() {
1516 $wgOut->setPageTitle( wfMsg( 'confirmedittitle' ) );
1517 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1518 $wgOut->setArticleRelated( false );
1520 $wgOut->addWikiText( wfMsg( 'confirmedittext' ) );
1521 $wgOut->returnToMain( false );
1525 * Produce the stock "your edit contains spam" page
1527 * @param $match Text which triggered one or more filters
1529 function spamPage( $match = false ) {
1532 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1533 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1534 $wgOut->setArticleRelated( false );
1536 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
1538 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
1540 $wgOut->returnToMain( false );
1547 function mergeChangesInto( &$editText ){
1548 $fname = 'EditPage::mergeChangesInto';
1549 wfProfileIn( $fname );
1551 $db =& wfGetDB( DB_MASTER
);
1553 // This is the revision the editor started from
1554 $baseRevision = Revision
::loadFromTimestamp(
1555 $db, $this->mArticle
->mTitle
, $this->edittime
);
1556 if( is_null( $baseRevision ) ) {
1557 wfProfileOut( $fname );
1560 $baseText = $baseRevision->getText();
1562 // The current state, we want to merge updates into it
1563 $currentRevision = Revision
::loadFromTitle(
1564 $db, $this->mArticle
->mTitle
);
1565 if( is_null( $currentRevision ) ) {
1566 wfProfileOut( $fname );
1569 $currentText = $currentRevision->getText();
1572 if( wfMerge( $baseText, $editText, $currentText, $result ) ){
1573 $editText = $result;
1574 wfProfileOut( $fname );
1577 wfProfileOut( $fname );
1583 * Check if the browser is on a blacklist of user-agents known to
1584 * mangle UTF-8 data on form submission. Returns true if Unicode
1585 * should make it through, false if it's known to be a problem.
1589 function checkUnicodeCompliantBrowser() {
1590 global $wgBrowserBlackList;
1591 if( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1592 // No User-Agent header sent? Trust it by default...
1595 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1596 foreach ( $wgBrowserBlackList as $browser ) {
1597 if ( preg_match($browser, $currentbrowser) ) {
1605 * Format an anchor fragment as it would appear for a given section name
1606 * @param string $text
1610 function sectionAnchor( $text ) {
1611 $headline = Sanitizer
::decodeCharReferences( $text );
1613 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
1614 $headline = trim( $headline );
1615 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
1616 $replacearray = array(
1621 array_keys( $replacearray ),
1622 array_values( $replacearray ),
1627 * Shows a bulletin board style toolbar for common editing functions.
1628 * It can be disabled in the user preferences.
1629 * The necessary JavaScript code can be found in style/wikibits.js.
1631 function getEditToolbar() {
1632 global $wgStylePath, $wgContLang, $wgJsMimeType;
1635 * toolarray an array of arrays which each include the filename of
1636 * the button image (without path), the opening tag, the closing tag,
1637 * and optionally a sample text that is inserted between the two when no
1638 * selection is highlighted.
1639 * The tip text is shown when the user moves the mouse over the button.
1641 * Already here are accesskeys (key), which are not used yet until someone
1642 * can figure out a way to make them work in IE. However, we should make
1643 * sure these keys are not defined on the edit page.
1646 array( 'image'=>'button_bold.png',
1647 'open' => '\\\'\\\'\\\'',
1648 'close' => '\\\'\\\'\\\'',
1649 'sample'=> wfMsg('bold_sample'),
1650 'tip' => wfMsg('bold_tip'),
1653 array( 'image'=>'button_italic.png',
1654 'open' => '\\\'\\\'',
1655 'close' => '\\\'\\\'',
1656 'sample'=> wfMsg('italic_sample'),
1657 'tip' => wfMsg('italic_tip'),
1660 array( 'image'=>'button_link.png',
1663 'sample'=> wfMsg('link_sample'),
1664 'tip' => wfMsg('link_tip'),
1667 array( 'image'=>'button_extlink.png',
1670 'sample'=> wfMsg('extlink_sample'),
1671 'tip' => wfMsg('extlink_tip'),
1674 array( 'image'=>'button_headline.png',
1676 'close' => " ==\\n",
1677 'sample'=> wfMsg('headline_sample'),
1678 'tip' => wfMsg('headline_tip'),
1681 array( 'image'=>'button_image.png',
1682 'open' => '[['.$wgContLang->getNsText(NS_IMAGE
).":",
1684 'sample'=> wfMsg('image_sample'),
1685 'tip' => wfMsg('image_tip'),
1688 array( 'image' =>'button_media.png',
1689 'open' => '[['.$wgContLang->getNsText(NS_MEDIA
).':',
1691 'sample'=> wfMsg('media_sample'),
1692 'tip' => wfMsg('media_tip'),
1695 array( 'image' =>'button_math.png',
1697 'close' => "<\\/math>",
1698 'sample'=> wfMsg('math_sample'),
1699 'tip' => wfMsg('math_tip'),
1702 array( 'image' =>'button_nowiki.png',
1703 'open' => "<nowiki>",
1704 'close' => "<\\/nowiki>",
1705 'sample'=> wfMsg('nowiki_sample'),
1706 'tip' => wfMsg('nowiki_tip'),
1709 array( 'image' =>'button_sig.png',
1713 'tip' => wfMsg('sig_tip'),
1716 array( 'image' =>'button_hr.png',
1717 'open' => "\\n----\\n",
1720 'tip' => wfMsg('hr_tip'),
1724 $toolbar = "<div id='toolbar'>\n";
1725 $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
1727 foreach($toolarray as $tool) {
1729 $image=$wgStylePath.'/common/images/'.$tool['image'];
1730 $open=$tool['open'];
1731 $close=$tool['close'];
1732 $sample = wfEscapeJsString( $tool['sample'] );
1734 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1735 // Older browsers show a "speedtip" type message only for ALT.
1736 // Ideally these should be different, realistically they
1737 // probably don't need to be.
1738 $tip = wfEscapeJsString( $tool['tip'] );
1740 #$key = $tool["key"];
1742 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
1745 $toolbar.="/*]]>*/\n</script>";
1746 $toolbar.="\n</div>";
1751 * Output preview text only. This can be sucked into the edit page
1752 * via JavaScript, and saves the server time rendering the skin as
1753 * well as theoretically being more robust on the client (doesn't
1754 * disturb the edit box's undo history, won't eat your text on
1757 * @todo This doesn't include category or interlanguage links.
1758 * Would need to enhance it a bit, maybe wrap them in XML
1759 * or something... that might also require more skin
1760 * initialization, so check whether that's a problem.
1762 function livePreview() {
1765 header( 'Content-type: text/xml' );
1766 header( 'Cache-control: no-cache' );
1768 echo $this->getPreviewText( );
1769 /* To not shake screen up and down between preview and live-preview */
1770 echo "<br style=\"clear:both;\" />\n";
1775 * Get a diff between the current contents of the edit box and the
1776 * version of the page we're editing from.
1778 * If this is a section edit, we'll replace the section as for final
1779 * save and then make a comparison.
1781 * @return string HTML
1783 function getDiff() {
1784 $oldtext = $this->mArticle
->fetchContent();
1785 $newtext = $this->mArticle
->replaceSection(
1786 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1787 $newtext = $this->mArticle
->preSaveTransform( $newtext );
1788 $oldtitle = wfMsgExt( 'currentrev', array('parseinline') );
1789 $newtitle = wfMsgExt( 'yourtext', array('parseinline') );
1790 if ( $oldtext !== false ||
$newtext != '' ) {
1791 $de = new DifferenceEngine( $this->mTitle
);
1792 $de->setText( $oldtext, $newtext );
1793 $difftext = $de->getDiff( $oldtitle, $newtitle );
1798 return '<div id="wikiDiff">' . $difftext . '</div>';
1802 * Filter an input field through a Unicode de-armoring process if it
1803 * came from an old browser with known broken Unicode editing issues.
1805 * @param WebRequest $request
1806 * @param string $field
1810 function safeUnicodeInput( $request, $field ) {
1811 $text = rtrim( $request->getText( $field ) );
1812 return $request->getBool( 'safemode' )
1813 ?
$this->unmakesafe( $text )
1818 * Filter an output field through a Unicode armoring process if it is
1819 * going to an old browser with known broken Unicode editing issues.
1821 * @param string $text
1825 function safeUnicodeOutput( $text ) {
1827 $codedText = $wgContLang->recodeForEdit( $text );
1828 return $this->checkUnicodeCompliantBrowser()
1830 : $this->makesafe( $codedText );
1834 * A number of web browsers are known to corrupt non-ASCII characters
1835 * in a UTF-8 text editing environment. To protect against this,
1836 * detected browsers will be served an armored version of the text,
1837 * with non-ASCII chars converted to numeric HTML character references.
1839 * Preexisting such character references will have a 0 added to them
1840 * to ensure that round-trips do not alter the original data.
1842 * @param string $invalue
1846 function makesafe( $invalue ) {
1847 // Armor existing references for reversability.
1848 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
1853 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1854 $bytevalue = ord( $invalue{$i} );
1855 if( $bytevalue <= 0x7F ) { //0xxx xxxx
1856 $result .= chr( $bytevalue );
1858 } elseif( $bytevalue <= 0xBF ) { //10xx xxxx
1859 $working = $working << 6;
1860 $working +
= ($bytevalue & 0x3F);
1862 if( $bytesleft <= 0 ) {
1863 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
1865 } elseif( $bytevalue <= 0xDF ) { //110x xxxx
1866 $working = $bytevalue & 0x1F;
1868 } elseif( $bytevalue <= 0xEF ) { //1110 xxxx
1869 $working = $bytevalue & 0x0F;
1871 } else { //1111 0xxx
1872 $working = $bytevalue & 0x07;
1880 * Reverse the previously applied transliteration of non-ASCII characters
1881 * back to UTF-8. Used to protect data from corruption by broken web browsers
1882 * as listed in $wgBrowserBlackList.
1884 * @param string $invalue
1888 function unmakesafe( $invalue ) {
1890 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1891 if( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+
3} != '0' ) ) {
1895 $hexstring .= $invalue{$i};
1897 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
1899 // Do some sanity checks. These aren't needed for reversability,
1900 // but should help keep the breakage down if the editor
1901 // breaks one of the entities whilst editing.
1902 if ((substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6)) {
1903 $codepoint = hexdec($hexstring);
1904 $result .= codepointToUtf8( $codepoint );
1906 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
1909 $result .= substr( $invalue, $i, 1 );
1912 // reverse the transform that we made for reversability reasons.
1913 return strtr( $result, array( "�" => "&#x" ) );
1916 function noCreatePermission() {
1918 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
1919 $wgOut->addWikiText( wfMsg( 'nocreatetext' ) );