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;
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 ()
45 global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
46 $this->mMetaData
= "" ;
47 if ( !$wgUseMetadataEdit ) return ;
48 if ( $wgMetadataWhitelist == "" ) return ;
50 $t = $this->mArticle
->getContent ( true ) ;
52 # MISSING : <nowiki> filtering
54 # Categories and language links
55 $t = explode ( "\n" , $t ) ;
56 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY
) ) ;
57 $cat = $ll = array() ;
58 foreach ( $t AS $key => $x )
60 $y = trim ( strtolower ( $x ) ) ;
61 while ( substr ( $y , 0 , 2 ) == "[[" )
63 $y = explode ( "]]" , trim ( $x ) ) ;
64 $first = array_shift ( $y ) ;
65 $first = explode ( ":" , $first ) ;
66 $ns = array_shift ( $first ) ;
67 $ns = trim ( str_replace ( "[" , "" , $ns ) ) ;
68 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
70 $add = "[[" . $ns . ":" . implode ( ":" , $first ) . "]]" ;
71 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
73 $x = implode ( "]]" , $y ) ;
75 $y = trim ( strtolower ( $x ) ) ;
79 if ( count ( $cat ) ) $s .= implode ( " " , $cat ) . "\n" ;
80 if ( count ( $ll ) ) $s .= implode ( " " , $ll ) . "\n" ;
81 $t = implode ( "\n" , $t ) ;
84 $sat = array () ; # stand-alone-templates; must be lowercase
85 $wl_title = Title
::newFromText ( $wgMetadataWhitelist ) ;
86 $wl_article = new Article ( $wl_title ) ;
87 $wl = explode ( "\n" , $wl_article->getContent(true) ) ;
92 while ( substr ( $x , 0 , 1 ) == "*" )
95 $x = trim ( substr ( $x , 1 ) ) ;
99 $sat[] = strtolower ( $x ) ;
104 # Templates, but only some
105 $t = explode ( "{{" , $t ) ;
107 foreach ( $t AS $key => $x )
109 $y = explode ( "}}" , $x , 2 ) ;
110 if ( count ( $y ) == 2 )
113 $z = explode ( "|" , $z ) ;
114 $tn = array_shift ( $z ) ;
115 if ( in_array ( strtolower ( $tn ) , $sat ) )
117 $tl[] = "{{" . $y[0] . "}}" ;
119 $y = explode ( "}}" , $y[1] , 2 ) ;
121 else $t[$key] = "{{" . $x ;
123 else if ( $key != 0 ) $t[$key] = "{{" . $x ;
126 if ( count ( $tl ) ) $s .= implode ( " " , $tl ) ;
127 $t = implode ( "" , $t ) ;
129 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
130 $this->mArticle
->mContent
= $t ;
131 $this->mMetaData
= $s ;
135 * This is the function that gets called for "action=edit".
138 global $wgOut, $wgUser, $wgWhitelistEdit, $wgRequest;
139 // this is not an article
140 $wgOut->setArticleFlag(false);
142 $this->importFormData( $wgRequest );
145 $this->livePreview();
149 if ( ! $this->mTitle
->userCanEdit() ) {
150 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ), true );
153 if ( !$this->preview
&& $wgUser->isBlocked( !$this->save
) ) {
154 # When previewing, don't check blocked state - will get caught at save time.
155 # Also, check when starting edition is done against slave to improve performance.
156 $this->blockedIPpage();
159 if ( $wgUser->isAnon() && $wgWhitelistEdit ) {
160 $this->userNotLoggedInPage();
163 if ( wfReadOnly() ) {
164 if( $this->save ||
$this->preview
) {
165 $this->editForm( 'preview' );
167 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ) );
172 $this->editForm( 'save' );
173 } else if ( $this->preview
) {
174 $this->editForm( 'preview' );
175 } else { # First time through
176 if( $wgUser->getOption('previewonfirst') ) {
177 $this->editForm( 'preview', true );
179 $this->extractMetaDataFromArticle () ;
180 $this->editForm( 'initial', true );
188 function importFormData( &$request ) {
189 if( $request->wasPosted() ) {
190 # These fields need to be checked for encoding.
191 # Also remove trailing whitespace, but don't remove _initial_
192 # whitespace from the text boxes. This may be significant formatting.
193 $this->textbox1
= rtrim( $request->getText( 'wpTextbox1' ) );
194 $this->textbox2
= rtrim( $request->getText( 'wpTextbox2' ) );
195 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
196 $this->summary
= trim( $request->getText( 'wpSummary' ) );
198 $this->edittime
= $request->getVal( 'wpEdittime' );
199 if( is_null( $this->edittime
) ) {
200 # If the form is incomplete, force to preview.
201 $this->preview
= true;
203 if( $this->tokenOk( $request ) ) {
204 # Some browsers will not report any submit button
205 # if the user hits enter in the comment box.
206 # The unmarked state will be assumed to be a save,
207 # if the form seems otherwise complete.
208 $this->preview
= $request->getCheck( 'wpPreview' );
210 # Page might be a hack attempt posted from
211 # an external site. Preview instead of saving.
212 $this->preview
= true;
215 $this->save
= !$this->preview
;
216 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
217 $this->edittime
= null;
220 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
221 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
223 # Not a posted form? Start with nothing.
224 $this->textbox1
= '';
225 $this->textbox2
= '';
226 $this->mMetaData
= '';
228 $this->edittime
= '';
229 $this->preview
= false;
231 $this->minoredit
= false;
232 $this->watchthis
= false;
235 $this->oldid
= $request->getInt( 'oldid' );
237 # Section edit can come from either the form or a link
238 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
240 $this->live
= $request->getCheck( 'live' );
244 * Make sure the form isn't faking a user's credentials.
246 * @param WebRequest $request
250 function tokenOk( &$request ) {
252 if( $wgUser->isAnon() ) {
253 # Anonymous users may not have a session
254 # open. Don't tokenize.
257 return $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
266 * The edit form is self-submitting, so that when things like
267 * preview and edit conflicts occur, we get the same form back
268 * with the extra stuff added. Only when the final submission
269 * is made and all is well do we actually save and redirect to
270 * the newly-edited page.
272 * @param string $formtype Type of form either : save, initial or preview
273 * @param bool $firsttime True to load form data from db
275 function editForm( $formtype, $firsttime = false ) {
276 global $wgOut, $wgUser;
277 global $wgLang, $wgContLang, $wgParser, $wgTitle;
278 global $wgAllowAnonymousMinor;
279 global $wgWhitelistEdit;
280 global $wgSpamRegex, $wgFilterCallback;
283 $sk = $wgUser->getSkin();
285 // css / js subpages of user pages get a special treatment
286 $isCssJsSubpage = $wgTitle->isCssJsSubpage();
289 if(!$this->mTitle
->getArticleID()) { # new article
290 $wgOut->addWikiText(wfmsg('newarticletext'));
293 if( $this->mTitle
->isTalkPage() ) {
294 $wgOut->addWikiText(wfmsg('talkpagetext'));
297 # Attempt submission here. This will check for edit conflicts,
298 # and redundantly check for locked database, blocked IPs, etc.
299 # that edit() already checked just in case someone tries to sneak
300 # in the back door with a hand-edited submission URL.
302 if ( 'save' == $formtype ) {
303 # Reintegrate metadata
304 if ( $this->mMetaData
!= "" ) $this->textbox1
.= "\n" . $this->mMetaData
;
305 $this->mMetaData
= "" ;
308 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
309 $this->spamPage ( $matches[0] );
312 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
313 # Error messages or other handling should be performed by the filter function
316 if ( $wgUser->isBlocked( false ) ) {
317 # Check block state against master, thus 'false'.
318 $this->blockedIPpage();
321 if ( $wgUser->isAnon() && $wgWhitelistEdit ) {
322 $this->userNotLoggedInPage();
325 if ( wfReadOnly() ) {
326 $wgOut->readOnlyPage();
330 # If article is new, insert it.
331 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
333 # Don't save a new article if it's blank.
334 if ( ( '' == $this->textbox1
) ||
335 ( wfMsg( 'newarticletext' ) == $this->textbox1
) ) {
336 $wgOut->redirect( $this->mTitle
->getFullURL() );
339 if (wfRunHooks('ArticleSave', $this->mArticle
, $wgUser, $this->textbox1
,
340 $this->summary
, $this->minoredit
, $this->watchthis
, NULL))
342 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
343 $this->minoredit
, $this->watchthis
);
344 wfRunHooks('ArticleSaveComplete', $this->mArticle
, $wgUser, $this->textbox1
,
345 $this->summary
, $this->minoredit
, $this->watchthis
, NULL);
350 # Article exists. Check for edit conflict.
352 $this->mArticle
->clear(); # Force reload of dates, etc.
353 $this->mArticle
->forUpdate( true ); # Lock the article
355 if( ( $this->section
!= 'new' ) &&
356 ($this->mArticle
->getTimestamp() != $this->edittime
) ) {
359 $userid = $wgUser->getID();
362 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
363 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
366 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
367 $this->section
, $this->textbox1
, $this->summary
);
369 # Suppress edit conflict with self
371 if ( ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
374 # switch from section editing to normal editing in edit conflict
377 if( $this->mergeChangesInto( $text ) ){
378 // Successful merge! Maybe we should tell the user the good news?
382 $this->textbox1
= $text;
386 if ( ! $isConflict ) {
389 if( $this->section
== 'new' ) {
390 if( $this->summary
!= '' ) {
391 $sectionanchor = $this->sectionAnchor( $this->summary
);
393 } elseif( $this->section
!= '' ) {
394 # Try to get a section anchor from the section source, redirect to edited section if header found
395 # XXX: might be better to integrate this into Article::getTextOfLastEditWithSectionReplacedOrAdded
396 # for duplicate heading checking and maybe parsing
397 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
398 # we can't deal with anchors, includes, html etc in the header for now,
399 # headline would need to be parsed to improve this
400 #if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) {
401 if($hasmatch and strlen($matches[2]) > 0) {
402 $sectionanchor = $this->sectionAnchor( $matches[2] );
406 if (wfRunHooks('ArticleSave', $this->mArticle
, $wgUser, $text, $this->summary
,
407 $this->minoredit
, $this->watchthis
, $sectionanchor))
409 # update the article here
410 if($this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
411 $this->watchthis
, '', $sectionanchor ))
413 wfRunHooks('ArticleSaveComplete', $this->mArticle
, $wgUser, $text, $this->summary
,
414 $this->minoredit
, $this->watchthis
, $sectionanchor);
422 # First time through: get contents, set time for conflict
425 if ( 'initial' == $formtype ||
$firsttime ) {
426 $this->edittime
= $this->mArticle
->getTimestamp();
427 $this->textbox1
= $this->mArticle
->getContent( true );
431 $wgOut->setRobotpolicy( 'noindex,nofollow' );
433 # Enabled article-related sidebar, toplinks, etc.
434 $wgOut->setArticleRelated( true );
437 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
438 $wgOut->setPageTitle( $s );
439 $wgOut->addHTML( wfMsg( 'explainconflict' ) );
441 $this->textbox2
= $this->textbox1
;
442 $this->textbox1
= $this->mArticle
->getContent( true );
443 $this->edittime
= $this->mArticle
->getTimestamp();
446 if( $this->section
!= '' ) {
447 if( $this->section
== 'new' ) {
448 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
450 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
452 if(!$this->preview
) {
453 preg_match( "/^(=+)(.+)\\1/mi",
456 if( !empty( $matches[2] ) ) {
457 $this->summary
= "/* ". trim($matches[2])." */ ";
461 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
463 $wgOut->setPageTitle( $s );
464 if ( !$wgUseLatin1 && !$this->checkUnicodeCompliantBrowser() ) {
465 $this->mArticle
->setOldSubtitle();
466 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
468 if ( $this->oldid
) {
469 $this->mArticle
->setOldSubtitle();
470 $wgOut->addHTML( wfMsg( 'editingold' ) );
475 $wgOut->addHTML( '<strong>' .
476 wfMsg( 'readonlywarning' ) .
478 } else if ( $isCssJsSubpage and 'preview' != $formtype) {
479 $wgOut->addHTML( wfMsg( 'usercssjsyoucanpreview' ));
481 if( $this->mTitle
->isProtected('edit') ) {
482 $wgOut->addHTML( '<strong>' . wfMsg( 'protectedpagewarning' ) .
483 "</strong><br />\n" );
486 $kblength = (int)(strlen( $this->textbox1
) / 1024);
487 if( $kblength > 29 ) {
488 $wgOut->addHTML( '<strong>' .
489 wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) )
493 $rows = $wgUser->getOption( 'rows' );
494 $cols = $wgUser->getOption( 'cols' );
496 $ew = $wgUser->getOption( 'editwidth' );
497 if ( $ew ) $ew = " style=\"width:100%\"";
500 $q = 'action=submit';
501 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
502 $action = $this->mTitle
->escapeLocalURL( $q );
504 $summary = wfMsg('summary');
505 $subject = wfMsg('subject');
506 $minor = wfMsg('minoredit');
507 $watchthis = wfMsg ('watchthis');
508 $save = wfMsg('savearticle');
509 $prev = wfMsg('showpreview');
511 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
513 $edithelpurl = $sk->makeUrl( wfMsg( 'edithelppage' ));
514 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
515 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
516 htmlspecialchars( wfMsg( 'newwindow' ) );
518 global $wgRightsText;
519 $copywarn = "<div id=\"editpage-copywarn\">\n" .
520 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
521 '[[' . wfMsg( 'copyrightpage' ) . ']]',
522 $wgRightsText ) . "\n</div>";
524 if( $wgUser->getOption('showtoolbar') and !$isCssJsSubpage ) {
525 # prepare toolbar for edit buttons
526 $toolbar = $this->getEditToolbar();
531 // activate checkboxes if user wants them to be always active
532 if( !$this->preview
) {
533 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis
= true;
534 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
536 // activate checkbox also if user is already watching the page,
537 // require wpWatchthis to be unset so that second condition is not
538 // checked unnecessarily
539 if( !$this->watchthis
&& $this->mTitle
->userIsWatching() ) $this->watchthis
= true;
544 if ( $wgUser->isLoggedIn() ||
$wgAllowAnonymousMinor ) {
546 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
547 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
548 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
553 if ( $wgUser->isLoggedIn() ) {
554 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".($this->watchthis?
" checked='checked'":"").
555 " accesskey='".wfMsg('accesskey-watch')."' id='wpWatchthis' />".
556 "<label for='wpWatchthis' title='".wfMsg('tooltip-watch')."'>{$watchthis}</label>";
559 $checkboxhtml = $minoredithtml . $watchhtml . '<br />';
561 $wgOut->addHTML( '<div id="wikiPreview">' );
562 if ( 'preview' == $formtype) {
563 $previewOutput = $this->getPreviewText( $isConflict, $isCssJsSubpage );
564 if( $wgUser->getOption('previewontop' ) ) {
565 $wgOut->addHTML( $previewOutput );
566 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
569 $wgOut->addHTML( '</div>' );
571 # if this is a comment, show a subject line at the top, which is also the edit summary.
572 # Otherwise, show a summary field at the bottom
573 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
574 if( $this->section
== 'new' ) {
575 $commentsubject="{$subject}: <input tabindex='1' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
578 $commentsubject = '';
579 $editsummary="{$summary}: <input tabindex='3' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
582 if( !$this->preview
) {
583 # Don't select the edit box on preview; this interferes with seeing what's going on.
584 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
586 # Prepare a list of templates used by this page
588 $id = $this->mTitle
->getArticleID();
590 $db =& wfGetDB( DB_SLAVE
);
591 $page = $db->tableName( 'page' );
592 $links = $db->tableName( 'links' );
593 $sql = "SELECT page_namespace,page_title,page_id ".
594 "FROM $page,$links WHERE l_to=page_id AND l_from={$id} and page_namespace=".NS_TEMPLATE
;
595 $res = $db->query( $sql, "EditPage::editform" );
596 if ( false !== $res ) {
597 if ( $db->numRows( $res ) ) {
598 $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
599 while ( $row = $db->fetchObject( $res ) ) {
600 if ( $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
) ) {
601 $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
604 $templates .= '</ul>';
606 $db->freeResult( $res );
610 global $wgLivePreview, $wgStylePath;
612 * Live Preview lets us fetch rendered preview page content and
613 * add it to the page without refreshing the whole page.
614 * Set up the button for it; if not supported by the browser
615 * it will fall through to the normal form submission method.
617 if( $wgLivePreview ) {
618 $wgOut->addHTML( '<script type="text/javascript" src="' .
619 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
620 '"></script>' . "\n" );
621 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
622 $liveOnclick = 'onclick="return !livePreview('.
623 'getElementById(\'wikiPreview\'),' .
624 'editform.wpTextbox1.value,' .
625 htmlspecialchars( '"' . $liveAction . '"' ) . ')"';
630 global $wgUseMetadataEdit ;
631 if ( $wgUseMetadataEdit )
633 $metadata = $this->mMetaData
;
634 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
635 $helppage = Title
::newFromText ( wfmsg("metadata_page") ) ;
636 $top = str_replace ( "$1" , $helppage->getInternalURL() , wfmsg("metadata") ) ;
637 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
639 else $metadata = "" ;
642 $wgOut->addHTML( <<<END
644 <form id="editform" name="editform" method="post" action="$action"
645 enctype="multipart/form-data">
647 <textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}'
650 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1
) ) .
656 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
657 " title=\"".wfMsg('tooltip-save')."\"/>
658 <input tabindex='6' id='wpPreview' type='submit' $liveOnclick value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
659 " title=\"".wfMsg('tooltip-preview')."\"/>
660 <em>{$cancel}</em> | <em>{$edithelp}</em>{$templates}" );
661 $wgOut->addWikiText( $copywarn );
663 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
664 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n" );
666 if ( $wgUser->isLoggedIn() ) {
668 * To make it harder for someone to slip a user a page
669 * which submits an edit form to the wiki without their
670 * knowledge, a random token is associated with the login
671 * session. If it's not passed back with the submission,
672 * we won't save the page, or render user JavaScript and
675 $token = htmlspecialchars( $wgUser->editToken() );
677 <input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
682 require_once( "DifferenceEngine.php" );
683 $wgOut->addHTML( "<h2>" . wfMsg( "yourdiff" ) . "</h2>\n" );
684 DifferenceEngine
::showDiff( $this->textbox2
, $this->textbox1
,
685 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
687 $wgOut->addHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
688 <textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
689 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox2
) ) .
693 $wgOut->addHTML( "</form>\n" );
694 if($formtype =="preview" && !$wgUser->getOption("previewontop")) {
695 $wgOut->addHTML('<div id="wikiPreview">' . $previewOutput . '</div>');
699 function getPreviewText( $isConflict, $isCssJsSubpage ) {
700 global $wgOut, $wgUser, $wgTitle, $wgParser;
701 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
702 "<p class='previewnote'>" . htmlspecialchars( wfMsg( 'previewnote' ) ) . "</p>\n";
704 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) .
708 $parserOptions = ParserOptions
::newFromUser( $wgUser );
709 $parserOptions->setEditSection( false );
710 $parserOptions->setEditSectionOnRightClick( false );
712 # don't parse user css/js, show message about preview
713 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
715 if ( $isCssJsSubpage ) {
716 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
717 $previewtext = wfMsg('usercsspreview');
718 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
719 $previewtext = wfMsg('userjspreview');
721 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
722 $wgOut->addHTML( $parserOutput->mText
);
725 # if user want to see preview when he edit an article
726 if( $wgUser->getOption('previewonfirst') and ($this->textbox1
== '')) {
727 $this->textbox1
= $this->mArticle
->getContent(true);
730 $toparse = $this->textbox1
;
731 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
733 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
734 $wgTitle, $parserOptions );
736 $previewHTML = $parserOutput->mText
;
737 $wgOut->addCategoryLinks($parserOutput->getCategoryLinks());
738 $wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
739 return $previewhead . $previewHTML;
746 function blockedIPpage() {
747 global $wgOut, $wgUser, $wgContLang, $wgIP;
749 $wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
750 $wgOut->setRobotpolicy( 'noindex,nofollow' );
751 $wgOut->setArticleRelated( false );
753 $id = $wgUser->blockedBy();
754 $reason = $wgUser->blockedFor();
757 if ( is_numeric( $id ) ) {
758 $name = User
::whoIs( $id );
762 $link = '[[' . $wgContLang->getNsText( NS_USER
) .
763 ":{$name}|{$name}]]";
765 $wgOut->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
766 $wgOut->returnToMain( false );
772 function userNotLoggedInPage() {
775 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
776 $wgOut->setRobotpolicy( 'noindex,nofollow' );
777 $wgOut->setArticleRelated( false );
779 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
780 $wgOut->returnToMain( false );
786 function spamPage ( $match = false )
789 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
790 $wgOut->setRobotpolicy( 'noindex,nofollow' );
791 $wgOut->setArticleRelated( false );
793 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
795 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
797 $wgOut->returnToMain( false );
801 * Forks processes to scan the originating IP for an open proxy server
802 * MemCached can be used to skip IPs that have already been scanned
804 function proxyCheck() {
805 global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
806 global $wgIP, $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
808 if ( !$wgBlockOpenProxies ) {
814 if ( $wgUseMemCached ) {
815 $mcKey = $wgDBname.':proxy:ip:'.$wgIP;
816 $mcValue = $wgMemc->get( $mcKey );
824 $title = Title
::makeTitle( NS_SPECIAL
, 'Blockme' );
825 $iphash = md5( $wgIP . $wgProxyKey );
826 $url = $title->getFullURL( 'ip='.$iphash );
828 foreach ( $wgProxyPorts as $port ) {
829 $params = implode( ' ', array(
830 escapeshellarg( $wgProxyScriptPath ),
831 escapeshellarg( $wgIP ),
832 escapeshellarg( $port ),
833 escapeshellarg( $url )
835 exec( "php $params &>/dev/null &" );
838 if ( $wgUseMemCached ) {
839 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
848 function mergeChangesInto( &$text ){
849 $yourtext = $this->mArticle
->fetchRevisionText();
851 $db =& wfGetDB( DB_SLAVE
);
852 $oldText = $this->mArticle
->fetchRevisionText(
853 $db->timestamp( $this->edittime
),
856 if(wfMerge($oldText, $text, $yourtext, $result)){
865 function checkUnicodeCompliantBrowser() {
866 global $wgBrowserBlackList;
867 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
868 foreach ( $wgBrowserBlackList as $browser ) {
869 if ( preg_match($browser, $currentbrowser) ) {
877 * Format an anchor fragment as it would appear for a given section name
878 * @param string $text
882 function sectionAnchor( $text ) {
883 global $wgInputEncoding;
884 $headline = do_html_entity_decode( $text, ENT_COMPAT
, $wgInputEncoding );
886 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
887 $headline = trim( $headline );
888 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
889 $replacearray = array(
894 array_keys( $replacearray ),
895 array_values( $replacearray ),
900 * Shows a bulletin board style toolbar for common editing functions.
901 * It can be disabled in the user preferences.
902 * The necessary JavaScript code can be found in style/wikibits.js.
904 function getEditToolbar() {
905 global $wgStylePath, $wgLang, $wgMimeType;
908 * toolarray an array of arrays which each include the filename of
909 * the button image (without path), the opening tag, the closing tag,
910 * and optionally a sample text that is inserted between the two when no
911 * selection is highlighted.
912 * The tip text is shown when the user moves the mouse over the button.
914 * Already here are accesskeys (key), which are not used yet until someone
915 * can figure out a way to make them work in IE. However, we should make
916 * sure these keys are not defined on the edit page.
919 array( 'image'=>'button_bold.png',
922 'sample'=> wfMsg('bold_sample'),
923 'tip' => wfMsg('bold_tip'),
926 array( 'image'=>'button_italic.png',
929 'sample'=> wfMsg('italic_sample'),
930 'tip' => wfMsg('italic_tip'),
933 array( 'image'=>'button_link.png',
936 'sample'=> wfMsg('link_sample'),
937 'tip' => wfMsg('link_tip'),
940 array( 'image'=>'button_extlink.png',
943 'sample'=> wfMsg('extlink_sample'),
944 'tip' => wfMsg('extlink_tip'),
947 array( 'image'=>'button_headline.png',
950 'sample'=> wfMsg('headline_sample'),
951 'tip' => wfMsg('headline_tip'),
954 array( 'image'=>'button_image.png',
955 'open' => '[['.$wgLang->getNsText(NS_IMAGE
).":",
957 'sample'=> wfMsg('image_sample'),
958 'tip' => wfMsg('image_tip'),
961 array( 'image' => 'button_media.png',
962 'open' => '[['.$wgLang->getNsText(NS_MEDIA
).':',
964 'sample'=> wfMsg('media_sample'),
965 'tip' => wfMsg('media_tip'),
968 array( 'image' => 'button_math.png',
969 'open' => "\\<math\\>",
970 'close' => "\\</math\\>",
971 'sample'=> wfMsg('math_sample'),
972 'tip' => wfMsg('math_tip'),
975 array( 'image' => 'button_nowiki.png',
976 'open' => "\\<nowiki\\>",
977 'close' => "\\</nowiki\\>",
978 'sample'=> wfMsg('nowiki_sample'),
979 'tip' => wfMsg('nowiki_tip'),
982 array( 'image' => 'button_sig.png',
986 'tip' => wfMsg('sig_tip'),
989 array( 'image' => 'button_hr.png',
990 'open' => "\\n----\\n",
993 'tip' => wfMsg('hr_tip'),
997 $toolbar ="<script type='text/javascript'>\n/*<![CDATA[*/\n";
999 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
1000 foreach($toolarray as $tool) {
1002 $image=$wgStylePath.'/common/images/'.$tool['image'];
1003 $open=$tool['open'];
1004 $close=$tool['close'];
1005 $sample = addslashes( $tool['sample'] );
1007 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1008 // Older browsers show a "speedtip" type message only for ALT.
1009 // Ideally these should be different, realistically they
1010 // probably don't need to be.
1011 $tip = addslashes( $tool['tip'] );
1013 #$key = $tool["key"];
1015 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
1018 $toolbar.="addInfobox('" . addslashes( wfMsg( "infobox" ) ) . "','" . addslashes(wfMsg("infobox_alert")) . "');\n";
1019 $toolbar.="document.writeln(\"</div>\");\n";
1021 $toolbar.="/*]]>*/\n</script>";
1026 * Output preview text only. This can be sucked into the edit page
1027 * via JavaScript, and saves the server time rendering the skin as
1028 * well as theoretically being more robust on the client (doesn't
1029 * disturb the edit box's undo history, won't eat your text on
1032 * @todo This doesn't include category or interlanguage links.
1033 * Would need to enhance it a bit, maybe wrap them in XML
1034 * or something... that might also require more skin
1035 * initialization, so check whether that's a problem.
1037 function livePreview() {
1040 header( 'Content-type: text/xml' );
1041 header( 'Cache-control: no-cache' );
1043 echo $this->getPreviewText( false, false );