Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
< ? php
namespace MediaWiki\Tests\Integration\CommentFormatter ;
2022-01-27 23:32:56 +00:00
use LinkCacheTestTrait ;
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
use MediaWiki\Cache\LinkBatchFactory ;
use MediaWiki\CommentFormatter\CommentParser ;
2022-01-27 23:32:56 +00:00
use MediaWiki\Logger\LoggerFactory ;
use MediaWiki\Tests\Unit\DummyServicesTrait ;
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
use SiteConfiguration ;
use Title ;
/**
2022-08-06 20:53:57 +00:00
* @ group Database
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
* @ covers \MediaWiki\CommentFormatter\CommentParser
*/
class CommentParserTest extends \MediaWikiIntegrationTestCase {
2022-01-27 23:32:56 +00:00
use DummyServicesTrait ;
use LinkCacheTestTrait ;
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
private function getParser () {
$services = $this -> getServiceContainer ();
return new CommentParser (
$services -> getLinkRenderer (),
$services -> getLinkBatchFactory (),
$services -> getLinkCache (),
$services -> getRepoGroup (),
$services -> getContentLanguage (),
$services -> getContentLanguage (),
$services -> getTitleParser (),
$services -> getNamespaceInfo (),
$services -> getHookContainer ()
);
}
2022-01-27 23:32:56 +00:00
private function setupInterwiki () {
$this -> overrideMwServices ( null , [
'InterwikiLookup' => function () {
return $this -> getDummyInterwikiLookup ( [
'interwiki' => [
'iw_prefix' => 'interwiki' ,
'iw_url' => 'https://interwiki/$1' ,
]
] );
}
] );
}
private function setupConf () {
$conf = new SiteConfiguration ();
$conf -> settings = [
'wgServer' => [
'enwiki' => '//en.example.org'
],
'wgArticlePath' => [
'enwiki' => '/w/$1' ,
],
];
$conf -> suffixes = [ 'wiki' ];
$this -> setMwGlobals ( [
'wgScript' => '/wiki/index.php' ,
'wgArticlePath' => '/wiki/$1' ,
'wgCapitalLinks' => true ,
'wgConf' => $conf ,
2022-07-21 21:25:22 +00:00
'wgLanguageCode' => 'en' ,
2022-01-27 23:32:56 +00:00
] );
}
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
/**
* Copied from LinkerTest so that LinkerTest can be deleted once deprecation
* and removal of Linker :: formatComment () is complete .
*
* @ return array []
*/
public function provideFormatComment () {
$wikiId = 'enwiki' ; // $wgConf has a fake entry for this
return [
// Linker::formatComment
[
'a<script>b' ,
'a<script>b' ,
],
[
'a—b' ,
'a—b' ,
],
[
" '''not bolded''' " ,
" '''not bolded''' " ,
],
[
" try <script>evil</scipt> things " ,
" try <script>evil</scipt> things " ,
],
// Linker::formatAutocomments
[
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→ autocomment</a></span></span>' ,
" /* autocomment */ " ,
],
[
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#linkie.3F" title="Special:BlankPage">→[[linkie?]]</a></span></span>' ,
" /* [[linkie?]] */ " ,
],
[
'<span dir="auto"><span class="autocomment">: </span> // Edit via via</span>' ,
// Regression test for T222857
" /* */ // Edit via via " ,
],
[
'<span dir="auto"><span class="autocomment">: </span> foobar</span>' ,
// Regression test for T222857
" /**/ foobar " ,
],
[
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→ autocomment</a>: </span> post</span>' ,
" /* autocomment */ post " ,
],
[
'pre <span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→ autocomment</a></span></span>' ,
" pre /* autocomment */ " ,
],
[
'pre <span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→ autocomment</a>: </span> post</span>' ,
" pre /* autocomment */ post " ,
],
[
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→ autocomment</a>: </span> multiple? <span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment2" title="Special:BlankPage">→ autocomment2</a></span></span></span>' ,
" /* autocomment */ multiple? /* autocomment2 */ " ,
],
[
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment_containing_.2F.2A" title="Special:BlankPage">→ autocomment containing /*</a>: </span> T70361</span>' ,
" /* autocomment containing /* */ T70361 "
],
[
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment_containing_.22quotes.22" title="Special:BlankPage">→ autocomment containing "quotes"</a></span></span>' ,
" /* autocomment containing \" quotes \" */ "
],
[
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment_containing_.3Cscript.3Etags.3C.2Fscript.3E" title="Special:BlankPage">→ autocomment containing <script>tags</script></a></span></span>' ,
" /* autocomment containing <script>tags</script> */ "
],
[
'<span dir="auto"><span class="autocomment"><a href="#autocomment">→ autocomment</a></span></span>' ,
" /* autocomment */ " ,
false , true
],
[
'<span dir="auto"><span class="autocomment">autocomment</span></span>' ,
" /* autocomment */ " ,
null
],
[
'' ,
" /* */ " ,
false , true
],
[
'' ,
" /* */ " ,
null
],
[
'<span dir="auto"><span class="autocomment">[[</span></span>' ,
" /* [[ */ " ,
false , true
],
[
'<span dir="auto"><span class="autocomment">[[</span></span>' ,
" /* [[ */ " ,
null
],
[
" foo <span dir= \" auto \" ><span class= \" autocomment \" ><a href= \" #.23 \" >→[[#_ \t _]]</a></span></span> " ,
" foo /* [[#_ \t _]] */ " ,
false , true
],
[
" foo <span dir= \" auto \" ><span class= \" autocomment \" ><a href= \" #_.09 \" >#_ \t _</a></span></span> " ,
" foo /* [[#_ \t _]] */ " ,
null
],
[
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→ autocomment</a></span></span>' ,
" /* autocomment */ " ,
false , false
],
[
'<span dir="auto"><span class="autocomment"><a class="external" rel="nofollow" href="//en.example.org/w/Special:BlankPage#autocomment">→ autocomment</a></span></span>' ,
" /* autocomment */ " ,
false , false , $wikiId
],
// Linker::formatLinksInComment
[
'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">link</a> def' ,
" abc [[link]] def " ,
],
[
'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">text</a> def' ,
" abc [[link|text]] def " ,
],
[
'abc <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a> def' ,
" abc [[Special:BlankPage|]] def " ,
],
[
'abc <a href="/wiki/index.php?title=%C4%84%C5%9B%C5%BC&action=edit&redlink=1" class="new" title="Ąśż (page does not exist)">ąśż</a> def' ,
" abc [[%C4%85%C5%9B%C5%BC]] def " ,
],
[
'abc <a href="/wiki/Special:BlankPage#section" title="Special:BlankPage">#section</a> def' ,
" abc [[#section]] def " ,
],
[
'abc <a href="/wiki/index.php?title=/subpage&action=edit&redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> def' ,
" abc [[/subpage]] def " ,
],
[
'abc <a href="/wiki/index.php?title=%22evil!%22&action=edit&redlink=1" class="new" title=""evil!" (page does not exist)">"evil!"</a> def' ,
" abc [[ \" evil! \" ]] def " ,
],
[
'abc [[<script>very evil</script>]] def' ,
" abc [[<script>very evil</script>]] def " ,
],
[
'abc [[|]] def' ,
" abc [[|]] def " ,
],
[
'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">link</a> def' ,
" abc [[link]] def " ,
false , false
],
[
'abc <a class="external" rel="nofollow" href="//en.example.org/w/Link">link</a> def' ,
" abc [[link]] def " ,
false , false , $wikiId
],
[
'<a href="/wiki/index.php?title=Special:Upload&wpDestFile=LinkerTest.jpg" class="new" title="LinkerTest.jpg">Media:LinkerTest.jpg</a>' ,
'[[Media:LinkerTest.jpg]]'
],
[
'<a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>' ,
'[[:Special:BlankPage]]'
],
[
'<a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">linktrail</a>...' ,
'[[link]]trail...'
2022-01-27 23:32:56 +00:00
],
[
'<a href="/wiki/Present" title="Present">Present</a>' ,
'[[Present]]' ,
],
[
'<a href="https://interwiki/Some_page" class="extiw" title="interwiki:Some page">interwiki:Some page</a>' ,
'[[interwiki:Some page]]' ,
],
[
'<a href="https://interwiki/Present" class="extiw" title="interwiki:Present">interwiki:Present</a> <a href="/wiki/Present" title="Present">Present</a>' ,
'[[interwiki:Present]] [[Present]]'
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
]
];
// phpcs:enable
}
/**
* Adapted from LinkerTest
*
* @ dataProvider provideFormatComment
*/
public function testFormatComment (
$expected , $comment , $title = false , $local = false , $wikiId = null
) {
$conf = new SiteConfiguration ();
$conf -> settings = [
'wgServer' => [
'enwiki' => '//en.example.org' ,
'dewiki' => '//de.example.org' ,
],
'wgArticlePath' => [
'enwiki' => '/w/$1' ,
'dewiki' => '/w/$1' ,
],
];
$conf -> suffixes = [ 'wiki' ];
$this -> setMwGlobals ( [
'wgScript' => '/wiki/index.php' ,
'wgArticlePath' => '/wiki/$1' ,
'wgCapitalLinks' => true ,
'wgConf' => $conf ,
// TODO: update tests when the default changes
'wgFragmentMode' => [ 'legacy' ],
2022-07-21 21:25:22 +00:00
'wgLanguageCode' => 'en' ,
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
] );
2022-01-27 23:32:56 +00:00
$this -> setupInterwiki ();
$this -> addGoodLinkObject ( 1 , Title :: newFromText ( 'Present' ) );
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
if ( $title === false ) {
// We need a page title that exists
$title = Title :: newFromText ( 'Special:BlankPage' );
}
$parser = $this -> getParser ();
$result = $parser -> finalize (
$parser -> preprocess (
$comment ,
$title ,
$local ,
$wikiId
)
);
$this -> assertEquals ( $expected , $result );
}
/**
* Adapted from LinkerTest
*/
public static function provideFormatLinksInComment () {
return [
[
'foo bar <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>' ,
'foo bar [[Special:BlankPage]]' ,
null ,
],
[
'<a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>' ,
'[[ :Special:BlankPage]]' ,
null ,
],
[
'[[Foo<a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>' ,
'[[Foo[[Special:BlankPage]]' ,
null ,
],
[
'<a class="external" rel="nofollow" href="//en.example.org/w/Foo%27bar">Foo'bar</a>' ,
" [[Foo'bar]] " ,
'enwiki' ,
],
[
'foo bar <a class="external" rel="nofollow" href="//en.example.org/w/Special:BlankPage">Special:BlankPage</a>' ,
'foo bar [[Special:BlankPage]]' ,
'enwiki' ,
],
[
'foo bar <a class="external" rel="nofollow" href="//en.example.org/w/File:Example">Image:Example</a>' ,
'foo bar [[Image:Example]]' ,
'enwiki' ,
],
];
// phpcs:enable
}
/**
* Adapted from LinkerTest . Note that we test the new HTML escaping variant .
*
* @ dataProvider provideFormatLinksInComment
*/
public function testFormatLinksInComment ( $expected , $input , $wiki ) {
2022-01-27 23:32:56 +00:00
$this -> setupConf ();
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
$parser = $this -> getParser ();
$title = Title :: newFromText ( 'Special:BlankPage' );
$result = $parser -> finalize (
$parser -> preprocess (
$input , $title , false , $wiki , false
)
);
$this -> assertEquals ( $expected , $result );
}
public function testLinkCacheInteraction () {
$this -> tablesUsed [] = 'page' ;
2022-07-21 21:25:22 +00:00
$this -> setupConf ();
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
$services = $this -> getServiceContainer ();
$present = Title :: newFromText ( 'Present' );
$absent = Title :: newFromText ( 'Absent' );
$this -> editPage (
$present ,
'content'
);
$parser = $this -> getParser ();
$linkCache = $services -> getLinkCache ();
$result = $parser -> finalize ( [
$parser -> preprocess ( " [[ $present ]] " ),
$parser -> preprocess ( " [[ $absent ]] " )
] );
$expected = [
2022-07-21 21:25:22 +00:00
'<a href="/wiki/Present" title="Present">Present</a>' ,
'<a href="/wiki/index.php?title=Absent&action=edit&redlink=1" class="new" title="Absent (page does not exist)">Absent</a>'
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
];
$this -> assertSame ( $expected , $result );
$this -> assertGreaterThan ( 0 , $linkCache -> getGoodLinkID ( $present ) );
$this -> assertTrue ( $linkCache -> isBadLink ( $absent ) );
// Run the comment batch again and confirm that LinkBatch does not need
// to execute a query. This is a CommentParser responsibility since
// LinkBatch does not provide a transparent read-through cache.
// TODO: Generic $this->assertQueryCount() would do the job.
$lbf = $services -> getDBLoadBalancerFactory ();
$fakeLB = $lbf -> newMainLB ();
$fakeLB -> disable ( __METHOD__ );
$linkBatchFactory = new LinkBatchFactory (
$services -> getLinkCache (),
$services -> getTitleFormatter (),
$services -> getContentLanguage (),
$services -> getGenderCache (),
2022-01-27 23:32:56 +00:00
$fakeLB ,
2022-04-21 19:35:30 +00:00
$services -> getLinksMigration (),
2022-01-27 23:32:56 +00:00
LoggerFactory :: getInstance ( 'LinkBatch' )
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
);
$parser = new CommentParser (
$services -> getLinkRenderer (),
$linkBatchFactory ,
$linkCache ,
$services -> getRepoGroup (),
$services -> getContentLanguage (),
$services -> getContentLanguage (),
$services -> getTitleParser (),
$services -> getNamespaceInfo (),
$services -> getHookContainer ()
);
$result = $parser -> finalize ( [
$parser -> preprocess ( " [[ $present ]] " ),
$parser -> preprocess ( " [[ $absent ]] " )
] );
$this -> assertSame ( $expected , $result );
}
2022-01-27 23:32:56 +00:00
/**
* Regression test for T300311
*/
public function testInterwikiLinkCachePollution () {
$this -> tablesUsed [] = 'page' ;
$this -> setupConf ();
$this -> setupInterwiki ();
$present = Title :: newFromText ( 'Template:Present' );
$this -> editPage (
$present ,
'content'
);
$this -> getServiceContainer () -> getLinkCache () -> clear ();
$parser = $this -> getParser ();
$result = $parser -> finalize (
$parser -> preprocess ( " [[interwiki: $present ]] [[ $present ]] " )
);
$this -> assertSame (
// phpcs:ignore Generic.Files.LineLength
" <a href= \" https://interwiki/ $present\ " class = \ " extiw \" title= \" interwiki: $present\ " > interwiki : $present </ a > < a href = \ " /wiki/ $present\ " title = \ " $present\ " > $present </ a > " ,
$result
);
}
2022-02-17 21:37:06 +00:00
/**
* Regression test for T293665
*/
public function testAlwaysKnownPages () {
2022-07-21 21:25:22 +00:00
$this -> setupConf ();
2022-02-17 21:37:06 +00:00
$this -> setTemporaryHook ( 'TitleIsAlwaysKnown' ,
static function ( $target , & $isKnown ) {
$isKnown = $target -> getText () == 'AlwaysKnownFoo' ;
}
);
$title = Title :: newFromText ( 'User:AlwaysKnownFoo' );
$this -> assertFalse ( $title -> exists () );
$parser = $this -> getParser ();
$result = $parser -> finalize ( $parser -> preprocess ( 'test [[User:AlwaysKnownFoo]]' ) );
$this -> assertSame (
2022-07-21 21:25:22 +00:00
'test <a href="/wiki/User:AlwaysKnownFoo" title="User:AlwaysKnownFoo">User:AlwaysKnownFoo</a>' ,
2022-07-09 20:19:27 +00:00
$result
2022-02-17 21:37:06 +00:00
);
}
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
}