X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fdiff%2FDifferenceEngine.php;h=d6cf69494c2e9b785a56c286d811a918bb18568d;hb=55cd620157d884af855459f1f7903b0427c992ce;hp=cf78ce03055489c93505de35ef64f9be43cdcf4a;hpb=651c43140fe78594a387a970b406159bcefd20cd;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php
index cf78ce0305..d6cf69494c 100644
--- a/includes/diff/DifferenceEngine.php
+++ b/includes/diff/DifferenceEngine.php
@@ -34,33 +34,47 @@ define( 'MW_DIFF_VERSION', '1.11a' );
* @ingroup DifferenceEngine
*/
class DifferenceEngine extends ContextSource {
+ /** @var int */
public $mOldid;
+
+ /** @var int */
public $mNewid;
+
private $mOldTags;
private $mNewTags;
- /**
- * @var Content
- */
+ /** @var Content */
public $mOldContent;
+
+ /** @var Content */
public $mNewContent;
+
+ /** @var Language */
protected $mDiffLang;
- /**
- * @var Title
- */
+ /** @var Title */
public $mOldPage;
+
+ /** @var Title */
public $mNewPage;
- /**
- * @var Revision
- */
+ /** @var Revision */
public $mOldRev;
+
+ /** @var Revision */
public $mNewRev;
- private $mRevisionsIdsLoaded = false; // Have the revisions IDs been loaded
- public $mRevisionsLoaded = false; // Have the revisions been loaded
- public $mTextLoaded = 0; // How many text blobs have been loaded, 0, 1 or 2?
- public $mCacheHit = false; // Was the diff fetched from cache?
+
+ /** @var bool Have the revisions IDs been loaded */
+ private $mRevisionsIdsLoaded = false;
+
+ /** @var bool Have the revisions been loaded */
+ public $mRevisionsLoaded = false;
+
+ /** @var int How many text blobs have been loaded, 0, 1 or 2? */
+ public $mTextLoaded = 0;
+
+ /** @var bool Was the diff fetched from cache? */
+ public $mCacheHit = false;
/**
* Set this to true to add debug info to the HTML output.
@@ -69,14 +83,16 @@ class DifferenceEngine extends ContextSource {
*/
public $enableDebugComment = false;
- // If true, line X is not displayed when X is 1, for example to increase
- // readability and conserve space with many small diffs.
+ /** @var bool If true, line X is not displayed when X is 1, for example
+ * to increase readability and conserve space with many small diffs.
+ */
protected $mReducedLineNumbers = false;
- // Link to action=markpatrolled
+ /** @var string Link to action=markpatrolled */
protected $mMarkPatrolledLink = null;
- protected $unhide = false; # show rev_deleted content if allowed
+ /** @var bool Show rev_deleted content if allowed */
+ protected $unhide = false;
/**#@-*/
/**
@@ -118,6 +134,7 @@ class DifferenceEngine extends ContextSource {
# Default language in which the diff text is written.
$this->mDiffLang = $this->getTitle()->getPageLanguage();
}
+
return $this->mDiffLang;
}
@@ -133,6 +150,7 @@ class DifferenceEngine extends ContextSource {
*/
function getOldid() {
$this->loadRevisionIds();
+
return $this->mOldid;
}
@@ -141,6 +159,7 @@ class DifferenceEngine extends ContextSource {
*/
function getNewid() {
$this->loadRevisionIds();
+
return $this->mNewid;
}
@@ -160,12 +179,14 @@ class DifferenceEngine extends ContextSource {
if ( $row ) {
$rev = Revision::newFromArchiveRow( $row );
$title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
+
return SpecialPage::getTitleFor( 'Undelete' )->getFullURL( array(
'target' => $title->getPrefixedText(),
'timestamp' => $rev->getTimestamp()
- ));
+ ) );
}
}
+
return false;
}
@@ -215,6 +236,7 @@ class DifferenceEngine extends ContextSource {
if ( !$this->loadRevisionData() ) {
$this->showMissingRevision();
wfProfileOut( __METHOD__ );
+
return;
}
@@ -283,7 +305,8 @@ class DifferenceEngine extends ContextSource {
'href' => $this->mNewPage->getLocalURL( array(
'action' => 'edit',
'undoafter' => $this->mOldid,
- 'undo' => $this->mNewid ) ),
+ 'undo' => $this->mNewid
+ ) ),
'title' => Linker::titleAttrib( 'undo' )
),
$this->msg( 'editundo' )->text()
@@ -316,9 +339,9 @@ class DifferenceEngine extends ContextSource {
$oldHeader = '
' . $oldRevisionHeader . '
' .
'' .
- Linker::revUserTools( $this->mOldRev, !$this->unhide ) . '
' .
+ Linker::revUserTools( $this->mOldRev, !$this->unhide ) . '' .
'' . $oldminor .
- Linker::revComment( $this->mOldRev, !$diffOnly, !$this->unhide ) . $ldel . '
' .
+ Linker::revComment( $this->mOldRev, !$diffOnly, !$this->unhide ) . $ldel . '' .
'' . $oldChangeTags[0] . '
' .
'' . $prevlink . '
';
@@ -358,7 +381,7 @@ class DifferenceEngine extends ContextSource {
$rdel = $this->revisionDeleteLink( $this->mNewRev );
# Allow extensions to define their own revision tools
- wfRunHooks( 'DiffRevisionTools', array( $this->mNewRev, &$revisionTools ) );
+ wfRunHooks( 'DiffRevisionTools', array( $this->mNewRev, &$revisionTools, $this->mOldRev ) );
$formattedRevisionTools = array();
// Put each one in parentheses (poor man's button)
foreach ( $revisionTools as $tool ) {
@@ -370,9 +393,9 @@ class DifferenceEngine extends ContextSource {
$newHeader = '' . $newRevisionHeader . '
' .
'' . Linker::revUserTools( $this->mNewRev, !$this->unhide ) .
- " $rollback
" .
+ " $rollback" .
'' . $newminor .
- Linker::revComment( $this->mNewRev, !$diffOnly, !$this->unhide ) . $rdel . '
' .
+ Linker::revComment( $this->mNewRev, !$diffOnly, !$this->unhide ) . $rdel . '' .
'' . $newChangeTags[0] . '
' .
'' . $nextlink . $this->markPatrolledLink() . '
';
@@ -503,6 +526,7 @@ class DifferenceEngine extends ContextSource {
if ( $link !== '' ) {
$link = ' ' . $link . ' ';
}
+
return $link;
}
@@ -556,19 +580,8 @@ class DifferenceEngine extends ContextSource {
$parserOutput = $this->getParserOutput( $wikiPage, $this->mNewRev );
- # Also try to load it as a redirect
- $rt = $this->mNewContent ? $this->mNewContent->getRedirectTarget() : null;
-
- if ( $rt ) {
- $article = Article::newFromTitle( $this->mNewPage, $this->getContext() );
- $out->addHTML( $article->viewRedirect( $rt ) );
-
- # WikiPage::getParserOutput() should not return false, but just in case
- if ( $parserOutput ) {
- # Show categories etc.
- $out->addParserOutputNoText( $parserOutput );
- }
- } elseif ( $parserOutput ) {
+ # WikiPage::getParserOutput() should not return false, but just in case
+ if ( $parserOutput ) {
$out->addParserOutput( $parserOutput );
}
}
@@ -589,6 +602,7 @@ class DifferenceEngine extends ContextSource {
}
$parserOutput = $page->getParserOutput( $parserOptions, $rev->getId() );
+
return $parserOutput;
}
@@ -606,10 +620,12 @@ class DifferenceEngine extends ContextSource {
$diff = $this->getDiff( $otitle, $ntitle, $notice );
if ( $diff === false ) {
$this->showMissingRevision();
+
return false;
} else {
$this->showDiffStyle();
$this->getOutput()->addHTML( $diff );
+
return true;
}
}
@@ -658,23 +674,27 @@ class DifferenceEngine extends ContextSource {
// Check if the diff should be hidden from this user
if ( !$this->loadRevisionData() ) {
wfProfileOut( __METHOD__ );
+
return false;
} elseif ( $this->mOldRev &&
!$this->mOldRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
) {
wfProfileOut( __METHOD__ );
+
return false;
} elseif ( $this->mNewRev &&
!$this->mNewRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
) {
wfProfileOut( __METHOD__ );
+
return false;
}
// Short-circuit
if ( $this->mOldRev === false || ( $this->mOldRev && $this->mNewRev
- && $this->mOldRev->getID() == $this->mNewRev->getID() ) )
- {
+ && $this->mOldRev->getID() == $this->mNewRev->getID() )
+ ) {
wfProfileOut( __METHOD__ );
+
return '';
}
// Cacheable?
@@ -690,6 +710,7 @@ class DifferenceEngine extends ContextSource {
$difftext = $this->localiseLineNumbers( $difftext );
$difftext .= "\n\n";
wfProfileOut( __METHOD__ );
+
return $difftext;
}
} // don't try to load but save the result
@@ -699,6 +720,7 @@ class DifferenceEngine extends ContextSource {
// Loadtext is permission safe, this just clears out the diff
if ( !$this->loadText() ) {
wfProfileOut( __METHOD__ );
+
return false;
}
@@ -718,6 +740,7 @@ class DifferenceEngine extends ContextSource {
$difftext = $this->localiseLineNumbers( $difftext );
}
wfProfileOut( __METHOD__ );
+
return $difftext;
}
@@ -757,8 +780,8 @@ class DifferenceEngine extends ContextSource {
*/
function generateContentDiffBody( Content $old, Content $new ) {
if ( !( $old instanceof TextContent ) ) {
- throw new MWException( "Diff not implemented for " . get_class( $old ) . "; "
- . "override generateContentDiffBody to fix this." );
+ throw new MWException( "Diff not implemented for " . get_class( $old ) . "; " .
+ "override generateContentDiffBody to fix this." );
}
if ( !( $new instanceof TextContent ) ) {
@@ -806,9 +829,10 @@ class DifferenceEngine extends ContextSource {
if ( $wgExternalDiffEngine == 'wikidiff' && function_exists( 'wikidiff_do_diff' ) ) {
# For historical reasons, external diff engine expects
# input text to be HTML-escaped already
- $otext = htmlspecialchars ( $wgContLang->segmentForDiff( $otext ) );
- $ntext = htmlspecialchars ( $wgContLang->segmentForDiff( $ntext ) );
+ $otext = htmlspecialchars( $wgContLang->segmentForDiff( $otext ) );
+ $ntext = htmlspecialchars( $wgContLang->segmentForDiff( $ntext ) );
wfProfileOut( __METHOD__ );
+
return $wgContLang->unsegmentForDiff( wikidiff_do_diff( $otext, $ntext, 2 ) ) .
$this->debug( 'wikidiff1' );
}
@@ -821,6 +845,7 @@ class DifferenceEngine extends ContextSource {
$text .= $this->debug( 'wikidiff2' );
wfProfileOut( 'wikidiff2_do_diff' );
wfProfileOut( __METHOD__ );
+
return $text;
}
if ( $wgExternalDiffEngine != 'wikidiff3' && $wgExternalDiffEngine !== false ) {
@@ -832,11 +857,13 @@ class DifferenceEngine extends ContextSource {
$tempFile1 = fopen( $tempName1, "w" );
if ( !$tempFile1 ) {
wfProfileOut( __METHOD__ );
+
return false;
}
$tempFile2 = fopen( $tempName2, "w" );
if ( !$tempFile2 ) {
wfProfileOut( __METHOD__ );
+
return false;
}
fwrite( $tempFile1, $otext );
@@ -851,6 +878,7 @@ class DifferenceEngine extends ContextSource {
unlink( $tempName1 );
unlink( $tempName2 );
wfProfileOut( __METHOD__ );
+
return $difftext;
}
@@ -860,7 +888,8 @@ class DifferenceEngine extends ContextSource {
$diffs = new Diff( $ota, $nta );
$formatter = new TableDiffFormatter();
$difftext = $wgContLang->unsegmentForDiff( $formatter->format( $diffs ) ) .
- wfProfileOut( __METHOD__ );
+ wfProfileOut( __METHOD__ );
+
return $difftext;
}
@@ -868,7 +897,7 @@ class DifferenceEngine extends ContextSource {
* Generate a debug comment indicating diff generating time,
* server node, and generator backend.
*
- * @param String $generator: What diff engine was used
+ * @param String $generator : What diff engine was used
*
* @return string
*/
@@ -882,13 +911,10 @@ class DifferenceEngine extends ContextSource {
$data[] = wfHostname();
}
$data[] = wfTimestamp( TS_DB );
- return "\n";
+
+ return "\n";
}
/**
@@ -899,14 +925,18 @@ class DifferenceEngine extends ContextSource {
* @return mixed
*/
function localiseLineNumbers( $text ) {
- return preg_replace_callback( '//',
- array( &$this, 'localiseLineNumbersCb' ), $text );
+ return preg_replace_callback(
+ '//',
+ array( &$this, 'localiseLineNumbersCb' ),
+ $text
+ );
}
function localiseLineNumbersCb( $matches ) {
if ( $matches[1] === '1' && $this->mReducedLineNumbers ) {
return '';
}
+
return $this->msg( 'lineno' )->numParams( $matches[1] )->escaped();
}
@@ -933,9 +963,16 @@ class DifferenceEngine extends ContextSource {
$nEdits = $this->mNewPage->countRevisionsBetween( $oldRev, $newRev );
if ( $nEdits > 0 ) {
$limit = 100; // use diff-multi-manyusers if too many users
- $numUsers = $this->mNewPage->countAuthorsBetween( $oldRev, $newRev, $limit );
+ $users = $this->mNewPage->getAuthorsBetween( $oldRev, $newRev, $limit );
+ $numUsers = count( $users );
+
+ if ( $numUsers == 1 && $users[0] == $newRev->getRawUserText() ) {
+ $numUsers = 0; // special case to say "by the same user" instead of "by one other user"
+ }
+
return self::intermediateEditsMsg( $nEdits, $numUsers, $limit );
}
+
return ''; // nothing
}
@@ -947,12 +984,15 @@ class DifferenceEngine extends ContextSource {
* @return string
*/
public static function intermediateEditsMsg( $numEdits, $numUsers, $limit ) {
- if ( $numUsers > $limit ) {
+ if ( $numUsers === 0 ) {
+ $msg = 'diff-multi-sameuser';
+ } elseif ( $numUsers > $limit ) {
$msg = 'diff-multi-manyusers';
$numUsers = $limit;
} else {
- $msg = 'diff-multi';
+ $msg = 'diff-multi-otherusers';
}
+
return wfMessage( $msg )->numParams( $numEdits, $numUsers )->parse();
}
@@ -1015,11 +1055,12 @@ class DifferenceEngine extends ContextSource {
/**
* Add the header to a diff body
*
- * @param String $diff: Diff body
- * @param String $otitle: Old revision header
- * @param String $ntitle: New revision header
- * @param String $multi: Notice telling user that there are intermediate revisions between the ones being compared
- * @param String $notice: Other notices, e.g. that user is viewing deleted content
+ * @param string $diff Diff body
+ * @param string $otitle Old revision header
+ * @param string $ntitle New revision header
+ * @param string $multi Notice telling user that there are intermediate
+ * revisions between the ones being compared
+ * @param string $notice Other notices, e.g. that user is viewing deleted content
*
* @return string
*/
@@ -1149,7 +1190,10 @@ class DifferenceEngine extends ContextSource {
$this->mNewid = 0;
}
- wfRunHooks( 'NewDifferenceEngine', array( $this->getTitle(), &$this->mOldid, &$this->mNewid, $old, $new ) );
+ wfRunHooks(
+ 'NewDifferenceEngine',
+ array( $this->getTitle(), &$this->mOldid, &$this->mNewid, $old, $new )
+ );
}
/**