20use PHPUnit\Framework\MockObject\MockObject;
39 $mock = $this->getMockBuilder( Title::class )
40 ->disableOriginalConstructor()
42 $mock->expects( $this->any() )
43 ->method(
'getNamespace' )
44 ->will( $this->returnValue(
NS_MAIN ) );
45 $mock->expects( $this->any() )
47 ->will( $this->returnValue( __CLASS__ ) );
48 $mock->expects( $this->any() )
49 ->method(
'getPrefixedText' )
50 ->will( $this->returnValue( __CLASS__ ) );
51 $mock->expects( $this->any() )
52 ->method(
'getDBkey' )
53 ->will( $this->returnValue( __CLASS__ ) );
54 $mock->expects( $this->any() )
55 ->method(
'getArticleID' )
56 ->will( $this->returnValue( $articleId ) );
57 $mock->expects( $this->any() )
58 ->method(
'getLatestRevId' )
59 ->will( $this->returnValue( $revisionId ) );
60 $mock->expects( $this->any() )
61 ->method(
'getContentModel' )
63 $mock->expects( $this->any() )
64 ->method(
'getPageLanguage' )
65 ->will( $this->returnValue( Language::factory(
'en' ) ) );
66 $mock->expects( $this->any() )
67 ->method(
'isContentPage' )
68 ->will( $this->returnValue(
true ) );
69 $mock->expects( $this->any() )
72 function (
Title $other )
use ( $mock ) {
76 $mock->expects( $this->any() )
80 return $user->isAllowed( $perm );
95 $db = $this->getMock( IDatabase::class );
96 $db->method(
'selectField' )
98 function ( $table, $fields, $cond )
use ( $maxRev, $linkCount ) {
121 $lb = $this->getMock( ILoadBalancer::class );
122 $lb->method(
'getConnection' )
125 $lb->method(
'getConnectionRef' )
128 $lb->method(
'getLazyConnectionRef' )
133 $slotRoles = $this->getMockBuilder( NameTableStore::class )
134 ->disableOriginalConstructor()
136 $slotRoles->method(
'getMap' )
140 $roleReg->defineRole(
'main',
function () {
149 if ( [ $table, $fields, $cond ] === [
'revision',
'MAX(rev_id)', [] ] ) {
153 $this->fail(
'Unexpected call to selectField' );
154 throw new LogicException(
'Ooops' );
163 $rev->setTimestamp(
'20180101000003' );
164 $rev->setComment( CommentStoreComment::newUnsavedComment(
'' ) );
167 $text .=
"* page:{{PAGENAME}}\n";
168 $text .=
"* rev:{{REVISIONID}}\n";
169 $text .=
"* user:{{REVISIONUSER}}\n";
170 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
171 $text .=
"* [[Link It]]\n";
175 $options = ParserOptions::newCanonical(
'canonical' );
178 $this->assertFalse( $rr->isContentDeleted(),
'isContentDeleted' );
180 $this->assertSame(
$rev, $rr->getRevision() );
181 $this->assertSame(
$options, $rr->getOptions() );
183 $html = $rr->getRevisionParserOutput()->getText();
185 $this->assertContains(
'page:' . __CLASS__,
$html );
186 $this->assertContains(
'rev:101',
$html );
187 $this->assertContains(
'user:Frank',
$html );
188 $this->assertContains(
'time:20180101000003',
$html );
190 $this->assertSame(
$html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
200 $rev->setTimestamp(
'20180101000003' );
201 $rev->setComment( CommentStoreComment::newUnsavedComment(
'' ) );
204 $text .=
"* page:{{PAGENAME}}\n";
205 $text .=
"* rev:{{REVISIONID}}\n";
206 $text .=
"* user:{{REVISIONUSER}}\n";
207 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
211 $options = ParserOptions::newCanonical(
'canonical' );
214 $this->assertFalse( $rr->isContentDeleted(),
'isContentDeleted' );
216 $this->assertSame(
$rev, $rr->getRevision() );
217 $this->assertSame(
$options, $rr->getOptions() );
219 $html = $rr->getRevisionParserOutput()->getText();
221 $this->assertContains(
'page:' . __CLASS__,
$html );
222 $this->assertContains(
'rev:21',
$html );
223 $this->assertContains(
'user:Frank',
$html );
224 $this->assertContains(
'time:20180101000003',
$html );
226 $this->assertSame(
$html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
236 $rev->setTimestamp(
'20180101000003' );
237 $rev->setComment( CommentStoreComment::newUnsavedComment(
'' ) );
240 $text .=
"* page:{{PAGENAME}}\n";
241 $text .=
"* rev:{{REVISIONID}}\n";
242 $text .=
"* user:{{REVISIONUSER}}\n";
243 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
247 $options = ParserOptions::newCanonical(
'canonical' );
248 $rr = $renderer->getRenderedRevision(
$rev,
$options,
null, [
'use-master' =>
true ] );
250 $this->assertFalse( $rr->isContentDeleted(),
'isContentDeleted' );
252 $html = $rr->getRevisionParserOutput()->getText();
254 $this->assertContains(
'rev:21',
$html );
256 $this->assertSame(
$html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
266 $rev->setTimestamp(
'20180101000003' );
267 $rev->setComment( CommentStoreComment::newUnsavedComment(
'' ) );
269 $text =
"uncached text";
274 $options = ParserOptions::newCanonical(
'canonical' );
275 $rr = $renderer->getRenderedRevision(
279 [
'known-revision-output' =>
$output ]
282 $this->assertSame(
$output, $rr->getRevisionParserOutput() );
283 $this->assertSame(
'cached text', $rr->getRevisionParserOutput()->getText() );
284 $this->assertSame(
'cached text', $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
294 $rev->setTimestamp(
'20180101000003' );
295 $rev->setComment( CommentStoreComment::newUnsavedComment(
'' ) );
298 $text .=
"* page:{{PAGENAME}}\n";
299 $text .=
"* rev:{{REVISIONID}}\n";
300 $text .=
"* user:{{REVISIONUSER}}\n";
301 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
305 $options = ParserOptions::newCanonical(
'canonical' );
308 $this->assertFalse( $rr->isContentDeleted(),
'isContentDeleted' );
310 $this->assertSame(
$rev, $rr->getRevision() );
311 $this->assertSame(
$options, $rr->getOptions() );
313 $html = $rr->getRevisionParserOutput()->getText();
315 $this->assertContains(
'page:' . __CLASS__,
$html );
316 $this->assertContains(
'rev:11',
$html );
317 $this->assertContains(
'user:Frank',
$html );
318 $this->assertContains(
'time:20180101000003',
$html );
320 $this->assertSame(
$html, $rr->getSlotParserOutput(
'main' )->getText() );
329 $rev->setVisibility( RevisionRecord::DELETED_TEXT );
331 $rev->setTimestamp(
'20180101000003' );
332 $rev->setComment( CommentStoreComment::newUnsavedComment(
'' ) );
335 $text .=
"* page:{{PAGENAME}}\n";
336 $text .=
"* rev:{{REVISIONID}}\n";
337 $text .=
"* user:{{REVISIONUSER}}\n";
338 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
342 $options = ParserOptions::newCanonical(
'canonical' );
345 $this->assertNull( $rr,
'getRenderedRevision' );
354 $rev->setVisibility( RevisionRecord::DELETED_TEXT );
356 $rev->setTimestamp(
'20180101000003' );
357 $rev->setComment( CommentStoreComment::newUnsavedComment(
'' ) );
360 $text .=
"* page:{{PAGENAME}}\n";
361 $text .=
"* rev:{{REVISIONID}}\n";
362 $text .=
"* user:{{REVISIONUSER}}\n";
363 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
367 $options = ParserOptions::newCanonical(
'canonical' );
368 $sysop = $this->
getTestUser( [
'sysop' ] )->getUser();
369 $rr = $renderer->getRenderedRevision(
$rev,
$options, $sysop );
371 $this->assertTrue( $rr->isContentDeleted(),
'isContentDeleted' );
373 $this->assertSame(
$rev, $rr->getRevision() );
374 $this->assertSame(
$options, $rr->getOptions() );
376 $html = $rr->getRevisionParserOutput()->getText();
379 $this->assertContains(
'page:' . __CLASS__,
$html );
380 $this->assertContains(
'rev:11',
$html );
381 $this->assertContains(
'user:Frank',
$html );
382 $this->assertContains(
'time:20180101000003',
$html );
384 $this->assertSame(
$html, $rr->getSlotParserOutput(
'main' )->getText() );
393 $rev->setVisibility( RevisionRecord::DELETED_TEXT );
395 $rev->setTimestamp(
'20180101000003' );
396 $rev->setComment( CommentStoreComment::newUnsavedComment(
'' ) );
399 $text .=
"* page:{{PAGENAME}}\n";
400 $text .=
"* rev:{{REVISIONID}}\n";
401 $text .=
"* user:{{REVISIONUSER}}\n";
402 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
406 $options = ParserOptions::newCanonical(
'canonical' );
407 $rr = $renderer->getRenderedRevision(
411 [
'audience' => RevisionRecord::RAW ]
414 $this->assertTrue( $rr->isContentDeleted(),
'isContentDeleted' );
416 $this->assertSame(
$rev, $rr->getRevision() );
417 $this->assertSame(
$options, $rr->getOptions() );
419 $html = $rr->getRevisionParserOutput()->getText();
422 $this->assertContains(
'page:' . __CLASS__,
$html );
423 $this->assertContains(
'rev:11',
$html );
424 $this->assertContains(
'user:Frank',
$html );
425 $this->assertContains(
'time:20180101000003',
$html );
427 $this->assertSame(
$html, $rr->getSlotParserOutput(
'main' )->getText() );
436 $rev->setTimestamp(
'20180101000003' );
437 $rev->setComment( CommentStoreComment::newUnsavedComment(
'' ) );
442 $rr = $renderer->getRenderedRevision(
$rev );
444 $combinedOutput = $rr->getRevisionParserOutput();
445 $mainOutput = $rr->getSlotParserOutput( SlotRecord::MAIN );
446 $auxOutput = $rr->getSlotParserOutput(
'aux' );
448 $combinedHtml = $combinedOutput->getText();
449 $mainHtml = $mainOutput->getText();
450 $auxHtml = $auxOutput->getText();
452 $this->assertContains(
'Kittens', $mainHtml );
453 $this->assertContains(
'Goats', $auxHtml );
454 $this->assertNotContains(
'Goats', $mainHtml );
455 $this->assertNotContains(
'Kittens', $auxHtml );
456 $this->assertContains(
'Kittens', $combinedHtml );
457 $this->assertContains(
'Goats', $combinedHtml );
458 $this->assertContains(
'>aux<', $combinedHtml,
'slot header' );
459 $this->assertNotContains(
'<mw:slotheader', $combinedHtml,
'slot header placeholder' );
462 $this->assertContains(
'class="mw-parser-output"', $mainHtml );
463 $this->assertContains(
'class="mw-parser-output"', $auxHtml );
464 $this->assertContains(
'class="mw-parser-output"', $combinedHtml );
467 $this->assertSame( 1, preg_match_all(
'#class="mw-parser-output"#', $combinedHtml ) );
468 $this->assertNotContains(
'class="mw-parser-output"', $combinedOutput->getRawText() );
470 $combinedLinks = $combinedOutput->getLinks();
471 $mainLinks = $mainOutput->getLinks();
472 $auxLinks = $auxOutput->getLinks();
473 $this->assertTrue( isset( $combinedLinks[
NS_MAIN][
'Kittens'] ),
'links from main slot' );
474 $this->assertTrue( isset( $combinedLinks[
NS_MAIN][
'Goats'] ),
'links from aux slot' );
475 $this->assertFalse( isset( $mainLinks[
NS_MAIN][
'Goats'] ),
'no aux links in main' );
476 $this->assertFalse( isset( $auxLinks[
NS_MAIN][
'Kittens'] ),
'no main links in aux' );
481 $mockContent = $this->getMockBuilder( WikitextContent::class )
482 ->setMethods( [
'getParserOutput' ] )
483 ->setConstructorArgs( [
'Whatever' ] )
485 $mockContent->method(
'getParserOutput' )
486 ->willReturnCallback(
function (
Title $title, $revId =
null,
489 if ( !$generateHtml ) {
492 $this->fail(
'Should not be called with $generateHtml == true' );
501 $rev->setContent( SlotRecord::MAIN, $mockContent );
502 $rev->setContent(
'aux', $mockContent );
505 $rr = $renderer->getRenderedRevision(
$rev );
507 $output = $rr->getSlotParserOutput( SlotRecord::MAIN, [
'generate-html' =>
false ] );
508 $this->assertFalse(
$output->hasText(),
'hasText' );
510 $output = $rr->getRevisionParserOutput( [
'generate-html' =>
false ] );
511 $this->assertFalse(
$output->hasText(),
'hasText' );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Internationalisation code.
A SlotRoleHandler for the main slot.
Set options of the Parser.
Represents a title within MediaWiki.
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Content object for wiki text pages.
const CONTENT_MODEL_WIKITEXT
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
namespace and then decline to actually register it file or subcat img or subcat $title
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
return true to allow those checks to and false if checking is done & $user
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Base interface for content objects.