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;
28 var $kblength = false;
31 var $save = false, $preview = false, $diff = false;
32 var $minoredit = false, $watchthis = false, $recreate = false;
33 var $textbox1 = '', $textbox2 = '', $summary = '';
34 var $edittime = '', $section = '', $starttime = '';
35 var $oldid = 0, $editintro = '', $scrolltop = null;
41 function EditPage( $article ) {
42 $this->mArticle
=& $article;
44 $this->mTitle
=& $wgTitle;
48 * This is the function that extracts metadata from the article body on the first view.
49 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
50 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
52 function extractMetaDataFromArticle () {
53 global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
54 $this->mMetaData
= '' ;
55 if ( !$wgUseMetadataEdit ) return ;
56 if ( $wgMetadataWhitelist == '' ) return ;
58 $t = $this->mArticle
->getContent();
60 # MISSING : <nowiki> filtering
62 # Categories and language links
63 $t = explode ( "\n" , $t ) ;
64 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY
) ) ;
65 $cat = $ll = array() ;
66 foreach ( $t AS $key => $x )
68 $y = trim ( strtolower ( $x ) ) ;
69 while ( substr ( $y , 0 , 2 ) == '[[' )
71 $y = explode ( ']]' , trim ( $x ) ) ;
72 $first = array_shift ( $y ) ;
73 $first = explode ( ':' , $first ) ;
74 $ns = array_shift ( $first ) ;
75 $ns = trim ( str_replace ( '[' , '' , $ns ) ) ;
76 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
78 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]' ;
79 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
81 $x = implode ( ']]' , $y ) ;
83 $y = trim ( strtolower ( $x ) ) ;
87 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n" ;
88 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n" ;
89 $t = implode ( "\n" , $t ) ;
92 $sat = array () ; # stand-alone-templates; must be lowercase
93 $wl_title = Title
::newFromText ( $wgMetadataWhitelist ) ;
94 $wl_article = new Article ( $wl_title ) ;
95 $wl = explode ( "\n" , $wl_article->getContent() ) ;
100 while ( substr ( $x , 0 , 1 ) == '*' )
103 $x = trim ( substr ( $x , 1 ) ) ;
107 $sat[] = strtolower ( $x ) ;
112 # Templates, but only some
113 $t = explode ( '{{' , $t ) ;
115 foreach ( $t AS $key => $x )
117 $y = explode ( '}}' , $x , 2 ) ;
118 if ( count ( $y ) == 2 )
121 $z = explode ( '|' , $z ) ;
122 $tn = array_shift ( $z ) ;
123 if ( in_array ( strtolower ( $tn ) , $sat ) )
125 $tl[] = '{{' . $y[0] . '}}' ;
127 $y = explode ( '}}' , $y[1] , 2 ) ;
129 else $t[$key] = '{{' . $x ;
131 else if ( $key != 0 ) $t[$key] = '{{' . $x ;
134 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl ) ;
135 $t = implode ( '' , $t ) ;
137 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
138 $this->mArticle
->mContent
= $t ;
139 $this->mMetaData
= $s ;
147 * This is the function that gets called for "action=edit". It
148 * sets up various member variables, then passes execution to
149 * another function, usually showEditForm()
151 * The edit form is self-submitting, so that when things like
152 * preview and edit conflicts occur, we get the same form back
153 * with the extra stuff added. Only when the final submission
154 * is made and all is well do we actually save and redirect to
155 * the newly-edited page.
158 global $wgOut, $wgUser, $wgRequest, $wgTitle,
159 $wgEmailConfirmToEdit;
161 if ( ! wfRunHooks( 'AlternateEdit', array( &$this ) ) )
164 $fname = 'EditPage::edit';
165 wfProfileIn( $fname );
166 wfDebug( "$fname: enter\n" );
168 // this is not an article
169 $wgOut->setArticleFlag(false);
171 $this->importFormData( $wgRequest );
172 $this->firsttime
= false;
175 $this->livePreview();
176 wfProfileOut( $fname );
180 if ( ! $this->mTitle
->userCanEdit() ) {
181 wfDebug( "$fname: user can't edit\n" );
182 $wgOut->readOnlyPage( $this->mArticle
->getContent(), true );
183 wfProfileOut( $fname );
186 wfDebug( "$fname: Checking blocks\n" );
187 if ( !$this->preview
&& !$this->diff
&& $wgUser->isBlockedFrom( $this->mTitle
, !$this->save
) ) {
188 # When previewing, don't check blocked state - will get caught at save time.
189 # Also, check when starting edition is done against slave to improve performance.
190 wfDebug( "$fname: user is blocked\n" );
191 $wgOut->blockedPage();
192 wfProfileOut( $fname );
195 if ( !$wgUser->isAllowed('edit') ) {
196 if ( $wgUser->isAnon() ) {
197 wfDebug( "$fname: user must log in\n" );
198 $this->userNotLoggedInPage();
199 wfProfileOut( $fname );
202 wfDebug( "$fname: read-only page\n" );
203 $wgOut->readOnlyPage( $this->mArticle
->getContent(), true );
204 wfProfileOut( $fname );
208 if ($wgEmailConfirmToEdit && !$wgUser->isEmailConfirmed()) {
209 wfDebug("$fname: user must confirm e-mail address\n");
210 $this->userNotConfirmedPage();
211 wfProfileOut($fname);
214 if ( !$this->mTitle
->userCan( 'create' ) && !$this->mTitle
->exists() ) {
215 wfDebug( "$fname: no create permission\n" );
216 $this->noCreatePermission();
217 wfProfileOut( $fname );
220 if ( wfReadOnly() ) {
221 wfDebug( "$fname: read-only mode is engaged\n" );
222 if( $this->save ||
$this->preview
) {
223 $this->formtype
= 'preview';
224 } else if ( $this->diff
) {
225 $this->formtype
= 'diff';
227 $wgOut->readOnlyPage( $this->mArticle
->getContent() );
228 wfProfileOut( $fname );
233 $this->formtype
= 'save';
234 } else if ( $this->preview
) {
235 $this->formtype
= 'preview';
236 } else if ( $this->diff
) {
237 $this->formtype
= 'diff';
238 } else { # First time through
239 $this->firsttime
= true;
240 if( $this->previewOnOpen() ) {
241 $this->formtype
= 'preview';
243 $this->extractMetaDataFromArticle () ;
244 $this->formtype
= 'initial';
249 wfProfileIn( "$fname-business-end" );
251 $this->isConflict
= false;
252 // css / js subpages of user pages get a special treatment
253 $this->isCssJsSubpage
= $wgTitle->isCssJsSubpage();
255 /* Notice that we can't use isDeleted, because it returns true if article is ever deleted
256 * no matter it's current state
258 $this->deletedSinceEdit
= false;
259 if ( $this->edittime
!= '' ) {
260 /* Note that we rely on logging table, which hasn't been always there,
261 * but that doesn't matter, because this only applies to brand new
262 * deletes. This is done on every preview and save request. Move it further down
263 * to only perform it on saves
265 if ( $this->mTitle
->isDeleted() ) {
266 $this->lastDelete
= $this->getLastDelete();
267 if ( !is_null($this->lastDelete
) ) {
268 $deletetime = $this->lastDelete
->log_timestamp
;
269 if ( ($deletetime - $this->starttime
) > 0 ) {
270 $this->deletedSinceEdit
= true;
276 if(!$this->mTitle
->getArticleID() && ('initial' == $this->formtype ||
$this->firsttime
)) { # new article
279 if( $this->mTitle
->isTalkPage() ) {
280 $wgOut->addWikiText( wfMsg( 'talkpagetext' ) );
283 # Attempt submission here. This will check for edit conflicts,
284 # and redundantly check for locked database, blocked IPs, etc.
285 # that edit() already checked just in case someone tries to sneak
286 # in the back door with a hand-edited submission URL.
288 if ( 'save' == $this->formtype
) {
289 if ( !$this->attemptSave() ) {
290 wfProfileOut( "$fname-business-end" );
291 wfProfileOut( $fname );
296 # First time through: get contents, set time for conflict
298 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
299 $this->initialiseForm();
302 $this->showEditForm();
303 wfProfileOut( "$fname-business-end" );
304 wfProfileOut( $fname );
308 * Return true if this page should be previewed when the edit form
309 * is initially opened.
313 function previewOnOpen() {
315 return $this->section
!= 'new' &&
316 ( ( $wgUser->getOption( 'previewonfirst' ) && $this->mTitle
->exists() ) ||
317 ( $this->mTitle
->getNamespace() == NS_CATEGORY
&&
318 !$this->mTitle
->exists() ) );
324 function importFormData( &$request ) {
326 $fname = 'EditPage::importFormData';
327 wfProfileIn( $fname );
329 if( $request->wasPosted() ) {
330 # These fields need to be checked for encoding.
331 # Also remove trailing whitespace, but don't remove _initial_
332 # whitespace from the text boxes. This may be significant formatting.
333 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
334 $this->textbox2
= $this->safeUnicodeInput( $request, 'wpTextbox2' );
335 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
336 # Truncate for whole multibyte characters. +5 bytes for ellipsis
337 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
339 $this->edittime
= $request->getVal( 'wpEdittime' );
340 $this->starttime
= $request->getVal( 'wpStarttime' );
342 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
344 if( is_null( $this->edittime
) ) {
345 # If the form is incomplete, force to preview.
346 wfDebug( "$fname: Form data appears to be incomplete\n" );
347 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
348 $this->preview
= true;
350 /* Fallback for live preview */
351 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
352 $this->diff
= $request->getCheck( 'wpDiff' );
354 if( !$this->preview
) {
355 if ( $this->tokenOk( $request ) ) {
356 # Some browsers will not report any submit button
357 # if the user hits enter in the comment box.
358 # The unmarked state will be assumed to be a save,
359 # if the form seems otherwise complete.
360 wfDebug( "$fname: Passed token check.\n" );
362 # Page might be a hack attempt posted from
363 # an external site. Preview instead of saving.
364 wfDebug( "$fname: Failed token check; forcing preview\n" );
365 $this->preview
= true;
369 $this->save
= ! ( $this->preview
OR $this->diff
);
370 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
371 $this->edittime
= null;
374 if( !preg_match( '/^\d{14}$/', $this->starttime
)) {
375 $this->starttime
= null;
378 $this->recreate
= $request->getCheck( 'wpRecreate' );
380 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
381 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
383 # Not a posted form? Start with nothing.
384 wfDebug( "$fname: Not a posted form.\n" );
385 $this->textbox1
= '';
386 $this->textbox2
= '';
387 $this->mMetaData
= '';
389 $this->edittime
= '';
390 $this->starttime
= wfTimestampNow();
391 $this->preview
= false;
394 $this->minoredit
= false;
395 $this->watchthis
= false;
396 $this->recreate
= false;
399 $this->oldid
= $request->getInt( 'oldid' );
401 # Section edit can come from either the form or a link
402 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
404 $this->live
= $request->getCheck( 'live' );
405 $this->editintro
= $request->getText( 'editintro' );
407 wfProfileOut( $fname );
411 * Make sure the form isn't faking a user's credentials.
413 * @param WebRequest $request
417 function tokenOk( &$request ) {
419 if( $wgUser->isAnon() ) {
420 # Anonymous users may not have a session
421 # open. Don't tokenize.
422 $this->mTokenOk
= true;
424 $this->mTokenOk
= $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
426 return $this->mTokenOk
;
429 function showIntro() {
430 global $wgOut, $wgUser;
431 $addstandardintro=true;
432 if($this->editintro
) {
433 $introtitle=Title
::newFromText($this->editintro
);
434 if(isset($introtitle) && $introtitle->userCanRead()) {
435 $rev=Revision
::newFromTitle($introtitle);
437 $wgOut->addSecondaryWikiText($rev->getText());
438 $addstandardintro=false;
442 if($addstandardintro) {
443 if ( $wgUser->isLoggedIn() )
444 $wgOut->addWikiText( wfMsg( 'newarticletext' ) );
446 $wgOut->addWikiText( wfMsg( 'newarticletextanon' ) );
452 * @return bool false if output is done, true if the rest of the form should be displayed
454 function attemptSave() {
455 global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut;
456 global $wgMaxArticleSize;
458 $fname = 'EditPage::attemptSave';
459 wfProfileIn( $fname );
460 wfProfileIn( "$fname-checks" );
462 # Reintegrate metadata
463 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
464 $this->mMetaData
= '' ;
467 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
468 $this->spamPage ( $matches[0] );
469 wfProfileOut( "$fname-checks" );
470 wfProfileOut( $fname );
473 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
474 # Error messages or other handling should be performed by the filter function
475 wfProfileOut( $fname );
476 wfProfileOut( "$fname-checks" );
479 if ( !wfRunHooks( 'EditFilter', array( &$this, $this->textbox1
, $this->section
) ) ) {
480 # Error messages or other handling should be performed by the filter function
481 wfProfileOut( $fname );
482 wfProfileOut( "$fname-checks" );
485 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
486 # Check block state against master, thus 'false'.
487 $this->blockedIPpage();
488 wfProfileOut( "$fname-checks" );
489 wfProfileOut( $fname );
492 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
493 if ( $this->kblength
> $wgMaxArticleSize ) {
494 // Error will be displayed by showEditForm()
495 $this->tooBig
= true;
496 wfProfileOut( "$fname-checks" );
497 wfProfileOut( $fname );
501 if ( !$wgUser->isAllowed('edit') ) {
502 if ( $wgUser->isAnon() ) {
503 $this->userNotLoggedInPage();
504 wfProfileOut( "$fname-checks" );
505 wfProfileOut( $fname );
509 $wgOut->readOnlyPage();
510 wfProfileOut( "$fname-checks" );
511 wfProfileOut( $fname );
516 if ( wfReadOnly() ) {
517 $wgOut->readOnlyPage();
518 wfProfileOut( "$fname-checks" );
519 wfProfileOut( $fname );
522 if ( $wgUser->pingLimiter() ) {
523 $wgOut->rateLimited();
524 wfProfileOut( "$fname-checks" );
525 wfProfileOut( $fname );
529 # If the article has been deleted while editing, don't save it without
531 if ( $this->deletedSinceEdit
&& !$this->recreate
) {
532 wfProfileOut( "$fname-checks" );
533 wfProfileOut( $fname );
537 wfProfileOut( "$fname-checks" );
539 # If article is new, insert it.
540 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
542 // Late check for create permission, just in case *PARANOIA*
543 if ( !$this->mTitle
->userCan( 'create' ) ) {
544 wfDebug( "$fname: no create permission\n" );
545 $this->noCreatePermission();
546 wfProfileOut( $fname );
550 # Don't save a new article if it's blank.
551 if ( ( '' == $this->textbox1
) ) {
552 $wgOut->redirect( $this->mTitle
->getFullURL() );
553 wfProfileOut( $fname );
557 $isComment=($this->section
=='new');
558 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
559 $this->minoredit
, $this->watchthis
, false, $isComment);
561 wfProfileOut( $fname );
565 # Article exists. Check for edit conflict.
567 $this->mArticle
->clear(); # Force reload of dates, etc.
568 $this->mArticle
->forUpdate( true ); # Lock the article
570 if( $this->mArticle
->getTimestamp() != $this->edittime
) {
571 $this->isConflict
= true;
572 if( $this->section
== 'new' ) {
573 if( $this->mArticle
->getUserText() == $wgUser->getName() &&
574 $this->mArticle
->getComment() == $this->summary
) {
575 // Probably a duplicate submission of a new comment.
576 // This can happen when squid resends a request after
577 // a timeout but the first one actually went through.
578 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
580 // New comment; suppress conflict.
581 $this->isConflict
= false;
582 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
586 $userid = $wgUser->getID();
588 if ( $this->isConflict
) {
589 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
590 $this->mArticle
->getTimestamp() . "'\n" );
591 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
594 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
595 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
597 if( is_null( $text ) ) {
598 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
599 $this->isConflict
= true;
600 $text = $this->textbox1
;
603 # Suppress edit conflict with self, except for section edits where merging is required.
604 if ( ( $this->section
== '' ) && ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
605 wfDebug( "Suppressing edit conflict, same user.\n" );
606 $this->isConflict
= false;
608 # switch from section editing to normal editing in edit conflict
609 if($this->isConflict
) {
611 if( $this->mergeChangesInto( $text ) ){
612 // Successful merge! Maybe we should tell the user the good news?
613 $this->isConflict
= false;
614 wfDebug( "Suppressing edit conflict, successful merge.\n" );
617 $this->textbox1
= $text;
618 wfDebug( "Keeping edit conflict, failed merge.\n" );
623 if ( $this->isConflict
) {
624 wfProfileOut( $fname );
629 wfProfileIn( "$fname-sectionanchor" );
631 if( $this->section
== 'new' ) {
632 if( $this->summary
!= '' ) {
633 $sectionanchor = $this->sectionAnchor( $this->summary
);
635 } elseif( $this->section
!= '' ) {
636 # Try to get a section anchor from the section source, redirect to edited section if header found
637 # XXX: might be better to integrate this into Article::replaceSection
638 # for duplicate heading checking and maybe parsing
639 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
640 # we can't deal with anchors, includes, html etc in the header for now,
641 # headline would need to be parsed to improve this
642 if($hasmatch and strlen($matches[2]) > 0) {
643 $sectionanchor = $this->sectionAnchor( $matches[2] );
646 wfProfileOut( "$fname-sectionanchor" );
648 // Save errors may fall down to the edit form, but we've now
649 // merged the section into full text. Clear the section field
650 // so that later submission of conflict forms won't try to
651 // replace that into a duplicated mess.
652 $this->textbox1
= $text;
655 // Check for length errors again now that the section is merged in
656 $this->kblength
= (int)(strlen( $text ) / 1024);
657 if ( $this->kblength
> $wgMaxArticleSize ) {
658 $this->tooBig
= true;
659 wfProfileOut( $fname );
663 # update the article here
664 if( $this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
665 $this->watchthis
, '', $sectionanchor ) ) {
666 wfProfileOut( $fname );
669 $this->isConflict
= true;
671 wfProfileOut( $fname );
676 * Initialise form fields in the object
677 * Called on the first invocation, e.g. when a user clicks an edit link
679 function initialiseForm() {
680 $this->edittime
= $this->mArticle
->getTimestamp();
681 $this->textbox1
= $this->mArticle
->getContent();
683 if ( !$this->mArticle
->exists() && $this->mArticle
->mTitle
->getNamespace() == NS_MEDIAWIKI
)
684 $this->textbox1
= wfMsgWeirdKey ( $this->mArticle
->mTitle
->getText() ) ;
689 * Send the edit form and related headers to $wgOut
690 * @param $formCallback Optional callable that takes an OutputPage
691 * parameter; will be called during form output
692 * near the top, for captchas and the like.
694 function showEditForm( $formCallback=null ) {
695 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize;
697 $fname = 'EditPage::showEditForm';
698 wfProfileIn( $fname );
700 $sk =& $wgUser->getSkin();
702 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
704 $wgOut->setRobotpolicy( 'noindex,nofollow' );
706 # Enabled article-related sidebar, toplinks, etc.
707 $wgOut->setArticleRelated( true );
709 if ( $this->isConflict
) {
710 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
711 $wgOut->setPageTitle( $s );
712 $wgOut->addWikiText( wfMsg( 'explainconflict' ) );
714 $this->textbox2
= $this->textbox1
;
715 $this->textbox1
= $this->mArticle
->getContent();
716 $this->edittime
= $this->mArticle
->getTimestamp();
719 if( $this->section
!= '' ) {
720 if( $this->section
== 'new' ) {
721 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
723 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
724 if( !$this->preview
&& !$this->diff
) {
725 preg_match( "/^(=+)(.+)\\1/mi",
728 if( !empty( $matches[2] ) ) {
729 $this->summary
= "/* ". trim($matches[2])." */ ";
734 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
736 $wgOut->setPageTitle( $s );
737 if ( !$this->checkUnicodeCompliantBrowser() ) {
738 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
740 if ( isset( $this->mArticle
)
741 && isset( $this->mArticle
->mRevision
)
742 && !$this->mArticle
->mRevision
->isCurrent() ) {
743 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
744 $wgOut->addWikiText( wfMsg( 'editingold' ) );
749 $wgOut->addWikiText( wfMsg( 'readonlywarning' ) );
750 } else if ( $this->isCssJsSubpage
and 'preview' != $this->formtype
) {
751 $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ));
752 } else if( $wgUser->isAnon() && $this->formtype
!= 'preview' ) {
753 $wgOut->addWikiText( wfMsg( 'anoneditwarning' ) );
756 if( $this->mTitle
->isProtected( 'edit' ) ) {
757 if( $this->mTitle
->isSemiProtected() ) {
758 $notice = wfMsg( 'semiprotectedpagewarning' );
759 if( wfEmptyMsg( 'semiprotectedpagewarning', $notice ) ||
$notice == '-' ) {
763 $notice = wfMsg( 'protectedpagewarning' );
765 $wgOut->addWikiText( $notice );
768 if ( $this->kblength
=== false ) {
769 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
771 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
772 $wgOut->addWikiText( wfMsg( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgMaxArticleSize ) );
773 } elseif( $this->kblength
> 29 ) {
774 $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength
) ) );
777 $rows = $wgUser->getOption( 'rows' );
778 $cols = $wgUser->getOption( 'cols' );
780 $ew = $wgUser->getOption( 'editwidth' );
781 if ( $ew ) $ew = " style=\"width:100%\"";
784 $q = 'action=submit';
785 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
786 $action = $this->mTitle
->escapeLocalURL( $q );
788 $summary = wfMsg('summary');
789 $subject = wfMsg('subject');
790 $minor = wfMsg('minoredit');
791 $watchthis = wfMsg ('watchthis');
793 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
795 $edithelpurl = $sk->makeInternalOrExternalUrl( wfMsg( 'edithelppage' ));
796 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
797 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
798 htmlspecialchars( wfMsg( 'newwindow' ) );
800 global $wgRightsText;
801 $copywarn = "<div id=\"editpage-copywarn\">\n" .
802 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
803 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
804 $wgRightsText ) . "\n</div>";
806 if( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage
) {
807 # prepare toolbar for edit buttons
808 $toolbar = $this->getEditToolbar();
813 // activate checkboxes if user wants them to be always active
814 if( !$this->preview
&& !$this->diff
) {
815 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis
= true;
816 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
818 // activate checkbox also if user is already watching the page,
819 // require wpWatchthis to be unset so that second condition is not
820 // checked unnecessarily
821 if( !$this->watchthis
&& $this->mTitle
->userIsWatching() ) $this->watchthis
= true;
826 if ( $wgUser->isAllowed('minoredit') ) {
828 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
829 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
830 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
835 if ( $wgUser->isLoggedIn() ) {
836 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".
837 ($this->watchthis?
" checked='checked'":"").
838 " accesskey=\"".htmlspecialchars(wfMsg('accesskey-watch'))."\" id='wpWatchthis' />".
839 "<label for='wpWatchthis' title=\"" .
840 htmlspecialchars(wfMsg('tooltip-watch'))."\">{$watchthis}</label>";
843 $checkboxhtml = $minoredithtml . $watchhtml;
845 if ( $wgUser->getOption( 'previewontop' ) ) {
847 if ( 'preview' == $this->formtype
) {
848 $this->showPreview();
850 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
853 if ( 'diff' == $this->formtype
) {
854 $wgOut->addHTML( $this->getDiff() );
859 # if this is a comment, show a subject line at the top, which is also the edit summary.
860 # Otherwise, show a summary field at the bottom
861 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
862 if( $this->section
== 'new' ) {
863 $commentsubject="<span id='wpSummaryLabel'><label for='wpSummary'>{$subject}:</label></span> <div class='editOptions'><input tabindex='1' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' /><br />";
866 $commentsubject = '';
867 $editsummary="<span id='wpSummaryLabel'><label for='wpSummary'>{$summary}:</label></span> <div class='editOptions'><input tabindex='2' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' /><br />";
870 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
871 if( !$this->preview
&& !$this->diff
) {
872 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
874 $templates = $this->formatTemplates();
876 global $wgUseMetadataEdit ;
877 if ( $wgUseMetadataEdit ) {
878 $metadata = $this->mMetaData
;
879 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
880 $helppage = Title
::newFromText( wfMsg( "metadata_page" ) ) ;
881 $top = wfMsg( 'metadata', $helppage->getLocalURL() );
882 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
884 else $metadata = "" ;
888 if ($this->deletedSinceEdit
) {
889 if ( 'save' != $this->formtype
) {
890 $wgOut->addWikiText( wfMsg('deletedwhileediting'));
892 // Hide the toolbar and edit area, use can click preview to get it back
893 // Add an confirmation checkbox and explanation.
895 $hidden = 'type="hidden" style="display:none;"';
896 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete
->user_name
, $this->lastDelete
->log_comment
));
898 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
899 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
908 'value' => wfMsg('savearticle'),
909 'accesskey' => wfMsg('accesskey-save'),
910 'title' => wfMsg('tooltip-save'),
912 $buttons['save'] = wfElement('input', $temp, '');
918 'value' => wfMsg('showdiff'),
919 'accesskey' => wfMsg('accesskey-diff'),
920 'title' => wfMsg('tooltip-diff'),
922 $buttons['diff'] = wfElement('input', $temp, '');
924 global $wgLivePreview;
925 if ( $wgLivePreview ) {
928 'name' => 'wpPreview',
931 'value' => wfMsg('showpreview'),
933 'title' => wfMsg('tooltip-preview'),
934 'style' => 'display: none;',
936 $buttons['preview'] = wfElement('input', $temp, '');
938 'id' => 'wpLivePreview',
939 'name' => 'wpLivePreview',
942 'value' => wfMsg('showlivepreview'),
943 'accesskey' => wfMsg('accesskey-preview'),
945 'onclick' => $this->doLivePreviewScript(),
947 $buttons['live'] = wfElement('input', $temp, '');
951 'name' => 'wpPreview',
954 'value' => wfMsg('showpreview'),
955 'accesskey' => wfMsg('accesskey-preview'),
956 'title' => wfMsg('tooltip-preview'),
958 $buttons['preview'] = wfElement('input', $temp, '');
959 $buttons['live'] = '';
962 $safemodehtml = $this->checkUnicodeCompliantBrowser()
964 : "<input type='hidden' name=\"safemode\" value='1' />\n";
966 $wgOut->addHTML( <<<END
968 <form id="editform" name="editform" method="post" action="$action"
969 enctype="multipart/form-data">
973 if( is_callable( $formCallback ) ) {
974 call_user_func_array( $formCallback, array( &$wgOut ) );
977 // Put these up at the top to ensure they aren't lost on early form submission
979 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
980 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
981 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
982 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
984 $wgOut->addHTML( <<<END
987 <textarea tabindex='1' accesskey="," name="wpTextbox1" id="wpTextbox1" rows='{$rows}'
988 cols='{$cols}'{$ew} $hidden>
990 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1
) ) .
995 $wgOut->addWikiText( $copywarn );
1004 <div class='editButtons'>
1006 {$buttons['preview']}
1009 <span class='editHelp'>{$cancel} | {$edithelp}</span>
1010 </div><!-- editButtons -->
1011 </div><!-- editOptions -->");
1013 $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
1016 <div class='templatesUsed'>
1021 if ( $wgUser->isLoggedIn() ) {
1023 * To make it harder for someone to slip a user a page
1024 * which submits an edit form to the wiki without their
1025 * knowledge, a random token is associated with the login
1026 * session. If it's not passed back with the submission,
1027 * we won't save the page, or render user JavaScript and
1030 $token = htmlspecialchars( $wgUser->editToken() );
1031 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1035 if ( $this->isConflict
) {
1036 require_once( "DifferenceEngine.php" );
1037 $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' );
1039 $de = new DifferenceEngine( $this->mTitle
);
1040 $de->setText( $this->textbox2
, $this->textbox1
);
1041 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1043 $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
1044 $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
1045 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2
) ) . "\n</textarea>" );
1047 $wgOut->addHTML( "</form>\n" );
1048 if ( !$wgUser->getOption( 'previewontop' ) ) {
1050 if ( $this->formtype
== 'preview') {
1051 $this->showPreview();
1053 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
1056 if ( $this->formtype
== 'diff') {
1057 $wgOut->addHTML( $this->getDiff() );
1062 wfProfileOut( $fname );
1066 * Append preview output to $wgOut.
1067 * Includes category rendering if this is a category page.
1070 function showPreview() {
1072 $wgOut->addHTML( '<div id="wikiPreview">' );
1073 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1074 $this->mArticle
->openShowCategory();
1076 $previewOutput = $this->getPreviewText();
1077 $wgOut->addHTML( $previewOutput );
1078 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1079 $this->mArticle
->closeShowCategory();
1081 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
1082 $wgOut->addHTML( '</div>' );
1086 * Prepare a list of templates used by this page. Returns HTML.
1088 function formatTemplates() {
1091 $fname = 'EditPage::formatTemplates';
1092 wfProfileIn( $fname );
1094 $sk =& $wgUser->getSkin();
1097 $templates = $this->mArticle
->getUsedTemplates();
1098 if ( count( $templates ) > 0 ) {
1099 # Do a batch existence check
1100 $batch = new LinkBatch
;
1101 foreach( $templates as $title ) {
1102 $batch->addObj( $title );
1106 # Construct the HTML
1107 $outText = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
1108 foreach ( $templates as $titleObj ) {
1109 $outText .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
1111 $outText .= '</ul>';
1113 wfProfileOut( $fname );
1118 * Live Preview lets us fetch rendered preview page content and
1119 * add it to the page without refreshing the whole page.
1120 * If not supported by the browser it will fall through to the normal form
1121 * submission method.
1123 * This function outputs a script tag to support live preview, and
1124 * returns an onclick handler which should be added to the attributes
1125 * of the preview button
1127 function doLivePreviewScript() {
1128 global $wgStylePath, $wgJsMimeType, $wgOut, $wgTitle;
1129 $wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' .
1130 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
1131 '"></script>' . "\n" );
1132 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
1133 return "return !livePreview(" .
1134 "getElementById('wikiPreview')," .
1135 "editform.wpTextbox1.value," .
1136 '"' . $liveAction . '"' . ")";
1139 function getLastDelete() {
1140 $dbr =& wfGetDB( DB_SLAVE
);
1141 $fname = 'EditPage::getLastDelete';
1142 $res = $dbr->select(
1143 array( 'logging', 'user' ),
1153 array( 'log_namespace' => $this->mTitle
->getNamespace(),
1154 'log_title' => $this->mTitle
->getDBkey(),
1155 'log_type' => 'delete',
1156 'log_action' => 'delete',
1157 'user_id=log_user' ),
1159 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1161 if($dbr->numRows($res) == 1) {
1162 while ( $x = $dbr->fetchObject ( $res ) )
1164 $dbr->freeResult ( $res ) ;
1174 function getPreviewText() {
1175 global $wgOut, $wgUser, $wgTitle, $wgParser;
1177 $fname = 'EditPage::getPreviewText';
1178 wfProfileIn( $fname );
1180 if ( $this->mTokenOk
) {
1181 $msg = 'previewnote';
1183 $msg = 'session_fail_preview';
1185 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1186 "<div class='previewnote'>" . $wgOut->parse( wfMsg( $msg ) ) . "</div>\n";
1187 if ( $this->isConflict
) {
1188 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1191 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1192 $parserOptions->setEditSection( false );
1194 # don't parse user css/js, show message about preview
1195 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1197 if ( $this->isCssJsSubpage
) {
1198 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
1199 $previewtext = wfMsg('usercsspreview');
1200 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
1201 $previewtext = wfMsg('userjspreview');
1203 $parserOptions->setTidy(true);
1204 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
1205 $wgOut->addHTML( $parserOutput->mText
);
1206 wfProfileOut( $fname );
1207 return $previewhead;
1209 # if user want to see preview when he edit an article
1210 if( $wgUser->getOption('previewonfirst') and ($this->textbox1
== '')) {
1211 $this->textbox1
= $this->mArticle
->getContent();
1214 $toparse = $this->textbox1
;
1216 # If we're adding a comment, we need to show the
1217 # summary as the headline
1218 if($this->section
=="new" && $this->summary
!="") {
1219 $toparse="== {$this->summary} ==\n\n".$toparse;
1222 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
1223 $parserOptions->setTidy(true);
1224 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
1225 $wgTitle, $parserOptions );
1227 $previewHTML = $parserOutput->getText();
1228 $wgOut->addParserOutputNoText( $parserOutput );
1230 wfProfileOut( $fname );
1231 return $previewhead . $previewHTML;
1238 function blockedIPpage() {
1240 $wgOut->blockedPage();
1246 function userNotLoggedInPage() {
1249 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1250 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1251 $wgOut->setArticleRelated( false );
1253 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
1254 $wgOut->returnToMain( false );
1258 * Creates a basic error page which informs the user that
1259 * they have to validate their email address before being
1262 function userNotConfirmedPage() {
1266 $wgOut->setPageTitle( wfMsg( 'confirmedittitle' ) );
1267 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1268 $wgOut->setArticleRelated( false );
1269 $wgOut->addWikiText( wfMsg( 'confirmedittext' ) );
1270 $wgOut->returnToMain( false );
1276 function spamPage ( $match = false )
1279 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1280 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1281 $wgOut->setArticleRelated( false );
1283 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
1285 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
1287 $wgOut->returnToMain( false );
1294 function mergeChangesInto( &$editText ){
1295 $fname = 'EditPage::mergeChangesInto';
1296 wfProfileIn( $fname );
1298 $db =& wfGetDB( DB_MASTER
);
1300 // This is the revision the editor started from
1301 $baseRevision = Revision
::loadFromTimestamp(
1302 $db, $this->mArticle
->mTitle
, $this->edittime
);
1303 if( is_null( $baseRevision ) ) {
1304 wfProfileOut( $fname );
1307 $baseText = $baseRevision->getText();
1309 // The current state, we want to merge updates into it
1310 $currentRevision = Revision
::loadFromTitle(
1311 $db, $this->mArticle
->mTitle
);
1312 if( is_null( $currentRevision ) ) {
1313 wfProfileOut( $fname );
1316 $currentText = $currentRevision->getText();
1318 if( wfMerge( $baseText, $editText, $currentText, $result ) ){
1319 $editText = $result;
1320 wfProfileOut( $fname );
1323 wfProfileOut( $fname );
1329 * Check if the browser is on a blacklist of user-agents known to
1330 * mangle UTF-8 data on form submission. Returns true if Unicode
1331 * should make it through, false if it's known to be a problem.
1335 function checkUnicodeCompliantBrowser() {
1336 global $wgBrowserBlackList;
1337 if( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1338 // No User-Agent header sent? Trust it by default...
1341 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1342 foreach ( $wgBrowserBlackList as $browser ) {
1343 if ( preg_match($browser, $currentbrowser) ) {
1351 * Format an anchor fragment as it would appear for a given section name
1352 * @param string $text
1356 function sectionAnchor( $text ) {
1357 $headline = Sanitizer
::decodeCharReferences( $text );
1359 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
1360 $headline = trim( $headline );
1361 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
1362 $replacearray = array(
1367 array_keys( $replacearray ),
1368 array_values( $replacearray ),
1373 * Shows a bulletin board style toolbar for common editing functions.
1374 * It can be disabled in the user preferences.
1375 * The necessary JavaScript code can be found in style/wikibits.js.
1377 function getEditToolbar() {
1378 global $wgStylePath, $wgContLang, $wgJsMimeType;
1381 * toolarray an array of arrays which each include the filename of
1382 * the button image (without path), the opening tag, the closing tag,
1383 * and optionally a sample text that is inserted between the two when no
1384 * selection is highlighted.
1385 * The tip text is shown when the user moves the mouse over the button.
1387 * Already here are accesskeys (key), which are not used yet until someone
1388 * can figure out a way to make them work in IE. However, we should make
1389 * sure these keys are not defined on the edit page.
1392 array( 'image'=>'button_bold.png',
1394 'close' => "\'\'\'",
1395 'sample'=> wfMsg('bold_sample'),
1396 'tip' => wfMsg('bold_tip'),
1399 array( 'image'=>'button_italic.png',
1402 'sample'=> wfMsg('italic_sample'),
1403 'tip' => wfMsg('italic_tip'),
1406 array( 'image'=>'button_link.png',
1409 'sample'=> wfMsg('link_sample'),
1410 'tip' => wfMsg('link_tip'),
1413 array( 'image'=>'button_extlink.png',
1416 'sample'=> wfMsg('extlink_sample'),
1417 'tip' => wfMsg('extlink_tip'),
1420 array( 'image'=>'button_headline.png',
1422 'close' => " ==\\n",
1423 'sample'=> wfMsg('headline_sample'),
1424 'tip' => wfMsg('headline_tip'),
1427 array( 'image'=>'button_image.png',
1428 'open' => '[['.$wgContLang->getNsText(NS_IMAGE
).":",
1430 'sample'=> wfMsg('image_sample'),
1431 'tip' => wfMsg('image_tip'),
1434 array( 'image' =>'button_media.png',
1435 'open' => '[['.$wgContLang->getNsText(NS_MEDIA
).':',
1437 'sample'=> wfMsg('media_sample'),
1438 'tip' => wfMsg('media_tip'),
1441 array( 'image' =>'button_math.png',
1442 'open' => "\\<math\\>",
1443 'close' => "\\</math\\>",
1444 'sample'=> wfMsg('math_sample'),
1445 'tip' => wfMsg('math_tip'),
1448 array( 'image' =>'button_nowiki.png',
1449 'open' => "\\<nowiki\\>",
1450 'close' => "\\</nowiki\\>",
1451 'sample'=> wfMsg('nowiki_sample'),
1452 'tip' => wfMsg('nowiki_tip'),
1455 array( 'image' =>'button_sig.png',
1459 'tip' => wfMsg('sig_tip'),
1462 array( 'image' =>'button_hr.png',
1463 'open' => "\\n----\\n",
1466 'tip' => wfMsg('hr_tip'),
1470 $toolbar ="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
1472 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
1473 foreach($toolarray as $tool) {
1475 $image=$wgStylePath.'/common/images/'.$tool['image'];
1476 $open=$tool['open'];
1477 $close=$tool['close'];
1478 $sample = wfEscapeJsString( $tool['sample'] );
1480 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1481 // Older browsers show a "speedtip" type message only for ALT.
1482 // Ideally these should be different, realistically they
1483 // probably don't need to be.
1484 $tip = wfEscapeJsString( $tool['tip'] );
1486 #$key = $tool["key"];
1488 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
1491 $toolbar.="document.writeln(\"</div>\");\n";
1492 $toolbar.="/*]]>*/\n</script>";
1497 * Output preview text only. This can be sucked into the edit page
1498 * via JavaScript, and saves the server time rendering the skin as
1499 * well as theoretically being more robust on the client (doesn't
1500 * disturb the edit box's undo history, won't eat your text on
1503 * @todo This doesn't include category or interlanguage links.
1504 * Would need to enhance it a bit, maybe wrap them in XML
1505 * or something... that might also require more skin
1506 * initialization, so check whether that's a problem.
1508 function livePreview() {
1511 header( 'Content-type: text/xml' );
1512 header( 'Cache-control: no-cache' );
1514 echo $this->getPreviewText( );
1515 /* To not shake screen up and down between preview and live-preview */
1516 echo "<br style=\"clear:both;\" />\n";
1521 * Get a diff between the current contents of the edit box and the
1522 * version of the page we're editing from.
1524 * If this is a section edit, we'll replace the section as for final
1525 * save and then make a comparison.
1527 * @return string HTML
1529 function getDiff() {
1532 require_once( 'DifferenceEngine.php' );
1533 $oldtext = $this->mArticle
->fetchContent();
1534 $newtext = $this->mArticle
->replaceSection(
1535 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1536 $oldtitle = wfMsg( 'currentrev' );
1537 $newtitle = wfMsg( 'yourtext' );
1538 if ( $oldtext !== false ||
$newtext != '' ) {
1539 $de = new DifferenceEngine( $this->mTitle
);
1540 $de->setText( $oldtext, $newtext );
1541 $difftext = $de->getDiff( $oldtitle, $newtitle );
1546 return '<div id="wikiDiff">' . $difftext . '</div>';
1550 * Filter an input field through a Unicode de-armoring process if it
1551 * came from an old browser with known broken Unicode editing issues.
1553 * @param WebRequest $request
1554 * @param string $field
1558 function safeUnicodeInput( $request, $field ) {
1559 $text = rtrim( $request->getText( $field ) );
1560 return $request->getBool( 'safemode' )
1561 ?
$this->unmakesafe( $text )
1566 * Filter an output field through a Unicode armoring process if it is
1567 * going to an old browser with known broken Unicode editing issues.
1569 * @param string $text
1573 function safeUnicodeOutput( $text ) {
1575 $codedText = $wgContLang->recodeForEdit( $text );
1576 return $this->checkUnicodeCompliantBrowser()
1578 : $this->makesafe( $codedText );
1582 * A number of web browsers are known to corrupt non-ASCII characters
1583 * in a UTF-8 text editing environment. To protect against this,
1584 * detected browsers will be served an armored version of the text,
1585 * with non-ASCII chars converted to numeric HTML character references.
1587 * Preexisting such character references will have a 0 added to them
1588 * to ensure that round-trips do not alter the original data.
1590 * @param string $invalue
1594 function makesafe( $invalue ) {
1595 // Armor existing references for reversability.
1596 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
1601 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1602 $bytevalue = ord( $invalue{$i} );
1603 if( $bytevalue <= 0x7F ) { //0xxx xxxx
1604 $result .= chr( $bytevalue );
1606 } elseif( $bytevalue <= 0xBF ) { //10xx xxxx
1607 $working = $working << 6;
1608 $working +
= ($bytevalue & 0x3F);
1610 if( $bytesleft <= 0 ) {
1611 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
1613 } elseif( $bytevalue <= 0xDF ) { //110x xxxx
1614 $working = $bytevalue & 0x1F;
1616 } elseif( $bytevalue <= 0xEF ) { //1110 xxxx
1617 $working = $bytevalue & 0x0F;
1619 } else { //1111 0xxx
1620 $working = $bytevalue & 0x07;
1628 * Reverse the previously applied transliteration of non-ASCII characters
1629 * back to UTF-8. Used to protect data from corruption by broken web browsers
1630 * as listed in $wgBrowserBlackList.
1632 * @param string $invalue
1636 function unmakesafe( $invalue ) {
1638 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1639 if( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+
3} != '0' ) ) {
1643 $hexstring .= $invalue{$i};
1645 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
1647 // Do some sanity checks. These aren't needed for reversability,
1648 // but should help keep the breakage down if the editor
1649 // breaks one of the entities whilst editing.
1650 if ((substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6)) {
1651 $codepoint = hexdec($hexstring);
1652 $result .= codepointToUtf8( $codepoint );
1654 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
1657 $result .= substr( $invalue, $i, 1 );
1660 // reverse the transform that we made for reversability reasons.
1661 return strtr( $result, array( "�" => "&#x" ) );
1664 function noCreatePermission() {
1666 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
1667 $wgOut->addWikiText( wfMsg( 'nocreatetext' ) );