8c2f3bdf293cb95789f3cedb812253833e3f8b6e
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->isBlocked( !$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( $wgUser->getOption('previewonfirst')
185 or $this->mTitle
->getNamespace() == NS_CATEGORY
) {
186 $this->editForm( 'preview', true );
188 $this->extractMetaDataFromArticle () ;
189 $this->editForm( 'initial', true );
197 function importFormData( &$request ) {
198 if( $request->wasPosted() ) {
199 # These fields need to be checked for encoding.
200 # Also remove trailing whitespace, but don't remove _initial_
201 # whitespace from the text boxes. This may be significant formatting.
202 $this->textbox1
= rtrim( $request->getText( 'wpTextbox1' ) );
203 $this->textbox2
= rtrim( $request->getText( 'wpTextbox2' ) );
204 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
205 $this->summary
= $request->getText( 'wpSummary' );
207 $this->edittime
= $request->getVal( 'wpEdittime' );
208 if( is_null( $this->edittime
) ) {
209 # If the form is incomplete, force to preview.
210 $this->preview
= true;
212 if( $this->tokenOk( $request ) ) {
213 # Some browsers will not report any submit button
214 # if the user hits enter in the comment box.
215 # The unmarked state will be assumed to be a save,
216 # if the form seems otherwise complete.
217 $this->preview
= $request->getCheck( 'wpPreview' );
218 $this->diff
= $request->getCheck( 'wpDiff' );
220 # Page might be a hack attempt posted from
221 # an external site. Preview instead of saving.
222 $this->preview
= true;
225 $this->save
= ! ( $this->preview
OR $this->diff
);
226 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
227 $this->edittime
= null;
230 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
231 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
233 # Not a posted form? Start with nothing.
234 $this->textbox1
= '';
235 $this->textbox2
= '';
236 $this->mMetaData
= '';
238 $this->edittime
= '';
239 $this->preview
= false;
242 $this->minoredit
= false;
243 $this->watchthis
= false;
246 $this->oldid
= $request->getInt( 'oldid' );
248 # Section edit can come from either the form or a link
249 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
251 $this->live
= $request->getCheck( 'live' );
255 * Make sure the form isn't faking a user's credentials.
257 * @param WebRequest $request
261 function tokenOk( &$request ) {
263 if( $wgUser->isAnon() ) {
264 # Anonymous users may not have a session
265 # open. Don't tokenize.
268 return $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
277 * The edit form is self-submitting, so that when things like
278 * preview and edit conflicts occur, we get the same form back
279 * with the extra stuff added. Only when the final submission
280 * is made and all is well do we actually save and redirect to
281 * the newly-edited page.
283 * @param string $formtype Type of form either : save, initial, diff or preview
284 * @param bool $firsttime True to load form data from db
286 function editForm( $formtype, $firsttime = false ) {
287 global $wgOut, $wgUser;
288 global $wgLang, $wgContLang, $wgParser, $wgTitle;
289 global $wgAllowAnonymousMinor;
290 global $wgSpamRegex, $wgFilterCallback;
292 $sk = $wgUser->getSkin();
294 // css / js subpages of user pages get a special treatment
295 $isCssJsSubpage = $wgTitle->isCssJsSubpage();
298 if(!$this->mTitle
->getArticleID()) { # new article
299 $wgOut->addWikiText(wfmsg('newarticletext'));
302 if( $this->mTitle
->isTalkPage() ) {
303 $wgOut->addWikiText(wfmsg('talkpagetext'));
306 # Attempt submission here. This will check for edit conflicts,
307 # and redundantly check for locked database, blocked IPs, etc.
308 # that edit() already checked just in case someone tries to sneak
309 # in the back door with a hand-edited submission URL.
311 if ( 'save' == $formtype ) {
312 # Reintegrate metadata
313 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
314 $this->mMetaData
= '' ;
317 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
318 $this->spamPage ( $matches[0] );
321 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
322 # Error messages or other handling should be performed by the filter function
325 if ( $wgUser->isBlocked( false ) ) {
326 # Check block state against master, thus 'false'.
327 $this->blockedIPpage();
331 if ( !$wgUser->isAllowed('edit') ) {
332 if ( $wgUser->isAnon() ) {
333 $this->userNotLoggedInPage();
337 $wgOut->readOnlyPage();
342 if ( wfReadOnly() ) {
343 $wgOut->readOnlyPage();
346 if ( $wgUser->pingLimiter() ) {
347 $wgOut->rateLimited();
351 # If article is new, insert it.
352 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
354 # Don't save a new article if it's blank.
355 if ( ( '' == $this->textbox1
) ||
356 ( wfMsg( 'newarticletext' ) == $this->textbox1
) ) {
357 $wgOut->redirect( $this->mTitle
->getFullURL() );
360 if (wfRunHooks('ArticleSave', array(&$this->mArticle
, &$wgUser, &$this->textbox1
,
361 &$this->summary
, &$this->minoredit
, &$this->watchthis
, NULL)))
363 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
364 $this->minoredit
, $this->watchthis
);
365 wfRunHooks('ArticleSaveComplete', array(&$this->mArticle
, &$wgUser, $this->textbox1
,
366 $this->summary
, $this->minoredit
,
367 $this->watchthis
, NULL));
372 # Article exists. Check for edit conflict.
374 $this->mArticle
->clear(); # Force reload of dates, etc.
375 $this->mArticle
->forUpdate( true ); # Lock the article
377 if( ( $this->section
!= 'new' ) &&
378 ($this->mArticle
->getTimestamp() != $this->edittime
) ) {
381 $userid = $wgUser->getID();
384 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
385 $this->mArticle
->getTimestamp() . "'\n" );
386 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
387 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
390 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
391 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
392 $this->section
, $this->textbox1
, $this->summary
);
394 # Suppress edit conflict with self
396 if ( ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
397 wfDebug( "Suppressing edit conflict, same user.\n" );
400 # switch from section editing to normal editing in edit conflict
403 if( $this->mergeChangesInto( $text ) ){
404 // Successful merge! Maybe we should tell the user the good news?
406 wfDebug( "Suppressing edit conflict, successful merge.\n" );
409 $this->textbox1
= $text;
410 wfDebug( "Keeping edit conflict, failed merge.\n" );
414 if ( ! $isConflict ) {
417 if( $this->section
== 'new' ) {
418 if( $this->summary
!= '' ) {
419 $sectionanchor = $this->sectionAnchor( $this->summary
);
421 } elseif( $this->section
!= '' ) {
422 # Try to get a section anchor from the section source, redirect to edited section if header found
423 # XXX: might be better to integrate this into Article::getTextOfLastEditWithSectionReplacedOrAdded
424 # for duplicate heading checking and maybe parsing
425 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
426 # we can't deal with anchors, includes, html etc in the header for now,
427 # headline would need to be parsed to improve this
428 #if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) {
429 if($hasmatch and strlen($matches[2]) > 0) {
430 $sectionanchor = $this->sectionAnchor( $matches[2] );
434 if (wfRunHooks('ArticleSave', array(&$this->mArticle
, &$wgUser, &$text,
435 &$this->summary
, &$this->minoredit
,
436 &$this->watchthis
, &$sectionanchor)))
438 # update the article here
439 if($this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
440 $this->watchthis
, '', $sectionanchor ))
442 wfRunHooks('ArticleSaveComplete', array(&$this->mArticle
, &$wgUser, $text,
443 $this->summary
, $this->minoredit
,
444 $this->watchthis
, $sectionanchor));
452 # First time through: get contents, set time for conflict
455 if ( 'initial' == $formtype ||
$firsttime ) {
456 $this->edittime
= $this->mArticle
->getTimestamp();
457 $this->textbox1
= $this->mArticle
->getContent( true );
461 $wgOut->setRobotpolicy( 'noindex,nofollow' );
463 # Enabled article-related sidebar, toplinks, etc.
464 $wgOut->setArticleRelated( true );
467 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
468 $wgOut->setPageTitle( $s );
469 $wgOut->addWikiText( wfMsg( 'explainconflict' ) );
471 $this->textbox2
= $this->textbox1
;
472 $this->textbox1
= $this->mArticle
->getContent( true );
473 $this->edittime
= $this->mArticle
->getTimestamp();
476 if( $this->section
!= '' ) {
477 if( $this->section
== 'new' ) {
478 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
480 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
482 if(!$this->preview
) {
483 preg_match( "/^(=+)(.+)\\1/mi",
486 if( !empty( $matches[2] ) ) {
487 $this->summary
= "/* ". trim($matches[2])." */ ";
491 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
493 $wgOut->setPageTitle( $s );
494 if ( !$this->checkUnicodeCompliantBrowser() ) {
495 $this->mArticle
->setOldSubtitle();
496 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
498 if ( isset( $this->mArticle
)
499 && isset( $this->mArticle
->mRevision
)
500 && !$this->mArticle
->mRevision
->isCurrent() ) {
501 $this->mArticle
->setOldSubtitle();
502 $wgOut->addWikiText( wfMsg( 'editingold' ) );
507 $wgOut->addWikiText( wfMsg( 'readonlywarning' ) );
508 } else if ( $isCssJsSubpage and 'preview' != $formtype) {
509 $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ));
511 if( $this->mTitle
->isProtected('edit') ) {
512 $wgOut->addWikiText( wfMsg( 'protectedpagewarning' ) );
515 $kblength = (int)(strlen( $this->textbox1
) / 1024);
516 if( $kblength > 29 ) {
517 $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) ) );
520 $rows = $wgUser->getOption( 'rows' );
521 $cols = $wgUser->getOption( 'cols' );
523 $ew = $wgUser->getOption( 'editwidth' );
524 if ( $ew ) $ew = " style=\"width:100%\"";
527 $q = 'action=submit';
528 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
529 $action = $this->mTitle
->escapeLocalURL( $q );
531 $summary = wfMsg('summary');
532 $subject = wfMsg('subject');
533 $minor = wfMsg('minoredit');
534 $watchthis = wfMsg ('watchthis');
535 $save = wfMsg('savearticle');
536 $prev = wfMsg('showpreview');
537 $diff = wfMsg('showdiff');
539 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
541 $edithelpurl = $sk->makeInternalOrExternalUrl( wfMsg( 'edithelppage' ));
542 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
543 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
544 htmlspecialchars( wfMsg( 'newwindow' ) );
546 global $wgRightsText;
547 $copywarn = "<div id=\"editpage-copywarn\">\n" .
548 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
549 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
550 $wgRightsText ) . "\n</div>";
552 if( $wgUser->getOption('showtoolbar') and !$isCssJsSubpage ) {
553 # prepare toolbar for edit buttons
554 $toolbar = $this->getEditToolbar();
559 // activate checkboxes if user wants them to be always active
560 if( !$this->preview
&& !$this->diff
) {
561 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis
= true;
562 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
564 // activate checkbox also if user is already watching the page,
565 // require wpWatchthis to be unset so that second condition is not
566 // checked unnecessarily
567 if( !$this->watchthis
&& $this->mTitle
->userIsWatching() ) $this->watchthis
= true;
572 if ( $wgUser->isLoggedIn() ||
$wgAllowAnonymousMinor ) {
574 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
575 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
576 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
581 if ( $wgUser->isLoggedIn() ) {
582 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".($this->watchthis?
" checked='checked'":"").
583 " accesskey='".wfMsg('accesskey-watch')."' id='wpWatchthis' />".
584 "<label for='wpWatchthis' title='".wfMsg('tooltip-watch')."'>{$watchthis}</label>";
587 $checkboxhtml = $minoredithtml . $watchhtml . '<br />';
589 $wgOut->addHTML( '<div id="wikiPreview">' );
590 if ( 'preview' == $formtype) {
591 $previewOutput = $this->getPreviewText( $isConflict, $isCssJsSubpage );
592 if ( $wgUser->getOption('previewontop' ) ) {
593 $wgOut->addHTML( $previewOutput );
594 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
595 $this->mArticle
->closeShowCategory();
597 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
600 $wgOut->addHTML( '</div>' );
601 if ( 'diff' == $formtype ) {
602 if ( $wgUser->getOption('previewontop' ) ) {
603 $wgOut->addHTML( $this->getDiff() );
608 # if this is a comment, show a subject line at the top, which is also the edit summary.
609 # Otherwise, show a summary field at the bottom
610 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
611 if( $this->section
== 'new' ) {
612 $commentsubject="{$subject}: <input tabindex='1' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
615 $commentsubject = '';
616 $editsummary="{$summary}: <input tabindex='2' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
619 if( !$this->preview
&& !$this->diff
) {
620 # Don't select the edit box on preview; this interferes with seeing what's going on.
621 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
623 # Prepare a list of templates used by this page
625 $articleTemplates = $this->mArticle
->getUsedTemplates();
626 if ( count( $articleTemplates ) > 0 ) {
627 $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
628 foreach ( $articleTemplates as $tpl ) {
629 if ( $titleObj = Title
::makeTitle( NS_TEMPLATE
, $tpl ) ) {
630 $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
633 $templates .= '</ul>';
636 global $wgLivePreview, $wgStylePath;
638 * Live Preview lets us fetch rendered preview page content and
639 * add it to the page without refreshing the whole page.
640 * Set up the button for it; if not supported by the browser
641 * it will fall through to the normal form submission method.
643 if( $wgLivePreview ) {
644 global $wgJsMimeType;
645 $wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' .
646 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
647 '"></script>' . "\n" );
648 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
649 $liveOnclick = 'onclick="return !livePreview('.
650 'getElementById(\'wikiPreview\'),' .
651 'editform.wpTextbox1.value,' .
652 htmlspecialchars( '"' . $liveAction . '"' ) . ')"';
657 global $wgUseMetadataEdit ;
658 if ( $wgUseMetadataEdit )
660 $metadata = $this->mMetaData
;
661 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
662 $helppage = Title
::newFromText ( wfmsg("metadata_page") ) ;
663 $top = str_replace ( "$1" , $helppage->getInternalURL() , wfmsg("metadata") ) ;
664 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
666 else $metadata = "" ;
669 $wgOut->addHTML( <<<END
671 <form id="editform" name="editform" method="post" action="$action"
672 enctype="multipart/form-data">
674 <textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}'
677 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1
) ) .
683 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
684 " title=\"".wfMsg('tooltip-save')."\"/>
685 <input tabindex='6' id='wpPreview' type='submit' $liveOnclick value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
686 " title=\"".wfMsg('tooltip-preview')."\"/>
687 <input tabindex='7' id='wpDiff' type='submit' value=\"{$diff}\" name=\"wpDiff\" accesskey=\"".wfMsg('accesskey-diff')."\"".
688 " title=\"".wfMsg('tooltip-diff')."\"/>
689 <em>{$cancel}</em> | <em>{$edithelp}</em>{$templates}" );
690 $wgOut->addWikiText( $copywarn );
692 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
693 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n" );
695 if ( $wgUser->isLoggedIn() ) {
697 * To make it harder for someone to slip a user a page
698 * which submits an edit form to the wiki without their
699 * knowledge, a random token is associated with the login
700 * session. If it's not passed back with the submission,
701 * we won't save the page, or render user JavaScript and
704 $token = htmlspecialchars( $wgUser->editToken() );
706 <input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
711 require_once( "DifferenceEngine.php" );
712 $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' );
713 DifferenceEngine
::showDiff( $this->textbox2
, $this->textbox1
,
714 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
716 $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
717 $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
718 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox2
) ) .
722 $wgOut->addHTML( "</form>\n" );
723 if ( $formtype == 'preview' && !$wgUser->getOption( 'previewontop' ) ) {
724 $wgOut->addHTML( '<div id="wikiPreview">' . $previewOutput . '</div>' );
726 if ( $formtype == 'diff' && !$wgUser->getOption( 'previewontop' ) ) {
727 #$wgOut->addHTML( '<div id="wikiPreview">' . $difftext . '</div>' );
728 $wgOut->addHTML( $this->getDiff() );
735 function getPreviewText( $isConflict, $isCssJsSubpage ) {
736 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgAllowDiffPreview, $wgEnableDiffPreviewPreference;
737 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
738 "<p class='previewnote'>" . htmlspecialchars( wfMsg( 'previewnote' ) ) . "</p>\n";
740 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) .
744 $parserOptions = ParserOptions
::newFromUser( $wgUser );
745 $parserOptions->setEditSection( false );
747 # don't parse user css/js, show message about preview
748 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
750 if ( $isCssJsSubpage ) {
751 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
752 $previewtext = wfMsg('usercsspreview');
753 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
754 $previewtext = wfMsg('userjspreview');
756 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
757 $wgOut->addHTML( $parserOutput->mText
);
760 # if user want to see preview when he edit an article
761 if( $wgUser->getOption('previewonfirst') and ($this->textbox1
== '')) {
762 $this->textbox1
= $this->mArticle
->getContent(true);
765 $toparse = $this->textbox1
;
766 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
768 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
769 $wgTitle, $parserOptions );
771 $previewHTML = $parserOutput->mText
;
773 $wgOut->addCategoryLinks($parserOutput->getCategoryLinks());
774 $wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
775 return $previewhead . $previewHTML;
782 function blockedIPpage() {
783 global $wgOut, $wgUser, $wgContLang, $wgIP;
785 $wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
786 $wgOut->setRobotpolicy( 'noindex,nofollow' );
787 $wgOut->setArticleRelated( false );
789 $id = $wgUser->blockedBy();
790 $reason = $wgUser->blockedFor();
793 if ( is_numeric( $id ) ) {
794 $name = User
::whoIs( $id );
798 $link = '[[' . $wgContLang->getNsText( NS_USER
) .
799 ":{$name}|{$name}]]";
801 $wgOut->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
802 $wgOut->returnToMain( false );
808 function userNotLoggedInPage() {
811 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
812 $wgOut->setRobotpolicy( 'noindex,nofollow' );
813 $wgOut->setArticleRelated( false );
815 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
816 $wgOut->returnToMain( false );
822 function spamPage ( $match = false )
825 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
826 $wgOut->setRobotpolicy( 'noindex,nofollow' );
827 $wgOut->setArticleRelated( false );
829 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
831 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
833 $wgOut->returnToMain( false );
837 * Forks processes to scan the originating IP for an open proxy server
838 * MemCached can be used to skip IPs that have already been scanned
840 function proxyCheck() {
841 global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
842 global $wgIP, $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
844 if ( !$wgBlockOpenProxies ) {
850 if ( $wgUseMemCached ) {
851 $mcKey = $wgDBname.':proxy:ip:'.$wgIP;
852 $mcValue = $wgMemc->get( $mcKey );
860 $title = Title
::makeTitle( NS_SPECIAL
, 'Blockme' );
861 $iphash = md5( $wgIP . $wgProxyKey );
862 $url = $title->getFullURL( 'ip='.$iphash );
864 foreach ( $wgProxyPorts as $port ) {
865 $params = implode( ' ', array(
866 escapeshellarg( $wgProxyScriptPath ),
867 escapeshellarg( $wgIP ),
868 escapeshellarg( $port ),
869 escapeshellarg( $url )
871 exec( "php $params &>/dev/null &" );
874 if ( $wgUseMemCached ) {
875 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
884 function mergeChangesInto( &$editText ){
885 $db =& wfGetDB( DB_MASTER
);
887 // This is the revision the editor started from
888 $baseRevision = Revision
::loadFromTimestamp(
889 $db, $this->mArticle
->mTitle
, $this->edittime
);
890 if( is_null( $baseRevision ) ) {
893 $baseText = $baseRevision->getText();
895 // The current state, we want to merge updates into it
896 $currentRevision = Revision
::loadFromTitle(
897 $db, $this->mArticle
->mTitle
);
898 if( is_null( $currentRevision ) ) {
901 $currentText = $currentRevision->getText();
903 if( wfMerge( $baseText, $editText, $currentText, $result ) ){
912 function checkUnicodeCompliantBrowser() {
913 global $wgBrowserBlackList;
914 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
915 foreach ( $wgBrowserBlackList as $browser ) {
916 if ( preg_match($browser, $currentbrowser) ) {
924 * Format an anchor fragment as it would appear for a given section name
925 * @param string $text
929 function sectionAnchor( $text ) {
930 $headline = Sanitizer
::decodeCharReferences( $text );
932 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
933 $headline = trim( $headline );
934 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
935 $replacearray = array(
940 array_keys( $replacearray ),
941 array_values( $replacearray ),
946 * Shows a bulletin board style toolbar for common editing functions.
947 * It can be disabled in the user preferences.
948 * The necessary JavaScript code can be found in style/wikibits.js.
950 function getEditToolbar() {
951 global $wgStylePath, $wgLang, $wgMimeType, $wgJsMimeType;
954 * toolarray an array of arrays which each include the filename of
955 * the button image (without path), the opening tag, the closing tag,
956 * and optionally a sample text that is inserted between the two when no
957 * selection is highlighted.
958 * The tip text is shown when the user moves the mouse over the button.
960 * Already here are accesskeys (key), which are not used yet until someone
961 * can figure out a way to make them work in IE. However, we should make
962 * sure these keys are not defined on the edit page.
965 array( 'image'=>'button_bold.png',
968 'sample'=> wfMsg('bold_sample'),
969 'tip' => wfMsg('bold_tip'),
972 array( 'image'=>'button_italic.png',
975 'sample'=> wfMsg('italic_sample'),
976 'tip' => wfMsg('italic_tip'),
979 array( 'image'=>'button_link.png',
982 'sample'=> wfMsg('link_sample'),
983 'tip' => wfMsg('link_tip'),
986 array( 'image'=>'button_extlink.png',
989 'sample'=> wfMsg('extlink_sample'),
990 'tip' => wfMsg('extlink_tip'),
993 array( 'image'=>'button_headline.png',
996 'sample'=> wfMsg('headline_sample'),
997 'tip' => wfMsg('headline_tip'),
1000 array( 'image'=>'button_image.png',
1001 'open' => '[['.$wgLang->getNsText(NS_IMAGE
).":",
1003 'sample'=> wfMsg('image_sample'),
1004 'tip' => wfMsg('image_tip'),
1007 array( 'image' =>'button_media.png',
1008 'open' => '[['.$wgLang->getNsText(NS_MEDIA
).':',
1010 'sample'=> wfMsg('media_sample'),
1011 'tip' => wfMsg('media_tip'),
1014 array( 'image' =>'button_math.png',
1015 'open' => "\\<math\\>",
1016 'close' => "\\</math\\>",
1017 'sample'=> wfMsg('math_sample'),
1018 'tip' => wfMsg('math_tip'),
1021 array( 'image' =>'button_nowiki.png',
1022 'open' => "\\<nowiki\\>",
1023 'close' => "\\</nowiki\\>",
1024 'sample'=> wfMsg('nowiki_sample'),
1025 'tip' => wfMsg('nowiki_tip'),
1028 array( 'image' =>'button_sig.png',
1032 'tip' => wfMsg('sig_tip'),
1035 array( 'image' =>'button_hr.png',
1036 'open' => "\\n----\\n",
1039 'tip' => wfMsg('hr_tip'),
1043 $toolbar ="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
1045 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
1046 foreach($toolarray as $tool) {
1048 $image=$wgStylePath.'/common/images/'.$tool['image'];
1049 $open=$tool['open'];
1050 $close=$tool['close'];
1051 $sample = wfEscapeJsString( $tool['sample'] );
1053 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1054 // Older browsers show a "speedtip" type message only for ALT.
1055 // Ideally these should be different, realistically they
1056 // probably don't need to be.
1057 $tip = wfEscapeJsString( $tool['tip'] );
1059 #$key = $tool["key"];
1061 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
1064 $toolbar.="addInfobox('" . wfEscapeJsString( wfMsg( "infobox" ) ) .
1065 "','" . wfEscapeJsString( wfMsg( "infobox_alert" ) ) . "');\n";
1066 $toolbar.="document.writeln(\"</div>\");\n";
1068 $toolbar.="/*]]>*/\n</script>";
1073 * Output preview text only. This can be sucked into the edit page
1074 * via JavaScript, and saves the server time rendering the skin as
1075 * well as theoretically being more robust on the client (doesn't
1076 * disturb the edit box's undo history, won't eat your text on
1079 * @todo This doesn't include category or interlanguage links.
1080 * Would need to enhance it a bit, maybe wrap them in XML
1081 * or something... that might also require more skin
1082 * initialization, so check whether that's a problem.
1084 function livePreview() {
1087 header( 'Content-type: text/xml' );
1088 header( 'Cache-control: no-cache' );
1090 echo $this->getPreviewText( false, false );
1095 * Get a diff between the current contents of the edit box and the
1096 * version of the page we're editing from.
1098 * If this is a section edit, we'll replace the section as for final
1099 * save and then make a comparison.
1101 * @return string HTML
1103 function getDiff() {
1104 require_once( 'DifferenceEngine.php' );
1105 $oldtext = $this->mArticle
->fetchContent();
1106 $newtext = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
1107 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1108 $oldtitle = wfMsg( 'currentrev' );
1109 $newtitle = wfMsg( 'yourtext' );
1110 if ( $oldtext != wfMsg( 'noarticletext' ) ||
$newtext != '' ) {
1111 $difftext = DifferenceEngine
::getDiff( $oldtext, $newtext, $oldtitle, $newtitle );
1114 return '<div id="wikiDiff">' . $difftext . '</div>';