3 * Contain the EditPage class
8 * Splitting edit page/HTML interface from Article...
9 * The actual database and text munging is still in Article,
10 * but it should get easier to call those from alternate
20 var $isConflict = false;
21 var $isCssJsSubpage = false;
22 var $deletedSinceEdit = false;
28 var $save = false, $preview = false, $diff = false;
29 var $minoredit = false, $watchthis = false, $recreate = false;
30 var $textbox1 = '', $textbox2 = '', $summary = '';
31 var $edittime = '', $section = '', $starttime = '';
32 var $oldid = 0, $editintro = '', $scrolltop = null;
38 function EditPage( $article ) {
39 $this->mArticle
=& $article;
41 $this->mTitle
=& $wgTitle;
45 * This is the function that extracts metadata from the article body on the first view.
46 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
47 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
49 function extractMetaDataFromArticle () {
50 global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
51 $this->mMetaData
= '' ;
52 if ( !$wgUseMetadataEdit ) return ;
53 if ( $wgMetadataWhitelist == '' ) return ;
55 $t = $this->mArticle
->getContent ( true ) ;
57 # MISSING : <nowiki> filtering
59 # Categories and language links
60 $t = explode ( "\n" , $t ) ;
61 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY
) ) ;
62 $cat = $ll = array() ;
63 foreach ( $t AS $key => $x )
65 $y = trim ( strtolower ( $x ) ) ;
66 while ( substr ( $y , 0 , 2 ) == '[[' )
68 $y = explode ( ']]' , trim ( $x ) ) ;
69 $first = array_shift ( $y ) ;
70 $first = explode ( ':' , $first ) ;
71 $ns = array_shift ( $first ) ;
72 $ns = trim ( str_replace ( '[' , '' , $ns ) ) ;
73 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
75 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]' ;
76 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
78 $x = implode ( ']]' , $y ) ;
80 $y = trim ( strtolower ( $x ) ) ;
84 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n" ;
85 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n" ;
86 $t = implode ( "\n" , $t ) ;
89 $sat = array () ; # stand-alone-templates; must be lowercase
90 $wl_title = Title
::newFromText ( $wgMetadataWhitelist ) ;
91 $wl_article = new Article ( $wl_title ) ;
92 $wl = explode ( "\n" , $wl_article->getContent(true) ) ;
97 while ( substr ( $x , 0 , 1 ) == '*' )
100 $x = trim ( substr ( $x , 1 ) ) ;
104 $sat[] = strtolower ( $x ) ;
109 # Templates, but only some
110 $t = explode ( '{{' , $t ) ;
112 foreach ( $t AS $key => $x )
114 $y = explode ( '}}' , $x , 2 ) ;
115 if ( count ( $y ) == 2 )
118 $z = explode ( '|' , $z ) ;
119 $tn = array_shift ( $z ) ;
120 if ( in_array ( strtolower ( $tn ) , $sat ) )
122 $tl[] = '{{' . $y[0] . '}}' ;
124 $y = explode ( '}}' , $y[1] , 2 ) ;
126 else $t[$key] = '{{' . $x ;
128 else if ( $key != 0 ) $t[$key] = '{{' . $x ;
131 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl ) ;
132 $t = implode ( '' , $t ) ;
134 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
135 $this->mArticle
->mContent
= $t ;
136 $this->mMetaData
= $s ;
144 * This is the function that gets called for "action=edit". It
145 * sets up various member variables, then passes execution to
146 * another function, usually showEditForm()
148 * The edit form is self-submitting, so that when things like
149 * preview and edit conflicts occur, we get the same form back
150 * with the extra stuff added. Only when the final submission
151 * is made and all is well do we actually save and redirect to
152 * the newly-edited page.
155 global $wgOut, $wgUser, $wgRequest, $wgTitle;
157 $fname = 'EditPage::edit';
158 wfProfileIn( $fname );
159 wfDebug( "$fname: enter\n" );
161 // this is not an article
162 $wgOut->setArticleFlag(false);
164 $this->importFormData( $wgRequest );
165 $this->firsttime
= false;
168 $this->livePreview();
169 wfProfileOut( $fname );
173 if ( ! $this->mTitle
->userCanEdit() ) {
174 wfDebug( "$fname: user can't edit\n" );
175 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ), true );
176 wfProfileOut( $fname );
179 wfDebug( "$fname: Checking blocks\n" );
180 if ( !$this->preview
&& !$this->diff
&& $wgUser->isBlockedFrom( $this->mTitle
, !$this->save
) ) {
181 # When previewing, don't check blocked state - will get caught at save time.
182 # Also, check when starting edition is done against slave to improve performance.
183 wfDebug( "$fname: user is blocked\n" );
184 $this->blockedIPpage();
185 wfProfileOut( $fname );
188 if ( !$wgUser->isAllowed('edit') ) {
189 if ( $wgUser->isAnon() ) {
190 wfDebug( "$fname: user must log in\n" );
191 $this->userNotLoggedInPage();
192 wfProfileOut( $fname );
195 wfDebug( "$fname: read-only page\n" );
196 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ), true );
197 wfProfileOut( $fname );
201 if ( wfReadOnly() ) {
202 wfDebug( "$fname: read-only mode is engaged\n" );
203 if( $this->save ||
$this->preview
) {
204 $this->formtype
= 'preview';
205 } else if ( $this->diff
) {
206 $this->formtype
= 'diff';
208 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ) );
209 wfProfileOut( $fname );
214 $this->formtype
= 'save';
215 } else if ( $this->preview
) {
216 $this->formtype
= 'preview';
217 } else if ( $this->diff
) {
218 $this->formtype
= 'diff';
219 } else { # First time through
220 $this->firsttime
= true;
221 if( $this->previewOnOpen() ) {
222 $this->formtype
= 'preview';
224 $this->extractMetaDataFromArticle () ;
225 $this->formtype
= 'initial';
230 wfProfileIn( "$fname-business-end" );
232 $this->isConflict
= false;
233 // css / js subpages of user pages get a special treatment
234 $this->isCssJsSubpage
= $wgTitle->isCssJsSubpage();
236 /* Notice that we can't use isDeleted, because it returns true if article is ever deleted
237 * no matter it's current state
239 $this->deletedSinceEdit
= false;
240 if ( $this->edittime
!= '' ) {
241 /* Note that we rely on logging table, which hasn't been always there,
242 * but that doesn't matter, because this only applies to brand new
243 * deletes. This is done on every preview and save request. Move it further down
244 * to only perform it on saves
246 if ( $this->mTitle
->isDeleted() ) {
247 $this->lastDelete
= $this->getLastDelete();
248 if ( !is_null($this->lastDelete
) ) {
249 $deletetime = $this->lastDelete
->log_timestamp
;
250 if ( ($deletetime - $this->starttime
) > 0 ) {
251 $this->deletedSinceEdit
= true;
257 if(!$this->mTitle
->getArticleID() && ('initial' == $this->formtype ||
$this->firsttime
)) { # new article
260 if( $this->mTitle
->isTalkPage() ) {
261 $wgOut->addWikiText( wfMsg( 'talkpagetext' ) );
264 # Attempt submission here. This will check for edit conflicts,
265 # and redundantly check for locked database, blocked IPs, etc.
266 # that edit() already checked just in case someone tries to sneak
267 # in the back door with a hand-edited submission URL.
269 if ( 'save' == $this->formtype
) {
270 if ( !$this->attemptSave() ) {
271 wfProfileOut( "$fname-business-end" );
272 wfProfileOut( $fname );
277 # First time through: get contents, set time for conflict
279 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
280 $this->initialiseForm();
283 $this->showEditForm();
284 wfProfileOut( "$fname-business-end" );
285 wfProfileOut( $fname );
289 * Return true if this page should be previewed when the edit form
290 * is initially opened.
294 function previewOnOpen() {
296 return $wgUser->getOption( 'previewonfirst' ) ||
297 ( $this->mTitle
->getNamespace() == NS_CATEGORY
&&
298 !$this->mTitle
->exists() );
304 function importFormData( &$request ) {
306 $fname = 'EditPage::importFormData';
307 wfProfileIn( $fname );
309 if( $request->wasPosted() ) {
310 # These fields need to be checked for encoding.
311 # Also remove trailing whitespace, but don't remove _initial_
312 # whitespace from the text boxes. This may be significant formatting.
313 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
314 $this->textbox2
= $this->safeUnicodeInput( $request, 'wpTextbox2' );
315 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
316 # Truncate for whole multibyte characters. +5 bytes for ellipsis
317 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
319 $this->edittime
= $request->getVal( 'wpEdittime' );
320 $this->starttime
= $request->getVal( 'wpStarttime' );
322 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
324 if( is_null( $this->edittime
) ) {
325 # If the form is incomplete, force to preview.
326 wfDebug( "$fname: Form data appears to be incomplete\n" );
327 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
328 $this->preview
= true;
330 if( $this->tokenOk( $request ) ) {
331 # Some browsers will not report any submit button
332 # if the user hits enter in the comment box.
333 # The unmarked state will be assumed to be a save,
334 # if the form seems otherwise complete.
335 wfDebug( "$fname: Passed token check.\n" );
336 $this->preview
= $request->getCheck( 'wpPreview' );
337 $this->diff
= $request->getCheck( 'wpDiff' );
339 # Page might be a hack attempt posted from
340 # an external site. Preview instead of saving.
341 wfDebug( "$fname: Failed token check; forcing preview\n" );
342 $this->preview
= true;
345 $this->save
= ! ( $this->preview
OR $this->diff
);
346 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
347 $this->edittime
= null;
350 if( !preg_match( '/^\d{14}$/', $this->starttime
)) {
351 $this->starttime
= null;
354 $this->recreate
= $request->getCheck( 'wpRecreate' );
356 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
357 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
359 # Not a posted form? Start with nothing.
360 wfDebug( "$fname: Not a posted form.\n" );
361 $this->textbox1
= '';
362 $this->textbox2
= '';
363 $this->mMetaData
= '';
365 $this->edittime
= '';
366 $this->starttime
= wfTimestampNow();
367 $this->preview
= false;
370 $this->minoredit
= false;
371 $this->watchthis
= false;
372 $this->recreate
= false;
375 $this->oldid
= $request->getInt( 'oldid' );
377 # Section edit can come from either the form or a link
378 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
380 $this->live
= $request->getCheck( 'live' );
381 $this->editintro
= $request->getText( 'editintro' );
383 wfProfileOut( $fname );
387 * Make sure the form isn't faking a user's credentials.
389 * @param WebRequest $request
393 function tokenOk( &$request ) {
395 if( $wgUser->isAnon() ) {
396 # Anonymous users may not have a session
397 # open. Don't tokenize.
400 return $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
404 function showIntro() {
405 global $wgOut, $wgUser;
406 $addstandardintro=true;
407 if($this->editintro
) {
408 $introtitle=Title
::newFromText($this->editintro
);
409 if(isset($introtitle) && $introtitle->userCanRead()) {
410 $rev=Revision
::newFromTitle($introtitle);
412 $wgOut->addWikiText($rev->getText());
413 $addstandardintro=false;
417 if($addstandardintro) {
418 if ( $wgUser->isLoggedIn() )
419 $wgOut->addWikiText( wfMsg( 'newarticletext' ) );
421 $wgOut->addWikiText( wfMsg( 'newarticletextanon' ) );
427 * @return bool false if output is done, true if the rest of the form should be displayed
429 function attemptSave() {
430 global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut;
432 $fname = 'EditPage::attemptSave';
433 wfProfileIn( $fname );
434 wfProfileIn( "$fname-checks" );
436 # Reintegrate metadata
437 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
438 $this->mMetaData
= '' ;
441 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
442 $this->spamPage ( $matches[0] );
443 wfProfileOut( "$fname-checks" );
444 wfProfileOut( $fname );
447 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
448 # Error messages or other handling should be performed by the filter function
449 wfProfileOut( $fname );
450 wfProfileOut( "$fname-checks" );
453 if ( !wfRunHooks( 'EditFilter', array( &$this, $this->textbox1
, $this->section
) ) ) {
454 # Error messages or other handling should be performed by the filter function
455 wfProfileOut( $fname );
456 wfProfileOut( "$fname-checks" );
459 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
460 # Check block state against master, thus 'false'.
461 $this->blockedIPpage();
462 wfProfileOut( "$fname-checks" );
463 wfProfileOut( $fname );
467 if ( !$wgUser->isAllowed('edit') ) {
468 if ( $wgUser->isAnon() ) {
469 $this->userNotLoggedInPage();
470 wfProfileOut( "$fname-checks" );
471 wfProfileOut( $fname );
475 $wgOut->readOnlyPage();
476 wfProfileOut( "$fname-checks" );
477 wfProfileOut( $fname );
482 if ( wfReadOnly() ) {
483 $wgOut->readOnlyPage();
484 wfProfileOut( "$fname-checks" );
485 wfProfileOut( $fname );
488 if ( $wgUser->pingLimiter() ) {
489 $wgOut->rateLimited();
490 wfProfileOut( "$fname-checks" );
491 wfProfileOut( $fname );
495 # If the article has been deleted while editing, don't save it without
497 if ( $this->deletedSinceEdit
&& !$this->recreate
) {
498 wfProfileOut( "$fname-checks" );
499 wfProfileOut( $fname );
503 wfProfileOut( "$fname-checks" );
505 # If article is new, insert it.
506 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
508 # Don't save a new article if it's blank.
509 if ( ( '' == $this->textbox1
) ) {
510 $wgOut->redirect( $this->mTitle
->getFullURL() );
511 wfProfileOut( $fname );
515 $isComment=($this->section
=='new');
516 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
517 $this->minoredit
, $this->watchthis
, false, $isComment);
519 wfProfileOut( $fname );
523 # Article exists. Check for edit conflict.
525 $this->mArticle
->clear(); # Force reload of dates, etc.
526 $this->mArticle
->forUpdate( true ); # Lock the article
528 if( ( $this->section
!= 'new' ) &&
529 ($this->mArticle
->getTimestamp() != $this->edittime
) )
531 $this->isConflict
= true;
533 $userid = $wgUser->getID();
535 if ( $this->isConflict
) {
536 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
537 $this->mArticle
->getTimestamp() . "'\n" );
538 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
541 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
542 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
544 if( is_null( $text ) ) {
545 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
546 $this->isConflict
= true;
547 $text = $this->textbox1
;
550 # Suppress edit conflict with self, except for section edits where merging is required.
551 if ( ( $this->section
== '' ) && ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
552 wfDebug( "Suppressing edit conflict, same user.\n" );
553 $this->isConflict
= false;
555 # switch from section editing to normal editing in edit conflict
556 if($this->isConflict
) {
558 if( $this->mergeChangesInto( $text ) ){
559 // Successful merge! Maybe we should tell the user the good news?
560 $this->isConflict
= false;
561 wfDebug( "Suppressing edit conflict, successful merge.\n" );
564 $this->textbox1
= $text;
565 wfDebug( "Keeping edit conflict, failed merge.\n" );
570 if ( $this->isConflict
) {
571 wfProfileOut( $fname );
576 wfProfileIn( "$fname-sectionanchor" );
578 if( $this->section
== 'new' ) {
579 if( $this->summary
!= '' ) {
580 $sectionanchor = $this->sectionAnchor( $this->summary
);
582 } elseif( $this->section
!= '' ) {
583 # Try to get a section anchor from the section source, redirect to edited section if header found
584 # XXX: might be better to integrate this into Article::replaceSection
585 # for duplicate heading checking and maybe parsing
586 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
587 # we can't deal with anchors, includes, html etc in the header for now,
588 # headline would need to be parsed to improve this
589 if($hasmatch and strlen($matches[2]) > 0) {
590 $sectionanchor = $this->sectionAnchor( $matches[2] );
593 wfProfileOut( "$fname-sectionanchor" );
595 // Save errors may fall down to the edit form, but we've now
596 // merged the section into full text. Clear the section field
597 // so that later submission of conflict forms won't try to
598 // replace that into a duplicated mess.
599 $this->textbox1
= $text;
602 # update the article here
603 if( $this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
604 $this->watchthis
, '', $sectionanchor ) ) {
605 wfProfileOut( $fname );
608 $this->isConflict
= true;
610 wfProfileOut( $fname );
615 * Initialise form fields in the object
616 * Called on the first invocation, e.g. when a user clicks an edit link
618 function initialiseForm() {
619 $this->edittime
= $this->mArticle
->getTimestamp();
620 $this->textbox1
= $this->mArticle
->getContent( true );
626 * Send the edit form and related headers to $wgOut
627 * @param $formCallback Optional callable that takes an OutputPage
628 * parameter; will be called during form output
629 * near the top, for captchas and the like.
631 function showEditForm( $formCallback=null ) {
632 global $wgOut, $wgUser, $wgAllowAnonymousMinor, $wgLang, $wgContLang;
634 $fname = 'EditPage::showEditForm';
635 wfProfileIn( $fname );
637 $sk =& $wgUser->getSkin();
639 $wgOut->setRobotpolicy( 'noindex,nofollow' );
641 # Enabled article-related sidebar, toplinks, etc.
642 $wgOut->setArticleRelated( true );
644 if ( $this->isConflict
) {
645 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
646 $wgOut->setPageTitle( $s );
647 $wgOut->addWikiText( wfMsg( 'explainconflict' ) );
649 $this->textbox2
= $this->textbox1
;
650 $this->textbox1
= $this->mArticle
->getContent( true );
651 $this->edittime
= $this->mArticle
->getTimestamp();
654 if( $this->section
!= '' ) {
655 if( $this->section
== 'new' ) {
656 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
658 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
659 if( !$this->preview
&& !$this->diff
) {
660 preg_match( "/^(=+)(.+)\\1/mi",
663 if( !empty( $matches[2] ) ) {
664 $this->summary
= "/* ". trim($matches[2])." */ ";
669 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
671 $wgOut->setPageTitle( $s );
672 if ( !$this->checkUnicodeCompliantBrowser() ) {
673 $this->mArticle
->setOldSubtitle();
674 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
676 if ( isset( $this->mArticle
)
677 && isset( $this->mArticle
->mRevision
)
678 && !$this->mArticle
->mRevision
->isCurrent() ) {
679 $this->mArticle
->setOldSubtitle();
680 $wgOut->addWikiText( wfMsg( 'editingold' ) );
685 $wgOut->addWikiText( wfMsg( 'readonlywarning' ) );
686 } else if ( $this->isCssJsSubpage
and 'preview' != $this->formtype
) {
687 $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ));
689 if( $this->mTitle
->isProtected('edit') ) {
690 $wgOut->addWikiText( wfMsg( 'protectedpagewarning' ) );
693 $kblength = (int)(strlen( $this->textbox1
) / 1024);
694 if( $kblength > 29 ) {
695 $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) ) );
698 $rows = $wgUser->getOption( 'rows' );
699 $cols = $wgUser->getOption( 'cols' );
701 $ew = $wgUser->getOption( 'editwidth' );
702 if ( $ew ) $ew = " style=\"width:100%\"";
705 $q = 'action=submit';
706 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
707 $action = $this->mTitle
->escapeLocalURL( $q );
709 $summary = wfMsg('summary');
710 $subject = wfMsg('subject');
711 $minor = wfMsg('minoredit');
712 $watchthis = wfMsg ('watchthis');
713 $save = wfMsg('savearticle');
714 $prev = wfMsg('showpreview');
715 $diff = wfMsg('showdiff');
717 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
719 $edithelpurl = $sk->makeInternalOrExternalUrl( wfMsg( 'edithelppage' ));
720 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
721 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
722 htmlspecialchars( wfMsg( 'newwindow' ) );
724 global $wgRightsText;
725 $copywarn = "<div id=\"editpage-copywarn\">\n" .
726 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
727 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
728 $wgRightsText ) . "\n</div>";
730 if( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage
) {
731 # prepare toolbar for edit buttons
732 $toolbar = $this->getEditToolbar();
737 // activate checkboxes if user wants them to be always active
738 if( !$this->preview
&& !$this->diff
) {
739 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis
= true;
740 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
742 // activate checkbox also if user is already watching the page,
743 // require wpWatchthis to be unset so that second condition is not
744 // checked unnecessarily
745 if( !$this->watchthis
&& $this->mTitle
->userIsWatching() ) $this->watchthis
= true;
750 if ( $wgUser->isLoggedIn() ||
$wgAllowAnonymousMinor ) {
752 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
753 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
754 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
759 if ( $wgUser->isLoggedIn() ) {
760 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".
761 ($this->watchthis?
" checked='checked'":"").
762 " accesskey=\"".htmlspecialchars(wfMsg('accesskey-watch'))."\" id='wpWatchthis' />".
763 "<label for='wpWatchthis' title=\"" .
764 htmlspecialchars(wfMsg('tooltip-watch'))."\">{$watchthis}</label>";
767 $checkboxhtml = $minoredithtml . $watchhtml;
769 $wgOut->addHTML( '<div id="wikiPreview">' );
770 if ( 'preview' == $this->formtype
) {
771 $previewOutput = $this->getPreviewText();
772 if ( $wgUser->getOption('previewontop' ) ) {
773 $wgOut->addHTML( $previewOutput );
774 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
775 $this->mArticle
->closeShowCategory();
777 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
780 $wgOut->addHTML( '</div>' );
781 if ( 'diff' == $this->formtype
) {
782 if ( $wgUser->getOption('previewontop' ) ) {
783 $wgOut->addHTML( $this->getDiff() );
788 # if this is a comment, show a subject line at the top, which is also the edit summary.
789 # Otherwise, show a summary field at the bottom
790 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
791 if( $this->section
== 'new' ) {
792 $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 />";
795 $commentsubject = '';
796 $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 />";
799 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
800 if( !$this->preview
&& !$this->diff
) {
801 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
803 $templates = $this->getTemplatesUsed();
805 global $wgLivePreview;
806 if ( $wgLivePreview ) {
807 $liveOnclick = $this->doLivePreviewScript();
812 global $wgUseMetadataEdit ;
813 if ( $wgUseMetadataEdit ) {
814 $metadata = $this->mMetaData
;
815 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
816 $helppage = Title
::newFromText( wfMsg( "metadata_page" ) ) ;
817 $top = wfMsg( 'metadata', $helppage->getInternalURL() );
818 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
820 else $metadata = "" ;
824 if ($this->deletedSinceEdit
) {
825 if ( 'save' != $this->formtype
) {
826 $wgOut->addWikiText( wfMsg('deletedwhileediting'));
828 // Hide the toolbar and edit area, use can click preview to get it back
829 // Add an confirmation checkbox and explanation.
831 $hidden = 'type="hidden" style="display:none;"';
832 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete
->user_name
, $this->lastDelete
->log_comment
));
834 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
835 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
839 $safemodehtml = $this->checkUnicodeCompliantBrowser()
841 : "<input type='hidden' name=\"safemode\" value='1' />\n";
843 $wgOut->addHTML( <<<END
845 <form id="editform" name="editform" method="post" action="$action"
846 enctype="multipart/form-data">
849 if( is_callable( $formCallback ) ) {
850 call_user_func_array( $formCallback, array( &$wgOut ) );
852 $wgOut->addHTML( <<<END
855 <textarea tabindex='1' accesskey="," name="wpTextbox1" id="wpTextbox1" rows='{$rows}'
856 cols='{$cols}'{$ew} $hidden>
858 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1
) ) .
865 <div class='editButtons'>
866 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
867 " title=\"".wfMsg('tooltip-save')."\"/>
868 <input tabindex='6' id='wpPreview' type='submit' $liveOnclick value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
869 " title=\"".wfMsg('tooltip-preview')."\"/>
870 <input tabindex='7' id='wpDiff' type='submit' value=\"{$diff}\" name=\"wpDiff\" accesskey=\"".wfMsg('accesskey-diff')."\"".
871 " title=\"".wfMsg('tooltip-diff')."\"/> <span class='editHelp'>{$cancel} | {$edithelp}</span></div>
873 <div class='templatesUsed'>
877 $wgOut->addWikiText( $copywarn );
879 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
880 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
881 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
882 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
884 if ( $wgUser->isLoggedIn() ) {
886 * To make it harder for someone to slip a user a page
887 * which submits an edit form to the wiki without their
888 * knowledge, a random token is associated with the login
889 * session. If it's not passed back with the submission,
890 * we won't save the page, or render user JavaScript and
893 $token = htmlspecialchars( $wgUser->editToken() );
894 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
898 if ( $this->isConflict
) {
899 require_once( "DifferenceEngine.php" );
900 $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' );
901 DifferenceEngine
::showDiff( $this->textbox2
, $this->textbox1
,
902 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
904 $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
905 $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
906 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2
) ) . "\n</textarea>" );
908 $wgOut->addHTML( "</form>\n" );
909 if ( $this->formtype
== 'preview' && !$wgUser->getOption( 'previewontop' ) ) {
910 $wgOut->addHTML( '<div id="wikiPreview">' . $previewOutput . '</div>' );
912 if ( $this->formtype
== 'diff' && !$wgUser->getOption( 'previewontop' ) ) {
913 #$wgOut->addHTML( '<div id="wikiPreview">' . $difftext . '</div>' );
914 $wgOut->addHTML( $this->getDiff() );
917 wfProfileOut( $fname );
921 * Prepare a list of templates used by this page. Returns HTML.
923 function getTemplatesUsed() {
926 $fname = 'EditPage::getTemplatesUsed';
927 wfProfileIn( $fname );
929 $sk =& $wgUser->getSkin();
932 $articleTemplates = $this->mArticle
->getUsedTemplates();
933 if ( count( $articleTemplates ) > 0 ) {
934 $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
935 foreach ( $articleTemplates as $tpl ) {
936 if ( $titleObj = Title
::makeTitle( NS_TEMPLATE
, $tpl ) ) {
937 $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
940 $templates .= '</ul>';
942 wfProfileOut( $fname );
947 * Live Preview lets us fetch rendered preview page content and
948 * add it to the page without refreshing the whole page.
949 * If not supported by the browser it will fall through to the normal form
952 * This function outputs a script tag to support live preview, and
953 * returns an onclick handler which should be added to the attributes
954 * of the preview button
956 function doLivePreviewScript() {
957 global $wgStylePath, $wgJsMimeType, $wgOut;
958 $wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' .
959 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
960 '"></script>' . "\n" );
961 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
962 return 'onclick="return !livePreview('.
963 'getElementById(\'wikiPreview\'),' .
964 'editform.wpTextbox1.value,' .
965 htmlspecialchars( '"' . $liveAction . '"' ) . ')"';
968 function getLastDelete() {
969 $dbr =& wfGetDB( DB_SLAVE
);
970 $fname = 'EditPage::getLastDelete';
972 array( 'logging', 'user' ),
982 array( 'log_namespace' => $this->mTitle
->getNamespace(),
983 'log_title' => $this->mTitle
->getDBkey(),
984 'log_type' => 'delete',
985 'log_action' => 'delete',
986 'user_id=log_user' ),
988 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
990 if($dbr->numRows($res) == 1) {
991 while ( $x = $dbr->fetchObject ( $res ) )
993 $dbr->freeResult ( $res ) ;
1003 function getPreviewText() {
1004 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgAllowDiffPreview, $wgEnableDiffPreviewPreference;
1006 $fname = 'EditPage::getPreviewText';
1007 wfProfileIn( $fname );
1009 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1010 "<div class='previewnote'>" . $wgOut->parse( wfMsg( 'previewnote' ) ) . "</div>\n";
1011 if ( $this->isConflict
) {
1012 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1015 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1016 $parserOptions->setEditSection( false );
1018 # don't parse user css/js, show message about preview
1019 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1021 if ( $this->isCssJsSubpage
) {
1022 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
1023 $previewtext = wfMsg('usercsspreview');
1024 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
1025 $previewtext = wfMsg('userjspreview');
1027 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
1028 $wgOut->addHTML( $parserOutput->mText
);
1029 wfProfileOut( $fname );
1030 return $previewhead;
1032 # if user want to see preview when he edit an article
1033 if( $wgUser->getOption('previewonfirst') and ($this->textbox1
== '')) {
1034 $this->textbox1
= $this->mArticle
->getContent(true);
1037 $toparse = $this->textbox1
;
1039 # If we're adding a comment, we need to show the
1040 # summary as the headline
1041 if($this->section
=="new" && $this->summary
!="") {
1042 $toparse="== {$this->summary} ==\n\n".$toparse;
1045 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
1047 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
1048 $wgTitle, $parserOptions );
1050 $previewHTML = $parserOutput->mText
;
1052 $wgOut->addCategoryLinks($parserOutput->getCategoryLinks());
1053 $wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
1055 wfProfileOut( $fname );
1056 return $previewhead . $previewHTML;
1063 function blockedIPpage() {
1064 global $wgOut, $wgUser, $wgContLang;
1066 $wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
1067 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1068 $wgOut->setArticleRelated( false );
1070 $id = $wgUser->blockedBy();
1071 $reason = $wgUser->blockedFor();
1074 if ( is_numeric( $id ) ) {
1075 $name = User
::whoIs( $id );
1079 $link = '[[' . $wgContLang->getNsText( NS_USER
) .
1080 ":{$name}|{$name}]]";
1082 $wgOut->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
1083 $wgOut->returnToMain( false );
1089 function userNotLoggedInPage() {
1092 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1093 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1094 $wgOut->setArticleRelated( false );
1096 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
1097 $wgOut->returnToMain( false );
1103 function spamPage ( $match = false )
1106 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1107 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1108 $wgOut->setArticleRelated( false );
1110 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
1112 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
1114 $wgOut->returnToMain( false );
1121 function mergeChangesInto( &$editText ){
1122 $fname = 'EditPage::mergeChangesInto';
1123 wfProfileIn( $fname );
1125 $db =& wfGetDB( DB_MASTER
);
1127 // This is the revision the editor started from
1128 $baseRevision = Revision
::loadFromTimestamp(
1129 $db, $this->mArticle
->mTitle
, $this->edittime
);
1130 if( is_null( $baseRevision ) ) {
1131 wfProfileOut( $fname );
1134 $baseText = $baseRevision->getText();
1136 // The current state, we want to merge updates into it
1137 $currentRevision = Revision
::loadFromTitle(
1138 $db, $this->mArticle
->mTitle
);
1139 if( is_null( $currentRevision ) ) {
1140 wfProfileOut( $fname );
1143 $currentText = $currentRevision->getText();
1145 if( wfMerge( $baseText, $editText, $currentText, $result ) ){
1146 $editText = $result;
1147 wfProfileOut( $fname );
1150 wfProfileOut( $fname );
1156 * Check if the browser is on a blacklist of user-agents known to
1157 * mangle UTF-8 data on form submission. Returns true if Unicode
1158 * should make it through, false if it's known to be a problem.
1162 function checkUnicodeCompliantBrowser() {
1163 global $wgBrowserBlackList;
1164 if( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1165 // No User-Agent header sent? Trust it by default...
1168 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1169 foreach ( $wgBrowserBlackList as $browser ) {
1170 if ( preg_match($browser, $currentbrowser) ) {
1178 * Format an anchor fragment as it would appear for a given section name
1179 * @param string $text
1183 function sectionAnchor( $text ) {
1184 $headline = Sanitizer
::decodeCharReferences( $text );
1186 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
1187 $headline = trim( $headline );
1188 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
1189 $replacearray = array(
1194 array_keys( $replacearray ),
1195 array_values( $replacearray ),
1200 * Shows a bulletin board style toolbar for common editing functions.
1201 * It can be disabled in the user preferences.
1202 * The necessary JavaScript code can be found in style/wikibits.js.
1204 function getEditToolbar() {
1205 global $wgStylePath, $wgLang, $wgMimeType, $wgJsMimeType;
1208 * toolarray an array of arrays which each include the filename of
1209 * the button image (without path), the opening tag, the closing tag,
1210 * and optionally a sample text that is inserted between the two when no
1211 * selection is highlighted.
1212 * The tip text is shown when the user moves the mouse over the button.
1214 * Already here are accesskeys (key), which are not used yet until someone
1215 * can figure out a way to make them work in IE. However, we should make
1216 * sure these keys are not defined on the edit page.
1219 array( 'image'=>'button_bold.png',
1221 'close' => "\'\'\'",
1222 'sample'=> wfMsg('bold_sample'),
1223 'tip' => wfMsg('bold_tip'),
1226 array( 'image'=>'button_italic.png',
1229 'sample'=> wfMsg('italic_sample'),
1230 'tip' => wfMsg('italic_tip'),
1233 array( 'image'=>'button_link.png',
1236 'sample'=> wfMsg('link_sample'),
1237 'tip' => wfMsg('link_tip'),
1240 array( 'image'=>'button_extlink.png',
1243 'sample'=> wfMsg('extlink_sample'),
1244 'tip' => wfMsg('extlink_tip'),
1247 array( 'image'=>'button_headline.png',
1249 'close' => " ==\\n",
1250 'sample'=> wfMsg('headline_sample'),
1251 'tip' => wfMsg('headline_tip'),
1254 array( 'image'=>'button_image.png',
1255 'open' => '[['.$wgLang->getNsText(NS_IMAGE
).":",
1257 'sample'=> wfMsg('image_sample'),
1258 'tip' => wfMsg('image_tip'),
1261 array( 'image' =>'button_media.png',
1262 'open' => '[['.$wgLang->getNsText(NS_MEDIA
).':',
1264 'sample'=> wfMsg('media_sample'),
1265 'tip' => wfMsg('media_tip'),
1268 array( 'image' =>'button_math.png',
1269 'open' => "\\<math\\>",
1270 'close' => "\\</math\\>",
1271 'sample'=> wfMsg('math_sample'),
1272 'tip' => wfMsg('math_tip'),
1275 array( 'image' =>'button_nowiki.png',
1276 'open' => "\\<nowiki\\>",
1277 'close' => "\\</nowiki\\>",
1278 'sample'=> wfMsg('nowiki_sample'),
1279 'tip' => wfMsg('nowiki_tip'),
1282 array( 'image' =>'button_sig.png',
1286 'tip' => wfMsg('sig_tip'),
1289 array( 'image' =>'button_hr.png',
1290 'open' => "\\n----\\n",
1293 'tip' => wfMsg('hr_tip'),
1297 $toolbar ="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
1299 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
1300 foreach($toolarray as $tool) {
1302 $image=$wgStylePath.'/common/images/'.$tool['image'];
1303 $open=$tool['open'];
1304 $close=$tool['close'];
1305 $sample = wfEscapeJsString( $tool['sample'] );
1307 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1308 // Older browsers show a "speedtip" type message only for ALT.
1309 // Ideally these should be different, realistically they
1310 // probably don't need to be.
1311 $tip = wfEscapeJsString( $tool['tip'] );
1313 #$key = $tool["key"];
1315 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
1318 $toolbar.="document.writeln(\"</div>\");\n";
1319 $toolbar.="/*]]>*/\n</script>";
1324 * Output preview text only. This can be sucked into the edit page
1325 * via JavaScript, and saves the server time rendering the skin as
1326 * well as theoretically being more robust on the client (doesn't
1327 * disturb the edit box's undo history, won't eat your text on
1330 * @todo This doesn't include category or interlanguage links.
1331 * Would need to enhance it a bit, maybe wrap them in XML
1332 * or something... that might also require more skin
1333 * initialization, so check whether that's a problem.
1335 function livePreview() {
1338 header( 'Content-type: text/xml' );
1339 header( 'Cache-control: no-cache' );
1341 echo $this->getPreviewText( false, false );
1346 * Get a diff between the current contents of the edit box and the
1347 * version of the page we're editing from.
1349 * If this is a section edit, we'll replace the section as for final
1350 * save and then make a comparison.
1352 * @return string HTML
1354 function getDiff() {
1357 require_once( 'DifferenceEngine.php' );
1358 $oldtext = $this->mArticle
->fetchContent();
1359 $newtext = $this->mArticle
->replaceSection(
1360 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1361 $oldtitle = wfMsg( 'currentrev' );
1362 $newtitle = wfMsg( 'yourtext' );
1363 if ( $oldtext != wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) ||
$newtext != '' ) {
1364 $difftext = DifferenceEngine
::getDiff( $oldtext, $newtext, $oldtitle, $newtitle );
1367 return '<div id="wikiDiff">' . $difftext . '</div>';
1371 * Filter an input field through a Unicode de-armoring process if it
1372 * came from an old browser with known broken Unicode editing issues.
1374 * @param WebRequest $request
1375 * @param string $field
1379 function safeUnicodeInput( $request, $field ) {
1380 $text = rtrim( $request->getText( $field ) );
1381 return $request->getBool( 'safemode' )
1382 ?
$this->unmakesafe( $text )
1387 * Filter an output field through a Unicode armoring process if it is
1388 * going to an old browser with known broken Unicode editing issues.
1390 * @param string $text
1394 function safeUnicodeOutput( $text ) {
1396 $codedText = $wgContLang->recodeForEdit( $text );
1397 return $this->checkUnicodeCompliantBrowser()
1399 : $this->makesafe( $codedText );
1403 * A number of web browsers are known to corrupt non-ASCII characters
1404 * in a UTF-8 text editing environment. To protect against this,
1405 * detected browsers will be served an armored version of the text,
1406 * with non-ASCII chars converted to numeric HTML character references.
1408 * Preexisting such character references will have a 0 added to them
1409 * to ensure that round-trips do not alter the original data.
1411 * @param string $invalue
1415 function makesafe( $invalue ) {
1416 // Armor existing references for reversability.
1417 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
1422 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1423 $bytevalue = ord( $invalue{$i} );
1424 if( $bytevalue <= 0x7F ) { //0xxx xxxx
1425 $result .= chr( $bytevalue );
1427 } elseif( $bytevalue <= 0xBF ) { //10xx xxxx
1428 $working = $working << 6;
1429 $working +
= ($bytevalue & 0x3F);
1431 if( $bytesleft <= 0 ) {
1432 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
1434 } elseif( $bytevalue <= 0xDF ) { //110x xxxx
1435 $working = $bytevalue & 0x1F;
1437 } elseif( $bytevalue <= 0xEF ) { //1110 xxxx
1438 $working = $bytevalue & 0x0F;
1440 } else { //1111 0xxx
1441 $working = $bytevalue & 0x07;
1449 * Reverse the previously applied transliteration of non-ASCII characters
1450 * back to UTF-8. Used to protect data from corruption by broken web browsers
1451 * as listed in $wgBrowserBlackList.
1453 * @param string $invalue
1457 function unmakesafe( $invalue ) {
1459 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1460 if( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+
3} != '0' ) ) {
1464 $hexstring .= $invalue{$i};
1466 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
1468 // Do some sanity checks. These aren't needed for reversability,
1469 // but should help keep the breakage down if the editor
1470 // breaks one of the entities whilst editing.
1471 if ((substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6)) {
1472 $codepoint = hexdec($hexstring);
1473 $result .= codepointToUtf8( $codepoint );
1475 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
1478 $result .= substr( $invalue, $i, 1 );
1481 // reverse the transform that we made for reversability reasons.
1482 return strtr( $result, array( "�" => "&#x" ) );