expiry: one hour
Difference Engine:
- key: $wgDBname:diff:version:{MW_DIFF_VERSION}:oldid:$old:newid:$new
+ key: $wgDBname:diff:version:{DifferenceEngine::CACHE_VERSION}:oldid:$old:newid:$new
ex: wikidb:diff:version:1.11a:oldid:1:newid:2
stores: body of a difference
cleared by: nothing
$de = $contentHandler->createDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
// DifferenceEngine directly fetched the revision:
- $this->mRevIdFetched = $de->mNewid;
+ $this->mRevIdFetched = $de->getNewid();
$de->showDiffPage( $diffOnly );
// Run view updates for the newer revision being diffed (and shown below the diff if not $diffOnly)
'ViewCountUpdate' => 'includes/deferred/ViewCountUpdate.php',
# includes/diff
- '_DiffEngine' => 'includes/diff/DairikiDiff.php',
- '_DiffOp' => 'includes/diff/DairikiDiff.php',
- '_DiffOp_Add' => 'includes/diff/DairikiDiff.php',
- '_DiffOp_Change' => 'includes/diff/DairikiDiff.php',
- '_DiffOp_Copy' => 'includes/diff/DairikiDiff.php',
- '_DiffOp_Delete' => 'includes/diff/DairikiDiff.php',
- '_HWLDF_WordAccumulator' => 'includes/diff/DairikiDiff.php',
- 'ArrayDiffFormatter' => 'includes/diff/DairikiDiff.php',
+ 'DiffEngine' => 'includes/diff/DairikiDiff.php',
+ 'DiffOp' => 'includes/diff/DairikiDiff.php',
+ 'DiffOp_Add' => 'includes/diff/DairikiDiff.php',
+ 'DiffOp_Change' => 'includes/diff/DairikiDiff.php',
+ 'DiffOp_Copy' => 'includes/diff/DairikiDiff.php',
+ 'DiffOp_Delete' => 'includes/diff/DairikiDiff.php',
+ 'HWLDF_WordAccumulator' => 'includes/diff/DairikiDiff.php',
+ 'ArrayDiffFormatter' => 'includes/diff/ArrayDiffFormatter.php',
'Diff' => 'includes/diff/DairikiDiff.php',
'DifferenceEngine' => 'includes/diff/DifferenceEngine.php',
- 'DiffFormatter' => 'includes/diff/DairikiDiff.php',
+ 'DiffFormatter' => 'includes/diff/DiffFormatter.php',
'MappedDiff' => 'includes/diff/DairikiDiff.php',
'RangeDifference' => 'includes/diff/WikiDiff3.php',
- 'TableDiffFormatter' => 'includes/diff/DairikiDiff.php',
- 'UnifiedDiffFormatter' => 'includes/diff/DairikiDiff.php',
+ 'TableDiffFormatter' => 'includes/diff/TableDiffFormatter.php',
+ 'UnifiedDiffFormatter' => 'includes/diff/UnifiedDiffFormatter.php',
'WikiDiff3' => 'includes/diff/WikiDiff3.php',
'WordLevelDiff' => 'includes/diff/DairikiDiff.php',
* @param $out OutputPage
*/
function outputPage( OutputPage $out = null ) {
- global $wgContLang;
- global $wgScript, $wgStylePath;
- global $wgMimeType, $wgJsMimeType;
- global $wgXhtmlNamespaces, $wgHtml5Version;
- global $wgDisableCounters, $wgSitename, $wgLogo;
- global $wgMaxCredits, $wgShowCreditsIfMax;
- global $wgPageShowWatchingUsers;
- global $wgArticlePath, $wgScriptPath, $wgServer;
-
wfProfileIn( __METHOD__ );
Profiler::instance()->setTemplated( true );
}
$out = $this->getOutput();
- $request = $this->getRequest();
$user = $this->getUser();
- $title = $this->getTitle();
wfProfileIn( __METHOD__ . '-init' );
$this->initPage( $out );
wfProfileOut( __METHOD__ . '-init' );
+ $tpl = $this->prepareQuickTemplate( $out );
+ // execute template
+ wfProfileIn( __METHOD__ . '-execute' );
+ $res = $tpl->execute();
+ wfProfileOut( __METHOD__ . '-execute' );
+
+ // result may be an error
+ $this->printOrError( $res );
+ if ( $oldContext ) {
+ $this->setContext( $oldContext );
+ }
+ }
+
+ /**
+ * initialize various variables and generate the template
+ *
+ * @since 1.23
+ * @param $out OutputPage
+ * @return QuickTemplate the template to be executed by outputPage
+ */
+ protected function prepareQuickTemplate( OutputPage $out = null ) {
+ global $wgContLang, $wgScript, $wgStylePath,
+ $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version,
+ $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
+ $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath,
+ $wgScriptPath, $wgServer;
+
+ $title = $this->getTitle();
+ $request = $this->getRequest();
$tpl = $this->setupTemplateForOutput();
wfProfileIn( __METHOD__ . '-stuff-head' );
$tpl->set( 'dataAfterContent', $this->afterContentHook() );
wfProfileOut( __METHOD__ . '-stuff5' );
- // execute template
- wfProfileIn( __METHOD__ . '-execute' );
- $res = $tpl->execute();
- wfProfileOut( __METHOD__ . '-execute' );
-
- // result may be an error
- $this->printOrError( $res );
-
- if ( $oldContext ) {
- $this->setContext( $oldContext );
- }
wfProfileOut( __METHOD__ );
+ return $tpl;
}
/**
* @param string $watchlist Valid values: 'watch', 'unwatch', 'preferences', 'nochange'
* @param $titleObj Title the page under consideration
* @param string $userOption The user option to consider when $watchlist=preferences.
- * If not set will magically default to either watchdefault or watchcreations
+ * If not set will use watchdefault always and watchcreations if $titleObj doesn't exist.
* @return bool
*/
protected function getWatchlistValue( $watchlist, $titleObj, $userOption = null ) {
if ( $userWatching ) {
return true;
}
- # If no user option was passed, use watchdefault or watchcreations
+ # If no user option was passed, use watchdefault and watchcreations
if ( is_null( $userOption ) ) {
- $userOption = $titleObj->exists()
- ? 'watchdefault' : 'watchcreations';
+ return $this->getUser()->getBoolOption( 'watchdefault' ) ||
+ $this->getUser()->getBoolOption( 'watchcreations' ) && !$titleObj->exists();
}
# Watch the article based on the user preference
return $this->getUser()->getBoolOption( $userOption );
$cascade = $params['cascade'];
$watch = $params['watch'] ? 'watch' : $params['watchlist'];
- $this->setWatch( $watch, $titleObj );
+ $this->setWatch( $watch, $titleObj, 'watchdefault' );
$status = $pageObj->doUpdateRestrictions( $protections, $expiryarray, $cascade, $params['reason'], $this->getUser() );
if ( $row['iw_local'] == '1' ) {
$val['local'] = '';
}
- // $val['trans'] = intval( $row['iw_trans'] ); // should this be exposed?
+ if ( $row['iw_trans'] == '1' ) {
+ $val['trans'] = '';
+ }
if ( isset( $langNames[$prefix] ) ) {
$val['language'] = $langNames[$prefix];
}
/** @var $file File */
$file = $this->mUpload->getLocalFile();
- $watch = $this->getWatchlistValue( $this->mParams['watchlist'], $file->getTitle() );
+
+ // For preferences mode, we want to watch if 'watchdefault' is set or
+ // if the *file* doesn't exist and 'watchcreations' is set. But
+ // getWatchlistValue()'s automatic handling checks if the *title*
+ // exists or not, so we need to check both prefs manually.
+ $watch = $this->getWatchlistValue(
+ $this->mParams['watchlist'], $file->getTitle(), 'watchdefault'
+ );
+ if ( !$watch && $this->mParams['watchlist'] == 'preferences' && !$file->exists() ) {
+ $watch = $this->getWatchlistValue(
+ $this->mParams['watchlist'], $file->getTitle(), 'watchcreations'
+ );
+ }
// Deprecated parameters
if ( $this->mParams['watch'] ) {
--- /dev/null
+<?php
+/**
+ * Portions taken from phpwiki-1.3.3.
+ *
+ * Copyright © 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org>
+ * You may copy this code freely under the conditions of the GPL.
+ *
+ * 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
+ */
+
+/**
+ * A pseudo-formatter that just passes along the Diff::$edits array
+ * @ingroup DifferenceEngine
+ */
+class ArrayDiffFormatter extends DiffFormatter {
+
+ /**
+ * @param $diff
+ * @return array
+ */
+ public function format( $diff ) {
+ $oldline = 1;
+ $newline = 1;
+ $retval = array();
+ foreach ( $diff->edits as $edit ) {
+ switch ( $edit->type ) {
+ case 'add':
+ foreach ( $edit->closing as $l ) {
+ $retval[] = array(
+ 'action' => 'add',
+ 'new' => $l,
+ 'newline' => $newline++
+ );
+ }
+ break;
+ case 'delete':
+ foreach ( $edit->orig as $l ) {
+ $retval[] = array(
+ 'action' => 'delete',
+ 'old' => $l,
+ 'oldline' => $oldline++,
+ );
+ }
+ break;
+ case 'change':
+ foreach ( $edit->orig as $i => $l ) {
+ $retval[] = array(
+ 'action' => 'change',
+ 'old' => $l,
+ 'new' => isset( $edit->closing[$i] ) ? $edit->closing[$i] : null,
+ 'oldline' => $oldline++,
+ 'newline' => $newline++,
+ );
+ }
+ break;
+ case 'copy':
+ $oldline += count( $edit->orig );
+ $newline += count( $edit->orig );
+ }
+ }
+ return $retval;
+ }
+}
* @private
* @ingroup DifferenceEngine
*/
-class _DiffOp {
- var $type;
- var $orig;
- var $closing;
+abstract class DiffOp {
+ public $type;
+ public $orig;
+ public $closing;
- function reverse() {
- trigger_error( 'pure virtual', E_USER_ERROR );
- }
+ public abstract function reverse();
/**
* @return int
* @private
* @ingroup DifferenceEngine
*/
-class _DiffOp_Copy extends _DiffOp {
- var $type = 'copy';
+class DiffOp_Copy extends DiffOp {
+ public $type = 'copy';
function __construct( $orig, $closing = false ) {
if ( !is_array( $closing ) ) {
}
/**
- * @return _DiffOp_Copy
+ * @return DiffOp_Copy
*/
function reverse() {
- return new _DiffOp_Copy( $this->closing, $this->orig );
+ return new DiffOp_Copy( $this->closing, $this->orig );
}
}
* @private
* @ingroup DifferenceEngine
*/
-class _DiffOp_Delete extends _DiffOp {
- var $type = 'delete';
+class DiffOp_Delete extends DiffOp {
+ public $type = 'delete';
function __construct( $lines ) {
$this->orig = $lines;
}
/**
- * @return _DiffOp_Add
+ * @return DiffOp_Add
*/
function reverse() {
- return new _DiffOp_Add( $this->orig );
+ return new DiffOp_Add( $this->orig );
}
}
* @private
* @ingroup DifferenceEngine
*/
-class _DiffOp_Add extends _DiffOp {
- var $type = 'add';
+class DiffOp_Add extends DiffOp {
+ public $type = 'add';
function __construct( $lines ) {
$this->closing = $lines;
}
/**
- * @return _DiffOp_Delete
+ * @return DiffOp_Delete
*/
function reverse() {
- return new _DiffOp_Delete( $this->closing );
+ return new DiffOp_Delete( $this->closing );
}
}
* @private
* @ingroup DifferenceEngine
*/
-class _DiffOp_Change extends _DiffOp {
- var $type = 'change';
+class DiffOp_Change extends DiffOp {
+ public $type = 'change';
function __construct( $orig, $closing ) {
$this->orig = $orig;
}
/**
- * @return _DiffOp_Change
+ * @return DiffOp_Change
*/
function reverse() {
- return new _DiffOp_Change( $this->closing, $this->orig );
+ return new DiffOp_Change( $this->closing, $this->orig );
}
}
* @private
* @ingroup DifferenceEngine
*/
-class _DiffEngine {
+class DiffEngine {
const MAX_XREF_LENGTH = 10000;
wfProfileIn( __METHOD__ );
// Diff and store locally
- $this->diff_local( $from_lines, $to_lines );
+ $this->diffLocal( $from_lines, $to_lines );
// Merge edits when possible
- $this->_shift_boundaries( $from_lines, $this->xchanged, $this->ychanged );
- $this->_shift_boundaries( $to_lines, $this->ychanged, $this->xchanged );
+ $this->shiftBoundaries( $from_lines, $this->xchanged, $this->ychanged );
+ $this->shiftBoundaries( $to_lines, $this->ychanged, $this->xchanged );
// Compute the edit operations.
$n_from = count( $from_lines );
++$yi;
}
if ( $copy ) {
- $edits[] = new _DiffOp_Copy( $copy );
+ $edits[] = new DiffOp_Copy( $copy );
}
// Find deletes & adds.
}
if ( $delete && $add ) {
- $edits[] = new _DiffOp_Change( $delete, $add );
+ $edits[] = new DiffOp_Change( $delete, $add );
} elseif ( $delete ) {
- $edits[] = new _DiffOp_Delete( $delete );
+ $edits[] = new DiffOp_Delete( $delete );
} elseif ( $add ) {
- $edits[] = new _DiffOp_Add( $add );
+ $edits[] = new DiffOp_Add( $add );
}
}
wfProfileOut( __METHOD__ );
* @param $from_lines
* @param $to_lines
*/
- function diff_local( $from_lines, $to_lines ) {
+ private function diffLocal( $from_lines, $to_lines ) {
global $wgExternalDiffEngine;
wfProfileIn( __METHOD__ );
// Ignore lines which do not exist in both files.
for ( $xi = $skip; $xi < $n_from - $endskip; $xi++ ) {
- $xhash[$this->_line_hash( $from_lines[$xi] )] = 1;
+ $xhash[$this->lineHash( $from_lines[$xi] )] = 1;
}
for ( $yi = $skip; $yi < $n_to - $endskip; $yi++ ) {
$line = $to_lines[$yi];
- if ( ( $this->ychanged[$yi] = empty( $xhash[$this->_line_hash( $line )] ) ) ) {
+ if ( ( $this->ychanged[$yi] = empty( $xhash[$this->lineHash( $line )] ) ) ) {
continue;
}
- $yhash[$this->_line_hash( $line )] = 1;
+ $yhash[$this->lineHash( $line )] = 1;
$this->yv[] = $line;
$this->yind[] = $yi;
}
for ( $xi = $skip; $xi < $n_from - $endskip; $xi++ ) {
$line = $from_lines[$xi];
- if ( ( $this->xchanged[$xi] = empty( $yhash[$this->_line_hash( $line )] ) ) ) {
+ if ( ( $this->xchanged[$xi] = empty( $yhash[$this->lineHash( $line )] ) ) ) {
continue;
}
$this->xv[] = $line;
}
// Find the LCS.
- $this->_compareseq( 0, count( $this->xv ), 0, count( $this->yv ) );
+ $this->compareSeq( 0, count( $this->xv ), 0, count( $this->yv ) );
}
wfProfileOut( __METHOD__ );
}
* @param $line string
* @return string
*/
- function _line_hash( $line ) {
+ private function lineHash( $line ) {
if ( strlen( $line ) > self::MAX_XREF_LENGTH ) {
return md5( $line );
} else {
* @param $nchunks
* @return array
*/
- function _diag( $xoff, $xlim, $yoff, $ylim, $nchunks ) {
+ private function diag( $xoff, $xlim, $yoff, $ylim, $nchunks ) {
$flip = false;
if ( $xlim - $xoff > $ylim - $yoff ) {
reset( $matches );
while ( list( , $y ) = each( $matches ) ) {
if ( empty( $this->in_seq[$y] ) ) {
- $k = $this->_lcs_pos( $y );
+ $k = $this->lcsPos( $y );
assert( '$k > 0' );
$ymids[$k] = $ymids[$k -1];
break;
$this->seq[$k] = $y;
$this->in_seq[$y] = 1;
} elseif ( empty( $this->in_seq[$y] ) ) {
- $k = $this->_lcs_pos( $y );
+ $k = $this->lcsPos( $y );
assert( '$k > 0' );
$ymids[$k] = $ymids[$k -1];
}
* @param $ypos
* @return int
*/
- function _lcs_pos( $ypos ) {
+ private function lcsPos( $ypos ) {
$end = $this->lcs;
if ( $end == 0 || $ypos > $this->seq[$end] ) {
$this->seq[++$this->lcs] = $ypos;
* @param $yoff
* @param $ylim
*/
- function _compareseq( $xoff, $xlim, $yoff, $ylim ) {
+ private function compareSeq( $xoff, $xlim, $yoff, $ylim ) {
// Slide down the bottom initial diagonal.
while ( $xoff < $xlim && $yoff < $ylim && $this->xv[$xoff] == $this->yv[$yoff] ) {
++$xoff;
// $nchunks = sqrt(min($xlim - $xoff, $ylim - $yoff) / 2.5);
// $nchunks = max(2,min(8,(int)$nchunks));
$nchunks = min( 7, $xlim - $xoff, $ylim - $yoff ) + 1;
- list( $lcs, $seps ) = $this->_diag( $xoff, $xlim, $yoff, $ylim, $nchunks );
+ list( $lcs, $seps ) = $this->diag( $xoff, $xlim, $yoff, $ylim, $nchunks );
}
if ( $lcs == 0 ) {
reset( $seps );
$pt1 = $seps[0];
while ( $pt2 = next( $seps ) ) {
- $this->_compareseq( $pt1[0], $pt2[0], $pt1[1], $pt2[1] );
+ $this->compareSeq( $pt1[0], $pt2[0], $pt1[1], $pt2[1] );
$pt1 = $pt2;
}
}
*
* This is extracted verbatim from analyze.c (GNU diffutils-2.7).
*/
- function _shift_boundaries( $lines, &$changed, $other_changed ) {
+ private function shiftBoundaries( $lines, &$changed, $other_changed ) {
wfProfileIn( __METHOD__ );
$i = 0;
$j = 0;
* @ingroup DifferenceEngine
*/
class Diff {
- var $edits;
+ public $edits;
/**
* Constructor.
* @param $to_lines array An array of strings.
*/
function __construct( $from_lines, $to_lines ) {
- $eng = new _DiffEngine;
+ $eng = new DiffEngine;
$this->edits = $eng->diff( $from_lines, $to_lines );
- // $this->_check($from_lines, $to_lines);
+ // $this->check($from_lines, $to_lines);
}
/**
function reverse() {
$rev = $this;
$rev->edits = array();
+ /** @var DiffOp $edit */
foreach ( $this->edits as $edit ) {
$rev->edits[] = $edit->reverse();
}
* @param $from_lines
* @param $to_lines
*/
- function _check( $from_lines, $to_lines ) {
+ private function check( $from_lines, $to_lines ) {
wfProfileIn( __METHOD__ );
if ( serialize( $from_lines ) != serialize( $this->orig() ) ) {
trigger_error( "Reconstructed original doesn't match", E_USER_ERROR );
}
}
-/**
- * A class to format Diffs
- *
- * This class formats the diff in classic diff format.
- * It is intended that this class be customized via inheritance,
- * to obtain fancier outputs.
- * @todo document
- * @private
- * @ingroup DifferenceEngine
- */
-class DiffFormatter {
- /**
- * Number of leading context "lines" to preserve.
- *
- * This should be left at zero for this class, but subclasses
- * may want to set this to other values.
- */
- var $leading_context_lines = 0;
-
- /**
- * Number of trailing context "lines" to preserve.
- *
- * This should be left at zero for this class, but subclasses
- * may want to set this to other values.
- */
- var $trailing_context_lines = 0;
-
- /**
- * Format a diff.
- *
- * @param $diff Diff A Diff object.
- * @return string The formatted output.
- */
- function format( $diff ) {
- wfProfileIn( __METHOD__ );
-
- $xi = $yi = 1;
- $block = false;
- $context = array();
-
- $nlead = $this->leading_context_lines;
- $ntrail = $this->trailing_context_lines;
-
- $this->_start_diff();
-
- foreach ( $diff->edits as $edit ) {
- if ( $edit->type == 'copy' ) {
- if ( is_array( $block ) ) {
- if ( count( $edit->orig ) <= $nlead + $ntrail ) {
- $block[] = $edit;
- } else {
- if ( $ntrail ) {
- $context = array_slice( $edit->orig, 0, $ntrail );
- $block[] = new _DiffOp_Copy( $context );
- }
- $this->_block( $x0, $ntrail + $xi - $x0,
- $y0, $ntrail + $yi - $y0,
- $block );
- $block = false;
- }
- }
- $context = $edit->orig;
- } else {
- if ( !is_array( $block ) ) {
- $context = array_slice( $context, count( $context ) - $nlead );
- $x0 = $xi - count( $context );
- $y0 = $yi - count( $context );
- $block = array();
- if ( $context ) {
- $block[] = new _DiffOp_Copy( $context );
- }
- }
- $block[] = $edit;
- }
-
- if ( $edit->orig ) {
- $xi += count( $edit->orig );
- }
- if ( $edit->closing ) {
- $yi += count( $edit->closing );
- }
- }
-
- if ( is_array( $block ) ) {
- $this->_block( $x0, $xi - $x0,
- $y0, $yi - $y0,
- $block );
- }
-
- $end = $this->_end_diff();
- wfProfileOut( __METHOD__ );
- return $end;
- }
-
- /**
- * @param $xbeg
- * @param $xlen
- * @param $ybeg
- * @param $ylen
- * @param $edits
- */
- function _block( $xbeg, $xlen, $ybeg, $ylen, &$edits ) {
- wfProfileIn( __METHOD__ );
- $this->_start_block( $this->_block_header( $xbeg, $xlen, $ybeg, $ylen ) );
- foreach ( $edits as $edit ) {
- if ( $edit->type == 'copy' ) {
- $this->_context( $edit->orig );
- } elseif ( $edit->type == 'add' ) {
- $this->_added( $edit->closing );
- } elseif ( $edit->type == 'delete' ) {
- $this->_deleted( $edit->orig );
- } elseif ( $edit->type == 'change' ) {
- $this->_changed( $edit->orig, $edit->closing );
- } else {
- trigger_error( 'Unknown edit type', E_USER_ERROR );
- }
- }
- $this->_end_block();
- wfProfileOut( __METHOD__ );
- }
-
- function _start_diff() {
- ob_start();
- }
-
- /**
- * @return string
- */
- function _end_diff() {
- $val = ob_get_contents();
- ob_end_clean();
- return $val;
- }
-
- /**
- * @param $xbeg
- * @param $xlen
- * @param $ybeg
- * @param $ylen
- * @return string
- */
- function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
- if ( $xlen > 1 ) {
- $xbeg .= ',' . ( $xbeg + $xlen - 1 );
- }
- if ( $ylen > 1 ) {
- $ybeg .= ',' . ( $ybeg + $ylen - 1 );
- }
-
- return $xbeg . ( $xlen ? ( $ylen ? 'c' : 'd' ) : 'a' ) . $ybeg;
- }
-
- function _start_block( $header ) {
- echo $header . "\n";
- }
-
- function _end_block() {
- }
-
- /**
- * @param $lines
- * @param $prefix string
- */
- function _lines( $lines, $prefix = ' ' ) {
- foreach ( $lines as $line ) {
- echo "$prefix $line\n";
- }
- }
-
- /**
- * @param $lines
- */
- function _context( $lines ) {
- $this->_lines( $lines );
- }
-
- /**
- * @param $lines
- */
- function _added( $lines ) {
- $this->_lines( $lines, '>' );
- }
-
- /**
- * @param $lines
- */
- function _deleted( $lines ) {
- $this->_lines( $lines, '<' );
- }
-
- /**
- * @param $orig
- * @param $closing
- */
- function _changed( $orig, $closing ) {
- $this->_deleted( $orig );
- echo "---\n";
- $this->_added( $closing );
- }
-}
-
-/**
- * A formatter that outputs unified diffs
- * @ingroup DifferenceEngine
- */
-class UnifiedDiffFormatter extends DiffFormatter {
- var $leading_context_lines = 2;
- var $trailing_context_lines = 2;
-
- /**
- * @param $lines
- */
- function _added( $lines ) {
- $this->_lines( $lines, '+' );
- }
-
- /**
- * @param $lines
- */
- function _deleted( $lines ) {
- $this->_lines( $lines, '-' );
- }
-
- /**
- * @param $orig
- * @param $closing
- */
- function _changed( $orig, $closing ) {
- $this->_deleted( $orig );
- $this->_added( $closing );
- }
-
- /**
- * @param $xbeg
- * @param $xlen
- * @param $ybeg
- * @param $ylen
- * @return string
- */
- function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
- return "@@ -$xbeg,$xlen +$ybeg,$ylen @@";
- }
-}
-
-/**
- * A pseudo-formatter that just passes along the Diff::$edits array
- * @ingroup DifferenceEngine
- */
-class ArrayDiffFormatter extends DiffFormatter {
-
- /**
- * @param $diff
- * @return array
- */
- function format( $diff ) {
- $oldline = 1;
- $newline = 1;
- $retval = array();
- foreach ( $diff->edits as $edit ) {
- switch ( $edit->type ) {
- case 'add':
- foreach ( $edit->closing as $l ) {
- $retval[] = array(
- 'action' => 'add',
- 'new' => $l,
- 'newline' => $newline++
- );
- }
- break;
- case 'delete':
- foreach ( $edit->orig as $l ) {
- $retval[] = array(
- 'action' => 'delete',
- 'old' => $l,
- 'oldline' => $oldline++,
- );
- }
- break;
- case 'change':
- foreach ( $edit->orig as $i => $l ) {
- $retval[] = array(
- 'action' => 'change',
- 'old' => $l,
- 'new' => isset( $edit->closing[$i] ) ? $edit->closing[$i] : null,
- 'oldline' => $oldline++,
- 'newline' => $newline++,
- );
- }
- break;
- case 'copy':
- $oldline += count( $edit->orig );
- $newline += count( $edit->orig );
- }
- }
- return $retval;
- }
-}
-
/**
* Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3
*/
-define( 'NBSP', ' ' ); // iso-8859-x non-breaking space.
-
/**
* @todo document
* @private
* @ingroup DifferenceEngine
*/
-class _HWLDF_WordAccumulator {
- function __construct() {
- $this->_lines = array();
- $this->_line = '';
- $this->_group = '';
- $this->_tag = '';
- }
+class HWLDF_WordAccumulator {
+ private $lines = array();
+ private $line = '';
+ private $group = '';
+ private $tag = '';
/**
* @param $new_tag
*/
- function _flushGroup( $new_tag ) {
- if ( $this->_group !== '' ) {
- if ( $this->_tag == 'ins' ) {
- $this->_line .= '<ins class="diffchange diffchange-inline">' .
- htmlspecialchars( $this->_group ) . '</ins>';
- } elseif ( $this->_tag == 'del' ) {
- $this->_line .= '<del class="diffchange diffchange-inline">' .
- htmlspecialchars( $this->_group ) . '</del>';
+ private function flushGroup( $new_tag ) {
+ if ( $this->group !== '' ) {
+ if ( $this->tag == 'ins' ) {
+ $this->line .= '<ins class="diffchange diffchange-inline">' .
+ htmlspecialchars( $this->group ) . '</ins>';
+ } elseif ( $this->tag == 'del' ) {
+ $this->line .= '<del class="diffchange diffchange-inline">' .
+ htmlspecialchars( $this->group ) . '</del>';
} else {
- $this->_line .= htmlspecialchars( $this->_group );
+ $this->line .= htmlspecialchars( $this->group );
}
}
- $this->_group = '';
- $this->_tag = $new_tag;
+ $this->group = '';
+ $this->tag = $new_tag;
}
/**
* @param $new_tag
*/
- function _flushLine( $new_tag ) {
- $this->_flushGroup( $new_tag );
- if ( $this->_line != '' ) {
- array_push( $this->_lines, $this->_line );
+ private function flushLine( $new_tag ) {
+ $this->flushGroup( $new_tag );
+ if ( $this->line != '' ) {
+ array_push( $this->lines, $this->line );
} else {
# make empty lines visible by inserting an NBSP
- array_push( $this->_lines, NBSP );
+ array_push( $this->lines, ' ' );
}
- $this->_line = '';
+ $this->line = '';
}
/**
* @param $words
* @param $tag string
*/
- function addWords( $words, $tag = '' ) {
- if ( $tag != $this->_tag ) {
- $this->_flushGroup( $tag );
+ public function addWords( $words, $tag = '' ) {
+ if ( $tag != $this->tag ) {
+ $this->flushGroup( $tag );
}
foreach ( $words as $word ) {
continue;
}
if ( $word[0] == "\n" ) {
- $this->_flushLine( $tag );
+ $this->flushLine( $tag );
$word = substr( $word, 1 );
}
assert( '!strstr( $word, "\n" )' );
- $this->_group .= $word;
+ $this->group .= $word;
}
}
/**
* @return array
*/
- function getLines() {
- $this->_flushLine( '~done' );
- return $this->_lines;
+ public function getLines() {
+ $this->flushLine( '~done' );
+ return $this->lines;
}
}
function __construct( $orig_lines, $closing_lines ) {
wfProfileIn( __METHOD__ );
- list( $orig_words, $orig_stripped ) = $this->_split( $orig_lines );
- list( $closing_words, $closing_stripped ) = $this->_split( $closing_lines );
+ list( $orig_words, $orig_stripped ) = $this->split( $orig_lines );
+ list( $closing_words, $closing_stripped ) = $this->split( $closing_lines );
parent::__construct( $orig_words, $closing_words,
$orig_stripped, $closing_stripped );
* @param $lines
* @return array
*/
- function _split( $lines ) {
+ private function split( $lines ) {
wfProfileIn( __METHOD__ );
$words = array();
/**
* @return array
*/
- function orig() {
+ public function orig() {
wfProfileIn( __METHOD__ );
- $orig = new _HWLDF_WordAccumulator;
+ $orig = new HWLDF_WordAccumulator;
foreach ( $this->edits as $edit ) {
if ( $edit->type == 'copy' ) {
/**
* @return array
*/
- function closing() {
+ public function closing() {
wfProfileIn( __METHOD__ );
- $closing = new _HWLDF_WordAccumulator;
+ $closing = new HWLDF_WordAccumulator;
foreach ( $this->edits as $edit ) {
if ( $edit->type == 'copy' ) {
return $lines;
}
}
-
-/**
- * Wikipedia Table style diff formatter.
- * @todo document
- * @private
- * @ingroup DifferenceEngine
- */
-class TableDiffFormatter extends DiffFormatter {
- function __construct() {
- $this->leading_context_lines = 2;
- $this->trailing_context_lines = 2;
- }
-
- /**
- * @static
- * @param $msg
- * @return mixed
- */
- public static function escapeWhiteSpace( $msg ) {
- $msg = preg_replace( '/^ /m', '  ', $msg );
- $msg = preg_replace( '/ $/m', '  ', $msg );
- $msg = preg_replace( '/ /', '  ', $msg );
- return $msg;
- }
-
- /**
- * @param $xbeg
- * @param $xlen
- * @param $ybeg
- * @param $ylen
- * @return string
- */
- function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
- $r = '<tr><td colspan="2" class="diff-lineno"><!--LINE ' . $xbeg . "--></td>\n" .
- '<td colspan="2" class="diff-lineno"><!--LINE ' . $ybeg . "--></td></tr>\n";
- return $r;
- }
-
- /**
- * @param $header
- */
- function _start_block( $header ) {
- echo $header;
- }
-
- function _end_block() {
- }
-
- function _lines( $lines, $prefix = ' ', $color = 'white' ) {
- }
-
- /**
- * HTML-escape parameter before calling this
- * @param $line
- * @return string
- */
- function addedLine( $line ) {
- return $this->wrapLine( '+', 'diff-addedline', $line );
- }
-
- /**
- * HTML-escape parameter before calling this
- * @param $line
- * @return string
- */
- function deletedLine( $line ) {
- return $this->wrapLine( '−', 'diff-deletedline', $line );
- }
-
- /**
- * HTML-escape parameter before calling this
- * @param $line
- * @return string
- */
- function contextLine( $line ) {
- return $this->wrapLine( ' ', 'diff-context', $line );
- }
-
- /**
- * @param $marker
- * @param $class
- * @param $line
- * @return string
- */
- private function wrapLine( $marker, $class, $line ) {
- if ( $line !== '' ) {
- // The <div> wrapper is needed for 'overflow: auto' style to scroll properly
- $line = Xml::tags( 'div', null, $this->escapeWhiteSpace( $line ) );
- }
- return "<td class='diff-marker'>$marker</td><td class='$class'>$line</td>";
- }
-
- /**
- * @return string
- */
- function emptyLine() {
- return '<td colspan="2"> </td>';
- }
-
- /**
- * @param $lines array
- */
- function _added( $lines ) {
- foreach ( $lines as $line ) {
- echo '<tr>' . $this->emptyLine() .
- $this->addedLine( '<ins class="diffchange">' .
- htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n";
- }
- }
-
- /**
- * @param $lines
- */
- function _deleted( $lines ) {
- foreach ( $lines as $line ) {
- echo '<tr>' . $this->deletedLine( '<del class="diffchange">' .
- htmlspecialchars( $line ) . '</del>' ) .
- $this->emptyLine() . "</tr>\n";
- }
- }
-
- /**
- * @param $lines
- */
- function _context( $lines ) {
- foreach ( $lines as $line ) {
- echo '<tr>' .
- $this->contextLine( htmlspecialchars( $line ) ) .
- $this->contextLine( htmlspecialchars( $line ) ) . "</tr>\n";
- }
- }
-
- /**
- * @param $orig
- * @param $closing
- */
- function _changed( $orig, $closing ) {
- wfProfileIn( __METHOD__ );
-
- $diff = new WordLevelDiff( $orig, $closing );
- $del = $diff->orig();
- $add = $diff->closing();
-
- # Notice that WordLevelDiff returns HTML-escaped output.
- # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
-
- while ( $line = array_shift( $del ) ) {
- $aline = array_shift( $add );
- echo '<tr>' . $this->deletedLine( $line ) .
- $this->addedLine( $aline ) . "</tr>\n";
- }
- foreach ( $add as $line ) { # If any leftovers
- echo '<tr>' . $this->emptyLine() .
- $this->addedLine( $line ) . "</tr>\n";
- }
- wfProfileOut( __METHOD__ );
- }
-}
--- /dev/null
+<?php
+/**
+ * Base for diff rendering classes. Portions taken from phpwiki-1.3.3.
+ *
+ * Copyright © 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org>
+ * You may copy this code freely under the conditions of the GPL.
+ *
+ * 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
+ */
+
+/**
+ * Base class for diff formatters
+ *
+ * This class formats the diff in classic diff format.
+ * It is intended that this class be customized via inheritance,
+ * to obtain fancier outputs.
+ * @todo document
+ * @ingroup DifferenceEngine
+ */
+abstract class DiffFormatter {
+ /**
+ * Number of leading context "lines" to preserve.
+ *
+ * This should be left at zero for this class, but subclasses
+ * may want to set this to other values.
+ */
+ protected $leadingContextLines = 0;
+
+ /**
+ * Number of trailing context "lines" to preserve.
+ *
+ * This should be left at zero for this class, but subclasses
+ * may want to set this to other values.
+ */
+ protected $trailingContextLines = 0;
+
+ /**
+ * Format a diff.
+ *
+ * @param $diff Diff A Diff object.
+ * @return string The formatted output.
+ */
+ public function format( $diff ) {
+ wfProfileIn( __METHOD__ );
+
+ $xi = $yi = 1;
+ $block = false;
+ $context = array();
+
+ $nlead = $this->leadingContextLines;
+ $ntrail = $this->trailingContextLines;
+
+ $this->startDiff();
+
+ foreach ( $diff->edits as $edit ) {
+ if ( $edit->type == 'copy' ) {
+ if ( is_array( $block ) ) {
+ if ( count( $edit->orig ) <= $nlead + $ntrail ) {
+ $block[] = $edit;
+ } else {
+ if ( $ntrail ) {
+ $context = array_slice( $edit->orig, 0, $ntrail );
+ $block[] = new DiffOp_Copy( $context );
+ }
+ $this->block( $x0, $ntrail + $xi - $x0,
+ $y0, $ntrail + $yi - $y0,
+ $block );
+ $block = false;
+ }
+ }
+ $context = $edit->orig;
+ } else {
+ if ( !is_array( $block ) ) {
+ $context = array_slice( $context, count( $context ) - $nlead );
+ $x0 = $xi - count( $context );
+ $y0 = $yi - count( $context );
+ $block = array();
+ if ( $context ) {
+ $block[] = new DiffOp_Copy( $context );
+ }
+ }
+ $block[] = $edit;
+ }
+
+ if ( $edit->orig ) {
+ $xi += count( $edit->orig );
+ }
+ if ( $edit->closing ) {
+ $yi += count( $edit->closing );
+ }
+ }
+
+ if ( is_array( $block ) ) {
+ $this->block( $x0, $xi - $x0,
+ $y0, $yi - $y0,
+ $block );
+ }
+
+ $end = $this->endDiff();
+ wfProfileOut( __METHOD__ );
+ return $end;
+ }
+
+ /**
+ * @param $xbeg
+ * @param $xlen
+ * @param $ybeg
+ * @param $ylen
+ * @param $edits
+ */
+ protected function block( $xbeg, $xlen, $ybeg, $ylen, &$edits ) {
+ wfProfileIn( __METHOD__ );
+ $this->startBlock( $this->blockHeader( $xbeg, $xlen, $ybeg, $ylen ) );
+ foreach ( $edits as $edit ) {
+ if ( $edit->type == 'copy' ) {
+ $this->context( $edit->orig );
+ } elseif ( $edit->type == 'add' ) {
+ $this->added( $edit->closing );
+ } elseif ( $edit->type == 'delete' ) {
+ $this->deleted( $edit->orig );
+ } elseif ( $edit->type == 'change' ) {
+ $this->changed( $edit->orig, $edit->closing );
+ } else {
+ throw new MWException( "Unknown edit type: {$edit->type}" );
+ }
+ }
+ $this->endBlock();
+ wfProfileOut( __METHOD__ );
+ }
+
+ protected function startDiff() {
+ ob_start();
+ }
+
+ /**
+ * @return string
+ */
+ protected function endDiff() {
+ $val = ob_get_contents();
+ ob_end_clean();
+ return $val;
+ }
+
+ /**
+ * @param $xbeg
+ * @param $xlen
+ * @param $ybeg
+ * @param $ylen
+ * @return string
+ */
+ protected function blockHeader( $xbeg, $xlen, $ybeg, $ylen ) {
+ if ( $xlen > 1 ) {
+ $xbeg .= ',' . ( $xbeg + $xlen - 1 );
+ }
+ if ( $ylen > 1 ) {
+ $ybeg .= ',' . ( $ybeg + $ylen - 1 );
+ }
+
+ return $xbeg . ( $xlen ? ( $ylen ? 'c' : 'd' ) : 'a' ) . $ybeg;
+ }
+
+ protected function startBlock( $header ) {
+ echo $header . "\n";
+ }
+
+ protected function endBlock() {
+ }
+
+ /**
+ * @param $lines
+ * @param $prefix string
+ */
+ protected function lines( $lines, $prefix = ' ' ) {
+ foreach ( $lines as $line ) {
+ echo "$prefix $line\n";
+ }
+ }
+
+ /**
+ * @param $lines
+ */
+ protected function context( $lines ) {
+ $this->lines( $lines );
+ }
+
+ /**
+ * @param $lines
+ */
+ protected function added( $lines ) {
+ $this->lines( $lines, '>' );
+ }
+
+ /**
+ * @param $lines
+ */
+ protected function deleted( $lines ) {
+ $this->lines( $lines, '<' );
+ }
+
+ /**
+ * @param $orig
+ * @param $closing
+ */
+ protected function changed( $orig, $closing ) {
+ $this->deleted( $orig );
+ echo "---\n";
+ $this->added( $closing );
+ }
+}
* @ingroup DifferenceEngine
*/
-/**
- * Constant to indicate diff cache compatibility.
- * Bump this when changing the diff formatting in a way that
- * fixes important bugs or such to force cached diff views to
- * clear.
- */
-define( 'MW_DIFF_VERSION', '1.11a' );
-
/**
* @todo document
* @ingroup DifferenceEngine
*/
class DifferenceEngine extends ContextSource {
- public $mOldid;
- public $mNewid;
- private $mOldTags;
- private $mNewTags;
+ /**
+ * Constant to indicate diff cache compatibility.
+ * Bump this when changing the diff formatting in a way that
+ * fixes important bugs or such to force cached diff views to
+ * clear.
+ */
+ const CACHE_VERSION ='1.11a';
+ /**#@+
+ * @private
+ */
+ public $oldId;
+ public $newId;
+ private $oldTags;
+ private $newTags;
/**
* @var Content
*/
- public $mOldContent;
- public $mNewContent;
- protected $mDiffLang;
+ public $oldContent;
+ /**
+ * @var Content
+ */
+ public $newContent;
+ protected $diffLang;
/**
* @var Title
*/
- public $mOldPage;
- public $mNewPage;
+ public $oldPage;
+ /**
+ * @var Title
+ */
+ public $newPage;
/**
* @var Revision
*/
- public $mOldRev;
- 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?
+ public $oldRev;
+ /**
+ * @var Revision
+ */
+ public $newRev;
+ private $revisionsIdsLoaded = false; // Have the revisions IDs been loaded
+ public $revisionsLoaded = false; // Have the revisions been loaded
+ public $textLoaded = 0; // How many text blobs have been loaded, 0, 1 or 2?
+ public $cacheHit = false; // Was the diff fetched from cache?
/**
* Set this to true to add debug info to the HTML output.
// 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;
+ protected $reducedLineNumbers = false;
// Link to action=markpatrolled
- protected $mMarkPatrolledLink = null;
+ protected $markPatrolledLink = null;
protected $unhide = false; # show rev_deleted content if allowed
+ private $refreshCache;
/**#@-*/
/**
* Constructor
* @param $context IContextSource context to use, anything else will be ignored
* @param $old Integer old ID we want to show and diff with.
- * @param $new String|int either 'prev' or 'next'. Default: 0.
+ * @param $new String|int either revision ID or 'prev' or 'next'. Default: 0.
* @param $rcid Integer Deprecated, no longer used!
* @param $refreshCache boolean If set, refreshes the diff cache
* @param $unhide boolean If set, allow viewing deleted revs
wfDebug( "DifferenceEngine old '$old' new '$new' rcid '$rcid'\n" );
- $this->mOldid = $old;
- $this->mNewid = $new;
- $this->mRefreshCache = $refreshCache;
+ $this->oldId = $old;
+ $this->newId = $new;
+ $this->refreshCache = $refreshCache;
$this->unhide = $unhide;
}
* @param $value bool
*/
function setReducedLineNumbers( $value = true ) {
- $this->mReducedLineNumbers = $value;
+ $this->reducedLineNumbers = $value;
}
/**
* @return Language
*/
function getDiffLang() {
- if ( $this->mDiffLang === null ) {
+ if ( $this->diffLang === null ) {
# Default language in which the diff text is written.
- $this->mDiffLang = $this->getTitle()->getPageLanguage();
+ $this->diffLang = $this->getTitle()->getPageLanguage();
}
- return $this->mDiffLang;
+ return $this->diffLang;
}
/**
* @return bool
*/
function wasCacheHit() {
- return $this->mCacheHit;
+ return $this->cacheHit;
}
/**
*/
function getOldid() {
$this->loadRevisionIds();
- return $this->mOldid;
+ return $this->oldId;
}
/**
*/
function getNewid() {
$this->loadRevisionIds();
- return $this->mNewid;
+ return $this->newId;
}
/**
$out = $this->getOutput();
$missing = array();
- if ( $this->mOldRev === null ||
- ( $this->mOldRev && $this->mOldContent === null )
+ if ( $this->oldRev === null ||
+ ( $this->oldRev && $this->oldContent === null )
) {
- $missing[] = $this->deletedIdMarker( $this->mOldid );
+ $missing[] = $this->deletedIdMarker( $this->oldId );
}
- if ( $this->mNewRev === null ||
- ( $this->mNewRev && $this->mNewContent === null )
+ if ( $this->newRev === null ||
+ ( $this->newRev && $this->newContent === null )
) {
- $missing[] = $this->deletedIdMarker( $this->mNewid );
+ $missing[] = $this->deletedIdMarker( $this->newId );
}
$out->setPageTitle( $this->msg( 'errorpagetitle' ) );
}
$user = $this->getUser();
- $permErrors = $this->mNewPage->getUserPermissionsErrors( 'read', $user );
- if ( $this->mOldPage ) { # mOldPage might not be set, see below.
+ $permErrors = $this->newPage->getUserPermissionsErrors( 'read', $user );
+ if ( $this->oldPage ) { # oldPage might not be set, see below.
$permErrors = wfMergeErrorArrays( $permErrors,
- $this->mOldPage->getUserPermissionsErrors( 'read', $user ) );
+ $this->oldPage->getUserPermissionsErrors( 'read', $user ) );
}
if ( count( $permErrors ) ) {
wfProfileOut( __METHOD__ );
}
$rollback = '';
- $undoLink = '';
$query = array();
# Carry over 'diffonly' param via navigation links
# Check if one of the revisions is deleted/suppressed
$deleted = $suppressed = false;
- $allowed = $this->mNewRev->userCan( Revision::DELETED_TEXT, $user );
+ $allowed = $this->newRev->userCan( Revision::DELETED_TEXT, $user );
$revisionTools = array();
- # mOldRev is false if the difference engine is called with a "vague" query for
+ # oldRev is false if the difference engine is called with a "vague" query for
# 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->msg( 'difference-title', $this->mNewPage->getPrefixedText() ) );
+ if ( $this->oldRev === false ) {
+ $out->setPageTitle( $this->msg( 'difference-title', $this->newPage->getPrefixedText() ) );
$samePage = true;
$oldHeader = '';
} else {
- wfRunHooks( 'DiffViewHeader', array( $this, $this->mOldRev, $this->mNewRev ) );
+ wfRunHooks( 'DiffViewHeader', array( $this, $this->oldRev, $this->newRev ) );
- if ( $this->mNewPage->equals( $this->mOldPage ) ) {
- $out->setPageTitle( $this->msg( 'difference-title', $this->mNewPage->getPrefixedText() ) );
+ if ( $this->newPage->equals( $this->oldPage ) ) {
+ $out->setPageTitle( $this->msg( 'difference-title', $this->newPage->getPrefixedText() ) );
$samePage = true;
} else {
$out->setPageTitle( $this->msg( 'difference-title-multipage',
- $this->mOldPage->getPrefixedText(), $this->mNewPage->getPrefixedText() ) );
+ $this->oldPage->getPrefixedText(), $this->newPage->getPrefixedText() ) );
$out->addSubtitle( $this->msg( 'difference-multipage' ) );
$samePage = false;
}
- if ( $samePage && $this->mNewPage->quickUserCan( 'edit', $user ) ) {
- if ( $this->mNewRev->isCurrent() && $this->mNewPage->userCan( 'rollback', $user ) ) {
- $rollbackLink = Linker::generateRollback( $this->mNewRev, $this->getContext() );
+ if ( $samePage && $this->newPage->quickUserCan( 'edit', $user ) ) {
+ if ( $this->newRev->isCurrent() && $this->newPage->userCan( 'rollback', $user ) ) {
+ $rollbackLink = Linker::generateRollback( $this->newRev, $this->getContext() );
if ( $rollbackLink ) {
$out->preventClickjacking();
$rollback = '   ' . $rollbackLink;
}
}
- if ( !$this->mOldRev->isDeleted( Revision::DELETED_TEXT ) &&
- !$this->mNewRev->isDeleted( Revision::DELETED_TEXT )
+ if ( !$this->oldRev->isDeleted( Revision::DELETED_TEXT ) &&
+ !$this->newRev->isDeleted( Revision::DELETED_TEXT )
) {
$undoLink = Html::element( 'a', array(
- 'href' => $this->mNewPage->getLocalURL( array(
+ 'href' => $this->newPage->getLocalURL( array(
'action' => 'edit',
- 'undoafter' => $this->mOldid,
- 'undo' => $this->mNewid ) ),
+ 'undoafter' => $this->oldId,
+ 'undo' => $this->newId ) ),
'title' => Linker::titleAttrib( 'undo' )
),
$this->msg( 'editundo' )->text()
}
# Make "previous revision link"
- if ( $samePage && $this->mOldRev->getPrevious() ) {
+ if ( $samePage && $this->oldRev->getPrevious() ) {
$prevlink = Linker::linkKnown(
- $this->mOldPage,
+ $this->oldPage,
$this->msg( 'previousdiff' )->escaped(),
array( 'id' => 'differences-prevlink' ),
- array( 'diff' => 'prev', 'oldid' => $this->mOldid ) + $query
+ array( 'diff' => 'prev', 'oldid' => $this->oldId ) + $query
);
} else {
$prevlink = ' ';
}
- if ( $this->mOldRev->isMinor() ) {
+ if ( $this->oldRev->isMinor() ) {
$oldminor = ChangesList::flag( 'minor' );
} else {
$oldminor = '';
}
- $ldel = $this->revisionDeleteLink( $this->mOldRev );
- $oldRevisionHeader = $this->getRevisionHeader( $this->mOldRev, 'complete' );
- $oldChangeTags = ChangeTags::formatSummaryRow( $this->mOldTags, 'diff' );
+ $ldel = $this->revisionDeleteLink( $this->oldRev );
+ $oldRevisionHeader = $this->getRevisionHeader( $this->oldRev, 'complete' );
+ $oldChangeTags = ChangeTags::formatSummaryRow( $this->oldTags, 'diff' );
$oldHeader = '<div id="mw-diff-otitle1"><strong>' . $oldRevisionHeader . '</strong></div>' .
'<div id="mw-diff-otitle2">' .
- Linker::revUserTools( $this->mOldRev, !$this->unhide ) . '</div>' .
+ Linker::revUserTools( $this->oldRev, !$this->unhide ) . '</div>' .
'<div id="mw-diff-otitle3">' . $oldminor .
- Linker::revComment( $this->mOldRev, !$diffOnly, !$this->unhide ) . $ldel . '</div>' .
+ Linker::revComment( $this->oldRev, !$diffOnly, !$this->unhide ) . $ldel . '</div>' .
'<div id="mw-diff-otitle5">' . $oldChangeTags[0] . '</div>' .
'<div id="mw-diff-otitle4">' . $prevlink . '</div>';
- if ( $this->mOldRev->isDeleted( Revision::DELETED_TEXT ) ) {
+ if ( $this->oldRev->isDeleted( Revision::DELETED_TEXT ) ) {
$deleted = true; // old revisions text is hidden
- if ( $this->mOldRev->isDeleted( Revision::DELETED_RESTRICTED ) ) {
+ if ( $this->oldRev->isDeleted( Revision::DELETED_RESTRICTED ) ) {
$suppressed = true; // also suppressed
}
}
# Check if this user can see the revisions
- if ( !$this->mOldRev->userCan( Revision::DELETED_TEXT, $user ) ) {
+ if ( !$this->oldRev->userCan( Revision::DELETED_TEXT, $user ) ) {
$allowed = false;
}
}
# Make "next revision link"
# Skip next link on the top revision
- if ( $samePage && !$this->mNewRev->isCurrent() ) {
+ if ( $samePage && !$this->newRev->isCurrent() ) {
$nextlink = Linker::linkKnown(
- $this->mNewPage,
+ $this->newPage,
$this->msg( 'nextdiff' )->escaped(),
array( 'id' => 'differences-nextlink' ),
- array( 'diff' => 'next', 'oldid' => $this->mNewid ) + $query
+ array( 'diff' => 'next', 'oldid' => $this->newId ) + $query
);
} else {
$nextlink = ' ';
}
- if ( $this->mNewRev->isMinor() ) {
+ if ( $this->newRev->isMinor() ) {
$newminor = ChangesList::flag( 'minor' );
} else {
$newminor = '';
}
# Handle RevisionDelete links...
- $rdel = $this->revisionDeleteLink( $this->mNewRev );
+ $rdel = $this->revisionDeleteLink( $this->newRev );
# Allow extensions to define their own revision tools
- wfRunHooks( 'DiffRevisionTools', array( $this->mNewRev, &$revisionTools ) );
+ wfRunHooks( 'DiffRevisionTools', array( $this->newRev, &$revisionTools ) );
$formattedRevisionTools = array();
// Put each one in parentheses (poor man's button)
foreach ( $revisionTools as $tool ) {
$formattedRevisionTools[] = $this->msg( 'parentheses' )->rawParams( $tool )->escaped();
}
- $newRevisionHeader = $this->getRevisionHeader( $this->mNewRev, 'complete' ) .
+ $newRevisionHeader = $this->getRevisionHeader( $this->newRev, 'complete' ) .
' ' . implode( ' ', $formattedRevisionTools );
- $newChangeTags = ChangeTags::formatSummaryRow( $this->mNewTags, 'diff' );
+ $newChangeTags = ChangeTags::formatSummaryRow( $this->newTags, 'diff' );
$newHeader = '<div id="mw-diff-ntitle1"><strong>' . $newRevisionHeader . '</strong></div>' .
- '<div id="mw-diff-ntitle2">' . Linker::revUserTools( $this->mNewRev, !$this->unhide ) .
+ '<div id="mw-diff-ntitle2">' . Linker::revUserTools( $this->newRev, !$this->unhide ) .
" $rollback</div>" .
'<div id="mw-diff-ntitle3">' . $newminor .
- Linker::revComment( $this->mNewRev, !$diffOnly, !$this->unhide ) . $rdel . '</div>' .
+ Linker::revComment( $this->newRev, !$diffOnly, !$this->unhide ) . $rdel . '</div>' .
'<div id="mw-diff-ntitle5">' . $newChangeTags[0] . '</div>' .
'<div id="mw-diff-ntitle4">' . $nextlink . $this->markPatrolledLink() . '</div>';
- if ( $this->mNewRev->isDeleted( Revision::DELETED_TEXT ) ) {
+ if ( $this->newRev->isDeleted( Revision::DELETED_TEXT ) ) {
$deleted = true; // new revisions text is hidden
- if ( $this->mNewRev->isDeleted( Revision::DELETED_RESTRICTED ) ) {
+ if ( $this->newRev->isDeleted( Revision::DELETED_RESTRICTED ) ) {
$suppressed = true; // also suppressed
}
}
global $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
$user = $this->getUser();
- if ( $this->mMarkPatrolledLink === null ) {
+ if ( $this->markPatrolledLink === null ) {
// Prepare a change patrol link, if applicable
if (
// Is patrolling enabled and the user allowed to?
- $wgUseRCPatrol && $this->mNewPage->quickUserCan( 'patrol', $user ) &&
+ $wgUseRCPatrol && $this->newPage->quickUserCan( 'patrol', $user ) &&
// Only do this if the revision isn't more than 6 hours older
// than the Max RC age (6h because the RC might not be cleaned out regularly)
- RecentChange::isInRCLifespan( $this->mNewRev->getTimestamp(), 21600 )
+ RecentChange::isInRCLifespan( $this->newRev->getTimestamp(), 21600 )
) {
// Look for an unpatrolled change corresponding to this diff
$db = wfGetDB( DB_SLAVE );
$change = RecentChange::newFromConds(
array(
- 'rc_timestamp' => $db->timestamp( $this->mNewRev->getTimestamp() ),
- 'rc_this_oldid' => $this->mNewid,
+ 'rc_timestamp' => $db->timestamp( $this->newRev->getTimestamp() ),
+ 'rc_this_oldid' => $this->newId,
'rc_patrolled' => 0
),
__METHOD__,
}
$token = $user->getEditToken( $rcid );
- $this->mMarkPatrolledLink = ' <span class="patrollink">[' . Linker::linkKnown(
- $this->mNewPage,
+ $this->markPatrolledLink = ' <span class="patrollink">[' . Linker::linkKnown(
+ $this->newPage,
$this->msg( 'markaspatrolleddiff' )->escaped(),
array(),
array(
)
) . ']</span>';
} else {
- $this->mMarkPatrolledLink = '';
+ $this->markPatrolledLink = '';
}
} else {
- $this->mMarkPatrolledLink = '';
+ $this->markPatrolledLink = '';
}
}
- return $this->mMarkPatrolledLink;
+ return $this->markPatrolledLink;
}
/**
function renderNewRevision() {
wfProfileIn( __METHOD__ );
$out = $this->getOutput();
- $revHeader = $this->getRevisionHeader( $this->mNewRev );
+ $revHeader = $this->getRevisionHeader( $this->newRev );
# Add "current version as of X" title
$out->addHTML( "<hr class='diff-hr' />
<h2 class='diff-currentversion-title'>{$revHeader}</h2>\n" );
# @codingStandardsIgnoreStart Ignoring long lines.
if ( wfRunHooks( 'ArticleContentOnDiff', array( $this, $out ) ) ) {
$this->loadNewText();
- $out->setRevisionId( $this->mNewid );
- $out->setRevisionTimestamp( $this->mNewRev->getTimestamp() );
+ $out->setRevisionId( $this->newId );
+ $out->setRevisionTimestamp( $this->newRev->getTimestamp() );
$out->setArticleFlag( true );
// NOTE: only needed for B/C: custom rendering of JS/CSS via hook
- if ( $this->mNewPage->isCssJsSubpage() || $this->mNewPage->isCssOrJsPage() ) {
+ if ( $this->newPage->isCssJsSubpage() || $this->newPage->isCssOrJsPage() ) {
// Stolen from Article::view --AG 2007-10-11
// Give hooks a chance to customise the output
// @todo standardize this crap into one function
- if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
+ if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->newContent, $this->newPage, $out ) ) ) {
// NOTE: deprecated hook, B/C only
// use the content object's own rendering
- $cnt = $this->mNewRev->getContent();
- $po = $cnt ? $cnt->getParserOutput( $this->mNewRev->getTitle(), $this->mNewRev->getId() ) : null;
+ $cnt = $this->newRev->getContent();
+ $po = $cnt ? $cnt->getParserOutput( $this->newRev->getTitle(), $this->newRev->getId() ) : null;
$txt = $po ? $po->getText() : '';
$out->addHTML( $txt );
}
- } elseif ( !wfRunHooks( 'ArticleContentViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
+ } elseif ( !wfRunHooks( 'ArticleContentViewCustom', array( $this->newContent, $this->newPage, $out ) ) ) {
// Handled by extension
- } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
+ } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom', array( $this->newContent, $this->newPage, $out ) ) ) {
// NOTE: deprecated hook, B/C only
// Handled by extension
} else {
// Normal page
- if ( $this->getTitle()->equals( $this->mNewPage ) ) {
+ if ( $this->getTitle()->equals( $this->newPage ) ) {
// If the Title stored in the context is the same as the one
// of the new revision, we can use its associated WikiPage
// object.
$wikiPage = $this->getWikiPage();
} else {
// Otherwise we need to create our own WikiPage object
- $wikiPage = WikiPage::factory( $this->mNewPage );
+ $wikiPage = WikiPage::factory( $this->newPage );
}
- $parserOutput = $this->getParserOutput( $wikiPage, $this->mNewRev );
+ $parserOutput = $this->getParserOutput( $wikiPage, $this->newRev );
# Also try to load it as a redirect
- $rt = $this->mNewContent ? $this->mNewContent->getRedirectTarget() : null;
+ $rt = $this->newContent ? $this->newContent->getRedirectTarget() : null;
if ( $rt ) {
- $article = Article::newFromTitle( $this->mNewPage, $this->getContext() );
+ $article = Article::newFromTitle( $this->newPage, $this->getContext() );
$out->addHTML( $article->viewRedirect( $rt ) );
# WikiPage::getParserOutput() should not return false, but just in case
*
* @param string|bool $otitle Header for old text or false
* @param string|bool $ntitle Header for new text or false
- * @param string $notice
+ * @param string $notice HTML between diff header and body
+ *
* @return bool
*/
function showDiff( $otitle, $ntitle, $notice = '' ) {
public function getDiffBody() {
global $wgMemc;
wfProfileIn( __METHOD__ );
- $this->mCacheHit = true;
+ $this->cacheHit = true;
// 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() )
+ } elseif ( $this->oldRev &&
+ !$this->oldRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
) {
wfProfileOut( __METHOD__ );
return false;
- } elseif ( $this->mNewRev &&
- !$this->mNewRev->userCan( Revision::DELETED_TEXT, $this->getUser() )
+ } elseif ( $this->newRev &&
+ !$this->newRev->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() ) )
+ if ( $this->oldRev === false || ( $this->oldRev && $this->newRev
+ && $this->oldRev->getID() == $this->newRev->getID() ) )
{
wfProfileOut( __METHOD__ );
return '';
}
// Cacheable?
$key = false;
- if ( $this->mOldid && $this->mNewid ) {
+ if ( $this->oldId && $this->newId ) {
$key = $this->getDiffBodyCacheKey();
// Try cache
- if ( !$this->mRefreshCache ) {
+ if ( !$this->refreshCache ) {
$difftext = $wgMemc->get( $key );
if ( $difftext ) {
wfIncrStats( 'diff_cache_hit' );
}
} // don't try to load but save the result
}
- $this->mCacheHit = false;
+ $this->cacheHit = false;
// Loadtext is permission safe, this just clears out the diff
if ( !$this->loadText() ) {
return false;
}
- $difftext = $this->generateContentDiffBody( $this->mOldContent, $this->mNewContent );
+ $difftext = $this->generateContentDiffBody( $this->oldContent, $this->newContent );
// Save to cache for 7 days
if ( !wfRunHooks( 'AbortDiffCache', array( &$this ) ) ) {
* @throws MWException
*/
protected function getDiffBodyCacheKey() {
- if ( !$this->mOldid || !$this->mNewid ) {
- throw new MWException( 'mOldid and mNewid must be set to get diff cache key.' );
+ if ( !$this->oldId || !$this->newId ) {
+ throw new MWException( 'oldId and newId must be set to get diff cache key.' );
}
- return wfMemcKey( 'diff', 'version', MW_DIFF_VERSION,
- 'oldid', $this->mOldid, 'newid', $this->mNewid );
+ return wfMemcKey( 'diff', 'version', self::CACHE_VERSION,
+ 'oldid', $this->oldId, 'newid', $this->newId );
}
/**
/**
* Generate a debug comment indicating diff generating time,
* server node, and generator backend.
+ *
+ * @param String $generator: What diff engine was used
+ *
* @return string
*/
protected function debug( $generator = "internal" ) {
$data[] = wfHostname();
}
$data[] = wfTimestamp( TS_DB );
- return "<!-- diff generator: " .
- implode( " ",
- array_map(
+ return "<!-- diff generator: "
+ . implode( " ",
+ array_map(
"htmlspecialchars",
- $data ) ) .
- " -->\n";
+ $data )
+ )
+ . " -->\n";
}
/**
* Replace line numbers with the text in the user's language
+ *
+ * @param String $text
+ *
* @return mixed
*/
function localiseLineNumbers( $text ) {
}
function localiseLineNumbersCb( $matches ) {
- if ( $matches[1] === '1' && $this->mReducedLineNumbers ) {
+ if ( $matches[1] === '1' && $this->reducedLineNumbers ) {
return '';
}
return $this->msg( 'lineno' )->numParams( $matches[1] )->escaped();
* @return string
*/
function getMultiNotice() {
- if ( !is_object( $this->mOldRev ) || !is_object( $this->mNewRev ) ) {
+ if ( !is_object( $this->oldRev ) || !is_object( $this->newRev ) ) {
return '';
- } elseif ( !$this->mOldPage->equals( $this->mNewPage ) ) {
+ } elseif ( !$this->oldPage->equals( $this->newPage ) ) {
// Comparing two different pages? Count would be meaningless.
return '';
}
- if ( $this->mOldRev->getTimestamp() > $this->mNewRev->getTimestamp() ) {
- $oldRev = $this->mNewRev; // flip
- $newRev = $this->mOldRev; // flip
+ if ( $this->oldRev->getTimestamp() > $this->newRev->getTimestamp() ) {
+ $oldRev = $this->newRev; // flip
+ $newRev = $this->oldRev; // flip
} else { // normal case
- $oldRev = $this->mOldRev;
- $newRev = $this->mNewRev;
+ $oldRev = $this->oldRev;
+ $newRev = $this->newRev;
}
- $nEdits = $this->mNewPage->countRevisionsBetween( $oldRev, $newRev );
+ $nEdits = $this->newPage->countRevisionsBetween( $oldRev, $newRev );
if ( $nEdits > 0 ) {
$limit = 100; // use diff-multi-manyusers if too many users
- $numUsers = $this->mNewPage->countAuthorsBetween( $oldRev, $newRev, $limit );
+ $numUsers = $this->newPage->countAuthorsBetween( $oldRev, $newRev, $limit );
return self::intermediateEditsMsg( $nEdits, $numUsers, $limit );
}
return ''; // nothing
/**
* 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
+ *
* @return string
*/
function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) {
* @since 1.21
*/
function setContent( Content $oldContent, Content $newContent ) {
- $this->mOldContent = $oldContent;
- $this->mNewContent = $newContent;
+ $this->oldContent = $oldContent;
+ $this->newContent = $newContent;
- $this->mTextLoaded = 2;
- $this->mRevisionsLoaded = true;
+ $this->textLoaded = 2;
+ $this->revisionsLoaded = true;
}
/**
* @since 1.19
*/
function setTextLanguage( $lang ) {
- $this->mDiffLang = wfGetLangObj( $lang );
+ $this->diffLang = wfGetLangObj( $lang );
}
/**
* Load revision IDs
*/
private function loadRevisionIds() {
- if ( $this->mRevisionsIdsLoaded ) {
+ if ( $this->revisionsIdsLoaded ) {
return;
}
- $this->mRevisionsIdsLoaded = true;
+ $this->revisionsIdsLoaded = true;
- $old = $this->mOldid;
- $new = $this->mNewid;
+ $old = $this->oldId;
+ $new = $this->newId;
- list( $this->mOldid, $this->mNewid ) = self::mapDiffPrevNext( $old, $new );
- if ( $new === 'next' && $this->mNewid === false ) {
+ list( $this->oldId, $this->newId ) = self::mapDiffPrevNext( $old, $new );
+ if ( $new === 'next' && $this->newId === false ) {
# if no result, NewId points to the newest old revision. The only newer
# revision is cur, which is "0".
- $this->mNewid = 0;
+ $this->newId = 0;
}
- wfRunHooks( 'NewDifferenceEngine', array( $this->getTitle(), &$this->mOldid, &$this->mNewid, $old, $new ) );
+ wfRunHooks( 'NewDifferenceEngine', array( $this->getTitle(), &$this->oldId, &$this->newId, $old, $new ) );
}
/**
* @return bool
*/
function loadRevisionData() {
- if ( $this->mRevisionsLoaded ) {
+ if ( $this->revisionsLoaded ) {
return true;
}
// Whether it succeeds or fails, we don't want to try again
- $this->mRevisionsLoaded = true;
+ $this->revisionsLoaded = true;
$this->loadRevisionIds();
// Load the new revision object
- if ( $this->mNewid ) {
- $this->mNewRev = Revision::newFromId( $this->mNewid );
+ if ( $this->newId ) {
+ $this->newRev = Revision::newFromId( $this->newId );
} else {
- $this->mNewRev = Revision::newFromTitle(
+ $this->newRev = Revision::newFromTitle(
$this->getTitle(),
false,
Revision::READ_NORMAL
);
}
- if ( !$this->mNewRev instanceof Revision ) {
+ if ( !$this->newRev instanceof Revision ) {
return false;
}
// Update the new revision ID in case it was 0 (makes life easier doing UI stuff)
- $this->mNewid = $this->mNewRev->getId();
- $this->mNewPage = $this->mNewRev->getTitle();
+ $this->newId = $this->newRev->getId();
+ $this->newPage = $this->newRev->getTitle();
// Load the old revision object
- $this->mOldRev = false;
- if ( $this->mOldid ) {
- $this->mOldRev = Revision::newFromId( $this->mOldid );
- } elseif ( $this->mOldid === 0 ) {
- $rev = $this->mNewRev->getPrevious();
+ $this->oldRev = false;
+ if ( $this->oldId ) {
+ $this->oldRev = Revision::newFromId( $this->oldId );
+ } elseif ( $this->oldId === 0 ) {
+ $rev = $this->newRev->getPrevious();
if ( $rev ) {
- $this->mOldid = $rev->getId();
- $this->mOldRev = $rev;
+ $this->oldId = $rev->getId();
+ $this->oldRev = $rev;
} else {
// No previous revision; mark to show as first-version only.
- $this->mOldid = false;
- $this->mOldRev = false;
+ $this->oldId = false;
+ $this->oldRev = false;
}
- } /* elseif ( $this->mOldid === false ) leave mOldRev false; */
+ } /* elseif ( $this->oldId === false ) leave oldRev false; */
- if ( is_null( $this->mOldRev ) ) {
+ if ( is_null( $this->oldRev ) ) {
return false;
}
- if ( $this->mOldRev ) {
- $this->mOldPage = $this->mOldRev->getTitle();
+ if ( $this->oldRev ) {
+ $this->oldPage = $this->oldRev->getTitle();
}
// Load tags information for both revisions
$dbr = wfGetDB( DB_SLAVE );
- if ( $this->mOldid !== false ) {
- $this->mOldTags = $dbr->selectField(
+ if ( $this->oldId !== false ) {
+ $this->oldTags = $dbr->selectField(
'tag_summary',
'ts_tags',
- array( 'ts_rev_id' => $this->mOldid ),
+ array( 'ts_rev_id' => $this->oldId ),
__METHOD__
);
} else {
- $this->mOldTags = false;
+ $this->oldTags = false;
}
- $this->mNewTags = $dbr->selectField(
+ $this->newTags = $dbr->selectField(
'tag_summary',
'ts_tags',
- array( 'ts_rev_id' => $this->mNewid ),
+ array( 'ts_rev_id' => $this->newId ),
__METHOD__
);
* @return bool
*/
function loadText() {
- if ( $this->mTextLoaded == 2 ) {
+ if ( $this->textLoaded == 2 ) {
return true;
}
// Whether it succeeds or fails, we don't want to try again
- $this->mTextLoaded = 2;
+ $this->textLoaded = 2;
if ( !$this->loadRevisionData() ) {
return false;
}
- if ( $this->mOldRev ) {
- $this->mOldContent = $this->mOldRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
- if ( $this->mOldContent === null ) {
+ if ( $this->oldRev ) {
+ $this->oldContent = $this->oldRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
+ if ( $this->oldContent === null ) {
return false;
}
}
- if ( $this->mNewRev ) {
- $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
- if ( $this->mNewContent === null ) {
+ if ( $this->newRev ) {
+ $this->newContent = $this->newRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
+ if ( $this->newContent === null ) {
return false;
}
}
* @return bool
*/
function loadNewText() {
- if ( $this->mTextLoaded >= 1 ) {
+ if ( $this->textLoaded >= 1 ) {
return true;
}
- $this->mTextLoaded = 1;
+ $this->textLoaded = 1;
if ( !$this->loadRevisionData() ) {
return false;
}
- $this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
+ $this->newContent = $this->newRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
return true;
}
--- /dev/null
+<?php
+/**
+ * Portions taken from phpwiki-1.3.3.
+ *
+ * Copyright © 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org>
+ * You may copy this code freely under the conditions of the GPL.
+ *
+ * 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
+ */
+
+/**
+ * MediaWiki default table style diff formatter
+ * @todo document
+ * @private
+ * @ingroup DifferenceEngine
+ */
+class TableDiffFormatter extends DiffFormatter {
+ function __construct() {
+ $this->leadingContextLines = 2;
+ $this->trailingContextLines = 2;
+ }
+
+ /**
+ * @static
+ * @param $msg
+ * @return mixed
+ */
+ public static function escapeWhiteSpace( $msg ) {
+ $msg = preg_replace( '/^ /m', '  ', $msg );
+ $msg = preg_replace( '/ $/m', '  ', $msg );
+ $msg = preg_replace( '/ /', '  ', $msg );
+ return $msg;
+ }
+
+ /**
+ * @param $xbeg
+ * @param $xlen
+ * @param $ybeg
+ * @param $ylen
+ * @return string
+ */
+ protected function blockHeader( $xbeg, $xlen, $ybeg, $ylen ) {
+ $r = '<tr><td colspan="2" class="diff-lineno"><!--LINE ' . $xbeg . "--></td>\n" .
+ '<td colspan="2" class="diff-lineno"><!--LINE ' . $ybeg . "--></td></tr>\n";
+ return $r;
+ }
+
+ /**
+ * @param $header
+ */
+ protected function startBlock( $header ) {
+ echo $header;
+ }
+
+ protected function endBlock() {
+ }
+
+ protected function lines( $lines, $prefix = ' ', $color = 'white' ) {
+ }
+
+ /**
+ * HTML-escape parameter before calling this
+ * @param $line
+ * @return string
+ */
+ protected function addedLine( $line ) {
+ return $this->wrapLine( '+', 'diff-addedline', $line );
+ }
+
+ /**
+ * HTML-escape parameter before calling this
+ * @param $line
+ * @return string
+ */
+ protected function deletedLine( $line ) {
+ return $this->wrapLine( '−', 'diff-deletedline', $line );
+ }
+
+ /**
+ * HTML-escape parameter before calling this
+ * @param $line
+ * @return string
+ */
+ protected function contextLine( $line ) {
+ return $this->wrapLine( ' ', 'diff-context', $line );
+ }
+
+ /**
+ * @param $marker
+ * @param $class
+ * @param $line
+ * @return string
+ */
+ protected function wrapLine( $marker, $class, $line ) {
+ if ( $line !== '' ) {
+ // The <div> wrapper is needed for 'overflow: auto' style to scroll properly
+ $line = Xml::tags( 'div', null, $this->escapeWhiteSpace( $line ) );
+ }
+ return "<td class='diff-marker'>$marker</td><td class='$class'>$line</td>";
+ }
+
+ /**
+ * @return string
+ */
+ protected function emptyLine() {
+ return '<td colspan="2"> </td>';
+ }
+
+ /**
+ * @param $lines array
+ */
+ protected function added( $lines ) {
+ foreach ( $lines as $line ) {
+ echo '<tr>' . $this->emptyLine() .
+ $this->addedLine( '<ins class="diffchange">' .
+ htmlspecialchars( $line ) . '</ins>' ) . "</tr>\n";
+ }
+ }
+
+ /**
+ * @param $lines
+ */
+ protected function deleted( $lines ) {
+ foreach ( $lines as $line ) {
+ echo '<tr>' . $this->deletedLine( '<del class="diffchange">' .
+ htmlspecialchars( $line ) . '</del>' ) .
+ $this->emptyLine() . "</tr>\n";
+ }
+ }
+
+ /**
+ * @param $lines
+ */
+ protected function context( $lines ) {
+ foreach ( $lines as $line ) {
+ echo '<tr>' .
+ $this->contextLine( htmlspecialchars( $line ) ) .
+ $this->contextLine( htmlspecialchars( $line ) ) . "</tr>\n";
+ }
+ }
+
+ /**
+ * @param $orig
+ * @param $closing
+ */
+ protected function changed( $orig, $closing ) {
+ wfProfileIn( __METHOD__ );
+
+ $diff = new WordLevelDiff( $orig, $closing );
+ $del = $diff->orig();
+ $add = $diff->closing();
+
+ # Notice that WordLevelDiff returns HTML-escaped output.
+ # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
+
+ while ( $line = array_shift( $del ) ) {
+ $aline = array_shift( $add );
+ echo '<tr>' . $this->deletedLine( $line ) .
+ $this->addedLine( $aline ) . "</tr>\n";
+ }
+ foreach ( $add as $line ) { # If any leftovers
+ echo '<tr>' . $this->emptyLine() .
+ $this->addedLine( $line ) . "</tr>\n";
+ }
+ wfProfileOut( __METHOD__ );
+ }
+}
--- /dev/null
+<?php
+/**
+ * Portions taken from phpwiki-1.3.3.
+ *
+ * Copyright © 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org>
+ * You may copy this code freely under the conditions of the GPL.
+ *
+ * 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
+ */
+
+/**
+ * A formatter that outputs unified diffs
+ * @ingroup DifferenceEngine
+ */
+class UnifiedDiffFormatter extends DiffFormatter {
+ protected $leadingContextLines = 2;
+ protected $trailingContextLines = 2;
+
+ /**
+ * @param $lines
+ */
+ protected function added( $lines ) {
+ $this->lines( $lines, '+' );
+ }
+
+ /**
+ * @param $lines
+ */
+ protected function deleted( $lines ) {
+ $this->lines( $lines, '-' );
+ }
+
+ /**
+ * @param $orig
+ * @param $closing
+ */
+ protected function changed( $orig, $closing ) {
+ $this->deleted( $orig );
+ $this->added( $closing );
+ }
+
+ /**
+ * @param $xbeg
+ * @param $xlen
+ * @param $ybeg
+ * @param $ylen
+ * @return string
+ */
+ protected function blockHeader( $xbeg, $xlen, $ybeg, $ylen ) {
+ return "@@ -$xbeg,$xlen +$ybeg,$ylen @@";
+ }
+}
$relPath = substr( $path, $this->suffixStart );
if ( is_array( $stat ) ) {
$storageDir = rtrim( $this->params['dir'], '/' );
- $this->backend->loadListingStatInternal( "$storageDir/$path", $stat );
+ $this->backend->loadListingStatInternal( "$storageDir/$relPath", $stat );
}
return $relPath;
}
$this->outputHeader();
$out = $this->getOutput();
$out->allowClickjacking();
- $out->addModuleStyles( 'mediawiki.special' );
+ $out->addModuleStyles( array(
+ 'mediawiki.special', 'mediawiki.special.search', 'mediawiki.ui'
+ ) );
// Strip underscores from title parameter; most of the time we'll want
// text form here. But don't strip underscores from actual text params!
$out .= Html::input( 'search', $term, 'search', array(
'id' => $this->profile === 'advanced' ? 'powerSearchText' : 'searchText',
'size' => '50',
- 'autofocus'
+ 'autofocus',
+ 'class' => 'mw-ui-input',
) ) . "\n";
$out .= Html::hidden( 'fulltext', 'Search' ) . "\n";
- $out .= Xml::submitButton( $this->msg( 'searchbutton' )->text() ) . "\n";
+ $out .= Xml::submitButton(
+ $this->msg( 'searchbutton' )->text(),
+ array( 'class' => array( 'mw-ui-button', 'mw-ui-primary' ) )
+ ) . "\n";
return $out . $this->didYouMeanHtml;
}
/** User input variables from the root section **/
public $mIgnoreWarning;
- public $mWatchThis;
+ public $mWatchthis;
public $mCopyrightStatus;
public $mCopyrightSource;
public $uploadFormTextTop;
public $uploadFormTextAfterSummary;
- public $mWatchthis;
-
/**
* Initialize instance variables from request and create an Upload handler
*/
return true;
}
+ $desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
+ if ( $desiredTitleObj instanceof Title && $this->getUser()->isWatched( $desiredTitleObj ) ) {
+ // Already watched, don't change that
+ return true;
+ }
+
$local = wfLocalFile( $this->mDesiredDestName );
if ( $local && $local->exists() ) {
// We're uploading a new version of an existing file.
// No creation, so don't watch it if we're not already.
- return $this->getUser()->isWatched( $local->getTitle() );
+ return false;
} else {
// New page should get watched if that's our option.
return $this->getUser()->getOption( 'watchcreations' );
'id' => 'wpWatchthis',
'label-message' => 'watchthisupload',
'section' => 'options',
- 'default' => $user->getOption( 'watchcreations' ),
+ 'default' => $this->mWatch,
)
);
}
// Add feed links
$wlToken = $user->getTokenFromOption( 'watchlisttoken' );
if ( $wlToken ) {
- $this->addFeedLinks( array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
- 'wlowner' => $user->getName(), 'wltoken' => $wlToken ) );
+ $this->addFeedLinks( array(
+ 'action' => 'feedwatchlist',
+ 'allrev' => 1,
+ 'wlowner' => $user->getName(),
+ 'wltoken' => $wlToken,
+ ) );
}
$this->setHeaders();
$this->outputHeader();
- $output->addSubtitle( $this->msg( 'watchlistfor2', $user->getName()
- )->rawParams( SpecialEditWatchlist::buildTools( null ) ) );
+ $output->addSubtitle(
+ $this->msg( 'watchlistfor2', $user->getName() )
+ ->rawParams( SpecialEditWatchlist::buildTools( null ) )
+ );
$request = $this->getRequest();
$nonRevisionTypes = array( RC_LOG );
wfRunHooks( 'SpecialWatchlistGetNonRevisionTypes', array( &$nonRevisionTypes ) );
if ( $nonRevisionTypes ) {
- if ( count( $nonRevisionTypes ) === 1 ) {
- // if only one use an equality instead of IN condition
- $nonRevisionTypes = reset( $nonRevisionTypes );
- }
$conds[] = $dbr->makeList(
array(
'rc_this_oldid=page_latest',
}
$this->lb = wfGetLBFactory()->newMainLB();
- $db = $this->lb->getConnection( DB_SLAVE, 'backup' );
+ $db = $this->lb->getConnection( DB_SLAVE, 'dump' );
// Discourage the server from disconnecting us if it takes a long time
// to read out the big ol' batch query.
// 2. The Connection, through the load balancer.
try {
- $this->db = $this->lb->getConnection( DB_SLAVE, 'backup' );
+ $this->db = $this->lb->getConnection( DB_SLAVE, 'dump' );
} catch ( Exception $e ) {
throw new MWException( __METHOD__ . " rotating DB failed to obtain new database (" . $e->getMessage() . ")" );
}
.searchresult {
display: inline !ie;
}
+
+/** Add some extra padding keep browser's "clear field"
+ UI from rubbing up against the side of the field */
+input[type="search"] {
+ padding-right: 0.5em;
+}