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
22 var $save = false, $preview = false, $diff = false;
23 var $minoredit = false, $watchthis = false;
24 var $textbox1 = '', $textbox2 = '', $summary = '';
25 var $edittime = '', $section = '';
32 function EditPage( $article ) {
33 $this->mArticle
=& $article;
35 $this->mTitle
=& $wgTitle;
39 * This is the function that extracts metadata from the article body on the first view.
40 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
41 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
43 function extractMetaDataFromArticle () {
44 global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
45 $this->mMetaData
= '' ;
46 if ( !$wgUseMetadataEdit ) return ;
47 if ( $wgMetadataWhitelist == '' ) return ;
49 $t = $this->mArticle
->getContent ( true ) ;
51 # MISSING : <nowiki> filtering
53 # Categories and language links
54 $t = explode ( "\n" , $t ) ;
55 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY
) ) ;
56 $cat = $ll = array() ;
57 foreach ( $t AS $key => $x )
59 $y = trim ( strtolower ( $x ) ) ;
60 while ( substr ( $y , 0 , 2 ) == '[[' )
62 $y = explode ( ']]' , trim ( $x ) ) ;
63 $first = array_shift ( $y ) ;
64 $first = explode ( ':' , $first ) ;
65 $ns = array_shift ( $first ) ;
66 $ns = trim ( str_replace ( '[' , '' , $ns ) ) ;
67 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
69 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]' ;
70 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
72 $x = implode ( ']]' , $y ) ;
74 $y = trim ( strtolower ( $x ) ) ;
78 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n" ;
79 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n" ;
80 $t = implode ( "\n" , $t ) ;
83 $sat = array () ; # stand-alone-templates; must be lowercase
84 $wl_title = Title
::newFromText ( $wgMetadataWhitelist ) ;
85 $wl_article = new Article ( $wl_title ) ;
86 $wl = explode ( "\n" , $wl_article->getContent(true) ) ;
91 while ( substr ( $x , 0 , 1 ) == '*' )
94 $x = trim ( substr ( $x , 1 ) ) ;
98 $sat[] = strtolower ( $x ) ;
103 # Templates, but only some
104 $t = explode ( '{{' , $t ) ;
106 foreach ( $t AS $key => $x )
108 $y = explode ( '}}' , $x , 2 ) ;
109 if ( count ( $y ) == 2 )
112 $z = explode ( '|' , $z ) ;
113 $tn = array_shift ( $z ) ;
114 if ( in_array ( strtolower ( $tn ) , $sat ) )
116 $tl[] = '{{' . $y[0] . '}}' ;
118 $y = explode ( '}}' , $y[1] , 2 ) ;
120 else $t[$key] = '{{' . $x ;
122 else if ( $key != 0 ) $t[$key] = '{{' . $x ;
125 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl ) ;
126 $t = implode ( '' , $t ) ;
128 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
129 $this->mArticle
->mContent
= $t ;
130 $this->mMetaData
= $s ;
134 * This is the function that gets called for "action=edit".
137 global $wgOut, $wgUser, $wgRequest;
138 // this is not an article
139 $wgOut->setArticleFlag(false);
141 $this->importFormData( $wgRequest );
144 $this->livePreview();
148 if ( ! $this->mTitle
->userCanEdit() ) {
149 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ), true );
152 if ( !$this->preview
&& !$this->diff
&& $wgUser->isBlockedFrom( $this->mTitle
, !$this->save
) ) {
153 # When previewing, don't check blocked state - will get caught at save time.
154 # Also, check when starting edition is done against slave to improve performance.
155 $this->blockedIPpage();
158 if ( !$wgUser->isAllowed('edit') ) {
159 if ( $wgUser->isAnon() ) {
160 $this->userNotLoggedInPage();
163 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ), true );
167 if ( wfReadOnly() ) {
168 if( $this->save ||
$this->preview
) {
169 $this->editForm( 'preview' );
170 } else if ( $this->diff
) {
171 $this->editForm( 'diff' );
173 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ) );
178 $this->editForm( 'save' );
179 } else if ( $this->preview
) {
180 $this->editForm( 'preview' );
181 } else if ( $this->diff
) {
182 $this->editForm( 'diff' );
183 } else { # First time through
184 if( $this->previewOnOpen() ) {
185 $this->editForm( 'preview', true );
187 $this->extractMetaDataFromArticle () ;
188 $this->editForm( 'initial', true );
194 * Return true if this page should be previewed when the edit form
195 * is initially opened.
199 function previewOnOpen() {
201 return $wgUser->getOption( 'previewonfirst' ) ||
202 ( $this->mTitle
->getNamespace() == NS_CATEGORY
&&
203 !$this->mTitle
->exists() );
209 function importFormData( &$request ) {
210 if( $request->wasPosted() ) {
211 # These fields need to be checked for encoding.
212 # Also remove trailing whitespace, but don't remove _initial_
213 # whitespace from the text boxes. This may be significant formatting.
214 $this->textbox1
= rtrim( $request->getText( 'wpTextbox1' ) );
215 $this->textbox2
= rtrim( $request->getText( 'wpTextbox2' ) );
216 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
217 $this->summary
= $request->getText( 'wpSummary' );
219 $this->edittime
= $request->getVal( 'wpEdittime' );
220 if( is_null( $this->edittime
) ) {
221 # If the form is incomplete, force to preview.
222 $this->preview
= true;
224 if( $this->tokenOk( $request ) ) {
225 # Some browsers will not report any submit button
226 # if the user hits enter in the comment box.
227 # The unmarked state will be assumed to be a save,
228 # if the form seems otherwise complete.
229 $this->preview
= $request->getCheck( 'wpPreview' );
230 $this->diff
= $request->getCheck( 'wpDiff' );
232 # Page might be a hack attempt posted from
233 # an external site. Preview instead of saving.
234 $this->preview
= true;
237 $this->save
= ! ( $this->preview
OR $this->diff
);
238 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
239 $this->edittime
= null;
242 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
243 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
245 # Not a posted form? Start with nothing.
246 $this->textbox1
= '';
247 $this->textbox2
= '';
248 $this->mMetaData
= '';
250 $this->edittime
= '';
251 $this->preview
= false;
254 $this->minoredit
= false;
255 $this->watchthis
= false;
258 $this->oldid
= $request->getInt( 'oldid' );
260 # Section edit can come from either the form or a link
261 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
263 $this->live
= $request->getCheck( 'live' );
267 * Make sure the form isn't faking a user's credentials.
269 * @param WebRequest $request
273 function tokenOk( &$request ) {
275 if( $wgUser->isAnon() ) {
276 # Anonymous users may not have a session
277 # open. Don't tokenize.
280 return $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
289 * The edit form is self-submitting, so that when things like
290 * preview and edit conflicts occur, we get the same form back
291 * with the extra stuff added. Only when the final submission
292 * is made and all is well do we actually save and redirect to
293 * the newly-edited page.
295 * @param string $formtype Type of form either : save, initial, diff or preview
296 * @param bool $firsttime True to load form data from db
298 function editForm( $formtype, $firsttime = false ) {
299 global $wgOut, $wgUser;
300 global $wgLang, $wgContLang, $wgParser, $wgTitle;
301 global $wgAllowAnonymousMinor, $wgRequest;
302 global $wgSpamRegex, $wgFilterCallback;
304 $sk = $wgUser->getSkin();
306 // css / js subpages of user pages get a special treatment
307 $isCssJsSubpage = $wgTitle->isCssJsSubpage();
309 # If we're creating a discussion page, use the standard comment
311 if(!$wgTitle->exists() && $wgTitle->isTalkPage()) {
312 $this->section
='new';
315 if(!$this->mTitle
->getArticleID()) { # new article
316 $editintro = $wgRequest->getText( 'editintro' );
317 $addstandardintro=true;
319 $introtitle=Title
::newFromText($editintro);
320 if(isset($introtitle) && $introtitle->userCanRead()) {
321 $rev=Revision
::newFromTitle($introtitle);
323 $wgOut->addWikiText($rev->getText());
324 $addstandardintro=false;
328 if($addstandardintro) {
329 $wgOut->addWikiText(wfmsg('newarticletext'));
333 if( $this->mTitle
->isTalkPage() ) {
334 $wgOut->addWikiText(wfmsg('talkpagetext'));
337 # Attempt submission here. This will check for edit conflicts,
338 # and redundantly check for locked database, blocked IPs, etc.
339 # that edit() already checked just in case someone tries to sneak
340 # in the back door with a hand-edited submission URL.
342 if ( 'save' == $formtype ) {
343 # Reintegrate metadata
344 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
345 $this->mMetaData
= '' ;
348 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
349 $this->spamPage ( $matches[0] );
352 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
353 # Error messages or other handling should be performed by the filter function
356 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
357 # Check block state against master, thus 'false'.
358 $this->blockedIPpage();
362 if ( !$wgUser->isAllowed('edit') ) {
363 if ( $wgUser->isAnon() ) {
364 $this->userNotLoggedInPage();
368 $wgOut->readOnlyPage();
373 if ( wfReadOnly() ) {
374 $wgOut->readOnlyPage();
377 if ( $wgUser->pingLimiter() ) {
378 $wgOut->rateLimited();
382 # If article is new, insert it.
383 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
385 # Don't save a new article if it's blank.
386 if ( ( '' == $this->textbox1
) ||
387 ( wfMsg( 'newarticletext' ) == $this->textbox1
) ) {
388 $wgOut->redirect( $this->mTitle
->getFullURL() );
391 if (wfRunHooks('ArticleSave', array(&$this->mArticle
, &$wgUser, &$this->textbox1
,
392 &$this->summary
, &$this->minoredit
, &$this->watchthis
, NULL)))
395 $isComment=($this->section
=='new');
396 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
397 $this->minoredit
, $this->watchthis
, false, $isComment);
398 wfRunHooks('ArticleSaveComplete', array(&$this->mArticle
, &$wgUser, $this->textbox1
,
399 $this->summary
, $this->minoredit
,
400 $this->watchthis
, NULL));
405 # Article exists. Check for edit conflict.
407 $this->mArticle
->clear(); # Force reload of dates, etc.
408 $this->mArticle
->forUpdate( true ); # Lock the article
410 if( ( $this->section
!= 'new' ) &&
411 ($this->mArticle
->getTimestamp() != $this->edittime
) ) {
414 $userid = $wgUser->getID();
417 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
418 $this->mArticle
->getTimestamp() . "'\n" );
419 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
420 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
423 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
424 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
425 $this->section
, $this->textbox1
, $this->summary
);
427 # Suppress edit conflict with self
429 if ( ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
430 wfDebug( "Suppressing edit conflict, same user.\n" );
433 # switch from section editing to normal editing in edit conflict
436 if( $this->mergeChangesInto( $text ) ){
437 // Successful merge! Maybe we should tell the user the good news?
439 wfDebug( "Suppressing edit conflict, successful merge.\n" );
442 $this->textbox1
= $text;
443 wfDebug( "Keeping edit conflict, failed merge.\n" );
447 if ( ! $isConflict ) {
450 if( $this->section
== 'new' ) {
451 if( $this->summary
!= '' ) {
452 $sectionanchor = $this->sectionAnchor( $this->summary
);
454 } elseif( $this->section
!= '' ) {
455 # Try to get a section anchor from the section source, redirect to edited section if header found
456 # XXX: might be better to integrate this into Article::getTextOfLastEditWithSectionReplacedOrAdded
457 # for duplicate heading checking and maybe parsing
458 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
459 # we can't deal with anchors, includes, html etc in the header for now,
460 # headline would need to be parsed to improve this
461 #if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) {
462 if($hasmatch and strlen($matches[2]) > 0) {
463 $sectionanchor = $this->sectionAnchor( $matches[2] );
467 if (wfRunHooks('ArticleSave', array(&$this->mArticle
, &$wgUser, &$text,
468 &$this->summary
, &$this->minoredit
,
469 &$this->watchthis
, &$sectionanchor)))
471 # update the article here
472 if($this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
473 $this->watchthis
, '', $sectionanchor ))
475 wfRunHooks('ArticleSaveComplete', array(&$this->mArticle
, &$wgUser, $text,
476 $this->summary
, $this->minoredit
,
477 $this->watchthis
, $sectionanchor));
485 # First time through: get contents, set time for conflict
488 if ( 'initial' == $formtype ||
$firsttime ) {
489 $this->edittime
= $this->mArticle
->getTimestamp();
490 $this->textbox1
= $this->mArticle
->getContent( true );
494 $wgOut->setRobotpolicy( 'noindex,nofollow' );
496 # Enabled article-related sidebar, toplinks, etc.
497 $wgOut->setArticleRelated( true );
500 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
501 $wgOut->setPageTitle( $s );
502 $wgOut->addWikiText( wfMsg( 'explainconflict' ) );
504 $this->textbox2
= $this->textbox1
;
505 $this->textbox1
= $this->mArticle
->getContent( true );
506 $this->edittime
= $this->mArticle
->getTimestamp();
509 if( $this->section
!= '' ) {
510 if( $this->section
== 'new' ) {
511 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
513 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
514 if( !$this->preview
&& !$this->diff
) {
515 preg_match( "/^(=+)(.+)\\1/mi",
518 if( !empty( $matches[2] ) ) {
519 $this->summary
= "/* ". trim($matches[2])." */ ";
524 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
526 $wgOut->setPageTitle( $s );
527 if ( !$this->checkUnicodeCompliantBrowser() ) {
528 $this->mArticle
->setOldSubtitle();
529 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
531 if ( isset( $this->mArticle
)
532 && isset( $this->mArticle
->mRevision
)
533 && !$this->mArticle
->mRevision
->isCurrent() ) {
534 $this->mArticle
->setOldSubtitle();
535 $wgOut->addWikiText( wfMsg( 'editingold' ) );
540 $wgOut->addWikiText( wfMsg( 'readonlywarning' ) );
541 } else if ( $isCssJsSubpage and 'preview' != $formtype) {
542 $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ));
544 if( $this->mTitle
->isProtected('edit') ) {
545 $wgOut->addWikiText( wfMsg( 'protectedpagewarning' ) );
548 $kblength = (int)(strlen( $this->textbox1
) / 1024);
549 if( $kblength > 29 ) {
550 $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) ) );
553 $rows = $wgUser->getOption( 'rows' );
554 $cols = $wgUser->getOption( 'cols' );
556 $ew = $wgUser->getOption( 'editwidth' );
557 if ( $ew ) $ew = " style=\"width:100%\"";
560 $q = 'action=submit';
561 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
562 $action = $this->mTitle
->escapeLocalURL( $q );
564 $summary = wfMsg('summary');
565 $subject = wfMsg('subject');
566 $minor = wfMsg('minoredit');
567 $watchthis = wfMsg ('watchthis');
568 $save = wfMsg('savearticle');
569 $prev = wfMsg('showpreview');
570 $diff = wfMsg('showdiff');
572 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
574 $edithelpurl = $sk->makeInternalOrExternalUrl( wfMsg( 'edithelppage' ));
575 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
576 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
577 htmlspecialchars( wfMsg( 'newwindow' ) );
579 global $wgRightsText;
580 $copywarn = "<div id=\"editpage-copywarn\">\n" .
581 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
582 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
583 $wgRightsText ) . "\n</div>";
585 if( $wgUser->getOption('showtoolbar') and !$isCssJsSubpage ) {
586 # prepare toolbar for edit buttons
587 $toolbar = $this->getEditToolbar();
592 // activate checkboxes if user wants them to be always active
593 if( !$this->preview
&& !$this->diff
) {
594 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis
= true;
595 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
597 // activate checkbox also if user is already watching the page,
598 // require wpWatchthis to be unset so that second condition is not
599 // checked unnecessarily
600 if( !$this->watchthis
&& $this->mTitle
->userIsWatching() ) $this->watchthis
= true;
605 if ( $wgUser->isLoggedIn() ||
$wgAllowAnonymousMinor ) {
607 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
608 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
609 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
614 if ( $wgUser->isLoggedIn() ) {
615 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".($this->watchthis?
" checked='checked'":"").
616 " accesskey='".wfMsg('accesskey-watch')."' id='wpWatchthis' />".
617 "<label for='wpWatchthis' title='".wfMsg('tooltip-watch')."'>{$watchthis}</label>";
620 $checkboxhtml = $minoredithtml . $watchhtml . '<br />';
622 $wgOut->addHTML( '<div id="wikiPreview">' );
623 if ( 'preview' == $formtype) {
624 $previewOutput = $this->getPreviewText( $isConflict, $isCssJsSubpage );
625 if ( $wgUser->getOption('previewontop' ) ) {
626 $wgOut->addHTML( $previewOutput );
627 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
628 $this->mArticle
->closeShowCategory();
630 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
633 $wgOut->addHTML( '</div>' );
634 if ( 'diff' == $formtype ) {
635 if ( $wgUser->getOption('previewontop' ) ) {
636 $wgOut->addHTML( $this->getDiff() );
641 # if this is a comment, show a subject line at the top, which is also the edit summary.
642 # Otherwise, show a summary field at the bottom
643 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
644 if( $this->section
== 'new' ) {
645 $commentsubject="{$subject}: <input tabindex='1' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
648 $commentsubject = '';
649 $editsummary="{$summary}: <input tabindex='2' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
652 if( !$this->preview
&& !$this->diff
) {
653 # Don't select the edit box on preview; this interferes with seeing what's going on.
654 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
656 # Prepare a list of templates used by this page
658 $articleTemplates = $this->mArticle
->getUsedTemplates();
659 if ( count( $articleTemplates ) > 0 ) {
660 $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
661 foreach ( $articleTemplates as $tpl ) {
662 if ( $titleObj = Title
::makeTitle( NS_TEMPLATE
, $tpl ) ) {
663 $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
666 $templates .= '</ul>';
669 global $wgLivePreview, $wgStylePath;
671 * Live Preview lets us fetch rendered preview page content and
672 * add it to the page without refreshing the whole page.
673 * Set up the button for it; if not supported by the browser
674 * it will fall through to the normal form submission method.
676 if( $wgLivePreview ) {
677 global $wgJsMimeType;
678 $wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' .
679 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
680 '"></script>' . "\n" );
681 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
682 $liveOnclick = 'onclick="return !livePreview('.
683 'getElementById(\'wikiPreview\'),' .
684 'editform.wpTextbox1.value,' .
685 htmlspecialchars( '"' . $liveAction . '"' ) . ')"';
690 global $wgUseMetadataEdit ;
691 if ( $wgUseMetadataEdit )
693 $metadata = $this->mMetaData
;
694 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
695 $helppage = Title
::newFromText ( wfmsg("metadata_page") ) ;
696 $top = str_replace ( "$1" , $helppage->getInternalURL() , wfmsg("metadata") ) ;
697 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
699 else $metadata = "" ;
702 $wgOut->addHTML( <<<END
704 <form id="editform" name="editform" method="post" action="$action"
705 enctype="multipart/form-data">
707 <textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}'
710 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1
) ) .
716 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
717 " title=\"".wfMsg('tooltip-save')."\"/>
718 <input tabindex='6' id='wpPreview' type='submit' $liveOnclick value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
719 " title=\"".wfMsg('tooltip-preview')."\"/>
720 <input tabindex='7' id='wpDiff' type='submit' value=\"{$diff}\" name=\"wpDiff\" accesskey=\"".wfMsg('accesskey-diff')."\"".
721 " title=\"".wfMsg('tooltip-diff')."\"/>
722 <em>{$cancel}</em> | <em>{$edithelp}</em>{$templates}" );
723 $wgOut->addWikiText( $copywarn );
725 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
726 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n" );
728 if ( $wgUser->isLoggedIn() ) {
730 * To make it harder for someone to slip a user a page
731 * which submits an edit form to the wiki without their
732 * knowledge, a random token is associated with the login
733 * session. If it's not passed back with the submission,
734 * we won't save the page, or render user JavaScript and
737 $token = htmlspecialchars( $wgUser->editToken() );
739 <input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
744 require_once( "DifferenceEngine.php" );
745 $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' );
746 DifferenceEngine
::showDiff( $this->textbox2
, $this->textbox1
,
747 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
749 $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
750 $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
751 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox2
) ) .
755 $wgOut->addHTML( "</form>\n" );
756 if ( $formtype == 'preview' && !$wgUser->getOption( 'previewontop' ) ) {
757 $wgOut->addHTML( '<div id="wikiPreview">' . $previewOutput . '</div>' );
759 if ( $formtype == 'diff' && !$wgUser->getOption( 'previewontop' ) ) {
760 #$wgOut->addHTML( '<div id="wikiPreview">' . $difftext . '</div>' );
761 $wgOut->addHTML( $this->getDiff() );
768 function getPreviewText( $isConflict, $isCssJsSubpage ) {
769 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgAllowDiffPreview, $wgEnableDiffPreviewPreference;
770 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
771 "<p class='previewnote'>" . htmlspecialchars( wfMsg( 'previewnote' ) ) . "</p>\n";
773 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) .
777 $parserOptions = ParserOptions
::newFromUser( $wgUser );
778 $parserOptions->setEditSection( false );
780 # don't parse user css/js, show message about preview
781 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
783 if ( $isCssJsSubpage ) {
784 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
785 $previewtext = wfMsg('usercsspreview');
786 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
787 $previewtext = wfMsg('userjspreview');
789 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
790 $wgOut->addHTML( $parserOutput->mText
);
793 # if user want to see preview when he edit an article
794 if( $wgUser->getOption('previewonfirst') and ($this->textbox1
== '')) {
795 $this->textbox1
= $this->mArticle
->getContent(true);
798 $toparse = $this->textbox1
;
800 # If we're adding a comment, we need to show the
801 # summary as the headline
802 if($this->section
=="new" && $this->summary
!="") {
803 $toparse="== {$this->summary} ==\n\n".$toparse;
806 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
808 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
809 $wgTitle, $parserOptions );
811 $previewHTML = $parserOutput->mText
;
813 $wgOut->addCategoryLinks($parserOutput->getCategoryLinks());
814 $wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
815 return $previewhead . $previewHTML;
822 function blockedIPpage() {
823 global $wgOut, $wgUser, $wgContLang, $wgIP;
825 $wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
826 $wgOut->setRobotpolicy( 'noindex,nofollow' );
827 $wgOut->setArticleRelated( false );
829 $id = $wgUser->blockedBy();
830 $reason = $wgUser->blockedFor();
833 if ( is_numeric( $id ) ) {
834 $name = User
::whoIs( $id );
838 $link = '[[' . $wgContLang->getNsText( NS_USER
) .
839 ":{$name}|{$name}]]";
841 $wgOut->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
842 $wgOut->returnToMain( false );
848 function userNotLoggedInPage() {
851 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
852 $wgOut->setRobotpolicy( 'noindex,nofollow' );
853 $wgOut->setArticleRelated( false );
855 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
856 $wgOut->returnToMain( false );
862 function spamPage ( $match = false )
865 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
866 $wgOut->setRobotpolicy( 'noindex,nofollow' );
867 $wgOut->setArticleRelated( false );
869 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
871 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
873 $wgOut->returnToMain( false );
877 * Forks processes to scan the originating IP for an open proxy server
878 * MemCached can be used to skip IPs that have already been scanned
880 function proxyCheck() {
881 global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
882 global $wgIP, $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
884 if ( !$wgBlockOpenProxies ) {
890 if ( $wgUseMemCached ) {
891 $mcKey = $wgDBname.':proxy:ip:'.$wgIP;
892 $mcValue = $wgMemc->get( $mcKey );
900 $title = Title
::makeTitle( NS_SPECIAL
, 'Blockme' );
901 $iphash = md5( $wgIP . $wgProxyKey );
902 $url = $title->getFullURL( 'ip='.$iphash );
904 foreach ( $wgProxyPorts as $port ) {
905 $params = implode( ' ', array(
906 escapeshellarg( $wgProxyScriptPath ),
907 escapeshellarg( $wgIP ),
908 escapeshellarg( $port ),
909 escapeshellarg( $url )
911 exec( "php $params &>/dev/null &" );
914 if ( $wgUseMemCached ) {
915 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
924 function mergeChangesInto( &$editText ){
925 $db =& wfGetDB( DB_MASTER
);
927 // This is the revision the editor started from
928 $baseRevision = Revision
::loadFromTimestamp(
929 $db, $this->mArticle
->mTitle
, $this->edittime
);
930 if( is_null( $baseRevision ) ) {
933 $baseText = $baseRevision->getText();
935 // The current state, we want to merge updates into it
936 $currentRevision = Revision
::loadFromTitle(
937 $db, $this->mArticle
->mTitle
);
938 if( is_null( $currentRevision ) ) {
941 $currentText = $currentRevision->getText();
943 if( wfMerge( $baseText, $editText, $currentText, $result ) ){
952 function checkUnicodeCompliantBrowser() {
953 global $wgBrowserBlackList;
954 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
955 foreach ( $wgBrowserBlackList as $browser ) {
956 if ( preg_match($browser, $currentbrowser) ) {
964 * Format an anchor fragment as it would appear for a given section name
965 * @param string $text
969 function sectionAnchor( $text ) {
970 $headline = Sanitizer
::decodeCharReferences( $text );
972 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
973 $headline = trim( $headline );
974 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
975 $replacearray = array(
980 array_keys( $replacearray ),
981 array_values( $replacearray ),
986 * Shows a bulletin board style toolbar for common editing functions.
987 * It can be disabled in the user preferences.
988 * The necessary JavaScript code can be found in style/wikibits.js.
990 function getEditToolbar() {
991 global $wgStylePath, $wgLang, $wgMimeType, $wgJsMimeType;
994 * toolarray an array of arrays which each include the filename of
995 * the button image (without path), the opening tag, the closing tag,
996 * and optionally a sample text that is inserted between the two when no
997 * selection is highlighted.
998 * The tip text is shown when the user moves the mouse over the button.
1000 * Already here are accesskeys (key), which are not used yet until someone
1001 * can figure out a way to make them work in IE. However, we should make
1002 * sure these keys are not defined on the edit page.
1005 array( 'image'=>'button_bold.png',
1007 'close' => "\'\'\'",
1008 'sample'=> wfMsg('bold_sample'),
1009 'tip' => wfMsg('bold_tip'),
1012 array( 'image'=>'button_italic.png',
1015 'sample'=> wfMsg('italic_sample'),
1016 'tip' => wfMsg('italic_tip'),
1019 array( 'image'=>'button_link.png',
1022 'sample'=> wfMsg('link_sample'),
1023 'tip' => wfMsg('link_tip'),
1026 array( 'image'=>'button_extlink.png',
1029 'sample'=> wfMsg('extlink_sample'),
1030 'tip' => wfMsg('extlink_tip'),
1033 array( 'image'=>'button_headline.png',
1035 'close' => " ==\\n",
1036 'sample'=> wfMsg('headline_sample'),
1037 'tip' => wfMsg('headline_tip'),
1040 array( 'image'=>'button_image.png',
1041 'open' => '[['.$wgLang->getNsText(NS_IMAGE
).":",
1043 'sample'=> wfMsg('image_sample'),
1044 'tip' => wfMsg('image_tip'),
1047 array( 'image' =>'button_media.png',
1048 'open' => '[['.$wgLang->getNsText(NS_MEDIA
).':',
1050 'sample'=> wfMsg('media_sample'),
1051 'tip' => wfMsg('media_tip'),
1054 array( 'image' =>'button_math.png',
1055 'open' => "\\<math\\>",
1056 'close' => "\\</math\\>",
1057 'sample'=> wfMsg('math_sample'),
1058 'tip' => wfMsg('math_tip'),
1061 array( 'image' =>'button_nowiki.png',
1062 'open' => "\\<nowiki\\>",
1063 'close' => "\\</nowiki\\>",
1064 'sample'=> wfMsg('nowiki_sample'),
1065 'tip' => wfMsg('nowiki_tip'),
1068 array( 'image' =>'button_sig.png',
1072 'tip' => wfMsg('sig_tip'),
1075 array( 'image' =>'button_hr.png',
1076 'open' => "\\n----\\n",
1079 'tip' => wfMsg('hr_tip'),
1083 $toolbar ="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
1085 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
1086 foreach($toolarray as $tool) {
1088 $image=$wgStylePath.'/common/images/'.$tool['image'];
1089 $open=$tool['open'];
1090 $close=$tool['close'];
1091 $sample = wfEscapeJsString( $tool['sample'] );
1093 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1094 // Older browsers show a "speedtip" type message only for ALT.
1095 // Ideally these should be different, realistically they
1096 // probably don't need to be.
1097 $tip = wfEscapeJsString( $tool['tip'] );
1099 #$key = $tool["key"];
1101 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
1104 $toolbar.="addInfobox('" . wfEscapeJsString( wfMsg( "infobox" ) ) .
1105 "','" . wfEscapeJsString( wfMsg( "infobox_alert" ) ) . "');\n";
1106 $toolbar.="document.writeln(\"</div>\");\n";
1108 $toolbar.="/*]]>*/\n</script>";
1113 * Output preview text only. This can be sucked into the edit page
1114 * via JavaScript, and saves the server time rendering the skin as
1115 * well as theoretically being more robust on the client (doesn't
1116 * disturb the edit box's undo history, won't eat your text on
1119 * @todo This doesn't include category or interlanguage links.
1120 * Would need to enhance it a bit, maybe wrap them in XML
1121 * or something... that might also require more skin
1122 * initialization, so check whether that's a problem.
1124 function livePreview() {
1127 header( 'Content-type: text/xml' );
1128 header( 'Cache-control: no-cache' );
1130 echo $this->getPreviewText( false, false );
1135 * Get a diff between the current contents of the edit box and the
1136 * version of the page we're editing from.
1138 * If this is a section edit, we'll replace the section as for final
1139 * save and then make a comparison.
1141 * @return string HTML
1143 function getDiff() {
1144 require_once( 'DifferenceEngine.php' );
1145 $oldtext = $this->mArticle
->fetchContent();
1146 $newtext = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
1147 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1148 $oldtitle = wfMsg( 'currentrev' );
1149 $newtitle = wfMsg( 'yourtext' );
1150 if ( $oldtext != wfMsg( 'noarticletext' ) ||
$newtext != '' ) {
1151 $difftext = DifferenceEngine
::getDiff( $oldtext, $newtext, $oldtitle, $newtitle );
1154 return '<div id="wikiDiff">' . $difftext . '</div>';