16 const RSS_RC_LINK =
'<link rel="alternate" type="application/rss+xml" title=" RSS feed" href="/w/index.php?title=Special:RecentChanges&feed=rss"/>';
17 const ATOM_RC_LINK =
'<link rel="alternate" type="application/atom+xml" title=" Atom feed" href="/w/index.php?title=Special:RecentChanges&feed=atom"/>';
19 const RSS_TEST_LINK =
'<link rel="alternate" type="application/rss+xml" title=""Test" RSS feed" href="fake-link"/>';
20 const ATOM_TEST_LINK =
'<link rel="alternate" type="application/atom+xml" title=""Test" Atom feed" href="fake-link"/>';
26 ResourceLoader::clearCache();
30 ResourceLoader::clearCache();
43 $op->redirect( $url,
$code );
45 $op->redirect( $url );
48 $this->
assertSame( $expectedUrl, $op->getRedirect() );
49 $this->
assertSame( $expectedUrl, $op->mRedirect );
55 [
'http://example.com' ],
56 [
'http://example.com',
'400' ],
57 [
'http://example.com',
'squirrels!!!' ],
64 'AdvertisedFeedTypes' => $types,
66 'OverrideSiteFeed' =>
false,
70 $outputPage->setTitle( Title::makeTitle(
NS_MAIN,
'Test' ) );
72 'wgScript' =>
'/w/index.php',
77 private function assertFeedLinks( $outputPage, $message, $present, $non_present ) {
78 $links = $outputPage->getHeadLinksArray();
79 foreach ( $present as
$link ) {
82 foreach ( $non_present as
$link ) {
89 $this->
assertTrue( $outputPage->isSyndicated(),
'Syndication should be offered' );
91 'Some syndication links should be there' );
93 $this->
assertFalse( $outputPage->isSyndicated(),
'No syndication should be offered' );
94 $this->
assertEquals( 0, count( $outputPage->getSyndicationLinks() ),
95 'No syndication links should be there' );
102 true, [
'rss' ],
'Only RSS RC link should be offerred',
106 true, [
'atom' ],
'Only Atom RC link should be offerred',
110 true, [],
'No RC feed formats should be offerred',
114 false, [
'atom' ],
'No RC feeds should be offerred',
126 $op->setCopyrightUrl(
'http://example.com' );
129 Html::element(
'link', [
'rel' =>
'license',
'href' =>
'http://example.com' ] ),
130 $op->getHeadLinksArray()[
'copyright']
139 $message, $present, $non_present ) {
140 $outputPage = $this->
setupFeedLinks( $feed, $advertised_feed_types );
141 $this->
assertFeedLinks( $outputPage, $message, $present, $non_present );
147 true, [
'atom' ],
'Additional Atom feed should be offered',
154 true, [
'rss' ],
'Additional RSS feed should be offered',
161 true, [
'rss' ],
'Additional Atom feed should NOT be offered with RSS enabled',
168 false, [
'atom' ],
'Additional Atom feed should NOT be offered, all feeds disabled',
188 $additional_feed_type, $present, $non_present, $any_ui_links ) {
189 $outputPage = $this->
setupFeedLinks( $feed, $advertised_feed_types );
190 $outputPage->addFeedLink( $additional_feed_type,
'fake-link' );
191 $this->
assertFeedLinks( $outputPage, $message, $present, $non_present );
204 $op->addMeta(
'http:expires',
'0' );
205 $op->addMeta(
'keywords',
'first' );
206 $op->addMeta(
'keywords',
'second' );
207 $op->addMeta(
'og:title',
'Ta-duh' );
210 [
'http:expires',
'0' ],
211 [
'keywords',
'first' ],
212 [
'keywords',
'second' ],
213 [
'og:title',
'Ta-duh' ],
215 $this->
assertSame( $expected, $op->getMetaTags() );
217 $links = $op->getHeadLinksArray();
218 $this->
assertContains(
'<meta http-equiv="expires" content="0"/>', $links );
219 $this->
assertContains(
'<meta name="keywords" content="first"/>', $links );
220 $this->
assertContains(
'<meta name="keywords" content="second"/>', $links );
221 $this->
assertContains(
'<meta property="og:title" content="Ta-duh"/>', $links );
235 [
'rel' =>
'foo',
'href' =>
'http://example.com' ],
238 foreach ( $links as
$link ) {
239 $op->addLink(
$link );
242 $this->
assertSame( $links, $op->getLinkTags() );
244 $result = $op->getHeadLinksArray();
246 foreach ( $links as
$link ) {
258 $op->setCanonicalUrl(
'http://example.comm' );
259 $op->setCanonicalUrl(
'http://example.com' );
261 $this->
assertSame(
'http://example.com', $op->getCanonicalUrl() );
263 $headLinks = $op->getHeadLinksArray();
266 'rel' =>
'canonical',
'href' =>
'http://example.com'
270 'rel' =>
'canonical',
'href' =>
'http://example.comm'
279 $op->addScript(
'some random string' );
281 $this->
assertContains(
"\nsome random string\n",
"\n" . $op->getBottomScripts() .
"\n" );
289 $op->addScriptFile(
'/somescript.js' );
290 $op->addScriptFile(
'//example.com/somescript.js' );
293 "\n" . Html::linkedScript(
'/somescript.js', $op->getCSPNonce() ) .
294 Html::linkedScript(
'//example.com/somescript.js', $op->getCSPNonce() ) .
"\n",
295 "\n" . $op->getBottomScripts() .
"\n"
306 'Use of OutputPage::addScriptFile was deprecated in MediaWiki 1.24.' );
309 $op->addScriptFile(
'ignored-script.js' );
321 $op->addScriptFile(
'ignored-script.js' );
331 $op->addInlineScript(
'let foo = "bar";' );
332 $op->addInlineScript(
'alert( foo );' );
335 "\n" . Html::inlineScript(
"\nlet foo = \"bar\";\n", $op->getCSPNonce() ) .
"\n" .
336 Html::inlineScript(
"\nalert( foo );\n", $op->getCSPNonce() ) .
"\n",
337 "\n" . $op->getBottomScripts() .
"\n"
349 $op->setTarget(
'foo' );
365 $op->addHeadItem(
'a',
'b' );
366 $op->addHeadItems( [
'c' =>
'<d>&',
'e' =>
'f',
'a' =>
'q' ] );
367 $op->addHeadItem(
'e',
'g' );
368 $op->addHeadItems(
'x' );
370 $this->
assertSame( [
'a' =>
'q',
'c' =>
'<d>&',
'e' =>
'g',
'x' ],
371 $op->getHeadItemsArray() );
379 '' . $op->headElement( $op->getContext()->getSkin() ) );
390 $op->addParserOutputMetadata( $stubPO1 );
392 [
'c' =>
'<d>&',
'e' =>
'f',
'a' =>
'q' ] );
393 $op->addParserOutputMetadata( $stubPO2 );
395 $op->addParserOutput( $stubPO3 );
397 $op->addParserOutputMetadata( $stubPO4 );
399 $this->
assertSame( [
'a' =>
'q',
'c' =>
'<d>&',
'e' =>
'g',
'x' ],
400 $op->getHeadItemsArray() );
409 '' . $op->headElement( $op->getContext()->getSkin() ) );
417 $op->addBodyClasses(
'a' );
418 $op->addBodyClasses(
'mediawiki' );
419 $op->addBodyClasses(
'b c' );
420 $op->addBodyClasses( [
'd',
'e' ] );
421 $op->addBodyClasses(
'a' );
424 '' . $op->headElement( $op->getContext()->getSkin() ) );
435 $op->setArticleBodyOnly(
true );
436 $this->
assertTrue( $op->getArticleBodyOnly() );
438 $op->addHTML(
'<b>a</b>' );
440 $this->
assertSame(
'<b>a</b>', $op->output(
true ) );
450 $this->
assertNull( $op->getProperty(
'foo' ) );
452 $op->setProperty(
'foo',
'bar' );
453 $op->setProperty(
'baz',
'quz' );
455 $this->
assertSame(
'bar', $op->getProperty(
'foo' ) );
456 $this->
assertSame(
'quz', $op->getProperty(
'baz' ) );
466 $timestamp, $ifModifiedSince, $expected, $config = [], $callback =
null
469 if ( $ifModifiedSince ) {
472 $ifModifiedSince = date(
'D, d M Y H:i:s', $ifModifiedSince ) .
' GMT';
474 $request->setHeader(
'If-Modified-Since', $ifModifiedSince );
477 if ( !
isset( $config[
'CacheEpoch'] ) ) {
479 $config[
'CacheEpoch'] =
'20000101000000';
485 $callback( $op, $this );
491 $this->
assertEquals( $expected, $op->checkLastModified( $timestamp ) );
498 $lastModified = time() - 3600;
502 'Timestamp Unix epoch' =>
504 'Timestamp same as If-Modified-Since' =>
506 'Timestamp one second after If-Modified-Since' =>
508 'No If-Modified-Since' =>
509 [ $lastModified + 1,
null,
false ],
510 'Malformed If-Modified-Since' =>
511 [ $lastModified + 1,
'GIBBERING WOMBATS !!!',
false ],
512 'Non-standard IE-style If-Modified-Since' =>
513 [
$lastModified, date(
'D, d M Y H:i:s', $lastModified ) .
' GMT; length=5202',
516 'If-Modified-Since not per spec but we accept it anyway because strtotime does' =>
518 '$wgCachePages = false' =>
522 [
'CacheEpoch' =>
wfTimestamp( TS_MW, $lastModified + 1 ) ] ],
523 'Recently-touched user' =>
526 $op->getContext()->setUser( $this->
getTestUser()->getUser() );
528 'After Squid expiry' =>
530 [
'UseSquid' =>
true,
'SquidMaxage' => 3599 ] ],
531 'Hook allows cache use' =>
534 $that->setTemporaryHook(
'OutputPageCheckLastModified',
535 function ( &$modifiedTimes ) {
536 $modifiedTimes = [ 1 ];
540 'Hooks prohibits cache use' =>
543 $that->setTemporaryHook(
'OutputPageCheckLastModified',
544 function ( &$modifiedTimes ) {
545 $modifiedTimes = [
max( $modifiedTimes ) + 1 ];
561 $actual =
max( $pageTime,
$out->getCdnCacheEpoch( $reqTime,
$params[
'maxAge'] ) );
565 gmdate( DateTime::ATOM, $actual ),
572 'pageTime' =>
'2011-04-01T12:00:00+00:00',
573 'maxAge' => 24 * 3600,
576 'after 1s' => [
$base + [
577 'reqTime' =>
'2011-04-01T12:00:01+00:00',
578 'expect' =>
'2011-04-01T12:00:00+00:00',
580 'after 23h' => [
$base + [
581 'reqTime' =>
'2011-04-02T11:00:00+00:00',
582 'expect' =>
'2011-04-01T12:00:00+00:00',
584 'after 24h and a bit' => [
$base + [
585 'reqTime' =>
'2011-04-02T12:34:56+00:00',
586 'expect' =>
'2011-04-01T12:34:56+00:00',
588 'after a year' => [
$base + [
589 'reqTime' =>
'2012-05-06T00:12:07+00:00',
590 'expect' =>
'2012-05-05T00:12:07+00:00',
603 $op->setRobotPolicy(
'noindex, nofollow' );
605 $links = $op->getHeadLinksArray();
606 $this->
assertContains(
'<meta name="robots" content="noindex,nofollow"/>', $links );
616 $op->setIndexPolicy(
'noindex' );
617 $op->setFollowPolicy(
'nofollow' );
619 $links = $op->getHeadLinksArray();
620 $this->
assertContains(
'<meta name="robots" content="noindex,nofollow"/>', $links );
624 $html = $op->headElement( $op->getContext()->getSkin() );
643 return $op->msg( ...$msgParams )->inContentLanguage()->text();
662 $op->setHTMLTitle(
'Potatoes will eat me' );
664 $this->
assertSame(
'Potatoes will eat me', $op->getHTMLTitle() );
670 $msg = $op->msg(
'mainpage' );
672 $op->setHTMLTitle( $msg );
673 $this->
assertSame( $msg->text(), $op->getHTMLTitle() );
674 $this->
assertSame( $msg->text(), $this->extractHTMLTitle( $op ) );
684 $op->setRedirectedFrom( Title::newFromText(
'Talk:Some page' ) );
685 $this->
assertSame(
'Talk:Some_page', $op->getJSVars()[
'wgRedirectedFrom'] );
701 $op->setPageTitle(
'foobar' );
703 $this->
assertSame(
'foobar', $op->getPageTitle() );
709 $op->setPageTitle(
'<script>a</script>&<i>b</i>' );
711 $this->
assertSame(
'<script>a</script>&<i>b</i>', $op->getPageTitle() );
713 $this->
getMsgText( $op,
'pagetitle',
'<script>a</script>&b' ),
720 $op->setPageTitle( $op->msg(
'mainpage' )->inContentLanguage() );
721 $this->
assertSame( $text, $op->getPageTitle() );
731 $this->
assertSame(
'My test page', $op->getTitle()->getPrefixedText() );
733 $op->setTitle( Title::newFromText(
'Another test page' ) );
735 $this->
assertSame(
'Another test page', $op->getTitle()->getPrefixedText() );
749 $op->addSubtitle(
'<b>foo</b>' );
751 $this->
assertSame(
'<b>foo</b>', $op->getSubtitle() );
753 $op->addSubtitle( $op->msg(
'mainpage' )->inContentLanguage() );
756 "<b>foo</b><br />\n\t\t\t\t" . $this->
getMsgText( $op,
'mainpage' ),
760 $op->setSubtitle(
'There can be only one' );
762 $this->
assertSame(
'There can be only one', $op->getSubtitle() );
764 $op->clearSubtitle();
781 $title = Title::newFromText(
$titles[0] );
785 $this->
editPage(
'Page 2',
'#REDIRECT [[Page 1]]' );
787 $str = OutputPage::buildBacklinkSubtitle( $title,
$query )->text();
789 foreach ( $contains as $substr ) {
793 foreach ( $notContains as $substr ) {
806 $this->
editPage(
'Page 2',
'#REDIRECT [[Page 1]]' );
809 foreach (
$titles as $i => $unused ) {
810 $op->addBacklinkSubtitle( Title::newFromText(
$titles[$i] ),
$queries[$i] );
813 $str = $op->getSubtitle();
815 foreach ( $contains as $substr ) {
819 foreach ( $notContains as $substr ) {
830 [
'redirect',
'Page 2' ],
840 [ [
'action' =>
'edit' ] ],
845 [
'Page 1',
'Page 2' ],
847 [
'Page 1',
'Page 2',
"<br />\n\t\t\t\t" ],
895 $op->addParserOutputMetadata( $pOut1 );
896 $this->
assertTrue( $op->showNewSectionLink() );
899 $op->addParserOutput( $pOut2 );
911 $this->
assertFalse( $op->forceHideNewSectionLink() );
914 $op->addParserOutputMetadata( $pOut1 );
915 $this->
assertTrue( $op->forceHideNewSectionLink() );
918 $op->addParserOutput( $pOut2 );
919 $this->
assertFalse( $op->forceHideNewSectionLink() );
930 $op->setSyndicated();
933 $op->setSyndicated(
false );
939 $op->setSyndicated();
951 $this->
assertSame( [], $op->getSyndicationLinks() );
953 $op->addFeedLink(
'not a supported format',
'abc' );
955 $this->
assertSame( [], $op->getSyndicationLinks() );
957 $feedTypes = $op->getConfig()->get(
'AdvertisedFeedTypes' );
959 $op->addFeedLink( $feedTypes[0],
'def' );
961 $this->
assertSame( [ $feedTypes[0] =>
'def' ], $op->getSyndicationLinks() );
963 $op->setFeedAppendQuery(
false );
965 foreach ( $feedTypes as
$type ) {
966 $expected[
$type] = $op->getTitle()->getLocalURL(
"feed=$type" );
968 $this->
assertSame( $expected, $op->getSyndicationLinks() );
970 $op->setFeedAppendQuery(
'apples=oranges' );
971 foreach ( $feedTypes as
$type ) {
972 $expected[
$type] = $op->getTitle()->getLocalURL(
"feed=$type&apples=oranges" );
974 $this->
assertSame( $expected, $op->getSyndicationLinks() );
977 $this->
assertSame( [], $op->getSyndicationLinks() );
979 $op->addFeedLink( $feedTypes[0],
'def' );
981 $this->
assertSame( [], $op->getSyndicationLinks() );
995 $op->setArticleRelated(
false );
999 $op->setArticleFlag(
true );
1001 $this->
assertTrue( $op->isArticleRelated() );
1003 $op->setArticleFlag(
false );
1005 $this->
assertTrue( $op->isArticleRelated() );
1007 $op->setArticleFlag(
true );
1008 $op->setArticleRelated(
false );
1022 $this->
assertSame( [], $op->getLanguageLinks() );
1024 $op->addLanguageLinks( [
'fr:A',
'it:B' ] );
1025 $this->
assertSame( [
'fr:A',
'it:B' ], $op->getLanguageLinks() );
1027 $op->addLanguageLinks( [
'de:C',
'es:D' ] );
1028 $this->
assertSame( [
'fr:A',
'it:B',
'de:C',
'es:D' ], $op->getLanguageLinks() );
1030 $op->setLanguageLinks( [
'pt:E' ] );
1031 $this->
assertSame( [
'pt:E' ], $op->getLanguageLinks() );
1034 $op->addParserOutputMetadata( $pOut1 );
1035 $this->
assertSame( [
'pt:E',
'he:F',
'ar:G' ], $op->getLanguageLinks() );
1038 $op->addParserOutput( $pOut2 );
1039 $this->
assertSame( [
'pt:E',
'he:F',
'ar:G',
'pt:H' ], $op->getLanguageLinks() );
1060 array $args,
array $fakeResults, callable $variantLinkCallback =
null,
1068 $op->addCategoryLinks(
$args );
1082 array $args,
array $fakeResults, callable $variantLinkCallback =
null,
1085 if ( count(
$args ) <= 1 ) {
1096 foreach (
$args as $key => $val ) {
1097 $op->addCategoryLinks( [ $key => $val ] );
1112 array $args,
array $fakeResults, callable $variantLinkCallback =
null,
1120 $op->setCategoryLinks( [
'Initial page' =>
'Initial page' ] );
1121 $op->setCategoryLinks(
$args );
1124 $expectedNormalCats =
array_merge( [
'Initial page' ], $expectedNormal );
1125 $expectedCats =
array_merge( $expectedHidden, $expectedNormalCats );
1140 array $args,
array $fakeResults, callable $variantLinkCallback =
null,
1154 $method = [
'addParserOutputMetadata',
'addParserOutput' ][$idx % 2];
1155 $op->$method( $stubPO );
1167 if ( !$expected ||
isset( $expected[0] ) ) {
1170 return $expected[$key] ?? $expected[
'default'];
1174 array $fakeResults, callable $variantLinkCallback =
null
1180 ->setMethods( [
'addCategoryLinksToLBAndGetResult',
'getTitle' ] )
1183 $title = Title::newFromText(
'My test page' );
1184 $op->expects( $this->
any() )
1185 ->method(
'getTitle' )
1188 $op->expects( $this->
any() )
1189 ->method(
'addCategoryLinksToLBAndGetResult' )
1192 foreach ( $categories as $category => $unused ) {
1193 if (
isset( $fakeResults[$category] ) ) {
1194 $return[] = $fakeResults[$category];
1197 return new FakeResultWrapper( $return );
1200 if ( $variantLinkCallback ) {
1202 ->setConstructorArgs( [
'en' ] )
1203 ->setMethods( [
'findVariantLink' ] )
1205 $mockContLang->expects( $this->
any() )
1206 ->method(
'findVariantLink' )
1211 $this->
assertSame( [], $op->getCategories() );
1218 $this->
assertSame( $expectedNormal, $op->getCategories(
'normal' ) );
1219 $this->
assertSame( $expectedHidden, $op->getCategories(
'hidden' ) );
1223 $catLinks = $op->getCategoryLinks();
1224 $this->
assertSame( (
bool)$expectedNormal + (
bool)$expectedHidden, count( $catLinks ) );
1225 if ( $expectedNormal ) {
1226 $this->
assertSame( count( $expectedNormal ), count( $catLinks[
'normal'] ) );
1228 if ( $expectedHidden ) {
1229 $this->
assertSame( count( $expectedHidden ), count( $catLinks[
'hidden'] ) );
1232 foreach ( $expectedNormal as $i => $name ) {
1235 foreach ( $expectedHidden as $i => $name ) {
1242 'No categories' => [ [], [],
null, [], [] ],
1244 [
'Test1' =>
'Some sortkey',
'Test2' =>
'A different sortkey' ],
1245 [
'Test1' => (
object)[
'pp_value' => 1,
'page_title' =>
'Test1' ],
1246 'Test2' => (
object)[
'page_title' =>
'Test2' ] ],
1251 'Invalid title' => [
1252 [
'[' =>
'[',
'Test' =>
'Test' ],
1253 [
'Test' => (
object)[
'page_title' =>
'Test' ] ],
1259 [
'Test' =>
'Test',
'Estay' =>
'Estay' ],
1260 [
'Test' => (
object)[
'page_title' =>
'Test' ] ],
1262 if (
$link ===
'Estay' ) {
1269 [
'onebyone' => [
'Test',
'Test' ],
'default' => [
'Test' ] ],
1280 'Invalid category type given: hiddne' );
1282 $op = $this->newInstance();
1283 $op->getCategories(
'hiddne' );
1296 $op = $this->newInstance();
1297 $this->
assertSame( [], $op->getIndicators() );
1299 $op->setIndicators( [] );
1300 $this->
assertSame( [], $op->getIndicators() );
1303 $op->setIndicators( [
'b' =>
'x',
'a' =>
'y' ] );
1304 $this->
assertSame( [
'a' =>
'y',
'b' =>
'x' ], $op->getIndicators() );
1307 $op->setIndicators( [
'c' =>
'z',
'a' =>
'w' ] );
1308 $this->
assertSame( [
'a' =>
'w',
'b' =>
'x',
'c' =>
'z' ], $op->getIndicators() );
1311 $pOut1 = $this->createParserOutputStub(
'getIndicators', [
'c' =>
'u',
'd' =>
'v' ] );
1312 $op->addParserOutputMetadata( $pOut1 );
1313 $this->
assertSame( [
'a' =>
'w',
'b' =>
'x',
'c' =>
'u',
'd' =>
'v' ],
1314 $op->getIndicators() );
1317 $pOut2 = $this->createParserOutputStub(
'getIndicators', [
'a' =>
'!!!' ] );
1318 $op->addParserOutput( $pOut2 );
1319 $this->
assertSame( [
'a' =>
'!!!',
'b' =>
'x',
'c' =>
'u',
'd' =>
'v' ],
1320 $op->getIndicators() );
1328 $op = $this->newInstance();
1330 $op->addHelpLink(
'Manual:PHP unit testing' );
1331 $indicators = $op->getIndicators();
1333 $this->
assertContains(
'Manual:PHP_unit_testing', $indicators[
'mw-helplink'] );
1335 $op->addHelpLink(
'https://phpunit.de',
true );
1336 $indicators = $op->getIndicators();
1338 $this->
assertContains(
'https://phpunit.de', $indicators[
'mw-helplink'] );
1351 $op = $this->newInstance();
1354 $op->addHTML(
'a' );
1357 $op->addHTML(
'b' );
1360 $op->prependHTML(
'c' );
1363 $op->addElement(
'p', [
'id' =>
'foo' ],
'd' );
1364 $this->
assertSame(
'cab<p id="foo">d</p>', $op->getHTML() );
1376 $op = $this->newInstance();
1378 $this->
assertNull( $op->setRevisionId( $newVal ) );
1379 $this->
assertSame( $expected, $op->getRevisionId() );
1380 $this->
assertSame( $expected, $op->setRevisionId(
null ) );
1391 [
'32% finished', 32 ],
1401 $op = $this->newInstance();
1402 $this->
assertNull( $op->getRevisionTimestamp() );
1404 $this->
assertNull( $op->setRevisionTimestamp(
'abc' ) );
1405 $this->
assertSame(
'abc', $op->getRevisionTimestamp() );
1406 $this->
assertSame(
'abc', $op->setRevisionTimestamp(
null ) );
1407 $this->
assertNull( $op->getRevisionTimestamp() );
1415 $op = $this->newInstance();
1418 $stubFile = $this->
createMock( File::class );
1419 $stubFile->method(
'exists' )->willReturn(
true );
1420 $stubFile->method(
'getTimestamp' )->willReturn(
'12211221123321' );
1421 $stubFile->method(
'getSha1' )->willReturn(
'bf3ffa7047dc080f5855377a4f83cd18887e3b05' );
1423 $op->setFileVersion( $stubFile );
1426 [
'time' =>
'12211221123321',
'sha1' =>
'bf3ffa7047dc080f5855377a4f83cd18887e3b05' ],
1427 $op->getFileVersion()
1430 $stubMissingFile = $this->
createMock( File::class );
1431 $stubMissingFile->method(
'exists' )->willReturn(
false );
1433 $op->setFileVersion( $stubMissingFile );
1436 $op->setFileVersion( $stubFile );
1439 $op->setFileVersion(
null );
1448 if ( count(
$args ) === 0 ) {
1451 $retVals =
$args[0];
1455 $pOut = $this->
getMock( ParserOutput::class );
1456 foreach ( $retVals as $method => $retVal ) {
1457 $pOut->method( $method )->willReturn( $retVal );
1460 $arrayReturningMethods = [
1462 'getFileSearchOptions',
1470 foreach ( $arrayReturningMethods as $method ) {
1471 $pOut->method( $method )->willReturn( [] );
1483 $op = $this->newInstance();
1484 $this->
assertSame( [], $op->getTemplateIds() );
1487 $stubPOEmpty = $this->createParserOutputStub();
1488 $op->addParserOutputMetadata( $stubPOEmpty );
1489 $this->
assertSame( [], $op->getTemplateIds() );
1493 NS_MAIN => [
'A' => 3,
'B' => 17 ],
1498 $stubPO1 = $this->createParserOutputStub(
'getTemplateIds', $ids );
1500 $op->addParserOutputMetadata( $stubPO1 );
1501 $this->
assertSame( $ids, $op->getTemplateIds() );
1504 $stubPO2 = $this->createParserOutputStub(
'getTemplateIds', [
1510 NS_MAIN => [
'E' => 1234,
'A' => 3,
'B' => 17 ],
1516 $op->addParserOutput( $stubPO2 );
1517 $this->
assertSame( $finalIds, $op->getTemplateIds() );
1520 $op->addParserOutputMetadata( $stubPOEmpty );
1521 $this->
assertSame( $finalIds, $op->getTemplateIds() );
1530 $op = $this->newInstance();
1531 $this->
assertSame( [], $op->getFileSearchOptions() );
1534 $stubPOEmpty = $this->createParserOutputStub();
1536 $op->addParserOutputMetadata( $stubPOEmpty );
1537 $this->
assertSame( [], $op->getFileSearchOptions() );
1541 'A' => [
'time' =>
null,
'sha1' =>
'' ],
1543 'time' =>
'12211221123321',
1544 'sha1' =>
'bf3ffa7047dc080f5855377a4f83cd18887e3b05',
1548 $stubPO1 = $this->createParserOutputStub(
'getFileSearchOptions', $files1 );
1550 $op->addParserOutput( $stubPO1 );
1551 $this->
assertSame( $files1, $op->getFileSearchOptions() );
1555 'C' => [
'time' =>
null,
'sha1' =>
'' ],
1556 'B' => [
'time' =>
null,
'sha1' =>
'' ],
1559 $stubPO2 = $this->createParserOutputStub(
'getFileSearchOptions', $files2 );
1561 $op->addParserOutputMetadata( $stubPO2 );
1565 $op->addParserOutput( $stubPOEmpty );
1582 $op = $this->newInstance();
1585 $this->hideDeprecated(
'OutputPage::addWikiText' );
1586 $this->hideDeprecated(
'OutputPage::addWikiTextTitle' );
1587 $this->hideDeprecated(
'OutputPage::addWikiTextWithTitle' );
1588 $this->hideDeprecated(
'OutputPage::addWikiTextTidy' );
1589 $this->hideDeprecated(
'OutputPage::addWikiTextTitleTidy' );
1590 $this->hideDeprecated(
'disabling tidy' );
1594 [
'addWikiTextWithTitle',
'addWikiTextTitleTidy',
'addWikiTextTitle' ]
1595 ) && count(
$args ) >= 2 &&
$args[1] ===
null ) {
1597 $args[1] = $op->getTitle();
1601 [
'addWikiTextAsInterface',
'addWikiTextAsContent' ]
1602 ) && count(
$args ) >= 3 &&
$args[2] ===
null ) {
1604 $args[2] = $op->getTitle();
1607 $op->$method( ...
$args );
1608 $this->
assertSame( $expected, $op->getHTML() );
1615 'Simple wikitext' => [
1617 "<p><b>Bold</b>\n</p>",
1618 ],
'List at start' => [
1620 "<ul><li>List</li></ul>\n",
1621 ],
'List not at start' => [
1622 [
'* Not a list',
false ],
1624 ],
'Non-interface' => [
1625 [
"'''Bold'''",
true,
false ],
1626 "<p><b>Bold</b>\n</p>",
1627 ],
'No section edit links' => [
1629 "<h2><span class=\"mw-headline\" id=\"Title\">Title</span></h2>",
1632 'addWikiTextWithTitle' => [
1634 'With title at start' => [
1635 [
'* {{PAGENAME}}', Title::newFromText(
'Talk:Some page' ) ],
1636 "<ul><li>Some page</li></ul>\n",
1637 ],
'With title at start' => [
1638 [
'* {{PAGENAME}}', Title::newFromText(
'Talk:Some page' ),
false ],
1642 'addWikiTextAsInterface' => [
1644 'Simple wikitext' => [
1646 "<p><b>Bold</b>\n</p>",
1647 ],
'Untidy wikitext' => [
1649 "<p><b>Bold\n</b></p>",
1650 ],
'List at start' => [
1652 "<ul><li>List</li></ul>\n",
1653 ],
'List not at start' => [
1654 [
'* Not a list',
false ],
1655 '<p>* Not a list</p>',
1656 ],
'No section edit links' => [
1658 "<h2><span class=\"mw-headline\" id=\"Title\">Title</span></h2>",
1659 ],
'With title at start' => [
1660 [
'* {{PAGENAME}}',
true, Title::newFromText(
'Talk:Some page' ) ],
1661 "<ul><li>Some page</li></ul>\n",
1662 ],
'With title at start' => [
1663 [
'* {{PAGENAME}}',
false, Title::newFromText(
'Talk:Some page' ),
false ],
1664 "<p>* Some page</p>",
1665 ],
'Untidy input' => [
1666 [
'<b>{{PAGENAME}}',
true, Title::newFromText(
'Talk:Some page' ) ],
1667 "<p><b>Some page\n</b></p>",
1670 'addWikiTextAsContent' => [
1672 'SpecialNewimages' => [
1673 [
"<p lang='en' dir='ltr'>\nMy message" ],
1674 '<p lang="en" dir="ltr">' .
"\nMy message</p>"
1675 ],
'List at start' => [
1677 "<ul><li>List</li></ul>",
1678 ],
'List not at start' => [
1679 [
'* <b>Not a list',
false ],
1680 '<p>* <b>Not a list</b></p>',
1681 ],
'With title at start' => [
1682 [
'* {{PAGENAME}}',
true, Title::newFromText(
'Talk:Some page' ) ],
1683 "<ul><li>Some page</li></ul>\n",
1684 ],
'With title at start' => [
1685 [
'* {{PAGENAME}}',
false, Title::newFromText(
'Talk:Some page' ),
false ],
1686 "<p>* Some page</p>",
1688 [
"<div class='mw-editintro'>{{PAGENAME}}",
true, Title::newFromText(
'Talk:Some page' ) ],
1689 '<div class="mw-editintro">' .
"Some page</div>"
1692 'wrapWikiTextAsInterface' => [
1694 [
'wrapperClass',
'text' ],
1695 "<div class=\"wrapperClass\"><p>text\n</p></div>"
1696 ],
'Spurious </div>' => [
1697 [
'wrapperClass',
'text</div><div>more' ],
1698 "<div class=\"wrapperClass\"><p>text</p><div>more</div></div>"
1699 ],
'Extra newlines would break <p> wrappers' => [
1700 [
'two classes',
"1\n\n2\n\n3" ],
1701 "<div class=\"two classes\"><p>1\n</p><p>2\n</p><p>3\n</p></div>"
1702 ],
'Other unclosed tags' => [
1703 [
'error',
'a<b>c<i>d' ],
1704 "<div class=\"error\"><p>a<b>c<i>d\n</i></b></p></div>"
1710 foreach ( $tests[
'addWikiText'] as $key => $val ) {
1711 $args = [ $val[0][0],
null, $val[0][1] ??
true,
false, $val[0][2] ??
true ];
1712 $tests[
'addWikiTextTitle'][
"$key (addWikiTextTitle)"] =
1715 foreach ( $tests[
'addWikiTextWithTitle'] as $key => $val ) {
1716 $args = [ $val[0][0], $val[0][1], $val[0][2] ??
true ];
1717 $tests[
'addWikiTextTitle'][
"$key (addWikiTextTitle)"] =
1720 foreach ( $tests[
'addWikiTextAsInterface'] as $key => $val ) {
1721 $args = [ $val[0][0], $val[0][2] ??
null, $val[0][1] ??
true,
true,
true ];
1722 $tests[
'addWikiTextTitle'][
"$key (addWikiTextTitle)"] =
1725 foreach ( $tests[
'addWikiTextAsContent'] as $key => $val ) {
1726 $args = [ $val[0][0], $val[0][2] ??
null, $val[0][1] ??
true,
true,
false ];
1727 $tests[
'addWikiTextTitle'][
"$key (addWikiTextTitle)"] =
1732 foreach ( $tests[
'addWikiTextAsContent'] as $key => $val ) {
1733 if ( count( $val[0] ) > 2 ) {
1734 $args = [ $val[0][0], $val[0][2], $val[0][1] ??
true ];
1735 $tests[
'addWikiTextTitleTidy'][
"$key (addWikiTextTitleTidy)"] =
1738 $args = [ $val[0][0], $val[0][1] ??
true ];
1739 $tests[
'addWikiTextTidy'][
"$key (addWikiTextTidy)"] =
1746 foreach ( $tests as $key => $subarray ) {
1747 foreach ( $subarray as $subkey => $val ) {
1760 $this->hideDeprecated(
'OutputPage::addWikiText' );
1763 $op = $this->newInstance( [],
null,
'notitle' );
1764 $op->addWikiText(
'a' );
1773 $op = $this->newInstance( [],
null,
'notitle' );
1774 $op->addWikiTextAsInterface(
'a' );
1783 $op = $this->newInstance( [],
null,
'notitle' );
1784 $op->addWikiTextAsContent(
'a' );
1792 $this->
assertSame(
'(a)', $msg->rawParams(
'a' )->plain() );
1794 $op = $this->newInstance();
1796 $op->addWikiMsg(
'parentheses',
"<b>a" );
1798 $this->
assertSame(
"<p>(<b>a)\n</b></p>", $op->getHTML() );
1806 $this->
assertSame(
'(a)', $msg->rawParams(
'a' )->plain() );
1808 $op = $this->newInstance();
1810 $op->wrapWikiMsg(
'[$1]', [
'parentheses',
"<b>a" ] );
1812 $this->
assertSame(
"<p>[(<b>a)]\n</b></p>", $op->getHTML() );
1820 $op = $this->newInstance();
1823 $stubPO1 = $this->createParserOutputStub(
'getNoGallery',
true );
1824 $op->addParserOutputMetadata( $stubPO1 );
1827 $stubPO2 = $this->createParserOutputStub(
'getNoGallery',
false );
1828 $op->addParserOutput( $stubPO2 );
1838 $op = $this->newInstance();
1839 $pOut = $this->createParserOutputStub(
'getOutputHooks', [
1840 [
'myhook',
'banana' ],
1841 [
'yourhook',
'kumquat' ],
1842 [
'theirhook',
'hippopotamus' ],
1845 self::$parserOutputHookCalled = [];
1847 $this->setMwGlobals(
'wgParserOutputHooks', [
1849 use ( $op, $pOut ) {
1853 self::$parserOutputHookCalled[] =
'closure';
1855 'yourhook' => [
$this,
'parserOutputHookCallback' ],
1856 'theirhook' => [
__CLASS__,
'parserOutputHookCallbackStatic' ],
1857 'uncalled' =>
function () {
1862 $op->addParserOutputMetadata( $pOut );
1864 $this->
assertSame( [
'closure',
'callback',
'static' ], self::$parserOutputHookCalled );
1872 self::$parserOutputHookCalled[] =
'callback';
1881 self::$parserOutputHookCalled[] =
'static';
1897 $op = $this->newInstance();
1900 $pOut = $this->createParserOutputStub(
'getText',
'<some text>' );
1902 $op->addParserOutputMetadata( $pOut );
1905 $op->addParserOutputText( $pOut );
1906 $this->
assertSame(
'<some text>', $op->getHTML() );
1913 $op = $this->newInstance();
1917 $pOut = $this->createParserOutputStub( [
1918 'getText' =>
'<some text>',
1919 'getNewSection' =>
true,
1922 $op->addParserOutput( $pOut );
1923 $this->
assertSame(
'<some text>', $op->getHTML() );
1924 $this->
assertTrue( $op->showNewSectionLink() );
1932 $template->method(
'getHTML' )->willReturn(
'<abc>&def;' );
1934 $op = $this->newInstance();
1937 $this->
assertSame(
'<abc>&def;', $op->getHTML() );
1948 $this->hideDeprecated(
'OutputPage::parse' );
1949 $op = $this->newInstance();
1950 $this->
assertSame( $expectedHTML, $op->parse( ...$args ) );
1958 if ( count(
$args ) > 3 ) {
1963 $this->hideDeprecated(
'OutputPage::parseInline' );
1964 $op = $this->newInstance();
1965 $this->
assertSame( $expectedHTMLInline ?? $expectedHTML, $op->parseInline( ...$args ) );
1970 'List at start of line (content)' => [
1971 [
'* List',
true,
false ],
1972 "<div class=\"mw-parser-output\"><ul><li>List</li></ul></div>",
1973 "<ul><li>List</li></ul>",
1975 'List at start of line (interface)' => [
1976 [
'* List',
true,
true ],
1977 "<ul><li>List</li></ul>",
1979 'List not at start (content)' => [
1980 [
"* ''Not'' list",
false,
false ],
1981 '<div class="mw-parser-output">* <i>Not</i> list</div>',
1982 '* <i>Not</i> list',
1984 'List not at start (interface)' => [
1985 [
"* ''Not'' list",
false,
true ],
1986 '* <i>Not</i> list',
1988 'Interface message' => [
1989 [
"''Italic''",
true,
true ],
1990 "<p><i>Italic</i>\n</p>",
1993 'formatnum (content)' => [
1994 [
'{{formatnum:123456.789}}',
true,
false ],
1995 "<div class=\"mw-parser-output\"><p>123,456.789\n</p></div>",
1998 'formatnum (interface)' => [
1999 [
'{{formatnum:123456.789}}',
true,
true ],
2000 "<p>123,456.789\n</p>",
2003 'Language (content)' => [
2004 [
'{{formatnum:123456.789}}',
true,
false, Language::factory(
'is' ) ],
2005 "<div class=\"mw-parser-output\"><p>123.456,789\n</p></div>",
2007 'Language (interface)' => [
2008 [
'{{formatnum:123456.789}}',
true,
true, Language::factory(
'is' ) ],
2009 "<p>123.456,789\n</p>",
2012 'No section edit links' => [
2014 '<div class="mw-parser-output"><h2><span class="mw-headline" id="Header">' .
2015 "Header</span></h2></div>",
2016 '<h2><span class="mw-headline" id="Header">Header</span></h2>',
2029 array $args, $expectedHTML, $expectedHTMLInline =
null
2031 $op = $this->newInstance();
2032 $this->
assertSame( $expectedHTML, $op->parseAsContent( ...$args ) );
2043 array $args, $expectedHTML, $expectedHTMLInline =
null
2045 $op = $this->newInstance();
2046 $this->
assertSame( $expectedHTML, $op->parseAsInterface( ...$args ) );
2054 array $args, $expectedHTML, $expectedHTMLInline =
null
2056 $op = $this->newInstance();
2058 $expectedHTMLInline ?? $expectedHTML,
2059 $op->parseInlineAsInterface( ...$args )
2065 'List at start of line' => [
2067 "<ul><li>List</li></ul>",
2069 'List not at start' => [
2070 [
"* ''Not'' list",
false ],
2071 '<p>* <i>Not</i> list</p>',
2072 '* <i>Not</i> list',
2075 [
"''Italic''",
true ],
2076 "<p><i>Italic</i>\n</p>",
2080 [
'{{formatnum:123456.789}}',
true ],
2081 "<p>123,456.789\n</p>",
2084 'No section edit links' => [
2086 '<h2><span class="mw-headline" id="Header">Header</span></h2>',
2095 $this->hideDeprecated(
'OutputPage::parse' );
2096 $this->
setExpectedException( MWException::class,
'Empty $mTitle in OutputPage::parseInternal' );
2097 $op = $this->newInstance( [],
null,
'notitle' );
2105 $this->hideDeprecated(
'OutputPage::parseInline' );
2106 $this->
setExpectedException( MWException::class,
'Empty $mTitle in OutputPage::parseInternal' );
2107 $op = $this->newInstance( [],
null,
'notitle' );
2108 $op->parseInline(
'' );
2115 $this->
setExpectedException( MWException::class,
'Empty $mTitle in OutputPage::parseInternal' );
2116 $op = $this->newInstance( [],
null,
'notitle' );
2117 $op->parseAsContent(
'' );
2124 $this->
setExpectedException( MWException::class,
'Empty $mTitle in OutputPage::parseInternal' );
2125 $op = $this->newInstance( [],
null,
'notitle' );
2126 $op->parseAsInterface(
'' );
2133 $this->
setExpectedException( MWException::class,
'Empty $mTitle in OutputPage::parseInternal' );
2134 $op = $this->newInstance( [],
null,
'notitle' );
2135 $op->parseInlineAsInterface(
'' );
2143 $op = $this->newInstance();
2144 $wrapper = TestingAccessWrapper::newFromObject( $op );
2145 $this->
assertSame( 0, $wrapper->mCdnMaxage );
2147 $op->setCdnMaxage( -1 );
2148 $this->
assertSame( -1, $wrapper->mCdnMaxage );
2150 $op->setCdnMaxage( 120 );
2151 $this->
assertSame( 120, $wrapper->mCdnMaxage );
2153 $op->setCdnMaxage( 60 );
2154 $this->
assertSame( 60, $wrapper->mCdnMaxage );
2156 $op->setCdnMaxage( 180 );
2157 $this->
assertSame( 180, $wrapper->mCdnMaxage );
2159 $op->lowerCdnMaxage( 240 );
2160 $this->
assertSame( 180, $wrapper->mCdnMaxage );
2162 $op->setCdnMaxage( 300 );
2163 $this->
assertSame( 240, $wrapper->mCdnMaxage );
2165 $op->lowerCdnMaxage( 120 );
2166 $this->
assertSame( 120, $wrapper->mCdnMaxage );
2168 $op->setCdnMaxage( 180 );
2169 $this->
assertSame( 120, $wrapper->mCdnMaxage );
2171 $op->setCdnMaxage( 60 );
2172 $this->
assertSame( 60, $wrapper->mCdnMaxage );
2174 $op->setCdnMaxage( 240 );
2175 $this->
assertSame( 120, $wrapper->mCdnMaxage );
2191 MWTimestamp::setFakeTime( self::$fakeTime );
2193 $op = $this->newInstance();
2196 $initial =
$options[
'initialMaxage'] ?? 86400;
2197 $op->setCdnMaxage( $initial );
2199 $op->adaptCdnTTL( ...
$args );
2201 MWTimestamp::setFakeTime(
false );
2204 $wrapper = TestingAccessWrapper::newFromObject( $op );
2207 if (
$args[0] ===
null ||
$args[0] ===
false ) {
2208 $this->
assertSame( $initial, $wrapper->mCdnMaxage,
'member value' );
2209 $op->setCdnMaxage( $expected + 1 );
2210 $this->
assertSame( $expected + 1, $wrapper->mCdnMaxage,
'member value after new set' );
2214 $this->
assertSame( $expected, $wrapper->mCdnMaxageLimit,
'limit value' );
2216 if ( $initial >= $expected ) {
2217 $this->
assertSame( $expected, $wrapper->mCdnMaxage,
'member value' );
2219 $this->
assertSame( $initial, $wrapper->mCdnMaxage,
'member value' );
2222 $op->setCdnMaxage( $expected + 1 );
2223 $this->
assertSame( $expected, $wrapper->mCdnMaxage,
'member value after new set' );
2229 self::$fakeTime =
$now;
2231 'Five minutes ago' => [ [ $now - 300 ], 270 ],
2232 'Now' => [ [ +0 ], IExpiringStore::TTL_MINUTE ],
2233 'Five minutes from now' => [ [ $now + 300 ], IExpiringStore::TTL_MINUTE ],
2234 'Five minutes ago, initial maxage four minutes' =>
2235 [ [ $now - 300 ], 270, [
'initialMaxage' => 240 ] ],
2236 'A very long time ago' => [ [ $now - 1000000000 ],
$wgSquidMaxage ],
2237 'Initial maxage zero' => [ [ $now - 300 ], 270, [
'initialMaxage' => 0 ] ],
2239 'false' => [ [
false ], IExpiringStore::TTL_MINUTE ],
2240 'null' => [ [
null ], IExpiringStore::TTL_MINUTE ],
2241 "'0'" => [ [
'0' ], IExpiringStore::TTL_MINUTE ],
2242 'Empty string' => [ [
'' ], IExpiringStore::TTL_MINUTE ],
2247 'Now, minTTL 0' => [ [
$now, 0 ], IExpiringStore::TTL_MINUTE ],
2248 'Now, minTTL 0.000001' => [ [
$now, 0.000001 ], 0 ],
2249 'A very long time ago, maxTTL even longer' =>
2250 [ [ $now - 1000000000, 0, 1000000001 ], 900000000 ],
2260 $op = $this->newInstance();
2263 $this->
assertSame(
true, $op->enableClientCache(
null ) );
2265 $this->
assertSame(
true, $op->enableClientCache(
null ) );
2268 $this->
assertSame(
true, $op->enableClientCache(
false ) );
2269 $this->
assertSame(
false, $op->enableClientCache(
null ) );
2271 $this->
assertSame(
false, $op->enableClientCache(
null ) );
2274 $pOutCacheable = $this->createParserOutputStub(
'isCacheable',
true );
2275 $op->addParserOutputMetadata( $pOutCacheable );
2276 $this->
assertSame(
false, $op->enableClientCache(
null ) );
2279 $this->
assertSame(
false, $op->enableClientCache(
true ) );
2280 $this->
assertSame(
true, $op->enableClientCache(
null ) );
2283 $pOutUncacheable = $this->createParserOutputStub(
'isCacheable',
false );
2284 $op->addParserOutput( $pOutUncacheable );
2285 $this->
assertSame(
false, $op->enableClientCache(
null ) );
2293 $op = $this->newInstance();
2295 $expectedCookies = [
2297 "{$prefix}LoggedOut",
2298 "{$prefix}_session",
2305 TestingAccessWrapper::newFromClass( OutputPage::class )->cacheVaryCookies =
null;
2307 $this->setMwGlobals(
'wgCacheVaryCookies', [
'cookie1' ] );
2308 $this->setTemporaryHook(
'GetCacheVaryCookies',
2309 function ( $innerOP, &$cookies ) use ( $op, $expectedCookies ) {
2311 $cookies[] =
'cookie2';
2312 $this->
assertSame( $expectedCookies, $cookies );
2316 $this->
assertSame( $expectedCookies, $op->getCacheVaryCookies() );
2324 $op = $this->newInstance( [],
$request );
2327 $this->
assertFalse( $op->haveCacheVaryCookies() );
2330 $request->setCookie(
'Token',
'' );
2331 $this->
assertFalse( $op->haveCacheVaryCookies() );
2334 $request->setCookie(
'Token',
'123' );
2335 $this->
assertTrue( $op->haveCacheVaryCookies() );
2354 ->setMethods( [
'getCacheVaryCookies' ] )
2356 $op->expects( $this->
any() )
2357 ->method(
'getCacheVaryCookies' )
2359 TestingAccessWrapper::newFromObject( $op )->mVaryHeader = [];
2361 $this->hideDeprecated(
'$wgUseKeyHeader' );
2362 foreach ( $calls as $call ) {
2363 $op->addVaryHeader( ...$call );
2365 $this->
assertEquals( $vary, $op->getVaryHeader(),
'Vary:' );
2366 $this->
assertEquals( $key, $op->getKeyHeader(),
'Key:' );
2378 'Single header' => [
2386 'Non-unique headers' => [
2389 [
'Accept-Language' ],
2393 'Vary: Cookie, Accept-Language',
2394 'Key: Cookie,Accept-Language',
2396 'Two headers with single options' => [
2398 [
'Cookie', [
'param=phpsessid' ] ],
2399 [
'Accept-Language', [
'substr=en' ] ],
2402 'Vary: Cookie, Accept-Language',
2403 'Key: Cookie;param=phpsessid,Accept-Language;substr=en',
2405 'One header with multiple options' => [
2407 [
'Cookie', [
'param=phpsessid',
'param=userId' ] ],
2411 'Key: Cookie;param=phpsessid;param=userId',
2413 'Duplicate option' => [
2415 [
'Cookie', [
'param=phpsessid' ] ],
2416 [
'Cookie', [
'param=phpsessid' ] ],
2417 [
'Accept-Language', [
'substr=en',
'substr=en' ] ],
2420 'Vary: Cookie, Accept-Language',
2421 'Key: Cookie;param=phpsessid,Accept-Language;substr=en',
2423 'Same header, different options' => [
2425 [
'Cookie', [
'param=phpsessid' ] ],
2426 [
'Cookie', [
'param=userId' ] ],
2430 'Key: Cookie;param=phpsessid;param=userId',
2432 'No header, vary cookies' => [
2434 [
'cookie1',
'cookie2' ],
2436 'Key: Cookie;param=cookie1;param=cookie2',
2438 'Cookie header with option plus vary cookies' => [
2440 [
'Cookie', [
'param=cookie1' ] ],
2442 [
'cookie2',
'cookie3' ],
2444 'Key: Cookie;param=cookie1;param=cookie2;param=cookie3',
2446 'Non-cookie header plus vary cookies' => [
2448 [
'Accept-Language' ],
2451 'Vary: Accept-Language, Cookie',
2452 'Key: Accept-Language,Cookie;param=cookie',
2454 'Cookie and non-cookie headers plus vary cookies' => [
2456 [
'Cookie', [
'param=cookie1' ] ],
2457 [
'Accept-Language' ],
2460 'Vary: Cookie, Accept-Language',
2461 'Key: Cookie;param=cookie1;param=cookie2,Accept-Language',
2470 $op = $this->newInstance();
2471 $this->
assertSame(
'Vary: Accept-Encoding, Cookie', $op->getVaryHeader() );
2481 $op = $this->newInstance();
2483 foreach ( $headers as
$header ) {
2484 $op->addLinkHeader(
$header );
2497 [
'<https://foo/bar.jpg>;rel=preload;as=image' ],
2498 'Link: <https://foo/bar.jpg>;rel=preload;as=image',
2502 '<https://foo/bar.jpg>;rel=preload;as=image',
2503 '<https://foo/baz.jpg>;rel=preload;as=image'
2505 'Link: <https://foo/bar.jpg>;rel=preload;as=image,<https://foo/baz.jpg>;' .
2506 'rel=preload;as=image',
2523 $mockLang = $this->
getMock( Language::class );
2526 $mockLang->expects( $this->never() )->method( $this->
anything() );
2528 $mockLang->method(
'hasVariants' )->willReturn( count( $variants ) > 1 );
2529 $mockLang->method(
'getVariants' )->willReturn( $variants );
2530 $mockLang->method(
'getCode' )->willReturn(
$code );
2533 $mockTitle = $this->
getMock( Title::class );
2534 $mockTitle->method(
'getPageLanguage' )->willReturn( $mockLang );
2536 $op->setTitle( $mockTitle );
2540 $op->sendCacheControl();
2542 $this->hideDeprecated(
'$wgUseKeyHeader' );
2543 $keyHeader = $op->getKeyHeader();
2550 $keyHeader = explode(
' ', $keyHeader, 2 )[1];
2551 $keyHeader = explode(
',', $keyHeader );
2553 $acceptLanguage =
null;
2554 foreach ( $keyHeader as $item ) {
2555 if (
strpos( $item,
'Accept-Language;' ) === 0 ) {
2556 $acceptLanguage =
$item;
2561 $expectedString =
'Accept-Language;substr=' . implode(
';substr=', $expected );
2562 $this->
assertSame( $expectedString, $acceptLanguage );
2567 'No variants' => [
'en', [
'en' ], [] ],
2568 'One simple variant' => [
'en', [
'en',
'en-x-piglatin' ], [
'en-x-piglatin' ] ],
2569 'Multiple variants with BCP47 alternatives' => [
2571 [
'zh',
'zh-hans',
'zh-cn',
'zh-tw' ],
2572 [
'zh-hans',
'zh-Hans',
'zh-cn',
'zh-Hans-CN',
'zh-tw',
'zh-Hant-TW' ],
2574 'No title' => [
'en', [
'en',
'en-x-piglatin' ], [], [
'notitle' ] ],
2575 'Variant in URL' => [
'en', [
'en',
'en-x-piglatin' ], [], [
'varianturl' ] ],
2587 $op = $this->newInstance();
2588 $this->
assertTrue( $op->getPreventClickjacking() );
2590 $op->allowClickjacking();
2591 $this->
assertFalse( $op->getPreventClickjacking() );
2593 $op->preventClickjacking();
2594 $this->
assertTrue( $op->getPreventClickjacking() );
2596 $op->preventClickjacking(
false );
2597 $this->
assertFalse( $op->getPreventClickjacking() );
2599 $pOut1 = $this->createParserOutputStub(
'preventClickjacking',
true );
2600 $op->addParserOutputMetadata( $pOut1 );
2601 $this->
assertTrue( $op->getPreventClickjacking() );
2604 $pOut2 = $this->createParserOutputStub(
'preventClickjacking',
false );
2605 $op->addParserOutputMetadata( $pOut2 );
2606 $this->
assertTrue( $op->getPreventClickjacking() );
2609 $op->allowClickjacking();
2610 $this->
assertFalse( $op->getPreventClickjacking() );
2612 $op->addParserOutput( $pOut1 );
2613 $this->
assertTrue( $op->getPreventClickjacking() );
2615 $op->addParserOutput( $pOut2 );
2616 $this->
assertTrue( $op->getPreventClickjacking() );
2625 $breakFrames, $preventClickjacking, $editPageFrameOptions, $expected
2627 $op = $this->newInstance( [
2628 'BreakFrames' => $breakFrames,
2629 'EditPageFrameOptions' => $editPageFrameOptions,
2631 $op->preventClickjacking( $preventClickjacking );
2633 $this->
assertSame( $expected, $op->getFrameOptions() );
2638 'BreakFrames true' => [
true,
false,
false,
'DENY' ],
2639 'Allow clickjacking locally' => [
false,
false,
'DENY',
false ],
2640 'Allow clickjacking globally' => [
false,
true,
false,
false ],
2641 'DENY globally' => [
false,
true,
'DENY',
'DENY' ],
2642 'SAMEORIGIN' => [
false,
true,
'SAMEORIGIN',
'SAMEORIGIN' ],
2643 'BreakFrames with SAMEORIGIN' => [
true,
true,
'SAMEORIGIN',
'DENY' ],
2655 $this->setMwGlobals( [
2656 'wgResourceLoaderDebug' =>
false,
2657 'wgLoadScript' =>
'http://127.0.0.1:8080/w/load.php',
2658 'wgCSPReportOnlyHeader' =>
true,
2661 $method = $class->getMethod(
'makeResourceLoaderLink' );
2662 $method->setAccessible(
true );
2664 $ctx->setSkin( SkinFactory::getDefaultInstance()->makeSkin(
'fallback' ) );
2665 $ctx->setLanguage(
'en' );
2667 $nonce = $class->getProperty(
'CSPNonce' );
2668 $nonce->setAccessible(
true );
2669 $nonce->setValue(
$out,
'secret' );
2670 $rl =
$out->getResourceLoader();
2671 $rl->setMessageBlobStore( $this->
createMock( MessageBlobStore::class ) );
2674 'script' =>
'mw.test.foo( { a: true } );',
2675 'styles' =>
'.mw-test-foo { content: "style"; }',
2678 'script' =>
'mw.test.bar( { a: true } );',
2679 'styles' =>
'.mw-test-bar { content: "style"; }',
2682 'script' =>
'mw.test.baz( { a: true } );',
2683 'styles' =>
'.mw-test-baz { content: "style"; }',
2686 'script' =>
'mw.test.baz( { token: 123 } );',
2687 'styles' =>
'/* pref-animate=off */ .mw-icon { transition: none; }',
2688 'group' =>
'private',
2691 'styles' =>
'.stuff { color: red; }',
2692 'group' =>
'noscript',
2695 'script' =>
'mw.doStuff( "foo" );',
2699 'script' =>
'mw.doStuff( "bar" );',
2703 $links = $method->invokeArgs(
$out,
$args );
2704 $actualHtml =
strval( $links );
2714 "<script nonce=\"secret\">(window.RLQ=window.RLQ||[]).push(function(){"
2715 .
'mw.loader.load("http://127.0.0.1:8080/w/load.php?lang=en\u0026modules=test.foo\u0026only=scripts\u0026skin=fallback");'
2722 '<link rel="stylesheet" href="http://127.0.0.1:8080/w/load.php?lang=en&modules=test.bar%2Cbaz%2Cfoo&only=styles&skin=fallback"/>'
2727 "<script nonce=\"secret\">(window.RLQ=window.RLQ||[]).push(function(){"
2728 .
"mw.test.baz({token:123});\nmw.loader.state({\"test.quux\":\"ready\"});"
2734 "<script nonce=\"secret\">(window.RLQ=window.RLQ||[]).push(function(){"
2735 .
"mw.loader.implement(\"test.quux@1ev0ijv\",function($,jQuery,require,module){"
2736 .
"mw.test.baz({token:123});},{\"css\":[\".mw-icon{transition:none}"
2737 .
"\"]});});</script>"
2747 '<noscript><link rel="stylesheet" href="http://127.0.0.1:8080/w/load.php?lang=en&modules=test.noscript&only=styles&skin=fallback"/></noscript>'
2752 "<script nonce=\"secret\">(window.RLQ=window.RLQ||[]).push(function(){"
2753 .
'mw.loader.load("http://127.0.0.1:8080/w/load.php?lang=en\u0026modules=test.group.bar\u0026skin=fallback");'
2754 .
'mw.loader.load("http://127.0.0.1:8080/w/load.php?lang=en\u0026modules=test.group.foo\u0026skin=fallback");'
2767 $this->setMwGlobals( [
2768 'wgResourceLoaderDebug' =>
false,
2769 'wgLoadScript' =>
'/w/load.php',
2772 'wgCacheEpoch' =>
'20140101000000',
2777 $ctx->setSkin( SkinFactory::getDefaultInstance()->makeSkin(
'fallback' ) );
2778 $ctx->setLanguage(
'en' );
2780 ->setConstructorArgs( [ $ctx ] )
2781 ->setMethods( [
'buildCssLinksArray' ] )
2783 $op->expects( $this->
any() )
2784 ->method(
'buildCssLinksArray' )
2786 $rl = $op->getResourceLoader();
2787 $rl->setMessageBlobStore( $this->
createMock( MessageBlobStore::class ) );
2796 $op = TestingAccessWrapper::newFromObject( $op );
2800 strval( $op->buildExemptModules() )
2808 'exemptStyleModules' => [],
2809 '<meta name="ResourceLoaderDynamicStyles" content=""/>',
2812 'exemptStyleModules' => [
'site' => [],
'noscript' => [],
'private' => [],
'user' => [] ],
2813 '<meta name="ResourceLoaderDynamicStyles" content=""/>',
2815 'default logged-out' => [
2816 'exemptStyleModules' => [
'site' => [
'site.styles' ] ],
2817 '<meta name="ResourceLoaderDynamicStyles" content=""/>' .
"\n" .
2818 '<link rel="stylesheet" href="/w/load.php?lang=en&modules=site.styles&only=styles&skin=fallback"/>',
2820 'default logged-in' => [
2821 'exemptStyleModules' => [
'site' => [
'site.styles' ],
'user' => [
'user.styles' ] ],
2822 '<meta name="ResourceLoaderDynamicStyles" content=""/>' .
"\n" .
2823 '<link rel="stylesheet" href="/w/load.php?lang=en&modules=site.styles&only=styles&skin=fallback"/>' .
"\n" .
2824 '<link rel="stylesheet" href="/w/load.php?lang=en&modules=user.styles&only=styles&skin=fallback&version=1ai9g6t"/>',
2826 'custom modules' => [
2827 'exemptStyleModules' => [
2828 'site' => [
'site.styles',
'example.site.a',
'example.site.b' ],
2829 'user' => [
'user.styles',
'example.user' ],
2831 '<meta name="ResourceLoaderDynamicStyles" content=""/>' .
"\n" .
2832 '<link rel="stylesheet" href="/w/load.php?lang=en&modules=example.site.a%2Cb&only=styles&skin=fallback"/>' .
"\n" .
2833 '<link rel="stylesheet" href="/w/load.php?lang=en&modules=site.styles&only=styles&skin=fallback"/>' .
"\n" .
2834 '<link rel="stylesheet" href="/w/load.php?lang=en&modules=example.user&only=styles&skin=fallback&version=0a56zyi"/>' .
"\n" .
2835 '<link rel="stylesheet" href="/w/load.php?lang=en&modules=user.styles&only=styles&skin=fallback&version=1ai9g6t"/>',
2847 $uploadPath =
null, $path =
null, $expected =
null
2849 if ( $path ===
null ) {
2853 $uploadDir =
"$baseDir/images";
2854 $uploadPath =
"$basePath/images";
2856 $this->setMwGlobals(
'IP', $baseDir );
2859 'UploadDirectory' => $uploadDir,
2860 'UploadPath' => $uploadPath,
2865 $actual = OutputPage::transformResourcePath( $conf, $path );
2872 $baseDir =
dirname( __DIR__ ) .
'/data/media';
2876 'baseDir' =>
$baseDir,
'basePath' =>
'/w',
2882 'baseDir' =>
$baseDir,
'basePath' =>
'/w',
2888 'baseDir' =>
$baseDir,
'basePath' =>
'/w',
2893 'baseDir' =>
$baseDir,
'basePath' =>
'/w',
2899 'baseDir' =>
$baseDir,
'basePath' =>
'/w',
2900 '//example.org/w/test.jpg'
2903 'baseDir' =>
$baseDir,
'basePath' =>
'/w',
2904 'https://example.org/w/test.jpg'
2908 'baseDir' =>
$baseDir,
'basePath' =>
'/w',
2909 'https://example.org/files/test.jpg'
2912 'baseDir' =>
$baseDir,
'basePath' =>
'/w',
2913 '//example.org/files/test.jpg'
2917 'baseDir' =>
$baseDir,
'basePath' =>
'',
2918 'https://example.org/files/test.jpg'
2921 'baseDir' =>
$baseDir,
'basePath' =>
'',
2923 '//example.org/files/test.jpg'
2927 'baseDir' =>
dirname( $baseDir ),
'basePath' =>
'',
2928 'uploadDir' =>
$baseDir,
'uploadPath' =>
'/images',
2930 '/images/test.jpg?edcf2'
2952 $queryData[
'printable'] =
$args[
'printableQuery'];
2956 $queryData[
'handheld'] =
$args[
'handheldQuery'];
2959 $fauxRequest =
new FauxRequest( $queryData,
false );
2960 $this->setMwGlobals( [
2961 'wgRequest' => $fauxRequest,
2964 $actualReturn = OutputPage::transformCssMedia(
$args[
'media'] );
2974 $this->assertTransformCssMediaCase( [
2975 'printableQuery' =>
'1',
2976 'media' =>
'screen',
2977 'expectedReturn' =>
null,
2978 'message' =>
'On printable request, screen returns null'
2981 $this->assertTransformCssMediaCase( [
2982 'printableQuery' =>
'1',
2983 'media' => self::SCREEN_MEDIA_QUERY,
2984 'expectedReturn' =>
null,
2985 'message' =>
'On printable request, screen media query returns null'
2988 $this->assertTransformCssMediaCase( [
2989 'printableQuery' =>
'1',
2990 'media' => self::SCREEN_ONLY_MEDIA_QUERY,
2991 'expectedReturn' =>
null,
2992 'message' =>
'On printable request, screen media query with only returns null'
2995 $this->assertTransformCssMediaCase( [
2996 'printableQuery' =>
'1',
2998 'expectedReturn' =>
'',
2999 'message' =>
'On printable request, media print returns empty string'
3009 $this->assertTransformCssMediaCase( [
3010 'media' =>
'screen',
3011 'expectedReturn' =>
'screen',
3012 'message' =>
'On screen request, screen media type is preserved'
3015 $this->assertTransformCssMediaCase( [
3016 'media' =>
'handheld',
3017 'expectedReturn' =>
'handheld',
3018 'message' =>
'On screen request, handheld media type is preserved'
3021 $this->assertTransformCssMediaCase( [
3022 'media' => self::SCREEN_MEDIA_QUERY,
3023 'expectedReturn' => self::SCREEN_MEDIA_QUERY,
3024 'message' =>
'On screen request, screen media query is preserved.'
3027 $this->assertTransformCssMediaCase( [
3028 'media' => self::SCREEN_ONLY_MEDIA_QUERY,
3029 'expectedReturn' => self::SCREEN_ONLY_MEDIA_QUERY,
3030 'message' =>
'On screen request, screen media query with only is preserved.'
3033 $this->assertTransformCssMediaCase( [
3035 'expectedReturn' =>
'print',
3036 'message' =>
'On screen request, print media type is preserved'
3046 $this->assertTransformCssMediaCase( [
3047 'handheldQuery' =>
'1',
3048 'media' =>
'handheld',
3049 'expectedReturn' =>
'',
3050 'message' =>
'On request with handheld querystring and media is handheld, returns empty string'
3053 $this->assertTransformCssMediaCase( [
3054 'handheldQuery' =>
'1',
3055 'media' =>
'screen',
3056 'expectedReturn' =>
null,
3057 'message' =>
'On request with handheld querystring and media is screen, returns null'
3067 $op = $this->newInstance();
3070 $pOut1 = $this->createParserOutputStub(
'getTOCHTML',
false );
3071 $op->addParserOutputMetadata( $pOut1 );
3074 $pOut2 = $this->createParserOutputStub(
'getTOCHTML',
true );
3075 $op->addParserOutput( $pOut2 );
3079 $op->addParserOutputMetadata( $pOut1 );
3089 $this->setMwGlobals( $config );
3091 ->disableOriginalConstructor()->getMock();
3094 $this->
assertEquals( [ $result ], $module->getHeaders( $ctx ) );
3101 'wgResourceBasePath' =>
'/w',
3102 'wgLogo' =>
'/img/default.png',
3104 '1.5x' =>
'/img/one-point-five.png',
3105 '2x' =>
'/img/two-x.png',
3108 'Link: </img/default.png>;rel=preload;as=image;media=' .
3109 'not all and (min-resolution: 1.5dppx),' .
3110 '</img/one-point-five.png>;rel=preload;as=image;media=' .
3111 '(min-resolution: 1.5dppx) and (max-resolution: 1.999999dppx),' .
3112 '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
3116 'wgResourceBasePath' =>
'/w',
3117 'wgLogo' =>
'/img/default.png',
3118 'wgLogoHD' =>
false,
3120 'Link: </img/default.png>;rel=preload;as=image'
3124 'wgResourceBasePath' =>
'/w',
3125 'wgLogo' =>
'/img/default.png',
3127 '2x' =>
'/img/two-x.png',
3130 'Link: </img/default.png>;rel=preload;as=image;media=' .
3131 'not all and (min-resolution: 2dppx),' .
3132 '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
3136 'wgResourceBasePath' =>
'/w',
3137 'wgLogo' =>
'/img/default.png',
3139 'svg' =>
'/img/vector.svg',
3142 'Link: </img/vector.svg>;rel=preload;as=image'
3147 'wgResourceBasePath' =>
'/w',
3148 'wgLogo' =>
'/w/test.jpg',
3149 'wgLogoHD' =>
false,
3150 'wgUploadPath' =>
'/w/images',
3151 'IP' =>
dirname( __DIR__ ) .
'/data/media',
3153 'Link: </w/test.jpg?edcf2>;rel=preload;as=image',
3166 'AppleTouchIcon' =>
false,
3167 'DisableLangConversion' =>
true,
3168 'EnableCanonicalServerLink' =>
false,
3171 'LanguageCode' =>
false,
3172 'ReferrerPolicy' =>
false,
3173 'RightsPage' =>
false,
3174 'RightsUrl' =>
false,
3175 'UniversalEditButton' =>
false,
3181 $context->setTitle( Title::newFromText(
'My test page' ) );
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
$wgSquidMaxage
Cache TTL for the CDN sent as s-maxage (without ESI) or Surrogate-Control (with ESI).
$wgCookiePrefix
Cookies generated by MediaWiki have names starting with this prefix.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
WebRequest clone which takes values from a provided array.
A Config instance which stores all settings as a member variable.
Provides a fallback sequence for Config objects.
testGetCategoriesInvalid()
OutputPage::getCategories.
testClientCache()
OutputPage::enableClientCache OutputPage::addParserOutputMetadata OutputPage::addParserOutput.
testGetCacheVaryCookies()
OutputPage::getCacheVaryCookies.
static int $fakeTime
Faked time to set for tests that need it.
testBodyHTML()
OutputPage::prependHTML OutputPage::addHTML OutputPage::addElement OutputPage::clearHTML OutputPage::...
newInstance( $config=[], WebRequest $request=null, $options=[])
testRecentChangesFeed( $feed, $advertised_feed_types, $message, $present, $non_present)
provideFeedLinkData OutputPage::getHeadLinksArray
testSetCopyrightUrl()
OutputPage::setCopyrightUrl OutputPage::getHeadLinksArray.
testAddWikiTextAsContentNoTitle()
OutputPage::addWikiTextAsContent.
static provideAdditionalFeedData()
const SCREEN_ONLY_MEDIA_QUERY
testAddParserOutputText()
OutputPage::addParserOutputText.
doCategoryLinkAsserts( $op, $expectedNormal, $expectedHidden)
testShowNewSectionLink()
OutputPage::showNewSectionLink OutputPage::addParserOutputMetadata OutputPage::addParserOutput.
testTemplateIds()
OutputPage::getTemplateIds OutputPage::addParserOutputMetadata OutputPage::addParserOutput.
testHeadItems()
OutputPage::getHeadItemsArray OutputPage::addHeadItem OutputPage::addHeadItems OutputPage::hasHeadIte...
testSubtitle()
OutputPage::setSubtitle OutputPage::clearSubtitle OutputPage::addSubtitle OutputPage::getSubtitle.
testCdnMaxage()
OutputPage::setCdnMaxage OutputPage::lowerCdnMaxage.
testParseInlineNullTitle()
OutputPage::parseInline.
testAddHelpLink()
OutputPage::addHelpLink OutputPage::getIndicators.
testForceHideNewSectionLink()
OutputPage::forceHideNewSectionLink OutputPage::addParserOutputMetadata OutputPage::addParserOutput.
testAddParserOutput()
OutputPage::addParserOutput.
testAddDeprecatedScriptFileWarning()
Test that addScriptFile() throws due to deprecation.
testParseNullTitle()
OutputPage::parse.
testSetCanonicalUrl()
OutputPage::setCanonicalUrl OutputPage::getCanonicalUrl OutputPage::getHeadLinksArray.
testParseInlineAsInterfaceNullTitle()
OutputPage::parseInlineAsInterface.
testAddWikiTextNoTitle()
OutputPage::addWikiText.
testAddBacklinkSubtitle( $titles, $queries, $contains, $notContains)
provideBacklinkSubtitle
static $parserOutputHookCalled
testMetaTags()
OutputPage::addMeta OutputPage::getMetaTags OutputPage::getHeadLinksArray.
testAddDeprecatedScriptFileNoOp()
Test the actual behavior of the method (in the case where it doesn't throw, e.g., in production).
testHaveCacheVaryCookies()
OutputPage::haveCacheVaryCookies.
testParserOutputHooks()
OutputPage::addParserOutputMetadata.
static getMsgText( $op,... $msgParams)
Shorthand for getting the text of a message, in content language.
testAddAcceptLanguage( $code, array $variants, array $expected, array $options=[])
provideAddAcceptLanguage OutputPage::addAcceptLanguage OutputPage::getKeyHeader
testPageTitle()
OutputPage::setPageTitle OutputPage::getPageTitle.
provideCheckLastModified()
testTransformResourcePath( $baseDir, $basePath, $uploadDir=null, $uploadPath=null, $path=null, $expected=null)
provideTransformFilePath OutputPage::transformFilePath OutputPage::transformResourcePath
static provideCdnCacheEpoch()
testAddScript()
OutputPage::addScript.
testHandheld()
Tests handheld behavior.
testFeedLinks()
OutputPage::isSyndicated OutputPage::setFeedAppendQuery OutputPage::addFeedLink OutputPage::getSyndic...
testHeadItemsParserOutput()
OutputPage::getHeadItemsArray OutputPage::addParserOutputMetadata OutputPage::addParserOutput.
extractExpectedCategories(array $expected, $key)
We allow different expectations for different tests as an associative array, like [ 'set' => [ ....
testNoGallery()
OutputPage::addParserOutputMetadata OutputPage::addParserOutput.
testParseAsInterface(array $args, $expectedHTML, $expectedHTMLInline=null)
provideParseAs OutputPage::parseAsInterface
testProperties()
OutputPage::setProperty OutputPage::getProperty.
testRevisionId( $newVal, $expected)
provideRevisionId OutputPage::setRevisionId OutputPage::getRevisionId
static provideTransformFilePath()
testAddCategoryLinksOneByOne(array $args, array $fakeResults, callable $variantLinkCallback=null, array $expectedNormal, array $expectedHidden)
provideGetCategories
testParse(array $args, $expectedHTML)
provideParse OutputPage::parse
testMakeResourceLoaderLink( $args, $expectedHtml)
See ResourceLoaderClientHtmlTest for full coverage.
testPreloadLinkHeaders( $config, $result)
providePreloadLinkHeaders ResourceLoaderSkinModule::getPreloadLinks ResourceLoaderSkinModule::getLogo...
testDisable()
OutputPage::disable OutputPage::isDisabled.
assertFeedLinks( $outputPage, $message, $present, $non_present)
testWrapWikiMsg()
OutputPage::wrapWikiMsg.
assertFeedUILinks( $outputPage, $ui_links)
testParseAsContent(array $args, $expectedHTML, $expectedHTMLInline=null)
provideParseAs OutputPage::parseAsContent
testVaryHeaders(array $calls, array $cookies, $vary, $key)
provideVaryHeaders
testHTMLTitle()
OutputPage::setHTMLTitle OutputPage::getHTMLTitle.
testLanguageLinks()
OutputPage::addLanguageLinks OutputPage::setLanguageLinks OutputPage::getLanguageLinks OutputPage::ad...
static provideMakeResourceLoaderLink()
assertTransformCssMediaCase( $args)
Tests a particular case of transformCssMedia, using the given input, globals, expected return,...
testRedirect( $url, $code=null)
provideRedirect
testSetRobotPolicy()
OutputPage::setRobotPolicy OutputPage::getHeadLinksArray.
testAddWikiTextAsInterfaceNoTitle()
OutputPage::addWikiTextAsInterface.
testAddWikiMsg()
OutputPage::addWikiMsg.
testSetTitle()
OutputPage::setTitle.
testAddBodyClasses()
OutputPage::addBodyClasses.
testAddWikiText( $method, array $args, $expected)
provideAddWikiText OutputPage::addWikiText OutputPage::addWikiTextAsInterface OutputPage::wrapWikiTex...
testParseInlineAsInterface(array $args, $expectedHTML, $expectedHTMLInline=null)
provideParseAs OutputPage::parseInlineAsInterface
testAddCategoryLinks(array $args, array $fakeResults, callable $variantLinkCallback=null, array $expectedNormal, array $expectedHidden)
provideGetCategories
testParserOutputCategoryLinks(array $args, array $fakeResults, callable $variantLinkCallback=null, array $expectedNormal, array $expectedHidden)
provideGetCategories
testAddInlineScript()
OutputPage::addInlineScript.
setupCategoryTests(array $fakeResults, callable $variantLinkCallback=null)
testClickjacking()
OutputPage::preventClickjacking OutputPage::allowClickjacking OutputPage::getPreventClickjacking Outp...
setupFeedLinks( $feed, $types)
testParseAsInterfaceNullTitle()
OutputPage::parseAsInterface.
testAddTemplate()
OutputPage::addTemplate.
testScreenRequests()
Tests screen requests, without either query parameter set.
createParserOutputStub(... $args)
Call either with arguments $methodName, $returnValue; or an array [ $methodName => $returnValue,...
testSetCategoryLinks(array $args, array $fakeResults, callable $variantLinkCallback=null, array $expectedNormal, array $expectedHidden)
provideGetCategories
testCheckLastModified( $timestamp, $ifModifiedSince, $expected, $config=[], $callback=null)
provideCheckLastModified
testPrintRequests()
Tests print requests.
static parserOutputHookCallbackStatic(OutputPage $op, ParserOutput $pOut, $data)
testArticleFlags()
OutputPage::setArticleFlag OutputPage::isArticle OutputPage::setArticleRelated OutputPage::isArticleR...
testAddScriptFile()
OutputPage::addScriptFile.
testAdaptCdnTTL(array $args, $expected, array $options=[])
provideAdaptCdnTTL OutputPage::adaptCdnTTL
testAdditionalFeeds( $feed, $advertised_feed_types, $message, $additional_feed_type, $present, $non_present, $any_ui_links)
provideAdditionalFeedData OutputPage::getHeadLinksArray OutputPage::addFeedLink OutputPage::getSyndic...
providePreloadLinkHeaders()
testRevisionTimestamp()
OutputPage::setRevisionTimestamp OutputPage::getRevisionTimestamp.
extractHTMLTitle(OutputPage $op)
testPrintable()
OutputPage::setPrintable OutputPage::isPrintable.
testFileSearchOptions()
OutputPage::getFileSearchOptions OutputPage::addParserOutputMetadata OutputPage::addParserOutput.
parserOutputHookCallback(OutputPage $op, ParserOutput $pOut, $data)
testBuildBacklinkSubtitle( $titles, $queries, $contains, $notContains)
provideBacklinkSubtitle
testSetTarget()
OutputPage::getTarget OutputPage::setTarget.
doCategoryAsserts( $op, $expectedNormal, $expectedHidden)
testVaryHeaderDefault()
OutputPage::getVaryHeader.
testGetFrameOptions( $breakFrames, $preventClickjacking, $editPageFrameOptions, $expected)
provideGetFrameOptions OutputPage::getFrameOptions OutputPage::preventClickjacking
testAddLink()
OutputPage::addLink OutputPage::getLinkTags OutputPage::getHeadLinksArray.
testParseInline(array $args, $expectedHTML, $expectedHTMLInline=null)
provideParse OutputPage::parseInline
testSetIndexFollowPolicies()
OutputPage::setIndexPolicy OutputPage::setFollowPolicy OutputPage::getHeadLinksArray.
testFileVersion()
OutputPage::setFileVersion OutputPage::getFileVersion.
static provideBuildExemptModules()
testCdnCacheEpoch( $params)
provideCdnCacheEpoch
static provideFeedLinkData()
testArticleBodyOnly()
OutputPage::setArticleBodyOnly OutputPage::getArticleBodyOnly.
testParseAsContentNullTitle()
OutputPage::parseAsContent.
testSetSyndicated()
OutputPage::setSyndicated OutputPage::isSyndicated.
provideBacklinkSubtitle()
testBuildExemptModules(array $exemptStyleModules, $expect)
provideBuildExemptModules
testIsTOCEnabled()
OutputPage::isTOCEnabled OutputPage::addParserOutputMetadata OutputPage::addParserOutput.
testLinkHeaders(array $headers, $result)
provideLinkHeaders
testIndicators()
OutputPage::setIndicators OutputPage::getIndicators OutputPage::addParserOutputMetadata OutputPage::a...
provideAddAcceptLanguage()
testSetRedirectedFrom()
OutputPage::setRedirectedFrom.
This class should be covered by a general architecture document which does not exist as of January 20...
Group all the pieces relevant to the context of a request into one instance.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same so they can t rely on Unix and must forbid reads to even standard directories like tmp lest users read each others files We cannot assume that the user has the ability to install or run any programs not written as web accessible PHP scripts Since anything that works on cheap shared hosting will work if you have shell or root access MediaWiki s design is based around catering to the lowest common denominator Although we support higher end setups as the way many things work by default is tailored toward shared hosting These defaults are unconventional from the point of view of and they certainly aren t ideal for someone who s installing MediaWiki as MediaWiki does not conform to normal Unix filesystem layout Hopefully we ll offer direct support for standard layouts in the but for now *any change to the location of files is unsupported *Moving things and leaving symlinks will *probably *not break anything
this hook is for auditing only $req
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping $template
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
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
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
namespace and then decline to actually register it file or subcat img or subcat $title
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
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 true
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 & $ret
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
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
usually copyright or history_copyright This message must be in HTML not wikitext & $link
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
processing should stop and the error should be shown to the user * false
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
controlled by the following MediaWiki still creates a BagOStuff but calls it to it are no ops If the cache daemon can t be it should also disable itself fairly $wgDBname
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))