a99328c95c1a282840c75a19c73294ed1aa4ef83
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;
29 var $save = false, $preview = false, $diff = false;
30 var $minoredit = false, $watchthis = false, $recreate = false;
31 var $textbox1 = '', $textbox2 = '', $summary = '';
32 var $edittime = '', $section = '', $starttime = '';
33 var $oldid = 0, $editintro = '', $scrolltop = null;
39 function EditPage( $article ) {
40 $this->mArticle
=& $article;
42 $this->mTitle
=& $wgTitle;
46 * This is the function that extracts metadata from the article body on the first view.
47 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
48 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
50 function extractMetaDataFromArticle () {
51 global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
52 $this->mMetaData
= '' ;
53 if ( !$wgUseMetadataEdit ) return ;
54 if ( $wgMetadataWhitelist == '' ) return ;
56 $t = $this->mArticle
->getContent ( true ) ;
58 # MISSING : <nowiki> filtering
60 # Categories and language links
61 $t = explode ( "\n" , $t ) ;
62 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY
) ) ;
63 $cat = $ll = array() ;
64 foreach ( $t AS $key => $x )
66 $y = trim ( strtolower ( $x ) ) ;
67 while ( substr ( $y , 0 , 2 ) == '[[' )
69 $y = explode ( ']]' , trim ( $x ) ) ;
70 $first = array_shift ( $y ) ;
71 $first = explode ( ':' , $first ) ;
72 $ns = array_shift ( $first ) ;
73 $ns = trim ( str_replace ( '[' , '' , $ns ) ) ;
74 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
76 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]' ;
77 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
79 $x = implode ( ']]' , $y ) ;
81 $y = trim ( strtolower ( $x ) ) ;
85 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n" ;
86 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n" ;
87 $t = implode ( "\n" , $t ) ;
90 $sat = array () ; # stand-alone-templates; must be lowercase
91 $wl_title = Title
::newFromText ( $wgMetadataWhitelist ) ;
92 $wl_article = new Article ( $wl_title ) ;
93 $wl = explode ( "\n" , $wl_article->getContent(true) ) ;
98 while ( substr ( $x , 0 , 1 ) == '*' )
101 $x = trim ( substr ( $x , 1 ) ) ;
105 $sat[] = strtolower ( $x ) ;
110 # Templates, but only some
111 $t = explode ( '{{' , $t ) ;
113 foreach ( $t AS $key => $x )
115 $y = explode ( '}}' , $x , 2 ) ;
116 if ( count ( $y ) == 2 )
119 $z = explode ( '|' , $z ) ;
120 $tn = array_shift ( $z ) ;
121 if ( in_array ( strtolower ( $tn ) , $sat ) )
123 $tl[] = '{{' . $y[0] . '}}' ;
125 $y = explode ( '}}' , $y[1] , 2 ) ;
127 else $t[$key] = '{{' . $x ;
129 else if ( $key != 0 ) $t[$key] = '{{' . $x ;
132 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl ) ;
133 $t = implode ( '' , $t ) ;
135 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
136 $this->mArticle
->mContent
= $t ;
137 $this->mMetaData
= $s ;
145 * This is the function that gets called for "action=edit". It
146 * sets up various member variables, then passes execution to
147 * another function, usually showEditForm()
149 * The edit form is self-submitting, so that when things like
150 * preview and edit conflicts occur, we get the same form back
151 * with the extra stuff added. Only when the final submission
152 * is made and all is well do we actually save and redirect to
153 * the newly-edited page.
156 global $wgOut, $wgUser, $wgRequest, $wgTitle;
158 if ( ! wfRunHooks( 'AlternateEdit', array( &$this ) ) )
161 $fname = 'EditPage::edit';
162 wfProfileIn( $fname );
163 wfDebug( "$fname: enter\n" );
165 // this is not an article
166 $wgOut->setArticleFlag(false);
168 $this->importFormData( $wgRequest );
169 $this->firsttime
= false;
172 $this->livePreview();
173 wfProfileOut( $fname );
177 if ( ! $this->mTitle
->userCanEdit() ) {
178 wfDebug( "$fname: user can't edit\n" );
179 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ), true );
180 wfProfileOut( $fname );
183 wfDebug( "$fname: Checking blocks\n" );
184 if ( !$this->preview
&& !$this->diff
&& $wgUser->isBlockedFrom( $this->mTitle
, !$this->save
) ) {
185 # When previewing, don't check blocked state - will get caught at save time.
186 # Also, check when starting edition is done against slave to improve performance.
187 wfDebug( "$fname: user is blocked\n" );
188 $wgOut->blockedPage();
189 wfProfileOut( $fname );
192 if ( !$wgUser->isAllowed('edit') ) {
193 if ( $wgUser->isAnon() ) {
194 wfDebug( "$fname: user must log in\n" );
195 $this->userNotLoggedInPage();
196 wfProfileOut( $fname );
199 wfDebug( "$fname: read-only page\n" );
200 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ), true );
201 wfProfileOut( $fname );
205 if ( !$this->mTitle
->userCan( 'create' ) && !$this->mTitle
->exists() ) {
206 wfDebug( "$fname: no create permission\n" );
207 $this->noCreatePermission();
208 wfProfileOut( $fname );
211 if ( wfReadOnly() ) {
212 wfDebug( "$fname: read-only mode is engaged\n" );
213 if( $this->save ||
$this->preview
) {
214 $this->formtype
= 'preview';
215 } else if ( $this->diff
) {
216 $this->formtype
= 'diff';
218 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ) );
219 wfProfileOut( $fname );
224 $this->formtype
= 'save';
225 } else if ( $this->preview
) {
226 $this->formtype
= 'preview';
227 } else if ( $this->diff
) {
228 $this->formtype
= 'diff';
229 } else { # First time through
230 $this->firsttime
= true;
231 if( $this->previewOnOpen() ) {
232 $this->formtype
= 'preview';
234 $this->extractMetaDataFromArticle () ;
235 $this->formtype
= 'initial';
240 wfProfileIn( "$fname-business-end" );
242 $this->isConflict
= false;
243 // css / js subpages of user pages get a special treatment
244 $this->isCssJsSubpage
= $wgTitle->isCssJsSubpage();
246 /* Notice that we can't use isDeleted, because it returns true if article is ever deleted
247 * no matter it's current state
249 $this->deletedSinceEdit
= false;
250 if ( $this->edittime
!= '' ) {
251 /* Note that we rely on logging table, which hasn't been always there,
252 * but that doesn't matter, because this only applies to brand new
253 * deletes. This is done on every preview and save request. Move it further down
254 * to only perform it on saves
256 if ( $this->mTitle
->isDeleted() ) {
257 $this->lastDelete
= $this->getLastDelete();
258 if ( !is_null($this->lastDelete
) ) {
259 $deletetime = $this->lastDelete
->log_timestamp
;
260 if ( ($deletetime - $this->starttime
) > 0 ) {
261 $this->deletedSinceEdit
= true;
267 if(!$this->mTitle
->getArticleID() && ('initial' == $this->formtype ||
$this->firsttime
)) { # new article
270 if( $this->mTitle
->isTalkPage() ) {
271 $wgOut->addWikiText( wfMsg( 'talkpagetext' ) );
274 # Attempt submission here. This will check for edit conflicts,
275 # and redundantly check for locked database, blocked IPs, etc.
276 # that edit() already checked just in case someone tries to sneak
277 # in the back door with a hand-edited submission URL.
279 if ( 'save' == $this->formtype
) {
280 if ( !$this->attemptSave() ) {
281 wfProfileOut( "$fname-business-end" );
282 wfProfileOut( $fname );
287 # First time through: get contents, set time for conflict
289 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
290 $this->initialiseForm();
293 $this->showEditForm();
294 wfProfileOut( "$fname-business-end" );
295 wfProfileOut( $fname );
299 * Return true if this page should be previewed when the edit form
300 * is initially opened.
304 function previewOnOpen() {
306 return $this->section
!= 'new' &&
307 ( ( $wgUser->getOption( 'previewonfirst' ) && $this->mTitle
->exists() ) ||
308 ( $this->mTitle
->getNamespace() == NS_CATEGORY
&&
309 !$this->mTitle
->exists() ) );
315 function importFormData( &$request ) {
317 $fname = 'EditPage::importFormData';
318 wfProfileIn( $fname );
320 if( $request->wasPosted() ) {
321 # These fields need to be checked for encoding.
322 # Also remove trailing whitespace, but don't remove _initial_
323 # whitespace from the text boxes. This may be significant formatting.
324 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
325 $this->textbox2
= $this->safeUnicodeInput( $request, 'wpTextbox2' );
326 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
327 # Truncate for whole multibyte characters. +5 bytes for ellipsis
328 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
330 $this->edittime
= $request->getVal( 'wpEdittime' );
331 $this->starttime
= $request->getVal( 'wpStarttime' );
333 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
335 if( is_null( $this->edittime
) ) {
336 # If the form is incomplete, force to preview.
337 wfDebug( "$fname: Form data appears to be incomplete\n" );
338 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
339 $this->preview
= true;
341 $this->preview
= $request->getCheck( 'wpPreview' );
342 $this->diff
= $request->getCheck( 'wpDiff' );
344 if( !$this->preview
) {
345 if ( $this->tokenOk( $request ) ) {
346 # Some browsers will not report any submit button
347 # if the user hits enter in the comment box.
348 # The unmarked state will be assumed to be a save,
349 # if the form seems otherwise complete.
350 wfDebug( "$fname: Passed token check.\n" );
352 # Page might be a hack attempt posted from
353 # an external site. Preview instead of saving.
354 wfDebug( "$fname: Failed token check; forcing preview\n" );
355 $this->preview
= true;
359 $this->save
= ! ( $this->preview
OR $this->diff
);
360 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
361 $this->edittime
= null;
364 if( !preg_match( '/^\d{14}$/', $this->starttime
)) {
365 $this->starttime
= null;
368 $this->recreate
= $request->getCheck( 'wpRecreate' );
370 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
371 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
373 # Not a posted form? Start with nothing.
374 wfDebug( "$fname: Not a posted form.\n" );
375 $this->textbox1
= '';
376 $this->textbox2
= '';
377 $this->mMetaData
= '';
379 $this->edittime
= '';
380 $this->starttime
= wfTimestampNow();
381 $this->preview
= false;
384 $this->minoredit
= false;
385 $this->watchthis
= false;
386 $this->recreate
= false;
389 $this->oldid
= $request->getInt( 'oldid' );
391 # Section edit can come from either the form or a link
392 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
394 $this->live
= $request->getCheck( 'live' );
395 $this->editintro
= $request->getText( 'editintro' );
397 wfProfileOut( $fname );
401 * Make sure the form isn't faking a user's credentials.
403 * @param WebRequest $request
407 function tokenOk( &$request ) {
409 if( $wgUser->isAnon() ) {
410 # Anonymous users may not have a session
411 # open. Don't tokenize.
412 $this->mTokenOk
= true;
414 $this->mTokenOk
= $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
416 return $this->mTokenOk
;
419 function showIntro() {
420 global $wgOut, $wgUser;
421 $addstandardintro=true;
422 if($this->editintro
) {
423 $introtitle=Title
::newFromText($this->editintro
);
424 if(isset($introtitle) && $introtitle->userCanRead()) {
425 $rev=Revision
::newFromTitle($introtitle);
427 $wgOut->addWikiText($rev->getText());
428 $addstandardintro=false;
432 if($addstandardintro) {
433 if ( $wgUser->isLoggedIn() )
434 $wgOut->addWikiText( wfMsg( 'newarticletext' ) );
436 $wgOut->addWikiText( wfMsg( 'newarticletextanon' ) );
442 * @return bool false if output is done, true if the rest of the form should be displayed
444 function attemptSave() {
445 global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut;
447 $fname = 'EditPage::attemptSave';
448 wfProfileIn( $fname );
449 wfProfileIn( "$fname-checks" );
451 # Reintegrate metadata
452 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
453 $this->mMetaData
= '' ;
456 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
457 $this->spamPage ( $matches[0] );
458 wfProfileOut( "$fname-checks" );
459 wfProfileOut( $fname );
462 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
463 # Error messages or other handling should be performed by the filter function
464 wfProfileOut( $fname );
465 wfProfileOut( "$fname-checks" );
468 if ( !wfRunHooks( 'EditFilter', array( &$this, $this->textbox1
, $this->section
) ) ) {
469 # Error messages or other handling should be performed by the filter function
470 wfProfileOut( $fname );
471 wfProfileOut( "$fname-checks" );
474 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
475 # Check block state against master, thus 'false'.
476 $this->blockedIPpage();
477 wfProfileOut( "$fname-checks" );
478 wfProfileOut( $fname );
482 if ( !$wgUser->isAllowed('edit') ) {
483 if ( $wgUser->isAnon() ) {
484 $this->userNotLoggedInPage();
485 wfProfileOut( "$fname-checks" );
486 wfProfileOut( $fname );
490 $wgOut->readOnlyPage();
491 wfProfileOut( "$fname-checks" );
492 wfProfileOut( $fname );
497 if ( wfReadOnly() ) {
498 $wgOut->readOnlyPage();
499 wfProfileOut( "$fname-checks" );
500 wfProfileOut( $fname );
503 if ( $wgUser->pingLimiter() ) {
504 $wgOut->rateLimited();
505 wfProfileOut( "$fname-checks" );
506 wfProfileOut( $fname );
510 # If the article has been deleted while editing, don't save it without
512 if ( $this->deletedSinceEdit
&& !$this->recreate
) {
513 wfProfileOut( "$fname-checks" );
514 wfProfileOut( $fname );
518 wfProfileOut( "$fname-checks" );
520 # If article is new, insert it.
521 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
523 // Late check for create permission, just in case *PARANOIA*
524 if ( !$this->mTitle
->userCan( 'create' ) ) {
525 wfDebug( "$fname: no create permission\n" );
526 $this->noCreatePermission();
527 wfProfileOut( $fname );
531 # Don't save a new article if it's blank.
532 if ( ( '' == $this->textbox1
) ) {
533 $wgOut->redirect( $this->mTitle
->getFullURL() );
534 wfProfileOut( $fname );
538 $isComment=($this->section
=='new');
539 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
540 $this->minoredit
, $this->watchthis
, false, $isComment);
542 wfProfileOut( $fname );
546 # Article exists. Check for edit conflict.
548 $this->mArticle
->clear(); # Force reload of dates, etc.
549 $this->mArticle
->forUpdate( true ); # Lock the article
551 if( $this->mArticle
->getTimestamp() != $this->edittime
) {
552 $this->isConflict
= true;
553 if( $this->section
== 'new' ) {
554 if( $this->mArticle
->getUserText() == $wgUser->getName() &&
555 $this->mArticle
->getComment() == $this->summary
) {
556 // Probably a duplicate submission of a new comment.
557 // This can happen when squid resends a request after
558 // a timeout but the first one actually went through.
559 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
561 // New comment; suppress conflict.
562 $this->isConflict
= false;
563 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
567 $userid = $wgUser->getID();
569 if ( $this->isConflict
) {
570 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
571 $this->mArticle
->getTimestamp() . "'\n" );
572 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
575 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
576 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
578 if( is_null( $text ) ) {
579 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
580 $this->isConflict
= true;
581 $text = $this->textbox1
;
584 # Suppress edit conflict with self, except for section edits where merging is required.
585 if ( ( $this->section
== '' ) && ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
586 wfDebug( "Suppressing edit conflict, same user.\n" );
587 $this->isConflict
= false;
589 # switch from section editing to normal editing in edit conflict
590 if($this->isConflict
) {
592 if( $this->mergeChangesInto( $text ) ){
593 // Successful merge! Maybe we should tell the user the good news?
594 $this->isConflict
= false;
595 wfDebug( "Suppressing edit conflict, successful merge.\n" );
598 $this->textbox1
= $text;
599 wfDebug( "Keeping edit conflict, failed merge.\n" );
604 if ( $this->isConflict
) {
605 wfProfileOut( $fname );
610 wfProfileIn( "$fname-sectionanchor" );
612 if( $this->section
== 'new' ) {
613 if( $this->summary
!= '' ) {
614 $sectionanchor = $this->sectionAnchor( $this->summary
);
616 } elseif( $this->section
!= '' ) {
617 # Try to get a section anchor from the section source, redirect to edited section if header found
618 # XXX: might be better to integrate this into Article::replaceSection
619 # for duplicate heading checking and maybe parsing
620 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
621 # we can't deal with anchors, includes, html etc in the header for now,
622 # headline would need to be parsed to improve this
623 if($hasmatch and strlen($matches[2]) > 0) {
624 $sectionanchor = $this->sectionAnchor( $matches[2] );
627 wfProfileOut( "$fname-sectionanchor" );
629 // Save errors may fall down to the edit form, but we've now
630 // merged the section into full text. Clear the section field
631 // so that later submission of conflict forms won't try to
632 // replace that into a duplicated mess.
633 $this->textbox1
= $text;
636 # update the article here
637 if( $this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
638 $this->watchthis
, '', $sectionanchor ) ) {
639 wfProfileOut( $fname );
642 $this->isConflict
= true;
644 wfProfileOut( $fname );
649 * Initialise form fields in the object
650 * Called on the first invocation, e.g. when a user clicks an edit link
652 function initialiseForm() {
653 $this->edittime
= $this->mArticle
->getTimestamp();
654 $this->textbox1
= $this->mArticle
->getContent( true );
656 if ( !$this->mArticle
->exists() && $this->mArticle
->mTitle
->getNamespace() == NS_MEDIAWIKI
)
657 $this->textbox1
= wfMsgWeirdKey ( $this->mArticle
->mTitle
->getText() ) ;
662 * Send the edit form and related headers to $wgOut
663 * @param $formCallback Optional callable that takes an OutputPage
664 * parameter; will be called during form output
665 * near the top, for captchas and the like.
667 function showEditForm( $formCallback=null ) {
668 global $wgOut, $wgUser, $wgLang, $wgContLang;
670 $fname = 'EditPage::showEditForm';
671 wfProfileIn( $fname );
673 $sk =& $wgUser->getSkin();
675 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
677 $wgOut->setRobotpolicy( 'noindex,nofollow' );
679 # Enabled article-related sidebar, toplinks, etc.
680 $wgOut->setArticleRelated( true );
682 if ( $this->isConflict
) {
683 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
684 $wgOut->setPageTitle( $s );
685 $wgOut->addWikiText( wfMsg( 'explainconflict' ) );
687 $this->textbox2
= $this->textbox1
;
688 $this->textbox1
= $this->mArticle
->getContent( true );
689 $this->edittime
= $this->mArticle
->getTimestamp();
692 if( $this->section
!= '' ) {
693 if( $this->section
== 'new' ) {
694 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
696 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
697 if( !$this->preview
&& !$this->diff
) {
698 preg_match( "/^(=+)(.+)\\1/mi",
701 if( !empty( $matches[2] ) ) {
702 $this->summary
= "/* ". trim($matches[2])." */ ";
707 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
709 $wgOut->setPageTitle( $s );
710 if ( !$this->checkUnicodeCompliantBrowser() ) {
711 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
713 if ( isset( $this->mArticle
)
714 && isset( $this->mArticle
->mRevision
)
715 && !$this->mArticle
->mRevision
->isCurrent() ) {
716 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
717 $wgOut->addWikiText( wfMsg( 'editingold' ) );
722 $wgOut->addWikiText( wfMsg( 'readonlywarning' ) );
723 } else if ( $this->isCssJsSubpage
and 'preview' != $this->formtype
) {
724 $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ));
726 if( $this->mTitle
->isProtected('edit') ) {
727 $wgOut->addWikiText( wfMsg( 'protectedpagewarning' ) );
730 $kblength = (int)(strlen( $this->textbox1
) / 1024);
731 if( $kblength > 29 ) {
732 $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) ) );
735 $rows = $wgUser->getOption( 'rows' );
736 $cols = $wgUser->getOption( 'cols' );
738 $ew = $wgUser->getOption( 'editwidth' );
739 if ( $ew ) $ew = " style=\"width:100%\"";
742 $q = 'action=submit';
743 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
744 $action = $this->mTitle
->escapeLocalURL( $q );
746 $summary = wfMsg('summary');
747 $subject = wfMsg('subject');
748 $minor = wfMsg('minoredit');
749 $watchthis = wfMsg ('watchthis');
750 $save = wfMsg('savearticle');
751 $prev = wfMsg('showpreview');
752 $diff = wfMsg('showdiff');
754 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
756 $edithelpurl = $sk->makeInternalOrExternalUrl( wfMsg( 'edithelppage' ));
757 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
758 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
759 htmlspecialchars( wfMsg( 'newwindow' ) );
761 global $wgRightsText;
762 $copywarn = "<div id=\"editpage-copywarn\">\n" .
763 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
764 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
765 $wgRightsText ) . "\n</div>";
767 if( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage
) {
768 # prepare toolbar for edit buttons
769 $toolbar = $this->getEditToolbar();
774 // activate checkboxes if user wants them to be always active
775 if( !$this->preview
&& !$this->diff
) {
776 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis
= true;
777 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
779 // activate checkbox also if user is already watching the page,
780 // require wpWatchthis to be unset so that second condition is not
781 // checked unnecessarily
782 if( !$this->watchthis
&& $this->mTitle
->userIsWatching() ) $this->watchthis
= true;
787 if ( $wgUser->isAllowed('minoredit') ) {
789 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
790 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
791 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
796 if ( $wgUser->isLoggedIn() ) {
797 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".
798 ($this->watchthis?
" checked='checked'":"").
799 " accesskey=\"".htmlspecialchars(wfMsg('accesskey-watch'))."\" id='wpWatchthis' />".
800 "<label for='wpWatchthis' title=\"" .
801 htmlspecialchars(wfMsg('tooltip-watch'))."\">{$watchthis}</label>";
804 $checkboxhtml = $minoredithtml . $watchhtml;
806 if ( 'preview' == $this->formtype
&& $wgUser->getOption( 'previewontop' ) ) {
807 $this->showPreview();
809 if ( 'diff' == $this->formtype
) {
810 if ( $wgUser->getOption('previewontop' ) ) {
811 $wgOut->addHTML( $this->getDiff() );
816 # if this is a comment, show a subject line at the top, which is also the edit summary.
817 # Otherwise, show a summary field at the bottom
818 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
819 if( $this->section
== 'new' ) {
820 $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 />";
823 $commentsubject = '';
824 $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 />";
827 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
828 if( !$this->preview
&& !$this->diff
) {
829 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
831 $templates = $this->formatTemplates();
833 global $wgLivePreview;
834 if ( $wgLivePreview ) {
835 $liveOnclick = $this->doLivePreviewScript();
840 global $wgUseMetadataEdit ;
841 if ( $wgUseMetadataEdit ) {
842 $metadata = $this->mMetaData
;
843 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
844 $helppage = Title
::newFromText( wfMsg( "metadata_page" ) ) ;
845 $top = wfMsg( 'metadata', $helppage->getLocalURL() );
846 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
848 else $metadata = "" ;
852 if ($this->deletedSinceEdit
) {
853 if ( 'save' != $this->formtype
) {
854 $wgOut->addWikiText( wfMsg('deletedwhileediting'));
856 // Hide the toolbar and edit area, use can click preview to get it back
857 // Add an confirmation checkbox and explanation.
859 $hidden = 'type="hidden" style="display:none;"';
860 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete
->user_name
, $this->lastDelete
->log_comment
));
862 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
863 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
867 $safemodehtml = $this->checkUnicodeCompliantBrowser()
869 : "<input type='hidden' name=\"safemode\" value='1' />\n";
871 $wgOut->addHTML( <<<END
873 <form id="editform" name="editform" method="post" action="$action"
874 enctype="multipart/form-data">
877 if( is_callable( $formCallback ) ) {
878 call_user_func_array( $formCallback, array( &$wgOut ) );
881 // Put these up at the top to ensure they aren't lost on early form submission
883 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
884 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
885 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
886 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
888 $wgOut->addHTML( <<<END
891 <textarea tabindex='1' accesskey="," name="wpTextbox1" id="wpTextbox1" rows='{$rows}'
892 cols='{$cols}'{$ew} $hidden>
894 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1
) ) .
900 $wgOut->addWikiText( $copywarn );
910 <div class='editButtons'>
911 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
912 " title=\"".wfMsg('tooltip-save')."\"/>
913 <input tabindex='6' id='wpPreview' type='submit' $liveOnclick value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
914 " title=\"".wfMsg('tooltip-preview')."\"/>
915 <input tabindex='7' id='wpDiff' type='submit' value=\"{$diff}\" name=\"wpDiff\" accesskey=\"".wfMsg('accesskey-diff')."\"".
916 " title=\"".wfMsg('tooltip-diff')."\"/> <span class='editHelp'>{$cancel} | {$edithelp}</span></div>
920 $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
923 <div class='templatesUsed'>
928 if ( $wgUser->isLoggedIn() ) {
930 * To make it harder for someone to slip a user a page
931 * which submits an edit form to the wiki without their
932 * knowledge, a random token is associated with the login
933 * session. If it's not passed back with the submission,
934 * we won't save the page, or render user JavaScript and
937 $token = htmlspecialchars( $wgUser->editToken() );
938 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
942 if ( $this->isConflict
) {
943 require_once( "DifferenceEngine.php" );
944 $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' );
946 $de = new DifferenceEngine( $this->mTitle
);
947 $de->setText( $this->textbox2
, $this->textbox1
);
948 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
950 $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
951 $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
952 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2
) ) . "\n</textarea>" );
954 $wgOut->addHTML( "</form>\n" );
955 if ( $this->formtype
== 'preview' && !$wgUser->getOption( 'previewontop' ) ) {
956 $this->showPreview();
958 if ( $this->formtype
== 'diff' && !$wgUser->getOption( 'previewontop' ) ) {
959 #$wgOut->addHTML( '<div id="wikiPreview">' . $difftext . '</div>' );
960 $wgOut->addHTML( $this->getDiff() );
963 wfProfileOut( $fname );
967 * Append preview output to $wgOut.
968 * Includes category rendering if this is a category page.
971 function showPreview() {
973 $wgOut->addHTML( '<div id="wikiPreview">' );
974 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
975 $this->mArticle
->openShowCategory();
977 $previewOutput = $this->getPreviewText();
978 $wgOut->addHTML( $previewOutput );
979 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
980 $this->mArticle
->closeShowCategory();
982 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
983 $wgOut->addHTML( '</div>' );
987 * Prepare a list of templates used by this page. Returns HTML.
989 function formatTemplates() {
992 $fname = 'EditPage::formatTemplates';
993 wfProfileIn( $fname );
995 $sk =& $wgUser->getSkin();
998 $templates = $this->mArticle
->getUsedTemplates();
999 if ( count( $templates ) > 0 ) {
1000 $outText = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
1001 foreach ( $templates as $titleObj ) {
1002 $outText .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
1004 $outText .= '</ul>';
1006 wfProfileOut( $fname );
1011 * Live Preview lets us fetch rendered preview page content and
1012 * add it to the page without refreshing the whole page.
1013 * If not supported by the browser it will fall through to the normal form
1014 * submission method.
1016 * This function outputs a script tag to support live preview, and
1017 * returns an onclick handler which should be added to the attributes
1018 * of the preview button
1020 function doLivePreviewScript() {
1021 global $wgStylePath, $wgJsMimeType, $wgOut;
1022 $wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' .
1023 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
1024 '"></script>' . "\n" );
1025 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
1026 return 'onclick="return !livePreview('.
1027 'getElementById(\'wikiPreview\'),' .
1028 'editform.wpTextbox1.value,' .
1029 htmlspecialchars( '"' . $liveAction . '"' ) . ')"';
1032 function getLastDelete() {
1033 $dbr =& wfGetDB( DB_SLAVE
);
1034 $fname = 'EditPage::getLastDelete';
1035 $res = $dbr->select(
1036 array( 'logging', 'user' ),
1046 array( 'log_namespace' => $this->mTitle
->getNamespace(),
1047 'log_title' => $this->mTitle
->getDBkey(),
1048 'log_type' => 'delete',
1049 'log_action' => 'delete',
1050 'user_id=log_user' ),
1052 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1054 if($dbr->numRows($res) == 1) {
1055 while ( $x = $dbr->fetchObject ( $res ) )
1057 $dbr->freeResult ( $res ) ;
1067 function getPreviewText() {
1068 global $wgOut, $wgUser, $wgTitle, $wgParser;
1070 $fname = 'EditPage::getPreviewText';
1071 wfProfileIn( $fname );
1073 if ( $this->mTokenOk
) {
1074 $msg = 'previewnote';
1076 $msg = 'session_fail_preview';
1078 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1079 "<div class='previewnote'>" . $wgOut->parse( wfMsg( $msg ) ) . "</div>\n";
1080 if ( $this->isConflict
) {
1081 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1084 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1085 $parserOptions->setEditSection( false );
1087 # don't parse user css/js, show message about preview
1088 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1090 if ( $this->isCssJsSubpage
) {
1091 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
1092 $previewtext = wfMsg('usercsspreview');
1093 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
1094 $previewtext = wfMsg('userjspreview');
1096 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
1097 $wgOut->addHTML( $parserOutput->mText
);
1098 wfProfileOut( $fname );
1099 return $previewhead;
1101 # if user want to see preview when he edit an article
1102 if( $wgUser->getOption('previewonfirst') and ($this->textbox1
== '')) {
1103 $this->textbox1
= $this->mArticle
->getContent(true);
1106 $toparse = $this->textbox1
;
1108 # If we're adding a comment, we need to show the
1109 # summary as the headline
1110 if($this->section
=="new" && $this->summary
!="") {
1111 $toparse="== {$this->summary} ==\n\n".$toparse;
1114 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
1116 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
1117 $wgTitle, $parserOptions );
1119 $previewHTML = $parserOutput->getText();
1120 $wgOut->addParserOutputNoText( $parserOutput );
1122 wfProfileOut( $fname );
1123 return $previewhead . $previewHTML;
1130 function blockedIPpage() {
1132 $wgOut->blockedPage();
1138 function userNotLoggedInPage() {
1141 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1142 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1143 $wgOut->setArticleRelated( false );
1145 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
1146 $wgOut->returnToMain( false );
1152 function spamPage ( $match = false )
1155 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1156 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1157 $wgOut->setArticleRelated( false );
1159 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
1161 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
1163 $wgOut->returnToMain( false );
1170 function mergeChangesInto( &$editText ){
1171 $fname = 'EditPage::mergeChangesInto';
1172 wfProfileIn( $fname );
1174 $db =& wfGetDB( DB_MASTER
);
1176 // This is the revision the editor started from
1177 $baseRevision = Revision
::loadFromTimestamp(
1178 $db, $this->mArticle
->mTitle
, $this->edittime
);
1179 if( is_null( $baseRevision ) ) {
1180 wfProfileOut( $fname );
1183 $baseText = $baseRevision->getText();
1185 // The current state, we want to merge updates into it
1186 $currentRevision = Revision
::loadFromTitle(
1187 $db, $this->mArticle
->mTitle
);
1188 if( is_null( $currentRevision ) ) {
1189 wfProfileOut( $fname );
1192 $currentText = $currentRevision->getText();
1194 if( wfMerge( $baseText, $editText, $currentText, $result ) ){
1195 $editText = $result;
1196 wfProfileOut( $fname );
1199 wfProfileOut( $fname );
1205 * Check if the browser is on a blacklist of user-agents known to
1206 * mangle UTF-8 data on form submission. Returns true if Unicode
1207 * should make it through, false if it's known to be a problem.
1211 function checkUnicodeCompliantBrowser() {
1212 global $wgBrowserBlackList;
1213 if( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1214 // No User-Agent header sent? Trust it by default...
1217 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1218 foreach ( $wgBrowserBlackList as $browser ) {
1219 if ( preg_match($browser, $currentbrowser) ) {
1227 * Format an anchor fragment as it would appear for a given section name
1228 * @param string $text
1232 function sectionAnchor( $text ) {
1233 $headline = Sanitizer
::decodeCharReferences( $text );
1235 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
1236 $headline = trim( $headline );
1237 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
1238 $replacearray = array(
1243 array_keys( $replacearray ),
1244 array_values( $replacearray ),
1249 * Shows a bulletin board style toolbar for common editing functions.
1250 * It can be disabled in the user preferences.
1251 * The necessary JavaScript code can be found in style/wikibits.js.
1253 function getEditToolbar() {
1254 global $wgStylePath, $wgLang, $wgJsMimeType;
1257 * toolarray an array of arrays which each include the filename of
1258 * the button image (without path), the opening tag, the closing tag,
1259 * and optionally a sample text that is inserted between the two when no
1260 * selection is highlighted.
1261 * The tip text is shown when the user moves the mouse over the button.
1263 * Already here are accesskeys (key), which are not used yet until someone
1264 * can figure out a way to make them work in IE. However, we should make
1265 * sure these keys are not defined on the edit page.
1268 array( 'image'=>'button_bold.png',
1270 'close' => "\'\'\'",
1271 'sample'=> wfMsg('bold_sample'),
1272 'tip' => wfMsg('bold_tip'),
1275 array( 'image'=>'button_italic.png',
1278 'sample'=> wfMsg('italic_sample'),
1279 'tip' => wfMsg('italic_tip'),
1282 array( 'image'=>'button_link.png',
1285 'sample'=> wfMsg('link_sample'),
1286 'tip' => wfMsg('link_tip'),
1289 array( 'image'=>'button_extlink.png',
1292 'sample'=> wfMsg('extlink_sample'),
1293 'tip' => wfMsg('extlink_tip'),
1296 array( 'image'=>'button_headline.png',
1298 'close' => " ==\\n",
1299 'sample'=> wfMsg('headline_sample'),
1300 'tip' => wfMsg('headline_tip'),
1303 array( 'image'=>'button_image.png',
1304 'open' => '[['.$wgLang->getNsText(NS_IMAGE
).":",
1306 'sample'=> wfMsg('image_sample'),
1307 'tip' => wfMsg('image_tip'),
1310 array( 'image' =>'button_media.png',
1311 'open' => '[['.$wgLang->getNsText(NS_MEDIA
).':',
1313 'sample'=> wfMsg('media_sample'),
1314 'tip' => wfMsg('media_tip'),
1317 array( 'image' =>'button_math.png',
1318 'open' => "\\<math\\>",
1319 'close' => "\\</math\\>",
1320 'sample'=> wfMsg('math_sample'),
1321 'tip' => wfMsg('math_tip'),
1324 array( 'image' =>'button_nowiki.png',
1325 'open' => "\\<nowiki\\>",
1326 'close' => "\\</nowiki\\>",
1327 'sample'=> wfMsg('nowiki_sample'),
1328 'tip' => wfMsg('nowiki_tip'),
1331 array( 'image' =>'button_sig.png',
1335 'tip' => wfMsg('sig_tip'),
1338 array( 'image' =>'button_hr.png',
1339 'open' => "\\n----\\n",
1342 'tip' => wfMsg('hr_tip'),
1346 $toolbar ="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
1348 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
1349 foreach($toolarray as $tool) {
1351 $image=$wgStylePath.'/common/images/'.$tool['image'];
1352 $open=$tool['open'];
1353 $close=$tool['close'];
1354 $sample = wfEscapeJsString( $tool['sample'] );
1356 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1357 // Older browsers show a "speedtip" type message only for ALT.
1358 // Ideally these should be different, realistically they
1359 // probably don't need to be.
1360 $tip = wfEscapeJsString( $tool['tip'] );
1362 #$key = $tool["key"];
1364 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
1367 $toolbar.="document.writeln(\"</div>\");\n";
1368 $toolbar.="/*]]>*/\n</script>";
1373 * Output preview text only. This can be sucked into the edit page
1374 * via JavaScript, and saves the server time rendering the skin as
1375 * well as theoretically being more robust on the client (doesn't
1376 * disturb the edit box's undo history, won't eat your text on
1379 * @todo This doesn't include category or interlanguage links.
1380 * Would need to enhance it a bit, maybe wrap them in XML
1381 * or something... that might also require more skin
1382 * initialization, so check whether that's a problem.
1384 function livePreview() {
1387 header( 'Content-type: text/xml' );
1388 header( 'Cache-control: no-cache' );
1390 echo $this->getPreviewText( false, false );
1395 * Get a diff between the current contents of the edit box and the
1396 * version of the page we're editing from.
1398 * If this is a section edit, we'll replace the section as for final
1399 * save and then make a comparison.
1401 * @return string HTML
1403 function getDiff() {
1406 require_once( 'DifferenceEngine.php' );
1407 $oldtext = $this->mArticle
->fetchContent();
1408 $newtext = $this->mArticle
->replaceSection(
1409 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1410 $oldtitle = wfMsg( 'currentrev' );
1411 $newtitle = wfMsg( 'yourtext' );
1412 if ( $oldtext !== false ||
$newtext != '' ) {
1413 $de = new DifferenceEngine( $this->mTitle
);
1414 $de->setText( $oldtext, $newtext );
1415 $difftext = $de->getDiff( $oldtitle, $newtitle );
1420 return '<div id="wikiDiff">' . $difftext . '</div>';
1424 * Filter an input field through a Unicode de-armoring process if it
1425 * came from an old browser with known broken Unicode editing issues.
1427 * @param WebRequest $request
1428 * @param string $field
1432 function safeUnicodeInput( $request, $field ) {
1433 $text = rtrim( $request->getText( $field ) );
1434 return $request->getBool( 'safemode' )
1435 ?
$this->unmakesafe( $text )
1440 * Filter an output field through a Unicode armoring process if it is
1441 * going to an old browser with known broken Unicode editing issues.
1443 * @param string $text
1447 function safeUnicodeOutput( $text ) {
1449 $codedText = $wgContLang->recodeForEdit( $text );
1450 return $this->checkUnicodeCompliantBrowser()
1452 : $this->makesafe( $codedText );
1456 * A number of web browsers are known to corrupt non-ASCII characters
1457 * in a UTF-8 text editing environment. To protect against this,
1458 * detected browsers will be served an armored version of the text,
1459 * with non-ASCII chars converted to numeric HTML character references.
1461 * Preexisting such character references will have a 0 added to them
1462 * to ensure that round-trips do not alter the original data.
1464 * @param string $invalue
1468 function makesafe( $invalue ) {
1469 // Armor existing references for reversability.
1470 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
1475 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1476 $bytevalue = ord( $invalue{$i} );
1477 if( $bytevalue <= 0x7F ) { //0xxx xxxx
1478 $result .= chr( $bytevalue );
1480 } elseif( $bytevalue <= 0xBF ) { //10xx xxxx
1481 $working = $working << 6;
1482 $working +
= ($bytevalue & 0x3F);
1484 if( $bytesleft <= 0 ) {
1485 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
1487 } elseif( $bytevalue <= 0xDF ) { //110x xxxx
1488 $working = $bytevalue & 0x1F;
1490 } elseif( $bytevalue <= 0xEF ) { //1110 xxxx
1491 $working = $bytevalue & 0x0F;
1493 } else { //1111 0xxx
1494 $working = $bytevalue & 0x07;
1502 * Reverse the previously applied transliteration of non-ASCII characters
1503 * back to UTF-8. Used to protect data from corruption by broken web browsers
1504 * as listed in $wgBrowserBlackList.
1506 * @param string $invalue
1510 function unmakesafe( $invalue ) {
1512 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1513 if( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+
3} != '0' ) ) {
1517 $hexstring .= $invalue{$i};
1519 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
1521 // Do some sanity checks. These aren't needed for reversability,
1522 // but should help keep the breakage down if the editor
1523 // breaks one of the entities whilst editing.
1524 if ((substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6)) {
1525 $codepoint = hexdec($hexstring);
1526 $result .= codepointToUtf8( $codepoint );
1528 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
1531 $result .= substr( $invalue, $i, 1 );
1534 // reverse the transform that we made for reversability reasons.
1535 return strtr( $result, array( "�" => "&#x" ) );
1538 function noCreatePermission() {
1540 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
1541 $wgOut->addWikiText( wfMsg( 'nocreatetext' ) );