summaryrefslogtreecommitdiff
path: root/includes/diff
diff options
context:
space:
mode:
Diffstat (limited to 'includes/diff')
-rw-r--r--includes/diff/DairikiDiff.php20
-rw-r--r--includes/diff/DifferenceEngine.php88
2 files changed, 67 insertions, 41 deletions
diff --git a/includes/diff/DairikiDiff.php b/includes/diff/DairikiDiff.php
index c935eee2..72eb5d3c 100644
--- a/includes/diff/DairikiDiff.php
+++ b/includes/diff/DairikiDiff.php
@@ -185,8 +185,8 @@ class _DiffEngine {
$edits = array();
$xi = $yi = 0;
while ( $xi < $n_from || $yi < $n_to ) {
- assert( $yi < $n_to || $this->xchanged[$xi] );
- assert( $xi < $n_from || $this->ychanged[$yi] );
+ assert( '$yi < $n_to || $this->xchanged[$xi]' );
+ assert( '$xi < $n_from || $this->ychanged[$yi]' );
// Skip matching "snake".
$copy = array();
@@ -374,14 +374,14 @@ class _DiffEngine {
while ( list( , $y ) = each( $matches ) ) {
if ( empty( $this->in_seq[$y] ) ) {
$k = $this->_lcs_pos( $y );
- assert( $k > 0 );
+ assert( '$k > 0' );
$ymids[$k] = $ymids[$k -1];
break;
}
}
while ( list ( , $y ) = each( $matches ) ) {
if ( $y > $this->seq[$k -1] ) {
- assert( $y < $this->seq[$k] );
+ assert( '$y < $this->seq[$k]' );
// Optimization: this is a common case:
// next match is just replacing previous match.
$this->in_seq[$this->seq[$k]] = false;
@@ -389,7 +389,7 @@ class _DiffEngine {
$this->in_seq[$y] = 1;
} elseif ( empty( $this->in_seq[$y] ) ) {
$k = $this->_lcs_pos( $y );
- assert( $k > 0 );
+ assert( '$k > 0' );
$ymids[$k] = $ymids[$k -1];
}
}
@@ -430,7 +430,7 @@ class _DiffEngine {
}
}
- assert( $ypos != $this->seq[$end] );
+ assert( '$ypos != $this->seq[$end]' );
$this->in_seq[$this->seq[$end]] = false;
$this->seq[$end] = $ypos;
@@ -661,7 +661,7 @@ class Diff {
*
* $diff = new Diff($lines1, $lines2);
* $rev = $diff->reverse();
- * @return object A Diff object representing the inverse of the
+ * @return Object A Diff object representing the inverse of the
* original diff.
*/
function reverse() {
@@ -814,8 +814,8 @@ class MappedDiff extends Diff {
$mapped_from_lines, $mapped_to_lines ) {
wfProfileIn( __METHOD__ );
- assert( sizeof( $from_lines ) == sizeof( $mapped_from_lines ) );
- assert( sizeof( $to_lines ) == sizeof( $mapped_to_lines ) );
+ assert( 'sizeof( $from_lines ) == sizeof( $mapped_from_lines )' );
+ assert( 'sizeof( $to_lines ) == sizeof( $mapped_to_lines )' );
parent::__construct( $mapped_from_lines, $mapped_to_lines );
@@ -1205,7 +1205,7 @@ class _HWLDF_WordAccumulator {
$this->_flushLine( $tag );
$word = substr( $word, 1 );
}
- assert( !strstr( $word, "\n" ) );
+ assert( '!strstr( $word, "\n" )' );
$this->_group .= $word;
}
}
diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php
index 439e3204..c7156fb2 100644
--- a/includes/diff/DifferenceEngine.php
+++ b/includes/diff/DifferenceEngine.php
@@ -1,6 +1,21 @@
<?php
/**
- * User interface for the difference engine
+ * User interface for the difference engine.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup DifferenceEngine
@@ -164,6 +179,22 @@ class DifferenceEngine extends ContextSource {
}
}
+ private function showMissingRevision() {
+ $out = $this->getOutput();
+
+ $missing = array();
+ if ( $this->mOldRev === null ) {
+ $missing[] = $this->deletedIdMarker( $this->mOldid );
+ }
+ if ( $this->mNewRev === null ) {
+ $missing[] = $this->deletedIdMarker( $this->mNewid );
+ }
+
+ $out->setPageTitle( $this->msg( 'errorpagetitle' ) );
+ $out->addWikiMsg( 'difference-missing-revision',
+ $this->getLanguage()->listToText( $missing ), count( $missing ) );
+ }
+
function showDiffPage( $diffOnly = false ) {
wfProfileIn( __METHOD__ );
@@ -173,13 +204,7 @@ class DifferenceEngine extends ContextSource {
$out->setRobotPolicy( 'noindex,nofollow' );
if ( !$this->loadRevisionData() ) {
- // Sounds like a deleted revision... Let's see what we can do.
- $t = $this->getTitle()->getPrefixedText();
- $d = $this->msg( 'missingarticle-diff',
- $this->deletedIdMarker( $this->mOldid ),
- $this->deletedIdMarker( $this->mNewid ) )->escaped();
- $out->setPageTitle( $this->msg( 'errorpagetitle' ) );
- $out->addWikiMsg( 'missing-article', "<nowiki>$t</nowiki>", "<span class='plainlinks'>$d</span>" );
+ $this->showMissingRevision();
wfProfileOut( __METHOD__ );
return;
}
@@ -239,8 +264,7 @@ class DifferenceEngine extends ContextSource {
# a diff between a version V and its previous version V' AND the version V
# is the first version of that article. In that case, V' does not exist.
if ( $this->mOldRev === false ) {
- $out->setPageTitle( $this->mNewPage->getPrefixedText() );
- $out->addSubtitle( $this->msg( 'difference' ) );
+ $out->setPageTitle( $this->msg( 'difference-title', $this->mNewPage->getPrefixedText() ) );
$samePage = true;
$oldHeader = '';
} else {
@@ -252,19 +276,19 @@ class DifferenceEngine extends ContextSource {
}
if ( $this->mNewPage->equals( $this->mOldPage ) ) {
- $out->setPageTitle( $this->mNewPage->getPrefixedText() );
- $out->addSubtitle( $this->msg( 'difference' ) );
+ $out->setPageTitle( $this->msg( 'difference-title', $this->mNewPage->getPrefixedText() ) );
$samePage = true;
} else {
- $out->setPageTitle( $this->mOldPage->getPrefixedText() . ', ' . $this->mNewPage->getPrefixedText() );
+ $out->setPageTitle( $this->msg( 'difference-title-multipage', $this->mOldPage->getPrefixedText(),
+ $this->mNewPage->getPrefixedText() ) );
$out->addSubtitle( $this->msg( 'difference-multipage' ) );
$samePage = false;
}
- if ( $samePage && $this->mNewPage->userCan( 'edit', $user ) ) {
+ if ( $samePage && $this->mNewPage->quickUserCan( 'edit', $user ) ) {
if ( $this->mNewRev->isCurrent() && $this->mNewPage->userCan( 'rollback', $user ) ) {
$out->preventClickjacking();
- $rollback = '&#160;&#160;&#160;' . Linker::generateRollback( $this->mNewRev );
+ $rollback = '&#160;&#160;&#160;' . Linker::generateRollback( $this->mNewRev, $this->getContext() );
}
if ( !$this->mOldRev->isDeleted( Revision::DELETED_TEXT ) && !$this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) {
$undoLink = ' ' . $this->msg( 'parentheses' )->rawParams(
@@ -403,7 +427,7 @@ class DifferenceEngine extends ContextSource {
if ( $this->mMarkPatrolledLink === null ) {
// Prepare a change patrol link, if applicable
- if ( $wgUseRCPatrol && $this->mNewPage->userCan( 'patrol', $this->getUser() ) ) {
+ if ( $wgUseRCPatrol && $this->mNewPage->quickUserCan( 'patrol', $this->getUser() ) ) {
// If we've been given an explicit change identifier, use it; saves time
if ( $this->mRcidMarkPatrolled ) {
$rcid = $this->mRcidMarkPatrolled;
@@ -512,9 +536,7 @@ class DifferenceEngine extends ContextSource {
$wikiPage = WikiPage::factory( $this->mNewPage );
}
- $parserOptions = ParserOptions::newFromContext( $this->getContext() );
- $parserOptions->enableLimitReport();
- $parserOptions->setTidy( true );
+ $parserOptions = $wikiPage->makeParserOptions( $this->getContext() );
if ( !$this->mNewRev->isCurrent() ) {
$parserOptions->setEditSection( false );
@@ -543,7 +565,7 @@ class DifferenceEngine extends ContextSource {
function showDiff( $otitle, $ntitle, $notice = '' ) {
$diff = $this->getDiff( $otitle, $ntitle, $notice );
if ( $diff === false ) {
- $this->getOutput()->addWikiMsg( 'missing-article', "<nowiki>(fixme, bug)</nowiki>", '' );
+ $this->showMissingRevision();
return false;
} else {
$this->showDiffStyle();
@@ -598,7 +620,7 @@ class DifferenceEngine extends ContextSource {
return false;
}
// Short-circuit
- // If mOldRev is false, it means that the
+ // If mOldRev is false, it means that the
if ( $this->mOldRev === false || ( $this->mOldRev && $this->mNewRev
&& $this->mOldRev->getID() == $this->mNewRev->getID() ) )
{
@@ -672,6 +694,7 @@ class DifferenceEngine extends ContextSource {
*
* @param $otext String: old text, must be already segmented
* @param $ntext String: new text, must be already segmented
+ * @return bool|string
*/
function generateDiffBody( $otext, $ntext ) {
global $wgExternalDiffEngine, $wgContLang;
@@ -705,9 +728,9 @@ class DifferenceEngine extends ContextSource {
}
if ( $wgExternalDiffEngine != 'wikidiff3' && $wgExternalDiffEngine !== false ) {
# Diff via the shell
- global $wgTmpDirectory;
- $tempName1 = tempnam( $wgTmpDirectory, 'diff_' );
- $tempName2 = tempnam( $wgTmpDirectory, 'diff_' );
+ $tmpDir = wfTempDir();
+ $tempName1 = tempnam( $tmpDir, 'diff_' );
+ $tempName2 = tempnam( $tmpDir, 'diff_' );
$tempFile1 = fopen( $tempName1, "w" );
if ( !$tempFile1 ) {
@@ -747,6 +770,7 @@ class DifferenceEngine extends ContextSource {
/**
* Generate a debug comment indicating diff generating time,
* server node, and generator backend.
+ * @return string
*/
protected function debug( $generator = "internal" ) {
global $wgShowHostnames;
@@ -768,6 +792,7 @@ class DifferenceEngine extends ContextSource {
/**
* Replace line numbers with the text in the user's language
+ * @return mixed
*/
function localiseLineNumbers( $text ) {
return preg_replace_callback( '/<!--LINE (\d+)-->/',
@@ -864,8 +889,9 @@ class DifferenceEngine extends ContextSource {
$editQuery['oldid'] = $rev->getID();
}
- $msg = $this->msg( $title->userCan( 'edit', $user ) ? 'editold' : 'viewsourceold' )->escaped();
- $header .= ' (' . Linker::linkKnown( $title, $msg, array(), $editQuery ) . ')';
+ $msg = $this->msg( $title->quickUserCan( 'edit', $user ) ? 'editold' : 'viewsourceold' )->escaped();
+ $header .= ' ' . $this->msg( 'parentheses' )->rawParams(
+ Linker::linkKnown( $title, $msg, array(), $editQuery ) )->plain();
if ( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
$header = Html::rawElement( 'span', array( 'class' => 'history-deleted' ), $header );
}
@@ -889,7 +915,7 @@ class DifferenceEngine extends ContextSource {
if ( !$diff && !$otitle ) {
$header .= "
- <tr valign='top'>
+ <tr style='vertical-align: top;'>
<td class='diff-ntitle'>{$ntitle}</td>
</tr>";
$multiColspan = 1;
@@ -907,17 +933,17 @@ class DifferenceEngine extends ContextSource {
$multiColspan = 2;
}
$header .= "
- <tr valign='top'>
+ <tr style='vertical-align: top;'>
<td colspan='$colspan' class='diff-otitle'>{$otitle}</td>
<td colspan='$colspan' class='diff-ntitle'>{$ntitle}</td>
</tr>";
}
if ( $multi != '' ) {
- $header .= "<tr><td colspan='{$multiColspan}' align='center' class='diff-multi'>{$multi}</td></tr>";
+ $header .= "<tr><td colspan='{$multiColspan}' style='text-align: center;' class='diff-multi'>{$multi}</td></tr>";
}
if ( $notice != '' ) {
- $header .= "<tr><td colspan='{$multiColspan}' align='center'>{$notice}</td></tr>";
+ $header .= "<tr><td colspan='{$multiColspan}' style='text-align: center;'>{$notice}</td></tr>";
}
return $header . $diff . "</table>";
@@ -1002,7 +1028,7 @@ class DifferenceEngine extends ContextSource {
// Load the new revision object
$this->mNewRev = $this->mNewid
? Revision::newFromId( $this->mNewid )
- : Revision::newFromTitle( $this->getTitle() );
+ : Revision::newFromTitle( $this->getTitle(), false, Revision::READ_NORMAL );
if ( !$this->mNewRev instanceof Revision ) {
return false;