* Avoid PHP warning messages when thumbnail not generated
[mediawiki.git] / includes / EditPage.php
blob33e17c9401ced90877047258881a669771502cd0
1 <?php
2 /**
3 * Contain the EditPage class
4 * @package MediaWiki
5 */
7 /**
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
11 * interfaces.
13 * @package MediaWiki
16 class EditPage {
17 var $mArticle;
18 var $mTitle;
20 # Form values
21 var $save = false, $preview = false;
22 var $minoredit = false, $watchthis = false;
23 var $textbox1 = '', $textbox2 = '', $summary = '';
24 var $edittime = '', $section = '';
25 var $oldid = 0;
27 /**
28 * @todo document
29 * @param $article
31 function EditPage( $article ) {
32 $this->mArticle =& $article;
33 global $wgTitle;
34 $this->mTitle =& $wgTitle;
37 /**
38 * This is the function that gets called for "action=edit".
40 function edit() {
41 global $wgOut, $wgUser, $wgWhitelistEdit, $wgRequest;
42 // this is not an article
43 $wgOut->setArticleFlag(false);
45 $this->importFormData( $wgRequest );
47 if( $this->live ) {
48 $this->livePreview();
49 return;
52 if ( ! $this->mTitle->userCanEdit() ) {
53 $wgOut->readOnlyPage( $this->mArticle->getContent( true ), true );
54 return;
56 if ( $wgUser->isBlocked() ) {
57 $this->blockedIPpage();
58 return;
60 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
61 $this->userNotLoggedInPage();
62 return;
64 if ( wfReadOnly() ) {
65 if( $this->save || $this->preview ) {
66 $this->editForm( 'preview' );
67 } else {
68 $wgOut->readOnlyPage( $this->mArticle->getContent( true ) );
70 return;
72 if ( $this->save ) {
73 $this->editForm( 'save' );
74 } else if ( $this->preview or $wgUser->getOption('previewonfirst')) {
75 $this->editForm( 'preview' );
76 } else { # First time through
77 $this->editForm( 'initial' );
81 /**
82 * @todo document
84 function importFormData( &$request ) {
85 # These fields need to be checked for encoding.
86 # Also remove trailing whitespace, but don't remove _initial_
87 # whitespace from the text boxes. This may be significant formatting.
88 $this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) );
89 $this->textbox2 = rtrim( $request->getText( 'wpTextbox2' ) );
90 $this->summary = trim( $request->getText( 'wpSummary' ) );
92 $this->edittime = $request->getVal( 'wpEdittime' );
93 if( !preg_match( '/^\d{14}$/', $this->edittime )) $this->edittime = '';
95 $this->preview = $request->getCheck( 'wpPreview' );
96 $this->save = $request->wasPosted() && !$this->preview;
97 $this->minoredit = $request->getCheck( 'wpMinoredit' );
98 $this->watchthis = $request->getCheck( 'wpWatchthis' );
100 $this->oldid = $request->getInt( 'oldid' );
102 # Section edit can come from either the form or a link
103 $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
105 $this->live = $request->getCheck( 'live' );
109 * Since there is only one text field on the edit form,
110 * pressing <enter> will cause the form to be submitted, but
111 * the submit button value won't appear in the query, so we
112 * Fake it here before going back to edit(). This is kind of
113 * ugly, but it helps some old URLs to still work.
115 function submit() {
116 if( !$this->preview ) $this->save = true;
118 $this->edit();
122 * The edit form is self-submitting, so that when things like
123 * preview and edit conflicts occur, we get the same form back
124 * with the extra stuff added. Only when the final submission
125 * is made and all is well do we actually save and redirect to
126 * the newly-edited page.
128 * @param string $formtype Type of form either : save, initial or preview
130 function editForm( $formtype ) {
131 global $wgOut, $wgUser;
132 global $wgLang, $wgContLang, $wgParser, $wgTitle;
133 global $wgAllowAnonymousMinor;
134 global $wgWhitelistEdit;
135 global $wgSpamRegex, $wgFilterCallback;
136 global $wgUseLatin1;
138 $sk = $wgUser->getSkin();
139 $isConflict = false;
140 // css / js subpages of user pages get a special treatment
141 $isCssJsSubpage = (Namespace::getUser() == $wgTitle->getNamespace() and preg_match("/\\.(css|js)$/", $wgTitle->getText() ));
143 if(!$this->mTitle->getArticleID()) { # new article
144 $wgOut->addWikiText(wfmsg('newarticletext'));
147 if( Namespace::isTalk( $this->mTitle->getNamespace() ) ) {
148 $wgOut->addWikiText(wfmsg('talkpagetext'));
151 # Attempt submission here. This will check for edit conflicts,
152 # and redundantly check for locked database, blocked IPs, etc.
153 # that edit() already checked just in case someone tries to sneak
154 # in the back door with a hand-edited submission URL.
156 if ( 'save' == $formtype ) {
157 # Check for spam
158 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1, $matches ) ) {
159 $this->spamPage ( $matches[0] );
160 return;
162 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section ) ) {
163 # Error messages or other handling should be performed by the filter function
164 return;
166 if ( $wgUser->isBlocked() ) {
167 $this->blockedIPpage();
168 return;
170 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
171 $this->userNotLoggedInPage();
172 return;
174 if ( wfReadOnly() ) {
175 $wgOut->readOnlyPage();
176 return;
179 # If article is new, insert it.
180 $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
181 if ( 0 == $aid ) {
182 # Don't save a new article if it's blank.
183 if ( ( '' == $this->textbox1 ) ||
184 ( wfMsg( 'newarticletext' ) == $this->textbox1 ) ) {
185 $wgOut->redirect( $this->mTitle->getFullURL() );
186 return;
188 if (wfRunHooks('ArticleSave', $this->mArticle, $wgUser, $this->textbox1,
189 $this->summary, $this->minoredit, $this->watchthis, NULL))
191 $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
192 $this->minoredit, $this->watchthis );
193 wfRunHooks('ArticleSaveComplete', $this->mArticle, $wgUser, $this->textbox1,
194 $this->summary, $this->minoredit, $this->watchthis, NULL);
196 return;
199 # Article exists. Check for edit conflict.
201 $this->mArticle->clear(); # Force reload of dates, etc.
202 $this->mArticle->forUpdate( true ); # Lock the article
204 if( ( $this->section != 'new' ) &&
205 ($this->mArticle->getTimestamp() != $this->edittime ) ) {
206 $isConflict = true;
208 $userid = $wgUser->getID();
210 if ( $isConflict) {
211 $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
212 $this->section, $this->textbox1, $this->summary, $this->edittime);
214 else {
215 $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
216 $this->section, $this->textbox1, $this->summary);
218 # Suppress edit conflict with self
220 if ( ( 0 != $userid ) && ( $this->mArticle->getUser() == $userid ) ) {
221 $isConflict = false;
222 } else {
223 # switch from section editing to normal editing in edit conflict
224 if($isConflict) {
225 # Attempt merge
226 if( $this->mergeChangesInto( $text ) ){
227 // Successful merge! Maybe we should tell the user the good news?
228 $isConflict = false;
229 } else {
230 $this->section = '';
231 $this->textbox1 = $text;
235 if ( ! $isConflict ) {
236 # All's well
237 $sectionanchor = '';
238 if( $this->section == 'new' ) {
239 if( $this->summary != '' ) {
240 $sectionanchor = $this->sectionAnchor( $this->summary );
242 } elseif( $this->section != '' ) {
243 # Try to get a section anchor from the section source, redirect to edited section if header found
244 # XXX: might be better to integrate this into Article::getTextOfLastEditWithSectionReplacedOrAdded
245 # for duplicate heading checking and maybe parsing
246 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );
247 # we can't deal with anchors, includes, html etc in the header for now,
248 # headline would need to be parsed to improve this
249 #if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) {
250 if($hasmatch and strlen($matches[2]) > 0) {
251 $sectionanchor = $this->sectionAnchor( $matches[2] );
255 if (wfRunHooks('ArticleSave', $this, $wgUser, $text, $this->summary,
256 $this->minoredit, $this->watchthis, $sectionanchor))
258 # update the article here
259 if($this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,
260 $this->watchthis, '', $sectionanchor ))
262 wfRunHooks('ArticleSaveComplete', $this, $wgUser, $text, $this->summary,
263 $this->minoredit, $this->watchthis, $sectionanchor);
264 return;
266 else
267 $isConflict = true;
271 # First time through: get contents, set time for conflict
272 # checking, etc.
274 if ( 'initial' == $formtype ) {
275 $this->edittime = $this->mArticle->getTimestamp();
276 $this->textbox1 = $this->mArticle->getContent( true );
277 $this->summary = '';
278 $this->proxyCheck();
280 $wgOut->setRobotpolicy( 'noindex,nofollow' );
282 # Enabled article-related sidebar, toplinks, etc.
283 $wgOut->setArticleRelated( true );
285 if ( $isConflict ) {
286 $s = wfMsg( 'editconflict', $this->mTitle->getPrefixedText() );
287 $wgOut->setPageTitle( $s );
288 $wgOut->addHTML( wfMsg( 'explainconflict' ) );
290 $this->textbox2 = $this->textbox1;
291 $this->textbox1 = $this->mArticle->getContent( true );
292 $this->edittime = $this->mArticle->getTimestamp();
293 } else {
295 if( $this->section != '' ) {
296 if( $this->section == 'new' ) {
297 $s = wfMsg('editingcomment', $this->mTitle->getPrefixedText() );
298 } else {
299 $s = wfMsg('editingsection', $this->mTitle->getPrefixedText() );
301 if(!$this->preview) {
302 preg_match( "/^(=+)(.+)\\1/mi",
303 $this->textbox1,
304 $matches );
305 if( !empty( $matches[2] ) ) {
306 $this->summary = "/* ". trim($matches[2])." */ ";
309 } else {
310 $s = wfMsg( 'editing', $this->mTitle->getPrefixedText() );
312 $wgOut->setPageTitle( $s );
313 if ( !$wgUseLatin1 && !$this->checkUnicodeCompliantBrowser() ) {
314 $this->mArticle->setOldSubtitle();
315 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
317 if ( $this->oldid ) {
318 $this->mArticle->setOldSubtitle();
319 $wgOut->addHTML( wfMsg( 'editingold' ) );
323 if( wfReadOnly() ) {
324 $wgOut->addHTML( '<strong>' .
325 wfMsg( 'readonlywarning' ) .
326 "</strong>" );
327 } else if ( $isCssJsSubpage and 'preview' != $formtype) {
328 $wgOut->addHTML( wfMsg( 'usercssjsyoucanpreview' ));
330 if( $this->mTitle->isProtected('edit') ) {
331 $wgOut->addHTML( '<strong>' . wfMsg( 'protectedpagewarning' ) .
332 "</strong><br />\n" );
335 $kblength = (int)(strlen( $this->textbox1 ) / 1024);
336 if( $kblength > 29 ) {
337 $wgOut->addHTML( '<strong>' .
338 wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) )
339 . '</strong>' );
342 $rows = $wgUser->getOption( 'rows' );
343 $cols = $wgUser->getOption( 'cols' );
345 $ew = $wgUser->getOption( 'editwidth' );
346 if ( $ew ) $ew = " style=\"width:100%\"";
347 else $ew = '';
349 $q = 'action=submit';
350 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
351 $action = $this->mTitle->escapeLocalURL( $q );
353 $summary = wfMsg('summary');
354 $subject = wfMsg('subject');
355 $minor = wfMsg('minoredit');
356 $watchthis = wfMsg ('watchthis');
357 $save = wfMsg('savearticle');
358 $prev = wfMsg('showpreview');
360 $cancel = $sk->makeKnownLink( $this->mTitle->getPrefixedText(),
361 wfMsg('cancel') );
362 $edithelpurl = $sk->makeUrl( wfMsg( 'edithelppage' ));
363 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
364 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
365 htmlspecialchars( wfMsg( 'newwindow' ) );
367 global $wgRightsText;
368 $copywarn = "<div id=\"editpage-copywarn\">\n" .
369 wfMsg( $wgRightsText ? 'copyrightwarning' : 'copyrightwarning2',
370 '[[' . wfMsg( 'copyrightpage' ) . ']]',
371 $wgRightsText ) . "\n</div>";
373 if( $wgUser->getOption('showtoolbar') and !$isCssJsSubpage ) {
374 # prepare toolbar for edit buttons
375 $toolbar = $this->getEditToolbar();
376 } else {
377 $toolbar = '';
380 // activate checkboxes if user wants them to be always active
381 if( !$this->preview ) {
382 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis = true;
383 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit = true;
385 // activate checkbox also if user is already watching the page,
386 // require wpWatchthis to be unset so that second condition is not
387 // checked unnecessarily
388 if( !$this->watchthis && $this->mTitle->userIsWatching() ) $this->watchthis = true;
391 $minoredithtml = '';
393 if ( 0 != $wgUser->getID() || $wgAllowAnonymousMinor ) {
394 $minoredithtml =
395 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?" checked='checked'":"").
396 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
397 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
400 $watchhtml = '';
402 if ( 0 != $wgUser->getID() ) {
403 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".($this->watchthis?" checked='checked'":"").
404 " accesskey='".wfMsg('accesskey-watch')."' id='wpWatchthis' />".
405 "<label for='wpWatchthis' title='".wfMsg('tooltip-watch')."'>{$watchthis}</label>";
408 $checkboxhtml = $minoredithtml . $watchhtml . '<br />';
410 $wgOut->addHTML( '<div id="wikiPreview">' );
411 if ( 'preview' == $formtype) {
412 $previewOutput = $this->getPreviewText( $isConflict, $isCssJsSubpage );
413 if( $wgUser->getOption('previewontop' ) ) {
414 $wgOut->addHTML( $previewOutput );
415 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
418 $wgOut->addHTML( '</div>' );
420 # if this is a comment, show a subject line at the top, which is also the edit summary.
421 # Otherwise, show a summary field at the bottom
422 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary ) ); # FIXME
423 if( $this->section == 'new' ) {
424 $commentsubject="{$subject}: <input tabindex='1' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
425 $editsummary = '';
426 } else {
427 $commentsubject = '';
428 $editsummary="{$summary}: <input tabindex='3' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
431 if( !$this->preview ) {
432 # Don't select the edit box on preview; this interferes with seeing what's going on.
433 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
435 # Prepare a list of templates used by this page
436 $db =& wfGetDB( DB_SLAVE );
437 $page = $db->tableName( 'page' );
438 $links = $db->tableName( 'links' );
439 $id = $this->mTitle->getArticleID();
440 $sql = "SELECT page_namespace,page_title,page_id ".
441 "FROM $page,$links WHERE l_to=page_id AND l_from={$id} and page_namespace=".NS_TEMPLATE;
442 $res = $db->query( $sql, "EditPage::editform" );
444 if ( $db->numRows( $res ) ) {
445 $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
446 while ( $row = $db->fetchObject( $res ) ) {
447 if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
448 $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
451 $templates .= '</ul>';
452 } else {
453 $templates = '';
456 global $wgLivePreview, $wgStylePath;
458 * Live Preview lets us fetch rendered preview page content and
459 * add it to the page without refreshing the whole page.
460 * Set up the button for it; if not supported by the browser
461 * it will fall through to the normal form submission method.
463 if( $wgLivePreview ) {
464 $wgOut->addHTML( '<script type="text/javascript" src="' .
465 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
466 '"></script>' . "\n" );
467 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
468 $liveOnclick = 'onclick="return !livePreview('.
469 'getElementById(\'wikiPreview\'),' .
470 'editform.wpTextbox1.value,' .
471 htmlspecialchars( '"' . $liveAction . '"' ) . ')"';
472 } else {
473 $liveOnclick = '';
476 $wgOut->addHTML( <<<END
477 {$toolbar}
478 <form id="editform" name="editform" method="post" action="$action"
479 enctype="multipart/form-data">
480 {$commentsubject}
481 <textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}'
482 cols='{$cols}'{$ew}>
484 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1 ) ) .
486 </textarea>
487 <br />{$editsummary}
488 {$checkboxhtml}
489 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
490 " title=\"".wfMsg('tooltip-save')."\"/>
491 <input tabindex='6' id='wpPreview' type='submit' $liveOnclick value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
492 " title=\"".wfMsg('tooltip-preview')."\"/>
493 <em>{$cancel}</em> | <em>{$edithelp}</em>{$templates}" );
494 $wgOut->addWikiText( $copywarn );
495 $wgOut->addHTML( "
496 <input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
497 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n" );
499 if ( $isConflict ) {
500 require_once( "DifferenceEngine.php" );
501 $wgOut->addHTML( "<h2>" . wfMsg( "yourdiff" ) . "</h2>\n" );
502 DifferenceEngine::showDiff( $this->textbox2, $this->textbox1,
503 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
505 $wgOut->addHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
506 <textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
507 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox2 ) ) .
509 </textarea>" );
511 $wgOut->addHTML( "</form>\n" );
512 if($formtype =="preview" && !$wgUser->getOption("previewontop")) {
513 $wgOut->addHTML('<div id="wikiPreview">' . $previewOutput . '</div>');
517 function getPreviewText( $isConflict, $isCssJsSubpage ) {
518 global $wgOut, $wgUser, $wgTitle, $wgParser;
519 $previewhead='<h2>' . wfMsg( 'preview' ) . "</h2>\n<p><center><font color=\"#cc0000\">" .
520 wfMsg( 'note' ) . wfMsg( 'previewnote' ) . "</font></center></p>\n";
521 if ( $isConflict ) {
522 $previewhead.='<h2>' . wfMsg( 'previewconflict' ) .
523 "</h2>\n";
526 $parserOptions = ParserOptions::newFromUser( $wgUser );
527 $parserOptions->setEditSection( false );
528 $parserOptions->setEditSectionOnRightClick( false );
530 # don't parse user css/js, show message about preview
531 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
533 if ( $isCssJsSubpage ) {
534 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
535 $previewtext = wfMsg('usercsspreview');
536 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
537 $previewtext = wfMsg('userjspreview');
539 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
540 $wgOut->addHTML( $parserOutput->mText );
541 } else {
542 # if user want to see preview when he edit an article
543 if( $wgUser->getOption('previewonfirst') and ($this->textbox1 == '')) {
544 $this->textbox1 = $this->mArticle->getContent(true);
547 $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $this->textbox1 ) ."\n\n",
548 $wgTitle, $parserOptions );
550 $previewHTML = $parserOutput->mText;
551 $wgOut->addCategoryLinks($parserOutput->getCategoryLinks());
552 $wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
554 return $previewhead . $previewHTML;
558 * @todo document
560 function blockedIPpage() {
561 global $wgOut, $wgUser, $wgContLang, $wgIP;
563 $wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
564 $wgOut->setRobotpolicy( 'noindex,nofollow' );
565 $wgOut->setArticleRelated( false );
567 $id = $wgUser->blockedBy();
568 $reason = $wgUser->blockedFor();
569 $ip = $wgIP;
571 if ( is_numeric( $id ) ) {
572 $name = User::whoIs( $id );
573 } else {
574 $name = $id;
576 $link = '[[' . $wgContLang->getNsText( Namespace::getUser() ) .
577 ":{$name}|{$name}]]";
579 $wgOut->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
580 $wgOut->returnToMain( false );
584 * @todo document
586 function userNotLoggedInPage() {
587 global $wgOut, $wgUser;
589 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
590 $wgOut->setRobotpolicy( 'noindex,nofollow' );
591 $wgOut->setArticleRelated( false );
593 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
594 $wgOut->returnToMain( false );
598 * @todo document
600 function spamPage ( $match = false )
602 global $wgOut;
603 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
604 $wgOut->setRobotpolicy( 'noindex,nofollow' );
605 $wgOut->setArticleRelated( false );
607 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
608 if ( $match ) {
609 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
611 $wgOut->returnToMain( false );
615 * Forks processes to scan the originating IP for an open proxy server
616 * MemCached can be used to skip IPs that have already been scanned
618 function proxyCheck() {
619 global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
620 global $wgIP, $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
622 if ( !$wgBlockOpenProxies ) {
623 return;
626 # Get MemCached key
627 $skip = false;
628 if ( $wgUseMemCached ) {
629 $mcKey = $wgDBname.':proxy:ip:'.$wgIP;
630 $mcValue = $wgMemc->get( $mcKey );
631 if ( $mcValue ) {
632 $skip = true;
636 # Fork the processes
637 if ( !$skip ) {
638 $title = Title::makeTitle( NS_SPECIAL, 'Blockme' );
639 $iphash = md5( $wgIP . $wgProxyKey );
640 $url = $title->getFullURL( 'ip='.$iphash );
642 foreach ( $wgProxyPorts as $port ) {
643 $params = implode( ' ', array(
644 escapeshellarg( $wgProxyScriptPath ),
645 escapeshellarg( $wgIP ),
646 escapeshellarg( $port ),
647 escapeshellarg( $url )
649 exec( "php $params &>/dev/null &" );
651 # Set MemCached key
652 if ( $wgUseMemCached ) {
653 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
659 * @access private
660 * @todo document
662 function mergeChangesInto( &$text ){
663 $yourtext = $this->mArticle->fetchRevisionText();
665 $db =& wfGetDB( DB_SLAVE );
666 $oldText = $this->mArticle->fetchRevisionText(
667 $db->timestamp( $this->edittime ),
668 'rev_timestamp' );
670 if(wfMerge($oldText, $text, $yourtext, $result)){
671 $text = $result;
672 return true;
673 } else {
674 return false;
679 function checkUnicodeCompliantBrowser() {
680 global $wgBrowserBlackList;
681 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
682 foreach ( $wgBrowserBlackList as $browser ) {
683 if ( preg_match($browser, $currentbrowser) ) {
684 return false;
687 return true;
691 * Format an anchor fragment as it would appear for a given section name
692 * @param string $text
693 * @return string
694 * @access private
696 function sectionAnchor( $text ) {
697 global $wgInputEncoding;
698 $headline = do_html_entity_decode( $text, ENT_COMPAT, $wgInputEncoding );
699 # strip out HTML
700 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
701 $headline = trim( $headline );
702 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
703 $replacearray = array(
704 '%3A' => ':',
705 '%' => '.'
707 return str_replace(
708 array_keys( $replacearray ),
709 array_values( $replacearray ),
710 $sectionanchor );
714 * Shows a bulletin board style toolbar for common editing functions.
715 * It can be disabled in the user preferences.
716 * The necessary JavaScript code can be found in style/wikibits.js.
718 function getEditToolbar() {
719 global $wgStylePath, $wgLang, $wgMimeType;
722 * toolarray an array of arrays which each include the filename of
723 * the button image (without path), the opening tag, the closing tag,
724 * and optionally a sample text that is inserted between the two when no
725 * selection is highlighted.
726 * The tip text is shown when the user moves the mouse over the button.
728 * Already here are accesskeys (key), which are not used yet until someone
729 * can figure out a way to make them work in IE. However, we should make
730 * sure these keys are not defined on the edit page.
732 $toolarray=array(
733 array( 'image'=>'button_bold.png',
734 'open' => "\'\'\'",
735 'close' => "\'\'\'",
736 'sample'=> wfMsg('bold_sample'),
737 'tip' => wfMsg('bold_tip'),
738 'key' => 'B'
740 array( 'image'=>'button_italic.png',
741 'open' => "\'\'",
742 'close' => "\'\'",
743 'sample'=> wfMsg('italic_sample'),
744 'tip' => wfMsg('italic_tip'),
745 'key' => 'I'
747 array( 'image'=>'button_link.png',
748 'open' => '[[',
749 'close' => ']]',
750 'sample'=> wfMsg('link_sample'),
751 'tip' => wfMsg('link_tip'),
752 'key' => 'L'
754 array( 'image'=>'button_extlink.png',
755 'open' => '[',
756 'close' => ']',
757 'sample'=> wfMsg('extlink_sample'),
758 'tip' => wfMsg('extlink_tip'),
759 'key' => 'X'
761 array( 'image'=>'button_headline.png',
762 'open' => "\\n== ",
763 'close' => " ==\\n",
764 'sample'=> wfMsg('headline_sample'),
765 'tip' => wfMsg('headline_tip'),
766 'key' => 'H'
768 array( 'image'=>'button_image.png',
769 'open' => '[['.$wgLang->getNsText(NS_IMAGE).":",
770 'close' => ']]',
771 'sample'=> wfMsg('image_sample'),
772 'tip' => wfMsg('image_tip'),
773 'key' => 'D'
775 array( 'image' => 'button_media.png',
776 'open' => '[['.$wgLang->getNsText(NS_MEDIA).':',
777 'close' => ']]',
778 'sample'=> wfMsg('media_sample'),
779 'tip' => wfMsg('media_tip'),
780 'key' => 'M'
782 array( 'image' => 'button_math.png',
783 'open' => "\\<math\\>",
784 'close' => "\\</math\\>",
785 'sample'=> wfMsg('math_sample'),
786 'tip' => wfMsg('math_tip'),
787 'key' => 'C'
789 array( 'image' => 'button_nowiki.png',
790 'open' => "\\<nowiki\\>",
791 'close' => "\\</nowiki\\>",
792 'sample'=> wfMsg('nowiki_sample'),
793 'tip' => wfMsg('nowiki_tip'),
794 'key' => 'N'
796 array( 'image' => 'button_sig.png',
797 'open' => '--~~~~',
798 'close' => '',
799 'sample'=> '',
800 'tip' => wfMsg('sig_tip'),
801 'key' => 'Y'
803 array( 'image' => 'button_hr.png',
804 'open' => "\\n----\\n",
805 'close' => '',
806 'sample'=> '',
807 'tip' => wfMsg('hr_tip'),
808 'key' => 'R'
811 $toolbar ="<script type='text/javascript'>\n/*<![CDATA[*/\n";
813 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
814 foreach($toolarray as $tool) {
816 $image=$wgStylePath.'/common/images/'.$tool['image'];
817 $open=$tool['open'];
818 $close=$tool['close'];
819 $sample = addslashes( $tool['sample'] );
821 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
822 // Older browsers show a "speedtip" type message only for ALT.
823 // Ideally these should be different, realistically they
824 // probably don't need to be.
825 $tip = addslashes( $tool['tip'] );
827 #$key = $tool["key"];
829 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
832 $toolbar.="addInfobox('" . addslashes( wfMsg( "infobox" ) ) . "','" . addslashes(wfMsg("infobox_alert")) . "');\n";
833 $toolbar.="document.writeln(\"</div>\");\n";
835 $toolbar.="/*]]>*/\n</script>";
836 return $toolbar;
840 * Output preview text only. This can be sucked into the edit page
841 * via JavaScript, and saves the server time rendering the skin as
842 * well as theoretically being more robust on the client (doesn't
843 * disturb the edit box's undo history, won't eat your text on
844 * failure, etc).
846 * @todo This doesn't include category or interlanguage links.
847 * Would need to enhance it a bit, maybe wrap them in XML
848 * or something... that might also require more skin
849 * initialization, so check whether that's a problem.
851 function livePreview() {
852 global $wgOut;
853 $wgOut->disable();
854 header( 'Content-type: text/xml' );
855 header( 'Cache-control: no-cache' );
856 # FIXME
857 echo $this->getPreviewText( false, false );