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