| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Api; |
| 4 |
|
| 5 |
use MediaWiki\Api\ApiUsageException; |
| 6 |
use MediaWiki\Context\RequestContext; |
| 7 |
use MediaWiki\MainConfigNames; |
| 8 |
use MediaWiki\Revision\RevisionRecord; |
| 9 |
use MediaWiki\Tests\User\TempUser\TempUserTestTrait; |
| 10 |
use MediaWiki\Title\Title; |
| 11 |
use MediaWiki\Title\TitleValue; |
| 12 |
use RevisionDeleter; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
class ApiComparePagesTest extends ApiTestCase { |
| 21 |
|
| 22 |
use TempUserTestTrait; |
| 23 |
|
| 24 |
|
| 25 |
protected static $repl = []; |
| 26 |
|
| 27 |
protected function addPage( $page, $text, $model = CONTENT_MODEL_WIKITEXT ) { |
| 28 |
$page = $this->getServiceContainer()->getWikiPageFactory() |
| 29 |
->newFromLinkTarget( new TitleValue( NS_MAIN, 'ApiComparePagesTest ' . $page ) ); |
| 30 |
$content = $this->getServiceContainer()->getContentHandlerFactory() |
| 31 |
->getContentHandler( $model ) |
| 32 |
->unserializeContent( $text ); |
| 33 |
$performer = static::getTestSysop()->getAuthority(); |
| 34 |
$status = $this->editPage( |
| 35 |
$page, |
| 36 |
$content, |
| 37 |
'Test for ApiComparePagesTest: ' . $text, |
| 38 |
NS_MAIN, |
| 39 |
$performer |
| 40 |
); |
| 41 |
if ( !$status->isOK() ) { |
| 42 |
$this->fail( 'Failed to create ' . $page->getTitle()->getPrefixedText() . ': ' . $status->getWikiText( false, false, 'en' ) ); |
| 43 |
} |
| 44 |
return $status->getNewRevision()->getId(); |
| 45 |
} |
| 46 |
|
| 47 |
public function addDBDataOnce() { |
| 48 |
$this->disableAutoCreateTempUser(); |
| 49 |
$user = static::getTestSysop()->getUser(); |
| 50 |
self::$repl['creator'] = $user->getName(); |
| 51 |
self::$repl['creatorid'] = $user->getId(); |
| 52 |
|
| 53 |
self::$repl['revA1'] = $this->addPage( 'A', 'A 1' ); |
| 54 |
self::$repl['revA2'] = $this->addPage( 'A', 'A 2' ); |
| 55 |
self::$repl['revA3'] = $this->addPage( 'A', 'A 3' ); |
| 56 |
self::$repl['revA4'] = $this->addPage( 'A', 'A 4' ); |
| 57 |
self::$repl['pageA'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest A' )->getArticleID(); |
| 58 |
|
| 59 |
self::$repl['revB1'] = $this->addPage( 'B', 'B 1' ); |
| 60 |
self::$repl['revB2'] = $this->addPage( 'B', 'B 2' ); |
| 61 |
self::$repl['revB3'] = $this->addPage( 'B', 'B 3' ); |
| 62 |
self::$repl['revB4'] = $this->addPage( 'B', 'B 4' ); |
| 63 |
self::$repl['pageB'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest B' )->getArticleID(); |
| 64 |
$updateTimestamps = [ |
| 65 |
self::$repl['revB1'] => '20010101011101', |
| 66 |
self::$repl['revB2'] => '20020202022202', |
| 67 |
self::$repl['revB3'] => '20030303033303', |
| 68 |
self::$repl['revB4'] => '20040404044404', |
| 69 |
]; |
| 70 |
foreach ( $updateTimestamps as $id => $ts ) { |
| 71 |
$this->getDb()->newUpdateQueryBuilder() |
| 72 |
->update( 'revision' ) |
| 73 |
->set( [ 'rev_timestamp' => $this->getDb()->timestamp( $ts ) ] ) |
| 74 |
->where( [ 'rev_id' => $id ] ) |
| 75 |
->caller( __METHOD__ ) |
| 76 |
->execute(); |
| 77 |
} |
| 78 |
|
| 79 |
self::$repl['revC1'] = $this->addPage( 'C', 'C 1' ); |
| 80 |
self::$repl['revC2'] = $this->addPage( 'C', 'C 2' ); |
| 81 |
self::$repl['revC3'] = $this->addPage( 'C', 'C 3' ); |
| 82 |
self::$repl['pageC'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest C' )->getArticleID(); |
| 83 |
|
| 84 |
$id = $this->addPage( 'D', 'D 1' ); |
| 85 |
self::$repl['pageD'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest D' )->getArticleID(); |
| 86 |
$this->getDb()->newDeleteQueryBuilder() |
| 87 |
->deleteFrom( 'revision' ) |
| 88 |
->where( [ 'rev_id' => $id ] ) |
| 89 |
->caller( __METHOD__ ) |
| 90 |
->execute(); |
| 91 |
|
| 92 |
self::$repl['revE1'] = $this->addPage( 'E', 'E 1' ); |
| 93 |
self::$repl['revE2'] = $this->addPage( 'E', 'E 2' ); |
| 94 |
self::$repl['revE3'] = $this->addPage( 'E', 'E 3' ); |
| 95 |
self::$repl['revE4'] = $this->addPage( 'E', 'E 4' ); |
| 96 |
self::$repl['pageE'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest E' )->getArticleID(); |
| 97 |
$this->getDb()->newUpdateQueryBuilder() |
| 98 |
->update( 'page' ) |
| 99 |
->set( [ 'page_latest' => 0 ] ) |
| 100 |
->where( [ 'page_id' => self::$repl['pageE'] ] ) |
| 101 |
->caller( __METHOD__ ) |
| 102 |
->execute(); |
| 103 |
|
| 104 |
self::$repl['revF1'] = $this->addPage( 'F', "== Section 1 ==\nF 1.1\n\n== Section 2 ==\nF 1.2" ); |
| 105 |
self::$repl['pageF'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest F' )->getArticleID(); |
| 106 |
|
| 107 |
self::$repl['revG1'] = $this->addPage( 'G', "== Section 1 ==\nG 1.1", CONTENT_MODEL_TEXT ); |
| 108 |
self::$repl['pageG'] = Title::makeTitle( NS_MAIN, 'ApiComparePagesTest G' )->getArticleID(); |
| 109 |
|
| 110 |
$page = $this->getServiceContainer()->getWikiPageFactory() |
| 111 |
->newFromTitle( Title::makeTitle( NS_MAIN, 'ApiComparePagesTest C' ) ); |
| 112 |
$this->deletePage( $page, 'Test for ApiComparePagesTest', $user ); |
| 113 |
|
| 114 |
RevisionDeleter::createList( |
| 115 |
'revision', |
| 116 |
RequestContext::getMain(), |
| 117 |
Title::makeTitle( NS_MAIN, 'ApiComparePagesTest B' ), |
| 118 |
[ self::$repl['revB2'] ] |
| 119 |
)->setVisibility( [ |
| 120 |
'value' => [ |
| 121 |
RevisionRecord::DELETED_TEXT => 1, |
| 122 |
RevisionRecord::DELETED_USER => 1, |
| 123 |
RevisionRecord::DELETED_COMMENT => 1, |
| 124 |
], |
| 125 |
'comment' => 'Test for ApiComparePages', |
| 126 |
] ); |
| 127 |
|
| 128 |
RevisionDeleter::createList( |
| 129 |
'revision', |
| 130 |
RequestContext::getMain(), |
| 131 |
Title::makeTitle( NS_MAIN, 'ApiComparePagesTest B' ), |
| 132 |
[ self::$repl['revB3'] ] |
| 133 |
)->setVisibility( [ |
| 134 |
'value' => [ |
| 135 |
RevisionRecord::DELETED_USER => 1, |
| 136 |
RevisionRecord::DELETED_COMMENT => 1, |
| 137 |
RevisionRecord::DELETED_RESTRICTED => 1, |
| 138 |
], |
| 139 |
'comment' => 'Test for ApiComparePages', |
| 140 |
] ); |
| 141 |
} |
| 142 |
|
| 143 |
protected function doReplacements( &$value ) { |
| 144 |
if ( is_string( $value ) ) { |
| 145 |
if ( preg_match( '/^{{REPL:(.+?)}}$/', $value, $m ) ) { |
| 146 |
$value = self::$repl[$m[1]]; |
| 147 |
} else { |
| 148 |
$value = preg_replace_callback( '/{{REPL:(.+?)}}/', static function ( $m ) { |
| 149 |
return self::$repl[$m[1]] ?? $m[0]; |
| 150 |
}, $value ); |
| 151 |
} |
| 152 |
} elseif ( is_array( $value ) || is_object( $value ) ) { |
| 153 |
foreach ( $value as &$v ) { |
| 154 |
$this->doReplacements( $v ); |
| 155 |
} |
| 156 |
unset( $v ); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public function testDiff( $params, $expect, $exceptionCode = false, $sysop = false ) { |
| 164 |
$this->overrideConfigValue( MainConfigNames::DiffEngine, 'php' ); |
| 165 |
|
| 166 |
$this->doReplacements( $params ); |
| 167 |
|
| 168 |
$params += [ |
| 169 |
'action' => 'compare', |
| 170 |
'errorformat' => 'none', |
| 171 |
]; |
| 172 |
|
| 173 |
$performer = $sysop |
| 174 |
? static::getTestSysop()->getAuthority() |
| 175 |
: static::getTestUser()->getAuthority(); |
| 176 |
if ( $exceptionCode ) { |
| 177 |
try { |
| 178 |
$this->doApiRequest( $params, null, false, $performer ); |
| 179 |
$this->fail( 'Expected exception not thrown' ); |
| 180 |
} catch ( ApiUsageException $ex ) { |
| 181 |
$this->assertApiErrorCode( $exceptionCode, $ex, |
| 182 |
"Exception with code $exceptionCode" ); |
| 183 |
} |
| 184 |
} else { |
| 185 |
$apiResult = $this->doApiRequest( $params, null, false, $performer ); |
| 186 |
$apiResult = $apiResult[0]; |
| 187 |
$this->doReplacements( $expect ); |
| 188 |
$this->assertEquals( $expect, $apiResult ); |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
private static function makeDeprecationWarnings( ...$params ) { |
| 193 |
$warn = []; |
| 194 |
foreach ( $params as $p ) { |
| 195 |
$warn[] = [ |
| 196 |
'code' => 'deprecation', |
| 197 |
'data' => [ 'feature' => "action=compare&{$p}" ], |
| 198 |
'module' => 'compare', |
| 199 |
]; |
| 200 |
if ( count( $warn ) === 1 ) { |
| 201 |
$warn[] = [ |
| 202 |
'code' => 'deprecation-help', |
| 203 |
'module' => 'main', |
| 204 |
]; |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
return $warn; |
| 209 |
} |
| 210 |
|
| 211 |
public static function provideDiff() { |
| 212 |
return [ |
| 213 |
'Basic diff, titles' => [ |
| 214 |
[ |
| 215 |
'fromtitle' => 'ApiComparePagesTest A', |
| 216 |
'totitle' => 'ApiComparePagesTest B', |
| 217 |
], |
| 218 |
[ |
| 219 |
'compare' => [ |
| 220 |
'fromid' => '{{REPL:pageA}}', |
| 221 |
'fromrevid' => '{{REPL:revA4}}', |
| 222 |
'fromns' => 0, |
| 223 |
'fromtitle' => 'ApiComparePagesTest A', |
| 224 |
'toid' => '{{REPL:pageB}}', |
| 225 |
'torevid' => '{{REPL:revB4}}', |
| 226 |
'tons' => 0, |
| 227 |
'totitle' => 'ApiComparePagesTest B', |
| 228 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 229 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 230 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">A </del>4</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">B </ins>4</div></td></tr>' . "\n", |
| 231 |
] |
| 232 |
], |
| 233 |
], |
| 234 |
'Basic diff, page IDs' => [ |
| 235 |
[ |
| 236 |
'fromid' => '{{REPL:pageA}}', |
| 237 |
'toid' => '{{REPL:pageB}}', |
| 238 |
], |
| 239 |
[ |
| 240 |
'compare' => [ |
| 241 |
'fromid' => '{{REPL:pageA}}', |
| 242 |
'fromrevid' => '{{REPL:revA4}}', |
| 243 |
'fromns' => 0, |
| 244 |
'fromtitle' => 'ApiComparePagesTest A', |
| 245 |
'toid' => '{{REPL:pageB}}', |
| 246 |
'torevid' => '{{REPL:revB4}}', |
| 247 |
'tons' => 0, |
| 248 |
'totitle' => 'ApiComparePagesTest B', |
| 249 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 250 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 251 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">A </del>4</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">B </ins>4</div></td></tr>' . "\n", |
| 252 |
] |
| 253 |
], |
| 254 |
], |
| 255 |
'Basic diff, revision IDs' => [ |
| 256 |
[ |
| 257 |
'fromrev' => '{{REPL:revA2}}', |
| 258 |
'torev' => '{{REPL:revA3}}', |
| 259 |
], |
| 260 |
[ |
| 261 |
'compare' => [ |
| 262 |
'fromid' => '{{REPL:pageA}}', |
| 263 |
'fromrevid' => '{{REPL:revA2}}', |
| 264 |
'fromns' => 0, |
| 265 |
'fromtitle' => 'ApiComparePagesTest A', |
| 266 |
'toid' => '{{REPL:pageA}}', |
| 267 |
'torevid' => '{{REPL:revA3}}', |
| 268 |
'tons' => 0, |
| 269 |
'totitle' => 'ApiComparePagesTest A', |
| 270 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 271 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 272 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div>A <del class="diffchange diffchange-inline">2</del></div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div>A <ins class="diffchange diffchange-inline">3</ins></div></td></tr>' . "\n", |
| 273 |
] |
| 274 |
], |
| 275 |
], |
| 276 |
'Basic diff, deleted revision ID as sysop' => [ |
| 277 |
[ |
| 278 |
'fromrev' => '{{REPL:revA2}}', |
| 279 |
'torev' => '{{REPL:revC2}}', |
| 280 |
], |
| 281 |
[ |
| 282 |
'compare' => [ |
| 283 |
'fromid' => '{{REPL:pageA}}', |
| 284 |
'fromrevid' => '{{REPL:revA2}}', |
| 285 |
'fromns' => 0, |
| 286 |
'fromtitle' => 'ApiComparePagesTest A', |
| 287 |
'toid' => 0, |
| 288 |
'torevid' => '{{REPL:revC2}}', |
| 289 |
'tons' => 0, |
| 290 |
'totitle' => 'ApiComparePagesTest C', |
| 291 |
'toarchive' => true, |
| 292 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 293 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 294 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">A </del>2</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">C </ins>2</div></td></tr>' . "\n", |
| 295 |
] |
| 296 |
], |
| 297 |
false, true |
| 298 |
], |
| 299 |
'Basic diff, revdel as sysop' => [ |
| 300 |
[ |
| 301 |
'fromrev' => '{{REPL:revA2}}', |
| 302 |
'torev' => '{{REPL:revB2}}', |
| 303 |
], |
| 304 |
[ |
| 305 |
'compare' => [ |
| 306 |
'fromid' => '{{REPL:pageA}}', |
| 307 |
'fromrevid' => '{{REPL:revA2}}', |
| 308 |
'fromns' => 0, |
| 309 |
'fromtitle' => 'ApiComparePagesTest A', |
| 310 |
'toid' => '{{REPL:pageB}}', |
| 311 |
'torevid' => '{{REPL:revB2}}', |
| 312 |
'tons' => 0, |
| 313 |
'totitle' => 'ApiComparePagesTest B', |
| 314 |
'totexthidden' => true, |
| 315 |
'touserhidden' => true, |
| 316 |
'tocommenthidden' => true, |
| 317 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 318 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 319 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">A </del>2</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">B </ins>2</div></td></tr>' . "\n", |
| 320 |
] |
| 321 |
], |
| 322 |
false, true |
| 323 |
], |
| 324 |
'Basic diff, text' => [ |
| 325 |
[ |
| 326 |
'fromslots' => 'main', |
| 327 |
'fromtext-main' => 'From text', |
| 328 |
'fromcontentmodel-main' => 'wikitext', |
| 329 |
'toslots' => 'main', |
| 330 |
'totext-main' => 'To text {{subst:PAGENAME}}', |
| 331 |
'tocontentmodel-main' => 'wikitext', |
| 332 |
], |
| 333 |
[ |
| 334 |
'compare' => [ |
| 335 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 336 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 337 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">{{subst:PAGENAME}}</ins></div></td></tr>' . "\n", |
| 338 |
] |
| 339 |
], |
| 340 |
], |
| 341 |
'Basic diff, text 2' => [ |
| 342 |
[ |
| 343 |
'fromslots' => 'main', |
| 344 |
'fromtext-main' => 'From text', |
| 345 |
'toslots' => 'main', |
| 346 |
'totext-main' => 'To text {{subst:PAGENAME}}', |
| 347 |
'tocontentmodel-main' => 'wikitext', |
| 348 |
], |
| 349 |
[ |
| 350 |
'compare' => [ |
| 351 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 352 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 353 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">{{subst:PAGENAME}}</ins></div></td></tr>' . "\n", |
| 354 |
] |
| 355 |
], |
| 356 |
], |
| 357 |
'Basic diff, guessed model' => [ |
| 358 |
[ |
| 359 |
'fromslots' => 'main', |
| 360 |
'fromtext-main' => 'From text', |
| 361 |
'toslots' => 'main', |
| 362 |
'totext-main' => 'To text', |
| 363 |
], |
| 364 |
[ |
| 365 |
'warnings' => [ [ 'code' => 'compare-nocontentmodel', 'module' => 'compare' ] ], |
| 366 |
'compare' => [ |
| 367 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 368 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 369 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text</div></td></tr>' . "\n", |
| 370 |
] |
| 371 |
], |
| 372 |
], |
| 373 |
'Basic diff, text with title and PST' => [ |
| 374 |
[ |
| 375 |
'fromslots' => 'main', |
| 376 |
'fromtext-main' => 'From text', |
| 377 |
'totitle' => 'Test', |
| 378 |
'toslots' => 'main', |
| 379 |
'totext-main' => 'To text {{subst:PAGENAME}}', |
| 380 |
'topst' => true, |
| 381 |
], |
| 382 |
[ |
| 383 |
'compare' => [ |
| 384 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 385 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 386 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">Test</ins></div></td></tr>' . "\n", |
| 387 |
] |
| 388 |
], |
| 389 |
], |
| 390 |
'Basic diff, text with page ID and PST' => [ |
| 391 |
[ |
| 392 |
'fromslots' => 'main', |
| 393 |
'fromtext-main' => 'From text', |
| 394 |
'toid' => '{{REPL:pageB}}', |
| 395 |
'toslots' => 'main', |
| 396 |
'totext-main' => 'To text {{subst:PAGENAME}}', |
| 397 |
'topst' => true, |
| 398 |
], |
| 399 |
[ |
| 400 |
'compare' => [ |
| 401 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 402 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 403 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest B</ins></div></td></tr>' . "\n", |
| 404 |
] |
| 405 |
], |
| 406 |
], |
| 407 |
'Basic diff, text with revision and PST' => [ |
| 408 |
[ |
| 409 |
'fromslots' => 'main', |
| 410 |
'fromtext-main' => 'From text', |
| 411 |
'torev' => '{{REPL:revB2}}', |
| 412 |
'toslots' => 'main', |
| 413 |
'totext-main' => 'To text {{subst:PAGENAME}}', |
| 414 |
'topst' => true, |
| 415 |
], |
| 416 |
[ |
| 417 |
'compare' => [ |
| 418 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 419 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 420 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest B</ins></div></td></tr>' . "\n", |
| 421 |
] |
| 422 |
], |
| 423 |
], |
| 424 |
'Basic diff, text with deleted revision and PST' => [ |
| 425 |
[ |
| 426 |
'fromslots' => 'main', |
| 427 |
'fromtext-main' => 'From text', |
| 428 |
'torev' => '{{REPL:revC2}}', |
| 429 |
'toslots' => 'main', |
| 430 |
'totext-main' => 'To text {{subst:PAGENAME}}', |
| 431 |
'topst' => true, |
| 432 |
], |
| 433 |
[ |
| 434 |
'compare' => [ |
| 435 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 436 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 437 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest C</ins></div></td></tr>' . "\n", |
| 438 |
] |
| 439 |
], |
| 440 |
false, true |
| 441 |
], |
| 442 |
'Basic diff, test with sections' => [ |
| 443 |
[ |
| 444 |
'fromtitle' => 'ApiComparePagesTest F', |
| 445 |
'fromslots' => 'main', |
| 446 |
'fromtext-main' => "== Section 2 ==\nFrom text?", |
| 447 |
'fromsection-main' => 2, |
| 448 |
'totitle' => 'ApiComparePagesTest F', |
| 449 |
'toslots' => 'main', |
| 450 |
'totext-main' => "== Section 1 ==\nTo text?", |
| 451 |
'tosection-main' => 1, |
| 452 |
], |
| 453 |
[ |
| 454 |
'compare' => [ |
| 455 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 456 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 457 |
. '<tr><td class="diff-marker"></td><td class="diff-context diff-side-deleted"><div>== Section 1 ==</div></td><td class="diff-marker"></td><td class="diff-context diff-side-added"><div>== Section 1 ==</div></td></tr>' . "\n" |
| 458 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">F 1.1</del></div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To text?</ins></div></td></tr>' . "\n" |
| 459 |
. '<tr><td class="diff-marker"></td><td class="diff-context diff-side-deleted"><br></td><td class="diff-marker"></td><td class="diff-context diff-side-added"><br></td></tr>' . "\n" |
| 460 |
. '<tr><td class="diff-marker"></td><td class="diff-context diff-side-deleted"><div>== Section 2 ==</div></td><td class="diff-marker"></td><td class="diff-context diff-side-added"><div>== Section 2 ==</div></td></tr>' . "\n" |
| 461 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From text?</del></div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">F 1.2</ins></div></td></tr>' . "\n", |
| 462 |
] |
| 463 |
], |
| 464 |
], |
| 465 |
'Diff with all props' => [ |
| 466 |
[ |
| 467 |
'fromrev' => '{{REPL:revB1}}', |
| 468 |
'torev' => '{{REPL:revB3}}', |
| 469 |
'totitle' => 'ApiComparePagesTest B', |
| 470 |
'prop' => 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size|timestamp' |
| 471 |
], |
| 472 |
[ |
| 473 |
'compare' => [ |
| 474 |
'fromid' => '{{REPL:pageB}}', |
| 475 |
'fromrevid' => '{{REPL:revB1}}', |
| 476 |
'fromns' => 0, |
| 477 |
'fromtitle' => 'ApiComparePagesTest B', |
| 478 |
'fromsize' => 3, |
| 479 |
'fromuser' => '{{REPL:creator}}', |
| 480 |
'fromuserid' => '{{REPL:creatorid}}', |
| 481 |
'fromcomment' => 'Test for ApiComparePagesTest: B 1', |
| 482 |
'fromparsedcomment' => 'Test for ApiComparePagesTest: B 1', |
| 483 |
'fromtimestamp' => '2001-01-01T01:11:01Z', |
| 484 |
'toid' => '{{REPL:pageB}}', |
| 485 |
'torevid' => '{{REPL:revB3}}', |
| 486 |
'tons' => 0, |
| 487 |
'totitle' => 'ApiComparePagesTest B', |
| 488 |
'tosize' => 3, |
| 489 |
'touserhidden' => true, |
| 490 |
'tocommenthidden' => true, |
| 491 |
'tosuppressed' => true, |
| 492 |
'totimestamp' => '2003-03-03T03:33:03Z', |
| 493 |
'next' => '{{REPL:revB4}}', |
| 494 |
'diffsize' => 454, |
| 495 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 496 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 497 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div>B <del class="diffchange diffchange-inline">1</del></div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div>B <ins class="diffchange diffchange-inline">3</ins></div></td></tr>' . "\n", |
| 498 |
] |
| 499 |
], |
| 500 |
], |
| 501 |
'Diff with all props as sysop' => [ |
| 502 |
[ |
| 503 |
'fromrev' => '{{REPL:revB2}}', |
| 504 |
'torev' => '{{REPL:revB3}}', |
| 505 |
'totitle' => 'ApiComparePagesTest B', |
| 506 |
'prop' => 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size|timestamp' |
| 507 |
], |
| 508 |
[ |
| 509 |
'compare' => [ |
| 510 |
'fromid' => '{{REPL:pageB}}', |
| 511 |
'fromrevid' => '{{REPL:revB2}}', |
| 512 |
'fromns' => 0, |
| 513 |
'fromtitle' => 'ApiComparePagesTest B', |
| 514 |
'fromsize' => 3, |
| 515 |
'fromtexthidden' => true, |
| 516 |
'fromuserhidden' => true, |
| 517 |
'fromuser' => '{{REPL:creator}}', |
| 518 |
'fromuserid' => '{{REPL:creatorid}}', |
| 519 |
'fromcommenthidden' => true, |
| 520 |
'fromcomment' => 'Test for ApiComparePagesTest: B 2', |
| 521 |
'fromparsedcomment' => 'Test for ApiComparePagesTest: B 2', |
| 522 |
'fromtimestamp' => '2002-02-02T02:22:02Z', |
| 523 |
'toid' => '{{REPL:pageB}}', |
| 524 |
'torevid' => '{{REPL:revB3}}', |
| 525 |
'tons' => 0, |
| 526 |
'totitle' => 'ApiComparePagesTest B', |
| 527 |
'tosize' => 3, |
| 528 |
'touserhidden' => true, |
| 529 |
'tocommenthidden' => true, |
| 530 |
'tosuppressed' => true, |
| 531 |
'totimestamp' => '2003-03-03T03:33:03Z', |
| 532 |
'prev' => '{{REPL:revB1}}', |
| 533 |
'next' => '{{REPL:revB4}}', |
| 534 |
'diffsize' => 454, |
| 535 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 536 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 537 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div>B <del class="diffchange diffchange-inline">2</del></div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div>B <ins class="diffchange diffchange-inline">3</ins></div></td></tr>' . "\n", |
| 538 |
] |
| 539 |
], |
| 540 |
false, true |
| 541 |
], |
| 542 |
'Text diff with all props' => [ |
| 543 |
[ |
| 544 |
'fromrev' => '{{REPL:revB1}}', |
| 545 |
'toslots' => 'main', |
| 546 |
'totext-main' => 'To text {{subst:PAGENAME}}', |
| 547 |
'tocontentmodel-main' => 'wikitext', |
| 548 |
'prop' => 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size|timestamp' |
| 549 |
], |
| 550 |
[ |
| 551 |
'compare' => [ |
| 552 |
'fromid' => '{{REPL:pageB}}', |
| 553 |
'fromrevid' => '{{REPL:revB1}}', |
| 554 |
'fromns' => 0, |
| 555 |
'fromtitle' => 'ApiComparePagesTest B', |
| 556 |
'fromsize' => 3, |
| 557 |
'fromuser' => '{{REPL:creator}}', |
| 558 |
'fromuserid' => '{{REPL:creatorid}}', |
| 559 |
'fromcomment' => 'Test for ApiComparePagesTest: B 1', |
| 560 |
'fromparsedcomment' => 'Test for ApiComparePagesTest: B 1', |
| 561 |
'fromtimestamp' => '2001-01-01T01:11:01Z', |
| 562 |
'diffsize' => 477, |
| 563 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 564 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 565 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">B 1</del></div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To text {{subst:PAGENAME}}</ins></div></td></tr>' . "\n", |
| 566 |
] |
| 567 |
], |
| 568 |
], |
| 569 |
'Relative diff, cur' => [ |
| 570 |
[ |
| 571 |
'fromrev' => '{{REPL:revA2}}', |
| 572 |
'torelative' => 'cur', |
| 573 |
'prop' => 'ids', |
| 574 |
], |
| 575 |
[ |
| 576 |
'compare' => [ |
| 577 |
'fromid' => '{{REPL:pageA}}', |
| 578 |
'fromrevid' => '{{REPL:revA2}}', |
| 579 |
'toid' => '{{REPL:pageA}}', |
| 580 |
'torevid' => '{{REPL:revA4}}', |
| 581 |
] |
| 582 |
], |
| 583 |
], |
| 584 |
'Relative diff, next' => [ |
| 585 |
[ |
| 586 |
'fromrev' => '{{REPL:revE2}}', |
| 587 |
'torelative' => 'next', |
| 588 |
'prop' => 'ids|rel', |
| 589 |
], |
| 590 |
[ |
| 591 |
'compare' => [ |
| 592 |
'fromid' => '{{REPL:pageE}}', |
| 593 |
'fromrevid' => '{{REPL:revE2}}', |
| 594 |
'toid' => '{{REPL:pageE}}', |
| 595 |
'torevid' => '{{REPL:revE3}}', |
| 596 |
'prev' => '{{REPL:revE1}}', |
| 597 |
'next' => '{{REPL:revE4}}', |
| 598 |
] |
| 599 |
], |
| 600 |
], |
| 601 |
'Relative diff, prev' => [ |
| 602 |
[ |
| 603 |
'fromrev' => '{{REPL:revE3}}', |
| 604 |
'torelative' => 'prev', |
| 605 |
'prop' => 'ids|rel', |
| 606 |
], |
| 607 |
[ |
| 608 |
'compare' => [ |
| 609 |
'fromid' => '{{REPL:pageE}}', |
| 610 |
'fromrevid' => '{{REPL:revE2}}', |
| 611 |
'toid' => '{{REPL:pageE}}', |
| 612 |
'torevid' => '{{REPL:revE3}}', |
| 613 |
'prev' => '{{REPL:revE1}}', |
| 614 |
'next' => '{{REPL:revE4}}', |
| 615 |
] |
| 616 |
], |
| 617 |
], |
| 618 |
'Relative diff, no prev' => [ |
| 619 |
[ |
| 620 |
'fromrev' => '{{REPL:revA1}}', |
| 621 |
'torelative' => 'prev', |
| 622 |
'prop' => 'ids|rel|diff|title|user|comment', |
| 623 |
], |
| 624 |
[ |
| 625 |
'warnings' => [ |
| 626 |
[ |
| 627 |
'code' => 'compare-no-prev', |
| 628 |
'module' => 'compare', |
| 629 |
], |
| 630 |
], |
| 631 |
'compare' => [ |
| 632 |
'toid' => '{{REPL:pageA}}', |
| 633 |
'torevid' => '{{REPL:revA1}}', |
| 634 |
'tons' => 0, |
| 635 |
'totitle' => 'ApiComparePagesTest A', |
| 636 |
'touser' => '{{REPL:creator}}', |
| 637 |
'touserid' => '{{REPL:creatorid}}', |
| 638 |
'tocomment' => 'Test for ApiComparePagesTest: A 1', |
| 639 |
'toparsedcomment' => 'Test for ApiComparePagesTest: A 1', |
| 640 |
'next' => '{{REPL:revA2}}', |
| 641 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 642 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 643 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div> </div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">A 1</ins></div></td></tr>' . "\n", |
| 644 |
], |
| 645 |
], |
| 646 |
], |
| 647 |
'Relative diff, no next' => [ |
| 648 |
[ |
| 649 |
'fromrev' => '{{REPL:revA4}}', |
| 650 |
'torelative' => 'next', |
| 651 |
'prop' => 'ids|rel|diff|title|user|comment', |
| 652 |
], |
| 653 |
[ |
| 654 |
'warnings' => [ |
| 655 |
[ |
| 656 |
'code' => 'compare-no-next', |
| 657 |
'module' => 'compare', |
| 658 |
], |
| 659 |
], |
| 660 |
'compare' => [ |
| 661 |
'fromid' => '{{REPL:pageA}}', |
| 662 |
'fromrevid' => '{{REPL:revA4}}', |
| 663 |
'fromns' => 0, |
| 664 |
'fromtitle' => 'ApiComparePagesTest A', |
| 665 |
'fromuser' => '{{REPL:creator}}', |
| 666 |
'fromuserid' => '{{REPL:creatorid}}', |
| 667 |
'fromcomment' => 'Test for ApiComparePagesTest: A 4', |
| 668 |
'fromparsedcomment' => 'Test for ApiComparePagesTest: A 4', |
| 669 |
'prev' => '{{REPL:revA3}}', |
| 670 |
'body' => '', |
| 671 |
], |
| 672 |
], |
| 673 |
], |
| 674 |
'Diff for specific slots' => [ |
| 675 |
|
| 676 |
[ |
| 677 |
'fromrev' => '{{REPL:revA1}}', |
| 678 |
'torev' => '{{REPL:revA3}}', |
| 679 |
'prop' => 'diff', |
| 680 |
'slots' => 'main', |
| 681 |
], |
| 682 |
[ |
| 683 |
'compare' => [ |
| 684 |
'bodies' => [ |
| 685 |
'main' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 686 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 687 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div>A <del class="diffchange diffchange-inline">1</del></div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div>A <ins class="diffchange diffchange-inline">3</ins></div></td></tr>' . "\n", |
| 688 |
], |
| 689 |
], |
| 690 |
], |
| 691 |
], |
| 692 |
|
| 693 |
|
| 694 |
'Basic diff, deprecated text' => [ |
| 695 |
[ |
| 696 |
'fromtext' => 'From text', |
| 697 |
'fromcontentmodel' => 'wikitext', |
| 698 |
'totext' => 'To text {{subst:PAGENAME}}', |
| 699 |
'tocontentmodel' => 'wikitext', |
| 700 |
], |
| 701 |
[ |
| 702 |
'warnings' => self::makeDeprecationWarnings( 'fromtext', 'fromcontentmodel', 'totext', 'tocontentmodel' ), |
| 703 |
'compare' => [ |
| 704 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 705 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 706 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">{{subst:PAGENAME}}</ins></div></td></tr>' . "\n", |
| 707 |
] |
| 708 |
], |
| 709 |
], |
| 710 |
'Basic diff, deprecated text 2' => [ |
| 711 |
[ |
| 712 |
'fromtext' => 'From text', |
| 713 |
'totext' => 'To text {{subst:PAGENAME}}', |
| 714 |
'tocontentmodel' => 'wikitext', |
| 715 |
], |
| 716 |
[ |
| 717 |
'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext', 'tocontentmodel' ), |
| 718 |
'compare' => [ |
| 719 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 720 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 721 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">{{subst:PAGENAME}}</ins></div></td></tr>' . "\n", |
| 722 |
] |
| 723 |
], |
| 724 |
], |
| 725 |
'Basic diff, deprecated text, guessed model' => [ |
| 726 |
[ |
| 727 |
'fromtext' => 'From text', |
| 728 |
'totext' => 'To text', |
| 729 |
], |
| 730 |
[ |
| 731 |
'warnings' => array_merge( self::makeDeprecationWarnings( 'fromtext', 'totext' ), [ |
| 732 |
[ 'code' => 'compare-nocontentmodel', 'module' => 'compare' ], |
| 733 |
] ), |
| 734 |
'compare' => [ |
| 735 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 736 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 737 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text</div></td></tr>' . "\n", |
| 738 |
] |
| 739 |
], |
| 740 |
], |
| 741 |
'Basic diff, deprecated text with title and PST' => [ |
| 742 |
[ |
| 743 |
'fromtext' => 'From text', |
| 744 |
'totitle' => 'Test', |
| 745 |
'totext' => 'To text {{subst:PAGENAME}}', |
| 746 |
'topst' => true, |
| 747 |
], |
| 748 |
[ |
| 749 |
'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext' ), |
| 750 |
'compare' => [ |
| 751 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 752 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 753 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">Test</ins></div></td></tr>' . "\n", |
| 754 |
] |
| 755 |
], |
| 756 |
], |
| 757 |
'Basic diff, deprecated text with page ID and PST' => [ |
| 758 |
[ |
| 759 |
'fromtext' => 'From text', |
| 760 |
'toid' => '{{REPL:pageB}}', |
| 761 |
'totext' => 'To text {{subst:PAGENAME}}', |
| 762 |
'topst' => true, |
| 763 |
], |
| 764 |
[ |
| 765 |
'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext' ), |
| 766 |
'compare' => [ |
| 767 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 768 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 769 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest B</ins></div></td></tr>' . "\n", |
| 770 |
] |
| 771 |
], |
| 772 |
], |
| 773 |
'Basic diff, deprecated text with revision and PST' => [ |
| 774 |
[ |
| 775 |
'fromtext' => 'From text', |
| 776 |
'torev' => '{{REPL:revB2}}', |
| 777 |
'totext' => 'To text {{subst:PAGENAME}}', |
| 778 |
'topst' => true, |
| 779 |
], |
| 780 |
[ |
| 781 |
'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext' ), |
| 782 |
'compare' => [ |
| 783 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 784 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 785 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest B</ins></div></td></tr>' . "\n", |
| 786 |
] |
| 787 |
], |
| 788 |
], |
| 789 |
'Basic diff, deprecated text with deleted revision and PST' => [ |
| 790 |
[ |
| 791 |
'fromtext' => 'From text', |
| 792 |
'torev' => '{{REPL:revC2}}', |
| 793 |
'totext' => 'To text {{subst:PAGENAME}}', |
| 794 |
'topst' => true, |
| 795 |
], |
| 796 |
[ |
| 797 |
'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext' ), |
| 798 |
'compare' => [ |
| 799 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 800 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 801 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest C</ins></div></td></tr>' . "\n", |
| 802 |
] |
| 803 |
], |
| 804 |
false, true |
| 805 |
], |
| 806 |
'Basic diff, test with deprecated sections' => [ |
| 807 |
[ |
| 808 |
'fromtitle' => 'ApiComparePagesTest F', |
| 809 |
'fromsection' => 1, |
| 810 |
'totext' => "== Section 1 ==\nTo text\n\n== Section 2 ==\nTo text?", |
| 811 |
'tosection' => 2, |
| 812 |
], |
| 813 |
[ |
| 814 |
'warnings' => self::makeDeprecationWarnings( 'fromsection', 'totext', 'tosection' ), |
| 815 |
'compare' => [ |
| 816 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 817 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 818 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div>== Section <del class="diffchange diffchange-inline">1 </del>==</div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div>== Section <ins class="diffchange diffchange-inline">2 </ins>==</div></td></tr>' . "\n" |
| 819 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div><del class="diffchange diffchange-inline">F 1.1</del></div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div><ins class="diffchange diffchange-inline">To text?</ins></div></td></tr>' . "\n", |
| 820 |
'fromid' => '{{REPL:pageF}}', |
| 821 |
'fromrevid' => '{{REPL:revF1}}', |
| 822 |
'fromns' => '0', |
| 823 |
'fromtitle' => 'ApiComparePagesTest F', |
| 824 |
] |
| 825 |
], |
| 826 |
], |
| 827 |
'Basic diff, test with deprecated sections and revdel, non-sysop' => [ |
| 828 |
[ |
| 829 |
'fromrev' => '{{REPL:revB2}}', |
| 830 |
'fromsection' => 0, |
| 831 |
'torev' => '{{REPL:revB4}}', |
| 832 |
'tosection' => 0, |
| 833 |
], |
| 834 |
[], |
| 835 |
'missingcontent' |
| 836 |
], |
| 837 |
'Basic diff, test with deprecated sections and revdel, sysop' => [ |
| 838 |
[ |
| 839 |
'fromrev' => '{{REPL:revB2}}', |
| 840 |
'fromsection' => 0, |
| 841 |
'torev' => '{{REPL:revB4}}', |
| 842 |
'tosection' => 0, |
| 843 |
], |
| 844 |
[ |
| 845 |
'warnings' => self::makeDeprecationWarnings( 'fromsection', 'tosection' ), |
| 846 |
'compare' => [ |
| 847 |
'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>' . "\n" |
| 848 |
. '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n" |
| 849 |
. '<tr><td class="diff-marker" data-marker="−"></td><td class="diff-deletedline diff-side-deleted"><div>B <del class="diffchange diffchange-inline">2</del></div></td><td class="diff-marker" data-marker="+"></td><td class="diff-addedline diff-side-added"><div>B <ins class="diffchange diffchange-inline">4</ins></div></td></tr>' . "\n", |
| 850 |
'fromid' => '{{REPL:pageB}}', |
| 851 |
'fromrevid' => '{{REPL:revB2}}', |
| 852 |
'fromns' => 0, |
| 853 |
'fromtitle' => 'ApiComparePagesTest B', |
| 854 |
'fromtexthidden' => true, |
| 855 |
'fromuserhidden' => true, |
| 856 |
'fromcommenthidden' => true, |
| 857 |
'toid' => '{{REPL:pageB}}', |
| 858 |
'torevid' => '{{REPL:revB4}}', |
| 859 |
'tons' => 0, |
| 860 |
'totitle' => 'ApiComparePagesTest B', |
| 861 |
] |
| 862 |
], |
| 863 |
false, true, |
| 864 |
], |
| 865 |
|
| 866 |
'Error, missing title' => [ |
| 867 |
[ |
| 868 |
'fromtitle' => 'ApiComparePagesTest X', |
| 869 |
'totitle' => 'ApiComparePagesTest B', |
| 870 |
], |
| 871 |
[], |
| 872 |
'missingtitle', |
| 873 |
], |
| 874 |
'Error, invalid title' => [ |
| 875 |
[ |
| 876 |
'fromtitle' => '<bad>', |
| 877 |
'totitle' => 'ApiComparePagesTest B', |
| 878 |
], |
| 879 |
[], |
| 880 |
'invalidtitle', |
| 881 |
], |
| 882 |
'Error, missing page ID' => [ |
| 883 |
[ |
| 884 |
'fromid' => 8817900, |
| 885 |
'totitle' => 'ApiComparePagesTest B', |
| 886 |
], |
| 887 |
[], |
| 888 |
'nosuchpageid', |
| 889 |
], |
| 890 |
'Error, page with missing revision' => [ |
| 891 |
[ |
| 892 |
'fromtitle' => 'ApiComparePagesTest D', |
| 893 |
'totitle' => 'ApiComparePagesTest B', |
| 894 |
], |
| 895 |
[], |
| 896 |
'nosuchrevid', |
| 897 |
], |
| 898 |
'Error, page with no revision' => [ |
| 899 |
[ |
| 900 |
'fromtitle' => 'ApiComparePagesTest E', |
| 901 |
'totitle' => 'ApiComparePagesTest B', |
| 902 |
], |
| 903 |
[], |
| 904 |
'nosuchrevid', |
| 905 |
], |
| 906 |
'Error, bad rev ID' => [ |
| 907 |
[ |
| 908 |
'fromrev' => 8817900, |
| 909 |
'totitle' => 'ApiComparePagesTest B', |
| 910 |
], |
| 911 |
[], |
| 912 |
'nosuchrevid', |
| 913 |
], |
| 914 |
'Error, deleted revision ID, non-sysop' => [ |
| 915 |
[ |
| 916 |
'fromrev' => '{{REPL:revA2}}', |
| 917 |
'torev' => '{{REPL:revC2}}', |
| 918 |
], |
| 919 |
[], |
| 920 |
'nosuchrevid', |
| 921 |
], |
| 922 |
'Error, deleted revision ID and torelative=prev' => [ |
| 923 |
[ |
| 924 |
'fromrev' => '{{REPL:revC2}}', |
| 925 |
'torelative' => 'prev', |
| 926 |
], |
| 927 |
[], |
| 928 |
'compare-relative-to-deleted', true |
| 929 |
], |
| 930 |
'Error, deleted revision ID and torelative=next' => [ |
| 931 |
[ |
| 932 |
'fromrev' => '{{REPL:revC2}}', |
| 933 |
'torelative' => 'next', |
| 934 |
], |
| 935 |
[], |
| 936 |
'compare-relative-to-deleted', true |
| 937 |
], |
| 938 |
'Deleted revision ID and torelative=cur' => [ |
| 939 |
[ |
| 940 |
'fromrev' => '{{REPL:revC2}}', |
| 941 |
'torelative' => 'cur', |
| 942 |
], |
| 943 |
[], |
| 944 |
'nosuchrevid', true |
| 945 |
], |
| 946 |
'Error, revision-deleted content' => [ |
| 947 |
[ |
| 948 |
'fromrev' => '{{REPL:revA2}}', |
| 949 |
'torev' => '{{REPL:revB2}}', |
| 950 |
], |
| 951 |
[], |
| 952 |
'missingcontent', |
| 953 |
], |
| 954 |
'Error, text with no title and PST' => [ |
| 955 |
[ |
| 956 |
'fromtext' => 'From text', |
| 957 |
'totext' => 'To text {{subst:PAGENAME}}', |
| 958 |
'topst' => true, |
| 959 |
], |
| 960 |
[], |
| 961 |
'compare-no-title', |
| 962 |
], |
| 963 |
'Error, test with invalid from section ID' => [ |
| 964 |
[ |
| 965 |
'fromtitle' => 'ApiComparePagesTest F', |
| 966 |
'fromsection' => 5, |
| 967 |
'totext' => "== Section 1 ==\nTo text\n\n== Section 2 ==\nTo text?", |
| 968 |
'tosection' => 2, |
| 969 |
], |
| 970 |
[], |
| 971 |
'nosuchfromsection', |
| 972 |
], |
| 973 |
'Error, test with invalid to section ID' => [ |
| 974 |
[ |
| 975 |
'fromtitle' => 'ApiComparePagesTest F', |
| 976 |
'fromsection' => 1, |
| 977 |
'totext' => "== Section 1 ==\nTo text\n\n== Section 2 ==\nTo text?", |
| 978 |
'tosection' => 5, |
| 979 |
], |
| 980 |
[], |
| 981 |
'nosuchtosection', |
| 982 |
], |
| 983 |
'Error, Relative diff, no from revision' => [ |
| 984 |
[ |
| 985 |
'fromtext' => 'Foo', |
| 986 |
'torelative' => 'cur', |
| 987 |
'prop' => 'ids', |
| 988 |
], |
| 989 |
[], |
| 990 |
'compare-relative-to-nothing' |
| 991 |
], |
| 992 |
'Error, Relative diff, cur with no current revision' => [ |
| 993 |
[ |
| 994 |
'fromrev' => '{{REPL:revE2}}', |
| 995 |
'torelative' => 'cur', |
| 996 |
'prop' => 'ids', |
| 997 |
], |
| 998 |
[], |
| 999 |
'nosuchrevid' |
| 1000 |
], |
| 1001 |
'Error, Relative diff, next revdeleted' => [ |
| 1002 |
[ |
| 1003 |
'fromrev' => '{{REPL:revB1}}', |
| 1004 |
'torelative' => 'next', |
| 1005 |
'prop' => 'ids', |
| 1006 |
], |
| 1007 |
[], |
| 1008 |
'missingcontent' |
| 1009 |
], |
| 1010 |
'Error, Relative diff, prev revdeleted' => [ |
| 1011 |
[ |
| 1012 |
'fromrev' => '{{REPL:revB3}}', |
| 1013 |
'torelative' => 'prev', |
| 1014 |
'prop' => 'ids', |
| 1015 |
], |
| 1016 |
[], |
| 1017 |
'missingcontent' |
| 1018 |
], |
| 1019 |
'Error, section diff with no revision' => [ |
| 1020 |
[ |
| 1021 |
'fromtitle' => 'ApiComparePagesTest F', |
| 1022 |
'toslots' => 'main', |
| 1023 |
'totext-main' => "== Section 1 ==\nTo text?", |
| 1024 |
'tosection-main' => 1, |
| 1025 |
], |
| 1026 |
[], |
| 1027 |
'compare-notorevision', |
| 1028 |
], |
| 1029 |
'Error, section diff with revdeleted revision' => [ |
| 1030 |
[ |
| 1031 |
'fromtitle' => 'ApiComparePagesTest F', |
| 1032 |
'torev' => '{{REPL:revB2}}', |
| 1033 |
'toslots' => 'main', |
| 1034 |
'totext-main' => "== Section 1 ==\nTo text?", |
| 1035 |
'tosection-main' => 1, |
| 1036 |
], |
| 1037 |
[], |
| 1038 |
'missingcontent', |
| 1039 |
], |
| 1040 |
'Error, section diff with a content model not supporting sections' => [ |
| 1041 |
[ |
| 1042 |
'fromtitle' => 'ApiComparePagesTest G', |
| 1043 |
'torev' => '{{REPL:revG1}}', |
| 1044 |
'toslots' => 'main', |
| 1045 |
'totext-main' => "== Section 1 ==\nTo text?", |
| 1046 |
'tosection-main' => 1, |
| 1047 |
], |
| 1048 |
[], |
| 1049 |
'sectionsnotsupported', |
| 1050 |
], |
| 1051 |
'Error, section diff with bad content model' => [ |
| 1052 |
[ |
| 1053 |
'fromtitle' => 'ApiComparePagesTest F', |
| 1054 |
'torev' => '{{REPL:revF1}}', |
| 1055 |
'toslots' => 'main', |
| 1056 |
'totext-main' => "== Section 1 ==\nTo text?", |
| 1057 |
'tosection-main' => 1, |
| 1058 |
'tocontentmodel-main' => CONTENT_MODEL_TEXT, |
| 1059 |
], |
| 1060 |
[], |
| 1061 |
'sectionreplacefailed', |
| 1062 |
], |
| 1063 |
'Error, deleting the main slot' => [ |
| 1064 |
[ |
| 1065 |
'fromtitle' => 'ApiComparePagesTest A', |
| 1066 |
'totitle' => 'ApiComparePagesTest A', |
| 1067 |
'toslots' => 'main', |
| 1068 |
], |
| 1069 |
[], |
| 1070 |
'compare-maintextrequired', |
| 1071 |
], |
| 1072 |
|
| 1073 |
]; |
| 1074 |
|
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
public function testNoReadAccess() { |
| 1081 |
$this->overrideConfigValue( MainConfigNames::DiffEngine, 'php' ); |
| 1082 |
|
| 1083 |
$params = [ |
| 1084 |
'fromrev' => '{{REPL:revA2}}', |
| 1085 |
'torelative' => 'cur', |
| 1086 |
'prop' => 'ids', |
| 1087 |
'action' => 'compare', |
| 1088 |
'errorformat' => 'none', |
| 1089 |
]; |
| 1090 |
|
| 1091 |
$this->doReplacements( $params ); |
| 1092 |
|
| 1093 |
$performer = static::getTestUser()->getAuthority(); |
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
$this->setTemporaryHook( |
| 1098 |
'getUserPermissionsErrors', |
| 1099 |
static function ( $title, $user, $action, &$result ) { |
| 1100 |
if ( $action === 'read' ) { |
| 1101 |
$result = 'badaccess-group0'; |
| 1102 |
return false; |
| 1103 |
} |
| 1104 |
|
| 1105 |
return true; |
| 1106 |
} |
| 1107 |
); |
| 1108 |
|
| 1109 |
$expectedCode = 'permissiondenied'; |
| 1110 |
|
| 1111 |
try { |
| 1112 |
$this->doApiRequest( $params, null, false, $performer ); |
| 1113 |
$this->fail( 'Expected exception not thrown' ); |
| 1114 |
} catch ( ApiUsageException $ex ) { |
| 1115 |
$this->assertApiErrorCode( $expectedCode, $ex, |
| 1116 |
"Exception with code $expectedCode" ); |
| 1117 |
} |
| 1118 |
} |
| 1119 |
} |