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