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;
29 var $missingComment = false;
30 var $missingSummary = false;
31 var $allowBlankSummary = false;
35 var $save = false, $preview = false, $diff = false;
36 var $minoredit = false, $watchthis = false, $recreate = false;
37 var $textbox1 = '', $textbox2 = '', $summary = '';
38 var $edittime = '', $section = '', $starttime = '';
39 var $oldid = 0, $editintro = '', $scrolltop = null;
45 function EditPage( $article ) {
46 $this->mArticle
=& $article;
48 $this->mTitle
=& $wgTitle;
52 * This is the function that extracts metadata from the article body on the first view.
53 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
54 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
56 function extractMetaDataFromArticle () {
57 global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
58 $this->mMetaData
= '' ;
59 if ( !$wgUseMetadataEdit ) return ;
60 if ( $wgMetadataWhitelist == '' ) return ;
62 $t = $this->mArticle
->getContent();
64 # MISSING : <nowiki> filtering
66 # Categories and language links
67 $t = explode ( "\n" , $t ) ;
68 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY
) ) ;
69 $cat = $ll = array() ;
70 foreach ( $t AS $key => $x )
72 $y = trim ( strtolower ( $x ) ) ;
73 while ( substr ( $y , 0 , 2 ) == '[[' )
75 $y = explode ( ']]' , trim ( $x ) ) ;
76 $first = array_shift ( $y ) ;
77 $first = explode ( ':' , $first ) ;
78 $ns = array_shift ( $first ) ;
79 $ns = trim ( str_replace ( '[' , '' , $ns ) ) ;
80 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
82 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]' ;
83 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
85 $x = implode ( ']]' , $y ) ;
87 $y = trim ( strtolower ( $x ) ) ;
91 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n" ;
92 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n" ;
93 $t = implode ( "\n" , $t ) ;
96 $sat = array () ; # stand-alone-templates; must be lowercase
97 $wl_title = Title
::newFromText ( $wgMetadataWhitelist ) ;
98 $wl_article = new Article ( $wl_title ) ;
99 $wl = explode ( "\n" , $wl_article->getContent() ) ;
100 foreach ( $wl AS $x )
104 while ( substr ( $x , 0 , 1 ) == '*' )
107 $x = trim ( substr ( $x , 1 ) ) ;
111 $sat[] = strtolower ( $x ) ;
116 # Templates, but only some
117 $t = explode ( '{{' , $t ) ;
119 foreach ( $t AS $key => $x )
121 $y = explode ( '}}' , $x , 2 ) ;
122 if ( count ( $y ) == 2 )
125 $z = explode ( '|' , $z ) ;
126 $tn = array_shift ( $z ) ;
127 if ( in_array ( strtolower ( $tn ) , $sat ) )
129 $tl[] = '{{' . $y[0] . '}}' ;
131 $y = explode ( '}}' , $y[1] , 2 ) ;
133 else $t[$key] = '{{' . $x ;
135 else if ( $key != 0 ) $t[$key] = '{{' . $x ;
138 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl ) ;
139 $t = implode ( '' , $t ) ;
141 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
142 $this->mArticle
->mContent
= $t ;
143 $this->mMetaData
= $s ;
151 * This is the function that gets called for "action=edit". It
152 * sets up various member variables, then passes execution to
153 * another function, usually showEditForm()
155 * The edit form is self-submitting, so that when things like
156 * preview and edit conflicts occur, we get the same form back
157 * with the extra stuff added. Only when the final submission
158 * is made and all is well do we actually save and redirect to
159 * the newly-edited page.
162 global $wgOut, $wgUser, $wgRequest, $wgTitle;
163 global $wgEmailConfirmToEdit;
165 if ( ! wfRunHooks( 'AlternateEdit', array( &$this ) ) )
168 $fname = 'EditPage::edit';
169 wfProfileIn( $fname );
170 wfDebug( "$fname: enter\n" );
172 // this is not an article
173 $wgOut->setArticleFlag(false);
175 $this->importFormData( $wgRequest );
176 $this->firsttime
= false;
179 $this->livePreview();
180 wfProfileOut( $fname );
184 if ( ! $this->mTitle
->userCanEdit() ) {
185 wfDebug( "$fname: user can't edit\n" );
186 $wgOut->readOnlyPage( $this->mArticle
->getContent(), true );
187 wfProfileOut( $fname );
190 wfDebug( "$fname: Checking blocks\n" );
191 if ( !$this->preview
&& !$this->diff
&& $wgUser->isBlockedFrom( $this->mTitle
, !$this->save
) ) {
192 # When previewing, don't check blocked state - will get caught at save time.
193 # Also, check when starting edition is done against slave to improve performance.
194 wfDebug( "$fname: user is blocked\n" );
195 $wgOut->blockedPage();
196 wfProfileOut( $fname );
199 if ( !$wgUser->isAllowed('edit') ) {
200 if ( $wgUser->isAnon() ) {
201 wfDebug( "$fname: user must log in\n" );
202 $this->userNotLoggedInPage();
203 wfProfileOut( $fname );
206 wfDebug( "$fname: read-only page\n" );
207 $wgOut->readOnlyPage( $this->mArticle
->getContent(), true );
208 wfProfileOut( $fname );
212 if ($wgEmailConfirmToEdit && !$wgUser->isEmailConfirmed()) {
213 wfDebug("$fname: user must confirm e-mail address\n");
214 $this->userNotConfirmedPage();
215 wfProfileOut($fname);
218 if ( !$this->mTitle
->userCan( 'create' ) && !$this->mTitle
->exists() ) {
219 wfDebug( "$fname: no create permission\n" );
220 $this->noCreatePermission();
221 wfProfileOut( $fname );
224 if ( wfReadOnly() ) {
225 wfDebug( "$fname: read-only mode is engaged\n" );
226 if( $this->save ||
$this->preview
) {
227 $this->formtype
= 'preview';
228 } else if ( $this->diff
) {
229 $this->formtype
= 'diff';
231 $wgOut->readOnlyPage( $this->mArticle
->getContent() );
232 wfProfileOut( $fname );
237 $this->formtype
= 'save';
238 } else if ( $this->preview
) {
239 $this->formtype
= 'preview';
240 } else if ( $this->diff
) {
241 $this->formtype
= 'diff';
242 } else { # First time through
243 $this->firsttime
= true;
244 if( $this->previewOnOpen() ) {
245 $this->formtype
= 'preview';
247 $this->extractMetaDataFromArticle () ;
248 $this->formtype
= 'initial';
253 wfProfileIn( "$fname-business-end" );
255 $this->isConflict
= false;
256 // css / js subpages of user pages get a special treatment
257 $this->isCssJsSubpage
= $wgTitle->isCssJsSubpage();
258 $this->isValidCssJsSubpage
= $wgTitle->isValidCssJsSubpage();
260 /* Notice that we can't use isDeleted, because it returns true if article is ever deleted
261 * no matter it's current state
263 $this->deletedSinceEdit
= false;
264 if ( $this->edittime
!= '' ) {
265 /* Note that we rely on logging table, which hasn't been always there,
266 * but that doesn't matter, because this only applies to brand new
267 * deletes. This is done on every preview and save request. Move it further down
268 * to only perform it on saves
270 if ( $this->mTitle
->isDeleted() ) {
271 $this->lastDelete
= $this->getLastDelete();
272 if ( !is_null($this->lastDelete
) ) {
273 $deletetime = $this->lastDelete
->log_timestamp
;
274 if ( ($deletetime - $this->starttime
) > 0 ) {
275 $this->deletedSinceEdit
= true;
281 if(!$this->mTitle
->getArticleID() && ('initial' == $this->formtype ||
$this->firsttime
)) { # new article
284 if( $this->mTitle
->isTalkPage() ) {
285 $wgOut->addWikiText( wfMsg( 'talkpagetext' ) );
288 # Attempt submission here. This will check for edit conflicts,
289 # and redundantly check for locked database, blocked IPs, etc.
290 # that edit() already checked just in case someone tries to sneak
291 # in the back door with a hand-edited submission URL.
293 if ( 'save' == $this->formtype
) {
294 if ( !$this->attemptSave() ) {
295 wfProfileOut( "$fname-business-end" );
296 wfProfileOut( $fname );
301 # First time through: get contents, set time for conflict
303 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
304 $this->initialiseForm();
307 $this->showEditForm();
308 wfProfileOut( "$fname-business-end" );
309 wfProfileOut( $fname );
313 * Return true if this page should be previewed when the edit form
314 * is initially opened.
318 function previewOnOpen() {
320 return $this->section
!= 'new' &&
321 ( ( $wgUser->getOption( 'previewonfirst' ) && $this->mTitle
->exists() ) ||
322 ( $this->mTitle
->getNamespace() == NS_CATEGORY
&&
323 !$this->mTitle
->exists() ) );
330 function importFormData( &$request ) {
331 global $wgLang, $wgUser;
332 $fname = 'EditPage::importFormData';
333 wfProfileIn( $fname );
335 if( $request->wasPosted() ) {
336 # These fields need to be checked for encoding.
337 # Also remove trailing whitespace, but don't remove _initial_
338 # whitespace from the text boxes. This may be significant formatting.
339 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
340 $this->textbox2
= $this->safeUnicodeInput( $request, 'wpTextbox2' );
341 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
342 # Truncate for whole multibyte characters. +5 bytes for ellipsis
343 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
345 $this->edittime
= $request->getVal( 'wpEdittime' );
346 $this->starttime
= $request->getVal( 'wpStarttime' );
348 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
350 if( is_null( $this->edittime
) ) {
351 # If the form is incomplete, force to preview.
352 wfDebug( "$fname: Form data appears to be incomplete\n" );
353 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
354 $this->preview
= true;
356 /* Fallback for live preview */
357 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
358 $this->diff
= $request->getCheck( 'wpDiff' );
360 if( !$this->preview
) {
361 if ( $this->tokenOk( $request ) ) {
362 # Some browsers will not report any submit button
363 # if the user hits enter in the comment box.
364 # The unmarked state will be assumed to be a save,
365 # if the form seems otherwise complete.
366 wfDebug( "$fname: Passed token check.\n" );
368 # Page might be a hack attempt posted from
369 # an external site. Preview instead of saving.
370 wfDebug( "$fname: Failed token check; forcing preview\n" );
371 $this->preview
= true;
375 $this->save
= ! ( $this->preview
OR $this->diff
);
376 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
377 $this->edittime
= null;
380 if( !preg_match( '/^\d{14}$/', $this->starttime
)) {
381 $this->starttime
= null;
384 $this->recreate
= $request->getCheck( 'wpRecreate' );
386 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
387 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
389 # Don't force edit summaries when a user is editing their own user or talk page
390 if( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) && $this->mTitle
->getText() == $wgUser->getName() ) {
391 $this->allowBlankSummary
= true;
393 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' );
396 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
398 # Not a posted form? Start with nothing.
399 wfDebug( "$fname: Not a posted form.\n" );
400 $this->textbox1
= '';
401 $this->textbox2
= '';
402 $this->mMetaData
= '';
404 $this->edittime
= '';
405 $this->starttime
= wfTimestampNow();
406 $this->preview
= false;
409 $this->minoredit
= false;
410 $this->watchthis
= false;
411 $this->recreate
= false;
414 $this->oldid
= $request->getInt( 'oldid' );
416 # Section edit can come from either the form or a link
417 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
419 $this->live
= $request->getCheck( 'live' );
420 $this->editintro
= $request->getText( 'editintro' );
422 wfProfileOut( $fname );
426 * Make sure the form isn't faking a user's credentials.
428 * @param $request WebRequest
432 function tokenOk( &$request ) {
434 if( $wgUser->isAnon() ) {
435 # Anonymous users may not have a session
436 # open. Don't tokenize.
437 $this->mTokenOk
= true;
439 $this->mTokenOk
= $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
441 return $this->mTokenOk
;
445 function showIntro() {
446 global $wgOut, $wgUser;
447 $addstandardintro=true;
448 if($this->editintro
) {
449 $introtitle=Title
::newFromText($this->editintro
);
450 if(isset($introtitle) && $introtitle->userCanRead()) {
451 $rev=Revision
::newFromTitle($introtitle);
453 $wgOut->addSecondaryWikiText($rev->getText());
454 $addstandardintro=false;
458 if($addstandardintro) {
459 if ( $wgUser->isLoggedIn() )
460 $wgOut->addWikiText( wfMsg( 'newarticletext' ) );
462 $wgOut->addWikiText( wfMsg( 'newarticletextanon' ) );
468 * @return bool false if output is done, true if the rest of the form should be displayed
470 function attemptSave() {
471 global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut;
472 global $wgMaxArticleSize;
474 $fname = 'EditPage::attemptSave';
475 wfProfileIn( $fname );
476 wfProfileIn( "$fname-checks" );
478 # Reintegrate metadata
479 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
480 $this->mMetaData
= '' ;
483 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
484 $this->spamPage ( $matches[0] );
485 wfProfileOut( "$fname-checks" );
486 wfProfileOut( $fname );
489 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
490 # Error messages or other handling should be performed by the filter function
491 wfProfileOut( $fname );
492 wfProfileOut( "$fname-checks" );
495 if ( !wfRunHooks( 'EditFilter', array( &$this, $this->textbox1
, $this->section
) ) ) {
496 # Error messages or other handling should be performed by the filter function
497 wfProfileOut( $fname );
498 wfProfileOut( "$fname-checks" );
501 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
502 # Check block state against master, thus 'false'.
503 $this->blockedIPpage();
504 wfProfileOut( "$fname-checks" );
505 wfProfileOut( $fname );
508 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
509 if ( $this->kblength
> $wgMaxArticleSize ) {
510 // Error will be displayed by showEditForm()
511 $this->tooBig
= true;
512 wfProfileOut( "$fname-checks" );
513 wfProfileOut( $fname );
517 if ( !$wgUser->isAllowed('edit') ) {
518 if ( $wgUser->isAnon() ) {
519 $this->userNotLoggedInPage();
520 wfProfileOut( "$fname-checks" );
521 wfProfileOut( $fname );
525 $wgOut->readOnlyPage();
526 wfProfileOut( "$fname-checks" );
527 wfProfileOut( $fname );
532 if ( wfReadOnly() ) {
533 $wgOut->readOnlyPage();
534 wfProfileOut( "$fname-checks" );
535 wfProfileOut( $fname );
538 if ( $wgUser->pingLimiter() ) {
539 $wgOut->rateLimited();
540 wfProfileOut( "$fname-checks" );
541 wfProfileOut( $fname );
545 # If the article has been deleted while editing, don't save it without
547 if ( $this->deletedSinceEdit
&& !$this->recreate
) {
548 wfProfileOut( "$fname-checks" );
549 wfProfileOut( $fname );
553 wfProfileOut( "$fname-checks" );
555 # If article is new, insert it.
556 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
558 // Late check for create permission, just in case *PARANOIA*
559 if ( !$this->mTitle
->userCan( 'create' ) ) {
560 wfDebug( "$fname: no create permission\n" );
561 $this->noCreatePermission();
562 wfProfileOut( $fname );
566 # Don't save a new article if it's blank.
567 if ( ( '' == $this->textbox1
) ) {
568 $wgOut->redirect( $this->mTitle
->getFullURL() );
569 wfProfileOut( $fname );
573 $isComment=($this->section
=='new');
574 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
575 $this->minoredit
, $this->watchthis
, false, $isComment);
577 wfProfileOut( $fname );
581 # Article exists. Check for edit conflict.
583 $this->mArticle
->clear(); # Force reload of dates, etc.
584 $this->mArticle
->forUpdate( true ); # Lock the article
586 if( $this->mArticle
->getTimestamp() != $this->edittime
) {
587 $this->isConflict
= true;
588 if( $this->section
== 'new' ) {
589 if( $this->mArticle
->getUserText() == $wgUser->getName() &&
590 $this->mArticle
->getComment() == $this->summary
) {
591 // Probably a duplicate submission of a new comment.
592 // This can happen when squid resends a request after
593 // a timeout but the first one actually went through.
594 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
596 // New comment; suppress conflict.
597 $this->isConflict
= false;
598 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
602 $userid = $wgUser->getID();
604 if ( $this->isConflict
) {
605 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
606 $this->mArticle
->getTimestamp() . "'\n" );
607 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
610 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
611 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
613 if( is_null( $text ) ) {
614 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
615 $this->isConflict
= true;
616 $text = $this->textbox1
;
619 # Suppress edit conflict with self, except for section edits where merging is required.
620 if ( ( $this->section
== '' ) && ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
621 wfDebug( "Suppressing edit conflict, same user.\n" );
622 $this->isConflict
= false;
624 # switch from section editing to normal editing in edit conflict
625 if($this->isConflict
) {
627 if( $this->mergeChangesInto( $text ) ){
628 // Successful merge! Maybe we should tell the user the good news?
629 $this->isConflict
= false;
630 wfDebug( "Suppressing edit conflict, successful merge.\n" );
633 $this->textbox1
= $text;
634 wfDebug( "Keeping edit conflict, failed merge.\n" );
639 if ( $this->isConflict
) {
640 wfProfileOut( $fname );
644 # Handle the user preference to force summaries here
645 if( $this->section
!= 'new' && !$this->allowBlankSummary
&& $wgUser->getOption( 'forceeditsummary' ) ) {
646 if( md5( $this->summary
) == $this->autoSumm
) {
647 $this->missingSummary
= true;
648 wfProfileOut( $fname );
654 wfProfileIn( "$fname-sectionanchor" );
656 if( $this->section
== 'new' ) {
657 if ( $this->textbox1
== '' ) {
658 $this->missingComment
= true;
661 if( $this->summary
!= '' ) {
662 $sectionanchor = $this->sectionAnchor( $this->summary
);
664 } elseif( $this->section
!= '' ) {
665 # Try to get a section anchor from the section source, redirect to edited section if header found
666 # XXX: might be better to integrate this into Article::replaceSection
667 # for duplicate heading checking and maybe parsing
668 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
669 # we can't deal with anchors, includes, html etc in the header for now,
670 # headline would need to be parsed to improve this
671 if($hasmatch and strlen($matches[2]) > 0) {
672 $sectionanchor = $this->sectionAnchor( $matches[2] );
675 wfProfileOut( "$fname-sectionanchor" );
677 // Save errors may fall down to the edit form, but we've now
678 // merged the section into full text. Clear the section field
679 // so that later submission of conflict forms won't try to
680 // replace that into a duplicated mess.
681 $this->textbox1
= $text;
684 // Check for length errors again now that the section is merged in
685 $this->kblength
= (int)(strlen( $text ) / 1024);
686 if ( $this->kblength
> $wgMaxArticleSize ) {
687 $this->tooBig
= true;
688 wfProfileOut( $fname );
692 # update the article here
693 if( $this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
694 $this->watchthis
, '', $sectionanchor ) ) {
695 wfProfileOut( $fname );
698 $this->isConflict
= true;
700 wfProfileOut( $fname );
705 * Initialise form fields in the object
706 * Called on the first invocation, e.g. when a user clicks an edit link
708 function initialiseForm() {
709 $this->edittime
= $this->mArticle
->getTimestamp();
710 $this->textbox1
= $this->mArticle
->getContent();
712 if ( !$this->mArticle
->exists() && $this->mArticle
->mTitle
->getNamespace() == NS_MEDIAWIKI
)
713 $this->textbox1
= wfMsgWeirdKey ( $this->mArticle
->mTitle
->getText() ) ;
718 * Send the edit form and related headers to $wgOut
719 * @param $formCallback Optional callable that takes an OutputPage
720 * parameter; will be called during form output
721 * near the top, for captchas and the like.
723 function showEditForm( $formCallback=null ) {
724 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize;
726 $fname = 'EditPage::showEditForm';
727 wfProfileIn( $fname );
729 $sk =& $wgUser->getSkin();
731 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
733 $wgOut->setRobotpolicy( 'noindex,nofollow' );
735 # Enabled article-related sidebar, toplinks, etc.
736 $wgOut->setArticleRelated( true );
738 if ( $this->isConflict
) {
739 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
740 $wgOut->setPageTitle( $s );
741 $wgOut->addWikiText( wfMsg( 'explainconflict' ) );
743 $this->textbox2
= $this->textbox1
;
744 $this->textbox1
= $this->mArticle
->getContent();
745 $this->edittime
= $this->mArticle
->getTimestamp();
748 if( $this->section
!= '' ) {
749 if( $this->section
== 'new' ) {
750 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
752 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
753 if( !$this->preview
&& !$this->diff
) {
754 preg_match( "/^(=+)(.+)\\1/mi",
757 if( !empty( $matches[2] ) ) {
758 $this->summary
= "/* ". trim($matches[2])." */ ";
763 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
765 $wgOut->setPageTitle( $s );
767 if ( $this->missingComment
) {
768 $wgOut->addWikiText( wfMsg( 'missingcommenttext' ) );
771 if( $this->missingSummary
) {
772 $wgOut->addWikiText( wfMsg( 'missingsummary' ) );
775 if ( !$this->checkUnicodeCompliantBrowser() ) {
776 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
778 if ( isset( $this->mArticle
)
779 && isset( $this->mArticle
->mRevision
)
780 && !$this->mArticle
->mRevision
->isCurrent() ) {
781 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
782 $wgOut->addWikiText( wfMsg( 'editingold' ) );
787 $wgOut->addWikiText( wfMsg( 'readonlywarning' ) );
788 } elseif( $wgUser->isAnon() && $this->formtype
!= 'preview' ) {
789 $wgOut->addWikiText( wfMsg( 'anoneditwarning' ) );
791 if( $this->isCssJsSubpage
&& $this->formtype
!= 'preview' ) {
792 # Check the skin exists
793 if( $this->isValidCssJsSubpage
) {
794 $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ) );
796 $wgOut->addWikiText( wfMsg( 'userinvalidcssjstitle', $this->mTitle
->getSkinFromCssJsSubpage() ) );
801 if( $this->mTitle
->isProtected( 'edit' ) ) {
802 # Is the protection due to the namespace, e.g. interface text?
803 if( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
804 # Yes; remind the user
805 $notice = wfMsg( 'editinginterface' );
806 } elseif( $this->mTitle
->isSemiProtected() ) {
808 $notice = wfMsg( 'semiprotectedpagewarning' );
809 if( wfEmptyMsg( 'semiprotectedpagewarning', $notice ) ||
$notice == '-' ) {
813 # No; regular protection
814 $notice = wfMsg( 'protectedpagewarning' );
816 $wgOut->addWikiText( $notice );
819 if ( $this->kblength
=== false ) {
820 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
822 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
823 $wgOut->addWikiText( wfMsg( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgMaxArticleSize ) );
824 } elseif( $this->kblength
> 29 ) {
825 $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength
) ) );
828 $rows = $wgUser->getOption( 'rows' );
829 $cols = $wgUser->getOption( 'cols' );
831 $ew = $wgUser->getOption( 'editwidth' );
832 if ( $ew ) $ew = " style=\"width:100%\"";
835 $q = 'action=submit';
836 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
837 $action = $this->mTitle
->escapeLocalURL( $q );
839 $summary = wfMsg('summary');
840 $subject = wfMsg('subject');
841 $minor = wfMsg('minoredit');
842 $watchthis = wfMsg ('watchthis');
844 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
846 $edithelpurl = $sk->makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
847 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
848 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
849 htmlspecialchars( wfMsg( 'newwindow' ) );
851 global $wgRightsText;
852 $copywarn = "<div id=\"editpage-copywarn\">\n" .
853 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
854 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
855 $wgRightsText ) . "\n</div>";
857 if( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage
) {
858 # prepare toolbar for edit buttons
859 $toolbar = $this->getEditToolbar();
864 // activate checkboxes if user wants them to be always active
865 if( !$this->preview
&& !$this->diff
) {
866 # Sort out the "watch" checkbox
867 if( $wgUser->getOption( 'watchdefault' ) ) {
869 $this->watchthis
= true;
870 } elseif( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
872 $this->watchthis
= true;
873 } elseif( $this->mTitle
->userIsWatching() ) {
875 $this->watchthis
= true;
878 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
883 if ( $wgUser->isAllowed('minoredit') ) {
885 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
886 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
887 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
892 if ( $wgUser->isLoggedIn() ) {
893 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".
894 ($this->watchthis?
" checked='checked'":"").
895 " accesskey=\"".htmlspecialchars(wfMsg('accesskey-watch'))."\" id='wpWatchthis' />".
896 "<label for='wpWatchthis' title=\"" .
897 htmlspecialchars(wfMsg('tooltip-watch'))."\">{$watchthis}</label>";
900 $checkboxhtml = $minoredithtml . $watchhtml;
902 if ( $wgUser->getOption( 'previewontop' ) ) {
904 if ( 'preview' == $this->formtype
) {
905 $this->showPreview();
907 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
910 if ( 'diff' == $this->formtype
) {
911 $wgOut->addHTML( $this->getDiff() );
916 # if this is a comment, show a subject line at the top, which is also the edit summary.
917 # Otherwise, show a summary field at the bottom
918 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
919 if( $this->section
== 'new' ) {
920 $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 />";
923 $commentsubject = '';
924 $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 />";
927 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
928 if( !$this->preview
&& !$this->diff
) {
929 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
931 $templates = $this->formatTemplates();
933 global $wgUseMetadataEdit ;
934 if ( $wgUseMetadataEdit ) {
935 $metadata = $this->mMetaData
;
936 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
937 $helppage = Title
::newFromText( wfMsg( "metadata_page" ) ) ;
938 $top = wfMsg( 'metadata', $helppage->getLocalURL() );
939 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
941 else $metadata = "" ;
945 if ($this->deletedSinceEdit
) {
946 if ( 'save' != $this->formtype
) {
947 $wgOut->addWikiText( wfMsg('deletedwhileediting'));
949 // Hide the toolbar and edit area, use can click preview to get it back
950 // Add an confirmation checkbox and explanation.
952 $hidden = 'type="hidden" style="display:none;"';
953 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete
->user_name
, $this->lastDelete
->log_comment
));
955 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
956 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
965 'value' => wfMsg('savearticle'),
966 'accesskey' => wfMsg('accesskey-save'),
967 'title' => wfMsg('tooltip-save'),
969 $buttons['save'] = wfElement('input', $temp, '');
975 'value' => wfMsg('showdiff'),
976 'accesskey' => wfMsg('accesskey-diff'),
977 'title' => wfMsg('tooltip-diff'),
979 $buttons['diff'] = wfElement('input', $temp, '');
981 global $wgLivePreview;
982 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
985 'name' => 'wpPreview',
988 'value' => wfMsg('showpreview'),
990 'title' => wfMsg('tooltip-preview'),
991 'style' => 'display: none;',
993 $buttons['preview'] = wfElement('input', $temp, '');
995 'id' => 'wpLivePreview',
996 'name' => 'wpLivePreview',
999 'value' => wfMsg('showlivepreview'),
1000 'accesskey' => wfMsg('accesskey-preview'),
1002 'onclick' => $this->doLivePreviewScript(),
1004 $buttons['live'] = wfElement('input', $temp, '');
1007 'id' => 'wpPreview',
1008 'name' => 'wpPreview',
1011 'value' => wfMsg('showpreview'),
1012 'accesskey' => wfMsg('accesskey-preview'),
1013 'title' => wfMsg('tooltip-preview'),
1015 $buttons['preview'] = wfElement('input', $temp, '');
1016 $buttons['live'] = '';
1019 $safemodehtml = $this->checkUnicodeCompliantBrowser()
1021 : "<input type='hidden' name=\"safemode\" value='1' />\n";
1023 $wgOut->addHTML( <<<END
1025 <form id="editform" name="editform" method="post" action="$action"
1026 enctype="multipart/form-data">
1030 if( is_callable( $formCallback ) ) {
1031 call_user_func_array( $formCallback, array( &$wgOut ) );
1034 // Put these up at the top to ensure they aren't lost on early form submission
1036 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
1037 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1038 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1039 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
1041 $wgOut->addHTML( <<<END
1044 <textarea tabindex='1' accesskey="," name="wpTextbox1" id="wpTextbox1" rows='{$rows}'
1045 cols='{$cols}'{$ew} $hidden>
1047 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1
) ) .
1052 $wgOut->addWikiText( $copywarn );
1061 <div class='editButtons'>
1063 {$buttons['preview']}
1066 <span class='editHelp'>{$cancel} | {$edithelp}</span>
1067 </div><!-- editButtons -->
1068 </div><!-- editOptions -->");
1070 $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
1073 <div class='templatesUsed'>
1078 if ( $wgUser->isLoggedIn() ) {
1080 * To make it harder for someone to slip a user a page
1081 * which submits an edit form to the wiki without their
1082 * knowledge, a random token is associated with the login
1083 * session. If it's not passed back with the submission,
1084 * we won't save the page, or render user JavaScript and
1087 $token = htmlspecialchars( $wgUser->editToken() );
1088 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1091 # If a blank edit summary was previously provided, and the appropriate
1092 # user preference is active, pass a hidden tag here. This will stop the
1093 # user being bounced back more than once in the event that a summary
1095 if( $this->missingSummary
) {
1096 $wgOut->addHTML( "<input type=\"hidden\" name=\"wpIgnoreBlankSummary\" value=\"1\" />\n" );
1099 # For a bit more sophisticated detection of blank summaries, hash the
1100 # automatic one and pass that in a hidden field.
1101 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
1102 $wgOut->addHTML( "<input type=\"hidden\" name=\"wpAutoSummary\" value=\"$autosumm\" />\n" );
1104 if ( $this->isConflict
) {
1105 require_once( "DifferenceEngine.php" );
1106 $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' );
1108 $de = new DifferenceEngine( $this->mTitle
);
1109 $de->setText( $this->textbox2
, $this->textbox1
);
1110 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1112 $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
1113 $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
1114 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2
) ) . "\n</textarea>" );
1116 $wgOut->addHTML( "</form>\n" );
1117 if ( !$wgUser->getOption( 'previewontop' ) ) {
1119 if ( $this->formtype
== 'preview') {
1120 $this->showPreview();
1122 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
1125 if ( $this->formtype
== 'diff') {
1126 $wgOut->addHTML( $this->getDiff() );
1131 wfProfileOut( $fname );
1135 * Append preview output to $wgOut.
1136 * Includes category rendering if this is a category page.
1139 function showPreview() {
1141 $wgOut->addHTML( '<div id="wikiPreview">' );
1142 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1143 $this->mArticle
->openShowCategory();
1145 $previewOutput = $this->getPreviewText();
1146 $wgOut->addHTML( $previewOutput );
1147 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1148 $this->mArticle
->closeShowCategory();
1150 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
1151 $wgOut->addHTML( '</div>' );
1155 * Prepare a list of templates used by this page. Returns HTML.
1157 function formatTemplates() {
1160 $fname = 'EditPage::formatTemplates';
1161 wfProfileIn( $fname );
1163 $sk =& $wgUser->getSkin();
1166 $templates = $this->mArticle
->getUsedTemplates();
1167 if ( count( $templates ) > 0 ) {
1168 # Do a batch existence check
1169 $batch = new LinkBatch
;
1170 foreach( $templates as $title ) {
1171 $batch->addObj( $title );
1175 # Construct the HTML
1176 $outText = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
1177 foreach ( $templates as $titleObj ) {
1178 $outText .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
1180 $outText .= '</ul>';
1182 wfProfileOut( $fname );
1187 * Live Preview lets us fetch rendered preview page content and
1188 * add it to the page without refreshing the whole page.
1189 * If not supported by the browser it will fall through to the normal form
1190 * submission method.
1192 * This function outputs a script tag to support live preview, and
1193 * returns an onclick handler which should be added to the attributes
1194 * of the preview button
1196 function doLivePreviewScript() {
1197 global $wgStylePath, $wgJsMimeType, $wgOut, $wgTitle;
1198 $wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' .
1199 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
1200 '"></script>' . "\n" );
1201 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
1202 return "return !livePreview(" .
1203 "getElementById('wikiPreview')," .
1204 "editform.wpTextbox1.value," .
1205 '"' . $liveAction . '"' . ")";
1208 function getLastDelete() {
1209 $dbr =& wfGetDB( DB_SLAVE
);
1210 $fname = 'EditPage::getLastDelete';
1211 $res = $dbr->select(
1212 array( 'logging', 'user' ),
1222 array( 'log_namespace' => $this->mTitle
->getNamespace(),
1223 'log_title' => $this->mTitle
->getDBkey(),
1224 'log_type' => 'delete',
1225 'log_action' => 'delete',
1226 'user_id=log_user' ),
1228 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1230 if($dbr->numRows($res) == 1) {
1231 while ( $x = $dbr->fetchObject ( $res ) )
1233 $dbr->freeResult ( $res ) ;
1243 function getPreviewText() {
1244 global $wgOut, $wgUser, $wgTitle, $wgParser;
1246 $fname = 'EditPage::getPreviewText';
1247 wfProfileIn( $fname );
1249 if ( $this->mTokenOk
) {
1250 $msg = 'previewnote';
1252 $msg = 'session_fail_preview';
1254 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1255 "<div class='previewnote'>" . $wgOut->parse( wfMsg( $msg ) ) . "</div>\n";
1256 if ( $this->isConflict
) {
1257 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1260 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1261 $parserOptions->setEditSection( false );
1263 # don't parse user css/js, show message about preview
1264 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1266 if ( $this->isCssJsSubpage
) {
1267 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
1268 $previewtext = wfMsg('usercsspreview');
1269 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
1270 $previewtext = wfMsg('userjspreview');
1272 $parserOptions->setTidy(true);
1273 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
1274 $wgOut->addHTML( $parserOutput->mText
);
1275 wfProfileOut( $fname );
1276 return $previewhead;
1278 # if user want to see preview when he edit an article
1279 if( $wgUser->getOption('previewonfirst') and ($this->textbox1
== '')) {
1280 $this->textbox1
= $this->mArticle
->getContent();
1283 $toparse = $this->textbox1
;
1285 # If we're adding a comment, we need to show the
1286 # summary as the headline
1287 if($this->section
=="new" && $this->summary
!="") {
1288 $toparse="== {$this->summary} ==\n\n".$toparse;
1291 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
1292 $parserOptions->setTidy(true);
1293 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
1294 $wgTitle, $parserOptions );
1296 $previewHTML = $parserOutput->getText();
1297 $wgOut->addParserOutputNoText( $parserOutput );
1299 wfProfileOut( $fname );
1300 return $previewhead . $previewHTML;
1307 function blockedIPpage() {
1309 $wgOut->blockedPage();
1315 function userNotLoggedInPage() {
1316 global $wgUser, $wgOut;
1317 $skin = $wgUser->getSkin();
1318 $loginTitle = Title
::makeTitle( NS_SPECIAL
, 'Userlogin' );
1319 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $this->mTitle
->getPrefixedText() );
1321 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1322 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1323 $wgOut->setArticleRelated( false );
1325 $wgOut->addHtml( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1326 $wgOut->returnToMain( false );
1330 * Creates a basic error page which informs the user that
1331 * they have to validate their email address before being
1334 function userNotConfirmedPage() {
1338 $wgOut->setPageTitle( wfMsg( 'confirmedittitle' ) );
1339 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1340 $wgOut->setArticleRelated( false );
1341 $wgOut->addWikiText( wfMsg( 'confirmedittext' ) );
1342 $wgOut->returnToMain( false );
1348 function spamPage ( $match = false )
1351 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1352 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1353 $wgOut->setArticleRelated( false );
1355 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
1357 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
1359 $wgOut->returnToMain( false );
1366 function mergeChangesInto( &$editText ){
1367 $fname = 'EditPage::mergeChangesInto';
1368 wfProfileIn( $fname );
1370 $db =& wfGetDB( DB_MASTER
);
1372 // This is the revision the editor started from
1373 $baseRevision = Revision
::loadFromTimestamp(
1374 $db, $this->mArticle
->mTitle
, $this->edittime
);
1375 if( is_null( $baseRevision ) ) {
1376 wfProfileOut( $fname );
1379 $baseText = $baseRevision->getText();
1381 // The current state, we want to merge updates into it
1382 $currentRevision = Revision
::loadFromTitle(
1383 $db, $this->mArticle
->mTitle
);
1384 if( is_null( $currentRevision ) ) {
1385 wfProfileOut( $fname );
1388 $currentText = $currentRevision->getText();
1390 if( wfMerge( $baseText, $editText, $currentText, $result ) ){
1391 $editText = $result;
1392 wfProfileOut( $fname );
1395 wfProfileOut( $fname );
1401 * Check if the browser is on a blacklist of user-agents known to
1402 * mangle UTF-8 data on form submission. Returns true if Unicode
1403 * should make it through, false if it's known to be a problem.
1407 function checkUnicodeCompliantBrowser() {
1408 global $wgBrowserBlackList;
1409 if( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1410 // No User-Agent header sent? Trust it by default...
1413 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1414 foreach ( $wgBrowserBlackList as $browser ) {
1415 if ( preg_match($browser, $currentbrowser) ) {
1423 * Format an anchor fragment as it would appear for a given section name
1424 * @param string $text
1428 function sectionAnchor( $text ) {
1429 $headline = Sanitizer
::decodeCharReferences( $text );
1431 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
1432 $headline = trim( $headline );
1433 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
1434 $replacearray = array(
1439 array_keys( $replacearray ),
1440 array_values( $replacearray ),
1445 * Shows a bulletin board style toolbar for common editing functions.
1446 * It can be disabled in the user preferences.
1447 * The necessary JavaScript code can be found in style/wikibits.js.
1449 function getEditToolbar() {
1450 global $wgStylePath, $wgContLang, $wgJsMimeType;
1453 * toolarray an array of arrays which each include the filename of
1454 * the button image (without path), the opening tag, the closing tag,
1455 * and optionally a sample text that is inserted between the two when no
1456 * selection is highlighted.
1457 * The tip text is shown when the user moves the mouse over the button.
1459 * Already here are accesskeys (key), which are not used yet until someone
1460 * can figure out a way to make them work in IE. However, we should make
1461 * sure these keys are not defined on the edit page.
1464 array( 'image'=>'button_bold.png',
1466 'close' => "\'\'\'",
1467 'sample'=> wfMsg('bold_sample'),
1468 'tip' => wfMsg('bold_tip'),
1471 array( 'image'=>'button_italic.png',
1474 'sample'=> wfMsg('italic_sample'),
1475 'tip' => wfMsg('italic_tip'),
1478 array( 'image'=>'button_link.png',
1481 'sample'=> wfMsg('link_sample'),
1482 'tip' => wfMsg('link_tip'),
1485 array( 'image'=>'button_extlink.png',
1488 'sample'=> wfMsg('extlink_sample'),
1489 'tip' => wfMsg('extlink_tip'),
1492 array( 'image'=>'button_headline.png',
1494 'close' => " ==\\n",
1495 'sample'=> wfMsg('headline_sample'),
1496 'tip' => wfMsg('headline_tip'),
1499 array( 'image'=>'button_image.png',
1500 'open' => '[['.$wgContLang->getNsText(NS_IMAGE
).":",
1502 'sample'=> wfMsg('image_sample'),
1503 'tip' => wfMsg('image_tip'),
1506 array( 'image' =>'button_media.png',
1507 'open' => '[['.$wgContLang->getNsText(NS_MEDIA
).':',
1509 'sample'=> wfMsg('media_sample'),
1510 'tip' => wfMsg('media_tip'),
1513 array( 'image' =>'button_math.png',
1514 'open' => "\\<math\\>",
1515 'close' => "\\</math\\>",
1516 'sample'=> wfMsg('math_sample'),
1517 'tip' => wfMsg('math_tip'),
1520 array( 'image' =>'button_nowiki.png',
1521 'open' => "\\<nowiki\\>",
1522 'close' => "\\</nowiki\\>",
1523 'sample'=> wfMsg('nowiki_sample'),
1524 'tip' => wfMsg('nowiki_tip'),
1527 array( 'image' =>'button_sig.png',
1531 'tip' => wfMsg('sig_tip'),
1534 array( 'image' =>'button_hr.png',
1535 'open' => "\\n----\\n",
1538 'tip' => wfMsg('hr_tip'),
1542 $toolbar = "<div id='toolbar'>\n";
1543 $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
1545 foreach($toolarray as $tool) {
1547 $image=$wgStylePath.'/common/images/'.$tool['image'];
1548 $open=$tool['open'];
1549 $close=$tool['close'];
1550 $sample = wfEscapeJsString( $tool['sample'] );
1552 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1553 // Older browsers show a "speedtip" type message only for ALT.
1554 // Ideally these should be different, realistically they
1555 // probably don't need to be.
1556 $tip = wfEscapeJsString( $tool['tip'] );
1558 #$key = $tool["key"];
1560 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
1563 $toolbar.="/*]]>*/\n</script>";
1564 $toolbar.="\n</div>";
1569 * Output preview text only. This can be sucked into the edit page
1570 * via JavaScript, and saves the server time rendering the skin as
1571 * well as theoretically being more robust on the client (doesn't
1572 * disturb the edit box's undo history, won't eat your text on
1575 * @todo This doesn't include category or interlanguage links.
1576 * Would need to enhance it a bit, maybe wrap them in XML
1577 * or something... that might also require more skin
1578 * initialization, so check whether that's a problem.
1580 function livePreview() {
1583 header( 'Content-type: text/xml' );
1584 header( 'Cache-control: no-cache' );
1586 echo $this->getPreviewText( );
1587 /* To not shake screen up and down between preview and live-preview */
1588 echo "<br style=\"clear:both;\" />\n";
1593 * Get a diff between the current contents of the edit box and the
1594 * version of the page we're editing from.
1596 * If this is a section edit, we'll replace the section as for final
1597 * save and then make a comparison.
1599 * @return string HTML
1601 function getDiff() {
1602 require_once( 'DifferenceEngine.php' );
1603 $oldtext = $this->mArticle
->fetchContent();
1604 $newtext = $this->mArticle
->replaceSection(
1605 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1606 $oldtitle = wfMsg( 'currentrev' );
1607 $newtitle = wfMsg( 'yourtext' );
1608 if ( $oldtext !== false ||
$newtext != '' ) {
1609 $de = new DifferenceEngine( $this->mTitle
);
1610 $de->setText( $oldtext, $newtext );
1611 $difftext = $de->getDiff( $oldtitle, $newtitle );
1616 return '<div id="wikiDiff">' . $difftext . '</div>';
1620 * Filter an input field through a Unicode de-armoring process if it
1621 * came from an old browser with known broken Unicode editing issues.
1623 * @param WebRequest $request
1624 * @param string $field
1628 function safeUnicodeInput( $request, $field ) {
1629 $text = rtrim( $request->getText( $field ) );
1630 return $request->getBool( 'safemode' )
1631 ?
$this->unmakesafe( $text )
1636 * Filter an output field through a Unicode armoring process if it is
1637 * going to an old browser with known broken Unicode editing issues.
1639 * @param string $text
1643 function safeUnicodeOutput( $text ) {
1645 $codedText = $wgContLang->recodeForEdit( $text );
1646 return $this->checkUnicodeCompliantBrowser()
1648 : $this->makesafe( $codedText );
1652 * A number of web browsers are known to corrupt non-ASCII characters
1653 * in a UTF-8 text editing environment. To protect against this,
1654 * detected browsers will be served an armored version of the text,
1655 * with non-ASCII chars converted to numeric HTML character references.
1657 * Preexisting such character references will have a 0 added to them
1658 * to ensure that round-trips do not alter the original data.
1660 * @param string $invalue
1664 function makesafe( $invalue ) {
1665 // Armor existing references for reversability.
1666 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
1671 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1672 $bytevalue = ord( $invalue{$i} );
1673 if( $bytevalue <= 0x7F ) { //0xxx xxxx
1674 $result .= chr( $bytevalue );
1676 } elseif( $bytevalue <= 0xBF ) { //10xx xxxx
1677 $working = $working << 6;
1678 $working +
= ($bytevalue & 0x3F);
1680 if( $bytesleft <= 0 ) {
1681 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
1683 } elseif( $bytevalue <= 0xDF ) { //110x xxxx
1684 $working = $bytevalue & 0x1F;
1686 } elseif( $bytevalue <= 0xEF ) { //1110 xxxx
1687 $working = $bytevalue & 0x0F;
1689 } else { //1111 0xxx
1690 $working = $bytevalue & 0x07;
1698 * Reverse the previously applied transliteration of non-ASCII characters
1699 * back to UTF-8. Used to protect data from corruption by broken web browsers
1700 * as listed in $wgBrowserBlackList.
1702 * @param string $invalue
1706 function unmakesafe( $invalue ) {
1708 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1709 if( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+
3} != '0' ) ) {
1713 $hexstring .= $invalue{$i};
1715 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
1717 // Do some sanity checks. These aren't needed for reversability,
1718 // but should help keep the breakage down if the editor
1719 // breaks one of the entities whilst editing.
1720 if ((substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6)) {
1721 $codepoint = hexdec($hexstring);
1722 $result .= codepointToUtf8( $codepoint );
1724 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
1727 $result .= substr( $invalue, $i, 1 );
1730 // reverse the transform that we made for reversability reasons.
1731 return strtr( $result, array( "�" => "&#x" ) );
1734 function noCreatePermission() {
1736 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
1737 $wgOut->addWikiText( wfMsg( 'nocreatetext' ) );