Fix bug 56, which causes sections to be dropped or duplicated
[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 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, $wgParser, $wgTitle;
126 global $wgAllowAnonymousMinor;
127 global $wgWhitelistEdit;
128 global $wgSpamRegex, $wgFilterCallback;
129
130 $sk = $wgUser->getSkin();
131 $isConflict = false;
132 // css / js subpages of user pages get a special treatment
133 $isCssJsSubpage = (Namespace::getUser() == $wgTitle->getNamespace() and preg_match("/\\.(css|js)$/", $wgTitle->getText() ));
134
135 if(!$this->mTitle->getArticleID()) { # new article
136 $wgOut->addWikiText(wfmsg('newarticletext'));
137 }
138
139 if( Namespace::isTalk( $this->mTitle->getNamespace() ) ) {
140 $wgOut->addWikiText(wfmsg('talkpagetext'));
141 }
142
143 # Attempt submission here. This will check for edit conflicts,
144 # and redundantly check for locked database, blocked IPs, etc.
145 # that edit() already checked just in case someone tries to sneak
146 # in the back door with a hand-edited submission URL.
147
148 if ( 'save' == $formtype ) {
149 # Check for spam
150 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1, $matches ) ) {
151 $this->spamPage ( $matches );
152 return;
153 }
154 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section ) ) {
155 # Error messages or other handling should be performed by the filter function
156 return;
157 }
158 if ( $wgUser->isBlocked() ) {
159 $this->blockedIPpage();
160 return;
161 }
162 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
163 $this->userNotLoggedInPage();
164 return;
165 }
166 if ( wfReadOnly() ) {
167 $wgOut->readOnlyPage();
168 return;
169 }
170
171 # If article is new, insert it.
172 $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
173 if ( 0 == $aid ) {
174 # Don't save a new article if it's blank.
175 if ( ( '' == $this->textbox1 ) ||
176 ( wfMsg( 'newarticletext' ) == $this->textbox1 ) ) {
177 $wgOut->redirect( $this->mTitle->getFullURL() );
178 return;
179 }
180 $this->mArticle->insertNewArticle( $this->textbox1, $this->summary, $this->minoredit, $this->watchthis );
181 return;
182 }
183
184 # Article exists. Check for edit conflict.
185
186 $this->mArticle->clear(); # Force reload of dates, etc.
187 $this->mArticle->forUpdate( true ); # Lock the article
188
189 if( ( $this->section != 'new' ) &&
190 ($this->mArticle->getTimestamp() != $this->edittime ) ) {
191 $isConflict = true;
192 }
193 $userid = $wgUser->getID();
194
195 if ( $isConflict) {
196 $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
197 $this->section, $this->textbox1, $this->summary, $this->edittime);
198 }
199 else {
200 $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
201 $this->section, $this->textbox1, $this->summary);
202 }
203 # Suppress edit conflict with self
204
205 if ( ( 0 != $userid ) && ( $this->mArticle->getUser() == $userid ) ) {
206 $isConflict = false;
207 } else {
208 # switch from section editing to normal editing in edit conflict
209 if($isConflict) {
210 # Attempt merge
211 if( $this->mergeChangesInto( $text ) ){
212 // Successful merge! Maybe we should tell the user the good news?
213 $isConflict = false;
214 } else {
215 $this->section = '';
216 $this->textbox1 = $text;
217 }
218 }
219 }
220 if ( ! $isConflict ) {
221 # All's well
222 $sectionanchor = '';
223 if( $this->section != '' ) {
224 # Try to get a section anchor from the section source, redirect to edited section if header found
225 # XXX: might be better to integrate this into Article::getTextOfLastEditWithSectionReplacedOrAdded
226 # for duplicate heading checking and maybe parsing
227 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );
228 # we can't deal with anchors, includes, html etc in the header for now,
229 # headline would need to be parsed to improve this
230 #if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) {
231 if($hasmatch and strlen($matches[2]) > 0) {
232 global $wgInputEncoding;
233 $headline = do_html_entity_decode( $matches[2], ENT_COMPAT, $wgInputEncoding );
234 # strip out HTML
235 $headline = preg_replace( "/<.*?" . ">/","",$headline );
236 $headline = trim( $headline );
237 $sectionanchor = '#'.urlencode( str_replace(' ', '_', $headline ) );
238 $replacearray = array(
239 '%3A' => ':',
240 '%' => '.'
241 );
242 $sectionanchor = str_replace(array_keys($replacearray),array_values($replacearray),$sectionanchor);
243 }
244 }
245
246 # update the article here
247 if($this->mArticle->updateArticle( $text, $this->summary, $this->minoredit, $this->watchthis, '', $sectionanchor ))
248 return;
249 else
250 $isConflict = true;
251 }
252 }
253 # First time through: get contents, set time for conflict
254 # checking, etc.
255
256 if ( 'initial' == $formtype ) {
257 $this->edittime = $this->mArticle->getTimestamp();
258 $this->textbox1 = $this->mArticle->getContent( true );
259 $this->summary = '';
260 $this->proxyCheck();
261 }
262 $wgOut->setRobotpolicy( 'noindex,nofollow' );
263
264 # Enabled article-related sidebar, toplinks, etc.
265 $wgOut->setArticleRelated( true );
266
267 if ( $isConflict ) {
268 $s = wfMsg( 'editconflict', $this->mTitle->getPrefixedText() );
269 $wgOut->setPageTitle( $s );
270 $wgOut->addHTML( wfMsg( 'explainconflict' ) );
271
272 $this->textbox2 = $this->textbox1;
273 $this->textbox1 = $this->mArticle->getContent( true );
274 $this->edittime = $this->mArticle->getTimestamp();
275 } else {
276 $s = wfMsg( 'editing', $this->mTitle->getPrefixedText() );
277
278 if( $this->section != '' ) {
279 if( $this->section == 'new' ) {
280 $s.=wfMsg('commentedit');
281 } else {
282 $s.=wfMsg('sectionedit');
283 }
284 if(!$this->preview) {
285 $sectitle=preg_match("/^=+(.*?)=+/mi",
286 $this->textbox1,
287 $matches);
288 if( !empty( $matches[1] ) ) {
289 $this->summary = "/* ". trim($matches[1])." */ ";
290 }
291 }
292 }
293 $wgOut->setPageTitle( $s );
294 if ( $this->oldid ) {
295 $this->mArticle->setOldSubtitle();
296 $wgOut->addHTML( wfMsg( 'editingold' ) );
297 }
298 }
299
300 if( wfReadOnly() ) {
301 $wgOut->addHTML( '<strong>' .
302 wfMsg( 'readonlywarning' ) .
303 "</strong>" );
304 } else if ( $isCssJsSubpage and 'preview' != $formtype) {
305 $wgOut->addHTML( wfMsg( 'usercssjsyoucanpreview' ));
306 }
307 if( $this->mTitle->isProtected() ) {
308 $wgOut->addHTML( '<strong>' . wfMsg( 'protectedpagewarning' ) .
309 "</strong><br />\n" );
310 }
311
312 $kblength = (int)(strlen( $this->textbox1 ) / 1024);
313 if( $kblength > 29 ) {
314 $wgOut->addHTML( '<strong>' .
315 wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) )
316 . '</strong>' );
317 }
318
319 $rows = $wgUser->getOption( 'rows' );
320 $cols = $wgUser->getOption( 'cols' );
321
322 $ew = $wgUser->getOption( 'editwidth' );
323 if ( $ew ) $ew = " style=\"width:100%\"";
324 else $ew = '';
325
326 $q = 'action=submit';
327 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
328 $action = $this->mTitle->escapeLocalURL( $q );
329
330 $summary = wfMsg('summary');
331 $subject = wfMsg('subject');
332 $minor = wfMsg('minoredit');
333 $watchthis = wfMsg ('watchthis');
334 $save = wfMsg('savearticle');
335 $prev = wfMsg('showpreview');
336
337 $cancel = $sk->makeKnownLink( $this->mTitle->getPrefixedText(),
338 wfMsg('cancel') );
339 $edithelpurl = $sk->makeUrl( wfMsg( 'edithelppage' ));
340 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
341 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
342 htmlspecialchars( wfMsg( 'newwindow' ) );
343
344 global $wgRightsText;
345 $copywarn = "<div id=\"editpage-copywarn\">\n" .
346 wfMsg( $wgRightsText ? 'copyrightwarning' : 'copyrightwarning2',
347 '[[' . wfMsg( 'copyrightpage' ) . ']]',
348 $wgRightsText ) . "\n</div>";
349
350 if( $wgUser->getOption('showtoolbar') and !$isCssJsSubpage ) {
351 # prepare toolbar for edit buttons
352 $toolbar = $sk->getEditToolbar();
353 } else {
354 $toolbar = '';
355 }
356
357 // activate checkboxes if user wants them to be always active
358 if( !$this->preview ) {
359 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis = true;
360 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit = true;
361
362 // activate checkbox also if user is already watching the page,
363 // require wpWatchthis to be unset so that second condition is not
364 // checked unnecessarily
365 if( !$this->watchthis && $this->mTitle->userIsWatching() ) $this->watchthis = true;
366 }
367
368 $minoredithtml = '';
369
370 if ( 0 != $wgUser->getID() || $wgAllowAnonymousMinor ) {
371 $minoredithtml =
372 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?" checked='checked'":"").
373 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
374 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
375 }
376
377 $watchhtml = '';
378
379 if ( 0 != $wgUser->getID() ) {
380 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".($this->watchthis?" checked='checked'":"").
381 " accesskey='".wfMsg('accesskey-watch')."' id='wpWatchthis' />".
382 "<label for='wpWatchthis' title='".wfMsg('tooltip-watch')."'>{$watchthis}</label>";
383 }
384
385 $checkboxhtml = $minoredithtml . $watchhtml . '<br />';
386
387 if ( 'preview' == $formtype) {
388 $previewhead='<h2>' . wfMsg( 'preview' ) . "</h2>\n<p><center><font color=\"#cc0000\">" .
389 wfMsg( 'note' ) . wfMsg( 'previewnote' ) . "</font></center></p>\n";
390 if ( $isConflict ) {
391 $previewhead.='<h2>' . wfMsg( 'previewconflict' ) .
392 "</h2>\n";
393 }
394
395 $parserOptions = ParserOptions::newFromUser( $wgUser );
396 $parserOptions->setEditSection( false );
397 $parserOptions->setEditSectionOnRightClick( false );
398
399 # don't parse user css/js, show message about preview
400 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
401
402 if ( $isCssJsSubpage ) {
403 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
404 $previewtext = wfMsg('usercsspreview');
405 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
406 $previewtext = wfMsg('userjspreview');
407 }
408 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
409 $wgOut->addHTML( $parserOutput->mText );
410 } else {
411 # if user want to see preview when he edit an article
412 if( $wgUser->getOption('previewonfirst') and ($this->textbox1 == '')) {
413 $this->textbox1 = $this->mArticle->getContent(true);
414 }
415
416 $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $this->textbox1 ) ."\n\n",
417 $wgTitle, $parserOptions );
418
419 $previewHTML = $parserOutput->mText;
420
421 if($wgUser->getOption('previewontop')) {
422 $wgOut->addHTML($previewhead);
423 $wgOut->addHTML($previewHTML);
424 }
425 $wgOut->addCategoryLinks($parserOutput->getCategoryLinks());
426 $wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
427 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
428 }
429 }
430
431 # if this is a comment, show a subject line at the top, which is also the edit summary.
432 # Otherwise, show a summary field at the bottom
433 $summarytext = htmlspecialchars( $wgLang->recodeForEdit( $this->summary ) ); # FIXME
434 if( $this->section == 'new' ) {
435 $commentsubject="{$subject}: <input tabindex='1' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
436 $editsummary = '';
437 } else {
438 $commentsubject = '';
439 $editsummary="{$summary}: <input tabindex='3' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
440 }
441
442 if( !$this->preview ) {
443 # Don't select the edit box on preview; this interferes with seeing what's going on.
444 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
445 }
446 # Prepare a list of templates used by this page
447 $db =& wfGetDB( DB_SLAVE );
448 $cur = $db->tableName( 'cur' );
449 $links = $db->tableName( 'links' );
450 $id = $this->mTitle->getArticleID();
451 $sql = "SELECT cur_namespace,cur_title,cur_id ".
452 "FROM $cur,$links WHERE l_to=cur_id AND l_from={$id} and cur_namespace=".NS_TEMPLATE;
453 $res = $db->query( $sql, "EditPage::editform" );
454
455 if ( $db->numRows( $res ) ) {
456 $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
457 while ( $row = $db->fetchObject( $res ) ) {
458 if ( $titleObj = Title::makeTitle( $row->cur_namespace, $row->cur_title ) ) {
459 $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
460 }
461 }
462 $templates .= '</ul>';
463 } else {
464 $templates = '';
465 }
466 $wgOut->addHTML( "
467 {$toolbar}
468 <form id=\"editform\" name=\"editform\" method=\"post\" action=\"$action\"
469 enctype=\"application/x-www-form-urlencoded\">
470 {$commentsubject}
471 <textarea tabindex='1' accesskey=\",\" name=\"wpTextbox1\" rows='{$rows}'
472 cols='{$cols}'{$ew}>" .
473 htmlspecialchars( $wgLang->recodeForEdit( $this->textbox1 ) ) .
474 "
475 </textarea>
476 <br />{$editsummary}
477 {$checkboxhtml}
478 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
479 " title=\"".wfMsg('tooltip-save')."\"/>
480 <input tabindex='6' id='wpPreview' type='submit' value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
481 " title=\"".wfMsg('tooltip-preview')."\"/>
482 <em>{$cancel}</em> | <em>{$edithelp}</em>{$templates}" );
483 $wgOut->addWikiText( $copywarn );
484 $wgOut->addHTML( "
485 <input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
486 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n" );
487
488 if ( $isConflict ) {
489 require_once( "DifferenceEngine.php" );
490 $wgOut->addHTML( "<h2>" . wfMsg( "yourdiff" ) . "</h2>\n" );
491 DifferenceEngine::showDiff( $this->textbox2, $this->textbox1,
492 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
493
494 $wgOut->addHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
495 <textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
496 . htmlspecialchars( $wgLang->recodeForEdit( $this->textbox2 ) ) .
497 "
498 </textarea>" );
499 }
500 $wgOut->addHTML( "</form>\n" );
501 if($formtype =="preview" && !$wgUser->getOption("previewontop")) {
502 $wgOut->addHTML($previewhead);
503 $wgOut->addHTML($previewHTML);
504 }
505 }
506
507 /**
508 * @todo document
509 */
510 function blockedIPpage() {
511 global $wgOut, $wgUser, $wgLang, $wgIP;
512
513 $wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
514 $wgOut->setRobotpolicy( 'noindex,nofollow' );
515 $wgOut->setArticleRelated( false );
516
517 $id = $wgUser->blockedBy();
518 $reason = $wgUser->blockedFor();
519 $ip = $wgIP;
520
521 if ( is_numeric( $id ) ) {
522 $name = User::whoIs( $id );
523 } else {
524 $name = $id;
525 }
526 $link = '[[' . $wgLang->getNsText( Namespace::getUser() ) .
527 ":{$name}|{$name}]]";
528
529 $wgOut->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
530 $wgOut->returnToMain( false );
531 }
532
533 /**
534 * @todo document
535 */
536 function userNotLoggedInPage() {
537 global $wgOut, $wgUser, $wgLang;
538
539 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
540 $wgOut->setRobotpolicy( 'noindex,nofollow' );
541 $wgOut->setArticleRelated( false );
542
543 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
544 $wgOut->returnToMain( false );
545 }
546
547 /**
548 * @todo document
549 */
550 function spamPage ( $matches = array() )
551 {
552 global $wgOut;
553 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
554 $wgOut->setRobotpolicy( 'noindex,nofollow' );
555 $wgOut->setArticleRelated( false );
556
557 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
558 if ( isset ( $matches[0] ) ) {
559 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$matches[0]}</nowiki>" ) );
560 }
561 $wgOut->returnToMain( false );
562 }
563
564 /**
565 * Forks processes to scan the originating IP for an open proxy server
566 * MemCached can be used to skip IPs that have already been scanned
567 */
568 function proxyCheck() {
569 global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
570 global $wgIP, $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
571
572 if ( !$wgBlockOpenProxies ) {
573 return;
574 }
575
576 # Get MemCached key
577 $skip = false;
578 if ( $wgUseMemCached ) {
579 $mcKey = $wgDBname.':proxy:ip:'.$wgIP;
580 $mcValue = $wgMemc->get( $mcKey );
581 if ( $mcValue ) {
582 $skip = true;
583 }
584 }
585
586 # Fork the processes
587 if ( !$skip ) {
588 $title = Title::makeTitle( NS_SPECIAL, 'Blockme' );
589 $iphash = md5( $wgIP . $wgProxyKey );
590 $url = $title->getFullURL( 'ip='.$iphash );
591
592 foreach ( $wgProxyPorts as $port ) {
593 $params = implode( ' ', array(
594 escapeshellarg( $wgProxyScriptPath ),
595 escapeshellarg( $wgIP ),
596 escapeshellarg( $port ),
597 escapeshellarg( $url )
598 ));
599 exec( "php $params &>/dev/null &" );
600 }
601 # Set MemCached key
602 if ( $wgUseMemCached ) {
603 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
604 }
605 }
606 }
607
608 /**
609 * @access private
610 * @todo document
611 */
612 function mergeChangesInto( &$text ){
613 $fname = 'EditPage::mergeChangesInto';
614 $oldDate = $this->edittime;
615 $dbw =& wfGetDB( DB_MASTER );
616 $obj = $dbw->getArray( 'cur', array( 'cur_text' ), array( 'cur_id' => $this->mTitle->getArticleID() ),
617 $fname, 'FOR UPDATE' );
618
619 $yourtext = $obj->cur_text;
620 $ns = $this->mTitle->getNamespace();
621 $title = $this->mTitle->getDBkey();
622 $obj = $dbw->getArray( 'old',
623 array( 'old_text','old_flags'),
624 array( 'old_namespace' => $ns, 'old_title' => $title,
625 'old_timestamp' => $dbw->timestamp($oldDate)),
626 $fname );
627 $oldText = Article::getRevisionText( $obj );
628
629 if(wfMerge($oldText, $text, $yourtext, $result)){
630 $text = $result;
631 return true;
632 } else {
633 return false;
634 }
635 }
636 }
637
638 ?>