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