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