82f875196f0d6e6e3399749983874e433690d297
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;
37 var $save = false, $preview = false, $diff = false;
38 var $minoredit = false, $watchthis = false, $recreate = false;
39 var $textbox1 = '', $textbox2 = '', $summary = '';
40 var $edittime = '', $section = '', $starttime = '';
41 var $oldid = 0, $editintro = '', $scrolltop = null;
47 function EditPage( $article ) {
48 $this->mArticle
=& $article;
50 $this->mTitle
=& $wgTitle;
54 * Fetch initial editing page content.
56 private function getContent() {
57 global $wgRequest, $wgParser;
59 # Get variables from query string :P
60 $section = $wgRequest->getVal( 'section' );
61 $preload = $wgRequest->getVal( 'preload' );
63 wfProfileIn( __METHOD__
);
66 if( !$this->mTitle
->exists() ) {
68 # If requested, preload some text.
69 $text = $this->getPreloadedText( $preload );
71 # We used to put MediaWiki:Newarticletext here if
72 # $text was empty at this point.
73 # This is now shown above the edit box instead.
75 // FIXME: may be better to use Revision class directly
76 // But don't mess with it just yet. Article knows how to
77 // fetch the page record from the high-priority server,
78 // which is needed to guarantee we don't pick up lagged
81 $text = $this->mArticle
->getContent();
83 if( $section != '' ) {
84 if( $section == 'new' ) {
85 $text = $this->getPreloadedText( $preload );
87 $text = $wgParser->getSection( $text, $section );
92 wfProfileOut( __METHOD__
);
97 * Get the contents of a page from its title and remove includeonly tags
99 * @param $preload String: the title of the page.
100 * @return string The contents of the page.
102 private function getPreloadedText($preload) {
103 if ( $preload === '' )
106 $preloadTitle = Title
::newFromText( $preload );
107 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
108 $rev=Revision
::newFromTitle($preloadTitle);
109 if ( is_object( $rev ) ) {
110 $text = $rev->getText();
111 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
112 // its own mini-parser! -ævar
113 $text = preg_replace( '~</?includeonly>~', '', $text );
122 * This is the function that extracts metadata from the article body on the first view.
123 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
124 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
126 function extractMetaDataFromArticle () {
127 global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
128 $this->mMetaData
= '' ;
129 if ( !$wgUseMetadataEdit ) return ;
130 if ( $wgMetadataWhitelist == '' ) return ;
132 $t = $this->getContent();
134 # MISSING : <nowiki> filtering
136 # Categories and language links
137 $t = explode ( "\n" , $t ) ;
138 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY
) ) ;
139 $cat = $ll = array() ;
140 foreach ( $t AS $key => $x )
142 $y = trim ( strtolower ( $x ) ) ;
143 while ( substr ( $y , 0 , 2 ) == '[[' )
145 $y = explode ( ']]' , trim ( $x ) ) ;
146 $first = array_shift ( $y ) ;
147 $first = explode ( ':' , $first ) ;
148 $ns = array_shift ( $first ) ;
149 $ns = trim ( str_replace ( '[' , '' , $ns ) ) ;
150 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
152 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]' ;
153 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
155 $x = implode ( ']]' , $y ) ;
157 $y = trim ( strtolower ( $x ) ) ;
161 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n" ;
162 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n" ;
163 $t = implode ( "\n" , $t ) ;
166 $sat = array () ; # stand-alone-templates; must be lowercase
167 $wl_title = Title
::newFromText ( $wgMetadataWhitelist ) ;
168 $wl_article = new Article ( $wl_title ) ;
169 $wl = explode ( "\n" , $wl_article->getContent() ) ;
170 foreach ( $wl AS $x )
174 while ( substr ( $x , 0 , 1 ) == '*' )
177 $x = trim ( substr ( $x , 1 ) ) ;
181 $sat[] = strtolower ( $x ) ;
186 # Templates, but only some
187 $t = explode ( '{{' , $t ) ;
189 foreach ( $t AS $key => $x )
191 $y = explode ( '}}' , $x , 2 ) ;
192 if ( count ( $y ) == 2 )
195 $z = explode ( '|' , $z ) ;
196 $tn = array_shift ( $z ) ;
197 if ( in_array ( strtolower ( $tn ) , $sat ) )
199 $tl[] = '{{' . $y[0] . '}}' ;
201 $y = explode ( '}}' , $y[1] , 2 ) ;
203 else $t[$key] = '{{' . $x ;
205 else if ( $key != 0 ) $t[$key] = '{{' . $x ;
208 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl ) ;
209 $t = implode ( '' , $t ) ;
211 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
212 $this->mArticle
->mContent
= $t ;
213 $this->mMetaData
= $s ;
221 * This is the function that gets called for "action=edit". It
222 * sets up various member variables, then passes execution to
223 * another function, usually showEditForm()
225 * The edit form is self-submitting, so that when things like
226 * preview and edit conflicts occur, we get the same form back
227 * with the extra stuff added. Only when the final submission
228 * is made and all is well do we actually save and redirect to
229 * the newly-edited page.
232 global $wgOut, $wgUser, $wgRequest, $wgTitle;
233 global $wgEmailConfirmToEdit;
235 if ( ! wfRunHooks( 'AlternateEdit', array( &$this ) ) )
238 $fname = 'EditPage::edit';
239 wfProfileIn( $fname );
240 wfDebug( "$fname: enter\n" );
242 // this is not an article
243 $wgOut->setArticleFlag(false);
245 $this->importFormData( $wgRequest );
246 $this->firsttime
= false;
249 $this->livePreview();
250 wfProfileOut( $fname );
254 if ( ! $this->mTitle
->userCanEdit() ) {
255 wfDebug( "$fname: user can't edit\n" );
256 $wgOut->readOnlyPage( $this->getContent(), true );
257 wfProfileOut( $fname );
260 wfDebug( "$fname: Checking blocks\n" );
261 if ( !$this->preview
&& !$this->diff
&& $wgUser->isBlockedFrom( $this->mTitle
, !$this->save
) ) {
262 # When previewing, don't check blocked state - will get caught at save time.
263 # Also, check when starting edition is done against slave to improve performance.
264 wfDebug( "$fname: user is blocked\n" );
265 $this->blockedPage();
266 wfProfileOut( $fname );
269 if ( !$wgUser->isAllowed('edit') ) {
270 if ( $wgUser->isAnon() ) {
271 wfDebug( "$fname: user must log in\n" );
272 $this->userNotLoggedInPage();
273 wfProfileOut( $fname );
276 wfDebug( "$fname: read-only page\n" );
277 $wgOut->readOnlyPage( $this->getContent(), true );
278 wfProfileOut( $fname );
282 if ($wgEmailConfirmToEdit && !$wgUser->isEmailConfirmed()) {
283 wfDebug("$fname: user must confirm e-mail address\n");
284 $this->userNotConfirmedPage();
285 wfProfileOut($fname);
288 if ( !$this->mTitle
->userCanCreate() && !$this->mTitle
->exists() ) {
289 wfDebug( "$fname: no create permission\n" );
290 $this->noCreatePermission();
291 wfProfileOut( $fname );
294 if ( wfReadOnly() ) {
295 wfDebug( "$fname: read-only mode is engaged\n" );
296 if( $this->save ||
$this->preview
) {
297 $this->formtype
= 'preview';
298 } else if ( $this->diff
) {
299 $this->formtype
= 'diff';
301 $wgOut->readOnlyPage( $this->getContent() );
302 wfProfileOut( $fname );
307 $this->formtype
= 'save';
308 } else if ( $this->preview
) {
309 $this->formtype
= 'preview';
310 } else if ( $this->diff
) {
311 $this->formtype
= 'diff';
312 } else { # First time through
313 $this->firsttime
= true;
314 if( $this->previewOnOpen() ) {
315 $this->formtype
= 'preview';
317 $this->extractMetaDataFromArticle () ;
318 $this->formtype
= 'initial';
323 wfProfileIn( "$fname-business-end" );
325 $this->isConflict
= false;
326 // css / js subpages of user pages get a special treatment
327 $this->isCssJsSubpage
= $wgTitle->isCssJsSubpage();
328 $this->isValidCssJsSubpage
= $wgTitle->isValidCssJsSubpage();
330 /* Notice that we can't use isDeleted, because it returns true if article is ever deleted
331 * no matter it's current state
333 $this->deletedSinceEdit
= false;
334 if ( $this->edittime
!= '' ) {
335 /* Note that we rely on logging table, which hasn't been always there,
336 * but that doesn't matter, because this only applies to brand new
337 * deletes. This is done on every preview and save request. Move it further down
338 * to only perform it on saves
340 if ( $this->mTitle
->isDeleted() ) {
341 $this->lastDelete
= $this->getLastDelete();
342 if ( !is_null($this->lastDelete
) ) {
343 $deletetime = $this->lastDelete
->log_timestamp
;
344 if ( ($deletetime - $this->starttime
) > 0 ) {
345 $this->deletedSinceEdit
= true;
351 if(!$this->mTitle
->getArticleID() && ('initial' == $this->formtype ||
$this->firsttime
)) { # new article
354 if( $this->mTitle
->isTalkPage() ) {
355 $wgOut->addWikiText( wfMsg( 'talkpagetext' ) );
358 # Attempt submission here. This will check for edit conflicts,
359 # and redundantly check for locked database, blocked IPs, etc.
360 # that edit() already checked just in case someone tries to sneak
361 # in the back door with a hand-edited submission URL.
363 if ( 'save' == $this->formtype
) {
364 if ( !$this->attemptSave() ) {
365 wfProfileOut( "$fname-business-end" );
366 wfProfileOut( $fname );
371 # First time through: get contents, set time for conflict
373 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
374 $this->initialiseForm();
375 if( !$this->mTitle
->getArticleId() )
376 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1
, &$this->mTitle
) );
379 $this->showEditForm();
380 wfProfileOut( "$fname-business-end" );
381 wfProfileOut( $fname );
385 * Return true if this page should be previewed when the edit form
386 * is initially opened.
390 function previewOnOpen() {
392 return $this->section
!= 'new' &&
393 ( ( $wgUser->getOption( 'previewonfirst' ) && $this->mTitle
->exists() ) ||
394 ( $this->mTitle
->getNamespace() == NS_CATEGORY
&&
395 !$this->mTitle
->exists() ) );
402 function importFormData( &$request ) {
403 global $wgLang, $wgUser;
404 $fname = 'EditPage::importFormData';
405 wfProfileIn( $fname );
407 if( $request->wasPosted() ) {
408 # These fields need to be checked for encoding.
409 # Also remove trailing whitespace, but don't remove _initial_
410 # whitespace from the text boxes. This may be significant formatting.
411 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
412 $this->textbox2
= $this->safeUnicodeInput( $request, 'wpTextbox2' );
413 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
414 # Truncate for whole multibyte characters. +5 bytes for ellipsis
415 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
417 $this->edittime
= $request->getVal( 'wpEdittime' );
418 $this->starttime
= $request->getVal( 'wpStarttime' );
420 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
422 if( is_null( $this->edittime
) ) {
423 # If the form is incomplete, force to preview.
424 wfDebug( "$fname: Form data appears to be incomplete\n" );
425 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
426 $this->preview
= true;
428 /* Fallback for live preview */
429 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
430 $this->diff
= $request->getCheck( 'wpDiff' );
432 // Remember whether a save was requested, so we can indicate
433 // if we forced preview due to session failure.
434 $this->mTriedSave
= !$this->preview
;
436 if ( $this->tokenOk( $request ) ) {
437 # Some browsers will not report any submit button
438 # if the user hits enter in the comment box.
439 # The unmarked state will be assumed to be a save,
440 # if the form seems otherwise complete.
441 wfDebug( "$fname: Passed token check.\n" );
442 } else if ( $this->diff
) {
443 # Failed token check, but only requested "Show Changes".
444 wfDebug( "$fname: Failed token check; Show Changes requested.\n" );
446 # Page might be a hack attempt posted from
447 # an external site. Preview instead of saving.
448 wfDebug( "$fname: Failed token check; forcing preview\n" );
449 $this->preview
= true;
452 $this->save
= ! ( $this->preview
OR $this->diff
);
453 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
454 $this->edittime
= null;
457 if( !preg_match( '/^\d{14}$/', $this->starttime
)) {
458 $this->starttime
= null;
461 $this->recreate
= $request->getCheck( 'wpRecreate' );
463 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
464 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
466 # Don't force edit summaries when a user is editing their own user or talk page
467 if( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) && $this->mTitle
->getText() == $wgUser->getName() ) {
468 $this->allowBlankSummary
= true;
470 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' );
473 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
475 # Not a posted form? Start with nothing.
476 wfDebug( "$fname: Not a posted form.\n" );
477 $this->textbox1
= '';
478 $this->textbox2
= '';
479 $this->mMetaData
= '';
481 $this->edittime
= '';
482 $this->starttime
= wfTimestampNow();
483 $this->preview
= false;
486 $this->minoredit
= false;
487 $this->watchthis
= false;
488 $this->recreate
= false;
491 $this->oldid
= $request->getInt( 'oldid' );
493 # Section edit can come from either the form or a link
494 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
496 $this->live
= $request->getCheck( 'live' );
497 $this->editintro
= $request->getText( 'editintro' );
499 wfProfileOut( $fname );
503 * Make sure the form isn't faking a user's credentials.
505 * @param $request WebRequest
509 function tokenOk( &$request ) {
511 if( $wgUser->isAnon() ) {
512 # Anonymous users may not have a session
513 # open. Don't tokenize.
514 $this->mTokenOk
= true;
516 $this->mTokenOk
= $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
518 return $this->mTokenOk
;
522 function showIntro() {
523 global $wgOut, $wgUser;
524 $addstandardintro=true;
525 if($this->editintro
) {
526 $introtitle=Title
::newFromText($this->editintro
);
527 if(isset($introtitle) && $introtitle->userCanRead()) {
528 $rev=Revision
::newFromTitle($introtitle);
530 $wgOut->addSecondaryWikiText($rev->getText());
531 $addstandardintro=false;
535 if($addstandardintro) {
536 if ( $wgUser->isLoggedIn() )
537 $wgOut->addWikiText( wfMsg( 'newarticletext' ) );
539 $wgOut->addWikiText( wfMsg( 'newarticletextanon' ) );
545 * @return bool false if output is done, true if the rest of the form should be displayed
547 function attemptSave() {
548 global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut;
549 global $wgMaxArticleSize;
551 $fname = 'EditPage::attemptSave';
552 wfProfileIn( $fname );
553 wfProfileIn( "$fname-checks" );
555 # Reintegrate metadata
556 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
557 $this->mMetaData
= '' ;
560 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
561 $this->spamPage ( $matches[0] );
562 wfProfileOut( "$fname-checks" );
563 wfProfileOut( $fname );
566 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
567 # Error messages or other handling should be performed by the filter function
568 wfProfileOut( $fname );
569 wfProfileOut( "$fname-checks" );
572 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1
, $this->section
, &$this->hookError
) ) ) {
573 # Error messages etc. could be handled within the hook...
574 wfProfileOut( $fname );
575 wfProfileOut( "$fname-checks" );
577 } elseif( $this->hookError
!= '' ) {
578 # ...or the hook could be expecting us to produce an error
579 wfProfileOut( "$fname-checks " );
580 wfProfileOut( $fname );
583 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
584 # Check block state against master, thus 'false'.
585 $this->blockedPage();
586 wfProfileOut( "$fname-checks" );
587 wfProfileOut( $fname );
590 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
591 if ( $this->kblength
> $wgMaxArticleSize ) {
592 // Error will be displayed by showEditForm()
593 $this->tooBig
= true;
594 wfProfileOut( "$fname-checks" );
595 wfProfileOut( $fname );
599 if ( !$wgUser->isAllowed('edit') ) {
600 if ( $wgUser->isAnon() ) {
601 $this->userNotLoggedInPage();
602 wfProfileOut( "$fname-checks" );
603 wfProfileOut( $fname );
607 $wgOut->readOnlyPage();
608 wfProfileOut( "$fname-checks" );
609 wfProfileOut( $fname );
614 if ( wfReadOnly() ) {
615 $wgOut->readOnlyPage();
616 wfProfileOut( "$fname-checks" );
617 wfProfileOut( $fname );
620 if ( $wgUser->pingLimiter() ) {
621 $wgOut->rateLimited();
622 wfProfileOut( "$fname-checks" );
623 wfProfileOut( $fname );
627 # If the article has been deleted while editing, don't save it without
629 if ( $this->deletedSinceEdit
&& !$this->recreate
) {
630 wfProfileOut( "$fname-checks" );
631 wfProfileOut( $fname );
635 wfProfileOut( "$fname-checks" );
637 # If article is new, insert it.
638 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
640 // Late check for create permission, just in case *PARANOIA*
641 if ( !$this->mTitle
->userCanCreate() ) {
642 wfDebug( "$fname: no create permission\n" );
643 $this->noCreatePermission();
644 wfProfileOut( $fname );
648 # Don't save a new article if it's blank.
649 if ( ( '' == $this->textbox1
) ) {
650 $wgOut->redirect( $this->mTitle
->getFullURL() );
651 wfProfileOut( $fname );
655 $isComment=($this->section
=='new');
656 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
657 $this->minoredit
, $this->watchthis
, false, $isComment);
659 wfProfileOut( $fname );
663 # Article exists. Check for edit conflict.
665 $this->mArticle
->clear(); # Force reload of dates, etc.
666 $this->mArticle
->forUpdate( true ); # Lock the article
668 if( $this->mArticle
->getTimestamp() != $this->edittime
) {
669 $this->isConflict
= true;
670 if( $this->section
== 'new' ) {
671 if( $this->mArticle
->getUserText() == $wgUser->getName() &&
672 $this->mArticle
->getComment() == $this->summary
) {
673 // Probably a duplicate submission of a new comment.
674 // This can happen when squid resends a request after
675 // a timeout but the first one actually went through.
676 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
678 // New comment; suppress conflict.
679 $this->isConflict
= false;
680 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
684 $userid = $wgUser->getID();
686 if ( $this->isConflict
) {
687 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
688 $this->mArticle
->getTimestamp() . "'\n" );
689 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
692 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
693 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
695 if( is_null( $text ) ) {
696 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
697 $this->isConflict
= true;
698 $text = $this->textbox1
;
701 # Suppress edit conflict with self, except for section edits where merging is required.
702 if ( ( $this->section
== '' ) && ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
703 wfDebug( "Suppressing edit conflict, same user.\n" );
704 $this->isConflict
= false;
706 # switch from section editing to normal editing in edit conflict
707 if($this->isConflict
) {
709 if( $this->mergeChangesInto( $text ) ){
710 // Successful merge! Maybe we should tell the user the good news?
711 $this->isConflict
= false;
712 wfDebug( "Suppressing edit conflict, successful merge.\n" );
715 $this->textbox1
= $text;
716 wfDebug( "Keeping edit conflict, failed merge.\n" );
721 if ( $this->isConflict
) {
722 wfProfileOut( $fname );
726 $oldtext = $this->mArticle
->getContent();
728 # Handle the user preference to force summaries here, but not for null edits
729 if( $this->section
!= 'new' && !$this->allowBlankSummary
&& $wgUser->getOption( 'forceeditsummary')
730 && 0 != strcmp($oldtext, $text) ) {
731 if( md5( $this->summary
) == $this->autoSumm
) {
732 $this->missingSummary
= true;
733 wfProfileOut( $fname );
738 #And a similar thing for new sections
739 if( $this->section
== 'new' && !$this->allowBlankSummary
&& $wgUser->getOption( 'forceeditsummary' ) ) {
740 if (trim($this->summary
) == '') {
741 $this->missingSummary
= true;
742 wfProfileOut( $fname );
748 wfProfileIn( "$fname-sectionanchor" );
750 if( $this->section
== 'new' ) {
751 if ( $this->textbox1
== '' ) {
752 $this->missingComment
= true;
755 if( $this->summary
!= '' ) {
756 $sectionanchor = $this->sectionAnchor( $this->summary
);
758 } elseif( $this->section
!= '' ) {
759 # Try to get a section anchor from the section source, redirect to edited section if header found
760 # XXX: might be better to integrate this into Article::replaceSection
761 # for duplicate heading checking and maybe parsing
762 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
763 # we can't deal with anchors, includes, html etc in the header for now,
764 # headline would need to be parsed to improve this
765 if($hasmatch and strlen($matches[2]) > 0) {
766 $sectionanchor = $this->sectionAnchor( $matches[2] );
769 wfProfileOut( "$fname-sectionanchor" );
771 // Save errors may fall down to the edit form, but we've now
772 // merged the section into full text. Clear the section field
773 // so that later submission of conflict forms won't try to
774 // replace that into a duplicated mess.
775 $this->textbox1
= $text;
778 // Check for length errors again now that the section is merged in
779 $this->kblength
= (int)(strlen( $text ) / 1024);
780 if ( $this->kblength
> $wgMaxArticleSize ) {
781 $this->tooBig
= true;
782 wfProfileOut( $fname );
786 # update the article here
787 if( $this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
788 $this->watchthis
, '', $sectionanchor ) ) {
789 wfProfileOut( $fname );
792 $this->isConflict
= true;
794 wfProfileOut( $fname );
799 * Initialise form fields in the object
800 * Called on the first invocation, e.g. when a user clicks an edit link
802 function initialiseForm() {
803 $this->edittime
= $this->mArticle
->getTimestamp();
804 $this->textbox1
= $this->getContent();
806 if ( !$this->mArticle
->exists() && $this->mArticle
->mTitle
->getNamespace() == NS_MEDIAWIKI
)
807 $this->textbox1
= wfMsgWeirdKey( $this->mArticle
->mTitle
->getText() ) ;
812 * Send the edit form and related headers to $wgOut
813 * @param $formCallback Optional callable that takes an OutputPage
814 * parameter; will be called during form output
815 * near the top, for captchas and the like.
817 function showEditForm( $formCallback=null ) {
818 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize;
820 $fname = 'EditPage::showEditForm';
821 wfProfileIn( $fname );
823 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
825 $wgOut->setRobotpolicy( 'noindex,nofollow' );
827 # Enabled article-related sidebar, toplinks, etc.
828 $wgOut->setArticleRelated( true );
830 if ( $this->isConflict
) {
831 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
832 $wgOut->setPageTitle( $s );
833 $wgOut->addWikiText( wfMsg( 'explainconflict' ) );
835 $this->textbox2
= $this->textbox1
;
836 $this->textbox1
= $this->getContent();
837 $this->edittime
= $this->mArticle
->getTimestamp();
840 if( $this->section
!= '' ) {
841 if( $this->section
== 'new' ) {
842 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
844 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
845 if( !$this->summary
&& !$this->preview
&& !$this->diff
) {
846 preg_match( "/^(=+)(.+)\\1/mi",
849 if( !empty( $matches[2] ) ) {
850 $this->summary
= "/* ". trim($matches[2])." */ ";
855 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
857 $wgOut->setPageTitle( $s );
859 if ( $this->missingComment
) {
860 $wgOut->addWikiText( wfMsg( 'missingcommenttext' ) );
863 if( $this->missingSummary
&& $this->section
!= 'new' ) {
864 $wgOut->addWikiText( wfMsg( 'missingsummary' ) );
867 if( $this->missingSummary
&& $this->section
== 'new' ) {
868 $wgOut->addWikiText( wfMsg( 'missingcommentheader' ) );
871 if( !$this->hookError
== '' ) {
872 $wgOut->addWikiText( $this->hookError
);
875 if ( !$this->checkUnicodeCompliantBrowser() ) {
876 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
878 if ( isset( $this->mArticle
)
879 && isset( $this->mArticle
->mRevision
)
880 && !$this->mArticle
->mRevision
->isCurrent() ) {
881 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
882 $wgOut->addWikiText( wfMsg( 'editingold' ) );
887 $wgOut->addWikiText( wfMsg( 'readonlywarning' ) );
888 } elseif( $wgUser->isAnon() && $this->formtype
!= 'preview' ) {
889 $wgOut->addWikiText( wfMsg( 'anoneditwarning' ) );
891 if( $this->isCssJsSubpage
&& $this->formtype
!= 'preview' ) {
892 # Check the skin exists
893 if( $this->isValidCssJsSubpage
) {
894 $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ) );
896 $wgOut->addWikiText( wfMsg( 'userinvalidcssjstitle', $this->mTitle
->getSkinFromCssJsSubpage() ) );
901 if( $this->mTitle
->isProtected( 'edit' ) ) {
902 # Is the protection due to the namespace, e.g. interface text?
903 if( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
904 # Yes; remind the user
905 $notice = wfMsg( 'editinginterface' );
906 } elseif( $this->mTitle
->isSemiProtected() ) {
908 $notice = wfMsg( 'semiprotectedpagewarning' );
909 if( wfEmptyMsg( 'semiprotectedpagewarning', $notice ) ||
$notice == '-' ) {
913 # No; regular protection
914 $notice = wfMsg( 'protectedpagewarning' );
916 $wgOut->addWikiText( $notice );
919 if ( $this->kblength
=== false ) {
920 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
922 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
923 $wgOut->addWikiText( wfMsg( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgMaxArticleSize ) );
924 } elseif( $this->kblength
> 29 ) {
925 $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength
) ) );
928 $rows = $wgUser->getIntOption( 'rows' );
929 $cols = $wgUser->getIntOption( 'cols' );
931 $ew = $wgUser->getOption( 'editwidth' );
932 if ( $ew ) $ew = " style=\"width:100%\"";
935 $q = 'action=submit';
936 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
937 $action = $this->mTitle
->escapeLocalURL( $q );
939 $summary = wfMsg('summary');
940 $subject = wfMsg('subject');
941 $minor = wfMsgExt('minoredit', array('parseinline'));
942 $watchthis = wfMsgExt('watchthis', array('parseinline'));
944 $cancel = Linker
::makeKnownLink( $this->mTitle
->getPrefixedText(),
945 wfMsgExt('cancel', array('parseinline')) );
946 $edithelpurl = Skin
::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
947 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
948 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
949 htmlspecialchars( wfMsg( 'newwindow' ) );
951 global $wgRightsText;
952 $copywarn = "<div id=\"editpage-copywarn\">\n" .
953 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
954 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
955 $wgRightsText ) . "\n</div>";
957 if( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage
) {
958 # prepare toolbar for edit buttons
959 $toolbar = $this->getEditToolbar();
964 // activate checkboxes if user wants them to be always active
965 if( !$this->preview
&& !$this->diff
) {
966 # Sort out the "watch" checkbox
967 if( $wgUser->getOption( 'watchdefault' ) ) {
969 $this->watchthis
= true;
970 } elseif( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
972 $this->watchthis
= true;
973 } elseif( $this->mTitle
->userIsWatching() ) {
975 $this->watchthis
= true;
978 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
983 if ( $wgUser->isAllowed('minoredit') ) {
985 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
986 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />\n".
987 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>\n";
992 if ( $wgUser->isLoggedIn() ) {
993 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".
994 ($this->watchthis?
" checked='checked'":"").
995 " accesskey=\"".htmlspecialchars(wfMsg('accesskey-watch'))."\" id='wpWatchthis' />\n".
996 "<label for='wpWatchthis' title=\"" .
997 htmlspecialchars(wfMsg('tooltip-watch'))."\">{$watchthis}</label>\n";
1000 $checkboxhtml = $minoredithtml . $watchhtml;
1002 if ( $wgUser->getOption( 'previewontop' ) ) {
1004 if ( 'preview' == $this->formtype
) {
1005 $this->showPreview();
1007 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
1010 if ( 'diff' == $this->formtype
) {
1011 $wgOut->addHTML( $this->getDiff() );
1016 # if this is a comment, show a subject line at the top, which is also the edit summary.
1017 # Otherwise, show a summary field at the bottom
1018 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
1019 if( $this->section
== 'new' ) {
1020 $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 />";
1023 $commentsubject = '';
1024 $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 />";
1027 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
1028 if( !$this->preview
&& !$this->diff
) {
1029 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
1031 $templates = $this->formatTemplates();
1033 global $wgUseMetadataEdit ;
1034 if ( $wgUseMetadataEdit ) {
1035 $metadata = $this->mMetaData
;
1036 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
1037 $top = wfMsgWikiHtml( 'metadata_help' );
1038 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
1040 else $metadata = "" ;
1044 if ($this->deletedSinceEdit
) {
1045 if ( 'save' != $this->formtype
) {
1046 $wgOut->addWikiText( wfMsg('deletedwhileediting'));
1048 // Hide the toolbar and edit area, use can click preview to get it back
1049 // Add an confirmation checkbox and explanation.
1051 $hidden = 'type="hidden" style="display:none;"';
1052 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete
->user_name
, $this->lastDelete
->log_comment
));
1054 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
1055 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
1064 'value' => wfMsg('savearticle'),
1065 'accesskey' => wfMsg('accesskey-save'),
1066 'title' => wfMsg('tooltip-save'),
1068 $buttons['save'] = wfElement('input', $temp, '');
1074 'value' => wfMsg('showdiff'),
1075 'accesskey' => wfMsg('accesskey-diff'),
1076 'title' => wfMsg('tooltip-diff'),
1078 $buttons['diff'] = wfElement('input', $temp, '');
1080 global $wgLivePreview;
1081 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
1083 'id' => 'wpPreview',
1084 'name' => 'wpPreview',
1087 'value' => wfMsg('showpreview'),
1089 'title' => wfMsg('tooltip-preview'),
1090 'style' => 'display: none;',
1092 $buttons['preview'] = wfElement('input', $temp, '');
1094 'id' => 'wpLivePreview',
1095 'name' => 'wpLivePreview',
1098 'value' => wfMsg('showlivepreview'),
1099 'accesskey' => wfMsg('accesskey-preview'),
1101 'onclick' => $this->doLivePreviewScript(),
1103 $buttons['live'] = wfElement('input', $temp, '');
1106 'id' => 'wpPreview',
1107 'name' => 'wpPreview',
1110 'value' => wfMsg('showpreview'),
1111 'accesskey' => wfMsg('accesskey-preview'),
1112 'title' => wfMsg('tooltip-preview'),
1114 $buttons['preview'] = wfElement('input', $temp, '');
1115 $buttons['live'] = '';
1118 $safemodehtml = $this->checkUnicodeCompliantBrowser()
1120 : "<input type='hidden' name=\"safemode\" value='1' />\n";
1122 $wgOut->addHTML( <<<END
1124 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1128 if( is_callable( $formCallback ) ) {
1129 call_user_func_array( $formCallback, array( &$wgOut ) );
1132 // Put these up at the top to ensure they aren't lost on early form submission
1134 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
1135 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1136 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1137 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
1139 $wgOut->addHTML( <<<END
1142 <textarea tabindex='1' accesskey="," name="wpTextbox1" id="wpTextbox1" rows='{$rows}'
1143 cols='{$cols}'{$ew} $hidden>
1145 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1
) ) .
1150 $wgOut->addWikiText( $copywarn );
1159 "<div class='editButtons'>
1161 {$buttons['preview']}
1164 <span class='editHelp'>{$cancel} | {$edithelp}</span>
1165 </div><!-- editButtons -->
1166 </div><!-- editOptions -->");
1168 $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
1171 <div class='templatesUsed'>
1176 if ( $wgUser->isLoggedIn() ) {
1178 * To make it harder for someone to slip a user a page
1179 * which submits an edit form to the wiki without their
1180 * knowledge, a random token is associated with the login
1181 * session. If it's not passed back with the submission,
1182 * we won't save the page, or render user JavaScript and
1185 $token = htmlspecialchars( $wgUser->editToken() );
1186 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1189 # If a blank edit summary was previously provided, and the appropriate
1190 # user preference is active, pass a hidden tag here. This will stop the
1191 # user being bounced back more than once in the event that a summary
1193 if( $this->missingSummary
) {
1194 $wgOut->addHTML( "<input type=\"hidden\" name=\"wpIgnoreBlankSummary\" value=\"1\" />\n" );
1197 # For a bit more sophisticated detection of blank summaries, hash the
1198 # automatic one and pass that in a hidden field.
1199 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
1200 $wgOut->addHtml( wfHidden( 'wpAutoSummary', $autosumm ) );
1202 if ( $this->isConflict
) {
1203 $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' );
1205 $de = new DifferenceEngine( $this->mTitle
);
1206 $de->setText( $this->textbox2
, $this->textbox1
);
1207 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1209 $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
1210 $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
1211 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2
) ) . "\n</textarea>" );
1213 $wgOut->addHTML( "</form>\n" );
1214 if ( !$wgUser->getOption( 'previewontop' ) ) {
1216 if ( $this->formtype
== 'preview') {
1217 $this->showPreview();
1219 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
1222 if ( $this->formtype
== 'diff') {
1223 $wgOut->addHTML( $this->getDiff() );
1228 wfProfileOut( $fname );
1232 * Append preview output to $wgOut.
1233 * Includes category rendering if this is a category page.
1236 function showPreview() {
1238 $wgOut->addHTML( '<div id="wikiPreview">' );
1239 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1240 $this->mArticle
->openShowCategory();
1242 $previewOutput = $this->getPreviewText();
1243 $wgOut->addHTML( $previewOutput );
1244 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1245 $this->mArticle
->closeShowCategory();
1247 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
1248 $wgOut->addHTML( '</div>' );
1252 * Prepare a list of templates used by this page. Returns HTML.
1254 function formatTemplates() {
1255 $fname = 'EditPage::formatTemplates';
1256 wfProfileIn( $fname );
1259 $templates = $this->mArticle
->getUsedTemplates();
1260 if ( count( $templates ) > 0 ) {
1261 # Do a batch existence check
1262 $batch = new LinkBatch
;
1263 foreach( $templates as $title ) {
1264 $batch->addObj( $title );
1268 # Construct the HTML
1269 $outText = '<div class="mw-templatesUsedExplanation">' .
1270 wfMsgExt( 'templatesused', array( 'parse' ) ) .
1272 foreach ( $templates as $titleObj ) {
1273 $outText .= '<li>' . Linker
::makeLinkObj( $titleObj ) . '</li>';
1275 $outText .= '</ul>';
1277 wfProfileOut( $fname );
1282 * Live Preview lets us fetch rendered preview page content and
1283 * add it to the page without refreshing the whole page.
1284 * If not supported by the browser it will fall through to the normal form
1285 * submission method.
1287 * This function outputs a script tag to support live preview, and
1288 * returns an onclick handler which should be added to the attributes
1289 * of the preview button
1291 function doLivePreviewScript() {
1292 global $wgStylePath, $wgJsMimeType, $wgStyleVersion, $wgOut, $wgTitle;
1293 $wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' .
1294 htmlspecialchars( "$wgStylePath/common/preview.js?$wgStyleVersion" ) .
1295 '"></script>' . "\n" );
1296 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
1297 return "return !livePreview(" .
1298 "getElementById('wikiPreview')," .
1299 "editform.wpTextbox1.value," .
1300 '"' . $liveAction . '"' . ")";
1303 function getLastDelete() {
1304 $dbr =& wfGetDB( DB_SLAVE
);
1305 $fname = 'EditPage::getLastDelete';
1306 $res = $dbr->select(
1307 array( 'logging', 'user' ),
1317 array( 'log_namespace' => $this->mTitle
->getNamespace(),
1318 'log_title' => $this->mTitle
->getDBkey(),
1319 'log_type' => 'delete',
1320 'log_action' => 'delete',
1321 'user_id=log_user' ),
1323 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1325 if($dbr->numRows($res) == 1) {
1326 while ( $x = $dbr->fetchObject ( $res ) )
1328 $dbr->freeResult ( $res ) ;
1338 function getPreviewText() {
1339 global $wgOut, $wgUser, $wgTitle, $wgParser;
1341 $fname = 'EditPage::getPreviewText';
1342 wfProfileIn( $fname );
1344 if ( $this->mTriedSave
&& !$this->mTokenOk
) {
1345 $msg = 'session_fail_preview';
1347 $msg = 'previewnote';
1349 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1350 "<div class='previewnote'>" . $wgOut->parse( wfMsg( $msg ) ) . "</div>\n";
1351 if ( $this->isConflict
) {
1352 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1355 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1356 $parserOptions->setEditSection( false );
1359 if( $wgRawHtml && !$this->mTokenOk
) {
1360 // Could be an offsite preview attempt. This is very unsafe if
1361 // HTML is enabled, as it could be an attack.
1362 return $wgOut->parse( "<div class='previewnote'>" .
1363 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1366 # don't parse user css/js, show message about preview
1367 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1369 if ( $this->isCssJsSubpage
) {
1370 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
1371 $previewtext = wfMsg('usercsspreview');
1372 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
1373 $previewtext = wfMsg('userjspreview');
1375 $parserOptions->setTidy(true);
1376 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
1377 $wgOut->addHTML( $parserOutput->mText
);
1378 wfProfileOut( $fname );
1379 return $previewhead;
1381 $toparse = $this->textbox1
;
1383 # If we're adding a comment, we need to show the
1384 # summary as the headline
1385 if($this->section
=="new" && $this->summary
!="") {
1386 $toparse="== {$this->summary} ==\n\n".$toparse;
1389 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
1390 $parserOptions->setTidy(true);
1391 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
1392 $wgTitle, $parserOptions );
1394 $previewHTML = $parserOutput->getText();
1395 $wgOut->addParserOutputNoText( $parserOutput );
1397 wfProfileOut( $fname );
1398 return $previewhead . $previewHTML;
1403 * Call the stock "user is blocked" page
1405 function blockedPage() {
1406 global $wgOut, $wgUser;
1407 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
1409 # If the user made changes, preserve them when showing the markup
1410 # (This happens when a user is blocked during edit, for instance)
1411 $first = $this->firsttime ||
( !$this->save
&& $this->textbox1
== '' );
1413 $source = $this->mTitle
->exists() ?
$this->getContent() : false;
1415 $source = $this->textbox1
;
1418 # Spit out the source or the user's modified version
1419 if( $source !== false ) {
1420 $rows = $wgUser->getOption( 'rows' );
1421 $cols = $wgUser->getOption( 'cols' );
1422 $attribs = array( 'id' => 'wpTextbox1', 'name' => 'wpTextbox1', 'cols' => $cols, 'rows' => $rows, 'readonly' => 'readonly' );
1423 $wgOut->addHtml( '<hr />' );
1424 $wgOut->addWikiText( wfMsg( $first ?
'blockedoriginalsource' : 'blockededitsource', $this->mTitle
->getPrefixedText() ) );
1425 $wgOut->addHtml( wfOpenElement( 'textarea', $attribs ) . htmlspecialchars( $source ) . wfCloseElement( 'textarea' ) );
1430 * Produce the stock "please login to edit pages" page
1432 function userNotLoggedInPage() {
1435 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1436 $loginLink = Linker
::makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $this->mTitle
->getPrefixedUrl() );
1438 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1439 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1440 $wgOut->setArticleRelated( false );
1442 $wgOut->addHtml( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1443 $wgOut->returnToMain( false, $this->mTitle
->getPrefixedUrl() );
1447 * Creates a basic error page which informs the user that
1448 * they have to validate their email address before being
1451 function userNotConfirmedPage() {
1454 $wgOut->setPageTitle( wfMsg( 'confirmedittitle' ) );
1455 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1456 $wgOut->setArticleRelated( false );
1458 $wgOut->addWikiText( wfMsg( 'confirmedittext' ) );
1459 $wgOut->returnToMain( false );
1463 * Produce the stock "your edit contains spam" page
1465 * @param $match Text which triggered one or more filters
1467 function spamPage( $match = false ) {
1470 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1471 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1472 $wgOut->setArticleRelated( false );
1474 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
1476 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
1478 $wgOut->returnToMain( false );
1485 function mergeChangesInto( &$editText ){
1486 $fname = 'EditPage::mergeChangesInto';
1487 wfProfileIn( $fname );
1489 $db =& wfGetDB( DB_MASTER
);
1491 // This is the revision the editor started from
1492 $baseRevision = Revision
::loadFromTimestamp(
1493 $db, $this->mArticle
->mTitle
, $this->edittime
);
1494 if( is_null( $baseRevision ) ) {
1495 wfProfileOut( $fname );
1498 $baseText = $baseRevision->getText();
1500 // The current state, we want to merge updates into it
1501 $currentRevision = Revision
::loadFromTitle(
1502 $db, $this->mArticle
->mTitle
);
1503 if( is_null( $currentRevision ) ) {
1504 wfProfileOut( $fname );
1507 $currentText = $currentRevision->getText();
1509 if( wfMerge( $baseText, $editText, $currentText, $result ) ){
1510 $editText = $result;
1511 wfProfileOut( $fname );
1514 wfProfileOut( $fname );
1520 * Check if the browser is on a blacklist of user-agents known to
1521 * mangle UTF-8 data on form submission. Returns true if Unicode
1522 * should make it through, false if it's known to be a problem.
1526 function checkUnicodeCompliantBrowser() {
1527 global $wgBrowserBlackList;
1528 if( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1529 // No User-Agent header sent? Trust it by default...
1532 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1533 foreach ( $wgBrowserBlackList as $browser ) {
1534 if ( preg_match($browser, $currentbrowser) ) {
1542 * Format an anchor fragment as it would appear for a given section name
1543 * @param string $text
1547 function sectionAnchor( $text ) {
1548 $headline = Sanitizer
::decodeCharReferences( $text );
1550 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
1551 $headline = trim( $headline );
1552 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
1553 $replacearray = array(
1558 array_keys( $replacearray ),
1559 array_values( $replacearray ),
1564 * Shows a bulletin board style toolbar for common editing functions.
1565 * It can be disabled in the user preferences.
1566 * The necessary JavaScript code can be found in style/wikibits.js.
1568 function getEditToolbar() {
1569 global $wgStylePath, $wgContLang, $wgJsMimeType;
1572 * toolarray an array of arrays which each include the filename of
1573 * the button image (without path), the opening tag, the closing tag,
1574 * and optionally a sample text that is inserted between the two when no
1575 * selection is highlighted.
1576 * The tip text is shown when the user moves the mouse over the button.
1578 * Already here are accesskeys (key), which are not used yet until someone
1579 * can figure out a way to make them work in IE. However, we should make
1580 * sure these keys are not defined on the edit page.
1583 array( 'image'=>'button_bold.png',
1585 'close' => "\'\'\'",
1586 'sample'=> wfMsg('bold_sample'),
1587 'tip' => wfMsg('bold_tip'),
1590 array( 'image'=>'button_italic.png',
1593 'sample'=> wfMsg('italic_sample'),
1594 'tip' => wfMsg('italic_tip'),
1597 array( 'image'=>'button_link.png',
1600 'sample'=> wfMsg('link_sample'),
1601 'tip' => wfMsg('link_tip'),
1604 array( 'image'=>'button_extlink.png',
1607 'sample'=> wfMsg('extlink_sample'),
1608 'tip' => wfMsg('extlink_tip'),
1611 array( 'image'=>'button_headline.png',
1613 'close' => " ==\\n",
1614 'sample'=> wfMsg('headline_sample'),
1615 'tip' => wfMsg('headline_tip'),
1618 array( 'image'=>'button_image.png',
1619 'open' => '[['.$wgContLang->getNsText(NS_IMAGE
).":",
1621 'sample'=> wfMsg('image_sample'),
1622 'tip' => wfMsg('image_tip'),
1625 array( 'image' =>'button_media.png',
1626 'open' => '[['.$wgContLang->getNsText(NS_MEDIA
).':',
1628 'sample'=> wfMsg('media_sample'),
1629 'tip' => wfMsg('media_tip'),
1632 array( 'image' =>'button_math.png',
1634 'close' => "<\\/math>",
1635 'sample'=> wfMsg('math_sample'),
1636 'tip' => wfMsg('math_tip'),
1639 array( 'image' =>'button_nowiki.png',
1640 'open' => "<nowiki>",
1641 'close' => "<\\/nowiki>",
1642 'sample'=> wfMsg('nowiki_sample'),
1643 'tip' => wfMsg('nowiki_tip'),
1646 array( 'image' =>'button_sig.png',
1650 'tip' => wfMsg('sig_tip'),
1653 array( 'image' =>'button_hr.png',
1654 'open' => "\\n----\\n",
1657 'tip' => wfMsg('hr_tip'),
1661 $toolbar = "<div id='toolbar'>\n";
1662 $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
1664 foreach($toolarray as $tool) {
1666 $image=$wgStylePath.'/common/images/'.$tool['image'];
1667 $open=$tool['open'];
1668 $close=$tool['close'];
1669 $sample = wfEscapeJsString( $tool['sample'] );
1671 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1672 // Older browsers show a "speedtip" type message only for ALT.
1673 // Ideally these should be different, realistically they
1674 // probably don't need to be.
1675 $tip = wfEscapeJsString( $tool['tip'] );
1677 #$key = $tool["key"];
1679 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
1682 $toolbar.="/*]]>*/\n</script>";
1683 $toolbar.="\n</div>";
1688 * Output preview text only. This can be sucked into the edit page
1689 * via JavaScript, and saves the server time rendering the skin as
1690 * well as theoretically being more robust on the client (doesn't
1691 * disturb the edit box's undo history, won't eat your text on
1694 * @todo This doesn't include category or interlanguage links.
1695 * Would need to enhance it a bit, maybe wrap them in XML
1696 * or something... that might also require more skin
1697 * initialization, so check whether that's a problem.
1699 function livePreview() {
1702 header( 'Content-type: text/xml' );
1703 header( 'Cache-control: no-cache' );
1705 echo $this->getPreviewText( );
1706 /* To not shake screen up and down between preview and live-preview */
1707 echo "<br style=\"clear:both;\" />\n";
1712 * Get a diff between the current contents of the edit box and the
1713 * version of the page we're editing from.
1715 * If this is a section edit, we'll replace the section as for final
1716 * save and then make a comparison.
1718 * @return string HTML
1720 function getDiff() {
1721 $oldtext = $this->mArticle
->fetchContent();
1722 $newtext = $this->mArticle
->replaceSection(
1723 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1724 $newtext = $this->mArticle
->preSaveTransform( $newtext );
1725 $oldtitle = wfMsgExt( 'currentrev', array('parseinline') );
1726 $newtitle = wfMsgExt( 'yourtext', array('parseinline') );
1727 if ( $oldtext !== false ||
$newtext != '' ) {
1728 $de = new DifferenceEngine( $this->mTitle
);
1729 $de->setText( $oldtext, $newtext );
1730 $difftext = $de->getDiff( $oldtitle, $newtitle );
1735 return '<div id="wikiDiff">' . $difftext . '</div>';
1739 * Filter an input field through a Unicode de-armoring process if it
1740 * came from an old browser with known broken Unicode editing issues.
1742 * @param WebRequest $request
1743 * @param string $field
1747 function safeUnicodeInput( $request, $field ) {
1748 $text = rtrim( $request->getText( $field ) );
1749 return $request->getBool( 'safemode' )
1750 ?
$this->unmakesafe( $text )
1755 * Filter an output field through a Unicode armoring process if it is
1756 * going to an old browser with known broken Unicode editing issues.
1758 * @param string $text
1762 function safeUnicodeOutput( $text ) {
1764 $codedText = $wgContLang->recodeForEdit( $text );
1765 return $this->checkUnicodeCompliantBrowser()
1767 : $this->makesafe( $codedText );
1771 * A number of web browsers are known to corrupt non-ASCII characters
1772 * in a UTF-8 text editing environment. To protect against this,
1773 * detected browsers will be served an armored version of the text,
1774 * with non-ASCII chars converted to numeric HTML character references.
1776 * Preexisting such character references will have a 0 added to them
1777 * to ensure that round-trips do not alter the original data.
1779 * @param string $invalue
1783 function makesafe( $invalue ) {
1784 // Armor existing references for reversability.
1785 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
1790 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1791 $bytevalue = ord( $invalue{$i} );
1792 if( $bytevalue <= 0x7F ) { //0xxx xxxx
1793 $result .= chr( $bytevalue );
1795 } elseif( $bytevalue <= 0xBF ) { //10xx xxxx
1796 $working = $working << 6;
1797 $working +
= ($bytevalue & 0x3F);
1799 if( $bytesleft <= 0 ) {
1800 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
1802 } elseif( $bytevalue <= 0xDF ) { //110x xxxx
1803 $working = $bytevalue & 0x1F;
1805 } elseif( $bytevalue <= 0xEF ) { //1110 xxxx
1806 $working = $bytevalue & 0x0F;
1808 } else { //1111 0xxx
1809 $working = $bytevalue & 0x07;
1817 * Reverse the previously applied transliteration of non-ASCII characters
1818 * back to UTF-8. Used to protect data from corruption by broken web browsers
1819 * as listed in $wgBrowserBlackList.
1821 * @param string $invalue
1825 function unmakesafe( $invalue ) {
1827 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1828 if( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+
3} != '0' ) ) {
1832 $hexstring .= $invalue{$i};
1834 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
1836 // Do some sanity checks. These aren't needed for reversability,
1837 // but should help keep the breakage down if the editor
1838 // breaks one of the entities whilst editing.
1839 if ((substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6)) {
1840 $codepoint = hexdec($hexstring);
1841 $result .= codepointToUtf8( $codepoint );
1843 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
1846 $result .= substr( $invalue, $i, 1 );
1849 // reverse the transform that we made for reversability reasons.
1850 return strtr( $result, array( "�" => "&#x" ) );
1853 function noCreatePermission() {
1855 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
1856 $wgOut->addWikiText( wfMsg( 'nocreatetext' ) );