3 * Contain the EditPage class
8 * Splitting edit page/HTML interface from Article...
9 * The actual database and text munging is still in Article,
10 * but it should get easier to call those from alternate
20 var $isConflict = false;
21 var $isCssJsSubpage = false;
22 var $deletedSinceEdit = false;
26 var $mTokenOk = false;
27 var $mTriedSave = false;
29 var $kblength = false;
30 var $missingComment = false;
31 var $missingSummary = false;
32 var $allowBlankSummary = false;
37 var $save = false, $preview = false, $diff = false;
38 var $minoredit = false, $watchthis = false, $recreate = false;
39 var $textbox1 = '', $textbox2 = '', $summary = '';
40 var $edittime = '', $section = '', $starttime = '';
41 var $oldid = 0, $editintro = '', $scrolltop = null;
47 function EditPage( $article ) {
48 $this->mArticle
=& $article;
50 $this->mTitle
=& $wgTitle;
54 * This is the function that extracts metadata from the article body on the first view.
55 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
56 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
58 function extractMetaDataFromArticle () {
59 global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
60 $this->mMetaData
= '' ;
61 if ( !$wgUseMetadataEdit ) return ;
62 if ( $wgMetadataWhitelist == '' ) return ;
64 $t = $this->mArticle
->getContent();
66 # MISSING : <nowiki> filtering
68 # Categories and language links
69 $t = explode ( "\n" , $t ) ;
70 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY
) ) ;
71 $cat = $ll = array() ;
72 foreach ( $t AS $key => $x )
74 $y = trim ( strtolower ( $x ) ) ;
75 while ( substr ( $y , 0 , 2 ) == '[[' )
77 $y = explode ( ']]' , trim ( $x ) ) ;
78 $first = array_shift ( $y ) ;
79 $first = explode ( ':' , $first ) ;
80 $ns = array_shift ( $first ) ;
81 $ns = trim ( str_replace ( '[' , '' , $ns ) ) ;
82 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
84 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]' ;
85 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
87 $x = implode ( ']]' , $y ) ;
89 $y = trim ( strtolower ( $x ) ) ;
93 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n" ;
94 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n" ;
95 $t = implode ( "\n" , $t ) ;
98 $sat = array () ; # stand-alone-templates; must be lowercase
99 $wl_title = Title
::newFromText ( $wgMetadataWhitelist ) ;
100 $wl_article = new Article ( $wl_title ) ;
101 $wl = explode ( "\n" , $wl_article->getContent() ) ;
102 foreach ( $wl AS $x )
106 while ( substr ( $x , 0 , 1 ) == '*' )
109 $x = trim ( substr ( $x , 1 ) ) ;
113 $sat[] = strtolower ( $x ) ;
118 # Templates, but only some
119 $t = explode ( '{{' , $t ) ;
121 foreach ( $t AS $key => $x )
123 $y = explode ( '}}' , $x , 2 ) ;
124 if ( count ( $y ) == 2 )
127 $z = explode ( '|' , $z ) ;
128 $tn = array_shift ( $z ) ;
129 if ( in_array ( strtolower ( $tn ) , $sat ) )
131 $tl[] = '{{' . $y[0] . '}}' ;
133 $y = explode ( '}}' , $y[1] , 2 ) ;
135 else $t[$key] = '{{' . $x ;
137 else if ( $key != 0 ) $t[$key] = '{{' . $x ;
140 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl ) ;
141 $t = implode ( '' , $t ) ;
143 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
144 $this->mArticle
->mContent
= $t ;
145 $this->mMetaData
= $s ;
153 * This is the function that gets called for "action=edit". It
154 * sets up various member variables, then passes execution to
155 * another function, usually showEditForm()
157 * The edit form is self-submitting, so that when things like
158 * preview and edit conflicts occur, we get the same form back
159 * with the extra stuff added. Only when the final submission
160 * is made and all is well do we actually save and redirect to
161 * the newly-edited page.
164 global $wgOut, $wgUser, $wgRequest, $wgTitle;
165 global $wgEmailConfirmToEdit;
167 if ( ! wfRunHooks( 'AlternateEdit', array( &$this ) ) )
170 $fname = 'EditPage::edit';
171 wfProfileIn( $fname );
172 wfDebug( "$fname: enter\n" );
174 // this is not an article
175 $wgOut->setArticleFlag(false);
177 $this->importFormData( $wgRequest );
178 $this->firsttime
= false;
181 $this->livePreview();
182 wfProfileOut( $fname );
186 if ( ! $this->mTitle
->userCanEdit() ) {
187 wfDebug( "$fname: user can't edit\n" );
188 $wgOut->readOnlyPage( $this->mArticle
->getContent(), true );
189 wfProfileOut( $fname );
192 wfDebug( "$fname: Checking blocks\n" );
193 if ( !$this->preview
&& !$this->diff
&& $wgUser->isBlockedFrom( $this->mTitle
, !$this->save
) ) {
194 # When previewing, don't check blocked state - will get caught at save time.
195 # Also, check when starting edition is done against slave to improve performance.
196 wfDebug( "$fname: user is blocked\n" );
197 $wgOut->blockedPage();
198 wfProfileOut( $fname );
201 if ( !$wgUser->isAllowed('edit') ) {
202 if ( $wgUser->isAnon() ) {
203 wfDebug( "$fname: user must log in\n" );
204 $this->userNotLoggedInPage();
205 wfProfileOut( $fname );
208 wfDebug( "$fname: read-only page\n" );
209 $wgOut->readOnlyPage( $this->mArticle
->getContent(), true );
210 wfProfileOut( $fname );
214 if ($wgEmailConfirmToEdit && !$wgUser->isEmailConfirmed()) {
215 wfDebug("$fname: user must confirm e-mail address\n");
216 $this->userNotConfirmedPage();
217 wfProfileOut($fname);
220 if ( !$this->mTitle
->userCan( 'create' ) && !$this->mTitle
->exists() ) {
221 wfDebug( "$fname: no create permission\n" );
222 $this->noCreatePermission();
223 wfProfileOut( $fname );
226 if ( wfReadOnly() ) {
227 wfDebug( "$fname: read-only mode is engaged\n" );
228 if( $this->save ||
$this->preview
) {
229 $this->formtype
= 'preview';
230 } else if ( $this->diff
) {
231 $this->formtype
= 'diff';
233 $wgOut->readOnlyPage( $this->mArticle
->getContent() );
234 wfProfileOut( $fname );
239 $this->formtype
= 'save';
240 } else if ( $this->preview
) {
241 $this->formtype
= 'preview';
242 } else if ( $this->diff
) {
243 $this->formtype
= 'diff';
244 } else { # First time through
245 $this->firsttime
= true;
246 if( $this->previewOnOpen() ) {
247 $this->formtype
= 'preview';
249 $this->extractMetaDataFromArticle () ;
250 $this->formtype
= 'initial';
255 wfProfileIn( "$fname-business-end" );
257 $this->isConflict
= false;
258 // css / js subpages of user pages get a special treatment
259 $this->isCssJsSubpage
= $wgTitle->isCssJsSubpage();
260 $this->isValidCssJsSubpage
= $wgTitle->isValidCssJsSubpage();
262 /* Notice that we can't use isDeleted, because it returns true if article is ever deleted
263 * no matter it's current state
265 $this->deletedSinceEdit
= false;
266 if ( $this->edittime
!= '' ) {
267 /* Note that we rely on logging table, which hasn't been always there,
268 * but that doesn't matter, because this only applies to brand new
269 * deletes. This is done on every preview and save request. Move it further down
270 * to only perform it on saves
272 if ( $this->mTitle
->isDeleted() ) {
273 $this->lastDelete
= $this->getLastDelete();
274 if ( !is_null($this->lastDelete
) ) {
275 $deletetime = $this->lastDelete
->log_timestamp
;
276 if ( ($deletetime - $this->starttime
) > 0 ) {
277 $this->deletedSinceEdit
= true;
283 if(!$this->mTitle
->getArticleID() && ('initial' == $this->formtype ||
$this->firsttime
)) { # new article
286 if( $this->mTitle
->isTalkPage() ) {
287 $wgOut->addWikiText( wfMsg( 'talkpagetext' ) );
290 # Attempt submission here. This will check for edit conflicts,
291 # and redundantly check for locked database, blocked IPs, etc.
292 # that edit() already checked just in case someone tries to sneak
293 # in the back door with a hand-edited submission URL.
295 if ( 'save' == $this->formtype
) {
296 if ( !$this->attemptSave() ) {
297 wfProfileOut( "$fname-business-end" );
298 wfProfileOut( $fname );
303 # First time through: get contents, set time for conflict
305 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
306 $this->initialiseForm();
309 $this->showEditForm();
310 wfProfileOut( "$fname-business-end" );
311 wfProfileOut( $fname );
315 * Return true if this page should be previewed when the edit form
316 * is initially opened.
320 function previewOnOpen() {
322 return $this->section
!= 'new' &&
323 ( ( $wgUser->getOption( 'previewonfirst' ) && $this->mTitle
->exists() ) ||
324 ( $this->mTitle
->getNamespace() == NS_CATEGORY
&&
325 !$this->mTitle
->exists() ) );
332 function importFormData( &$request ) {
333 global $wgLang, $wgUser;
334 $fname = 'EditPage::importFormData';
335 wfProfileIn( $fname );
337 if( $request->wasPosted() ) {
338 # These fields need to be checked for encoding.
339 # Also remove trailing whitespace, but don't remove _initial_
340 # whitespace from the text boxes. This may be significant formatting.
341 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
342 $this->textbox2
= $this->safeUnicodeInput( $request, 'wpTextbox2' );
343 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
344 # Truncate for whole multibyte characters. +5 bytes for ellipsis
345 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
347 $this->edittime
= $request->getVal( 'wpEdittime' );
348 $this->starttime
= $request->getVal( 'wpStarttime' );
350 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
352 if( is_null( $this->edittime
) ) {
353 # If the form is incomplete, force to preview.
354 wfDebug( "$fname: Form data appears to be incomplete\n" );
355 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
356 $this->preview
= true;
358 /* Fallback for live preview */
359 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
360 $this->diff
= $request->getCheck( 'wpDiff' );
362 // Remember whether a save was requested, so we can indicate
363 // if we forced preview due to session failure.
364 $this->mTriedSave
= !$this->preview
;
366 if ( $this->tokenOk( $request ) ) {
367 # Some browsers will not report any submit button
368 # if the user hits enter in the comment box.
369 # The unmarked state will be assumed to be a save,
370 # if the form seems otherwise complete.
371 wfDebug( "$fname: Passed token check.\n" );
373 # Page might be a hack attempt posted from
374 # an external site. Preview instead of saving.
375 wfDebug( "$fname: Failed token check; forcing preview\n" );
376 $this->preview
= true;
379 $this->save
= ! ( $this->preview
OR $this->diff
);
380 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
381 $this->edittime
= null;
384 if( !preg_match( '/^\d{14}$/', $this->starttime
)) {
385 $this->starttime
= null;
388 $this->recreate
= $request->getCheck( 'wpRecreate' );
390 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
391 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
393 # Don't force edit summaries when a user is editing their own user or talk page
394 if( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) && $this->mTitle
->getText() == $wgUser->getName() ) {
395 $this->allowBlankSummary
= true;
397 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' );
400 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
402 # Not a posted form? Start with nothing.
403 wfDebug( "$fname: Not a posted form.\n" );
404 $this->textbox1
= '';
405 $this->textbox2
= '';
406 $this->mMetaData
= '';
408 $this->edittime
= '';
409 $this->starttime
= wfTimestampNow();
410 $this->preview
= false;
413 $this->minoredit
= false;
414 $this->watchthis
= false;
415 $this->recreate
= false;
418 $this->oldid
= $request->getInt( 'oldid' );
420 # Section edit can come from either the form or a link
421 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
423 $this->live
= $request->getCheck( 'live' );
424 $this->editintro
= $request->getText( 'editintro' );
426 wfProfileOut( $fname );
430 * Make sure the form isn't faking a user's credentials.
432 * @param $request WebRequest
436 function tokenOk( &$request ) {
438 if( $wgUser->isAnon() ) {
439 # Anonymous users may not have a session
440 # open. Don't tokenize.
441 $this->mTokenOk
= true;
443 $this->mTokenOk
= $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
445 return $this->mTokenOk
;
449 function showIntro() {
450 global $wgOut, $wgUser;
451 $addstandardintro=true;
452 if($this->editintro
) {
453 $introtitle=Title
::newFromText($this->editintro
);
454 if(isset($introtitle) && $introtitle->userCanRead()) {
455 $rev=Revision
::newFromTitle($introtitle);
457 $wgOut->addSecondaryWikiText($rev->getText());
458 $addstandardintro=false;
462 if($addstandardintro) {
463 if ( $wgUser->isLoggedIn() )
464 $wgOut->addWikiText( wfMsg( 'newarticletext' ) );
466 $wgOut->addWikiText( wfMsg( 'newarticletextanon' ) );
472 * @return bool false if output is done, true if the rest of the form should be displayed
474 function attemptSave() {
475 global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut;
476 global $wgMaxArticleSize;
478 $fname = 'EditPage::attemptSave';
479 wfProfileIn( $fname );
480 wfProfileIn( "$fname-checks" );
482 # Reintegrate metadata
483 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
484 $this->mMetaData
= '' ;
487 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
488 $this->spamPage ( $matches[0] );
489 wfProfileOut( "$fname-checks" );
490 wfProfileOut( $fname );
493 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
494 # Error messages or other handling should be performed by the filter function
495 wfProfileOut( $fname );
496 wfProfileOut( "$fname-checks" );
499 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1
, $this->section
, &$this->hookError
) ) ) {
500 # Error messages etc. could be handled within the hook...
501 wfProfileOut( $fname );
502 wfProfileOut( "$fname-checks" );
504 } elseif( $this->hookError
!= '' ) {
505 # ...or the hook could be expecting us to produce an error
506 wfProfileOut( "$fname-checks " );
507 wfProfileOut( $fname );
510 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
511 # Check block state against master, thus 'false'.
512 $this->blockedIPpage();
513 wfProfileOut( "$fname-checks" );
514 wfProfileOut( $fname );
517 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
518 if ( $this->kblength
> $wgMaxArticleSize ) {
519 // Error will be displayed by showEditForm()
520 $this->tooBig
= true;
521 wfProfileOut( "$fname-checks" );
522 wfProfileOut( $fname );
526 if ( !$wgUser->isAllowed('edit') ) {
527 if ( $wgUser->isAnon() ) {
528 $this->userNotLoggedInPage();
529 wfProfileOut( "$fname-checks" );
530 wfProfileOut( $fname );
534 $wgOut->readOnlyPage();
535 wfProfileOut( "$fname-checks" );
536 wfProfileOut( $fname );
541 if ( wfReadOnly() ) {
542 $wgOut->readOnlyPage();
543 wfProfileOut( "$fname-checks" );
544 wfProfileOut( $fname );
547 if ( $wgUser->pingLimiter() ) {
548 $wgOut->rateLimited();
549 wfProfileOut( "$fname-checks" );
550 wfProfileOut( $fname );
554 # If the article has been deleted while editing, don't save it without
556 if ( $this->deletedSinceEdit
&& !$this->recreate
) {
557 wfProfileOut( "$fname-checks" );
558 wfProfileOut( $fname );
562 wfProfileOut( "$fname-checks" );
564 # If article is new, insert it.
565 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
567 // Late check for create permission, just in case *PARANOIA*
568 if ( !$this->mTitle
->userCan( 'create' ) ) {
569 wfDebug( "$fname: no create permission\n" );
570 $this->noCreatePermission();
571 wfProfileOut( $fname );
575 # Don't save a new article if it's blank.
576 if ( ( '' == $this->textbox1
) ) {
577 $wgOut->redirect( $this->mTitle
->getFullURL() );
578 wfProfileOut( $fname );
582 # If no edit comment was given when creating a new page, and what's being
583 # created is a redirect, be smart and fill in a neat auto-comment
584 if( $this->summary
== '' ) {
585 $rt = Title
::newFromRedirect( $this->textbox1
);
586 if( is_object( $rt ) )
587 $this->summary
= wfMsgForContent( 'autoredircomment', $rt->getPrefixedText() );
590 $isComment=($this->section
=='new');
591 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
592 $this->minoredit
, $this->watchthis
, false, $isComment);
594 wfProfileOut( $fname );
598 # Article exists. Check for edit conflict.
600 $this->mArticle
->clear(); # Force reload of dates, etc.
601 $this->mArticle
->forUpdate( true ); # Lock the article
603 if( $this->mArticle
->getTimestamp() != $this->edittime
) {
604 $this->isConflict
= true;
605 if( $this->section
== 'new' ) {
606 if( $this->mArticle
->getUserText() == $wgUser->getName() &&
607 $this->mArticle
->getComment() == $this->summary
) {
608 // Probably a duplicate submission of a new comment.
609 // This can happen when squid resends a request after
610 // a timeout but the first one actually went through.
611 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
613 // New comment; suppress conflict.
614 $this->isConflict
= false;
615 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
619 $userid = $wgUser->getID();
621 if ( $this->isConflict
) {
622 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
623 $this->mArticle
->getTimestamp() . "'\n" );
624 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
627 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
628 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
630 if( is_null( $text ) ) {
631 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
632 $this->isConflict
= true;
633 $text = $this->textbox1
;
636 # Suppress edit conflict with self, except for section edits where merging is required.
637 if ( ( $this->section
== '' ) && ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
638 wfDebug( "Suppressing edit conflict, same user.\n" );
639 $this->isConflict
= false;
641 # switch from section editing to normal editing in edit conflict
642 if($this->isConflict
) {
644 if( $this->mergeChangesInto( $text ) ){
645 // Successful merge! Maybe we should tell the user the good news?
646 $this->isConflict
= false;
647 wfDebug( "Suppressing edit conflict, successful merge.\n" );
650 $this->textbox1
= $text;
651 wfDebug( "Keeping edit conflict, failed merge.\n" );
656 if ( $this->isConflict
) {
657 wfProfileOut( $fname );
661 # If no edit comment was given when turning a page into a redirect, be smart
662 # and fill in a neat auto-comment
663 if( $this->summary
== '' ) {
664 $rt = Title
::newFromRedirect( $this->textbox1
);
665 if( is_object( $rt ) )
666 $this->summary
= wfMsgForContent( 'autoredircomment', $rt->getPrefixedText() );
669 # Handle the user preference to force summaries here
670 if( $this->section
!= 'new' && !$this->allowBlankSummary
&& $wgUser->getOption( 'forceeditsummary' ) ) {
671 if( md5( $this->summary
) == $this->autoSumm
) {
672 $this->missingSummary
= true;
673 wfProfileOut( $fname );
679 wfProfileIn( "$fname-sectionanchor" );
681 if( $this->section
== 'new' ) {
682 if ( $this->textbox1
== '' ) {
683 $this->missingComment
= true;
686 if( $this->summary
!= '' ) {
687 $sectionanchor = $this->sectionAnchor( $this->summary
);
689 } elseif( $this->section
!= '' ) {
690 # Try to get a section anchor from the section source, redirect to edited section if header found
691 # XXX: might be better to integrate this into Article::replaceSection
692 # for duplicate heading checking and maybe parsing
693 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
694 # we can't deal with anchors, includes, html etc in the header for now,
695 # headline would need to be parsed to improve this
696 if($hasmatch and strlen($matches[2]) > 0) {
697 $sectionanchor = $this->sectionAnchor( $matches[2] );
700 wfProfileOut( "$fname-sectionanchor" );
702 // Save errors may fall down to the edit form, but we've now
703 // merged the section into full text. Clear the section field
704 // so that later submission of conflict forms won't try to
705 // replace that into a duplicated mess.
706 $this->textbox1
= $text;
709 // Check for length errors again now that the section is merged in
710 $this->kblength
= (int)(strlen( $text ) / 1024);
711 if ( $this->kblength
> $wgMaxArticleSize ) {
712 $this->tooBig
= true;
713 wfProfileOut( $fname );
717 # update the article here
718 if( $this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
719 $this->watchthis
, '', $sectionanchor ) ) {
720 wfProfileOut( $fname );
723 $this->isConflict
= true;
725 wfProfileOut( $fname );
730 * Initialise form fields in the object
731 * Called on the first invocation, e.g. when a user clicks an edit link
733 function initialiseForm() {
734 $this->edittime
= $this->mArticle
->getTimestamp();
735 $this->textbox1
= $this->mArticle
->getContent();
737 if ( !$this->mArticle
->exists() && $this->mArticle
->mTitle
->getNamespace() == NS_MEDIAWIKI
)
738 $this->textbox1
= wfMsgWeirdKey ( $this->mArticle
->mTitle
->getText() ) ;
743 * Send the edit form and related headers to $wgOut
744 * @param $formCallback Optional callable that takes an OutputPage
745 * parameter; will be called during form output
746 * near the top, for captchas and the like.
748 function showEditForm( $formCallback=null ) {
749 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize;
751 $fname = 'EditPage::showEditForm';
752 wfProfileIn( $fname );
754 $sk =& $wgUser->getSkin();
756 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
758 $wgOut->setRobotpolicy( 'noindex,nofollow' );
760 # Enabled article-related sidebar, toplinks, etc.
761 $wgOut->setArticleRelated( true );
763 if ( $this->isConflict
) {
764 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
765 $wgOut->setPageTitle( $s );
766 $wgOut->addWikiText( wfMsg( 'explainconflict' ) );
768 $this->textbox2
= $this->textbox1
;
769 $this->textbox1
= $this->mArticle
->getContent();
770 $this->edittime
= $this->mArticle
->getTimestamp();
773 if( $this->section
!= '' ) {
774 if( $this->section
== 'new' ) {
775 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
777 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
778 if( !$this->preview
&& !$this->diff
) {
779 preg_match( "/^(=+)(.+)\\1/mi",
782 if( !empty( $matches[2] ) ) {
783 $this->summary
= "/* ". trim($matches[2])." */ ";
788 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
790 $wgOut->setPageTitle( $s );
792 if ( $this->missingComment
) {
793 $wgOut->addWikiText( wfMsg( 'missingcommenttext' ) );
796 if( $this->missingSummary
) {
797 $wgOut->addWikiText( wfMsg( 'missingsummary' ) );
800 if( !$this->hookError
== '' ) {
801 $wgOut->addWikiText( $this->hookError
);
804 if ( !$this->checkUnicodeCompliantBrowser() ) {
805 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
807 if ( isset( $this->mArticle
)
808 && isset( $this->mArticle
->mRevision
)
809 && !$this->mArticle
->mRevision
->isCurrent() ) {
810 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
811 $wgOut->addWikiText( wfMsg( 'editingold' ) );
816 $wgOut->addWikiText( wfMsg( 'readonlywarning' ) );
817 } elseif( $wgUser->isAnon() && $this->formtype
!= 'preview' ) {
818 $wgOut->addWikiText( wfMsg( 'anoneditwarning' ) );
820 if( $this->isCssJsSubpage
&& $this->formtype
!= 'preview' ) {
821 # Check the skin exists
822 if( $this->isValidCssJsSubpage
) {
823 $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ) );
825 $wgOut->addWikiText( wfMsg( 'userinvalidcssjstitle', $this->mTitle
->getSkinFromCssJsSubpage() ) );
830 if( $this->mTitle
->isProtected( 'edit' ) ) {
831 # Is the protection due to the namespace, e.g. interface text?
832 if( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
833 # Yes; remind the user
834 $notice = wfMsg( 'editinginterface' );
835 } elseif( $this->mTitle
->isSemiProtected() ) {
837 $notice = wfMsg( 'semiprotectedpagewarning' );
838 if( wfEmptyMsg( 'semiprotectedpagewarning', $notice ) ||
$notice == '-' ) {
842 # No; regular protection
843 $notice = wfMsg( 'protectedpagewarning' );
845 $wgOut->addWikiText( $notice );
848 if ( $this->kblength
=== false ) {
849 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
851 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
852 $wgOut->addWikiText( wfMsg( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgMaxArticleSize ) );
853 } elseif( $this->kblength
> 29 ) {
854 $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength
) ) );
857 $rows = $wgUser->getIntOption( 'rows' );
858 $cols = $wgUser->getIntOption( 'cols' );
860 $ew = $wgUser->getOption( 'editwidth' );
861 if ( $ew ) $ew = " style=\"width:100%\"";
864 $q = 'action=submit';
865 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
866 $action = $this->mTitle
->escapeLocalURL( $q );
868 $summary = wfMsg('summary');
869 $subject = wfMsg('subject');
870 $minor = wfMsgExt('minoredit', array('parseinline'));
871 $watchthis = wfMsgExt('watchthis', array('parseinline'));
873 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
874 wfMsgExt('cancel', array('parseinline')) );
875 $edithelpurl = $sk->makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
876 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
877 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
878 htmlspecialchars( wfMsg( 'newwindow' ) );
880 global $wgRightsText;
881 $copywarn = "<div id=\"editpage-copywarn\">\n" .
882 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
883 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
884 $wgRightsText ) . "\n</div>";
886 if( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage
) {
887 # prepare toolbar for edit buttons
888 $toolbar = $this->getEditToolbar();
893 // activate checkboxes if user wants them to be always active
894 if( !$this->preview
&& !$this->diff
) {
895 # Sort out the "watch" checkbox
896 if( $wgUser->getOption( 'watchdefault' ) ) {
898 $this->watchthis
= true;
899 } elseif( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
901 $this->watchthis
= true;
902 } elseif( $this->mTitle
->userIsWatching() ) {
904 $this->watchthis
= true;
907 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
912 if ( $wgUser->isAllowed('minoredit') ) {
914 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
915 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />\n".
916 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>\n";
921 if ( $wgUser->isLoggedIn() ) {
922 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".
923 ($this->watchthis?
" checked='checked'":"").
924 " accesskey=\"".htmlspecialchars(wfMsg('accesskey-watch'))."\" id='wpWatchthis' />\n".
925 "<label for='wpWatchthis' title=\"" .
926 htmlspecialchars(wfMsg('tooltip-watch'))."\">{$watchthis}</label>\n";
929 $checkboxhtml = $minoredithtml . $watchhtml;
931 if ( $wgUser->getOption( 'previewontop' ) ) {
933 if ( 'preview' == $this->formtype
) {
934 $this->showPreview();
936 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
939 if ( 'diff' == $this->formtype
) {
940 $wgOut->addHTML( $this->getDiff() );
945 # if this is a comment, show a subject line at the top, which is also the edit summary.
946 # Otherwise, show a summary field at the bottom
947 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
948 if( $this->section
== 'new' ) {
949 $commentsubject="<span id='wpSummaryLabel'><label for='wpSummary'>{$subject}:</label></span>\n<div class='editOptions'>\n<input tabindex='1' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' /><br />";
952 $commentsubject = '';
953 $editsummary="<span id='wpSummaryLabel'><label for='wpSummary'>{$summary}:</label></span>\n<div class='editOptions'>\n<input tabindex='2' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' /><br />";
956 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
957 if( !$this->preview
&& !$this->diff
) {
958 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
960 $templates = $this->formatTemplates();
962 global $wgUseMetadataEdit ;
963 if ( $wgUseMetadataEdit ) {
964 $metadata = $this->mMetaData
;
965 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
966 $top = wfMsgWikiHtml( 'metadata_help' );
967 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
969 else $metadata = "" ;
973 if ($this->deletedSinceEdit
) {
974 if ( 'save' != $this->formtype
) {
975 $wgOut->addWikiText( wfMsg('deletedwhileediting'));
977 // Hide the toolbar and edit area, use can click preview to get it back
978 // Add an confirmation checkbox and explanation.
980 $hidden = 'type="hidden" style="display:none;"';
981 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete
->user_name
, $this->lastDelete
->log_comment
));
983 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
984 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
993 'value' => wfMsg('savearticle'),
994 'accesskey' => wfMsg('accesskey-save'),
995 'title' => wfMsg('tooltip-save'),
997 $buttons['save'] = wfElement('input', $temp, '');
1003 'value' => wfMsg('showdiff'),
1004 'accesskey' => wfMsg('accesskey-diff'),
1005 'title' => wfMsg('tooltip-diff'),
1007 $buttons['diff'] = wfElement('input', $temp, '');
1009 global $wgLivePreview;
1010 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
1012 'id' => 'wpPreview',
1013 'name' => 'wpPreview',
1016 'value' => wfMsg('showpreview'),
1018 'title' => wfMsg('tooltip-preview'),
1019 'style' => 'display: none;',
1021 $buttons['preview'] = wfElement('input', $temp, '');
1023 'id' => 'wpLivePreview',
1024 'name' => 'wpLivePreview',
1027 'value' => wfMsg('showlivepreview'),
1028 'accesskey' => wfMsg('accesskey-preview'),
1030 'onclick' => $this->doLivePreviewScript(),
1032 $buttons['live'] = wfElement('input', $temp, '');
1035 'id' => 'wpPreview',
1036 'name' => 'wpPreview',
1039 'value' => wfMsg('showpreview'),
1040 'accesskey' => wfMsg('accesskey-preview'),
1041 'title' => wfMsg('tooltip-preview'),
1043 $buttons['preview'] = wfElement('input', $temp, '');
1044 $buttons['live'] = '';
1047 $safemodehtml = $this->checkUnicodeCompliantBrowser()
1049 : "<input type='hidden' name=\"safemode\" value='1' />\n";
1051 $wgOut->addHTML( <<<END
1053 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1057 if( is_callable( $formCallback ) ) {
1058 call_user_func_array( $formCallback, array( &$wgOut ) );
1061 // Put these up at the top to ensure they aren't lost on early form submission
1063 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
1064 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1065 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1066 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
1068 $wgOut->addHTML( <<<END
1071 <textarea tabindex='1' accesskey="," name="wpTextbox1" id="wpTextbox1" rows='{$rows}'
1072 cols='{$cols}'{$ew} $hidden>
1074 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1
) ) .
1079 $wgOut->addWikiText( $copywarn );
1088 "<div class='editButtons'>
1090 {$buttons['preview']}
1093 <span class='editHelp'>{$cancel} | {$edithelp}</span>
1094 </div><!-- editButtons -->
1095 </div><!-- editOptions -->");
1097 $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
1100 <div class='templatesUsed'>
1105 if ( $wgUser->isLoggedIn() ) {
1107 * To make it harder for someone to slip a user a page
1108 * which submits an edit form to the wiki without their
1109 * knowledge, a random token is associated with the login
1110 * session. If it's not passed back with the submission,
1111 * we won't save the page, or render user JavaScript and
1114 $token = htmlspecialchars( $wgUser->editToken() );
1115 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1118 # If a blank edit summary was previously provided, and the appropriate
1119 # user preference is active, pass a hidden tag here. This will stop the
1120 # user being bounced back more than once in the event that a summary
1122 if( $this->missingSummary
) {
1123 $wgOut->addHTML( "<input type=\"hidden\" name=\"wpIgnoreBlankSummary\" value=\"1\" />\n" );
1126 # For a bit more sophisticated detection of blank summaries, hash the
1127 # automatic one and pass that in a hidden field.
1128 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
1129 $wgOut->addHtml( wfHidden( 'wpAutoSummary', $autosumm ) );
1131 if ( $this->isConflict
) {
1132 require_once( "DifferenceEngine.php" );
1133 $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' );
1135 $de = new DifferenceEngine( $this->mTitle
);
1136 $de->setText( $this->textbox2
, $this->textbox1
);
1137 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1139 $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
1140 $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
1141 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2
) ) . "\n</textarea>" );
1143 $wgOut->addHTML( "</form>\n" );
1144 if ( !$wgUser->getOption( 'previewontop' ) ) {
1146 if ( $this->formtype
== 'preview') {
1147 $this->showPreview();
1149 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
1152 if ( $this->formtype
== 'diff') {
1153 $wgOut->addHTML( $this->getDiff() );
1158 wfProfileOut( $fname );
1162 * Append preview output to $wgOut.
1163 * Includes category rendering if this is a category page.
1166 function showPreview() {
1168 $wgOut->addHTML( '<div id="wikiPreview">' );
1169 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1170 $this->mArticle
->openShowCategory();
1172 $previewOutput = $this->getPreviewText();
1173 $wgOut->addHTML( $previewOutput );
1174 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1175 $this->mArticle
->closeShowCategory();
1177 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
1178 $wgOut->addHTML( '</div>' );
1182 * Prepare a list of templates used by this page. Returns HTML.
1184 function formatTemplates() {
1187 $fname = 'EditPage::formatTemplates';
1188 wfProfileIn( $fname );
1190 $sk =& $wgUser->getSkin();
1193 $templates = $this->mArticle
->getUsedTemplates();
1194 if ( count( $templates ) > 0 ) {
1195 # Do a batch existence check
1196 $batch = new LinkBatch
;
1197 foreach( $templates as $title ) {
1198 $batch->addObj( $title );
1202 # Construct the HTML
1203 $outText = '<br />'. wfMsgExt( 'templatesused', array( 'parseinline' ) ) . '<ul>';
1204 foreach ( $templates as $titleObj ) {
1205 $outText .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
1207 $outText .= '</ul>';
1209 wfProfileOut( $fname );
1214 * Live Preview lets us fetch rendered preview page content and
1215 * add it to the page without refreshing the whole page.
1216 * If not supported by the browser it will fall through to the normal form
1217 * submission method.
1219 * This function outputs a script tag to support live preview, and
1220 * returns an onclick handler which should be added to the attributes
1221 * of the preview button
1223 function doLivePreviewScript() {
1224 global $wgStylePath, $wgJsMimeType, $wgOut, $wgTitle;
1225 $wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' .
1226 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
1227 '"></script>' . "\n" );
1228 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
1229 return "return !livePreview(" .
1230 "getElementById('wikiPreview')," .
1231 "editform.wpTextbox1.value," .
1232 '"' . $liveAction . '"' . ")";
1235 function getLastDelete() {
1236 $dbr =& wfGetDB( DB_SLAVE
);
1237 $fname = 'EditPage::getLastDelete';
1238 $res = $dbr->select(
1239 array( 'logging', 'user' ),
1249 array( 'log_namespace' => $this->mTitle
->getNamespace(),
1250 'log_title' => $this->mTitle
->getDBkey(),
1251 'log_type' => 'delete',
1252 'log_action' => 'delete',
1253 'user_id=log_user' ),
1255 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1257 if($dbr->numRows($res) == 1) {
1258 while ( $x = $dbr->fetchObject ( $res ) )
1260 $dbr->freeResult ( $res ) ;
1270 function getPreviewText() {
1271 global $wgOut, $wgUser, $wgTitle, $wgParser;
1273 $fname = 'EditPage::getPreviewText';
1274 wfProfileIn( $fname );
1276 if ( $this->mTriedSave
&& !$this->mTokenOk
) {
1277 $msg = 'session_fail_preview';
1279 $msg = 'previewnote';
1281 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1282 "<div class='previewnote'>" . $wgOut->parse( wfMsg( $msg ) ) . "</div>\n";
1283 if ( $this->isConflict
) {
1284 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1287 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1288 $parserOptions->setEditSection( false );
1291 if( $wgRawHtml && !$this->mTokenOk
) {
1292 // Could be an offsite preview attempt. This is very unsafe if
1293 // HTML is enabled, as it could be an attack.
1294 return $wgOut->parse( "<div class='previewnote'>" .
1295 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1298 # don't parse user css/js, show message about preview
1299 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1301 if ( $this->isCssJsSubpage
) {
1302 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
1303 $previewtext = wfMsg('usercsspreview');
1304 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
1305 $previewtext = wfMsg('userjspreview');
1307 $parserOptions->setTidy(true);
1308 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
1309 $wgOut->addHTML( $parserOutput->mText
);
1310 wfProfileOut( $fname );
1311 return $previewhead;
1313 # if user want to see preview when he edit an article
1314 if( $wgUser->getOption('previewonfirst') and ($this->textbox1
== '')) {
1315 $this->textbox1
= $this->mArticle
->getContent();
1318 $toparse = $this->textbox1
;
1320 # If we're adding a comment, we need to show the
1321 # summary as the headline
1322 if($this->section
=="new" && $this->summary
!="") {
1323 $toparse="== {$this->summary} ==\n\n".$toparse;
1326 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
1327 $parserOptions->setTidy(true);
1328 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
1329 $wgTitle, $parserOptions );
1331 $previewHTML = $parserOutput->getText();
1332 $wgOut->addParserOutputNoText( $parserOutput );
1334 wfProfileOut( $fname );
1335 return $previewhead . $previewHTML;
1340 * Call the stock "user is blocked" page
1342 function blockedIPpage() {
1344 $wgOut->blockedPage();
1348 * Produce the stock "please login to edit pages" page
1350 function userNotLoggedInPage() {
1351 global $wgUser, $wgOut;
1352 $skin = $wgUser->getSkin();
1354 $loginTitle = Title
::makeTitle( NS_SPECIAL
, 'Userlogin' );
1355 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $this->mTitle
->getPrefixedUrl() );
1357 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1358 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1359 $wgOut->setArticleRelated( false );
1361 $wgOut->addHtml( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1362 $wgOut->returnToMain( false, $this->mTitle
->getPrefixedUrl() );
1366 * Creates a basic error page which informs the user that
1367 * they have to validate their email address before being
1370 function userNotConfirmedPage() {
1373 $wgOut->setPageTitle( wfMsg( 'confirmedittitle' ) );
1374 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1375 $wgOut->setArticleRelated( false );
1377 $wgOut->addWikiText( wfMsg( 'confirmedittext' ) );
1378 $wgOut->returnToMain( false );
1382 * Produce the stock "your edit contains spam" page
1384 * @param $match Text which triggered one or more filters
1386 function spamPage( $match = false ) {
1389 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1390 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1391 $wgOut->setArticleRelated( false );
1393 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
1395 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
1397 $wgOut->returnToMain( false );
1404 function mergeChangesInto( &$editText ){
1405 $fname = 'EditPage::mergeChangesInto';
1406 wfProfileIn( $fname );
1408 $db =& wfGetDB( DB_MASTER
);
1410 // This is the revision the editor started from
1411 $baseRevision = Revision
::loadFromTimestamp(
1412 $db, $this->mArticle
->mTitle
, $this->edittime
);
1413 if( is_null( $baseRevision ) ) {
1414 wfProfileOut( $fname );
1417 $baseText = $baseRevision->getText();
1419 // The current state, we want to merge updates into it
1420 $currentRevision = Revision
::loadFromTitle(
1421 $db, $this->mArticle
->mTitle
);
1422 if( is_null( $currentRevision ) ) {
1423 wfProfileOut( $fname );
1426 $currentText = $currentRevision->getText();
1428 if( wfMerge( $baseText, $editText, $currentText, $result ) ){
1429 $editText = $result;
1430 wfProfileOut( $fname );
1433 wfProfileOut( $fname );
1439 * Check if the browser is on a blacklist of user-agents known to
1440 * mangle UTF-8 data on form submission. Returns true if Unicode
1441 * should make it through, false if it's known to be a problem.
1445 function checkUnicodeCompliantBrowser() {
1446 global $wgBrowserBlackList;
1447 if( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1448 // No User-Agent header sent? Trust it by default...
1451 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1452 foreach ( $wgBrowserBlackList as $browser ) {
1453 if ( preg_match($browser, $currentbrowser) ) {
1461 * Format an anchor fragment as it would appear for a given section name
1462 * @param string $text
1466 function sectionAnchor( $text ) {
1467 $headline = Sanitizer
::decodeCharReferences( $text );
1469 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
1470 $headline = trim( $headline );
1471 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
1472 $replacearray = array(
1477 array_keys( $replacearray ),
1478 array_values( $replacearray ),
1483 * Shows a bulletin board style toolbar for common editing functions.
1484 * It can be disabled in the user preferences.
1485 * The necessary JavaScript code can be found in style/wikibits.js.
1487 function getEditToolbar() {
1488 global $wgStylePath, $wgContLang, $wgJsMimeType;
1491 * toolarray an array of arrays which each include the filename of
1492 * the button image (without path), the opening tag, the closing tag,
1493 * and optionally a sample text that is inserted between the two when no
1494 * selection is highlighted.
1495 * The tip text is shown when the user moves the mouse over the button.
1497 * Already here are accesskeys (key), which are not used yet until someone
1498 * can figure out a way to make them work in IE. However, we should make
1499 * sure these keys are not defined on the edit page.
1502 array( 'image'=>'button_bold.png',
1504 'close' => "\'\'\'",
1505 'sample'=> wfMsg('bold_sample'),
1506 'tip' => wfMsg('bold_tip'),
1509 array( 'image'=>'button_italic.png',
1512 'sample'=> wfMsg('italic_sample'),
1513 'tip' => wfMsg('italic_tip'),
1516 array( 'image'=>'button_link.png',
1519 'sample'=> wfMsg('link_sample'),
1520 'tip' => wfMsg('link_tip'),
1523 array( 'image'=>'button_extlink.png',
1526 'sample'=> wfMsg('extlink_sample'),
1527 'tip' => wfMsg('extlink_tip'),
1530 array( 'image'=>'button_headline.png',
1532 'close' => " ==\\n",
1533 'sample'=> wfMsg('headline_sample'),
1534 'tip' => wfMsg('headline_tip'),
1537 array( 'image'=>'button_image.png',
1538 'open' => '[['.$wgContLang->getNsText(NS_IMAGE
).":",
1540 'sample'=> wfMsg('image_sample'),
1541 'tip' => wfMsg('image_tip'),
1544 array( 'image' =>'button_media.png',
1545 'open' => '[['.$wgContLang->getNsText(NS_MEDIA
).':',
1547 'sample'=> wfMsg('media_sample'),
1548 'tip' => wfMsg('media_tip'),
1551 array( 'image' =>'button_math.png',
1553 'close' => "<\\/math>",
1554 'sample'=> wfMsg('math_sample'),
1555 'tip' => wfMsg('math_tip'),
1558 array( 'image' =>'button_nowiki.png',
1559 'open' => "<nowiki>",
1560 'close' => "<\\/nowiki>",
1561 'sample'=> wfMsg('nowiki_sample'),
1562 'tip' => wfMsg('nowiki_tip'),
1565 array( 'image' =>'button_sig.png',
1569 'tip' => wfMsg('sig_tip'),
1572 array( 'image' =>'button_hr.png',
1573 'open' => "\\n----\\n",
1576 'tip' => wfMsg('hr_tip'),
1580 $toolbar = "<div id='toolbar'>\n";
1581 $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
1583 foreach($toolarray as $tool) {
1585 $image=$wgStylePath.'/common/images/'.$tool['image'];
1586 $open=$tool['open'];
1587 $close=$tool['close'];
1588 $sample = wfEscapeJsString( $tool['sample'] );
1590 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1591 // Older browsers show a "speedtip" type message only for ALT.
1592 // Ideally these should be different, realistically they
1593 // probably don't need to be.
1594 $tip = wfEscapeJsString( $tool['tip'] );
1596 #$key = $tool["key"];
1598 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
1601 $toolbar.="/*]]>*/\n</script>";
1602 $toolbar.="\n</div>";
1607 * Output preview text only. This can be sucked into the edit page
1608 * via JavaScript, and saves the server time rendering the skin as
1609 * well as theoretically being more robust on the client (doesn't
1610 * disturb the edit box's undo history, won't eat your text on
1613 * @todo This doesn't include category or interlanguage links.
1614 * Would need to enhance it a bit, maybe wrap them in XML
1615 * or something... that might also require more skin
1616 * initialization, so check whether that's a problem.
1618 function livePreview() {
1621 header( 'Content-type: text/xml' );
1622 header( 'Cache-control: no-cache' );
1624 echo $this->getPreviewText( );
1625 /* To not shake screen up and down between preview and live-preview */
1626 echo "<br style=\"clear:both;\" />\n";
1631 * Get a diff between the current contents of the edit box and the
1632 * version of the page we're editing from.
1634 * If this is a section edit, we'll replace the section as for final
1635 * save and then make a comparison.
1637 * @return string HTML
1639 function getDiff() {
1640 require_once( 'DifferenceEngine.php' );
1641 $oldtext = $this->mArticle
->fetchContent();
1642 $newtext = $this->mArticle
->replaceSection(
1643 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1644 $newtext = $this->mArticle
->preSaveTransform( $newtext );
1645 $oldtitle = wfMsgExt( 'currentrev', array('parseinline') );
1646 $newtitle = wfMsgExt( 'yourtext', array('parseinline') );
1647 if ( $oldtext !== false ||
$newtext != '' ) {
1648 $de = new DifferenceEngine( $this->mTitle
);
1649 $de->setText( $oldtext, $newtext );
1650 $difftext = $de->getDiff( $oldtitle, $newtitle );
1655 return '<div id="wikiDiff">' . $difftext . '</div>';
1659 * Filter an input field through a Unicode de-armoring process if it
1660 * came from an old browser with known broken Unicode editing issues.
1662 * @param WebRequest $request
1663 * @param string $field
1667 function safeUnicodeInput( $request, $field ) {
1668 $text = rtrim( $request->getText( $field ) );
1669 return $request->getBool( 'safemode' )
1670 ?
$this->unmakesafe( $text )
1675 * Filter an output field through a Unicode armoring process if it is
1676 * going to an old browser with known broken Unicode editing issues.
1678 * @param string $text
1682 function safeUnicodeOutput( $text ) {
1684 $codedText = $wgContLang->recodeForEdit( $text );
1685 return $this->checkUnicodeCompliantBrowser()
1687 : $this->makesafe( $codedText );
1691 * A number of web browsers are known to corrupt non-ASCII characters
1692 * in a UTF-8 text editing environment. To protect against this,
1693 * detected browsers will be served an armored version of the text,
1694 * with non-ASCII chars converted to numeric HTML character references.
1696 * Preexisting such character references will have a 0 added to them
1697 * to ensure that round-trips do not alter the original data.
1699 * @param string $invalue
1703 function makesafe( $invalue ) {
1704 // Armor existing references for reversability.
1705 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
1710 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1711 $bytevalue = ord( $invalue{$i} );
1712 if( $bytevalue <= 0x7F ) { //0xxx xxxx
1713 $result .= chr( $bytevalue );
1715 } elseif( $bytevalue <= 0xBF ) { //10xx xxxx
1716 $working = $working << 6;
1717 $working +
= ($bytevalue & 0x3F);
1719 if( $bytesleft <= 0 ) {
1720 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
1722 } elseif( $bytevalue <= 0xDF ) { //110x xxxx
1723 $working = $bytevalue & 0x1F;
1725 } elseif( $bytevalue <= 0xEF ) { //1110 xxxx
1726 $working = $bytevalue & 0x0F;
1728 } else { //1111 0xxx
1729 $working = $bytevalue & 0x07;
1737 * Reverse the previously applied transliteration of non-ASCII characters
1738 * back to UTF-8. Used to protect data from corruption by broken web browsers
1739 * as listed in $wgBrowserBlackList.
1741 * @param string $invalue
1745 function unmakesafe( $invalue ) {
1747 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1748 if( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+
3} != '0' ) ) {
1752 $hexstring .= $invalue{$i};
1754 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
1756 // Do some sanity checks. These aren't needed for reversability,
1757 // but should help keep the breakage down if the editor
1758 // breaks one of the entities whilst editing.
1759 if ((substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6)) {
1760 $codepoint = hexdec($hexstring);
1761 $result .= codepointToUtf8( $codepoint );
1763 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
1766 $result .= substr( $invalue, $i, 1 );
1769 // reverse the transform that we made for reversability reasons.
1770 return strtr( $result, array( "�" => "&#x" ) );
1773 function noCreatePermission() {
1775 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
1776 $wgOut->addWikiText( wfMsg( 'nocreatetext' ) );