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 $fname = 'EditPage::edit';
159 wfProfileIn( $fname );
160 wfDebug( "$fname: enter\n" );
162 // this is not an article
163 $wgOut->setArticleFlag(false);
165 $this->importFormData( $wgRequest );
166 $this->firsttime
= false;
169 $this->livePreview();
170 wfProfileOut( $fname );
174 if ( ! $this->mTitle
->userCanEdit() ) {
175 wfDebug( "$fname: user can't edit\n" );
176 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ), true );
177 wfProfileOut( $fname );
180 wfDebug( "$fname: Checking blocks\n" );
181 if ( !$this->preview
&& !$this->diff
&& $wgUser->isBlockedFrom( $this->mTitle
, !$this->save
) ) {
182 # When previewing, don't check blocked state - will get caught at save time.
183 # Also, check when starting edition is done against slave to improve performance.
184 wfDebug( "$fname: user is blocked\n" );
185 $this->blockedIPpage();
186 wfProfileOut( $fname );
189 if ( !$wgUser->isAllowed('edit') ) {
190 if ( $wgUser->isAnon() ) {
191 wfDebug( "$fname: user must log in\n" );
192 $this->userNotLoggedInPage();
193 wfProfileOut( $fname );
196 wfDebug( "$fname: read-only page\n" );
197 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ), true );
198 wfProfileOut( $fname );
202 if ( wfReadOnly() ) {
203 wfDebug( "$fname: read-only mode is engaged\n" );
204 if( $this->save ||
$this->preview
) {
205 $this->formtype
= 'preview';
206 } else if ( $this->diff
) {
207 $this->formtype
= 'diff';
209 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ) );
210 wfProfileOut( $fname );
215 $this->formtype
= 'save';
216 } else if ( $this->preview
) {
217 $this->formtype
= 'preview';
218 } else if ( $this->diff
) {
219 $this->formtype
= 'diff';
220 } else { # First time through
221 $this->firsttime
= true;
222 if( $this->previewOnOpen() ) {
223 $this->formtype
= 'preview';
225 $this->extractMetaDataFromArticle () ;
226 $this->formtype
= 'initial';
231 wfProfileIn( "$fname-business-end" );
233 $this->isConflict
= false;
234 // css / js subpages of user pages get a special treatment
235 $this->isCssJsSubpage
= $wgTitle->isCssJsSubpage();
237 /* Notice that we can't use isDeleted, because it returns true if article is ever deleted
238 * no matter it's current state
240 $this->deletedSinceEdit
= false;
241 if ( $this->edittime
!= '' ) {
242 /* Note that we rely on logging table, which hasn't been always there,
243 * but that doesn't matter, because this only applies to brand new
244 * deletes. This is done on every preview and save request. Move it further down
245 * to only perform it on saves
247 if ( $this->mTitle
->isDeleted() ) {
248 $this->lastDelete
= $this->getLastDelete();
249 if ( !is_null($this->lastDelete
) ) {
250 $deletetime = $this->lastDelete
->log_timestamp
;
251 if ( ($deletetime - $this->starttime
) > 0 ) {
252 $this->deletedSinceEdit
= true;
258 if(!$this->mTitle
->getArticleID() && ('initial' == $this->formtype ||
$this->firsttime
)) { # new article
261 if( $this->mTitle
->isTalkPage() ) {
262 $wgOut->addWikiText( wfMsg( 'talkpagetext' ) );
265 # Attempt submission here. This will check for edit conflicts,
266 # and redundantly check for locked database, blocked IPs, etc.
267 # that edit() already checked just in case someone tries to sneak
268 # in the back door with a hand-edited submission URL.
270 if ( 'save' == $this->formtype
) {
271 if ( !$this->attemptSave() ) {
272 wfProfileOut( "$fname-business-end" );
273 wfProfileOut( $fname );
278 # First time through: get contents, set time for conflict
280 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
281 $this->initialiseForm();
284 $this->showEditForm();
285 wfProfileOut( "$fname-business-end" );
286 wfProfileOut( $fname );
290 * Return true if this page should be previewed when the edit form
291 * is initially opened.
295 function previewOnOpen() {
297 return $wgUser->getOption( 'previewonfirst' ) ||
298 ( $this->mTitle
->getNamespace() == NS_CATEGORY
&&
299 !$this->mTitle
->exists() );
305 function importFormData( &$request ) {
307 $fname = 'EditPage::importFormData';
308 wfProfileIn( $fname );
310 if( $request->wasPosted() ) {
311 # These fields need to be checked for encoding.
312 # Also remove trailing whitespace, but don't remove _initial_
313 # whitespace from the text boxes. This may be significant formatting.
314 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
315 $this->textbox2
= $this->safeUnicodeInput( $request, 'wpTextbox2' );
316 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
317 # Truncate for whole multibyte characters. +5 bytes for ellipsis
318 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
320 $this->edittime
= $request->getVal( 'wpEdittime' );
321 $this->starttime
= $request->getVal( 'wpStarttime' );
323 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
325 if( is_null( $this->edittime
) ) {
326 # If the form is incomplete, force to preview.
327 wfDebug( "$fname: Form data appears to be incomplete\n" );
328 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
329 $this->preview
= true;
331 $this->preview
= $request->getCheck( 'wpPreview' );
332 $this->diff
= $request->getCheck( 'wpDiff' );
334 if( !$this->preview
) {
335 if ( $this->tokenOk( $request ) ) {
336 # Some browsers will not report any submit button
337 # if the user hits enter in the comment box.
338 # The unmarked state will be assumed to be a save,
339 # if the form seems otherwise complete.
340 wfDebug( "$fname: Passed token check.\n" );
342 # Page might be a hack attempt posted from
343 # an external site. Preview instead of saving.
344 wfDebug( "$fname: Failed token check; forcing preview\n" );
345 $this->preview
= true;
349 $this->save
= ! ( $this->preview
OR $this->diff
);
350 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
351 $this->edittime
= null;
354 if( !preg_match( '/^\d{14}$/', $this->starttime
)) {
355 $this->starttime
= null;
358 $this->recreate
= $request->getCheck( 'wpRecreate' );
360 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
361 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
363 # Not a posted form? Start with nothing.
364 wfDebug( "$fname: Not a posted form.\n" );
365 $this->textbox1
= '';
366 $this->textbox2
= '';
367 $this->mMetaData
= '';
369 $this->edittime
= '';
370 $this->starttime
= wfTimestampNow();
371 $this->preview
= false;
374 $this->minoredit
= false;
375 $this->watchthis
= false;
376 $this->recreate
= false;
379 $this->oldid
= $request->getInt( 'oldid' );
381 # Section edit can come from either the form or a link
382 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
384 $this->live
= $request->getCheck( 'live' );
385 $this->editintro
= $request->getText( 'editintro' );
387 wfProfileOut( $fname );
391 * Make sure the form isn't faking a user's credentials.
393 * @param WebRequest $request
397 function tokenOk( &$request ) {
399 if( $wgUser->isAnon() ) {
400 # Anonymous users may not have a session
401 # open. Don't tokenize.
402 $this->mTokenOk
= true;
404 $this->mTokenOk
= $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
406 return $this->mTokenOk
;
409 function showIntro() {
410 global $wgOut, $wgUser;
411 $addstandardintro=true;
412 if($this->editintro
) {
413 $introtitle=Title
::newFromText($this->editintro
);
414 if(isset($introtitle) && $introtitle->userCanRead()) {
415 $rev=Revision
::newFromTitle($introtitle);
417 $wgOut->addWikiText($rev->getText());
418 $addstandardintro=false;
422 if($addstandardintro) {
423 if ( $wgUser->isLoggedIn() )
424 $wgOut->addWikiText( wfMsg( 'newarticletext' ) );
426 $wgOut->addWikiText( wfMsg( 'newarticletextanon' ) );
432 * @return bool false if output is done, true if the rest of the form should be displayed
434 function attemptSave() {
435 global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut;
437 $fname = 'EditPage::attemptSave';
438 wfProfileIn( $fname );
439 wfProfileIn( "$fname-checks" );
441 # Reintegrate metadata
442 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
443 $this->mMetaData
= '' ;
446 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
447 $this->spamPage ( $matches[0] );
448 wfProfileOut( "$fname-checks" );
449 wfProfileOut( $fname );
452 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
453 # Error messages or other handling should be performed by the filter function
454 wfProfileOut( $fname );
455 wfProfileOut( "$fname-checks" );
458 if ( !wfRunHooks( 'EditFilter', array( &$this, $this->textbox1
, $this->section
) ) ) {
459 # Error messages or other handling should be performed by the filter function
460 wfProfileOut( $fname );
461 wfProfileOut( "$fname-checks" );
464 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
465 # Check block state against master, thus 'false'.
466 $this->blockedIPpage();
467 wfProfileOut( "$fname-checks" );
468 wfProfileOut( $fname );
472 if ( !$wgUser->isAllowed('edit') ) {
473 if ( $wgUser->isAnon() ) {
474 $this->userNotLoggedInPage();
475 wfProfileOut( "$fname-checks" );
476 wfProfileOut( $fname );
480 $wgOut->readOnlyPage();
481 wfProfileOut( "$fname-checks" );
482 wfProfileOut( $fname );
487 if ( wfReadOnly() ) {
488 $wgOut->readOnlyPage();
489 wfProfileOut( "$fname-checks" );
490 wfProfileOut( $fname );
493 if ( $wgUser->pingLimiter() ) {
494 $wgOut->rateLimited();
495 wfProfileOut( "$fname-checks" );
496 wfProfileOut( $fname );
500 # If the article has been deleted while editing, don't save it without
502 if ( $this->deletedSinceEdit
&& !$this->recreate
) {
503 wfProfileOut( "$fname-checks" );
504 wfProfileOut( $fname );
508 wfProfileOut( "$fname-checks" );
510 # If article is new, insert it.
511 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
513 # Don't save a new article if it's blank.
514 if ( ( '' == $this->textbox1
) ) {
515 $wgOut->redirect( $this->mTitle
->getFullURL() );
516 wfProfileOut( $fname );
520 $isComment=($this->section
=='new');
521 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
522 $this->minoredit
, $this->watchthis
, false, $isComment);
524 wfProfileOut( $fname );
528 # Article exists. Check for edit conflict.
530 $this->mArticle
->clear(); # Force reload of dates, etc.
531 $this->mArticle
->forUpdate( true ); # Lock the article
533 if( ( $this->section
!= 'new' ) &&
534 ($this->mArticle
->getTimestamp() != $this->edittime
) )
536 $this->isConflict
= true;
538 $userid = $wgUser->getID();
540 if ( $this->isConflict
) {
541 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
542 $this->mArticle
->getTimestamp() . "'\n" );
543 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
546 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
547 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
549 if( is_null( $text ) ) {
550 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
551 $this->isConflict
= true;
552 $text = $this->textbox1
;
555 # Suppress edit conflict with self, except for section edits where merging is required.
556 if ( ( $this->section
== '' ) && ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
557 wfDebug( "Suppressing edit conflict, same user.\n" );
558 $this->isConflict
= false;
560 # switch from section editing to normal editing in edit conflict
561 if($this->isConflict
) {
563 if( $this->mergeChangesInto( $text ) ){
564 // Successful merge! Maybe we should tell the user the good news?
565 $this->isConflict
= false;
566 wfDebug( "Suppressing edit conflict, successful merge.\n" );
569 $this->textbox1
= $text;
570 wfDebug( "Keeping edit conflict, failed merge.\n" );
575 if ( $this->isConflict
) {
576 wfProfileOut( $fname );
581 wfProfileIn( "$fname-sectionanchor" );
583 if( $this->section
== 'new' ) {
584 if( $this->summary
!= '' ) {
585 $sectionanchor = $this->sectionAnchor( $this->summary
);
587 } elseif( $this->section
!= '' ) {
588 # Try to get a section anchor from the section source, redirect to edited section if header found
589 # XXX: might be better to integrate this into Article::replaceSection
590 # for duplicate heading checking and maybe parsing
591 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
592 # we can't deal with anchors, includes, html etc in the header for now,
593 # headline would need to be parsed to improve this
594 if($hasmatch and strlen($matches[2]) > 0) {
595 $sectionanchor = $this->sectionAnchor( $matches[2] );
598 wfProfileOut( "$fname-sectionanchor" );
600 // Save errors may fall down to the edit form, but we've now
601 // merged the section into full text. Clear the section field
602 // so that later submission of conflict forms won't try to
603 // replace that into a duplicated mess.
604 $this->textbox1
= $text;
607 # update the article here
608 if( $this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
609 $this->watchthis
, '', $sectionanchor ) ) {
610 wfProfileOut( $fname );
613 $this->isConflict
= true;
615 wfProfileOut( $fname );
620 * Initialise form fields in the object
621 * Called on the first invocation, e.g. when a user clicks an edit link
623 function initialiseForm() {
624 $this->edittime
= $this->mArticle
->getTimestamp();
625 $this->textbox1
= $this->mArticle
->getContent( true );
631 * Send the edit form and related headers to $wgOut
632 * @param $formCallback Optional callable that takes an OutputPage
633 * parameter; will be called during form output
634 * near the top, for captchas and the like.
636 function showEditForm( $formCallback=null ) {
637 global $wgOut, $wgUser, $wgAllowAnonymousMinor, $wgLang, $wgContLang;
639 $fname = 'EditPage::showEditForm';
640 wfProfileIn( $fname );
642 $sk =& $wgUser->getSkin();
644 $wgOut->setRobotpolicy( 'noindex,nofollow' );
646 # Enabled article-related sidebar, toplinks, etc.
647 $wgOut->setArticleRelated( true );
649 if ( $this->isConflict
) {
650 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
651 $wgOut->setPageTitle( $s );
652 $wgOut->addWikiText( wfMsg( 'explainconflict' ) );
654 $this->textbox2
= $this->textbox1
;
655 $this->textbox1
= $this->mArticle
->getContent( true );
656 $this->edittime
= $this->mArticle
->getTimestamp();
659 if( $this->section
!= '' ) {
660 if( $this->section
== 'new' ) {
661 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
663 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
664 if( !$this->preview
&& !$this->diff
) {
665 preg_match( "/^(=+)(.+)\\1/mi",
668 if( !empty( $matches[2] ) ) {
669 $this->summary
= "/* ". trim($matches[2])." */ ";
674 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
676 $wgOut->setPageTitle( $s );
677 if ( !$this->checkUnicodeCompliantBrowser() ) {
678 $this->mArticle
->setOldSubtitle();
679 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
681 if ( isset( $this->mArticle
)
682 && isset( $this->mArticle
->mRevision
)
683 && !$this->mArticle
->mRevision
->isCurrent() ) {
684 $this->mArticle
->setOldSubtitle();
685 $wgOut->addWikiText( wfMsg( 'editingold' ) );
690 $wgOut->addWikiText( wfMsg( 'readonlywarning' ) );
691 } else if ( $this->isCssJsSubpage
and 'preview' != $this->formtype
) {
692 $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ));
694 if( $this->mTitle
->isProtected('edit') ) {
695 $wgOut->addWikiText( wfMsg( 'protectedpagewarning' ) );
698 $kblength = (int)(strlen( $this->textbox1
) / 1024);
699 if( $kblength > 29 ) {
700 $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) ) );
703 $rows = $wgUser->getOption( 'rows' );
704 $cols = $wgUser->getOption( 'cols' );
706 $ew = $wgUser->getOption( 'editwidth' );
707 if ( $ew ) $ew = " style=\"width:100%\"";
710 $q = 'action=submit';
711 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
712 $action = $this->mTitle
->escapeLocalURL( $q );
714 $summary = wfMsg('summary');
715 $subject = wfMsg('subject');
716 $minor = wfMsg('minoredit');
717 $watchthis = wfMsg ('watchthis');
718 $save = wfMsg('savearticle');
719 $prev = wfMsg('showpreview');
720 $diff = wfMsg('showdiff');
722 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
724 $edithelpurl = $sk->makeInternalOrExternalUrl( wfMsg( 'edithelppage' ));
725 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
726 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
727 htmlspecialchars( wfMsg( 'newwindow' ) );
729 global $wgRightsText;
730 $copywarn = "<div id=\"editpage-copywarn\">\n" .
731 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
732 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
733 $wgRightsText ) . "\n</div>";
735 if( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage
) {
736 # prepare toolbar for edit buttons
737 $toolbar = $this->getEditToolbar();
742 // activate checkboxes if user wants them to be always active
743 if( !$this->preview
&& !$this->diff
) {
744 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis
= true;
745 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
747 // activate checkbox also if user is already watching the page,
748 // require wpWatchthis to be unset so that second condition is not
749 // checked unnecessarily
750 if( !$this->watchthis
&& $this->mTitle
->userIsWatching() ) $this->watchthis
= true;
755 if ( $wgUser->isLoggedIn() ||
$wgAllowAnonymousMinor ) {
757 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
758 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
759 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
764 if ( $wgUser->isLoggedIn() ) {
765 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".
766 ($this->watchthis?
" checked='checked'":"").
767 " accesskey=\"".htmlspecialchars(wfMsg('accesskey-watch'))."\" id='wpWatchthis' />".
768 "<label for='wpWatchthis' title=\"" .
769 htmlspecialchars(wfMsg('tooltip-watch'))."\">{$watchthis}</label>";
772 $checkboxhtml = $minoredithtml . $watchhtml;
774 if ( 'preview' == $this->formtype
&& $wgUser->getOption( 'previewontop' ) ) {
775 $this->showPreview();
777 if ( 'diff' == $this->formtype
) {
778 if ( $wgUser->getOption('previewontop' ) ) {
779 $wgOut->addHTML( $this->getDiff() );
784 # if this is a comment, show a subject line at the top, which is also the edit summary.
785 # Otherwise, show a summary field at the bottom
786 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
787 if( $this->section
== 'new' ) {
788 $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 />";
791 $commentsubject = '';
792 $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 />";
795 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
796 if( !$this->preview
&& !$this->diff
) {
797 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
799 $templates = $this->getTemplatesUsed();
801 global $wgLivePreview;
802 if ( $wgLivePreview ) {
803 $liveOnclick = $this->doLivePreviewScript();
808 global $wgUseMetadataEdit ;
809 if ( $wgUseMetadataEdit ) {
810 $metadata = $this->mMetaData
;
811 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
812 $helppage = Title
::newFromText( wfMsg( "metadata_page" ) ) ;
813 $top = wfMsg( 'metadata', $helppage->getInternalURL() );
814 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
816 else $metadata = "" ;
820 if ($this->deletedSinceEdit
) {
821 if ( 'save' != $this->formtype
) {
822 $wgOut->addWikiText( wfMsg('deletedwhileediting'));
824 // Hide the toolbar and edit area, use can click preview to get it back
825 // Add an confirmation checkbox and explanation.
827 $hidden = 'type="hidden" style="display:none;"';
828 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete
->user_name
, $this->lastDelete
->log_comment
));
830 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
831 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
835 $safemodehtml = $this->checkUnicodeCompliantBrowser()
837 : "<input type='hidden' name=\"safemode\" value='1' />\n";
839 $wgOut->addHTML( <<<END
841 <form id="editform" name="editform" method="post" action="$action"
842 enctype="multipart/form-data">
845 if( is_callable( $formCallback ) ) {
846 call_user_func_array( $formCallback, array( &$wgOut ) );
848 $wgOut->addHTML( <<<END
851 <textarea tabindex='1' accesskey="," name="wpTextbox1" id="wpTextbox1" rows='{$rows}'
852 cols='{$cols}'{$ew} $hidden>
854 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1
) ) .
861 <div class='editButtons'>
862 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
863 " title=\"".wfMsg('tooltip-save')."\"/>
864 <input tabindex='6' id='wpPreview' type='submit' $liveOnclick value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
865 " title=\"".wfMsg('tooltip-preview')."\"/>
866 <input tabindex='7' id='wpDiff' type='submit' value=\"{$diff}\" name=\"wpDiff\" accesskey=\"".wfMsg('accesskey-diff')."\"".
867 " title=\"".wfMsg('tooltip-diff')."\"/> <span class='editHelp'>{$cancel} | {$edithelp}</span></div>
869 <div class='templatesUsed'>
873 $wgOut->addWikiText( $copywarn );
875 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
876 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
877 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
878 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
880 if ( $wgUser->isLoggedIn() ) {
882 * To make it harder for someone to slip a user a page
883 * which submits an edit form to the wiki without their
884 * knowledge, a random token is associated with the login
885 * session. If it's not passed back with the submission,
886 * we won't save the page, or render user JavaScript and
889 $token = htmlspecialchars( $wgUser->editToken() );
890 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
894 if ( $this->isConflict
) {
895 require_once( "DifferenceEngine.php" );
896 $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' );
897 DifferenceEngine
::showDiff( $this->textbox2
, $this->textbox1
,
898 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
900 $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
901 $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
902 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2
) ) . "\n</textarea>" );
904 $wgOut->addHTML( "</form>\n" );
905 if ( $this->formtype
== 'preview' && !$wgUser->getOption( 'previewontop' ) ) {
906 $this->showPreview();
908 if ( $this->formtype
== 'diff' && !$wgUser->getOption( 'previewontop' ) ) {
909 #$wgOut->addHTML( '<div id="wikiPreview">' . $difftext . '</div>' );
910 $wgOut->addHTML( $this->getDiff() );
913 wfProfileOut( $fname );
917 * Append preview output to $wgOut.
918 * Includes category rendering if this is a category page.
921 function showPreview() {
923 $wgOut->addHTML( '<div id="wikiPreview">' );
924 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
925 $this->mArticle
->openShowCategory();
927 $previewOutput = $this->getPreviewText();
928 $wgOut->addHTML( $previewOutput );
929 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
930 $this->mArticle
->closeShowCategory();
932 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
933 $wgOut->addHTML( '</div>' );
937 * Prepare a list of templates used by this page. Returns HTML.
939 function getTemplatesUsed() {
942 $fname = 'EditPage::getTemplatesUsed';
943 wfProfileIn( $fname );
945 $sk =& $wgUser->getSkin();
948 $articleTemplates = $this->mArticle
->getUsedTemplates();
949 if ( count( $articleTemplates ) > 0 ) {
950 $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
951 foreach ( $articleTemplates as $tpl ) {
952 if ( $titleObj = Title
::makeTitle( NS_TEMPLATE
, $tpl ) ) {
953 $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
956 $templates .= '</ul>';
958 wfProfileOut( $fname );
963 * Live Preview lets us fetch rendered preview page content and
964 * add it to the page without refreshing the whole page.
965 * If not supported by the browser it will fall through to the normal form
968 * This function outputs a script tag to support live preview, and
969 * returns an onclick handler which should be added to the attributes
970 * of the preview button
972 function doLivePreviewScript() {
973 global $wgStylePath, $wgJsMimeType, $wgOut;
974 $wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' .
975 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
976 '"></script>' . "\n" );
977 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
978 return 'onclick="return !livePreview('.
979 'getElementById(\'wikiPreview\'),' .
980 'editform.wpTextbox1.value,' .
981 htmlspecialchars( '"' . $liveAction . '"' ) . ')"';
984 function getLastDelete() {
985 $dbr =& wfGetDB( DB_SLAVE
);
986 $fname = 'EditPage::getLastDelete';
988 array( 'logging', 'user' ),
998 array( 'log_namespace' => $this->mTitle
->getNamespace(),
999 'log_title' => $this->mTitle
->getDBkey(),
1000 'log_type' => 'delete',
1001 'log_action' => 'delete',
1002 'user_id=log_user' ),
1004 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1006 if($dbr->numRows($res) == 1) {
1007 while ( $x = $dbr->fetchObject ( $res ) )
1009 $dbr->freeResult ( $res ) ;
1019 function getPreviewText() {
1020 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgAllowDiffPreview, $wgEnableDiffPreviewPreference;
1022 $fname = 'EditPage::getPreviewText';
1023 wfProfileIn( $fname );
1025 if ( $this->mTokenOk
) {
1026 $msg = 'previewnote';
1028 $msg = 'session_fail_preview';
1030 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1031 "<div class='previewnote'>" . $wgOut->parse( wfMsg( $msg ) ) . "</div>\n";
1032 if ( $this->isConflict
) {
1033 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1036 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1037 $parserOptions->setEditSection( false );
1039 # don't parse user css/js, show message about preview
1040 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1042 if ( $this->isCssJsSubpage
) {
1043 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
1044 $previewtext = wfMsg('usercsspreview');
1045 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
1046 $previewtext = wfMsg('userjspreview');
1048 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
1049 $wgOut->addHTML( $parserOutput->mText
);
1050 wfProfileOut( $fname );
1051 return $previewhead;
1053 # if user want to see preview when he edit an article
1054 if( $wgUser->getOption('previewonfirst') and ($this->textbox1
== '')) {
1055 $this->textbox1
= $this->mArticle
->getContent(true);
1058 $toparse = $this->textbox1
;
1060 # If we're adding a comment, we need to show the
1061 # summary as the headline
1062 if($this->section
=="new" && $this->summary
!="") {
1063 $toparse="== {$this->summary} ==\n\n".$toparse;
1066 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
1068 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
1069 $wgTitle, $parserOptions );
1071 $previewHTML = $parserOutput->mText
;
1073 $wgOut->addCategoryLinks($parserOutput->getCategoryLinks());
1074 $wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
1076 wfProfileOut( $fname );
1077 return $previewhead . $previewHTML;
1084 function blockedIPpage() {
1085 global $wgOut, $wgUser, $wgContLang;
1087 $wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
1088 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1089 $wgOut->setArticleRelated( false );
1091 $id = $wgUser->blockedBy();
1092 $reason = $wgUser->blockedFor();
1095 if ( is_numeric( $id ) ) {
1096 $name = User
::whoIs( $id );
1100 $link = '[[' . $wgContLang->getNsText( NS_USER
) .
1101 ":{$name}|{$name}]]";
1103 $wgOut->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
1104 $wgOut->returnToMain( false );
1110 function userNotLoggedInPage() {
1113 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1114 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1115 $wgOut->setArticleRelated( false );
1117 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
1118 $wgOut->returnToMain( false );
1124 function spamPage ( $match = false )
1127 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1128 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1129 $wgOut->setArticleRelated( false );
1131 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
1133 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
1135 $wgOut->returnToMain( false );
1142 function mergeChangesInto( &$editText ){
1143 $fname = 'EditPage::mergeChangesInto';
1144 wfProfileIn( $fname );
1146 $db =& wfGetDB( DB_MASTER
);
1148 // This is the revision the editor started from
1149 $baseRevision = Revision
::loadFromTimestamp(
1150 $db, $this->mArticle
->mTitle
, $this->edittime
);
1151 if( is_null( $baseRevision ) ) {
1152 wfProfileOut( $fname );
1155 $baseText = $baseRevision->getText();
1157 // The current state, we want to merge updates into it
1158 $currentRevision = Revision
::loadFromTitle(
1159 $db, $this->mArticle
->mTitle
);
1160 if( is_null( $currentRevision ) ) {
1161 wfProfileOut( $fname );
1164 $currentText = $currentRevision->getText();
1166 if( wfMerge( $baseText, $editText, $currentText, $result ) ){
1167 $editText = $result;
1168 wfProfileOut( $fname );
1171 wfProfileOut( $fname );
1177 * Check if the browser is on a blacklist of user-agents known to
1178 * mangle UTF-8 data on form submission. Returns true if Unicode
1179 * should make it through, false if it's known to be a problem.
1183 function checkUnicodeCompliantBrowser() {
1184 global $wgBrowserBlackList;
1185 if( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1186 // No User-Agent header sent? Trust it by default...
1189 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1190 foreach ( $wgBrowserBlackList as $browser ) {
1191 if ( preg_match($browser, $currentbrowser) ) {
1199 * Format an anchor fragment as it would appear for a given section name
1200 * @param string $text
1204 function sectionAnchor( $text ) {
1205 $headline = Sanitizer
::decodeCharReferences( $text );
1207 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
1208 $headline = trim( $headline );
1209 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
1210 $replacearray = array(
1215 array_keys( $replacearray ),
1216 array_values( $replacearray ),
1221 * Shows a bulletin board style toolbar for common editing functions.
1222 * It can be disabled in the user preferences.
1223 * The necessary JavaScript code can be found in style/wikibits.js.
1225 function getEditToolbar() {
1226 global $wgStylePath, $wgLang, $wgMimeType, $wgJsMimeType;
1229 * toolarray an array of arrays which each include the filename of
1230 * the button image (without path), the opening tag, the closing tag,
1231 * and optionally a sample text that is inserted between the two when no
1232 * selection is highlighted.
1233 * The tip text is shown when the user moves the mouse over the button.
1235 * Already here are accesskeys (key), which are not used yet until someone
1236 * can figure out a way to make them work in IE. However, we should make
1237 * sure these keys are not defined on the edit page.
1240 array( 'image'=>'button_bold.png',
1242 'close' => "\'\'\'",
1243 'sample'=> wfMsg('bold_sample'),
1244 'tip' => wfMsg('bold_tip'),
1247 array( 'image'=>'button_italic.png',
1250 'sample'=> wfMsg('italic_sample'),
1251 'tip' => wfMsg('italic_tip'),
1254 array( 'image'=>'button_link.png',
1257 'sample'=> wfMsg('link_sample'),
1258 'tip' => wfMsg('link_tip'),
1261 array( 'image'=>'button_extlink.png',
1264 'sample'=> wfMsg('extlink_sample'),
1265 'tip' => wfMsg('extlink_tip'),
1268 array( 'image'=>'button_headline.png',
1270 'close' => " ==\\n",
1271 'sample'=> wfMsg('headline_sample'),
1272 'tip' => wfMsg('headline_tip'),
1275 array( 'image'=>'button_image.png',
1276 'open' => '[['.$wgLang->getNsText(NS_IMAGE
).":",
1278 'sample'=> wfMsg('image_sample'),
1279 'tip' => wfMsg('image_tip'),
1282 array( 'image' =>'button_media.png',
1283 'open' => '[['.$wgLang->getNsText(NS_MEDIA
).':',
1285 'sample'=> wfMsg('media_sample'),
1286 'tip' => wfMsg('media_tip'),
1289 array( 'image' =>'button_math.png',
1290 'open' => "\\<math\\>",
1291 'close' => "\\</math\\>",
1292 'sample'=> wfMsg('math_sample'),
1293 'tip' => wfMsg('math_tip'),
1296 array( 'image' =>'button_nowiki.png',
1297 'open' => "\\<nowiki\\>",
1298 'close' => "\\</nowiki\\>",
1299 'sample'=> wfMsg('nowiki_sample'),
1300 'tip' => wfMsg('nowiki_tip'),
1303 array( 'image' =>'button_sig.png',
1307 'tip' => wfMsg('sig_tip'),
1310 array( 'image' =>'button_hr.png',
1311 'open' => "\\n----\\n",
1314 'tip' => wfMsg('hr_tip'),
1318 $toolbar ="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
1320 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
1321 foreach($toolarray as $tool) {
1323 $image=$wgStylePath.'/common/images/'.$tool['image'];
1324 $open=$tool['open'];
1325 $close=$tool['close'];
1326 $sample = wfEscapeJsString( $tool['sample'] );
1328 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1329 // Older browsers show a "speedtip" type message only for ALT.
1330 // Ideally these should be different, realistically they
1331 // probably don't need to be.
1332 $tip = wfEscapeJsString( $tool['tip'] );
1334 #$key = $tool["key"];
1336 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
1339 $toolbar.="document.writeln(\"</div>\");\n";
1340 $toolbar.="/*]]>*/\n</script>";
1345 * Output preview text only. This can be sucked into the edit page
1346 * via JavaScript, and saves the server time rendering the skin as
1347 * well as theoretically being more robust on the client (doesn't
1348 * disturb the edit box's undo history, won't eat your text on
1351 * @todo This doesn't include category or interlanguage links.
1352 * Would need to enhance it a bit, maybe wrap them in XML
1353 * or something... that might also require more skin
1354 * initialization, so check whether that's a problem.
1356 function livePreview() {
1359 header( 'Content-type: text/xml' );
1360 header( 'Cache-control: no-cache' );
1362 echo $this->getPreviewText( false, false );
1367 * Get a diff between the current contents of the edit box and the
1368 * version of the page we're editing from.
1370 * If this is a section edit, we'll replace the section as for final
1371 * save and then make a comparison.
1373 * @return string HTML
1375 function getDiff() {
1378 require_once( 'DifferenceEngine.php' );
1379 $oldtext = $this->mArticle
->fetchContent();
1380 $newtext = $this->mArticle
->replaceSection(
1381 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1382 $oldtitle = wfMsg( 'currentrev' );
1383 $newtitle = wfMsg( 'yourtext' );
1384 if ( $oldtext != wfMsg( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon' ) ||
$newtext != '' ) {
1385 $difftext = DifferenceEngine
::getDiff( $oldtext, $newtext, $oldtitle, $newtitle );
1388 return '<div id="wikiDiff">' . $difftext . '</div>';
1392 * Filter an input field through a Unicode de-armoring process if it
1393 * came from an old browser with known broken Unicode editing issues.
1395 * @param WebRequest $request
1396 * @param string $field
1400 function safeUnicodeInput( $request, $field ) {
1401 $text = rtrim( $request->getText( $field ) );
1402 return $request->getBool( 'safemode' )
1403 ?
$this->unmakesafe( $text )
1408 * Filter an output field through a Unicode armoring process if it is
1409 * going to an old browser with known broken Unicode editing issues.
1411 * @param string $text
1415 function safeUnicodeOutput( $text ) {
1417 $codedText = $wgContLang->recodeForEdit( $text );
1418 return $this->checkUnicodeCompliantBrowser()
1420 : $this->makesafe( $codedText );
1424 * A number of web browsers are known to corrupt non-ASCII characters
1425 * in a UTF-8 text editing environment. To protect against this,
1426 * detected browsers will be served an armored version of the text,
1427 * with non-ASCII chars converted to numeric HTML character references.
1429 * Preexisting such character references will have a 0 added to them
1430 * to ensure that round-trips do not alter the original data.
1432 * @param string $invalue
1436 function makesafe( $invalue ) {
1437 // Armor existing references for reversability.
1438 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
1443 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1444 $bytevalue = ord( $invalue{$i} );
1445 if( $bytevalue <= 0x7F ) { //0xxx xxxx
1446 $result .= chr( $bytevalue );
1448 } elseif( $bytevalue <= 0xBF ) { //10xx xxxx
1449 $working = $working << 6;
1450 $working +
= ($bytevalue & 0x3F);
1452 if( $bytesleft <= 0 ) {
1453 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
1455 } elseif( $bytevalue <= 0xDF ) { //110x xxxx
1456 $working = $bytevalue & 0x1F;
1458 } elseif( $bytevalue <= 0xEF ) { //1110 xxxx
1459 $working = $bytevalue & 0x0F;
1461 } else { //1111 0xxx
1462 $working = $bytevalue & 0x07;
1470 * Reverse the previously applied transliteration of non-ASCII characters
1471 * back to UTF-8. Used to protect data from corruption by broken web browsers
1472 * as listed in $wgBrowserBlackList.
1474 * @param string $invalue
1478 function unmakesafe( $invalue ) {
1480 for( $i = 0; $i < strlen( $invalue ); $i++
) {
1481 if( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+
3} != '0' ) ) {
1485 $hexstring .= $invalue{$i};
1487 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
1489 // Do some sanity checks. These aren't needed for reversability,
1490 // but should help keep the breakage down if the editor
1491 // breaks one of the entities whilst editing.
1492 if ((substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6)) {
1493 $codepoint = hexdec($hexstring);
1494 $result .= codepointToUtf8( $codepoint );
1496 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
1499 $result .= substr( $invalue, $i, 1 );
1502 // reverse the transform that we made for reversability reasons.
1503 return strtr( $result, array( "�" => "&#x" ) );