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
42 function extractMetaDataFromArticle ()
44 global $wgUseMetadataEdit , $wgLang ;
45 $this->mMetaData
= "" ;
46 if ( !$wgUseMetadataEdit ) return ;
48 $t = $this->mArticle
->getContent ( true ) ;
50 # MISSING : <nowiki> filtering
52 # Categories and language links
53 $t = explode ( "\n" , $t ) ;
54 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY
) ) ;
55 $cat = $ll = array() ;
56 foreach ( $t AS $key => $x )
58 $y = trim ( strtolower ( $x ) ) ;
59 while ( substr ( $y , 0 , 2 ) == "[[" )
61 $y = explode ( "]]" , trim ( $x ) ) ;
62 $first = array_shift ( $y ) ;
63 $first = explode ( ":" , $first ) ;
64 $ns = array_shift ( $first ) ;
65 $ns = trim ( str_replace ( "[" , "" , $ns ) ) ;
66 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
68 $add = "[[" . $ns . ":" . implode ( ":" , $first ) . "]]" ;
69 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
71 $x = implode ( "]]" , $y ) ;
73 $y = trim ( strtolower ( $x ) ) ;
77 if ( count ( $cat ) ) $s .= implode ( " " , $cat ) . "\n" ;
78 if ( count ( $ll ) ) $s .= implode ( " " , $ll ) . "\n" ;
79 $t = implode ( "\n" , $t ) ;
81 # Templates, but only some
82 $sat = array ( "meta-template" ) ; # stand-alone-templates; must be lowercase
83 $t = explode ( "{{" , $t ) ;
85 foreach ( $t AS $key => $x )
87 $y = explode ( "}}" , $x , 2 ) ;
88 if ( count ( $y ) == 2 )
91 $z = explode ( "|" , $z ) ;
92 $tn = array_shift ( $z ) ;
93 if ( in_array ( strtolower ( $tn ) , $sat ) )
95 $tl[] = "{{" . $y[0] . "}}" ;
97 $y = explode ( "}}" , $y[1] , 2 ) ;
99 else $t[$key] = "{{" . $x ;
101 else if ( $key != 0 ) $t[$key] = "{{" . $x ;
104 if ( count ( $tl ) ) $s .= implode ( " " , $tl ) ;
105 $t = implode ( "" , $t ) ;
107 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
108 $this->mArticle
->mContent
= $t ;
109 $this->mMetaData
= $s ;
113 * This is the function that gets called for "action=edit".
116 global $wgOut, $wgUser, $wgWhitelistEdit, $wgRequest;
117 // this is not an article
118 $wgOut->setArticleFlag(false);
120 $this->importFormData( $wgRequest );
123 $this->livePreview();
127 if ( ! $this->mTitle
->userCanEdit() ) {
128 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ), true );
131 if ( $wgUser->isBlocked() ) {
132 $this->blockedIPpage();
135 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
136 $this->userNotLoggedInPage();
139 if ( wfReadOnly() ) {
140 if( $this->save ||
$this->preview
) {
141 $this->editForm( 'preview' );
143 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ) );
148 $this->editForm( 'save' );
149 } else if ( $this->preview
) {
150 $this->editForm( 'preview' );
151 } else { # First time through
152 if( $wgUser->getOption('previewonfirst') ) {
153 $this->editForm( 'preview', true );
155 $this->extractMetaDataFromArticle () ;
156 $this->editForm( 'initial', true );
164 function importFormData( &$request ) {
165 # These fields need to be checked for encoding.
166 # Also remove trailing whitespace, but don't remove _initial_
167 # whitespace from the text boxes. This may be significant formatting.
168 $this->textbox1
= rtrim( $request->getText( 'wpTextbox1' ) );
169 $this->textbox2
= rtrim( $request->getText( 'wpTextbox2' ) );
170 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
171 $this->summary
= trim( $request->getText( 'wpSummary' ) );
173 $this->edittime
= $request->getVal( 'wpEdittime' );
174 if( !preg_match( '/^\d{14}$/', $this->edittime
)) $this->edittime
= '';
176 $this->preview
= $request->getCheck( 'wpPreview' );
177 $this->save
= $request->wasPosted() && !$this->preview
;
178 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
179 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
181 $this->oldid
= $request->getInt( 'oldid' );
183 # Section edit can come from either the form or a link
184 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
186 $this->live
= $request->getCheck( 'live' );
190 * Since there is only one text field on the edit form,
191 * pressing <enter> will cause the form to be submitted, but
192 * the submit button value won't appear in the query, so we
193 * Fake it here before going back to edit(). This is kind of
194 * ugly, but it helps some old URLs to still work.
197 if( !$this->preview
) $this->save
= true;
203 * The edit form is self-submitting, so that when things like
204 * preview and edit conflicts occur, we get the same form back
205 * with the extra stuff added. Only when the final submission
206 * is made and all is well do we actually save and redirect to
207 * the newly-edited page.
209 * @param string $formtype Type of form either : save, initial or preview
210 * @param bool $firsttime True to load form data from db
212 function editForm( $formtype, $firsttime = false ) {
213 global $wgOut, $wgUser;
214 global $wgLang, $wgContLang, $wgParser, $wgTitle;
215 global $wgAllowAnonymousMinor;
216 global $wgWhitelistEdit;
217 global $wgSpamRegex, $wgFilterCallback;
220 $sk = $wgUser->getSkin();
222 // css / js subpages of user pages get a special treatment
223 $isCssJsSubpage = (Namespace::getUser() == $wgTitle->getNamespace() and preg_match("/\\.(css|js)$/", $wgTitle->getText() ));
225 if(!$this->mTitle
->getArticleID()) { # new article
226 $wgOut->addWikiText(wfmsg('newarticletext'));
229 if( Namespace::isTalk( $this->mTitle
->getNamespace() ) ) {
230 $wgOut->addWikiText(wfmsg('talkpagetext'));
233 # Attempt submission here. This will check for edit conflicts,
234 # and redundantly check for locked database, blocked IPs, etc.
235 # that edit() already checked just in case someone tries to sneak
236 # in the back door with a hand-edited submission URL.
238 if ( 'save' == $formtype ) {
239 # Reintegrate metadata
240 if ( $this->mMetaData
!= "" ) $this->textbox1
.= "\n" . $this->mMetaData
;
241 $this->mMetaData
= "" ;
244 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
245 $this->spamPage ( $matches[0] );
248 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
249 # Error messages or other handling should be performed by the filter function
252 if ( $wgUser->isBlocked() ) {
253 $this->blockedIPpage();
256 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
257 $this->userNotLoggedInPage();
260 if ( wfReadOnly() ) {
261 $wgOut->readOnlyPage();
265 # If article is new, insert it.
266 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
268 # Don't save a new article if it's blank.
269 if ( ( '' == $this->textbox1
) ||
270 ( wfMsg( 'newarticletext' ) == $this->textbox1
) ) {
271 $wgOut->redirect( $this->mTitle
->getFullURL() );
274 if (wfRunHooks('ArticleSave', $this->mArticle
, $wgUser, $this->textbox1
,
275 $this->summary
, $this->minoredit
, $this->watchthis
, NULL))
277 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
278 $this->minoredit
, $this->watchthis
);
279 wfRunHooks('ArticleSaveComplete', $this->mArticle
, $wgUser, $this->textbox1
,
280 $this->summary
, $this->minoredit
, $this->watchthis
, NULL);
285 # Article exists. Check for edit conflict.
287 $this->mArticle
->clear(); # Force reload of dates, etc.
288 $this->mArticle
->forUpdate( true ); # Lock the article
290 if( ( $this->section
!= 'new' ) &&
291 ($this->mArticle
->getTimestamp() != $this->edittime
) ) {
294 $userid = $wgUser->getID();
297 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
298 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
301 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
302 $this->section
, $this->textbox1
, $this->summary
);
304 # Suppress edit conflict with self
306 if ( ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
309 # switch from section editing to normal editing in edit conflict
312 if( $this->mergeChangesInto( $text ) ){
313 // Successful merge! Maybe we should tell the user the good news?
317 $this->textbox1
= $text;
321 if ( ! $isConflict ) {
324 if( $this->section
== 'new' ) {
325 if( $this->summary
!= '' ) {
326 $sectionanchor = $this->sectionAnchor( $this->summary
);
328 } elseif( $this->section
!= '' ) {
329 # Try to get a section anchor from the section source, redirect to edited section if header found
330 # XXX: might be better to integrate this into Article::getTextOfLastEditWithSectionReplacedOrAdded
331 # for duplicate heading checking and maybe parsing
332 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
333 # we can't deal with anchors, includes, html etc in the header for now,
334 # headline would need to be parsed to improve this
335 #if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) {
336 if($hasmatch and strlen($matches[2]) > 0) {
337 $sectionanchor = $this->sectionAnchor( $matches[2] );
341 if (wfRunHooks('ArticleSave', $this->mArticle
, $wgUser, $text, $this->summary
,
342 $this->minoredit
, $this->watchthis
, $sectionanchor))
344 # update the article here
345 if($this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
346 $this->watchthis
, '', $sectionanchor ))
348 wfRunHooks('ArticleSaveComplete', $this->mArticle
, $wgUser, $text, $this->summary
,
349 $this->minoredit
, $this->watchthis
, $sectionanchor);
357 # First time through: get contents, set time for conflict
360 if ( 'initial' == $formtype ||
$firsttime ) {
361 $this->edittime
= $this->mArticle
->getTimestamp();
362 $this->textbox1
= $this->mArticle
->getContent( true );
366 $wgOut->setRobotpolicy( 'noindex,nofollow' );
368 # Enabled article-related sidebar, toplinks, etc.
369 $wgOut->setArticleRelated( true );
372 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
373 $wgOut->setPageTitle( $s );
374 $wgOut->addHTML( wfMsg( 'explainconflict' ) );
376 $this->textbox2
= $this->textbox1
;
377 $this->textbox1
= $this->mArticle
->getContent( true );
378 $this->edittime
= $this->mArticle
->getTimestamp();
381 if( $this->section
!= '' ) {
382 if( $this->section
== 'new' ) {
383 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
385 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
387 if(!$this->preview
) {
388 preg_match( "/^(=+)(.+)\\1/mi",
391 if( !empty( $matches[2] ) ) {
392 $this->summary
= "/* ". trim($matches[2])." */ ";
396 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
398 $wgOut->setPageTitle( $s );
399 if ( !$wgUseLatin1 && !$this->checkUnicodeCompliantBrowser() ) {
400 $this->mArticle
->setOldSubtitle();
401 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
403 if ( $this->oldid
) {
404 $this->mArticle
->setOldSubtitle();
405 $wgOut->addHTML( wfMsg( 'editingold' ) );
410 $wgOut->addHTML( '<strong>' .
411 wfMsg( 'readonlywarning' ) .
413 } else if ( $isCssJsSubpage and 'preview' != $formtype) {
414 $wgOut->addHTML( wfMsg( 'usercssjsyoucanpreview' ));
416 if( $this->mTitle
->isProtected('edit') ) {
417 $wgOut->addHTML( '<strong>' . wfMsg( 'protectedpagewarning' ) .
418 "</strong><br />\n" );
421 $kblength = (int)(strlen( $this->textbox1
) / 1024);
422 if( $kblength > 29 ) {
423 $wgOut->addHTML( '<strong>' .
424 wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) )
428 $rows = $wgUser->getOption( 'rows' );
429 $cols = $wgUser->getOption( 'cols' );
431 $ew = $wgUser->getOption( 'editwidth' );
432 if ( $ew ) $ew = " style=\"width:100%\"";
435 $q = 'action=submit';
436 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
437 $action = $this->mTitle
->escapeLocalURL( $q );
439 $summary = wfMsg('summary');
440 $subject = wfMsg('subject');
441 $minor = wfMsg('minoredit');
442 $watchthis = wfMsg ('watchthis');
443 $save = wfMsg('savearticle');
444 $prev = wfMsg('showpreview');
446 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
448 $edithelpurl = $sk->makeUrl( wfMsg( 'edithelppage' ));
449 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
450 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
451 htmlspecialchars( wfMsg( 'newwindow' ) );
453 global $wgRightsText;
454 $copywarn = "<div id=\"editpage-copywarn\">\n" .
455 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
456 '[[' . wfMsg( 'copyrightpage' ) . ']]',
457 $wgRightsText ) . "\n</div>";
459 if( $wgUser->getOption('showtoolbar') and !$isCssJsSubpage ) {
460 # prepare toolbar for edit buttons
461 $toolbar = $this->getEditToolbar();
466 // activate checkboxes if user wants them to be always active
467 if( !$this->preview
) {
468 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis
= true;
469 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
471 // activate checkbox also if user is already watching the page,
472 // require wpWatchthis to be unset so that second condition is not
473 // checked unnecessarily
474 if( !$this->watchthis
&& $this->mTitle
->userIsWatching() ) $this->watchthis
= true;
479 if ( 0 != $wgUser->getID() ||
$wgAllowAnonymousMinor ) {
481 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
482 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
483 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
488 if ( 0 != $wgUser->getID() ) {
489 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".($this->watchthis?
" checked='checked'":"").
490 " accesskey='".wfMsg('accesskey-watch')."' id='wpWatchthis' />".
491 "<label for='wpWatchthis' title='".wfMsg('tooltip-watch')."'>{$watchthis}</label>";
494 $checkboxhtml = $minoredithtml . $watchhtml . '<br />';
496 $wgOut->addHTML( '<div id="wikiPreview">' );
497 if ( 'preview' == $formtype) {
498 $previewOutput = $this->getPreviewText( $isConflict, $isCssJsSubpage );
499 if( $wgUser->getOption('previewontop' ) ) {
500 $wgOut->addHTML( $previewOutput );
501 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
504 $wgOut->addHTML( '</div>' );
506 # if this is a comment, show a subject line at the top, which is also the edit summary.
507 # Otherwise, show a summary field at the bottom
508 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
509 if( $this->section
== 'new' ) {
510 $commentsubject="{$subject}: <input tabindex='1' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
513 $commentsubject = '';
514 $editsummary="{$summary}: <input tabindex='3' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
517 if( !$this->preview
) {
518 # Don't select the edit box on preview; this interferes with seeing what's going on.
519 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
521 # Prepare a list of templates used by this page
522 $db =& wfGetDB( DB_SLAVE
);
523 $page = $db->tableName( 'page' );
524 $links = $db->tableName( 'links' );
525 $id = $this->mTitle
->getArticleID();
526 $sql = "SELECT page_namespace,page_title,page_id ".
527 "FROM $page,$links WHERE l_to=page_id AND l_from={$id} and page_namespace=".NS_TEMPLATE
;
528 $res = $db->query( $sql, "EditPage::editform" );
530 if ( $db->numRows( $res ) ) {
531 $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
532 while ( $row = $db->fetchObject( $res ) ) {
533 if ( $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
) ) {
534 $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
537 $templates .= '</ul>';
542 global $wgLivePreview, $wgStylePath;
544 * Live Preview lets us fetch rendered preview page content and
545 * add it to the page without refreshing the whole page.
546 * Set up the button for it; if not supported by the browser
547 * it will fall through to the normal form submission method.
549 if( $wgLivePreview ) {
550 $wgOut->addHTML( '<script type="text/javascript" src="' .
551 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
552 '"></script>' . "\n" );
553 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
554 $liveOnclick = 'onclick="return !livePreview('.
555 'getElementById(\'wikiPreview\'),' .
556 'editform.wpTextbox1.value,' .
557 htmlspecialchars( '"' . $liveAction . '"' ) . ')"';
562 global $wgUseMetadataEdit ;
563 if ( $wgUseMetadataEdit )
565 $metadata = $this->mMetaData
;
566 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
567 $metadata = "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
569 else $metadata = "" ;
572 $wgOut->addHTML( <<<END
574 <form id="editform" name="editform" method="post" action="$action"
575 enctype="multipart/form-data">
578 <textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}'
581 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1
) ) .
587 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
588 " title=\"".wfMsg('tooltip-save')."\"/>
589 <input tabindex='6' id='wpPreview' type='submit' $liveOnclick value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
590 " title=\"".wfMsg('tooltip-preview')."\"/>
591 <em>{$cancel}</em> | <em>{$edithelp}</em>{$templates}" );
592 $wgOut->addWikiText( $copywarn );
594 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
595 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n" );
598 require_once( "DifferenceEngine.php" );
599 $wgOut->addHTML( "<h2>" . wfMsg( "yourdiff" ) . "</h2>\n" );
600 DifferenceEngine
::showDiff( $this->textbox2
, $this->textbox1
,
601 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
603 $wgOut->addHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
604 <textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
605 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox2
) ) .
609 $wgOut->addHTML( "</form>\n" );
610 if($formtype =="preview" && !$wgUser->getOption("previewontop")) {
611 $wgOut->addHTML('<div id="wikiPreview">' . $previewOutput . '</div>');
615 function getPreviewText( $isConflict, $isCssJsSubpage ) {
616 global $wgOut, $wgUser, $wgTitle, $wgParser;
617 $previewhead='<h2>' . wfMsg( 'preview' ) . "</h2>\n<p><center><font color=\"#cc0000\">" .
618 wfMsg( 'note' ) . wfMsg( 'previewnote' ) . "</font></center></p>\n";
620 $previewhead.='<h2>' . wfMsg( 'previewconflict' ) .
624 $parserOptions = ParserOptions
::newFromUser( $wgUser );
625 $parserOptions->setEditSection( false );
626 $parserOptions->setEditSectionOnRightClick( false );
628 # don't parse user css/js, show message about preview
629 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
631 if ( $isCssJsSubpage ) {
632 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
633 $previewtext = wfMsg('usercsspreview');
634 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
635 $previewtext = wfMsg('userjspreview');
637 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
638 $wgOut->addHTML( $parserOutput->mText
);
640 # if user want to see preview when he edit an article
641 if( $wgUser->getOption('previewonfirst') and ($this->textbox1
== '')) {
642 $this->textbox1
= $this->mArticle
->getContent(true);
645 $toparse = $this->textbox1
;
646 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
648 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
649 $wgTitle, $parserOptions );
651 $previewHTML = $parserOutput->mText
;
652 $wgOut->addCategoryLinks($parserOutput->getCategoryLinks());
653 $wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
655 return $previewhead . $previewHTML;
661 function blockedIPpage() {
662 global $wgOut, $wgUser, $wgContLang, $wgIP;
664 $wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
665 $wgOut->setRobotpolicy( 'noindex,nofollow' );
666 $wgOut->setArticleRelated( false );
668 $id = $wgUser->blockedBy();
669 $reason = $wgUser->blockedFor();
672 if ( is_numeric( $id ) ) {
673 $name = User
::whoIs( $id );
677 $link = '[[' . $wgContLang->getNsText( Namespace::getUser() ) .
678 ":{$name}|{$name}]]";
680 $wgOut->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
681 $wgOut->returnToMain( false );
687 function userNotLoggedInPage() {
688 global $wgOut, $wgUser;
690 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
691 $wgOut->setRobotpolicy( 'noindex,nofollow' );
692 $wgOut->setArticleRelated( false );
694 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
695 $wgOut->returnToMain( false );
701 function spamPage ( $match = false )
704 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
705 $wgOut->setRobotpolicy( 'noindex,nofollow' );
706 $wgOut->setArticleRelated( false );
708 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
710 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
712 $wgOut->returnToMain( false );
716 * Forks processes to scan the originating IP for an open proxy server
717 * MemCached can be used to skip IPs that have already been scanned
719 function proxyCheck() {
720 global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
721 global $wgIP, $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
723 if ( !$wgBlockOpenProxies ) {
729 if ( $wgUseMemCached ) {
730 $mcKey = $wgDBname.':proxy:ip:'.$wgIP;
731 $mcValue = $wgMemc->get( $mcKey );
739 $title = Title
::makeTitle( NS_SPECIAL
, 'Blockme' );
740 $iphash = md5( $wgIP . $wgProxyKey );
741 $url = $title->getFullURL( 'ip='.$iphash );
743 foreach ( $wgProxyPorts as $port ) {
744 $params = implode( ' ', array(
745 escapeshellarg( $wgProxyScriptPath ),
746 escapeshellarg( $wgIP ),
747 escapeshellarg( $port ),
748 escapeshellarg( $url )
750 exec( "php $params &>/dev/null &" );
753 if ( $wgUseMemCached ) {
754 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
763 function mergeChangesInto( &$text ){
764 $yourtext = $this->mArticle
->fetchRevisionText();
766 $db =& wfGetDB( DB_SLAVE
);
767 $oldText = $this->mArticle
->fetchRevisionText(
768 $db->timestamp( $this->edittime
),
771 if(wfMerge($oldText, $text, $yourtext, $result)){
780 function checkUnicodeCompliantBrowser() {
781 global $wgBrowserBlackList;
782 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
783 foreach ( $wgBrowserBlackList as $browser ) {
784 if ( preg_match($browser, $currentbrowser) ) {
792 * Format an anchor fragment as it would appear for a given section name
793 * @param string $text
797 function sectionAnchor( $text ) {
798 global $wgInputEncoding;
799 $headline = do_html_entity_decode( $text, ENT_COMPAT
, $wgInputEncoding );
801 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
802 $headline = trim( $headline );
803 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
804 $replacearray = array(
809 array_keys( $replacearray ),
810 array_values( $replacearray ),
815 * Shows a bulletin board style toolbar for common editing functions.
816 * It can be disabled in the user preferences.
817 * The necessary JavaScript code can be found in style/wikibits.js.
819 function getEditToolbar() {
820 global $wgStylePath, $wgLang, $wgMimeType;
823 * toolarray an array of arrays which each include the filename of
824 * the button image (without path), the opening tag, the closing tag,
825 * and optionally a sample text that is inserted between the two when no
826 * selection is highlighted.
827 * The tip text is shown when the user moves the mouse over the button.
829 * Already here are accesskeys (key), which are not used yet until someone
830 * can figure out a way to make them work in IE. However, we should make
831 * sure these keys are not defined on the edit page.
834 array( 'image'=>'button_bold.png',
837 'sample'=> wfMsg('bold_sample'),
838 'tip' => wfMsg('bold_tip'),
841 array( 'image'=>'button_italic.png',
844 'sample'=> wfMsg('italic_sample'),
845 'tip' => wfMsg('italic_tip'),
848 array( 'image'=>'button_link.png',
851 'sample'=> wfMsg('link_sample'),
852 'tip' => wfMsg('link_tip'),
855 array( 'image'=>'button_extlink.png',
858 'sample'=> wfMsg('extlink_sample'),
859 'tip' => wfMsg('extlink_tip'),
862 array( 'image'=>'button_headline.png',
865 'sample'=> wfMsg('headline_sample'),
866 'tip' => wfMsg('headline_tip'),
869 array( 'image'=>'button_image.png',
870 'open' => '[['.$wgLang->getNsText(NS_IMAGE
).":",
872 'sample'=> wfMsg('image_sample'),
873 'tip' => wfMsg('image_tip'),
876 array( 'image' => 'button_media.png',
877 'open' => '[['.$wgLang->getNsText(NS_MEDIA
).':',
879 'sample'=> wfMsg('media_sample'),
880 'tip' => wfMsg('media_tip'),
883 array( 'image' => 'button_math.png',
884 'open' => "\\<math\\>",
885 'close' => "\\</math\\>",
886 'sample'=> wfMsg('math_sample'),
887 'tip' => wfMsg('math_tip'),
890 array( 'image' => 'button_nowiki.png',
891 'open' => "\\<nowiki\\>",
892 'close' => "\\</nowiki\\>",
893 'sample'=> wfMsg('nowiki_sample'),
894 'tip' => wfMsg('nowiki_tip'),
897 array( 'image' => 'button_sig.png',
901 'tip' => wfMsg('sig_tip'),
904 array( 'image' => 'button_hr.png',
905 'open' => "\\n----\\n",
908 'tip' => wfMsg('hr_tip'),
912 $toolbar ="<script type='text/javascript'>\n/*<![CDATA[*/\n";
914 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
915 foreach($toolarray as $tool) {
917 $image=$wgStylePath.'/common/images/'.$tool['image'];
919 $close=$tool['close'];
920 $sample = addslashes( $tool['sample'] );
922 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
923 // Older browsers show a "speedtip" type message only for ALT.
924 // Ideally these should be different, realistically they
925 // probably don't need to be.
926 $tip = addslashes( $tool['tip'] );
928 #$key = $tool["key"];
930 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
933 $toolbar.="addInfobox('" . addslashes( wfMsg( "infobox" ) ) . "','" . addslashes(wfMsg("infobox_alert")) . "');\n";
934 $toolbar.="document.writeln(\"</div>\");\n";
936 $toolbar.="/*]]>*/\n</script>";
941 * Output preview text only. This can be sucked into the edit page
942 * via JavaScript, and saves the server time rendering the skin as
943 * well as theoretically being more robust on the client (doesn't
944 * disturb the edit box's undo history, won't eat your text on
947 * @todo This doesn't include category or interlanguage links.
948 * Would need to enhance it a bit, maybe wrap them in XML
949 * or something... that might also require more skin
950 * initialization, so check whether that's a problem.
952 function livePreview() {
955 header( 'Content-type: text/xml' );
956 header( 'Cache-control: no-cache' );
958 echo $this->getPreviewText( false, false );