+ $this->mOldid = $this->mNewid; # hack to make loadText() work.
+
+ # Get article text from the DB
+ #
+ if ( ! $this->loadText() ) {
+ $t = $wgTitle->getPrefixedText() . " (Diff: {$this->mOldid}, " .
+ "{$this->mNewid})";
+ $mtext = wfMsg( 'missingarticle', $t );
+ $wgOut->setPagetitle( wfMsg( 'errorpagetitle' ) );
+ $wgOut->addHTML( $mtext );
+ wfProfileOut( $fname );
+ return;
+ }
+
+ # Check if user is allowed to look at this page. If not, bail out.
+ #
+ if ( !( $this->mOldPage->userCanRead() ) ) {
+ $wgOut->loginToUse();
+ $wgOut->output();
+ wfProfileOut( $fname );
+ exit;
+ }
+
+ # Prepare the header box
+ #
+ $sk = $wgUser->getSkin();
+
+ $uTLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER_TALK, $this->mOldUser ), $wgLang->getNsText( NS_TALK ) );
+ $userLink = $sk->makeLinkObj( Title::makeTitleSafe( NS_USER, $this->mOldUser ), $this->mOldUser );
+ $contribs = $sk->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ), wfMsg( 'contribslink' ),
+ 'target=' . urlencode($this->mOldUser) );
+ $nextlink = $sk->makeKnownLinkObj( $wgTitle, wfMsg( 'nextdiff' ), 'diff=next&oldid='.$this->mNewid );
+ $header = "<div class=\"firstrevisionheader\" style=\"text-align: center\"><strong>{$this->mOldtitle}</strong><br />$userLink " .
+ "($uTLink | $contribs)<br />" . $this->mOldComment .
+ '<br />' . $nextlink. "</div>\n";
+
+ $wgOut->addHTML( $header );
+
+ $wgOut->setSubtitle( wfMsg( 'difference' ) );
+ $wgOut->setRobotpolicy( 'noindex,follow' );
+
+
+ # Show current revision
+ #
+ $wgOut->addHTML( "<hr /><h2>{$this->mPagetitle}</h2>\n" );
+ $wgOut->addWikiText( $this->mNewtext );
+
+ wfProfileOut( $fname );
+ }
+
+ function showDiff( $otext, $ntext, $otitle, $ntitle )
+ {
+ global $wgOut;
+ $wgOut->addHTML( DifferenceEngine::getDiff( $otext, $ntext, $otitle, $ntitle ) );
+ }
+
+ function getDiff( $otext, $ntext, $otitle, $ntitle ) {
+ global $wgUseExternalDiffEngine, $wgContLang;
+ $out = "
+ <table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>
+ <tr>
+ <td colspan='2' width='50%' align='center' class='diff-otitle'>{$otitle}</td>
+ <td colspan='2' width='50%' align='center' class='diff-ntitle'>{$ntitle}</td>
+ </tr>
+ ";
+ $otext = $wgContLang->segmentForDiff($otext);
+ $ntext = $wgContLang->segmentForDiff($ntext);
+ $difftext='';
+ if ( $wgUseExternalDiffEngine ) {
+ # For historical reasons, external diff engine expects
+ # input text to be HTML-escaped already
+ $otext = str_replace( "\r\n", "\n", htmlspecialchars ( $otext ) );
+ $ntext = str_replace( "\r\n", "\n", htmlspecialchars ( $ntext ) );
+ if( !function_exists( 'wikidiff_do_diff' ) ) {
+ dl('php_wikidiff.so');
+ }
+ $difftext = wikidiff_do_diff( $otext, $ntext, 2 );
+ } else {
+ $ota = explode( "\n", str_replace( "\r\n", "\n", $otext ) );
+ $nta = explode( "\n", str_replace( "\r\n", "\n", $ntext ) );
+ $diffs =& new Diff( $ota, $nta );
+ $formatter =& new TableDiffFormatter();
+ $difftext = $formatter->format( $diffs );
+ }
+ $difftext = $wgContLang->unsegmentForDiff($difftext);
+ $out .= $difftext."</table>\n";
+ return $out;