Bug 774: section=new does not jump to the added section after save
[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 $s = wfMsg( 'editing', $this->mTitle->getPrefixedText() );
273
274 if( $this->section != '' ) {
275 if( $this->section == 'new' ) {
276 $s.=wfMsg('commentedit');
277 } else {
278 $s.=wfMsg('sectionedit');
279 }
280 if(!$this->preview) {
281 $sectitle=preg_match("/^=+(.*?)=+/mi",
282 $this->textbox1,
283 $matches);
284 if( !empty( $matches[1] ) ) {
285 $this->summary = "/* ". trim($matches[1])." */ ";
286 }
287 }
288 }
289 $wgOut->setPageTitle( $s );
290 if ( !$wgUseLatin1 && !$this->checkUnicodeCompliantBrowser() ) {
291 $this->mArticle->setOldSubtitle();
292 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
293 }
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( $wgContLang->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=\"multipart/form-data\">
470 {$commentsubject}
471 <textarea tabindex='1' accesskey=\",\" name=\"wpTextbox1\" rows='{$rows}'
472 cols='{$cols}'{$ew}>" .
473 htmlspecialchars( $wgContLang->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( $wgContLang->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, $wgContLang, $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 = '[[' . $wgContLang->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;
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->selectRow( '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->selectRow( '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 function checkUnicodeCompliantBrowser() {
639 global $wgBrowserBlackList;
640 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
641 foreach ( $wgBrowserBlackList as $browser ) {
642 if ( preg_match($browser, $currentbrowser) ) {
643 return false;
644 }
645 }
646 return true;
647 }
648
649 /**
650 * Format an anchor fragment as it would appear for a given section name
651 * @param string $text
652 * @return string
653 * @access private
654 */
655 function sectionAnchor( $text ) {
656 global $wgInputEncoding;
657 $headline = do_html_entity_decode( $text, ENT_COMPAT, $wgInputEncoding );
658 # strip out HTML
659 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
660 $headline = trim( $headline );
661 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
662 $replacearray = array(
663 '%3A' => ':',
664 '%' => '.'
665 );
666 return str_replace(
667 array_keys( $replacearray ),
668 array_values( $replacearray ),
669 $sectionanchor );
670 }
671 }
672
673 ?>