Merge "Use empty arrays instead of empty strings for diffs"

This commit is contained in:
jenkins-bot 2018-07-27 00:55:40 +00:00 committed by Gerrit Code Review
commit 55d825c325
2 changed files with 19 additions and 2 deletions

View file

@ -154,6 +154,8 @@ class AFComputedVariable {
switch ( $this->mMethod ) {
case 'diff':
// Currently unused. Kept for backwards compatibility since it remains
// as mMethod for old variables. A fallthrough would instead change old results.
$text1Var = $parameters['oldtext-var'];
$text2Var = $parameters['newtext-var'];
$text1 = $vars->getVar( $text1Var )->toString();
@ -162,6 +164,21 @@ class AFComputedVariable {
$format = new UnifiedDiffFormatter();
$result = $format->format( $diffs );
break;
case 'diff-array':
// Introduced with T74329 to uniform the diff to MW's standard one.
// The difference with 'diff' method is noticeable when one of the
// $text is empty: it'll be treated as **really** empty, instead of
// an empty string.
$text1Var = $parameters['oldtext-var'];
$text2Var = $parameters['newtext-var'];
$text1 = $vars->getVar( $text1Var )->toString();
$text2 = $vars->getVar( $text2Var )->toString();
$text1 = $text1 === '' ? [] : explode( "\n", $text1 );
$text2 = $text2 === '' ? [] : explode( "\n", $text2 );
$diffs = new Diff( $text1, $text2 );
$format = new UnifiedDiffFormatter();
$result = $format->format( $diffs );
break;
case 'diff-split':
$diff = $vars->getVar( $parameters['diff-var'] )->toString();
$line_prefix = $parameters['line-prefix'];

View file

@ -2686,9 +2686,9 @@ class AbuseFilter {
$page = WikiPage::factory( $title );
}
$vars->setLazyLoadVar( 'edit_diff', 'diff',
$vars->setLazyLoadVar( 'edit_diff', 'diff-array',
[ 'oldtext-var' => 'old_wikitext', 'newtext-var' => 'new_wikitext' ] );
$vars->setLazyLoadVar( 'edit_diff_pst', 'diff',
$vars->setLazyLoadVar( 'edit_diff_pst', 'diff-array',
[ 'oldtext-var' => 'old_wikitext', 'newtext-var' => 'new_pst' ] );
$vars->setLazyLoadVar( 'new_size', 'length', [ 'length-var' => 'new_wikitext' ] );
$vars->setLazyLoadVar( 'old_size', 'length', [ 'length-var' => 'old_wikitext' ] );