Escape unescaped messages shown on a diff page
[lhc/web/wiklou.git] / includes / diff / DifferenceEngine.php
1 <?php
2 /**
3 * User interface for the difference engine.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup DifferenceEngine
22 */
23
24 /**
25 * Constant to indicate diff cache compatibility.
26 * Bump this when changing the diff formatting in a way that
27 * fixes important bugs or such to force cached diff views to
28 * clear.
29 */
30 define( 'MW_DIFF_VERSION', '1.11a' );
31
32 /**
33 * @todo document
34 * @ingroup DifferenceEngine
35 */
36 class DifferenceEngine extends ContextSource {
37
38 /** @var int */
39 public $mOldid;
40
41 /** @var int */
42 public $mNewid;
43
44 private $mOldTags;
45 private $mNewTags;
46
47 /** @var Content */
48 public $mOldContent;
49
50 /** @var Content */
51 public $mNewContent;
52
53 /** @var Language */
54 protected $mDiffLang;
55
56 /** @var Title */
57 public $mOldPage;
58
59 /** @var Title */
60 public $mNewPage;
61
62 /** @var Revision */
63 public $mOldRev;
64
65 /** @var Revision */
66 public $mNewRev;
67
68 /** @var bool Have the revisions IDs been loaded */
69 private $mRevisionsIdsLoaded = false;
70
71 /** @var bool Have the revisions been loaded */
72 public $mRevisionsLoaded = false;
73
74 /** @var int How many text blobs have been loaded, 0, 1 or 2? */
75 public $mTextLoaded = 0;
76
77 /** @var bool Was the diff fetched from cache? */
78 public $mCacheHit = false;
79
80 /**
81 * Set this to true to add debug info to the HTML output.
82 * Warning: this may cause RSS readers to spuriously mark articles as "new"
83 * (bug 20601)
84 */
85 public $enableDebugComment = false;
86
87 /** @var bool If true, line X is not displayed when X is 1, for example
88 * to increase readability and conserve space with many small diffs.
89 */
90 protected $mReducedLineNumbers = false;
91
92 /** @var string Link to action=markpatrolled */
93 protected $mMarkPatrolledLink = null;
94
95 /** @var bool Show rev_deleted content if allowed */
96 protected $unhide = false;
97 /**#@-*/
98
99 /**
100 * Constructor
101 * @param IContextSource $context Context to use, anything else will be ignored
102 * @param int $old Old ID we want to show and diff with.
103 * @param string|int $new Either revision ID or 'prev' or 'next'. Default: 0.
104 * @param int $rcid Deprecated, no longer used!
105 * @param bool $refreshCache If set, refreshes the diff cache
106 * @param bool $unhide If set, allow viewing deleted revs
107 */
108 public function __construct( $context = null, $old = 0, $new = 0, $rcid = 0,
109 $refreshCache = false, $unhide = false
110 ) {
111 if ( $context instanceof IContextSource ) {
112 $this->setContext( $context );
113 }
114
115 wfDebug( "DifferenceEngine old '$old' new '$new' rcid '$rcid'\n" );
116
117 $this->mOldid = $old;
118 $this->mNewid = $new;
119 $this->mRefreshCache = $refreshCache;
120 $this->unhide = $unhide;
121 }
122
123 /**
124 * @param bool $value
125 */
126 public function setReducedLineNumbers( $value = true ) {
127 $this->mReducedLineNumbers = $value;
128 }
129
130 /**
131 * @return Language
132 */
133 public function getDiffLang() {
134 if ( $this->mDiffLang === null ) {
135 # Default language in which the diff text is written.
136 $this->mDiffLang = $this->getTitle()->getPageLanguage();
137 }
138
139 return $this->mDiffLang;
140 }
141
142 /**
143 * @return bool
144 */
145 public function wasCacheHit() {
146 return $this->mCacheHit;
147 }
148
149 /**
150 * @return int
151 */
152 public function getOldid() {
153 $this->loadRevisionIds();
154
155 return $this->mOldid;
156 }
157
158 /**
159 * @return bool|int
160 */
161 public function getNewid() {
162 $this->loadRevisionIds();
163
164 return $this->mNewid;
165 }
166
167 /**
168 * Look up a special:Undelete link to the given deleted revision id,
169 * as a workaround for being unable to load deleted diffs in currently.
170 *
171 * @param int $id Revision ID
172 *
173 * @return mixed URL or false
174 */
175 public function deletedLink( $id ) {
176 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
177 $dbr = wfGetDB( DB_SLAVE );
178 $row = $dbr->selectRow( 'archive', '*',
179 array( 'ar_rev_id' => $id ),
180 __METHOD__ );
181 if ( $row ) {
182 $rev = Revision::newFromArchiveRow( $row );
183 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
184
185 return SpecialPage::getTitleFor( 'Undelete' )->getFullURL( array(
186 'target' => $title->getPrefixedText(),
187 'timestamp' => $rev->getTimestamp()
188 ) );
189 }
190 }
191
192 return false;
193 }
194
195 /**
196 * Build a wikitext link toward a deleted revision, if viewable.
197 *
198 * @param int $id Revision ID
199 *
200 * @return string Wikitext fragment
201 */
202 public function deletedIdMarker( $id ) {
203 $link = $this->deletedLink( $id );
204 if ( $link ) {
205 return "[$link $id]";
206 } else {
207 return $id;
208 }
209 }
210
211 private function showMissingRevision() {
212 $out = $this->getOutput();
213
214 $missing = array();
215 if ( $this->mOldRev === null ||
216 ( $this->mOldRev && $this->mOldContent === null )
217 ) {
218 $missing[] = $this->deletedIdMarker( $this->mOldid );
219 }
220 if ( $this->mNewRev === null ||
221 ( $this->mNewRev && $this->mNewContent === null )
222 ) {
223 $missing[] = $this->deletedIdMarker( $this->mNewid );
224 }
225
226 $out->setPageTitle( $this->msg( 'errorpagetitle' ) );
227 $msg = $this->msg( 'difference-missing-revision' )
228 ->params( $this->getLanguage()->listToText( $missing ) )
229 ->numParams( count( $missing ) )
230 ->parseAsBlock();
231 $out->addHtml( $msg );
232 }
233
234 public function showDiffPage( $diffOnly = false ) {
235 wfProfileIn( __METHOD__ );
236
237 # Allow frames except in certain special cases
238 $out = $this->getOutput();
239 $out->allowClickjacking();
240 $out->setRobotPolicy( 'noindex,nofollow' );
241
242 if ( !$this->loadRevisionData() ) {
243 $this->showMissingRevision();
244 wfProfileOut( __METHOD__ );
245
246 return;
247 }
248
249 $user = $this->getUser();
250 $permErrors = $this->mNewPage->getUserPermissionsErrors( 'read', $user );
251 if ( $this->mOldPage ) { # mOldPage might not be set, see below.
252 $permErrors = wfMergeErrorArrays( $permErrors,
253 $this->mOldPage->getUserPermissionsErrors( 'read', $user ) );
254 }
255 if ( count( $permErrors ) ) {
256 wfProfileOut( __METHOD__ );
257 throw new PermissionsError( 'read', $permErrors );
258 }
259
260 $rollback = '';
261
262 $query = array();
263 # Carry over 'diffonly' param via navigation links
264 if ( $diffOnly != $user->getBoolOption( 'diffonly' ) ) {
265 $query['diffonly'] = $diffOnly;
266 }
267 # Cascade unhide param in links for easy deletion browsing
268 if ( $this->unhide ) {
269 $query['unhide'] = 1;
270 }
271
272 # Check if one of the revisions is deleted/suppressed
273 $deleted = $suppressed = false;
274 $allowed = $this->mNewRev->userCan( Revision::DELETED_TEXT, $user );
275
276 $revisionTools = array();
277
278 # mOldRev is false if the difference engine is called with a "vague" query for
279 # a diff between a version V and its previous version V' AND the version V
280 # is the first version of that article. In that case, V' does not exist.
281 if ( $this->mOldRev === false ) {
282 $out->setPageTitle( $this->msg( 'difference-title', $this->mNewPage->getPrefixedText() ) );
283 $samePage = true;
284 $oldHeader = '';
285 } else {
286 Hooks::run( 'DiffViewHeader', array( $this, $this->mOldRev, $this->mNewRev ) );
287
288 if ( $this->mNewPage->equals( $this->mOldPage ) ) {
289 $out->setPageTitle( $this->msg( 'difference-title', $this->mNewPage->getPrefixedText() ) );
290 $samePage = true;
291 } else {
292 $out->setPageTitle( $this->msg( 'difference-title-multipage',
293 $this->mOldPage->getPrefixedText(), $this->mNewPage->getPrefixedText() ) );
294 $out->addSubtitle( $this->msg( 'difference-multipage' ) );
295 $samePage = false;
296 }
297
298 if ( $samePage && $this->mNewPage->quickUserCan( 'edit', $user ) ) {
299 if ( $this->mNewRev->isCurrent() && $this->mNewPage->userCan( 'rollback', $user ) ) {
300 $rollbackLink = Linker::generateRollback( $this->mNewRev, $this->getContext() );
301 if ( $rollbackLink ) {
302 $out->preventClickjacking();
303 $rollback = '&#160;&#160;&#160;' . $rollbackLink;
304 }
305 }
306
307 if ( !$this->mOldRev->isDeleted( Revision::DELETED_TEXT ) &&
308 !$this->mNewRev->isDeleted( Revision::DELETED_TEXT )
309 ) {
310 $undoLink = Html::element( 'a', array(
311 'href' => $this->mNewPage->getLocalURL( array(
312 'action' => 'edit',
313 'undoafter' => $this->mOldid,
314 'undo' => $this->mNewid
315 ) ),
316 'title' => Linker::titleAttrib( 'undo' ),
317 ),
318 $this->msg( 'editundo' )->text()
319 );
320 $revisionTools['mw-diff-undo'] = $undoLink;
321 }
322 }
323
324 # Make "previous revision link"
325 if ( $samePage && $this->mOldRev->getPrevious() ) {
326 $prevlink = Linker::linkKnown(
327 $this->mOldPage,
328 $this->msg( 'previousdiff' )->escaped(),
329 array( 'id' => 'differences-prevlink' ),
330 array( 'diff' => 'prev', 'oldid' => $this->mOldid ) + $query
331 );
332 } else {
333 $prevlink = '&#160;';
334 }
335
336 if ( $this->mOldRev->isMinor() ) {
337 $oldminor = ChangesList::flag( 'minor' );
338 } else {
339 $oldminor = '';
340 }
341
342 $ldel = $this->revisionDeleteLink( $this->mOldRev );
343 $oldRevisionHeader = $this->getRevisionHeader( $this->mOldRev, 'complete' );
344 $oldChangeTags = ChangeTags::formatSummaryRow( $this->mOldTags, 'diff' );
345
346 $oldHeader = '<div id="mw-diff-otitle1"><strong>' . $oldRevisionHeader . '</strong></div>' .
347 '<div id="mw-diff-otitle2">' .
348 Linker::revUserTools( $this->mOldRev, !$this->unhide ) . '</div>' .
349 '<div id="mw-diff-otitle3">' . $oldminor .
350 Linker::revComment( $this->mOldRev, !$diffOnly, !$this->unhide ) . $ldel . '</div>' .
351 '<div id="mw-diff-otitle5">' . $oldChangeTags[0] . '</div>' .
352 '<div id="mw-diff-otitle4">' . $prevlink . '</div>';
353
354 if ( $this->mOldRev->isDeleted( Revision::DELETED_TEXT ) ) {
355 $deleted = true; // old revisions text is hidden
356 if ( $this->mOldRev->isDeleted( Revision::DELETED_RESTRICTED ) ) {
357 $suppressed = true; // also suppressed
358 }
359 }
360
361 # Check if this user can see the revisions
362 if ( !$this->mOldRev->userCan( Revision::DELETED_TEXT, $user ) ) {
363 $allowed = false;
364 }
365 }
366
367 # Make "next revision link"
368 # Skip next link on the top revision
369 if ( $samePage && !$this->mNewRev->isCurrent() ) {
370 $nextlink = Linker::linkKnown(
371 $this->mNewPage,
372 $this->msg( 'nextdiff' )->escaped(),
373 array( 'id' => 'differences-nextlink' ),
374 array( 'diff' => 'next', 'oldid' => $this->mNewid ) + $query
375 );
376 } else {
377 $nextlink = '&#160;';
378 }
379
380 if ( $this->mNewRev->isMinor() ) {
381 $newminor = ChangesList::flag( 'minor' );
382 } else {
383 $newminor = '';
384 }
385
386 # Handle RevisionDelete links...
387 $rdel = $this->revisionDeleteLink( $this->mNewRev );
388
389 # Allow extensions to define their own revision tools
390 Hooks::run( 'DiffRevisionTools', array( $this->mNewRev, &$revisionTools, $this->mOldRev ) );
391 $formattedRevisionTools = array();
392 // Put each one in parentheses (poor man's button)
393 foreach ( $revisionTools as $key => $tool ) {
394 $toolClass = is_string( $key ) ? $key : 'mw-diff-tool';
395 $element = Html::rawElement(
396 'span',
397 array( 'class' => $toolClass ),
398 $this->msg( 'parentheses' )->rawParams( $tool )->escaped()
399 );
400 $formattedRevisionTools[] = $element;
401 }
402 $newRevisionHeader = $this->getRevisionHeader( $this->mNewRev, 'complete' ) .
403 ' ' . implode( ' ', $formattedRevisionTools );
404 $newChangeTags = ChangeTags::formatSummaryRow( $this->mNewTags, 'diff' );
405
406 $newHeader = '<div id="mw-diff-ntitle1"><strong>' . $newRevisionHeader . '</strong></div>' .
407 '<div id="mw-diff-ntitle2">' . Linker::revUserTools( $this->mNewRev, !$this->unhide ) .
408 " $rollback</div>" .
409 '<div id="mw-diff-ntitle3">' . $newminor .
410 Linker::revComment( $this->mNewRev, !$diffOnly, !$this->unhide ) . $rdel . '</div>' .
411 '<div id="mw-diff-ntitle5">' . $newChangeTags[0] . '</div>' .
412 '<div id="mw-diff-ntitle4">' . $nextlink . $this->markPatrolledLink() . '</div>';
413
414 if ( $this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) {
415 $deleted = true; // new revisions text is hidden
416 if ( $this->mNewRev->isDeleted( Revision::DELETED_RESTRICTED ) ) {
417 $suppressed = true; // also suppressed
418 }
419 }
420
421 # If the diff cannot be shown due to a deleted revision, then output
422 # the diff header and links to unhide (if available)...
423 if ( $deleted && ( !$this->unhide || !$allowed ) ) {
424 $this->showDiffStyle();
425 $multi = $this->getMultiNotice();
426 $out->addHTML( $this->addHeader( '', $oldHeader, $newHeader, $multi ) );
427 if ( !$allowed ) {
428 $msg = $suppressed ? 'rev-suppressed-no-diff' : 'rev-deleted-no-diff';
429 # Give explanation for why revision is not visible
430 $out->wrapWikiMsg( "<div id='mw-$msg' class='mw-warning plainlinks'>\n$1\n</div>\n",
431 array( $msg ) );
432 } else {
433 # Give explanation and add a link to view the diff...
434 $query = $this->getRequest()->appendQueryValue( 'unhide', '1', true );
435 $link = $this->getTitle()->getFullURL( $query );
436 $msg = $suppressed ? 'rev-suppressed-unhide-diff' : 'rev-deleted-unhide-diff';
437 $out->wrapWikiMsg(
438 "<div id='mw-$msg' class='mw-warning plainlinks'>\n$1\n</div>\n",
439 array( $msg, $link )
440 );
441 }
442 # Otherwise, output a regular diff...
443 } else {
444 # Add deletion notice if the user is viewing deleted content
445 $notice = '';
446 if ( $deleted ) {
447 $msg = $suppressed ? 'rev-suppressed-diff-view' : 'rev-deleted-diff-view';
448 $notice = "<div id='mw-$msg' class='mw-warning plainlinks'>\n" .
449 $this->msg( $msg )->parse() .
450 "</div>\n";
451 }
452 $this->showDiff( $oldHeader, $newHeader, $notice );
453 if ( !$diffOnly ) {
454 $this->renderNewRevision();
455 }
456 }
457 wfProfileOut( __METHOD__ );
458 }
459
460 /**
461 * Get a link to mark the change as patrolled, or '' if there's either no
462 * revision to patrol or the user is not allowed to to it.
463 * Side effect: When the patrol link is build, this method will call
464 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
465 *
466 * @return string
467 */
468 protected function markPatrolledLink() {
469 global $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
470 $user = $this->getUser();
471
472 if ( $this->mMarkPatrolledLink === null ) {
473 // Prepare a change patrol link, if applicable
474 if (
475 // Is patrolling enabled and the user allowed to?
476 $wgUseRCPatrol && $this->mNewPage->quickUserCan( 'patrol', $user ) &&
477 // Only do this if the revision isn't more than 6 hours older
478 // than the Max RC age (6h because the RC might not be cleaned out regularly)
479 RecentChange::isInRCLifespan( $this->mNewRev->getTimestamp(), 21600 )
480 ) {
481 // Look for an unpatrolled change corresponding to this diff
482
483 $db = wfGetDB( DB_SLAVE );
484 $change = RecentChange::newFromConds(
485 array(
486 'rc_timestamp' => $db->timestamp( $this->mNewRev->getTimestamp() ),
487 'rc_this_oldid' => $this->mNewid,
488 'rc_patrolled' => 0
489 ),
490 __METHOD__,
491 array( 'USE INDEX' => 'rc_timestamp' )
492 );
493
494 if ( $change && $change->getPerformer()->getName() !== $user->getName() ) {
495 $rcid = $change->getAttribute( 'rc_id' );
496 } else {
497 // None found or the page has been created by the current user.
498 // If the user could patrol this it already would be patrolled
499 $rcid = 0;
500 }
501 // Build the link
502 if ( $rcid ) {
503 $this->getOutput()->preventClickjacking();
504 if ( $wgEnableAPI && $wgEnableWriteAPI
505 && $user->isAllowed( 'writeapi' )
506 ) {
507 $this->getOutput()->addModules( 'mediawiki.page.patrol.ajax' );
508 }
509
510 $token = $user->getEditToken( $rcid );
511 $this->mMarkPatrolledLink = ' <span class="patrollink">[' . Linker::linkKnown(
512 $this->mNewPage,
513 $this->msg( 'markaspatrolleddiff' )->escaped(),
514 array(),
515 array(
516 'action' => 'markpatrolled',
517 'rcid' => $rcid,
518 'token' => $token,
519 )
520 ) . ']</span>';
521 } else {
522 $this->mMarkPatrolledLink = '';
523 }
524 } else {
525 $this->mMarkPatrolledLink = '';
526 }
527 }
528
529 return $this->mMarkPatrolledLink;
530 }
531
532 /**
533 * @param Revision $rev
534 *
535 * @return string
536 */
537 protected function revisionDeleteLink( $rev ) {
538 $link = Linker::getRevDeleteLink( $this->getUser(), $rev, $rev->getTitle() );
539 if ( $link !== '' ) {
540 $link = '&#160;&#160;&#160;' . $link . ' ';
541 }
542
543 return $link;
544 }
545
546 /**
547 * Show the new revision of the page.
548 */
549 public function renderNewRevision() {
550 wfProfileIn( __METHOD__ );
551 $out = $this->getOutput();
552 $revHeader = $this->getRevisionHeader( $this->mNewRev );
553 # Add "current version as of X" title
554 $out->addHTML( "<hr class='diff-hr' />
555 <h2 class='diff-currentversion-title'>{$revHeader}</h2>\n" );
556 # Page content may be handled by a hooked call instead...
557 # @codingStandardsIgnoreStart Ignoring long lines.
558 if ( Hooks::run( 'ArticleContentOnDiff', array( $this, $out ) ) ) {
559 $this->loadNewText();
560 $out->setRevisionId( $this->mNewid );
561 $out->setRevisionTimestamp( $this->mNewRev->getTimestamp() );
562 $out->setArticleFlag( true );
563
564 // NOTE: only needed for B/C: custom rendering of JS/CSS via hook
565 if ( $this->mNewPage->isCssJsSubpage() || $this->mNewPage->isCssOrJsPage() ) {
566 // This needs to be synchronised with Article::showCssOrJsPage(), which sucks
567 // Give hooks a chance to customise the output
568 // @todo standardize this crap into one function
569 if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
570 // NOTE: deprecated hook, B/C only
571 // use the content object's own rendering
572 $cnt = $this->mNewRev->getContent();
573 $po = $cnt ? $cnt->getParserOutput( $this->mNewRev->getTitle(), $this->mNewRev->getId() ) : null;
574 if ( $po ) {
575 $out->addParserOutputContent( $po );
576 }
577 }
578 } elseif ( !Hooks::run( 'ArticleContentViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
579 // Handled by extension
580 } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
581 // NOTE: deprecated hook, B/C only
582 // Handled by extension
583 } else {
584 // Normal page
585 if ( $this->getTitle()->equals( $this->mNewPage ) ) {
586 // If the Title stored in the context is the same as the one
587 // of the new revision, we can use its associated WikiPage
588 // object.
589 $wikiPage = $this->getWikiPage();
590 } else {
591 // Otherwise we need to create our own WikiPage object
592 $wikiPage = WikiPage::factory( $this->mNewPage );
593 }
594
595 $parserOutput = $this->getParserOutput( $wikiPage, $this->mNewRev );
596
597 # WikiPage::getParserOutput() should not return false, but just in case
598 if ( $parserOutput ) {
599 $out->addParserOutput( $parserOutput );
600 }
601 }
602 }
603 # @codingStandardsIgnoreEnd
604
605 # Add redundant patrol link on bottom...
606 $out->addHTML( $this->markPatrolledLink() );
607
608 wfProfileOut( __METHOD__ );
609 }
610
611 protected function getParserOutput( WikiPage $page, Revision $rev ) {
612 $parserOptions = $page->makeParserOptions( $this->getContext() );
613
614 if ( !$rev->isCurrent() || !$rev->getTitle()->quickUserCan( "edit" ) ) {
615 $parserOptions->setEditSection( false );
616 }
617
618 $parserOutput = $page->getParserOutput( $parserOptions, $rev->getId() );
619
620 return $parserOutput;
621 }
622
623 /**
624 * Get the diff text, send it to the OutputPage object
625 * Returns false if the diff could not be generated, otherwise returns true
626 *
627 * @param string|bool $otitle Header for old text or false
628 * @param string|bool $ntitle Header for new text or false
629 * @param string $notice HTML between diff header and body
630 *
631 * @return bool
632 */
633 public function showDiff( $otitle, $ntitle, $notice = '' ) {
634 $diff = $this->getDiff( $otitle, $ntitle, $notice );
635 if ( $diff === false ) {
636 $this->showMissingRevision();
637
638 return false;
639 } else {
640 $this->showDiffStyle();
641 $this->getOutput()->addHTML( $diff );
642
643 return true;
644 }
645 }
646
647 /**
648 * Add style sheets and supporting JS for diff display.
649 */
650 public function showDiffStyle() {
651 $this->getOutput()->addModuleStyles( 'mediawiki.action.history.diff' );
652 }
653
654 /**
655 * Get complete diff table, including header
656 *
657 * @param string|bool $otitle Header for old text or false
658 * @param string|bool $ntitle Header for new text or false
659 * @param string $notice HTML between diff header and body
660 *
661 * @return mixed
662 */
663 public function getDiff( $otitle, $ntitle, $notice = '' ) {
664 $body = $this->getDiffBody();
665 if ( $body === false ) {
666 return false;
667 }
668
669 $multi = $this->getMultiNotice();
670 // Display a message when the diff is empty
671 if ( $body === '' ) {
672 $notice .= '<div class="mw-diff-empty">' .
673 $this->msg( 'diff-empty' )->parse() .
674 "</div>\n";
675 }
676
677 return $this->addHeader( $body, $otitle, $ntitle, $multi, $notice );
678 }
679
680 /**
681 * Get the diff table body, without header
682 *
683 * @return mixed (string/false)
684 */
685 public function getDiffBody() {
686 global $wgMemc;
687 wfProfileIn( __METHOD__ );
688 $this->mCacheHit = true;
689 // Check if the diff should be hidden from this user
690 if ( !$this->loadRevisionData() ) {
691 wfProfileOut( __METHOD__ );
692
693 return false;
694 } elseif ( $this->mOldRev &&
695 !$this->mOldRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
696 ) {
697 wfProfileOut( __METHOD__ );
698
699 return false;
700 } elseif ( $this->mNewRev &&
701 !$this->mNewRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
702 ) {
703 wfProfileOut( __METHOD__ );
704
705 return false;
706 }
707 // Short-circuit
708 if ( $this->mOldRev === false || ( $this->mOldRev && $this->mNewRev
709 && $this->mOldRev->getID() == $this->mNewRev->getID() )
710 ) {
711 wfProfileOut( __METHOD__ );
712
713 return '';
714 }
715 // Cacheable?
716 $key = false;
717 if ( $this->mOldid && $this->mNewid ) {
718 $key = $this->getDiffBodyCacheKey();
719
720 // Try cache
721 if ( !$this->mRefreshCache ) {
722 $difftext = $wgMemc->get( $key );
723 if ( $difftext ) {
724 wfIncrStats( 'diff_cache_hit' );
725 $difftext = $this->localiseLineNumbers( $difftext );
726 $difftext .= "\n<!-- diff cache key $key -->\n";
727 wfProfileOut( __METHOD__ );
728
729 return $difftext;
730 }
731 } // don't try to load but save the result
732 }
733 $this->mCacheHit = false;
734
735 // Loadtext is permission safe, this just clears out the diff
736 if ( !$this->loadText() ) {
737 wfProfileOut( __METHOD__ );
738
739 return false;
740 }
741
742 $difftext = $this->generateContentDiffBody( $this->mOldContent, $this->mNewContent );
743
744 // Save to cache for 7 days
745 if ( !Hooks::run( 'AbortDiffCache', array( &$this ) ) ) {
746 wfIncrStats( 'diff_uncacheable' );
747 } elseif ( $key !== false && $difftext !== false ) {
748 wfIncrStats( 'diff_cache_miss' );
749 $wgMemc->set( $key, $difftext, 7 * 86400 );
750 } else {
751 wfIncrStats( 'diff_uncacheable' );
752 }
753 // Replace line numbers with the text in the user's language
754 if ( $difftext !== false ) {
755 $difftext = $this->localiseLineNumbers( $difftext );
756 }
757 wfProfileOut( __METHOD__ );
758
759 return $difftext;
760 }
761
762 /**
763 * Returns the cache key for diff body text or content.
764 *
765 * @since 1.23
766 *
767 * @throws MWException
768 * @return string
769 */
770 protected function getDiffBodyCacheKey() {
771 if ( !$this->mOldid || !$this->mNewid ) {
772 throw new MWException( 'mOldid and mNewid must be set to get diff cache key.' );
773 }
774
775 return wfMemcKey( 'diff', 'version', MW_DIFF_VERSION,
776 'oldid', $this->mOldid, 'newid', $this->mNewid );
777 }
778
779 /**
780 * Generate a diff, no caching.
781 *
782 * This implementation uses generateTextDiffBody() to generate a diff based on the default
783 * serialization of the given Content objects. This will fail if $old or $new are not
784 * instances of TextContent.
785 *
786 * Subclasses may override this to provide a different rendering for the diff,
787 * perhaps taking advantage of the content's native form. This is required for all content
788 * models that are not text based.
789 *
790 * @since 1.21
791 *
792 * @param Content $old Old content
793 * @param Content $new New content
794 *
795 * @throws MWException If old or new content is not an instance of TextContent.
796 * @return bool|string
797 */
798 public function generateContentDiffBody( Content $old, Content $new ) {
799 if ( !( $old instanceof TextContent ) ) {
800 throw new MWException( "Diff not implemented for " . get_class( $old ) . "; " .
801 "override generateContentDiffBody to fix this." );
802 }
803
804 if ( !( $new instanceof TextContent ) ) {
805 throw new MWException( "Diff not implemented for " . get_class( $new ) . "; "
806 . "override generateContentDiffBody to fix this." );
807 }
808
809 $otext = $old->serialize();
810 $ntext = $new->serialize();
811
812 return $this->generateTextDiffBody( $otext, $ntext );
813 }
814
815 /**
816 * Generate a diff, no caching
817 *
818 * @param string $otext Old text, must be already segmented
819 * @param string $ntext New text, must be already segmented
820 *
821 * @return bool|string
822 * @deprecated since 1.21, use generateContentDiffBody() instead!
823 */
824 public function generateDiffBody( $otext, $ntext ) {
825 ContentHandler::deprecated( __METHOD__, "1.21" );
826
827 return $this->generateTextDiffBody( $otext, $ntext );
828 }
829
830 /**
831 * Generate a diff, no caching
832 *
833 * @todo move this to TextDifferenceEngine, make DifferenceEngine abstract. At some point.
834 *
835 * @param string $otext Old text, must be already segmented
836 * @param string $ntext New text, must be already segmented
837 *
838 * @return bool|string
839 */
840 public function generateTextDiffBody( $otext, $ntext ) {
841 global $wgExternalDiffEngine, $wgContLang;
842
843 wfProfileIn( __METHOD__ );
844
845 $otext = str_replace( "\r\n", "\n", $otext );
846 $ntext = str_replace( "\r\n", "\n", $ntext );
847
848 if ( $wgExternalDiffEngine == 'wikidiff' && function_exists( 'wikidiff_do_diff' ) ) {
849 # For historical reasons, external diff engine expects
850 # input text to be HTML-escaped already
851 $otext = htmlspecialchars( $wgContLang->segmentForDiff( $otext ) );
852 $ntext = htmlspecialchars( $wgContLang->segmentForDiff( $ntext ) );
853 wfProfileOut( __METHOD__ );
854
855 return $wgContLang->unsegmentForDiff( wikidiff_do_diff( $otext, $ntext, 2 ) ) .
856 $this->debug( 'wikidiff1' );
857 }
858
859 if ( $wgExternalDiffEngine == 'wikidiff2' && function_exists( 'wikidiff2_do_diff' ) ) {
860 # Better external diff engine, the 2 may some day be dropped
861 # This one does the escaping and segmenting itself
862 wfProfileIn( 'wikidiff2_do_diff' );
863 $text = wikidiff2_do_diff( $otext, $ntext, 2 );
864 $text .= $this->debug( 'wikidiff2' );
865 wfProfileOut( 'wikidiff2_do_diff' );
866 wfProfileOut( __METHOD__ );
867
868 return $text;
869 }
870 if ( $wgExternalDiffEngine != 'wikidiff3' && $wgExternalDiffEngine !== false ) {
871 # Diff via the shell
872 $tmpDir = wfTempDir();
873 $tempName1 = tempnam( $tmpDir, 'diff_' );
874 $tempName2 = tempnam( $tmpDir, 'diff_' );
875
876 $tempFile1 = fopen( $tempName1, "w" );
877 if ( !$tempFile1 ) {
878 wfProfileOut( __METHOD__ );
879
880 return false;
881 }
882 $tempFile2 = fopen( $tempName2, "w" );
883 if ( !$tempFile2 ) {
884 wfProfileOut( __METHOD__ );
885
886 return false;
887 }
888 fwrite( $tempFile1, $otext );
889 fwrite( $tempFile2, $ntext );
890 fclose( $tempFile1 );
891 fclose( $tempFile2 );
892 $cmd = wfEscapeShellArg( $wgExternalDiffEngine, $tempName1, $tempName2 );
893 wfProfileIn( __METHOD__ . "-shellexec" );
894 $difftext = wfShellExec( $cmd );
895 $difftext .= $this->debug( "external $wgExternalDiffEngine" );
896 wfProfileOut( __METHOD__ . "-shellexec" );
897 unlink( $tempName1 );
898 unlink( $tempName2 );
899 wfProfileOut( __METHOD__ );
900
901 return $difftext;
902 }
903
904 # Native PHP diff
905 $ota = explode( "\n", $wgContLang->segmentForDiff( $otext ) );
906 $nta = explode( "\n", $wgContLang->segmentForDiff( $ntext ) );
907 $diffs = new Diff( $ota, $nta );
908 $formatter = new TableDiffFormatter();
909 $difftext = $wgContLang->unsegmentForDiff( $formatter->format( $diffs ) ) .
910 wfProfileOut( __METHOD__ );
911
912 return $difftext;
913 }
914
915 /**
916 * Generate a debug comment indicating diff generating time,
917 * server node, and generator backend.
918 *
919 * @param string $generator : What diff engine was used
920 *
921 * @return string
922 */
923 protected function debug( $generator = "internal" ) {
924 global $wgShowHostnames;
925 if ( !$this->enableDebugComment ) {
926 return '';
927 }
928 $data = array( $generator );
929 if ( $wgShowHostnames ) {
930 $data[] = wfHostname();
931 }
932 $data[] = wfTimestamp( TS_DB );
933
934 return "<!-- diff generator: " .
935 implode( " ", array_map( "htmlspecialchars", $data ) ) .
936 " -->\n";
937 }
938
939 /**
940 * Replace line numbers with the text in the user's language
941 *
942 * @param string $text
943 *
944 * @return mixed
945 */
946 public function localiseLineNumbers( $text ) {
947 return preg_replace_callback(
948 '/<!--LINE (\d+)-->/',
949 array( &$this, 'localiseLineNumbersCb' ),
950 $text
951 );
952 }
953
954 public function localiseLineNumbersCb( $matches ) {
955 if ( $matches[1] === '1' && $this->mReducedLineNumbers ) {
956 return '';
957 }
958
959 return $this->msg( 'lineno' )->numParams( $matches[1] )->escaped();
960 }
961
962 /**
963 * If there are revisions between the ones being compared, return a note saying so.
964 *
965 * @return string
966 */
967 public function getMultiNotice() {
968 if ( !is_object( $this->mOldRev ) || !is_object( $this->mNewRev ) ) {
969 return '';
970 } elseif ( !$this->mOldPage->equals( $this->mNewPage ) ) {
971 // Comparing two different pages? Count would be meaningless.
972 return '';
973 }
974
975 if ( $this->mOldRev->getTimestamp() > $this->mNewRev->getTimestamp() ) {
976 $oldRev = $this->mNewRev; // flip
977 $newRev = $this->mOldRev; // flip
978 } else { // normal case
979 $oldRev = $this->mOldRev;
980 $newRev = $this->mNewRev;
981 }
982
983 // Sanity: don't show the notice if too many rows must be scanned
984 // @todo show some special message for that case
985 $nEdits = $this->mNewPage->countRevisionsBetween( $oldRev, $newRev, 1000 );
986 if ( $nEdits > 0 && $nEdits <= 1000 ) {
987 $limit = 100; // use diff-multi-manyusers if too many users
988 $users = $this->mNewPage->getAuthorsBetween( $oldRev, $newRev, $limit );
989 $numUsers = count( $users );
990
991 if ( $numUsers == 1 && $users[0] == $newRev->getRawUserText() ) {
992 $numUsers = 0; // special case to say "by the same user" instead of "by one other user"
993 }
994
995 return self::intermediateEditsMsg( $nEdits, $numUsers, $limit );
996 }
997
998 return ''; // nothing
999 }
1000
1001 /**
1002 * Get a notice about how many intermediate edits and users there are
1003 *
1004 * @param int $numEdits
1005 * @param int $numUsers
1006 * @param int $limit
1007 *
1008 * @return string
1009 */
1010 public static function intermediateEditsMsg( $numEdits, $numUsers, $limit ) {
1011 if ( $numUsers === 0 ) {
1012 $msg = 'diff-multi-sameuser';
1013 } elseif ( $numUsers > $limit ) {
1014 $msg = 'diff-multi-manyusers';
1015 $numUsers = $limit;
1016 } else {
1017 $msg = 'diff-multi-otherusers';
1018 }
1019
1020 return wfMessage( $msg )->numParams( $numEdits, $numUsers )->parse();
1021 }
1022
1023 /**
1024 * Get a header for a specified revision.
1025 *
1026 * @param Revision $rev
1027 * @param string $complete 'complete' to get the header wrapped depending
1028 * the visibility of the revision and a link to edit the page.
1029 *
1030 * @return string HTML fragment
1031 */
1032 protected function getRevisionHeader( Revision $rev, $complete = '' ) {
1033 $lang = $this->getLanguage();
1034 $user = $this->getUser();
1035 $revtimestamp = $rev->getTimestamp();
1036 $timestamp = $lang->userTimeAndDate( $revtimestamp, $user );
1037 $dateofrev = $lang->userDate( $revtimestamp, $user );
1038 $timeofrev = $lang->userTime( $revtimestamp, $user );
1039
1040 $header = $this->msg(
1041 $rev->isCurrent() ? 'currentrev-asof' : 'revisionasof',
1042 $timestamp,
1043 $dateofrev,
1044 $timeofrev
1045 )->escaped();
1046
1047 if ( $complete !== 'complete' ) {
1048 return $header;
1049 }
1050
1051 $title = $rev->getTitle();
1052
1053 $header = Linker::linkKnown( $title, $header, array(),
1054 array( 'oldid' => $rev->getID() ) );
1055
1056 if ( $rev->userCan( Revision::DELETED_TEXT, $user ) ) {
1057 $editQuery = array( 'action' => 'edit' );
1058 if ( !$rev->isCurrent() ) {
1059 $editQuery['oldid'] = $rev->getID();
1060 }
1061
1062 $key = $title->quickUserCan( 'edit', $user ) ? 'editold' : 'viewsourceold';
1063 $msg = $this->msg( $key )->escaped();
1064 $editLink = $this->msg( 'parentheses' )->rawParams(
1065 Linker::linkKnown( $title, $msg, array( ), $editQuery ) )->escaped();
1066 $header .= ' ' . Html::rawElement(
1067 'span',
1068 array( 'class' => 'mw-diff-edit' ),
1069 $editLink
1070 );
1071 if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
1072 $header = Html::rawElement(
1073 'span',
1074 array( 'class' => 'history-deleted' ),
1075 $header
1076 );
1077 }
1078 } else {
1079 $header = Html::rawElement( 'span', array( 'class' => 'history-deleted' ), $header );
1080 }
1081
1082 return $header;
1083 }
1084
1085 /**
1086 * Add the header to a diff body
1087 *
1088 * @param string $diff Diff body
1089 * @param string $otitle Old revision header
1090 * @param string $ntitle New revision header
1091 * @param string $multi Notice telling user that there are intermediate
1092 * revisions between the ones being compared
1093 * @param string $notice Other notices, e.g. that user is viewing deleted content
1094 *
1095 * @return string
1096 */
1097 public function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
1098 // shared.css sets diff in interface language/dir, but the actual content
1099 // is often in a different language, mostly the page content language/dir
1100 $tableClass = 'diff diff-contentalign-' . htmlspecialchars( $this->getDiffLang()->alignStart() );
1101 $header = "<table class='$tableClass'>";
1102
1103 if ( !$diff && !$otitle ) {
1104 $header .= "
1105 <tr style='vertical-align: top;'>
1106 <td class='diff-ntitle'>{$ntitle}</td>
1107 </tr>";
1108 $multiColspan = 1;
1109 } else {
1110 if ( $diff ) { // Safari/Chrome show broken output if cols not used
1111 $header .= "
1112 <col class='diff-marker' />
1113 <col class='diff-content' />
1114 <col class='diff-marker' />
1115 <col class='diff-content' />";
1116 $colspan = 2;
1117 $multiColspan = 4;
1118 } else {
1119 $colspan = 1;
1120 $multiColspan = 2;
1121 }
1122 if ( $otitle || $ntitle ) {
1123 $header .= "
1124 <tr style='vertical-align: top;'>
1125 <td colspan='$colspan' class='diff-otitle'>{$otitle}</td>
1126 <td colspan='$colspan' class='diff-ntitle'>{$ntitle}</td>
1127 </tr>";
1128 }
1129 }
1130
1131 if ( $multi != '' ) {
1132 $header .= "<tr><td colspan='{$multiColspan}' style='text-align: center;' " .
1133 "class='diff-multi'>{$multi}</td></tr>";
1134 }
1135 if ( $notice != '' ) {
1136 $header .= "<tr><td colspan='{$multiColspan}' style='text-align: center;'>{$notice}</td></tr>";
1137 }
1138
1139 return $header . $diff . "</table>";
1140 }
1141
1142 /**
1143 * Use specified text instead of loading from the database
1144 * @deprecated since 1.21, use setContent() instead.
1145 */
1146 public function setText( $oldText, $newText ) {
1147 ContentHandler::deprecated( __METHOD__, "1.21" );
1148
1149 $oldContent = ContentHandler::makeContent( $oldText, $this->getTitle() );
1150 $newContent = ContentHandler::makeContent( $newText, $this->getTitle() );
1151
1152 $this->setContent( $oldContent, $newContent );
1153 }
1154
1155 /**
1156 * Use specified text instead of loading from the database
1157 * @param Content $oldContent
1158 * @param Content $newContent
1159 * @since 1.21
1160 */
1161 public function setContent( Content $oldContent, Content $newContent ) {
1162 $this->mOldContent = $oldContent;
1163 $this->mNewContent = $newContent;
1164
1165 $this->mTextLoaded = 2;
1166 $this->mRevisionsLoaded = true;
1167 }
1168
1169 /**
1170 * Set the language in which the diff text is written
1171 * (Defaults to page content language).
1172 * @param Language|string $lang
1173 * @since 1.19
1174 */
1175 public function setTextLanguage( $lang ) {
1176 $this->mDiffLang = wfGetLangObj( $lang );
1177 }
1178
1179 /**
1180 * Maps a revision pair definition as accepted by DifferenceEngine constructor
1181 * to a pair of actual integers representing revision ids.
1182 *
1183 * @param int $old Revision id, e.g. from URL parameter 'oldid'
1184 * @param int|string $new Revision id or strings 'next' or 'prev', e.g. from URL parameter 'diff'
1185 *
1186 * @return int[] List of two revision ids, older first, later second.
1187 * Zero signifies invalid argument passed.
1188 * false signifies that there is no previous/next revision ($old is the oldest/newest one).
1189 */
1190 public function mapDiffPrevNext( $old, $new ) {
1191 if ( $new === 'prev' ) {
1192 // Show diff between revision $old and the previous one. Get previous one from DB.
1193 $newid = intval( $old );
1194 $oldid = $this->getTitle()->getPreviousRevisionID( $newid );
1195 } elseif ( $new === 'next' ) {
1196 // Show diff between revision $old and the next one. Get next one from DB.
1197 $oldid = intval( $old );
1198 $newid = $this->getTitle()->getNextRevisionID( $oldid );
1199 } else {
1200 $oldid = intval( $old );
1201 $newid = intval( $new );
1202 }
1203
1204 return array( $oldid, $newid );
1205 }
1206
1207 /**
1208 * Load revision IDs
1209 */
1210 private function loadRevisionIds() {
1211 if ( $this->mRevisionsIdsLoaded ) {
1212 return;
1213 }
1214
1215 $this->mRevisionsIdsLoaded = true;
1216
1217 $old = $this->mOldid;
1218 $new = $this->mNewid;
1219
1220 list( $this->mOldid, $this->mNewid ) = self::mapDiffPrevNext( $old, $new );
1221 if ( $new === 'next' && $this->mNewid === false ) {
1222 # if no result, NewId points to the newest old revision. The only newer
1223 # revision is cur, which is "0".
1224 $this->mNewid = 0;
1225 }
1226
1227 Hooks::run(
1228 'NewDifferenceEngine',
1229 array( $this->getTitle(), &$this->mOldid, &$this->mNewid, $old, $new )
1230 );
1231 }
1232
1233 /**
1234 * Load revision metadata for the specified articles. If newid is 0, then compare
1235 * the old article in oldid to the current article; if oldid is 0, then
1236 * compare the current article to the immediately previous one (ignoring the
1237 * value of newid).
1238 *
1239 * If oldid is false, leave the corresponding revision object set
1240 * to false. This is impossible via ordinary user input, and is provided for
1241 * API convenience.
1242 *
1243 * @return bool
1244 */
1245 public function loadRevisionData() {
1246 if ( $this->mRevisionsLoaded ) {
1247 return true;
1248 }
1249
1250 // Whether it succeeds or fails, we don't want to try again
1251 $this->mRevisionsLoaded = true;
1252
1253 $this->loadRevisionIds();
1254
1255 // Load the new revision object
1256 if ( $this->mNewid ) {
1257 $this->mNewRev = Revision::newFromId( $this->mNewid );
1258 } else {
1259 $this->mNewRev = Revision::newFromTitle(
1260 $this->getTitle(),
1261 false,
1262 Revision::READ_NORMAL
1263 );
1264 }
1265
1266 if ( !$this->mNewRev instanceof Revision ) {
1267 return false;
1268 }
1269
1270 // Update the new revision ID in case it was 0 (makes life easier doing UI stuff)
1271 $this->mNewid = $this->mNewRev->getId();
1272 $this->mNewPage = $this->mNewRev->getTitle();
1273
1274 // Load the old revision object
1275 $this->mOldRev = false;
1276 if ( $this->mOldid ) {
1277 $this->mOldRev = Revision::newFromId( $this->mOldid );
1278 } elseif ( $this->mOldid === 0 ) {
1279 $rev = $this->mNewRev->getPrevious();
1280 if ( $rev ) {
1281 $this->mOldid = $rev->getId();
1282 $this->mOldRev = $rev;
1283 } else {
1284 // No previous revision; mark to show as first-version only.
1285 $this->mOldid = false;
1286 $this->mOldRev = false;
1287 }
1288 } /* elseif ( $this->mOldid === false ) leave mOldRev false; */
1289
1290 if ( is_null( $this->mOldRev ) ) {
1291 return false;
1292 }
1293
1294 if ( $this->mOldRev ) {
1295 $this->mOldPage = $this->mOldRev->getTitle();
1296 }
1297
1298 // Load tags information for both revisions
1299 $dbr = wfGetDB( DB_SLAVE );
1300 if ( $this->mOldid !== false ) {
1301 $this->mOldTags = $dbr->selectField(
1302 'tag_summary',
1303 'ts_tags',
1304 array( 'ts_rev_id' => $this->mOldid ),
1305 __METHOD__
1306 );
1307 } else {
1308 $this->mOldTags = false;
1309 }
1310 $this->mNewTags = $dbr->selectField(
1311 'tag_summary',
1312 'ts_tags',
1313 array( 'ts_rev_id' => $this->mNewid ),
1314 __METHOD__
1315 );
1316
1317 return true;
1318 }
1319
1320 /**
1321 * Load the text of the revisions, as well as revision data.
1322 *
1323 * @return bool
1324 */
1325 public function loadText() {
1326 if ( $this->mTextLoaded == 2 ) {
1327 return true;
1328 }
1329
1330 // Whether it succeeds or fails, we don't want to try again
1331 $this->mTextLoaded = 2;
1332
1333 if ( !$this->loadRevisionData() ) {
1334 return false;
1335 }
1336
1337 if ( $this->mOldRev ) {
1338 $this->mOldContent = $this->mOldRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
1339 if ( $this->mOldContent === null ) {
1340 return false;
1341 }
1342 }
1343
1344 if ( $this->mNewRev ) {
1345 $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
1346 if ( $this->mNewContent === null ) {
1347 return false;
1348 }
1349 }
1350
1351 return true;
1352 }
1353
1354 /**
1355 * Load the text of the new revision, not the old one
1356 *
1357 * @return bool
1358 */
1359 public function loadNewText() {
1360 if ( $this->mTextLoaded >= 1 ) {
1361 return true;
1362 }
1363
1364 $this->mTextLoaded = 1;
1365
1366 if ( !$this->loadRevisionData() ) {
1367 return false;
1368 }
1369
1370 $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
1371
1372 return true;
1373 }
1374
1375 }