removed sectionedit and commentedit messages. Replaced by editingsection and editingc...
[lhc/web/wiklou.git] / includes / EditPage.php
1 <?php
2 /**
3 * Contain the EditPage class
4 * @package MediaWiki
5 * @version $Id$
6 */
7
8 /**
9 * Splitting edit page/HTML interface from Article...
10 * The actual database and text munging is still in Article,
11 * but it should get easier to call those from alternate
12 * interfaces.
13 *
14 * @package MediaWiki
15 */
16
17 class EditPage {
18 var $mArticle;
19 var $mTitle;
20
21 # Form values
22 var $save = false, $preview = false;
23 var $minoredit = false, $watchthis = false;
24 var $textbox1 = '', $textbox2 = '', $summary = '';
25 var $edittime = '', $section = '';
26 var $oldid = 0;
27
28 /**
29 * @todo document
30 * @param $article
31 */
32 function EditPage( $article ) {
33 $this->mArticle =& $article;
34 global $wgTitle;
35 $this->mTitle =& $wgTitle;
36 }
37
38 /**
39 * This is the function that gets called for "action=edit".
40 */
41 function edit() {
42 global $wgOut, $wgUser, $wgWhitelistEdit, $wgRequest;
43 // this is not an article
44 $wgOut->setArticleFlag(false);
45
46 $this->importFormData( $wgRequest );
47
48 if ( ! $this->mTitle->userCanEdit() ) {
49 $wgOut->readOnlyPage( $this->mArticle->getContent( true ), true );
50 return;
51 }
52 if ( $wgUser->isBlocked() ) {
53 $this->blockedIPpage();
54 return;
55 }
56 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
57 $this->userNotLoggedInPage();
58 return;
59 }
60 if ( wfReadOnly() ) {
61 if( $this->save || $this->preview ) {
62 $this->editForm( 'preview' );
63 } else {
64 $wgOut->readOnlyPage( $this->mArticle->getContent( true ) );
65 }
66 return;
67 }
68 if ( $this->save ) {
69 $this->editForm( 'save' );
70 } else if ( $this->preview or $wgUser->getOption('previewonfirst')) {
71 $this->editForm( 'preview' );
72 } else { # First time through
73 $this->editForm( 'initial' );
74 }
75 }
76
77 /**
78 * @todo document
79 */
80 function importFormData( &$request ) {
81 # These fields need to be checked for encoding.
82 # Also remove trailing whitespace, but don't remove _initial_
83 # whitespace from the text boxes. This may be significant formatting.
84 $this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) );
85 $this->textbox2 = rtrim( $request->getText( 'wpTextbox2' ) );
86 $this->summary = trim( $request->getText( 'wpSummary' ) );
87
88 $this->edittime = $request->getVal( 'wpEdittime' );
89 if( !preg_match( '/^\d{14}$/', $this->edittime )) $this->edittime = '';
90
91 $this->preview = $request->getCheck( 'wpPreview' );
92 $this->save = $request->wasPosted() && !$this->preview;
93 $this->minoredit = $request->getCheck( 'wpMinoredit' );
94 $this->watchthis = $request->getCheck( 'wpWatchthis' );
95
96 $this->oldid = $request->getInt( 'oldid' );
97
98 # Section edit can come from either the form or a link
99 $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
100 }
101
102 /**
103 * Since there is only one text field on the edit form,
104 * pressing <enter> will cause the form to be submitted, but
105 * the submit button value won't appear in the query, so we
106 * Fake it here before going back to edit(). This is kind of
107 * ugly, but it helps some old URLs to still work.
108 */
109 function submit() {
110 if( !$this->preview ) $this->save = true;
111
112 $this->edit();
113 }
114
115 /**
116 * The edit form is self-submitting, so that when things like
117 * preview and edit conflicts occur, we get the same form back
118 * with the extra stuff added. Only when the final submission
119 * is made and all is well do we actually save and redirect to
120 * the newly-edited page.
121 *
122 * @param string $formtype Type of form either : save, initial or preview
123 */
124 function editForm( $formtype ) {
125 global $wgOut, $wgUser;
126 global $wgLang, $wgContLang, $wgParser, $wgTitle;
127 global $wgAllowAnonymousMinor;
128 global $wgWhitelistEdit;
129 global $wgSpamRegex, $wgFilterCallback;
130 global $wgUseLatin1;
131
132 $sk = $wgUser->getSkin();
133 $isConflict = false;
134 // css / js subpages of user pages get a special treatment
135 $isCssJsSubpage = (Namespace::getUser() == $wgTitle->getNamespace() and preg_match("/\\.(css|js)$/", $wgTitle->getText() ));
136
137 if(!$this->mTitle->getArticleID()) { # new article
138 $wgOut->addWikiText(wfmsg('newarticletext'));
139 }
140
141 if( Namespace::isTalk( $this->mTitle->getNamespace() ) ) {
142 $wgOut->addWikiText(wfmsg('talkpagetext'));
143 }
144
145 # Attempt submission here. This will check for edit conflicts,
146 # and redundantly check for locked database, blocked IPs, etc.
147 # that edit() already checked just in case someone tries to sneak
148 # in the back door with a hand-edited submission URL.
149
150 if ( 'save' == $formtype ) {
151 # Check for spam
152 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1, $matches ) ) {
153 $this->spamPage ( $matches );
154 return;
155 }
156 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section ) ) {
157 # Error messages or other handling should be performed by the filter function
158 return;
159 }
160 if ( $wgUser->isBlocked() ) {
161 $this->blockedIPpage();
162 return;
163 }
164 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
165 $this->userNotLoggedInPage();
166 return;
167 }
168 if ( wfReadOnly() ) {
169 $wgOut->readOnlyPage();
170 return;
171 }
172
173 # If article is new, insert it.
174 $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
175 if ( 0 == $aid ) {
176 # Don't save a new article if it's blank.
177 if ( ( '' == $this->textbox1 ) ||
178 ( wfMsg( 'newarticletext' ) == $this->textbox1 ) ) {
179 $wgOut->redirect( $this->mTitle->getFullURL() );
180 return;
181 }
182 $this->mArticle->insertNewArticle( $this->textbox1, $this->summary, $this->minoredit, $this->watchthis );
183 return;
184 }
185
186 # Article exists. Check for edit conflict.
187
188 $this->mArticle->clear(); # Force reload of dates, etc.
189 $this->mArticle->forUpdate( true ); # Lock the article
190
191 if( ( $this->section != 'new' ) &&
192 ($this->mArticle->getTimestamp() != $this->edittime ) ) {
193 $isConflict = true;
194 }
195 $userid = $wgUser->getID();
196
197 if ( $isConflict) {
198 $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
199 $this->section, $this->textbox1, $this->summary, $this->edittime);
200 }
201 else {
202 $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
203 $this->section, $this->textbox1, $this->summary);
204 }
205 # Suppress edit conflict with self
206
207 if ( ( 0 != $userid ) && ( $this->mArticle->getUser() == $userid ) ) {
208 $isConflict = false;
209 } else {
210 # switch from section editing to normal editing in edit conflict
211 if($isConflict) {
212 # Attempt merge
213 if( $this->mergeChangesInto( $text ) ){
214 // Successful merge! Maybe we should tell the user the good news?
215 $isConflict = false;
216 } else {
217 $this->section = '';
218 $this->textbox1 = $text;
219 }
220 }
221 }
222 if ( ! $isConflict ) {
223 # All's well
224 $sectionanchor = '';
225 if( $this->section == 'new' ) {
226 if( $this->summary != '' ) {
227 $sectionanchor = $this->sectionAnchor( $this->summary );
228 }
229 } elseif( $this->section != '' ) {
230 # Try to get a section anchor from the section source, redirect to edited section if header found
231 # XXX: might be better to integrate this into Article::getTextOfLastEditWithSectionReplacedOrAdded
232 # for duplicate heading checking and maybe parsing
233 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );
234 # we can't deal with anchors, includes, html etc in the header for now,
235 # headline would need to be parsed to improve this
236 #if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) {
237 if($hasmatch and strlen($matches[2]) > 0) {
238 $sectionanchor = $this->sectionAnchor( $matches[2] );
239 }
240 }
241
242 # update the article here
243 if($this->mArticle->updateArticle( $text, $this->summary, $this->minoredit, $this->watchthis, '', $sectionanchor ))
244 return;
245 else
246 $isConflict = true;
247 }
248 }
249 # First time through: get contents, set time for conflict
250 # checking, etc.
251
252 if ( 'initial' == $formtype ) {
253 $this->edittime = $this->mArticle->getTimestamp();
254 $this->textbox1 = $this->mArticle->getContent( true );
255 $this->summary = '';
256 $this->proxyCheck();
257 }
258 $wgOut->setRobotpolicy( 'noindex,nofollow' );
259
260 # Enabled article-related sidebar, toplinks, etc.
261 $wgOut->setArticleRelated( true );
262
263 if ( $isConflict ) {
264 $s = wfMsg( 'editconflict', $this->mTitle->getPrefixedText() );
265 $wgOut->setPageTitle( $s );
266 $wgOut->addHTML( wfMsg( 'explainconflict' ) );
267
268 $this->textbox2 = $this->textbox1;
269 $this->textbox1 = $this->mArticle->getContent( true );
270 $this->edittime = $this->mArticle->getTimestamp();
271 } else {
272
273 if( $this->section != '' ) {
274 if( $this->section == 'new' ) {
275 $s.=wfMsg('editingcomment', $this->mTitle->getPrefixedText() );
276 } else {
277 $s.=wfMsg('editingsection', $this->mTitle->getPrefixedText() );
278 }
279 if(!$this->preview) {
280 $sectitle=preg_match("/^=+(.*?)=+/mi",
281 $this->textbox1,
282 $matches);
283 if( !empty( $matches[1] ) ) {
284 $this->summary = "/* ". trim($matches[1])." */ ";
285 }
286 }
287 } else {
288 $s = wfMsg( 'editing', $this->mTitle->getPrefixedText() );
289 }
290 $wgOut->setPageTitle( $s );
291 if ( !$wgUseLatin1 && !$this->checkUnicodeCompliantBrowser() ) {
292 $this->mArticle->setOldSubtitle();
293 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
294 }
295 if ( $this->oldid ) {
296 $this->mArticle->setOldSubtitle();
297 $wgOut->addHTML( wfMsg( 'editingold' ) );
298 }
299 }
300
301 if( wfReadOnly() ) {
302 $wgOut->addHTML( '<strong>' .
303 wfMsg( 'readonlywarning' ) .
304 "</strong>" );
305 } else if ( $isCssJsSubpage and 'preview' != $formtype) {
306 $wgOut->addHTML( wfMsg( 'usercssjsyoucanpreview' ));
307 }
308 if( $this->mTitle->isProtected() ) {
309 $wgOut->addHTML( '<strong>' . wfMsg( 'protectedpagewarning' ) .
310 "</strong><br />\n" );
311 }
312
313 $kblength = (int)(strlen( $this->textbox1 ) / 1024);
314 if( $kblength > 29 ) {
315 $wgOut->addHTML( '<strong>' .
316 wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) )
317 . '</strong>' );
318 }
319
320 $rows = $wgUser->getOption( 'rows' );
321 $cols = $wgUser->getOption( 'cols' );
322
323 $ew = $wgUser->getOption( 'editwidth' );
324 if ( $ew ) $ew = " style=\"width:100%\"";
325 else $ew = '';
326
327 $q = 'action=submit';
328 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
329 $action = $this->mTitle->escapeLocalURL( $q );
330
331 $summary = wfMsg('summary');
332 $subject = wfMsg('subject');
333 $minor = wfMsg('minoredit');
334 $watchthis = wfMsg ('watchthis');
335 $save = wfMsg('savearticle');
336 $prev = wfMsg('showpreview');
337
338 $cancel = $sk->makeKnownLink( $this->mTitle->getPrefixedText(),
339 wfMsg('cancel') );
340 $edithelpurl = $sk->makeUrl( wfMsg( 'edithelppage' ));
341 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
342 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
343 htmlspecialchars( wfMsg( 'newwindow' ) );
344
345 global $wgRightsText;
346 $copywarn = "<div id=\"editpage-copywarn\">\n" .
347 wfMsg( $wgRightsText ? 'copyrightwarning' : 'copyrightwarning2',
348 '[[' . wfMsg( 'copyrightpage' ) . ']]',
349 $wgRightsText ) . "\n</div>";
350
351 if( $wgUser->getOption('showtoolbar') and !$isCssJsSubpage ) {
352 # prepare toolbar for edit buttons
353 $toolbar = $sk->getEditToolbar();
354 } else {
355 $toolbar = '';
356 }
357
358 // activate checkboxes if user wants them to be always active
359 if( !$this->preview ) {
360 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis = true;
361 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit = true;
362
363 // activate checkbox also if user is already watching the page,
364 // require wpWatchthis to be unset so that second condition is not
365 // checked unnecessarily
366 if( !$this->watchthis && $this->mTitle->userIsWatching() ) $this->watchthis = true;
367 }
368
369 $minoredithtml = '';
370
371 if ( 0 != $wgUser->getID() || $wgAllowAnonymousMinor ) {
372 $minoredithtml =
373 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?" checked='checked'":"").
374 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
375 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
376 }
377
378 $watchhtml = '';
379
380 if ( 0 != $wgUser->getID() ) {
381 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".($this->watchthis?" checked='checked'":"").
382 " accesskey='".wfMsg('accesskey-watch')."' id='wpWatchthis' />".
383 "<label for='wpWatchthis' title='".wfMsg('tooltip-watch')."'>{$watchthis}</label>";
384 }
385
386 $checkboxhtml = $minoredithtml . $watchhtml . '<br />';
387
388 if ( 'preview' == $formtype) {
389 $previewhead='<h2>' . wfMsg( 'preview' ) . "</h2>\n<p><center><font color=\"#cc0000\">" .
390 wfMsg( 'note' ) . wfMsg( 'previewnote' ) . "</font></center></p>\n";
391 if ( $isConflict ) {
392 $previewhead.='<h2>' . wfMsg( 'previewconflict' ) .
393 "</h2>\n";
394 }
395
396 $parserOptions = ParserOptions::newFromUser( $wgUser );
397 $parserOptions->setEditSection( false );
398 $parserOptions->setEditSectionOnRightClick( false );
399
400 # don't parse user css/js, show message about preview
401 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
402
403 if ( $isCssJsSubpage ) {
404 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
405 $previewtext = wfMsg('usercsspreview');
406 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
407 $previewtext = wfMsg('userjspreview');
408 }
409 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
410 $wgOut->addHTML( $parserOutput->mText );
411 } else {
412 # if user want to see preview when he edit an article
413 if( $wgUser->getOption('previewonfirst') and ($this->textbox1 == '')) {
414 $this->textbox1 = $this->mArticle->getContent(true);
415 }
416
417 $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $this->textbox1 ) ."\n\n",
418 $wgTitle, $parserOptions );
419
420 $previewHTML = $parserOutput->mText;
421
422 if($wgUser->getOption('previewontop')) {
423 $wgOut->addHTML($previewhead);
424 $wgOut->addHTML($previewHTML);
425 }
426 $wgOut->addCategoryLinks($parserOutput->getCategoryLinks());
427 $wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
428 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
429 }
430 }
431
432 # if this is a comment, show a subject line at the top, which is also the edit summary.
433 # Otherwise, show a summary field at the bottom
434 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary ) ); # FIXME
435 if( $this->section == 'new' ) {
436 $commentsubject="{$subject}: <input tabindex='1' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
437 $editsummary = '';
438 } else {
439 $commentsubject = '';
440 $editsummary="{$summary}: <input tabindex='3' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
441 }
442
443 if( !$this->preview ) {
444 # Don't select the edit box on preview; this interferes with seeing what's going on.
445 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
446 }
447 # Prepare a list of templates used by this page
448 $db =& wfGetDB( DB_SLAVE );
449 $cur = $db->tableName( 'cur' );
450 $links = $db->tableName( 'links' );
451 $id = $this->mTitle->getArticleID();
452 $sql = "SELECT cur_namespace,cur_title,cur_id ".
453 "FROM $cur,$links WHERE l_to=cur_id AND l_from={$id} and cur_namespace=".NS_TEMPLATE;
454 $res = $db->query( $sql, "EditPage::editform" );
455
456 if ( $db->numRows( $res ) ) {
457 $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
458 while ( $row = $db->fetchObject( $res ) ) {
459 if ( $titleObj = Title::makeTitle( $row->cur_namespace, $row->cur_title ) ) {
460 $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
461 }
462 }
463 $templates .= '</ul>';
464 } else {
465 $templates = '';
466 }
467 $wgOut->addHTML( "
468 {$toolbar}
469 <form id=\"editform\" name=\"editform\" method=\"post\" action=\"$action\"
470 enctype=\"multipart/form-data\">
471 {$commentsubject}
472 <textarea tabindex='1' accesskey=\",\" name=\"wpTextbox1\" rows='{$rows}'
473 cols='{$cols}'{$ew}>" .
474 htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1 ) ) .
475 "
476 </textarea>
477 <br />{$editsummary}
478 {$checkboxhtml}
479 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
480 " title=\"".wfMsg('tooltip-save')."\"/>
481 <input tabindex='6' id='wpPreview' type='submit' value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
482 " title=\"".wfMsg('tooltip-preview')."\"/>
483 <em>{$cancel}</em> | <em>{$edithelp}</em>{$templates}" );
484 $wgOut->addWikiText( $copywarn );
485 $wgOut->addHTML( "
486 <input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
487 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n" );
488
489 if ( $isConflict ) {
490 require_once( "DifferenceEngine.php" );
491 $wgOut->addHTML( "<h2>" . wfMsg( "yourdiff" ) . "</h2>\n" );
492 DifferenceEngine::showDiff( $this->textbox2, $this->textbox1,
493 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
494
495 $wgOut->addHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
496 <textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
497 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox2 ) ) .
498 "
499 </textarea>" );
500 }
501 $wgOut->addHTML( "</form>\n" );
502 if($formtype =="preview" && !$wgUser->getOption("previewontop")) {
503 $wgOut->addHTML($previewhead);
504 $wgOut->addHTML($previewHTML);
505 }
506 }
507
508 /**
509 * @todo document
510 */
511 function blockedIPpage() {
512 global $wgOut, $wgUser, $wgContLang, $wgIP;
513
514 $wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
515 $wgOut->setRobotpolicy( 'noindex,nofollow' );
516 $wgOut->setArticleRelated( false );
517
518 $id = $wgUser->blockedBy();
519 $reason = $wgUser->blockedFor();
520 $ip = $wgIP;
521
522 if ( is_numeric( $id ) ) {
523 $name = User::whoIs( $id );
524 } else {
525 $name = $id;
526 }
527 $link = '[[' . $wgContLang->getNsText( Namespace::getUser() ) .
528 ":{$name}|{$name}]]";
529
530 $wgOut->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
531 $wgOut->returnToMain( false );
532 }
533
534 /**
535 * @todo document
536 */
537 function userNotLoggedInPage() {
538 global $wgOut, $wgUser;
539
540 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
541 $wgOut->setRobotpolicy( 'noindex,nofollow' );
542 $wgOut->setArticleRelated( false );
543
544 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
545 $wgOut->returnToMain( false );
546 }
547
548 /**
549 * @todo document
550 */
551 function spamPage ( $matches = array() )
552 {
553 global $wgOut;
554 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
555 $wgOut->setRobotpolicy( 'noindex,nofollow' );
556 $wgOut->setArticleRelated( false );
557
558 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
559 if ( isset ( $matches[0] ) ) {
560 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$matches[0]}</nowiki>" ) );
561 }
562 $wgOut->returnToMain( false );
563 }
564
565 /**
566 * Forks processes to scan the originating IP for an open proxy server
567 * MemCached can be used to skip IPs that have already been scanned
568 */
569 function proxyCheck() {
570 global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
571 global $wgIP, $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
572
573 if ( !$wgBlockOpenProxies ) {
574 return;
575 }
576
577 # Get MemCached key
578 $skip = false;
579 if ( $wgUseMemCached ) {
580 $mcKey = $wgDBname.':proxy:ip:'.$wgIP;
581 $mcValue = $wgMemc->get( $mcKey );
582 if ( $mcValue ) {
583 $skip = true;
584 }
585 }
586
587 # Fork the processes
588 if ( !$skip ) {
589 $title = Title::makeTitle( NS_SPECIAL, 'Blockme' );
590 $iphash = md5( $wgIP . $wgProxyKey );
591 $url = $title->getFullURL( 'ip='.$iphash );
592
593 foreach ( $wgProxyPorts as $port ) {
594 $params = implode( ' ', array(
595 escapeshellarg( $wgProxyScriptPath ),
596 escapeshellarg( $wgIP ),
597 escapeshellarg( $port ),
598 escapeshellarg( $url )
599 ));
600 exec( "php $params &>/dev/null &" );
601 }
602 # Set MemCached key
603 if ( $wgUseMemCached ) {
604 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
605 }
606 }
607 }
608
609 /**
610 * @access private
611 * @todo document
612 */
613 function mergeChangesInto( &$text ){
614 $fname = 'EditPage::mergeChangesInto';
615 $oldDate = $this->edittime;
616 $dbw =& wfGetDB( DB_MASTER );
617 $obj = $dbw->selectRow( 'cur', array( 'cur_text' ), array( 'cur_id' => $this->mTitle->getArticleID() ),
618 $fname, 'FOR UPDATE' );
619
620 $yourtext = $obj->cur_text;
621 $ns = $this->mTitle->getNamespace();
622 $title = $this->mTitle->getDBkey();
623 $obj = $dbw->selectRow( 'old',
624 array( 'old_text','old_flags'),
625 array( 'old_namespace' => $ns, 'old_title' => $title,
626 'old_timestamp' => $dbw->timestamp($oldDate)),
627 $fname );
628 $oldText = Article::getRevisionText( $obj );
629
630 if(wfMerge($oldText, $text, $yourtext, $result)){
631 $text = $result;
632 return true;
633 } else {
634 return false;
635 }
636 }
637
638
639 function checkUnicodeCompliantBrowser() {
640 global $wgBrowserBlackList;
641 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
642 foreach ( $wgBrowserBlackList as $browser ) {
643 if ( preg_match($browser, $currentbrowser) ) {
644 return false;
645 }
646 }
647 return true;
648 }
649
650 /**
651 * Format an anchor fragment as it would appear for a given section name
652 * @param string $text
653 * @return string
654 * @access private
655 */
656 function sectionAnchor( $text ) {
657 global $wgInputEncoding;
658 $headline = do_html_entity_decode( $text, ENT_COMPAT, $wgInputEncoding );
659 # strip out HTML
660 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
661 $headline = trim( $headline );
662 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
663 $replacearray = array(
664 '%3A' => ':',
665 '%' => '.'
666 );
667 return str_replace(
668 array_keys( $replacearray ),
669 array_values( $replacearray ),
670 $sectionanchor );
671 }
672 }
673
674 ?>