MediaWiki  master
OutputPage.php
Go to the documentation of this file.
1 <?php
23 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
28 use Wikimedia\RelPath;
29 use Wikimedia\WrappedString;
30 use Wikimedia\WrappedStringList;
31 
47 class OutputPage extends ContextSource {
48  use ProtectedHookAccessorTrait;
49 
51  protected $mMetatags = [];
52 
54  protected $mLinktags = [];
55 
57  protected $mCanonicalUrl = false;
58 
62  private $mPageTitle = '';
63 
71  private $displayTitle;
72 
74  private $cacheIsFinal = false;
75 
80  public $mBodytext = '';
81 
83  private $mHTMLtitle = '';
84 
89  private $mIsArticle = false;
90 
92  private $mIsArticleRelated = true;
93 
95  private $mHasCopyright = false;
96 
101  private $mPrintable = false;
102 
107  private $mSubtitle = [];
108 
110  public $mRedirect = '';
111 
113  protected $mStatusCode;
114 
119  protected $mLastModified = '';
120 
122  protected $mCategoryLinks = [];
123 
125  protected $mCategories = [
126  'hidden' => [],
127  'normal' => [],
128  ];
129 
131  protected $mIndicators = [];
132 
134  private $mLanguageLinks = [];
135 
142  private $mScripts = '';
143 
145  protected $mInlineStyles = '';
146 
151  public $mPageLinkTitle = '';
152 
157  protected $mAdditionalHtmlClasses = [];
158 
160  protected $mHeadItems = [];
161 
163  protected $mAdditionalBodyClasses = [];
164 
166  protected $mModules = [];
167 
169  protected $mModuleStyles = [];
170 
172  protected $mResourceLoader;
173 
175  private $rlClient;
176 
179 
182 
184  protected $mJsConfigVars = [];
185 
187  protected $mTemplateIds = [];
188 
190  protected $mImageTimeKeys = [];
191 
193  public $mRedirectCode = '';
194 
195  protected $mFeedLinksAppendQuery = null;
196 
202  protected $mAllowedModules = [
203  ResourceLoaderModule::TYPE_COMBINED => ResourceLoaderModule::ORIGIN_ALL,
204  ];
205 
207  protected $mDoNothing = false;
208 
209  // Parser related.
210 
212  protected $mContainsNewMagic = 0;
213 
218  protected $mParserOptions = null;
219 
225  private $mFeedLinks = [];
226 
227  // Gwicke work on squid caching? Roughly from 2003.
228  protected $mEnableClientCache = true;
229 
231  private $mArticleBodyOnly = false;
232 
234  protected $mNewSectionLink = false;
235 
237  protected $mHideNewSectionLink = false;
238 
244  public $mNoGallery = false;
245 
247  protected $mCdnMaxage = 0;
249  protected $mCdnMaxageLimit = INF;
250 
256  protected $mPreventClickjacking = true;
257 
259  private $mRevisionId = null;
260 
262  private $mRevisionTimestamp = null;
263 
265  protected $mFileVersion = null;
266 
275  protected $styles = [];
276 
277  private $mIndexPolicy = 'index';
278  private $mFollowPolicy = 'follow';
279 
285  private $mVaryHeader = [
286  'Accept-Encoding' => null,
287  ];
288 
295  private $mRedirectedFrom = null;
296 
300  private $mProperties = [];
301 
305  private $mTarget = null;
306 
310  private $mEnableTOC = false;
311 
315  private $copyrightUrl;
316 
318  private $limitReportJSData = [];
319 
321  private $contentOverrides = [];
322 
325 
329  private $mLinkHeader = [];
330 
334  private $CSP;
335 
339  private static $cacheVaryCookies = null;
340 
347  public function __construct( IContextSource $context ) {
348  $this->setContext( $context );
349  $this->CSP = new ContentSecurityPolicy(
350  $context->getRequest()->response(),
351  $context->getConfig(),
352  $this->getHookContainer()
353  );
354  }
355 
362  public function redirect( $url, $responsecode = '302' ) {
363  # Strip newlines as a paranoia check for header injection in PHP<5.1.2
364  $this->mRedirect = str_replace( "\n", '', $url );
365  $this->mRedirectCode = (string)$responsecode;
366  }
367 
373  public function getRedirect() {
374  return $this->mRedirect;
375  }
376 
385  public function setCopyrightUrl( $url ) {
386  $this->copyrightUrl = $url;
387  }
388 
394  public function setStatusCode( $statusCode ) {
395  $this->mStatusCode = $statusCode;
396  }
397 
405  public function addMeta( $name, $val ) {
406  $this->mMetatags[] = [ $name, $val ];
407  }
408 
415  public function getMetaTags() {
416  return $this->mMetatags;
417  }
418 
426  public function addLink( array $linkarr ) {
427  $this->mLinktags[] = $linkarr;
428  }
429 
436  public function getLinkTags() {
437  return $this->mLinktags;
438  }
439 
445  public function setCanonicalUrl( $url ) {
446  $this->mCanonicalUrl = $url;
447  }
448 
456  public function getCanonicalUrl() {
457  return $this->mCanonicalUrl;
458  }
459 
467  public function addScript( $script ) {
468  $this->mScripts .= $script;
469  }
470 
479  public function addScriptFile( $file, $unused = null ) {
480  $this->addScript( Html::linkedScript( $file, $this->CSP->getNonce() ) );
481  }
482 
489  public function addInlineScript( $script ) {
490  $this->mScripts .= Html::inlineScript( "\n$script\n", $this->CSP->getNonce() ) . "\n";
491  }
492 
501  protected function filterModules( array $modules, $position = null,
502  $type = ResourceLoaderModule::TYPE_COMBINED
503  ) {
504  $resourceLoader = $this->getResourceLoader();
505  $filteredModules = [];
506  foreach ( $modules as $val ) {
507  $module = $resourceLoader->getModule( $val );
508  if ( $module instanceof ResourceLoaderModule
509  && $module->getOrigin() <= $this->getAllowedModules( $type )
510  ) {
511  if ( $this->mTarget && !in_array( $this->mTarget, $module->getTargets() ) ) {
512  $this->warnModuleTargetFilter( $module->getName() );
513  continue;
514  }
515  $filteredModules[] = $val;
516  }
517  }
518  return $filteredModules;
519  }
520 
521  private function warnModuleTargetFilter( $moduleName ) {
522  static $warnings = [];
523  if ( isset( $warnings[$this->mTarget][$moduleName] ) ) {
524  return;
525  }
526  $warnings[$this->mTarget][$moduleName] = true;
527  $this->getResourceLoader()->getLogger()->debug(
528  'Module "{module}" not loadable on target "{target}".',
529  [
530  'module' => $moduleName,
531  'target' => $this->mTarget,
532  ]
533  );
534  }
535 
545  public function getModules( $filter = false, $position = null, $param = 'mModules',
546  $type = ResourceLoaderModule::TYPE_COMBINED
547  ) {
548  $modules = array_values( array_unique( $this->$param ) );
549  return $filter
550  ? $this->filterModules( $modules, null, $type )
551  : $modules;
552  }
553 
559  public function addModules( $modules ) {
560  $this->mModules = array_merge( $this->mModules, (array)$modules );
561  }
562 
570  public function getModuleStyles( $filter = false, $position = null ) {
571  return $this->getModules( $filter, null, 'mModuleStyles',
572  ResourceLoaderModule::TYPE_STYLES
573  );
574  }
575 
585  public function addModuleStyles( $modules ) {
586  $this->mModuleStyles = array_merge( $this->mModuleStyles, (array)$modules );
587  }
588 
592  public function getTarget() {
593  return $this->mTarget;
594  }
595 
601  public function setTarget( $target ) {
602  $this->mTarget = $target;
603  }
604 
612  public function addContentOverride( LinkTarget $target, Content $content ) {
613  if ( !$this->contentOverrides ) {
614  // Register a callback for $this->contentOverrides on the first call
615  $this->addContentOverrideCallback( function ( LinkTarget $target ) {
616  $key = $target->getNamespace() . ':' . $target->getDBkey();
617  return $this->contentOverrides[$key] ?? null;
618  } );
619  }
620 
621  $key = $target->getNamespace() . ':' . $target->getDBkey();
622  $this->contentOverrides[$key] = $content;
623  }
624 
632  public function addContentOverrideCallback( callable $callback ) {
633  $this->contentOverrideCallbacks[] = $callback;
634  }
635 
643  public function addHtmlClasses( $classes ) {
644  $this->mAdditionalHtmlClasses = array_merge( $this->mAdditionalHtmlClasses, (array)$classes );
645  }
646 
652  public function getHeadItemsArray() {
653  return $this->mHeadItems;
654  }
655 
668  public function addHeadItem( $name, $value ) {
669  $this->mHeadItems[$name] = $value;
670  }
671 
678  public function addHeadItems( $values ) {
679  $this->mHeadItems = array_merge( $this->mHeadItems, (array)$values );
680  }
681 
688  public function hasHeadItem( $name ) {
689  return isset( $this->mHeadItems[$name] );
690  }
691 
698  public function addBodyClasses( $classes ) {
699  $this->mAdditionalBodyClasses = array_merge( $this->mAdditionalBodyClasses, (array)$classes );
700  }
701 
709  public function setArticleBodyOnly( $only ) {
710  $this->mArticleBodyOnly = $only;
711  }
712 
718  public function getArticleBodyOnly() {
720  }
721 
729  public function setProperty( $name, $value ) {
730  $this->mProperties[$name] = $value;
731  }
732 
740  public function getProperty( $name ) {
741  return $this->mProperties[$name] ?? null;
742  }
743 
755  public function checkLastModified( $timestamp ) {
756  if ( !$timestamp || $timestamp == '19700101000000' ) {
757  wfDebug( __METHOD__ . ": CACHE DISABLED, NO TIMESTAMP" );
758  return false;
759  }
760  $config = $this->getConfig();
761  if ( !$config->get( 'CachePages' ) ) {
762  wfDebug( __METHOD__ . ": CACHE DISABLED" );
763  return false;
764  }
765 
766  $timestamp = wfTimestamp( TS_MW, $timestamp );
767  $modifiedTimes = [
768  'page' => $timestamp,
769  'user' => $this->getUser()->getTouched(),
770  'epoch' => $config->get( 'CacheEpoch' )
771  ];
772  if ( $config->get( 'UseCdn' ) ) {
773  $modifiedTimes['sepoch'] = wfTimestamp( TS_MW, $this->getCdnCacheEpoch(
774  time(),
775  $config->get( 'CdnMaxAge' )
776  ) );
777  }
778  $this->getHookRunner()->onOutputPageCheckLastModified( $modifiedTimes, $this );
779 
780  $maxModified = max( $modifiedTimes );
781  $this->mLastModified = wfTimestamp( TS_RFC2822, $maxModified );
782 
783  $clientHeader = $this->getRequest()->getHeader( 'If-Modified-Since' );
784  if ( $clientHeader === false ) {
785  wfDebug( __METHOD__ . ": client did not send If-Modified-Since header", 'private' );
786  return false;
787  }
788 
789  # IE sends sizes after the date like this:
790  # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
791  # this breaks strtotime().
792  $clientHeader = preg_replace( '/;.*$/', '', $clientHeader );
793 
794  Wikimedia\suppressWarnings(); // E_STRICT system time warnings
795  $clientHeaderTime = strtotime( $clientHeader );
796  Wikimedia\restoreWarnings();
797  if ( !$clientHeaderTime ) {
798  wfDebug( __METHOD__
799  . ": unable to parse the client's If-Modified-Since header: $clientHeader" );
800  return false;
801  }
802  $clientHeaderTime = wfTimestamp( TS_MW, $clientHeaderTime );
803 
804  # Make debug info
805  $info = '';
806  foreach ( $modifiedTimes as $name => $value ) {
807  if ( $info !== '' ) {
808  $info .= ', ';
809  }
810  $info .= "$name=" . wfTimestamp( TS_ISO_8601, $value );
811  }
812 
813  wfDebug( __METHOD__ . ": client sent If-Modified-Since: " .
814  wfTimestamp( TS_ISO_8601, $clientHeaderTime ), 'private' );
815  wfDebug( __METHOD__ . ": effective Last-Modified: " .
816  wfTimestamp( TS_ISO_8601, $maxModified ), 'private' );
817  if ( $clientHeaderTime < $maxModified ) {
818  wfDebug( __METHOD__ . ": STALE, $info", 'private' );
819  return false;
820  }
821 
822  # Not modified
823  # Give a 304 Not Modified response code and disable body output
824  wfDebug( __METHOD__ . ": NOT MODIFIED, $info", 'private' );
825  ini_set( 'zlib.output_compression', 0 );
826  $this->getRequest()->response()->statusHeader( 304 );
827  $this->sendCacheControl();
828  $this->disable();
829 
830  // Don't output a compressed blob when using ob_gzhandler;
831  // it's technically against HTTP spec and seems to confuse
832  // Firefox when the response gets split over two packets.
834 
835  return true;
836  }
837 
843  private function getCdnCacheEpoch( $reqTime, $maxAge ) {
844  // Ensure Last-Modified is never more than $wgCdnMaxAge in the past,
845  // because even if the wiki page content hasn't changed since, static
846  // resources may have changed (skin HTML, interface messages, urls, etc.)
847  // and must roll-over in a timely manner (T46570)
848  return $reqTime - $maxAge;
849  }
850 
857  public function setLastModified( $timestamp ) {
858  $this->mLastModified = wfTimestamp( TS_RFC2822, $timestamp );
859  }
860 
869  public function setRobotPolicy( $policy ) {
870  $policy = Article::formatRobotPolicy( $policy );
871 
872  if ( isset( $policy['index'] ) ) {
873  $this->setIndexPolicy( $policy['index'] );
874  }
875  if ( isset( $policy['follow'] ) ) {
876  $this->setFollowPolicy( $policy['follow'] );
877  }
878  }
879 
886  public function getRobotPolicy() {
887  return "{$this->mIndexPolicy},{$this->mFollowPolicy}";
888  }
889 
897  public function setIndexPolicy( $policy ) {
898  $policy = trim( $policy );
899  if ( in_array( $policy, [ 'index', 'noindex' ] ) ) {
900  $this->mIndexPolicy = $policy;
901  }
902  }
903 
909  public function getIndexPolicy() {
910  return $this->mIndexPolicy;
911  }
912 
920  public function setFollowPolicy( $policy ) {
921  $policy = trim( $policy );
922  if ( in_array( $policy, [ 'follow', 'nofollow' ] ) ) {
923  $this->mFollowPolicy = $policy;
924  }
925  }
926 
932  public function getFollowPolicy() {
933  return $this->mFollowPolicy;
934  }
935 
942  public function setHTMLTitle( $name ) {
943  if ( $name instanceof Message ) {
944  $this->mHTMLtitle = $name->setContext( $this->getContext() )->text();
945  } else {
946  $this->mHTMLtitle = $name;
947  }
948  }
949 
955  public function getHTMLTitle() {
956  return $this->mHTMLtitle;
957  }
958 
964  public function setRedirectedFrom( $t ) {
965  $this->mRedirectedFrom = $t;
966  }
967 
980  public function setPageTitle( $name ) {
981  if ( $name instanceof Message ) {
982  $name = $name->setContext( $this->getContext() )->text();
983  }
984 
985  # change "<script>foo&bar</script>" to "&lt;script&gt;foo&amp;bar&lt;/script&gt;"
986  # but leave "<i>foobar</i>" alone
988  $this->mPageTitle = $nameWithTags;
989 
990  # change "<i>foo&amp;bar</i>" to "foo&bar"
991  $this->setHTMLTitle(
992  $this->msg( 'pagetitle' )->plaintextParams( Sanitizer::stripAllTags( $nameWithTags ) )
993  ->inContentLanguage()
994  );
995  }
996 
1002  public function getPageTitle() {
1003  return $this->mPageTitle;
1004  }
1005 
1013  public function setDisplayTitle( $html ) {
1014  $this->displayTitle = $html;
1015  }
1016 
1025  public function getDisplayTitle() {
1026  $html = $this->displayTitle;
1027  if ( $html === null ) {
1028  $html = $this->getTitle()->getPrefixedText();
1029  }
1030 
1032  }
1033 
1040  public function getUnprefixedDisplayTitle() {
1041  $text = $this->getDisplayTitle();
1042  $nsPrefix = $this->getTitle()->getNsText() . ':';
1043  $prefix = preg_quote( $nsPrefix, '/' );
1044 
1045  return preg_replace( "/^$prefix/i", '', $text );
1046  }
1047 
1053  public function setTitle( Title $t ) {
1054  // @phan-suppress-next-next-line PhanUndeclaredMethod
1055  // @fixme Not all implementations of IContextSource have this method!
1056  $this->getContext()->setTitle( $t );
1057  }
1058 
1064  public function setSubtitle( $str ) {
1065  $this->clearSubtitle();
1066  $this->addSubtitle( $str );
1067  }
1068 
1074  public function addSubtitle( $str ) {
1075  if ( $str instanceof Message ) {
1076  $this->mSubtitle[] = $str->setContext( $this->getContext() )->parse();
1077  } else {
1078  $this->mSubtitle[] = $str;
1079  }
1080  }
1081 
1090  public static function buildBacklinkSubtitle( Title $title, $query = [] ) {
1091  if ( $title->isRedirect() ) {
1092  $query['redirect'] = 'no';
1093  }
1094  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
1095  return wfMessage( 'backlinksubtitle' )
1096  ->rawParams( $linkRenderer->makeLink( $title, null, [], $query ) );
1097  }
1098 
1105  public function addBacklinkSubtitle( Title $title, $query = [] ) {
1106  $this->addSubtitle( self::buildBacklinkSubtitle( $title, $query ) );
1107  }
1108 
1112  public function clearSubtitle() {
1113  $this->mSubtitle = [];
1114  }
1115 
1121  public function getSubtitle() {
1122  return implode( "<br />\n\t\t\t\t", $this->mSubtitle );
1123  }
1124 
1129  public function setPrintable() {
1130  $this->mPrintable = true;
1131  }
1132 
1138  public function isPrintable() {
1139  return $this->mPrintable;
1140  }
1141 
1145  public function disable() {
1146  $this->mDoNothing = true;
1147  }
1148 
1154  public function isDisabled() {
1155  return $this->mDoNothing;
1156  }
1157 
1163  public function showNewSectionLink() {
1164  return $this->mNewSectionLink;
1165  }
1166 
1172  public function forceHideNewSectionLink() {
1174  }
1175 
1184  public function setSyndicated( $show = true ) {
1185  if ( $show ) {
1186  $this->setFeedAppendQuery( false );
1187  } else {
1188  $this->mFeedLinks = [];
1189  }
1190  }
1191 
1198  protected function getAdvertisedFeedTypes() {
1199  if ( $this->getConfig()->get( 'Feed' ) ) {
1200  return $this->getConfig()->get( 'AdvertisedFeedTypes' );
1201  } else {
1202  return [];
1203  }
1204  }
1205 
1215  public function setFeedAppendQuery( $val ) {
1216  $this->mFeedLinks = [];
1217 
1218  foreach ( $this->getAdvertisedFeedTypes() as $type ) {
1219  $query = "feed=$type";
1220  if ( is_string( $val ) ) {
1221  $query .= '&' . $val;
1222  }
1223  $this->mFeedLinks[$type] = $this->getTitle()->getLocalURL( $query );
1224  }
1225  }
1226 
1233  public function addFeedLink( $format, $href ) {
1234  if ( in_array( $format, $this->getAdvertisedFeedTypes() ) ) {
1235  $this->mFeedLinks[$format] = $href;
1236  }
1237  }
1238 
1243  public function isSyndicated() {
1244  return count( $this->mFeedLinks ) > 0;
1245  }
1246 
1251  public function getSyndicationLinks() {
1252  return $this->mFeedLinks;
1253  }
1254 
1260  public function getFeedAppendQuery() {
1262  }
1263 
1271  public function setArticleFlag( $newVal ) {
1272  $this->mIsArticle = $newVal;
1273  if ( $newVal ) {
1274  $this->mIsArticleRelated = $newVal;
1275  }
1276  }
1277 
1284  public function isArticle() {
1285  return $this->mIsArticle;
1286  }
1287 
1294  public function setArticleRelated( $newVal ) {
1295  $this->mIsArticleRelated = $newVal;
1296  if ( !$newVal ) {
1297  $this->mIsArticle = false;
1298  }
1299  }
1300 
1306  public function isArticleRelated() {
1307  return $this->mIsArticleRelated;
1308  }
1309 
1315  public function setCopyright( $hasCopyright ) {
1316  $this->mHasCopyright = $hasCopyright;
1317  }
1318 
1328  public function showsCopyright() {
1329  return $this->isArticle() || $this->mHasCopyright;
1330  }
1331 
1338  public function addLanguageLinks( array $newLinkArray ) {
1339  $this->mLanguageLinks = array_merge( $this->mLanguageLinks, $newLinkArray );
1340  }
1341 
1348  public function setLanguageLinks( array $newLinkArray ) {
1349  $this->mLanguageLinks = $newLinkArray;
1350  }
1351 
1357  public function getLanguageLinks() {
1358  return $this->mLanguageLinks;
1359  }
1360 
1366  public function addCategoryLinks( array $categories ) {
1367  if ( !$categories ) {
1368  return;
1369  }
1370 
1371  $res = $this->addCategoryLinksToLBAndGetResult( $categories );
1372 
1373  # Set all the values to 'normal'.
1374  $categories = array_fill_keys( array_keys( $categories ), 'normal' );
1375 
1376  # Mark hidden categories
1377  foreach ( $res as $row ) {
1378  if ( isset( $row->pp_value ) ) {
1379  $categories[$row->page_title] = 'hidden';
1380  }
1381  }
1382 
1383  # Add the remaining categories to the skin
1384  if ( $this->getHookRunner()->onOutputPageMakeCategoryLinks(
1385  $this, $categories, $this->mCategoryLinks )
1386  ) {
1387  $services = MediaWikiServices::getInstance();
1388  $linkRenderer = $services->getLinkRenderer();
1389  foreach ( $categories as $category => $type ) {
1390  // array keys will cast numeric category names to ints, so cast back to string
1391  $category = (string)$category;
1392  $origcategory = $category;
1393  $title = Title::makeTitleSafe( NS_CATEGORY, $category );
1394  if ( !$title ) {
1395  continue;
1396  }
1397  $services->getContentLanguage()->findVariantLink( $category, $title, true );
1398  if ( $category != $origcategory && array_key_exists( $category, $categories ) ) {
1399  continue;
1400  }
1401  $text = $services->getContentLanguage()->convertHtml( $title->getText() );
1402  $this->mCategories[$type][] = $title->getText();
1403  $this->mCategoryLinks[$type][] = $linkRenderer->makeLink( $title, new HtmlArmor( $text ) );
1404  }
1405  }
1406  }
1407 
1412  protected function addCategoryLinksToLBAndGetResult( array $categories ) {
1413  # Add the links to a LinkBatch
1414  $arr = [ NS_CATEGORY => $categories ];
1415  $lb = new LinkBatch;
1416  $lb->setArray( $arr );
1417 
1418  # Fetch existence plus the hiddencat property
1419  $dbr = wfGetDB( DB_REPLICA );
1420  $fields = array_merge(
1422  [ 'page_namespace', 'page_title', 'pp_value' ]
1423  );
1424 
1425  $res = $dbr->select( [ 'page', 'page_props' ],
1426  $fields,
1427  $lb->constructSet( 'page', $dbr ),
1428  __METHOD__,
1429  [],
1430  [ 'page_props' => [ 'LEFT JOIN', [
1431  'pp_propname' => 'hiddencat',
1432  'pp_page = page_id'
1433  ] ] ]
1434  );
1435 
1436  # Add the results to the link cache
1437  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1438  $lb->addResultToCache( $linkCache, $res );
1439 
1440  return $res;
1441  }
1442 
1448  public function setCategoryLinks( array $categories ) {
1449  $this->mCategoryLinks = [];
1450  $this->addCategoryLinks( $categories );
1451  }
1452 
1461  public function getCategoryLinks() {
1462  return $this->mCategoryLinks;
1463  }
1464 
1474  public function getCategories( $type = 'all' ) {
1475  if ( $type === 'all' ) {
1476  $allCategories = [];
1477  foreach ( $this->mCategories as $categories ) {
1478  $allCategories = array_merge( $allCategories, $categories );
1479  }
1480  return $allCategories;
1481  }
1482  if ( !isset( $this->mCategories[$type] ) ) {
1483  throw new InvalidArgumentException( 'Invalid category type given: ' . $type );
1484  }
1485  return $this->mCategories[$type];
1486  }
1487 
1497  public function setIndicators( array $indicators ) {
1498  $this->mIndicators = $indicators + $this->mIndicators;
1499  // Keep ordered by key
1500  ksort( $this->mIndicators );
1501  }
1502 
1511  public function getIndicators() {
1512  return $this->mIndicators;
1513  }
1514 
1523  public function addHelpLink( $to, $overrideBaseUrl = false ) {
1524  $this->addModuleStyles( 'mediawiki.helplink' );
1525  $text = $this->msg( 'helppage-top-gethelp' )->escaped();
1526 
1527  if ( $overrideBaseUrl ) {
1528  $helpUrl = $to;
1529  } else {
1530  $toUrlencoded = wfUrlencode( str_replace( ' ', '_', $to ) );
1531  $helpUrl = "https://www.mediawiki.org/wiki/Special:MyLanguage/$toUrlencoded";
1532  }
1533 
1534  $link = Html::rawElement(
1535  'a',
1536  [
1537  'href' => $helpUrl,
1538  'target' => '_blank',
1539  'class' => 'mw-helplink',
1540  ],
1541  $text
1542  );
1543 
1544  $this->setIndicators( [ 'mw-helplink' => $link ] );
1545  }
1546 
1555  public function disallowUserJs() {
1556  $this->reduceAllowedModules(
1557  ResourceLoaderModule::TYPE_SCRIPTS,
1558  ResourceLoaderModule::ORIGIN_CORE_INDIVIDUAL
1559  );
1560 
1561  // Site-wide styles are controlled by a config setting, see T73621
1562  // for background on why. User styles are never allowed.
1563  if ( $this->getConfig()->get( 'AllowSiteCSSOnRestrictedPages' ) ) {
1564  $styleOrigin = ResourceLoaderModule::ORIGIN_USER_SITEWIDE;
1565  } else {
1566  $styleOrigin = ResourceLoaderModule::ORIGIN_CORE_INDIVIDUAL;
1567  }
1568  $this->reduceAllowedModules(
1569  ResourceLoaderModule::TYPE_STYLES,
1570  $styleOrigin
1571  );
1572  }
1573 
1580  public function getAllowedModules( $type ) {
1581  if ( $type == ResourceLoaderModule::TYPE_COMBINED ) {
1582  return min( array_values( $this->mAllowedModules ) );
1583  } else {
1584  return $this->mAllowedModules[$type] ?? ResourceLoaderModule::ORIGIN_ALL;
1585  }
1586  }
1587 
1597  public function reduceAllowedModules( $type, $level ) {
1598  $this->mAllowedModules[$type] = min( $this->getAllowedModules( $type ), $level );
1599  }
1600 
1606  public function prependHTML( $text ) {
1607  $this->mBodytext = $text . $this->mBodytext;
1608  }
1609 
1615  public function addHTML( $text ) {
1616  $this->mBodytext .= $text;
1617  }
1618 
1628  public function addElement( $element, array $attribs = [], $contents = '' ) {
1629  $this->addHTML( Html::element( $element, $attribs, $contents ) );
1630  }
1631 
1635  public function clearHTML() {
1636  $this->mBodytext = '';
1637  }
1638 
1644  public function getHTML() {
1645  return $this->mBodytext;
1646  }
1647 
1654  public function parserOptions() {
1655  if ( !$this->mParserOptions ) {
1656  if ( !$this->getUser()->isSafeToLoad() ) {
1657  // $wgUser isn't unstubbable yet, so don't try to get a
1658  // ParserOptions for it. And don't cache this ParserOptions
1659  // either.
1661  $po->setAllowUnsafeRawHtml( false );
1662  $po->isBogus = true;
1663  return $po;
1664  }
1665 
1666  $this->mParserOptions = ParserOptions::newFromContext( $this->getContext() );
1667  $this->mParserOptions->setAllowUnsafeRawHtml( false );
1668  }
1669 
1670  return $this->mParserOptions;
1671  }
1672 
1680  public function setRevisionId( $revid ) {
1681  $val = $revid === null ? null : intval( $revid );
1682  return wfSetVar( $this->mRevisionId, $val, true );
1683  }
1684 
1690  public function getRevisionId() {
1691  return $this->mRevisionId;
1692  }
1693 
1700  public function isRevisionCurrent() {
1701  return $this->mRevisionId == 0 || $this->mRevisionId == $this->getTitle()->getLatestRevID();
1702  }
1703 
1711  public function setRevisionTimestamp( $timestamp ) {
1712  return wfSetVar( $this->mRevisionTimestamp, $timestamp, true );
1713  }
1714 
1721  public function getRevisionTimestamp() {
1723  }
1724 
1731  public function setFileVersion( $file ) {
1732  $val = null;
1733  if ( $file instanceof File && $file->exists() ) {
1734  $val = [ 'time' => $file->getTimestamp(), 'sha1' => $file->getSha1() ];
1735  }
1736  return wfSetVar( $this->mFileVersion, $val, true );
1737  }
1738 
1744  public function getFileVersion() {
1745  return $this->mFileVersion;
1746  }
1747 
1754  public function getTemplateIds() {
1755  return $this->mTemplateIds;
1756  }
1757 
1764  public function getFileSearchOptions() {
1765  return $this->mImageTimeKeys;
1766  }
1767 
1784  public function addWikiTextAsInterface(
1785  $text, $linestart = true, Title $title = null
1786  ) {
1787  if ( $title === null ) {
1788  $title = $this->getTitle();
1789  }
1790  if ( !$title ) {
1791  throw new MWException( 'Title is null' );
1792  }
1793  $this->addWikiTextTitleInternal( $text, $title, $linestart, /*interface*/true );
1794  }
1795 
1809  public function wrapWikiTextAsInterface(
1810  $wrapperClass, $text
1811  ) {
1812  $this->addWikiTextTitleInternal(
1813  $text, $this->getTitle(),
1814  /*linestart*/true, /*interface*/true,
1815  $wrapperClass
1816  );
1817  }
1818 
1834  public function addWikiTextAsContent(
1835  $text, $linestart = true, Title $title = null
1836  ) {
1837  if ( $title === null ) {
1838  $title = $this->getTitle();
1839  }
1840  if ( !$title ) {
1841  throw new MWException( 'Title is null' );
1842  }
1843  $this->addWikiTextTitleInternal( $text, $title, $linestart, /*interface*/false );
1844  }
1845 
1858  private function addWikiTextTitleInternal(
1859  $text, Title $title, $linestart, $interface, $wrapperClass = null
1860  ) {
1861  $parserOutput = $this->parseInternal(
1862  $text, $title, $linestart, $interface
1863  );
1864 
1865  $this->addParserOutput( $parserOutput, [
1866  'enableSectionEditLinks' => false,
1867  'wrapperDivClass' => $wrapperClass ?? '',
1868  ] );
1869  }
1870 
1879  public function addParserOutputMetadata( ParserOutput $parserOutput ) {
1880  $this->mLanguageLinks =
1881  array_merge( $this->mLanguageLinks, $parserOutput->getLanguageLinks() );
1882  $this->addCategoryLinks( $parserOutput->getCategories() );
1883  $this->setIndicators( $parserOutput->getIndicators() );
1884  $this->mNewSectionLink = $parserOutput->getNewSection();
1885  $this->mHideNewSectionLink = $parserOutput->getHideNewSection();
1886 
1887  if ( !$parserOutput->isCacheable() ) {
1888  $this->enableClientCache( false );
1889  }
1890  $this->mNoGallery = $parserOutput->getNoGallery();
1891  $this->mHeadItems = array_merge( $this->mHeadItems, $parserOutput->getHeadItems() );
1892  $this->addModules( $parserOutput->getModules() );
1893  $this->addModuleStyles( $parserOutput->getModuleStyles() );
1894  $this->addJsConfigVars( $parserOutput->getJsConfigVars() );
1895  $this->mPreventClickjacking = $this->mPreventClickjacking
1896  || $parserOutput->preventClickjacking();
1897  $scriptSrcs = $parserOutput->getExtraCSPScriptSrcs();
1898  foreach ( $scriptSrcs as $src ) {
1899  $this->getCSP()->addScriptSrc( $src );
1900  }
1901  $defaultSrcs = $parserOutput->getExtraCSPDefaultSrcs();
1902  foreach ( $defaultSrcs as $src ) {
1903  $this->getCSP()->addDefaultSrc( $src );
1904  }
1905  $styleSrcs = $parserOutput->getExtraCSPStyleSrcs();
1906  foreach ( $styleSrcs as $src ) {
1907  $this->getCSP()->addStyleSrc( $src );
1908  }
1909 
1910  // If $wgImagePreconnect is true, and if the output contains
1911  // images, give the user-agent a hint about foreign repos from
1912  // which those images may be served. See T123582.
1913  //
1914  // TODO: We don't have an easy way to know from which remote(s)
1915  // the image(s) will be served. For now, we only hint the first
1916  // valid one.
1917  if ( $this->getConfig()->get( 'ImagePreconnect' ) && count( $parserOutput->getImages() ) ) {
1918  $preconnect = [];
1919  $repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
1920  $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$preconnect ) {
1921  $preconnect[] = wfParseUrl( $repo->getZoneUrl( 'thumb' ) )['host'];
1922  } );
1923  $preconnect[] = wfParseUrl( $repoGroup->getLocalRepo()->getZoneUrl( 'thumb' ) )['host'];
1924  foreach ( $preconnect as $host ) {
1925  if ( $host ) {
1926  $this->addLink( [ 'rel' => 'preconnect', 'href' => '//' . $host ] );
1927  break;
1928  }
1929  }
1930  }
1931 
1932  // Template versioning...
1933  foreach ( (array)$parserOutput->getTemplateIds() as $ns => $dbks ) {
1934  if ( isset( $this->mTemplateIds[$ns] ) ) {
1935  $this->mTemplateIds[$ns] = $dbks + $this->mTemplateIds[$ns];
1936  } else {
1937  $this->mTemplateIds[$ns] = $dbks;
1938  }
1939  }
1940  // File versioning...
1941  foreach ( (array)$parserOutput->getFileSearchOptions() as $dbk => $data ) {
1942  $this->mImageTimeKeys[$dbk] = $data;
1943  }
1944 
1945  // Hooks registered in the object
1946  $parserOutputHooks = $this->getConfig()->get( 'ParserOutputHooks' );
1947  foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
1948  list( $hookName, $data ) = $hookInfo;
1949  if ( isset( $parserOutputHooks[$hookName] ) ) {
1950  $parserOutputHooks[$hookName]( $this, $parserOutput, $data );
1951  }
1952  }
1953 
1954  // Enable OOUI if requested via ParserOutput
1955  if ( $parserOutput->getEnableOOUI() ) {
1956  $this->enableOOUI();
1957  }
1958 
1959  // Include parser limit report
1960  if ( !$this->limitReportJSData ) {
1961  $this->limitReportJSData = $parserOutput->getLimitReportJSData();
1962  }
1963 
1964  // Link flags are ignored for now, but may in the future be
1965  // used to mark individual language links.
1966  $linkFlags = [];
1967  $this->getHookRunner()->onLanguageLinks( $this->getTitle(), $this->mLanguageLinks, $linkFlags );
1968  $this->getHookRunner()->onOutputPageParserOutput( $this, $parserOutput );
1969 
1970  // This check must be after 'OutputPageParserOutput' runs in addParserOutputMetadata
1971  // so that extensions may modify ParserOutput to toggle TOC.
1972  // This cannot be moved to addParserOutputText because that is not
1973  // called by EditPage for Preview.
1974  if ( $parserOutput->getTOCHTML() ) {
1975  $this->mEnableTOC = true;
1976  }
1977  }
1978 
1987  public function addParserOutputContent( ParserOutput $parserOutput, $poOptions = [] ) {
1988  $this->addParserOutputText( $parserOutput, $poOptions );
1989 
1990  $this->addModules( $parserOutput->getModules() );
1991  $this->addModuleStyles( $parserOutput->getModuleStyles() );
1992 
1993  $this->addJsConfigVars( $parserOutput->getJsConfigVars() );
1994  }
1995 
2003  public function addParserOutputText( ParserOutput $parserOutput, $poOptions = [] ) {
2004  $text = $parserOutput->getText( $poOptions );
2005  $this->getHookRunner()->onOutputPageBeforeHTML( $this, $text );
2006  $this->addHTML( $text );
2007  }
2008 
2015  public function addParserOutput( ParserOutput $parserOutput, $poOptions = [] ) {
2016  $this->addParserOutputMetadata( $parserOutput );
2017  $this->addParserOutputText( $parserOutput, $poOptions );
2018  }
2019 
2025  public function addTemplate( &$template ) {
2026  $this->addHTML( $template->getHTML() );
2027  }
2028 
2040  public function parseAsContent( $text, $linestart = true ) {
2041  return $this->parseInternal(
2042  $text, $this->getTitle(), $linestart, /*interface*/false
2043  )->getText( [
2044  'enableSectionEditLinks' => false,
2045  'wrapperDivClass' => ''
2046  ] );
2047  }
2048 
2061  public function parseAsInterface( $text, $linestart = true ) {
2062  return $this->parseInternal(
2063  $text, $this->getTitle(), $linestart, /*interface*/true
2064  )->getText( [
2065  'enableSectionEditLinks' => false,
2066  'wrapperDivClass' => ''
2067  ] );
2068  }
2069 
2084  public function parseInlineAsInterface( $text, $linestart = true ) {
2086  $this->parseAsInterface( $text, $linestart )
2087  );
2088  }
2089 
2102  private function parseInternal( $text, $title, $linestart, $interface ) {
2103  if ( $title === null ) {
2104  throw new MWException( 'Empty $mTitle in ' . __METHOD__ );
2105  }
2106 
2107  $popts = $this->parserOptions();
2108 
2109  $oldInterface = $popts->setInterfaceMessage( (bool)$interface );
2110 
2111  $parserOutput = MediaWikiServices::getInstance()->getParser()->getFreshParser()->parse(
2112  $text, $title, $popts,
2113  $linestart, true, $this->mRevisionId
2114  );
2115 
2116  $popts->setInterfaceMessage( $oldInterface );
2117 
2118  return $parserOutput;
2119  }
2120 
2126  public function setCdnMaxage( $maxage ) {
2127  $this->mCdnMaxage = min( $maxage, $this->mCdnMaxageLimit );
2128  }
2129 
2139  public function lowerCdnMaxage( $maxage ) {
2140  $this->mCdnMaxageLimit = min( $maxage, $this->mCdnMaxageLimit );
2141  $this->setCdnMaxage( $this->mCdnMaxage );
2142  }
2143 
2156  public function adaptCdnTTL( $mtime, $minTTL = 0, $maxTTL = 0 ) {
2157  $minTTL = $minTTL ?: IExpiringStore::TTL_MINUTE;
2158  $maxTTL = $maxTTL ?: $this->getConfig()->get( 'CdnMaxAge' );
2159 
2160  if ( $mtime === null || $mtime === false ) {
2161  return; // entity does not exist
2162  }
2163 
2164  $age = MWTimestamp::time() - (int)wfTimestamp( TS_UNIX, $mtime );
2165  $adaptiveTTL = max( 0.9 * $age, $minTTL );
2166  $adaptiveTTL = min( $adaptiveTTL, $maxTTL );
2167 
2168  $this->lowerCdnMaxage( (int)$adaptiveTTL );
2169  }
2170 
2178  public function enableClientCache( $state ) {
2179  return wfSetVar( $this->mEnableClientCache, $state );
2180  }
2181 
2188  public function couldBePublicCached() {
2189  if ( !$this->cacheIsFinal ) {
2190  // - The entry point handles its own caching and/or doesn't use OutputPage.
2191  // (such as load.php, AjaxDispatcher, or MediaWiki\Rest\EntryPoint).
2192  //
2193  // - Or, we haven't finished processing the main part of the request yet
2194  // (e.g. Action::show, SpecialPage::execute), and the state may still
2195  // change via enableClientCache().
2196  return true;
2197  }
2198  // e.g. various error-type pages disable all client caching
2200  }
2201 
2211  public function considerCacheSettingsFinal() {
2212  $this->cacheIsFinal = true;
2213  }
2214 
2220  public function getCacheVaryCookies() {
2221  if ( self::$cacheVaryCookies === null ) {
2222  $config = $this->getConfig();
2223  self::$cacheVaryCookies = array_values( array_unique( array_merge(
2224  SessionManager::singleton()->getVaryCookies(),
2225  [
2226  'forceHTTPS',
2227  ],
2228  $config->get( 'CacheVaryCookies' )
2229  ) ) );
2230  $this->getHookRunner()->onGetCacheVaryCookies( $this, self::$cacheVaryCookies );
2231  }
2232  return self::$cacheVaryCookies;
2233  }
2234 
2241  public function haveCacheVaryCookies() {
2242  $request = $this->getRequest();
2243  foreach ( $this->getCacheVaryCookies() as $cookieName ) {
2244  if ( $request->getCookie( $cookieName, '', '' ) !== '' ) {
2245  wfDebug( __METHOD__ . ": found $cookieName" );
2246  return true;
2247  }
2248  }
2249  wfDebug( __METHOD__ . ": no cache-varying cookies found" );
2250  return false;
2251  }
2252 
2262  public function addVaryHeader( $header, array $option = null ) {
2263  if ( $option !== null && count( $option ) > 0 ) {
2265  'The $option parameter to addVaryHeader is ignored since MediaWiki 1.34',
2266  '1.34' );
2267  }
2268  if ( !array_key_exists( $header, $this->mVaryHeader ) ) {
2269  $this->mVaryHeader[$header] = null;
2270  }
2271  }
2272 
2279  public function getVaryHeader() {
2280  // If we vary on cookies, let's make sure it's always included here too.
2281  if ( $this->getCacheVaryCookies() ) {
2282  $this->addVaryHeader( 'Cookie' );
2283  }
2284 
2285  foreach ( SessionManager::singleton()->getVaryHeaders() as $header => $options ) {
2286  $this->addVaryHeader( $header, $options );
2287  }
2288  return 'Vary: ' . implode( ', ', array_keys( $this->mVaryHeader ) );
2289  }
2290 
2296  public function addLinkHeader( $header ) {
2297  $this->mLinkHeader[] = $header;
2298  }
2299 
2305  public function getLinkHeader() {
2306  if ( !$this->mLinkHeader ) {
2307  return false;
2308  }
2309 
2310  return 'Link: ' . implode( ',', $this->mLinkHeader );
2311  }
2312 
2320  private function addAcceptLanguage() {
2321  $title = $this->getTitle();
2322  if ( !$title instanceof Title ) {
2323  return;
2324  }
2325 
2326  $lang = $title->getPageLanguage();
2327  if ( !$this->getRequest()->getCheck( 'variant' ) && $lang->hasVariants() ) {
2328  $this->addVaryHeader( 'Accept-Language' );
2329  }
2330  }
2331 
2342  public function preventClickjacking( $enable = true ) {
2343  $this->mPreventClickjacking = $enable;
2344  }
2345 
2351  public function allowClickjacking() {
2352  $this->mPreventClickjacking = false;
2353  }
2354 
2361  public function getPreventClickjacking() {
2363  }
2364 
2372  public function getFrameOptions() {
2373  $config = $this->getConfig();
2374  if ( $config->get( 'BreakFrames' ) ) {
2375  return 'DENY';
2376  } elseif ( $this->mPreventClickjacking && $config->get( 'EditPageFrameOptions' ) ) {
2377  return $config->get( 'EditPageFrameOptions' );
2378  }
2379  return false;
2380  }
2381 
2388  private function getOriginTrials() {
2389  $config = $this->getConfig();
2390 
2391  return $config->get( 'OriginTrials' );
2392  }
2393 
2394  private function getReportTo() {
2395  $config = $this->getConfig();
2396 
2397  $expiry = $config->get( 'ReportToExpiry' );
2398 
2399  if ( !$expiry ) {
2400  return false;
2401  }
2402 
2403  $endpoints = $config->get( 'ReportToEndpoints' );
2404 
2405  if ( !$endpoints ) {
2406  return false;
2407  }
2408 
2409  $output = [ 'max_age' => $expiry, 'endpoints' => [] ];
2410 
2411  foreach ( $endpoints as $endpoint ) {
2412  $output['endpoints'][] = [ 'url' => $endpoint ];
2413  }
2414 
2415  return json_encode( $output, JSON_UNESCAPED_SLASHES );
2416  }
2417 
2418  private function getFeaturePolicyReportOnly() {
2419  $config = $this->getConfig();
2420 
2421  $features = $config->get( 'FeaturePolicyReportOnly' );
2422  return implode( ';', $features );
2423  }
2424 
2428  public function sendCacheControl() {
2429  $response = $this->getRequest()->response();
2430  $config = $this->getConfig();
2431 
2432  $this->addVaryHeader( 'Cookie' );
2433  $this->addAcceptLanguage();
2434 
2435  # don't serve compressed data to clients who can't handle it
2436  # maintain different caches for logged-in users and non-logged in ones
2437  $response->header( $this->getVaryHeader() );
2438 
2439  if ( $this->mEnableClientCache ) {
2440  if (
2441  $config->get( 'UseCdn' ) &&
2442  !$response->hasCookies() &&
2443  // The client might use methods other than cookies to appear logged-in.
2444  // E.g. HTTP headers, or query parameter tokens, OAuth, etc.
2445  !SessionManager::getGlobalSession()->isPersistent() &&
2446  !$this->isPrintable() &&
2447  $this->mCdnMaxage != 0 &&
2448  !$this->haveCacheVaryCookies()
2449  ) {
2450  # We'll purge the proxy cache for anons explicitly, but require end user agents
2451  # to revalidate against the proxy on each visit.
2452  # IMPORTANT! The CDN needs to replace the Cache-Control header with
2453  # Cache-Control: s-maxage=0, must-revalidate, max-age=0
2454  wfDebug( __METHOD__ .
2455  ": local proxy caching; {$this->mLastModified} **", 'private' );
2456  # start with a shorter timeout for initial testing
2457  # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
2458  $response->header( "Cache-Control: " .
2459  "s-maxage={$this->mCdnMaxage}, must-revalidate, max-age=0" );
2460  } else {
2461  # We do want clients to cache if they can, but they *must* check for updates
2462  # on revisiting the page, after the max-age period.
2463  wfDebug( __METHOD__ . ": private caching; {$this->mLastModified} **", 'private' );
2464 
2465  if ( $response->hasCookies() || SessionManager::getGlobalSession()->isPersistent() ) {
2466  $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
2467  $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
2468  } else {
2469  $response->header(
2470  'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $config->get( 'LoggedOutMaxAge' ) ) . ' GMT'
2471  );
2472  $response->header(
2473  "Cache-Control: private, must-revalidate, max-age={$config->get( 'LoggedOutMaxAge' )}"
2474  );
2475  }
2476  }
2477  if ( $this->mLastModified ) {
2478  $response->header( "Last-Modified: {$this->mLastModified}" );
2479  }
2480  } else {
2481  wfDebug( __METHOD__ . ": no caching **", 'private' );
2482 
2483  # In general, the absence of a last modified header should be enough to prevent
2484  # the client from using its cache. We send a few other things just to make sure.
2485  $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
2486  $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
2487  $response->header( 'Pragma: no-cache' );
2488  }
2489  }
2490 
2496  public function loadSkinModules( $sk ) {
2497  foreach ( $sk->getDefaultModules() as $group => $modules ) {
2498  if ( $group === 'styles' ) {
2499  foreach ( $modules as $key => $moduleMembers ) {
2500  $this->addModuleStyles( $moduleMembers );
2501  }
2502  } else {
2503  $this->addModules( $modules );
2504  }
2505  }
2506  }
2507 
2518  public function output( $return = false ) {
2519  if ( $this->mDoNothing ) {
2520  return $return ? '' : null;
2521  }
2522 
2523  $response = $this->getRequest()->response();
2524  $config = $this->getConfig();
2525 
2526  if ( $this->mRedirect != '' ) {
2527  # Standards require redirect URLs to be absolute
2528  $this->mRedirect = wfExpandUrl( $this->mRedirect, PROTO_CURRENT );
2529 
2530  $redirect = $this->mRedirect;
2531  $code = $this->mRedirectCode;
2532 
2533  if ( $this->getHookRunner()->onBeforePageRedirect( $this, $redirect, $code ) ) {
2534  if ( $code == '301' || $code == '303' ) {
2535  if ( !$config->get( 'DebugRedirects' ) ) {
2536  $response->statusHeader( $code );
2537  }
2538  $this->mLastModified = wfTimestamp( TS_RFC2822 );
2539  }
2540  if ( $config->get( 'VaryOnXFP' ) ) {
2541  $this->addVaryHeader( 'X-Forwarded-Proto' );
2542  }
2543  $this->sendCacheControl();
2544 
2545  $response->header( "Content-Type: text/html; charset=utf-8" );
2546  if ( $config->get( 'DebugRedirects' ) ) {
2547  $url = htmlspecialchars( $redirect );
2548  print "<!DOCTYPE html>\n<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
2549  print "<p>Location: <a href=\"$url\">$url</a></p>\n";
2550  print "</body>\n</html>\n";
2551  } else {
2552  $response->header( 'Location: ' . $redirect );
2553  }
2554  }
2555 
2556  return $return ? '' : null;
2557  } elseif ( $this->mStatusCode ) {
2558  $response->statusHeader( $this->mStatusCode );
2559  }
2560 
2561  # Buffer output; final headers may depend on later processing
2562  ob_start();
2563 
2564  $response->header( 'Content-type: ' . $config->get( 'MimeType' ) . '; charset=UTF-8' );
2565  $response->header( 'Content-language: ' .
2566  MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() );
2567 
2568  $linkHeader = $this->getLinkHeader();
2569  if ( $linkHeader ) {
2570  $response->header( $linkHeader );
2571  }
2572 
2573  // Prevent framing, if requested
2574  $frameOptions = $this->getFrameOptions();
2575  if ( $frameOptions ) {
2576  $response->header( "X-Frame-Options: $frameOptions" );
2577  }
2578 
2579  $originTrials = $this->getOriginTrials();
2580  foreach ( $originTrials as $originTrial ) {
2581  $response->header( "Origin-Trial: $originTrial", false );
2582  }
2583 
2584  $reportTo = $this->getReportTo();
2585  if ( $reportTo ) {
2586  $response->header( "Report-To: $reportTo" );
2587  }
2588 
2589  $featurePolicyReportOnly = $this->getFeaturePolicyReportOnly();
2590  if ( $featurePolicyReportOnly ) {
2591  $response->header( "Feature-Policy-Report-Only: $featurePolicyReportOnly" );
2592  }
2593 
2594  if ( $this->mArticleBodyOnly ) {
2595  $this->CSP->sendHeaders();
2596  echo $this->mBodytext;
2597  } else {
2598  // Enable safe mode if requested (T152169)
2599  if ( $this->getRequest()->getBool( 'safemode' ) ) {
2600  $this->disallowUserJs();
2601  }
2602 
2603  $sk = $this->getSkin();
2604  $this->loadSkinModules( $sk );
2605 
2606  MWDebug::addModules( $this );
2607 
2608  // Hook that allows last minute changes to the output page, e.g.
2609  // adding of CSS or Javascript by extensions, adding CSP sources.
2610  $this->getHookRunner()->onBeforePageDisplay( $this, $sk );
2611 
2612  $this->CSP->sendHeaders();
2613 
2614  try {
2615  $sk->outputPage();
2616  } catch ( Exception $e ) {
2617  ob_end_clean(); // bug T129657
2618  throw $e;
2619  }
2620  }
2621 
2622  try {
2623  // This hook allows last minute changes to final overall output by modifying output buffer
2624  $this->getHookRunner()->onAfterFinalPageOutput( $this );
2625  } catch ( Exception $e ) {
2626  ob_end_clean(); // bug T129657
2627  throw $e;
2628  }
2629 
2630  $this->sendCacheControl();
2631 
2632  if ( $return ) {
2633  return ob_get_clean();
2634  } else {
2635  ob_end_flush();
2636  return null;
2637  }
2638  }
2639 
2650  public function prepareErrorPage( $pageTitle, $htmlTitle = false ) {
2651  $this->setPageTitle( $pageTitle );
2652  if ( $htmlTitle !== false ) {
2653  $this->setHTMLTitle( $htmlTitle );
2654  }
2655  $this->setRobotPolicy( 'noindex,nofollow' );
2656  $this->setArticleRelated( false );
2657  $this->enableClientCache( false );
2658  $this->mRedirect = '';
2659  $this->clearSubtitle();
2660  $this->clearHTML();
2661  }
2662 
2675  public function showErrorPage( $title, $msg, $params = [] ) {
2676  if ( !$title instanceof Message ) {
2677  $title = $this->msg( $title );
2678  }
2679 
2680  $this->prepareErrorPage( $title );
2681 
2682  if ( $msg instanceof Message ) {
2683  if ( $params !== [] ) {
2684  trigger_error( 'Argument ignored: $params. The message parameters argument '
2685  . 'is discarded when the $msg argument is a Message object instead of '
2686  . 'a string.', E_USER_NOTICE );
2687  }
2688  $this->addHTML( $msg->parseAsBlock() );
2689  } else {
2690  $this->addWikiMsgArray( $msg, $params );
2691  }
2692 
2693  $this->returnToMain();
2694  }
2695 
2702  public function showPermissionsErrorPage( array $errors, $action = null ) {
2703  $services = MediaWikiServices::getInstance();
2704  $permissionManager = $services->getPermissionManager();
2705  foreach ( $errors as $key => $error ) {
2706  $errors[$key] = (array)$error;
2707  }
2708 
2709  // For some action (read, edit, create and upload), display a "login to do this action"
2710  // error if all of the following conditions are met:
2711  // 1. the user is not logged in
2712  // 2. the only error is insufficient permissions (i.e. no block or something else)
2713  // 3. the error can be avoided simply by logging in
2714 
2715  if ( in_array( $action, [ 'read', 'edit', 'createpage', 'createtalk', 'upload' ] )
2716  && $this->getUser()->isAnon() && count( $errors ) == 1 && isset( $errors[0][0] )
2717  && ( $errors[0][0] == 'badaccess-groups' || $errors[0][0] == 'badaccess-group0' )
2718  && ( $permissionManager->groupHasPermission( 'user', $action )
2719  || $permissionManager->groupHasPermission( 'autoconfirmed', $action ) )
2720  ) {
2721  $displayReturnto = null;
2722 
2723  # Due to T34276, if a user does not have read permissions,
2724  # $this->getTitle() will just give Special:Badtitle, which is
2725  # not especially useful as a returnto parameter. Use the title
2726  # from the request instead, if there was one.
2727  $request = $this->getRequest();
2728  $returnto = Title::newFromText( $request->getVal( 'title', '' ) );
2729  if ( $action == 'edit' ) {
2730  $msg = 'whitelistedittext';
2731  $displayReturnto = $returnto;
2732  } elseif ( $action == 'createpage' || $action == 'createtalk' ) {
2733  $msg = 'nocreatetext';
2734  } elseif ( $action == 'upload' ) {
2735  $msg = 'uploadnologintext';
2736  } else { # Read
2737  $msg = 'loginreqpagetext';
2738  $displayReturnto = Title::newMainPage();
2739  }
2740 
2741  $query = [];
2742 
2743  if ( $returnto ) {
2744  $query['returnto'] = $returnto->getPrefixedText();
2745 
2746  if ( !$request->wasPosted() ) {
2747  $returntoquery = $request->getValues();
2748  unset( $returntoquery['title'] );
2749  unset( $returntoquery['returnto'] );
2750  unset( $returntoquery['returntoquery'] );
2751  $query['returntoquery'] = wfArrayToCgi( $returntoquery );
2752  }
2753  }
2754 
2755  $title = SpecialPage::getTitleFor( 'Userlogin' );
2756  $linkRenderer = $services->getLinkRenderer();
2757  $loginUrl = $title->getLinkURL( $query, false, PROTO_RELATIVE );
2758  $loginLink = $linkRenderer->makeKnownLink(
2759  $title,
2760  $this->msg( 'loginreqlink' )->text(),
2761  [],
2762  $query
2763  );
2764 
2765  $this->prepareErrorPage( $this->msg( 'loginreqtitle' ) );
2766  $this->addHTML( $this->msg( $msg )->rawParams( $loginLink )->params( $loginUrl )->parse() );
2767 
2768  # Don't return to a page the user can't read otherwise
2769  # we'll end up in a pointless loop
2770  if ( $displayReturnto && $permissionManager->userCan(
2771  'read', $this->getUser(), $displayReturnto
2772  ) ) {
2773  $this->returnToMain( null, $displayReturnto );
2774  }
2775  } else {
2776  $this->prepareErrorPage( $this->msg( 'permissionserrors' ) );
2777  $this->addWikiTextAsInterface( $this->formatPermissionsErrorMessage( $errors, $action ) );
2778  }
2779  }
2780 
2787  public function versionRequired( $version ) {
2788  $this->prepareErrorPage( $this->msg( 'versionrequired', $version ) );
2789 
2790  $this->addWikiMsg( 'versionrequiredtext', $version );
2791  $this->returnToMain();
2792  }
2793 
2801  public function formatPermissionsErrorMessage( array $errors, $action = null ) {
2802  if ( $action == null ) {
2803  $text = $this->msg( 'permissionserrorstext', count( $errors ) )->plain() . "\n\n";
2804  } else {
2805  $action_desc = $this->msg( "action-$action" )->plain();
2806  $text = $this->msg(
2807  'permissionserrorstext-withaction',
2808  count( $errors ),
2809  $action_desc
2810  )->plain() . "\n\n";
2811  }
2812 
2813  if ( count( $errors ) > 1 ) {
2814  $text .= '<ul class="permissions-errors">' . "\n";
2815 
2816  foreach ( $errors as $error ) {
2817  $text .= '<li>';
2818  $text .= $this->msg( ...$error )->plain();
2819  $text .= "</li>\n";
2820  }
2821  $text .= '</ul>';
2822  } else {
2823  $text .= "<div class=\"permissions-errors\">\n" .
2824  $this->msg( ...reset( $errors ) )->plain() .
2825  "\n</div>";
2826  }
2827 
2828  return $text;
2829  }
2830 
2840  public function showLagWarning( $lag ) {
2841  $config = $this->getConfig();
2842  if ( $lag >= $config->get( 'SlaveLagWarning' ) ) {
2843  $lag = floor( $lag ); // floor to avoid nano seconds to display
2844  $message = $lag < $config->get( 'SlaveLagCritical' )
2845  ? 'lag-warn-normal'
2846  : 'lag-warn-high';
2847  // For grep: mw-lag-warn-normal, mw-lag-warn-high
2848  $wrap = Html::rawElement( 'div', [ 'class' => "mw-{$message}" ], "\n$1\n" );
2849  $this->wrapWikiMsg( "$wrap\n", [ $message, $this->getLanguage()->formatNum( $lag ) ] );
2850  }
2851  }
2852 
2859  public function showFatalError( $message ) {
2860  $this->prepareErrorPage( $this->msg( 'internalerror' ) );
2861 
2862  $this->addHTML( $message );
2863  }
2864 
2873  public function addReturnTo( $title, array $query = [], $text = null, $options = [] ) {
2874  $linkRenderer = MediaWikiServices::getInstance()
2875  ->getLinkRendererFactory()->createFromLegacyOptions( $options );
2876  $link = $this->msg( 'returnto' )->rawParams(
2877  $linkRenderer->makeLink( $title, $text, [], $query ) )->escaped();
2878  $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
2879  }
2880 
2889  public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) {
2890  if ( $returnto == null ) {
2891  $returnto = $this->getRequest()->getText( 'returnto' );
2892  }
2893 
2894  if ( $returntoquery == null ) {
2895  $returntoquery = $this->getRequest()->getText( 'returntoquery' );
2896  }
2897 
2898  if ( $returnto === '' ) {
2899  $returnto = Title::newMainPage();
2900  }
2901 
2902  if ( is_object( $returnto ) ) {
2903  $titleObj = $returnto;
2904  } else {
2905  $titleObj = Title::newFromText( $returnto );
2906  }
2907  // We don't want people to return to external interwiki. That
2908  // might potentially be used as part of a phishing scheme
2909  if ( !is_object( $titleObj ) || $titleObj->isExternal() ) {
2910  $titleObj = Title::newMainPage();
2911  }
2912 
2913  $this->addReturnTo( $titleObj, wfCgiToArray( $returntoquery ) );
2914  }
2915 
2916  private function getRlClientContext() {
2917  if ( !$this->rlClientContext ) {
2919  [], // modules; not relevant
2920  $this->getLanguage()->getCode(),
2921  $this->getSkin()->getSkinName(),
2922  $this->getUser()->isLoggedIn() ? $this->getUser()->getName() : null,
2923  null, // version; not relevant
2925  null, // only; not relevant
2926  $this->isPrintable(),
2927  $this->getRequest()->getBool( 'handheld' )
2928  );
2929  $this->rlClientContext = new ResourceLoaderContext(
2930  $this->getResourceLoader(),
2931  new FauxRequest( $query )
2932  );
2933  if ( $this->contentOverrideCallbacks ) {
2934  $this->rlClientContext = new DerivativeResourceLoaderContext( $this->rlClientContext );
2935  $this->rlClientContext->setContentOverrideCallback( function ( Title $title ) {
2936  foreach ( $this->contentOverrideCallbacks as $callback ) {
2937  $content = $callback( $title );
2938  if ( $content !== null ) {
2940  if ( strpos( $text, '</script>' ) !== false ) {
2941  // Proactively replace this so that we can display a message
2942  // to the user, instead of letting it go to Html::inlineScript(),
2943  // where it would be considered a server-side issue.
2944  $titleFormatted = $title->getPrefixedText();
2946  Xml::encodeJsCall( 'mw.log.error', [
2947  "Cannot preview $titleFormatted due to script-closing tag."
2948  ] )
2949  );
2950  }
2951  return $content;
2952  }
2953  }
2954  return null;
2955  } );
2956  }
2957  }
2958  return $this->rlClientContext;
2959  }
2960 
2972  public function getRlClient() {
2973  if ( !$this->rlClient ) {
2974  $context = $this->getRlClientContext();
2975  $rl = $this->getResourceLoader();
2976  $this->addModules( [
2977  'user',
2978  'user.options',
2979  ] );
2980  $this->addModuleStyles( [
2981  'site.styles',
2982  'noscript',
2983  'user.styles',
2984  ] );
2985 
2986  // Prepare exempt modules for buildExemptModules()
2987  $exemptGroups = [ 'site' => [], 'noscript' => [], 'private' => [], 'user' => [] ];
2988  $exemptStates = [];
2989  $moduleStyles = $this->getModuleStyles( /*filter*/ true );
2990 
2991  // Preload getTitleInfo for isKnownEmpty calls below and in ResourceLoaderClientHtml
2992  // Separate user-specific batch for improved cache-hit ratio.
2993  $userBatch = [ 'user.styles', 'user' ];
2994  $siteBatch = array_diff( $moduleStyles, $userBatch );
2995  $dbr = wfGetDB( DB_REPLICA );
2998 
2999  // Filter out modules handled by buildExemptModules()
3000  $moduleStyles = array_filter( $moduleStyles,
3001  function ( $name ) use ( $rl, $context, &$exemptGroups, &$exemptStates ) {
3002  $module = $rl->getModule( $name );
3003  if ( $module ) {
3004  $group = $module->getGroup();
3005  if ( isset( $exemptGroups[$group] ) ) {
3006  $exemptStates[$name] = 'ready';
3007  if ( !$module->isKnownEmpty( $context ) ) {
3008  // E.g. Don't output empty <styles>
3009  $exemptGroups[$group][] = $name;
3010  }
3011  return false;
3012  }
3013  }
3014  return true;
3015  }
3016  );
3017  $this->rlExemptStyleModules = $exemptGroups;
3018 
3020  'target' => $this->getTarget(),
3021  'nonce' => $this->CSP->getNonce(),
3022  // When 'safemode', disallowUserJs(), or reduceAllowedModules() is used
3023  // to only restrict modules to ORIGIN_CORE (ie. disallow ORIGIN_USER), the list of
3024  // modules enqueud for loading on this page is filtered to just those.
3025  // However, to make sure we also apply the restriction to dynamic dependencies and
3026  // lazy-loaded modules at run-time on the client-side, pass 'safemode' down to the
3027  // StartupModule so that the client-side registry will not contain any restricted
3028  // modules either. (T152169, T185303)
3029  'safemode' => ( $this->getAllowedModules( ResourceLoaderModule::TYPE_COMBINED )
3030  <= ResourceLoaderModule::ORIGIN_CORE_INDIVIDUAL
3031  ) ? '1' : null,
3032  ] );
3033  $rlClient->setConfig( $this->getJSVars() );
3034  $rlClient->setModules( $this->getModules( /*filter*/ true ) );
3035  $rlClient->setModuleStyles( $moduleStyles );
3036  $rlClient->setExemptStates( $exemptStates );
3037  $this->rlClient = $rlClient;
3038  }
3039  return $this->rlClient;
3040  }
3041 
3047  public function headElement( Skin $sk, $includeStyle = true ) {
3048  $config = $this->getConfig();
3049  $userdir = $this->getLanguage()->getDir();
3050  $sitedir = MediaWikiServices::getInstance()->getContentLanguage()->getDir();
3051 
3052  $pieces = [];
3054  $this->getRlClient()->getDocumentAttributes(),
3056  ), [ 'class' => implode( ' ', $this->mAdditionalHtmlClasses ) ] );
3057  $pieces[] = Html::htmlHeader( $htmlAttribs );
3058  $pieces[] = Html::openElement( 'head' );
3059 
3060  if ( $this->getHTMLTitle() == '' ) {
3061  $this->setHTMLTitle( $this->msg( 'pagetitle', $this->getPageTitle() )->inContentLanguage() );
3062  }
3063 
3064  if ( !Html::isXmlMimeType( $config->get( 'MimeType' ) ) ) {
3065  // Add <meta charset="UTF-8">
3066  // This should be before <title> since it defines the charset used by
3067  // text including the text inside <title>.
3068  // The spec recommends defining XHTML5's charset using the XML declaration
3069  // instead of meta.
3070  // Our XML declaration is output by Html::htmlHeader.
3071  // https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-content-type
3072  // https://html.spec.whatwg.org/multipage/semantics.html#charset
3073  $pieces[] = Html::element( 'meta', [ 'charset' => 'UTF-8' ] );
3074  }
3075 
3076  $pieces[] = Html::element( 'title', null, $this->getHTMLTitle() );
3077  $pieces[] = $this->getRlClient()->getHeadHtml( $htmlAttribs['class'] ?? null );
3078  $pieces[] = $this->buildExemptModules();
3079  $pieces = array_merge( $pieces, array_values( $this->getHeadLinksArray() ) );
3080  $pieces = array_merge( $pieces, array_values( $this->mHeadItems ) );
3081 
3082  $pieces[] = Html::closeElement( 'head' );
3083 
3084  $bodyClasses = $this->mAdditionalBodyClasses;
3085  $bodyClasses[] = 'mediawiki';
3086 
3087  # Classes for LTR/RTL directionality support
3088  $bodyClasses[] = $userdir;
3089  $bodyClasses[] = "sitedir-$sitedir";
3090 
3091  $underline = $this->getUser()->getOption( 'underline' );
3092  if ( $underline < 2 ) {
3093  // The following classes can be used here:
3094  // * mw-underline-always
3095  // * mw-underline-never
3096  $bodyClasses[] = 'mw-underline-' . ( $underline ? 'always' : 'never' );
3097  }
3098 
3099  if ( $this->getLanguage()->capitalizeAllNouns() ) {
3100  # A <body> class is probably not the best way to do this . . .
3101  $bodyClasses[] = 'capitalize-all-nouns';
3102  }
3103 
3104  // Parser feature migration class
3105  // The idea is that this will eventually be removed, after the wikitext
3106  // which requires it is cleaned up.
3107  $bodyClasses[] = 'mw-hide-empty-elt';
3108 
3109  $bodyClasses[] = $sk->getPageClasses( $this->getTitle() );
3110  $bodyClasses[] = 'skin-' . Sanitizer::escapeClass( $sk->getSkinName() );
3111  $bodyClasses[] =
3112  'action-' . Sanitizer::escapeClass( Action::getActionName( $this->getContext() ) );
3113 
3114  if ( $sk->isResponsive() ) {
3115  $bodyClasses[] = 'skin--responsive';
3116  }
3117 
3118  $bodyAttrs = [];
3119  // While the implode() is not strictly needed, it's used for backwards compatibility
3120  // (this used to be built as a string and hooks likely still expect that).
3121  $bodyAttrs['class'] = implode( ' ', $bodyClasses );
3122 
3123  // Allow skins and extensions to add body attributes they need
3124  // Get ones from deprecated method
3125  if ( method_exists( $sk, 'addToBodyAttributes' ) ) {
3127  $sk->addToBodyAttributes( $this, $bodyAttrs );
3128  wfDeprecated( 'Skin::addToBodyAttributes method to add body attributes', '1.35' );
3129  }
3130 
3131  // Then run the hook, the recommended way of adding body attributes now
3132  $this->getHookRunner()->onOutputPageBodyAttributes( $this, $sk, $bodyAttrs );
3133 
3134  $pieces[] = Html::openElement( 'body', $bodyAttrs );
3135 
3136  return self::combineWrappedStrings( $pieces );
3137  }
3138 
3144  public function getResourceLoader() {
3145  if ( $this->mResourceLoader === null ) {
3146  // Lazy-initialise as needed
3147  $this->mResourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
3148  }
3149  return $this->mResourceLoader;
3150  }
3151 
3160  public function makeResourceLoaderLink( $modules, $only, array $extraQuery = [] ) {
3161  // Apply 'target' and 'origin' filters
3162  $modules = $this->filterModules( (array)$modules, null, $only );
3163 
3165  $this->getRlClientContext(),
3166  $modules,
3167  $only,
3168  $extraQuery,
3169  $this->CSP->getNonce()
3170  );
3171  }
3172 
3179  protected static function combineWrappedStrings( array $chunks ) {
3180  // Filter out empty values
3181  $chunks = array_filter( $chunks, 'strlen' );
3182  return WrappedString::join( "\n", $chunks );
3183  }
3184 
3191  public function getBottomScripts() {
3192  $chunks = [];
3193  $chunks[] = $this->getRlClient()->getBodyHtml();
3194 
3195  // Legacy non-ResourceLoader scripts
3196  $chunks[] = $this->mScripts;
3197 
3198  if ( $this->limitReportJSData ) {
3201  [ 'wgPageParseReport' => $this->limitReportJSData ]
3202  ),
3203  $this->CSP->getNonce()
3204  );
3205  }
3206 
3207  return self::combineWrappedStrings( $chunks );
3208  }
3209 
3216  public function getJsConfigVars() {
3217  return $this->mJsConfigVars;
3218  }
3219 
3226  public function addJsConfigVars( $keys, $value = null ) {
3227  if ( is_array( $keys ) ) {
3228  foreach ( $keys as $key => $value ) {
3229  $this->mJsConfigVars[$key] = $value;
3230  }
3231  return;
3232  }
3233 
3234  $this->mJsConfigVars[$keys] = $value;
3235  }
3236 
3246  public function getJSVars() {
3247  $curRevisionId = 0;
3248  $articleId = 0;
3249  $canonicalSpecialPageName = false; # T23115
3250  $services = MediaWikiServices::getInstance();
3251 
3252  $title = $this->getTitle();
3253  $ns = $title->getNamespace();
3254  $nsInfo = $services->getNamespaceInfo();
3255  $canonicalNamespace = $nsInfo->exists( $ns )
3256  ? $nsInfo->getCanonicalName( $ns )
3257  : $title->getNsText();
3258 
3259  $sk = $this->getSkin();
3260  // Get the relevant title so that AJAX features can use the correct page name
3261  // when making API requests from certain special pages (T36972).
3262  $relevantTitle = $sk->getRelevantTitle();
3263  $relevantUser = $sk->getRelevantUser();
3264 
3265  if ( $ns === NS_SPECIAL ) {
3266  list( $canonicalSpecialPageName, /*...*/ ) =
3267  $services->getSpecialPageFactory()->
3268  resolveAlias( $title->getDBkey() );
3269  } elseif ( $this->canUseWikiPage() ) {
3270  $wikiPage = $this->getWikiPage();
3271  $curRevisionId = $wikiPage->getLatest();
3272  $articleId = $wikiPage->getId();
3273  }
3274 
3275  $lang = $title->getPageViewLanguage();
3276 
3277  // Pre-process information
3278  $separatorTransTable = $lang->separatorTransformTable();
3279  $separatorTransTable = $separatorTransTable ?: [];
3280  $compactSeparatorTransTable = [
3281  implode( "\t", array_keys( $separatorTransTable ) ),
3282  implode( "\t", $separatorTransTable ),
3283  ];
3284  $digitTransTable = $lang->digitTransformTable();
3285  $digitTransTable = $digitTransTable ?: [];
3286  $compactDigitTransTable = [
3287  implode( "\t", array_keys( $digitTransTable ) ),
3288  implode( "\t", $digitTransTable ),
3289  ];
3290 
3291  $user = $this->getUser();
3292 
3293  // Internal variables for MediaWiki core
3294  $vars = [
3295  // @internal For mediawiki.page.ready
3296  'wgBreakFrames' => $this->getFrameOptions() == 'DENY',
3297 
3298  // @internal For jquery.tablesorter
3299  'wgSeparatorTransformTable' => $compactSeparatorTransTable,
3300  'wgDigitTransformTable' => $compactDigitTransTable,
3301  'wgDefaultDateFormat' => $lang->getDefaultDateFormat(),
3302  'wgMonthNames' => $lang->getMonthNamesArray(),
3303 
3304  // @internal For debugging purposes
3305  'wgRequestId' => WebRequest::getRequestId(),
3306 
3307  // @internal For mw.loader
3308  'wgCSPNonce' => $this->CSP->getNonce(),
3309  ];
3310 
3311  // Start of supported and stable config vars (for use by extensions/gadgets).
3312  $vars += [
3313  'wgCanonicalNamespace' => $canonicalNamespace,
3314  'wgCanonicalSpecialPageName' => $canonicalSpecialPageName,
3315  'wgNamespaceNumber' => $title->getNamespace(),
3316  'wgPageName' => $title->getPrefixedDBkey(),
3317  'wgTitle' => $title->getText(),
3318  'wgCurRevisionId' => $curRevisionId,
3319  'wgRevisionId' => (int)$this->getRevisionId(),
3320  'wgArticleId' => $articleId,
3321  'wgIsArticle' => $this->isArticle(),
3322  'wgIsRedirect' => $title->isRedirect(),
3323  'wgAction' => Action::getActionName( $this->getContext() ),
3324  'wgUserName' => $user->isAnon() ? null : $user->getName(),
3325  'wgUserGroups' => $user->getEffectiveGroups(),
3326  'wgCategories' => $this->getCategories(),
3327  'wgPageContentLanguage' => $lang->getCode(),
3328  'wgPageContentModel' => $title->getContentModel(),
3329  'wgRelevantPageName' => $relevantTitle->getPrefixedDBkey(),
3330  'wgRelevantArticleId' => $relevantTitle->getArticleID(),
3331  ];
3332  if ( $user->isLoggedIn() ) {
3333  $vars['wgUserId'] = $user->getId();
3334  $vars['wgUserEditCount'] = $user->getEditCount();
3335  $userReg = $user->getRegistration();
3336  $vars['wgUserRegistration'] = $userReg ? (int)wfTimestamp( TS_UNIX, $userReg ) * 1000 : null;
3337  // Get the revision ID of the oldest new message on the user's talk
3338  // page. This can be used for constructing new message alerts on
3339  // the client side.
3340  $userNewMsgRevId = $this->getLastSeenUserTalkRevId();
3341  // Only occupy precious space in the <head> when it is non-null (T53640)
3342  // mw.config.get returns null by default.
3343  if ( $userNewMsgRevId ) {
3344  $vars['wgUserNewMsgRevisionId'] = $userNewMsgRevId;
3345  }
3346  }
3347  $contLang = $services->getContentLanguage();
3348  if ( $contLang->hasVariants() ) {
3349  $vars['wgUserVariant'] = $contLang->getPreferredVariant();
3350  }
3351  // Same test as SkinTemplate
3352  $vars['wgIsProbablyEditable'] = $this->userCanEditOrCreate( $user, $title );
3353  $vars['wgRelevantPageIsProbablyEditable'] = $relevantTitle &&
3354  $this->userCanEditOrCreate( $user, $relevantTitle );
3355  foreach ( $title->getRestrictionTypes() as $type ) {
3356  // Following keys are set in $vars:
3357  // wgRestrictionCreate, wgRestrictionEdit, wgRestrictionMove, wgRestrictionUpload
3358  $vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type );
3359  }
3360  if ( $title->isMainPage() ) {
3361  $vars['wgIsMainPage'] = true;
3362  }
3363  if ( $relevantUser ) {
3364  $vars['wgRelevantUserName'] = $relevantUser->getName();
3365  }
3366  // End of stable config vars
3367 
3368  if ( $this->mRedirectedFrom ) {
3369  // @internal For skin JS
3370  $vars['wgRedirectedFrom'] = $this->mRedirectedFrom->getPrefixedDBkey();
3371  }
3372 
3373  // Allow extensions to add their custom variables to the mw.config map.
3374  // Use the 'ResourceLoaderGetConfigVars' hook if the variable is not
3375  // page-dependant but site-wide (without state).
3376  // Alternatively, you may want to use OutputPage->addJsConfigVars() instead.
3377  $this->getHookRunner()->onMakeGlobalVariablesScript( $vars, $this );
3378 
3379  // Merge in variables from addJsConfigVars last
3380  return array_merge( $vars, $this->getJsConfigVars() );
3381  }
3382 
3388  private function getLastSeenUserTalkRevId() {
3389  $services = MediaWikiServices::getInstance();
3390  $user = $this->getUser();
3391  $userHasNewMessages = $services
3392  ->getTalkPageNotificationManager()
3393  ->userHasNewMessages( $user );
3394  if ( !$userHasNewMessages ) {
3395  return null;
3396  }
3397 
3398  $timestamp = $services
3399  ->getTalkPageNotificationManager()
3400  ->getLatestSeenMessageTimestamp( $user );
3401 
3402  if ( !$timestamp ) {
3403  return null;
3404  }
3405 
3406  $revRecord = $services->getRevisionLookup()->getRevisionByTimestamp(
3407  $user->getTalkPage(),
3408  $timestamp
3409  );
3410 
3411  if ( !$revRecord ) {
3412  return null;
3413  }
3414 
3415  return $revRecord->getId();
3416  }
3417 
3427  public function userCanPreview() {
3428  $request = $this->getRequest();
3429  if (
3430  $request->getVal( 'action' ) !== 'submit' ||
3431  !$request->wasPosted()
3432  ) {
3433  return false;
3434  }
3435 
3436  $user = $this->getUser();
3437 
3438  if ( !$user->isLoggedIn() ) {
3439  // Anons have predictable edit tokens
3440  return false;
3441  }
3442  if ( !$user->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
3443  return false;
3444  }
3445 
3446  $title = $this->getTitle();
3447  $errors = MediaWikiServices::getInstance()->getPermissionManager()
3448  ->getPermissionErrors( 'edit', $user, $title );
3449  if ( count( $errors ) !== 0 ) {
3450  return false;
3451  }
3452 
3453  return true;
3454  }
3455 
3461  private function userCanEditOrCreate(
3462  User $user,
3464  ) {
3465  $pm = MediaWikiServices::getInstance()->getPermissionManager();
3466  return $pm->quickUserCan( 'edit', $user, $title )
3467  && ( $this->getTitle()->exists() ||
3468  $pm->quickUserCan( 'create', $user, $title ) );
3469  }
3470 
3474  public function getHeadLinksArray() {
3475  $tags = [];
3476  $config = $this->getConfig();
3477 
3478  $canonicalUrl = $this->mCanonicalUrl;
3479 
3480  $tags['meta-generator'] = Html::element( 'meta', [
3481  'name' => 'generator',
3482  'content' => 'MediaWiki ' . MW_VERSION,
3483  ] );
3484 
3485  if ( $config->get( 'ReferrerPolicy' ) !== false ) {
3486  // Per https://w3c.github.io/webappsec-referrer-policy/#unknown-policy-values
3487  // fallbacks should come before the primary value so we need to reverse the array.
3488  foreach ( array_reverse( (array)$config->get( 'ReferrerPolicy' ) ) as $i => $policy ) {
3489  $tags["meta-referrer-$i"] = Html::element( 'meta', [
3490  'name' => 'referrer',
3491  'content' => $policy,
3492  ] );
3493  }
3494  }
3495 
3496  $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
3497  if ( $p !== 'index,follow' ) {
3498  // http://www.robotstxt.org/wc/meta-user.html
3499  // Only show if it's different from the default robots policy
3500  $tags['meta-robots'] = Html::element( 'meta', [
3501  'name' => 'robots',
3502  'content' => $p,
3503  ] );
3504  }
3505 
3506  foreach ( $this->mMetatags as $tag ) {
3507  if ( strncasecmp( $tag[0], 'http:', 5 ) === 0 ) {
3508  $a = 'http-equiv';
3509  $tag[0] = substr( $tag[0], 5 );
3510  } elseif ( strncasecmp( $tag[0], 'og:', 3 ) === 0 ) {
3511  $a = 'property';
3512  } else {
3513  $a = 'name';
3514  }
3515  $tagName = "meta-{$tag[0]}";
3516  if ( isset( $tags[$tagName] ) ) {
3517  $tagName .= $tag[1];
3518  }
3519  $tags[$tagName] = Html::element( 'meta',
3520  [
3521  $a => $tag[0],
3522  'content' => $tag[1]
3523  ]
3524  );
3525  }
3526 
3527  foreach ( $this->mLinktags as $tag ) {
3528  $tags[] = Html::element( 'link', $tag );
3529  }
3530 
3531  # Universal edit button
3532  if ( $config->get( 'UniversalEditButton' ) && $this->isArticleRelated() ) {
3533  if ( $this->userCanEditOrCreate( $this->getUser(), $this->getTitle() ) ) {
3534  // Original UniversalEditButton
3535  $msg = $this->msg( 'edit' )->text();
3536  $tags['universal-edit-button'] = Html::element( 'link', [
3537  'rel' => 'alternate',
3538  'type' => 'application/x-wiki',
3539  'title' => $msg,
3540  'href' => $this->getTitle()->getEditURL(),
3541  ] );
3542  // Alternate edit link
3543  $tags['alternative-edit'] = Html::element( 'link', [
3544  'rel' => 'edit',
3545  'title' => $msg,
3546  'href' => $this->getTitle()->getEditURL(),
3547  ] );
3548  }
3549  }
3550 
3551  # Generally the order of the favicon and apple-touch-icon links
3552  # should not matter, but Konqueror (3.5.9 at least) incorrectly
3553  # uses whichever one appears later in the HTML source. Make sure
3554  # apple-touch-icon is specified first to avoid this.
3555  if ( $config->get( 'AppleTouchIcon' ) !== false ) {
3556  $tags['apple-touch-icon'] = Html::element( 'link', [
3557  'rel' => 'apple-touch-icon',
3558  'href' => $config->get( 'AppleTouchIcon' )
3559  ] );
3560  }
3561 
3562  if ( $config->get( 'Favicon' ) !== false ) {
3563  $tags['favicon'] = Html::element( 'link', [
3564  'rel' => 'shortcut icon',
3565  'href' => $config->get( 'Favicon' )
3566  ] );
3567  }
3568 
3569  # OpenSearch description link
3570  $tags['opensearch'] = Html::element( 'link', [
3571  'rel' => 'search',
3572  'type' => 'application/opensearchdescription+xml',
3573  'href' => wfScript( 'opensearch_desc' ),
3574  'title' => $this->msg( 'opensearch-desc' )->inContentLanguage()->text(),
3575  ] );
3576 
3577  # Real Simple Discovery link, provides auto-discovery information
3578  # for the MediaWiki API (and potentially additional custom API
3579  # support such as WordPress or Twitter-compatible APIs for a
3580  # blogging extension, etc)
3581  $tags['rsd'] = Html::element( 'link', [
3582  'rel' => 'EditURI',
3583  'type' => 'application/rsd+xml',
3584  // Output a protocol-relative URL here if $wgServer is protocol-relative.
3585  // Whether RSD accepts relative or protocol-relative URLs is completely
3586  // undocumented, though.
3587  'href' => wfExpandUrl( wfAppendQuery(
3588  wfScript( 'api' ),
3589  [ 'action' => 'rsd' ] ),
3591  ),
3592  ] );
3593 
3594  # Language variants
3595  if ( !$config->get( 'DisableLangConversion' ) ) {
3596  $lang = $this->getTitle()->getPageLanguage();
3597  if ( $lang->hasVariants() ) {
3598  $variants = $lang->getVariants();
3599  foreach ( $variants as $variant ) {
3600  $tags["variant-$variant"] = Html::element( 'link', [
3601  'rel' => 'alternate',
3602  'hreflang' => LanguageCode::bcp47( $variant ),
3603  'href' => $this->getTitle()->getLocalURL(
3604  [ 'variant' => $variant ] )
3605  ]
3606  );
3607  }
3608  # x-default link per https://support.google.com/webmasters/answer/189077?hl=en
3609  $tags["variant-x-default"] = Html::element( 'link', [
3610  'rel' => 'alternate',
3611  'hreflang' => 'x-default',
3612  'href' => $this->getTitle()->getLocalURL() ] );
3613  }
3614  }
3615 
3616  # Copyright
3617  if ( $this->copyrightUrl !== null ) {
3618  $copyright = $this->copyrightUrl;
3619  } else {
3620  $copyright = '';
3621  if ( $config->get( 'RightsPage' ) ) {
3622  $copy = Title::newFromText( $config->get( 'RightsPage' ) );
3623 
3624  if ( $copy ) {
3625  $copyright = $copy->getLocalURL();
3626  }
3627  }
3628 
3629  if ( !$copyright && $config->get( 'RightsUrl' ) ) {
3630  $copyright = $config->get( 'RightsUrl' );
3631  }
3632  }
3633 
3634  if ( $copyright ) {
3635  $tags['copyright'] = Html::element( 'link', [
3636  'rel' => 'license',
3637  'href' => $copyright ]
3638  );
3639  }
3640 
3641  # Feeds
3642  if ( $config->get( 'Feed' ) ) {
3643  $feedLinks = [];
3644 
3645  foreach ( $this->getSyndicationLinks() as $format => $link ) {
3646  # Use the page name for the title. In principle, this could
3647  # lead to issues with having the same name for different feeds
3648  # corresponding to the same page, but we can't avoid that at
3649  # this low a level.
3650 
3651  $feedLinks[] = $this->feedLink(
3652  $format,
3653  $link,
3654  # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
3655  $this->msg(
3656  "page-{$format}-feed", $this->getTitle()->getPrefixedText()
3657  )->text()
3658  );
3659  }
3660 
3661  # Recent changes feed should appear on every page (except recentchanges,
3662  # that would be redundant). Put it after the per-page feed to avoid
3663  # changing existing behavior. It's still available, probably via a
3664  # menu in your browser. Some sites might have a different feed they'd
3665  # like to promote instead of the RC feed (maybe like a "Recent New Articles"
3666  # or "Breaking news" one). For this, we see if $wgOverrideSiteFeed is defined.
3667  # If so, use it instead.
3668  $sitename = $config->get( 'Sitename' );
3669  $overrideSiteFeed = $config->get( 'OverrideSiteFeed' );
3670  if ( $overrideSiteFeed ) {
3671  foreach ( $overrideSiteFeed as $type => $feedUrl ) {
3672  // Note, this->feedLink escapes the url.
3673  $feedLinks[] = $this->feedLink(
3674  $type,
3675  $feedUrl,
3676  $this->msg( "site-{$type}-feed", $sitename )->text()
3677  );
3678  }
3679  } elseif ( !$this->getTitle()->isSpecial( 'Recentchanges' ) ) {
3680  $rctitle = SpecialPage::getTitleFor( 'Recentchanges' );
3681  foreach ( $this->getAdvertisedFeedTypes() as $format ) {
3682  $feedLinks[] = $this->feedLink(
3683  $format,
3684  $rctitle->getLocalURL( [ 'feed' => $format ] ),
3685  # For grep: 'site-rss-feed', 'site-atom-feed'
3686  $this->msg( "site-{$format}-feed", $sitename )->text()
3687  );
3688  }
3689  }
3690 
3691  # Allow extensions to change the list pf feeds. This hook is primarily for changing,
3692  # manipulating or removing existing feed tags. If you want to add new feeds, you should
3693  # use OutputPage::addFeedLink() instead.
3694  $this->getHookRunner()->onAfterBuildFeedLinks( $feedLinks );
3695 
3696  $tags += $feedLinks;
3697  }
3698 
3699  # Canonical URL
3700  if ( $config->get( 'EnableCanonicalServerLink' ) ) {
3701  if ( $canonicalUrl !== false ) {
3702  $canonicalUrl = wfExpandUrl( $canonicalUrl, PROTO_CANONICAL );
3703  } elseif ( $this->isArticleRelated() ) {
3704  // This affects all requests where "setArticleRelated" is true. This is
3705  // typically all requests that show content (query title, curid, oldid, diff),
3706  // and all wikipage actions (edit, delete, purge, info, history etc.).
3707  // It does not apply to File pages and Special pages.
3708  // 'history' and 'info' actions address page metadata rather than the page
3709  // content itself, so they may not be canonicalized to the view page url.
3710  // TODO: this ought to be better encapsulated in the Action class.
3711  $action = Action::getActionName( $this->getContext() );
3712  if ( in_array( $action, [ 'history', 'info' ] ) ) {
3713  $query = "action={$action}";
3714  } else {
3715  $query = '';
3716  }
3717  $canonicalUrl = $this->getTitle()->getCanonicalURL( $query );
3718  } else {
3719  $reqUrl = $this->getRequest()->getRequestURL();
3720  $canonicalUrl = wfExpandUrl( $reqUrl, PROTO_CANONICAL );
3721  }
3722  }
3723  if ( $canonicalUrl !== false ) {
3724  $tags[] = Html::element( 'link', [
3725  'rel' => 'canonical',
3726  'href' => $canonicalUrl
3727  ] );
3728  }
3729 
3730  // Allow extensions to add, remove and/or otherwise manipulate these links
3731  // If you want only to *add* <head> links, please use the addHeadItem()
3732  // (or addHeadItems() for multiple items) method instead.
3733  // This hook is provided as a last resort for extensions to modify these
3734  // links before the output is sent to client.
3735  $this->getHookRunner()->onOutputPageAfterGetHeadLinksArray( $tags, $this );
3736 
3737  return $tags;
3738  }
3739 
3748  private function feedLink( $type, $url, $text ) {
3749  return Html::element( 'link', [
3750  'rel' => 'alternate',
3751  'type' => "application/$type+xml",
3752  'title' => $text,
3753  'href' => $url ]
3754  );
3755  }
3756 
3766  public function addStyle( $style, $media = '', $condition = '', $dir = '' ) {
3767  $options = [];
3768  if ( $media ) {
3769  $options['media'] = $media;
3770  }
3771  if ( $condition ) {
3772  $options['condition'] = $condition;
3773  }
3774  if ( $dir ) {
3775  $options['dir'] = $dir;
3776  }
3777  $this->styles[$style] = $options;
3778  }
3779 
3787  public function addInlineStyle( $style_css, $flip = 'noflip' ) {
3788  if ( $flip === 'flip' && $this->getLanguage()->isRTL() ) {
3789  # If wanted, and the interface is right-to-left, flip the CSS
3790  $style_css = CSSJanus::transform( $style_css, true, false );
3791  }
3792  $this->mInlineStyles .= Html::inlineStyle( $style_css );
3793  }
3794 
3800  protected function buildExemptModules() {
3801  $chunks = [];
3802 
3803  // Requirements:
3804  // - Within modules provided by the software (core, skin, extensions),
3805  // styles from skin stylesheets should be overridden by styles
3806  // from modules dynamically loaded with JavaScript.
3807  // - Styles from site-specific, private, and user modules should override
3808  // both of the above.
3809  //
3810  // The effective order for stylesheets must thus be:
3811  // 1. Page style modules, formatted server-side by ResourceLoaderClientHtml.
3812  // 2. Dynamically-loaded styles, inserted client-side by mw.loader.
3813  // 3. Styles that are site-specific, private or from the user, formatted
3814  // server-side by this function.
3815  //
3816  // The 'ResourceLoaderDynamicStyles' marker helps JavaScript know where
3817  // point #2 is.
3818 
3819  // Add legacy styles added through addStyle()/addInlineStyle() here
3820  $chunks[] = implode( '', $this->buildCssLinksArray() ) . $this->mInlineStyles;
3821 
3822  // Things that go after the ResourceLoaderDynamicStyles marker
3823  $append = [];
3824  $separateReq = [ 'site.styles', 'user.styles' ];
3825  foreach ( $this->rlExemptStyleModules as $group => $moduleNames ) {
3826  if ( $moduleNames ) {
3827  $append[] = $this->makeResourceLoaderLink(
3828  array_diff( $moduleNames, $separateReq ),
3829  ResourceLoaderModule::TYPE_STYLES
3830  );
3831 
3832  foreach ( array_intersect( $moduleNames, $separateReq ) as $name ) {
3833  // These require their own dedicated request in order to support "@import"
3834  // syntax, which is incompatible with concatenation. (T147667, T37562)
3835  $append[] = $this->makeResourceLoaderLink( $name,
3836  ResourceLoaderModule::TYPE_STYLES
3837  );
3838  }
3839  }
3840  }
3841  if ( $append ) {
3842  $chunks[] = Html::element(
3843  'meta',
3844  [ 'name' => 'ResourceLoaderDynamicStyles', 'content' => '' ]
3845  );
3846  $chunks = array_merge( $chunks, $append );
3847  }
3848 
3849  return self::combineWrappedStrings( $chunks );
3850  }
3851 
3855  public function buildCssLinksArray() {
3856  $links = [];
3857 
3858  foreach ( $this->styles as $file => $options ) {
3859  $link = $this->styleLink( $file, $options );
3860  if ( $link ) {
3861  $links[$file] = $link;
3862  }
3863  }
3864  return $links;
3865  }
3866 
3874  protected function styleLink( $style, array $options ) {
3875  if ( isset( $options['dir'] ) && $this->getLanguage()->getDir() != $options['dir'] ) {
3876  return '';
3877  }
3878 
3879  if ( isset( $options['media'] ) ) {
3880  $media = self::transformCssMedia( $options['media'] );
3881  if ( $media === null ) {
3882  return '';
3883  }
3884  } else {
3885  $media = 'all';
3886  }
3887 
3888  if ( substr( $style, 0, 1 ) == '/' ||
3889  substr( $style, 0, 5 ) == 'http:' ||
3890  substr( $style, 0, 6 ) == 'https:' ) {
3891  $url = $style;
3892  } else {
3893  $config = $this->getConfig();
3894  // Append file hash as query parameter
3896  $config,
3897  $config->get( 'StylePath' ) . '/' . $style
3898  );
3899  }
3900 
3901  $link = Html::linkedStyle( $url, $media );
3902 
3903  if ( isset( $options['condition'] ) ) {
3904  $condition = htmlspecialchars( $options['condition'] );
3905  $link = "<!--[if $condition]>$link<![endif]-->";
3906  }
3907  return $link;
3908  }
3909 
3931  public static function transformResourcePath( Config $config, $path ) {
3932  global $IP;
3933 
3934  $localDir = $IP;
3935  $remotePathPrefix = $config->get( 'ResourceBasePath' );
3936  if ( $remotePathPrefix === '' ) {
3937  // The configured base path is required to be empty string for
3938  // wikis in the domain root
3939  $remotePath = '/';
3940  } else {
3941  $remotePath = $remotePathPrefix;
3942  }
3943  if ( strpos( $path, $remotePath ) !== 0 || substr( $path, 0, 2 ) === '//' ) {
3944  // - Path is outside wgResourceBasePath, ignore.
3945  // - Path is protocol-relative. Fixes T155310. Not supported by RelPath lib.
3946  return $path;
3947  }
3948  // For files in resources, extensions/ or skins/, ResourceBasePath is preferred here.
3949  // For other misc files in $IP, we'll fallback to that as well. There is, however, a fourth
3950  // supported dir/path pair in the configuration (wgUploadDirectory, wgUploadPath)
3951  // which is not expected to be in wgResourceBasePath on CDNs. (T155146)
3952  $uploadPath = $config->get( 'UploadPath' );
3953  if ( strpos( $path, $uploadPath ) === 0 ) {
3954  $localDir = $config->get( 'UploadDirectory' );
3955  $remotePathPrefix = $remotePath = $uploadPath;
3956  }
3957 
3958  $path = RelPath::getRelativePath( $path, $remotePath );
3959  return self::transformFilePath( $remotePathPrefix, $localDir, $path );
3960  }
3961 
3973  public static function transformFilePath( $remotePathPrefix, $localPath, $file ) {
3974  $hash = md5_file( "$localPath/$file" );
3975  if ( $hash === false ) {
3976  wfLogWarning( __METHOD__ . ": Failed to hash $localPath/$file" );
3977  $hash = '';
3978  }
3979  return "$remotePathPrefix/$file?" . substr( $hash, 0, 5 );
3980  }
3981 
3989  public static function transformCssMedia( $media ) {
3990  global $wgRequest;
3991 
3992  // https://www.w3.org/TR/css3-mediaqueries/#syntax
3993  $screenMediaQueryRegex = '/^(?:only\s+)?screen\b/i';
3994 
3995  // Switch in on-screen display for media testing
3996  $switches = [
3997  'printable' => 'print',
3998  'handheld' => 'handheld',
3999  ];
4000  foreach ( $switches as $switch => $targetMedia ) {
4001  if ( $wgRequest->getBool( $switch ) ) {
4002  if ( $media == $targetMedia ) {
4003  $media = '';
4004  } elseif ( preg_match( $screenMediaQueryRegex, $media ) === 1 ) {
4005  /* This regex will not attempt to understand a comma-separated media_query_list
4006  *
4007  * Example supported values for $media:
4008  * 'screen', 'only screen', 'screen and (min-width: 982px)' ),
4009  * Example NOT supported value for $media:
4010  * '3d-glasses, screen, print and resolution > 90dpi'
4011  *
4012  * If it's a print request, we never want any kind of screen stylesheets
4013  * If it's a handheld request (currently the only other choice with a switch),
4014  * we don't want simple 'screen' but we might want screen queries that
4015  * have a max-width or something, so we'll pass all others on and let the
4016  * client do the query.
4017  */
4018  if ( $targetMedia == 'print' || $media == 'screen' ) {
4019  return null;
4020  }
4021  }
4022  }
4023  }
4024 
4025  return $media;
4026  }
4027 
4036  public function addWikiMsg( ...$args ) {
4037  $name = array_shift( $args );
4038  $this->addWikiMsgArray( $name, $args );
4039  }
4040 
4049  public function addWikiMsgArray( $name, $args ) {
4050  $this->addHTML( $this->msg( $name, $args )->parseAsBlock() );
4051  }
4052 
4079  public function wrapWikiMsg( $wrap, ...$msgSpecs ) {
4080  $s = $wrap;
4081  foreach ( $msgSpecs as $n => $spec ) {
4082  if ( is_array( $spec ) ) {
4083  $args = $spec;
4084  $name = array_shift( $args );
4085  } else {
4086  $args = [];
4087  $name = $spec;
4088  }
4089  $s = str_replace( '$' . ( $n + 1 ), $this->msg( $name, $args )->plain(), $s );
4090  }
4091  $this->addWikiTextAsInterface( $s );
4092  }
4093 
4099  public function isTOCEnabled() {
4100  return $this->mEnableTOC;
4101  }
4102 
4110  public static function setupOOUI( $skinName = 'default', $dir = 'ltr' ) {
4112  $theme = $themes[$skinName] ?? $themes['default'];
4113  // For example, 'OOUI\WikimediaUITheme'.
4114  $themeClass = "OOUI\\{$theme}Theme";
4115  OOUI\Theme::setSingleton( new $themeClass() );
4116  OOUI\Element::setDefaultDir( $dir );
4117  }
4118 
4125  public function enableOOUI() {
4127  strtolower( $this->getSkin()->getSkinName() ),
4128  $this->getLanguage()->getDir()
4129  );
4130  $this->addModuleStyles( [
4131  'oojs-ui-core.styles',
4132  'oojs-ui.styles.indicators',
4133  'mediawiki.widgets.styles',
4134  'oojs-ui-core.icons',
4135  ] );
4136  }
4137 
4148  public function getCSPNonce() {
4149  return $this->CSP->getNonce();
4150  }
4151 
4158  public function getCSP() {
4159  return $this->CSP;
4160  }
4161 }
Action\getActionName
static getActionName(IContextSource $context)
Get the action that will be executed, not necessarily the one passed passed through the "action" requ...
Definition: Action.php:154
OutputPage\preventClickjacking
preventClickjacking( $enable=true)
Set a flag which will cause an X-Frame-Options header appropriate for edit pages to be sent.
Definition: OutputPage.php:2342
OutputPage\output
output( $return=false)
Finally, all the text has been munged and accumulated into the object, let's actually output it:
Definition: OutputPage.php:2518
OutputPage\$mCategories
array $mCategories
Definition: OutputPage.php:125
ParserOutput\getEnableOOUI
getEnableOOUI()
Definition: ParserOutput.php:687
OutputPage\addBacklinkSubtitle
addBacklinkSubtitle(Title $title, $query=[])
Add a subtitle containing a backlink to a page.
Definition: OutputPage.php:1105
OutputPage\$mLastModified
string $mLastModified
Used for sending cache control.
Definition: OutputPage.php:119
ParserOptions
Set options of the Parser.
Definition: ParserOptions.php:44
OutputPage\getCategoryLinks
getCategoryLinks()
Get the list of category links, in a 2-D array with the following format: $arr[$type][] = $link,...
Definition: OutputPage.php:1461
OutputPage\addMeta
addMeta( $name, $val)
Add a new "<meta>" tag To add an http-equiv meta tag, precede the name with "http:".
Definition: OutputPage.php:405
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:37
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:70
OutputPage\getTarget
getTarget()
Definition: OutputPage.php:592
ResourceLoaderContext
Context object that contains information about the state of a specific ResourceLoader web request.
Definition: ResourceLoaderContext.php:33
OutputPage\getSubtitle
getSubtitle()
Get the subtitle.
Definition: OutputPage.php:1121
OutputPage\parseAsInterface
parseAsInterface( $text, $linestart=true)
Parse wikitext in the user interface language and return the HTML.
Definition: OutputPage.php:2061
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:35
OutputPage\enableClientCache
enableClientCache( $state)
Use enableClientCache(false) to force it to send nocache headers.
Definition: OutputPage.php:2178
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:328
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:45
OutputPage\getLanguageLinks
getLanguageLinks()
Get the list of language links.
Definition: OutputPage.php:1357
OutputPage\buildBacklinkSubtitle
static buildBacklinkSubtitle(Title $title, $query=[])
Build message object for a subtitle containing a backlink to a page.
Definition: OutputPage.php:1090
HtmlArmor
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:30
ResourceLoaderClientHtml
Load and configure a ResourceLoader client on an HTML page.
Definition: ResourceLoaderClientHtml.php:30
OutputPage\reduceAllowedModules
reduceAllowedModules( $type, $level)
Limit the highest level of CSS/JS untrustworthiness allowed.
Definition: OutputPage.php:1597
PROTO_CANONICAL
const PROTO_CANONICAL
Definition: Defines.php:212
OutputPage\$mModuleStyles
array $mModuleStyles
Definition: OutputPage.php:169
OutputPage\addSubtitle
addSubtitle( $str)
Add $str to the subtitle.
Definition: OutputPage.php:1074
OutputPage\addScriptFile
addScriptFile( $file, $unused=null)
Add a JavaScript file to be loaded as <script> on this page.
Definition: OutputPage.php:479
OutputPage\addAcceptLanguage
addAcceptLanguage()
T23672: Add Accept-Language to Vary header if there's no 'variant' parameter in GET.
Definition: OutputPage.php:2320
ParserOutput
Definition: ParserOutput.php:27
Article\formatRobotPolicy
static formatRobotPolicy( $policy)
Converts a String robot policy into an associative array, to allow merging of several policies using ...
Definition: Article.php:1079
OutputPage\getJSVars
getJSVars()
Get an array containing the variables to be set in mw.config in JavaScript.
Definition: OutputPage.php:3246
ResourceLoader\makeConfigSetScript
static makeConfigSetScript(array $configuration)
Return JS code which will set the MediaWiki configuration array to the given value.
Definition: ResourceLoader.php:1670
OutputPage\getRlClientContext
getRlClientContext()
Definition: OutputPage.php:2916
OutputPage\getDisplayTitle
getDisplayTitle()
Returns page display title.
Definition: OutputPage.php:1025
OutputPage\$mRedirectedFrom
Title $mRedirectedFrom
If the current page was reached through a redirect, $mRedirectedFrom contains the Title of the redire...
Definition: OutputPage.php:295
Sanitizer\stripAllTags
static stripAllTags( $html)
Take a fragment of (potentially invalid) HTML and return a version with any tags removed,...
Definition: Sanitizer.php:1574
OutputPage\setTitle
setTitle(Title $t)
Set the Title object to use.
Definition: OutputPage.php:1053
OutputPage\$mVaryHeader
array $mVaryHeader
Headers that cause the cache to vary.
Definition: OutputPage.php:285
OutputPage\showsCopyright
showsCopyright()
Return whether the standard copyright should be shown for the current page.
Definition: OutputPage.php:1328
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:35
OutputPage\addLink
addLink(array $linkarr)
Add a new <link> tag to the page header.
Definition: OutputPage.php:426
OutputPage\addContentOverride
addContentOverride(LinkTarget $target, Content $content)
Add a mapping from a LinkTarget to a Content, for things like page preview.
Definition: OutputPage.php:612
OutputPage\addCategoryLinksToLBAndGetResult
addCategoryLinksToLBAndGetResult(array $categories)
Definition: OutputPage.php:1412
OutputPage\parserOptions
parserOptions()
Get/set the ParserOptions object to use for wikitext parsing.
Definition: OutputPage.php:1654
OutputPage\hasHeadItem
hasHeadItem( $name)
Check if the header item $name is already set.
Definition: OutputPage.php:688
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:160
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
OutputPage\getMetaTags
getMetaTags()
Returns the current <meta> tags.
Definition: OutputPage.php:415
OutputPage\addLanguageLinks
addLanguageLinks(array $newLinkArray)
Add new language links.
Definition: OutputPage.php:1338
OutputPage\addLinkHeader
addLinkHeader( $header)
Add an HTTP Link: header.
Definition: OutputPage.php:2296
OutputPage\addModuleStyles
addModuleStyles( $modules)
Load the styles of one or more style-only ResourceLoader modules on this page.
Definition: OutputPage.php:585
OutputPage\$mNewSectionLink
bool $mNewSectionLink
Definition: OutputPage.php:234
wfSetVar
wfSetVar(&$dest, $source, $force=false)
Sets dest to source and returns the original value of dest If source is NULL, it just returns the val...
Definition: GlobalFunctions.php:1550
OutputPage\getCSP
getCSP()
Get the ContentSecurityPolicy object.
Definition: OutputPage.php:4158
OutputPage\isArticleRelated
isArticleRelated()
Return whether this page is related an article on the wiki.
Definition: OutputPage.php:1306
OutputPage\setArticleBodyOnly
setArticleBodyOnly( $only)
Set whether the output should only contain the body of the article, without any skin,...
Definition: OutputPage.php:709
OutputPage\getFrameOptions
getFrameOptions()
Get the X-Frame-Options header value (without the name part), or false if there isn't one.
Definition: OutputPage.php:2372
OutputPage\__construct
__construct(IContextSource $context)
Constructor for OutputPage.
Definition: OutputPage.php:347
ResourceLoader\makeInlineScript
static makeInlineScript( $script, $nonce=null)
Make an HTML script that runs given JS code after startup and base modules.
Definition: ResourceLoader.php:1643
OutputPage\$mRedirectCode
string $mRedirectCode
Definition: OutputPage.php:193
Sanitizer\removeHTMLtags
static removeHTMLtags( $text, $processCallback=null, $args=[], $extratags=[], $removetags=[])
Cleans up HTML, removes dangerous tags and attributes, and removes HTML comments.
Definition: Sanitizer.php:239
OutputPage\getRevisionId
getRevisionId()
Get the displayed revision ID.
Definition: OutputPage.php:1690
OutputPage\clearHTML
clearHTML()
Clear the body HTML.
Definition: OutputPage.php:1635
OutputPage\addScript
addScript( $script)
Add raw HTML to the list of scripts (including <script> tag, etc.) Internal use only.
Definition: OutputPage.php:467
ParserOutput\getModules
getModules()
Definition: ParserOutput.php:640
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1815
ParserOutput\getImages
& getImages()
Definition: ParserOutput.php:616
OutputPage\returnToMain
returnToMain( $unused=null, $returnto=null, $returntoquery=null)
Add a "return to" link pointing to a specified title, or the title indicated in the request,...
Definition: OutputPage.php:2889
OutputPage\buildCssLinksArray
buildCssLinksArray()
Definition: OutputPage.php:3855
OutputPage\addParserOutputMetadata
addParserOutputMetadata(ParserOutput $parserOutput)
Add all metadata associated with a ParserOutput object, but without the actual HTML.
Definition: OutputPage.php:1879
OutputPage\combineWrappedStrings
static combineWrappedStrings(array $chunks)
Combine WrappedString chunks and filter out empty ones.
Definition: OutputPage.php:3179
Sanitizer\mergeAttributes
static mergeAttributes( $a, $b)
Merge two sets of HTML attributes.
Definition: Sanitizer.php:541
MW_VERSION
const MW_VERSION
The running version of MediaWiki.
Definition: Defines.php:39
OutputPage\$mHideNewSectionLink
bool $mHideNewSectionLink
Definition: OutputPage.php:237
OutputPage\$contentOverrides
array $contentOverrides
Map Title to Content.
Definition: OutputPage.php:321
OutputPage\$mBodytext
string $mBodytext
Contains all of the "<body>" content.
Definition: OutputPage.php:80
OutputPage\getOriginTrials
getOriginTrials()
Get the Origin-Trial header values.
Definition: OutputPage.php:2388
ParserOutput\getJsConfigVars
getJsConfigVars()
Definition: ParserOutput.php:652
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:308
OutputPage\getBottomScripts
getBottomScripts()
JS stuff to put at the bottom of the <body>.
Definition: OutputPage.php:3191
ParserOptions\newFromAnon
static newFromAnon()
Get a ParserOptions object for an anonymous user.
Definition: ParserOptions.php:1063
OutputPage\couldBePublicCached
couldBePublicCached()
Whether the output might become publicly cached.
Definition: OutputPage.php:2188
OutputPage\addHeadItems
addHeadItems( $values)
Add one or more head items to the output.
Definition: OutputPage.php:678
OutputPage\getModuleStyles
getModuleStyles( $filter=false, $position=null)
Get the list of style-only modules to load on this page.
Definition: OutputPage.php:570
OutputPage\getFeaturePolicyReportOnly
getFeaturePolicyReportOnly()
Definition: OutputPage.php:2418
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
Html\htmlHeader
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition: Html.php:965
OutputPage\versionRequired
versionRequired( $version)
Display an error page indicating that a given version of MediaWiki is required to use it.
Definition: OutputPage.php:2787
ResourceLoaderClientHtml\setExemptStates
setExemptStates(array $states)
Set state of special modules that are handled by the caller manually.
Definition: ResourceLoaderClientHtml.php:108
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1220
$s
$s
Definition: mergeMessageFileList.php:184
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:92
Sanitizer\escapeClass
static escapeClass( $class)
Given a value, escape it so that it can be used as a CSS class and return it.
Definition: Sanitizer.php:976
OutputPage\getFileVersion
getFileVersion()
Get the displayed file version.
Definition: OutputPage.php:1744
OutputPage\getSyndicationLinks
getSyndicationLinks()
Return URLs for each supported syndication format for this page.
Definition: OutputPage.php:1251
ContextSource\canUseWikiPage
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
Definition: ContextSource.php:101
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1087
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:79
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:653
OutputPage\getRedirect
getRedirect()
Get the URL to redirect to, or an empty string if not redirect URL set.
Definition: OutputPage.php:373
OutputPage\setCanonicalUrl
setCanonicalUrl( $url)
Set the URL to be used for the <link rel=canonical>>.
Definition: OutputPage.php:445
$res
$res
Definition: testCompression.php:57
ParserOutput\getHeadItems
getHeadItems()
Definition: ParserOutput.php:636
ContextSource\getUser
getUser()
Stable to override.
Definition: ContextSource.php:134
ContextSource\getTitle
getTitle()
Definition: ContextSource.php:88
OutputPage\$mLinktags
array $mLinktags
Definition: OutputPage.php:54
OutputPage\$mIndexPolicy
$mIndexPolicy
Definition: OutputPage.php:277
Skin\getHtmlElementAttributes
getHtmlElementAttributes()
Return values for <html> element.
Definition: Skin.php:503
LinkBatch\setArray
setArray( $array)
Set the link list to a given 2-d array First key is the namespace, second is the DB key,...
Definition: LinkBatch.php:147
OutputPage\setIndicators
setIndicators(array $indicators)
Add an array of indicators, with their identifiers as array keys and HTML contents as values.
Definition: OutputPage.php:1497
LinkCache\getSelectFields
static getSelectFields()
Fields that LinkCache needs to select.
Definition: LinkCache.php:231
OutputPage\addHTML
addHTML( $text)
Append $text to the body HTML.
Definition: OutputPage.php:1615
OutputPage\parseInternal
parseInternal( $text, $title, $linestart, $interface)
Parse wikitext and return the HTML (internal implementation helper)
Definition: OutputPage.php:2102
OutputPage\getReportTo
getReportTo()
Definition: OutputPage.php:2394
OutputPage\addHeadItem
addHeadItem( $name, $value)
Add or replace a head item to the output.
Definition: OutputPage.php:668
OutputPage\addContentOverrideCallback
addContentOverrideCallback(callable $callback)
Add a callback for mapping from a Title to a Content object, for things like page preview.
Definition: OutputPage.php:632
OutputPage\getRevisionTimestamp
getRevisionTimestamp()
Get the timestamp of displayed revision.
Definition: OutputPage.php:1721
OutputPage\addWikiMsgArray
addWikiMsgArray( $name, $args)
Add a wikitext-formatted message to the output.
Definition: OutputPage.php:4049
OutputPage\transformCssMedia
static transformCssMedia( $media)
Transform "media" attribute based on request parameters.
Definition: OutputPage.php:3989
OutputPage\setLastModified
setLastModified( $timestamp)
Override the last modified timestamp.
Definition: OutputPage.php:857
$dbr
$dbr
Definition: testCompression.php:54
ResourceLoaderClientHtml\setConfig
setConfig(array $vars)
Set mw.config variables.
Definition: ResourceLoaderClientHtml.php:77
ContextSource\getLanguage
getLanguage()
Definition: ContextSource.php:143
OutputPage\$mImageTimeKeys
array $mImageTimeKeys
Definition: OutputPage.php:190
OutputPage\showPermissionsErrorPage
showPermissionsErrorPage(array $errors, $action=null)
Output a standard permission error page.
Definition: OutputPage.php:2702
wfAppendQuery
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Definition: GlobalFunctions.php:438
ParserOutput\getModuleStyles
getModuleStyles()
Definition: ParserOutput.php:644
OutputPage\getLinkTags
getLinkTags()
Returns the current <link> tags.
Definition: OutputPage.php:436
OutputPage\forceHideNewSectionLink
forceHideNewSectionLink()
Forcibly hide the new section link?
Definition: OutputPage.php:1172
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:315
Xml\encodeJsCall
static encodeJsCall( $name, $args, $pretty=false)
Create a call to a JavaScript function.
Definition: Xml.php:684
OutputPage\$rlClientContext
ResourceLoaderContext $rlClientContext
Definition: OutputPage.php:178
Html\isXmlMimeType
static isXmlMimeType( $mimetype)
Determines if the given MIME type is xml.
Definition: Html.php:1003
OutputPage\setArticleRelated
setArticleRelated( $newVal)
Set whether this page is related an article on the wiki Setting false will cause the change of "artic...
Definition: OutputPage.php:1294
OutputPage\addElement
addElement( $element, array $attribs=[], $contents='')
Shortcut for adding an Html::element via addHTML.
Definition: OutputPage.php:1628
OutputPage\addParserOutputContent
addParserOutputContent(ParserOutput $parserOutput, $poOptions=[])
Add the HTML and enhancements for it (like ResourceLoader modules) associated with a ParserOutput obj...
Definition: OutputPage.php:1987
Config
Interface for configuration instances.
Definition: Config.php:30
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:58
ParserOutput\getExtraCSPDefaultSrcs
getExtraCSPDefaultSrcs()
Get extra Content-Security-Policy 'default-src' directives.
Definition: ParserOutput.php:696
MediaWiki\Linker\LinkTarget\getNamespace
getNamespace()
Get the namespace index.
OutputPage\userCanEditOrCreate
userCanEditOrCreate(User $user, LinkTarget $title)
Definition: OutputPage.php:3461
wfParseUrl
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
Definition: GlobalFunctions.php:792
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:63
ParserOutput\getLimitReportJSData
getLimitReportJSData()
Definition: ParserOutput.php:683
Html\linkedScript
static linkedScript( $url, $nonce=null)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
Definition: Html.php:596
OutputPage\feedLink
feedLink( $type, $url, $text)
Generate a "<link rel/>" for a feed.
Definition: OutputPage.php:3748
wfDeprecatedMsg
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
Definition: GlobalFunctions.php:1059
OutputPage\addWikiTextAsInterface
addWikiTextAsInterface( $text, $linestart=true, Title $title=null)
Convert wikitext in the user interface language to HTML and add it to the buffer.
Definition: OutputPage.php:1784
MWException
MediaWiki exception.
Definition: MWException.php:29
OutputPage\considerCacheSettingsFinal
considerCacheSettingsFinal()
Set the expectation that cache control will not change after this point.
Definition: OutputPage.php:2211
OutputPage\getModules
getModules( $filter=false, $position=null, $param='mModules', $type=ResourceLoaderModule::TYPE_COMBINED)
Get the list of modules to include on this page.
Definition: OutputPage.php:545
OutputPage\addStyle
addStyle( $style, $media='', $condition='', $dir='')
Add a local or specified stylesheet, with the given media options.
Definition: OutputPage.php:3766
OutputPage\sendCacheControl
sendCacheControl()
Send cache control HTTP headers.
Definition: OutputPage.php:2428
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1027
OutputPage\$mCdnMaxageLimit
int $mCdnMaxageLimit
Upper limit on mCdnMaxage.
Definition: OutputPage.php:249
OutputPage\getLastSeenUserTalkRevId
getLastSeenUserTalkRevId()
Get the revision ID for the last user talk page revision viewed by the talk page owner.
Definition: OutputPage.php:3388
OutputPage\$mTemplateIds
array $mTemplateIds
Definition: OutputPage.php:187
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2542
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:24
ResourceLoaderWikiModule\preloadTitleInfo
static preloadTitleInfo(ResourceLoaderContext $context, IDatabase $db, array $moduleNames)
Definition: ResourceLoaderWikiModule.php:459
OutputPage\styleLink
styleLink( $style, array $options)
Generate <link> tags for stylesheets.
Definition: OutputPage.php:3874
OutputPage\$mEnableTOC
bool $mEnableTOC
Whether parser output contains a table of contents.
Definition: OutputPage.php:310
Config\get
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
OutputPage\$mSubtitle
array $mSubtitle
Contains the page subtitle.
Definition: OutputPage.php:107
OutputPage\setFileVersion
setFileVersion( $file)
Set the displayed file version.
Definition: OutputPage.php:1731
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2475
OutputPage\getLinkHeader
getLinkHeader()
Return a Link: header.
Definition: OutputPage.php:2305
OutputPage\getResourceLoader
getResourceLoader()
Get a ResourceLoader object associated with this OutputPage.
Definition: OutputPage.php:3144
OutputPage\isTOCEnabled
isTOCEnabled()
Whether the output has a table of contents.
Definition: OutputPage.php:4099
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:31
ContextSource\getWikiPage
getWikiPage()
Get the WikiPage object.
Definition: ContextSource.php:115
OutputPage\setFeedAppendQuery
setFeedAppendQuery( $val)
Add default feeds to the page header This is mainly kept for backward compatibility,...
Definition: OutputPage.php:1215
OutputPage\setDisplayTitle
setDisplayTitle( $html)
Same as page title but only contains name of the page, not any other text.
Definition: OutputPage.php:1013
$modules
$modules
Definition: HTMLFormElement.php:15
OutputPage\isDisabled
isDisabled()
Return whether the output will be completely disabled.
Definition: OutputPage.php:1154
OutputPage\setRevisionId
setRevisionId( $revid)
Set the revision ID which will be seen by the wiki text parser for things such as embedded {{REVISION...
Definition: OutputPage.php:1680
OutputPage\setArticleFlag
setArticleFlag( $newVal)
Set whether the displayed content is related to the source of the corresponding article on the wiki S...
Definition: OutputPage.php:1271
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:211
OutputPage\disallowUserJs
disallowUserJs()
Do not allow scripts which can be modified by wiki users to load on this page; only allow scripts bun...
Definition: OutputPage.php:1555
ContextSource\getSkin
getSkin()
Definition: ContextSource.php:152
OutputPage\setSubtitle
setSubtitle( $str)
Replace the subtitle with $str.
Definition: OutputPage.php:1064
$args
if( $line===false) $args
Definition: mcc.php:124
OutputPage\$mInlineStyles
string $mInlineStyles
Inline CSS styles.
Definition: OutputPage.php:145
wfCgiToArray
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
Definition: GlobalFunctions.php:391
OutputPage\getVaryHeader
getVaryHeader()
Return a Vary: header on which to vary caches.
Definition: OutputPage.php:2279
OutputPage\addModules
addModules( $modules)
Load one or more ResourceLoader modules on this page.
Definition: OutputPage.php:559
OutputPage\showLagWarning
showLagWarning( $lag)
Show a warning about replica DB lag.
Definition: OutputPage.php:2840
$title
$title
Definition: testCompression.php:38
OutputPage\getCacheVaryCookies
getCacheVaryCookies()
Get the list of cookie names that will influence the cache.
Definition: OutputPage.php:2220
OutputPage\setCopyrightUrl
setCopyrightUrl( $url)
Set the copyright URL to send with the output.
Definition: OutputPage.php:385
OutputPage\$mFollowPolicy
$mFollowPolicy
Definition: OutputPage.php:278
OutputPage\$rlClient
ResourceLoaderClientHtml $rlClient
Definition: OutputPage.php:175
OutputPage\addHtmlClasses
addHtmlClasses( $classes)
Add a class to the <html> element.
Definition: OutputPage.php:643
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:83
OutputPage\getIndexPolicy
getIndexPolicy()
Get the current index policy for the page as a string.
Definition: OutputPage.php:909
OutputPage\addBodyClasses
addBodyClasses( $classes)
Add a class to the <body> element.
Definition: OutputPage.php:698
ParserOutput\getIndicators
getIndicators()
Definition: ParserOutput.php:584
ResourceLoaderModule\getOrigin
getOrigin()
Get this module's origin.
Definition: ResourceLoaderModule.php:145
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:910
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:61
OutputPage\isArticle
isArticle()
Return whether the content displayed page is related to the source of the corresponding article on th...
Definition: OutputPage.php:1284
OutputPage
This is one of the Core classes and should be read at least once by any new developers.
Definition: OutputPage.php:47
ParserOutput\getLanguageLinks
& getLanguageLinks()
Definition: ParserOutput.php:564
OutputPage\showErrorPage
showErrorPage( $title, $msg, $params=[])
Output a standard error page.
Definition: OutputPage.php:2675
OutputPage\addParserOutputText
addParserOutputText(ParserOutput $parserOutput, $poOptions=[])
Add the HTML associated with a ParserOutput object, without any metadata.
Definition: OutputPage.php:2003
OutputPage\getCSPNonce
getCSPNonce()
Get (and set if not yet set) the CSP nonce.
Definition: OutputPage.php:4148
OutputPage\$mParserOptions
ParserOptions $mParserOptions
lazy initialised, use parserOptions()
Definition: OutputPage.php:218
OutputPage\$mContainsNewMagic
int $mContainsNewMagic
Definition: OutputPage.php:212
JavaScriptContent
Content for JavaScript pages.
Definition: JavaScriptContent.php:36
OutputPage\$limitReportJSData
array $limitReportJSData
Profiling data.
Definition: OutputPage.php:318
OutputPage\addInlineScript
addInlineScript( $script)
Add a self-contained script tag with the given contents Internal use only.
Definition: OutputPage.php:489
ParserOutput\getTemplateIds
& getTemplateIds()
Definition: ParserOutput.php:612
OutputPage\getArticleBodyOnly
getArticleBodyOnly()
Return whether the output will contain only the body of the article.
Definition: OutputPage.php:718
OutputPage\getPreventClickjacking
getPreventClickjacking()
Get the prevent-clickjacking flag.
Definition: OutputPage.php:2361
ParserOutput\getTOCHTML
getTOCHTML()
Definition: ParserOutput.php:668
OutputPage\$mModules
array $mModules
Definition: OutputPage.php:166
OutputPage\addWikiTextAsContent
addWikiTextAsContent( $text, $linestart=true, Title $title=null)
Convert wikitext in the page content language to HTML and add it to the buffer.
Definition: OutputPage.php:1834
ParserOutput\getExtraCSPScriptSrcs
getExtraCSPScriptSrcs()
Get extra Content-Security-Policy 'script-src' directives.
Definition: ParserOutput.php:705
OutputPage\getCanonicalUrl
getCanonicalUrl()
Returns the URL to be used for the <link rel=canonical>> if one is set.
Definition: OutputPage.php:456
OutputPage\wrapWikiMsg
wrapWikiMsg( $wrap,... $msgSpecs)
This function takes a number of message/argument specifications, wraps them in some overall structure...
Definition: OutputPage.php:4079
OutputPage\setStatusCode
setStatusCode( $statusCode)
Set the HTTP status code to send with the output.
Definition: OutputPage.php:394
OutputPage\$mRedirect
string $mRedirect
Definition: OutputPage.php:110
Html\inlineStyle
static inlineStyle( $contents, $media='all', $attribs=[])
Output a "<style>" tag with the given contents for the given media type (if any).
Definition: Html.php:619
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:187
OutputPage\$mIsArticle
bool $mIsArticle
Is the displayed content related to the source of the corresponding wiki article.
Definition: OutputPage.php:89
OutputPage\haveCacheVaryCookies
haveCacheVaryCookies()
Check if the request has a cache-varying cookie header If it does, it's very important that we don't ...
Definition: OutputPage.php:2241
ResourceLoader\makeLoaderQuery
static makeLoaderQuery(array $modules, $lang, $skin, $user=null, $version=null, $debug=false, $only=null, $printable=false, $handheld=false, array $extraQuery=[])
Build a query array (array representation of query string) for load.php.
Definition: ResourceLoader.php:1845
OutputPage\getPageTitle
getPageTitle()
Return the "page title", i.e.
Definition: OutputPage.php:1002
OutputPage\disable
disable()
Disable output completely, i.e.
Definition: OutputPage.php:1145
OutputPage\setIndexPolicy
setIndexPolicy( $policy)
Set the index policy for the page, but leave the follow policy un- touched.
Definition: OutputPage.php:897
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:617
OutputPage\$mResourceLoader
ResourceLoader $mResourceLoader
Definition: OutputPage.php:172
ParserOutput\getNewSection
getNewSection()
Definition: ParserOutput.php:798
$content
$content
Definition: router.php:76
Skin\getPageClasses
getPageClasses( $title)
TODO: document.
Definition: Skin.php:465
OutputPage\addCategoryLinks
addCategoryLinks(array $categories)
Add an array of categories, with names in the keys.
Definition: OutputPage.php:1366
OutputPage\setRevisionTimestamp
setRevisionTimestamp( $timestamp)
Set the timestamp of the revision which will be displayed.
Definition: OutputPage.php:1711
OutputPage\getHeadItemsArray
getHeadItemsArray()
Get an array of head items.
Definition: OutputPage.php:652
wfClearOutputBuffers
wfClearOutputBuffers()
More legible than passing a 'false' parameter to wfResetOutputBuffers():
Definition: GlobalFunctions.php:1694
OutputPage\$CSP
ContentSecurityPolicy $CSP
Definition: OutputPage.php:334
OutputPage\addReturnTo
addReturnTo( $title, array $query=[], $text=null, $options=[])
Add a "return to" link pointing to a specified title.
Definition: OutputPage.php:2873
OutputPage\buildExemptModules
buildExemptModules()
Build exempt modules and legacy non-ResourceLoader styles.
Definition: OutputPage.php:3800
OutputPage\$copyrightUrl
string null $copyrightUrl
The URL to send in a <link> element with rel=license.
Definition: OutputPage.php:315
OutputPage\getProperty
getProperty( $name)
Get an additional output property.
Definition: OutputPage.php:740
ParserOptions\newFromContext
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
Definition: ParserOptions.php:1102
OutputPage\addWikiMsg
addWikiMsg(... $args)
Add a wikitext-formatted message to the output.
Definition: OutputPage.php:4036
Html\inlineScript
static inlineScript( $contents, $nonce=null)
Output an HTML script tag with the given contents.
Definition: Html.php:572
$header
$header
Definition: updateCredits.php:41
OutputPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: OutputPage.php:1523
OutputPage\formatPermissionsErrorMessage
formatPermissionsErrorMessage(array $errors, $action=null)
Format a list of error messages.
Definition: OutputPage.php:2801
ParserOutput\getOutputHooks
getOutputHooks()
Definition: ParserOutput.php:656
OutputPage\$mIndicators
array $mIndicators
Definition: OutputPage.php:131
OutputPage\setTarget
setTarget( $target)
Sets ResourceLoader target for load.php links.
Definition: OutputPage.php:601
OutputPage\getRobotPolicy
getRobotPolicy()
Get the current robot policy for the page as a string in the form <index policy>,<follow policy>.
Definition: OutputPage.php:886
ParserOutput\getHideNewSection
getHideNewSection()
Definition: ParserOutput.php:794
MediaWiki\Session\SessionManager
This serves as the entry point to the MediaWiki session handling system.
Definition: SessionManager.php:52
OutputPage\$contentOverrideCallbacks
callable[] $contentOverrideCallbacks
Definition: OutputPage.php:324
OutputPage\setHTMLTitle
setHTMLTitle( $name)
"HTML title" means the contents of "<title>".
Definition: OutputPage.php:942
DerivativeResourceLoaderContext
A mutable version of ResourceLoaderContext.
Definition: DerivativeResourceLoaderContext.php:33
MediaWiki\Linker\LinkTarget\getDBkey
getDBkey()
Get the main part with underscores.
OutputPage\$mMetatags
string[][] $mMetatags
Should be private.
Definition: OutputPage.php:51
OutputPage\setLanguageLinks
setLanguageLinks(array $newLinkArray)
Reset the language links and add new language links.
Definition: OutputPage.php:1348
OutputPage\setupOOUI
static setupOOUI( $skinName='default', $dir='ltr')
Helper function to setup the PHP implementation of OOUI to use in this request.
Definition: OutputPage.php:4110
OutputPage\$rlExemptStyleModules
array $rlExemptStyleModules
Definition: OutputPage.php:181
OutputPage\$mAdditionalHtmlClasses
array $mAdditionalHtmlClasses
Additional <html> classes; This should be rarely modified; prefer mAdditionalBodyClasses.
Definition: OutputPage.php:157
OutputPage\$mProperties
$mProperties
Additional key => value data.
Definition: OutputPage.php:300
PROTO_RELATIVE
const PROTO_RELATIVE
Definition: Defines.php:210
OutputPage\prependHTML
prependHTML( $text)
Prepend $text to the body HTML.
Definition: OutputPage.php:1606
ParserOutput\getNoGallery
getNoGallery()
Definition: ParserOutput.php:632
OutputPage\$mEnableClientCache
$mEnableClientCache
Definition: OutputPage.php:228
OutputPage\getHTMLTitle
getHTMLTitle()
Return the "HTML title", i.e.
Definition: OutputPage.php:955
OutputPage\$cacheIsFinal
bool $cacheIsFinal
See OutputPage::couldBePublicCached.
Definition: OutputPage.php:74
OutputPage\clearSubtitle
clearSubtitle()
Clear the subtitles.
Definition: OutputPage.php:1112
OutputPage\warnModuleTargetFilter
warnModuleTargetFilter( $moduleName)
Definition: OutputPage.php:521
OutputPage\$mCdnMaxage
int $mCdnMaxage
Cache stuff.
Definition: OutputPage.php:247
OutputPage\enableOOUI
enableOOUI()
Add ResourceLoader module styles for OOUI and set up the PHP implementation of it for use with MediaW...
Definition: OutputPage.php:4125
OutputPage\$cacheVaryCookies
static array $cacheVaryCookies
A cache of the names of the cookies that will influence the cache.
Definition: OutputPage.php:339
OutputPage\$mScripts
$mScripts
Used for JavaScript (predates ResourceLoader)
Definition: OutputPage.php:142
OutputPage\$mAllowedModules
array $mAllowedModules
What level of 'untrustworthiness' is allowed in CSS/JS modules loaded on this page?
Definition: OutputPage.php:202
getSkinThemeMap
static getSkinThemeMap()
Return a map of skin names (in lowercase) to OOUI theme names, defining which theme a given skin shou...
Definition: ResourceLoaderOOUIModule.php:76
OutputPage\$mPrintable
bool $mPrintable
We have to set isPrintable().
Definition: OutputPage.php:101
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
OutputPage\$mLanguageLinks
array $mLanguageLinks
Array of Interwiki Prefixed (non DB key) Titles (e.g.
Definition: OutputPage.php:134
OutputPage\setCategoryLinks
setCategoryLinks(array $categories)
Reset the category links (but not the category list) and add $categories.
Definition: OutputPage.php:1448
OutputPage\setFollowPolicy
setFollowPolicy( $policy)
Set the follow policy for the page, but leave the index policy un- touched.
Definition: OutputPage.php:920
Content
Base interface for content objects.
Definition: Content.php:35
OutputPage\setPageTitle
setPageTitle( $name)
"Page title" means the contents of <h1>.
Definition: OutputPage.php:980
OutputPage\getRlClient
getRlClient()
Call this to freeze the module queue and JS config and create a formatter.
Definition: OutputPage.php:2972
ResourceLoaderClientHtml\makeLoad
static makeLoad(ResourceLoaderContext $mainContext, array $modules, $only, array $extraQuery=[], $nonce=null)
Explicitly load or embed modules on a page.
Definition: ResourceLoaderClientHtml.php:388
OutputPage\$mFileVersion
array $mFileVersion
Definition: OutputPage.php:265
OutputPage\checkLastModified
checkLastModified( $timestamp)
checkLastModified tells the client to use the client-cached page if possible.
Definition: OutputPage.php:755
OutputPage\$mNoGallery
bool $mNoGallery
Comes from the parser.
Definition: OutputPage.php:244
OutputPage\$mHeadItems
array $mHeadItems
Array of elements in "<head>".
Definition: OutputPage.php:160
OutputPage\$mRevisionTimestamp
string $mRevisionTimestamp
Definition: OutputPage.php:262
OutputPage\$displayTitle
string $displayTitle
The displayed title of the page.
Definition: OutputPage.php:71
ParserOutput\getFileSearchOptions
& getFileSearchOptions()
Definition: ParserOutput.php:620
Title
Represents a title within MediaWiki.
Definition: Title.php:41
ResourceLoaderModule
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
Definition: ResourceLoaderModule.php:39
OutputPage\setCdnMaxage
setCdnMaxage( $maxage)
Set the value of the "s-maxage" part of the "Cache-control" HTTP header.
Definition: OutputPage.php:2126
Parser\stripOuterParagraph
static stripOuterParagraph( $html)
Strip outer.
Definition: Parser.php:6231
OutputPage\getAllowedModules
getAllowedModules( $type)
Show what level of JavaScript / CSS untrustworthiness is allowed on this page.
Definition: OutputPage.php:1580
ResourceLoader
ResourceLoader is a loading system for JavaScript and CSS resources.
Definition: ResourceLoader.php:56
OutputPage\addVaryHeader
addVaryHeader( $header, array $option=null)
Add an HTTP header that will influence on the cache.
Definition: OutputPage.php:2262
ContentHandler\getContentText
static getContentText(Content $content=null)
Convenience function for getting flat text from a Content object.
Definition: ContentHandler.php:91
OutputPage\setProperty
setProperty( $name, $value)
Set an additional output property.
Definition: OutputPage.php:729
OutputPage\isPrintable
isPrintable()
Return whether the page is "printable".
Definition: OutputPage.php:1138
OutputPage\setSyndicated
setSyndicated( $show=true)
Add or remove feed links in the page header This is mainly kept for backward compatibility,...
Definition: OutputPage.php:1184
OutputPage\wrapWikiTextAsInterface
wrapWikiTextAsInterface( $wrapperClass, $text)
Convert wikitext in the user interface language to HTML and add it to the buffer with a <div class="$...
Definition: OutputPage.php:1809
OutputPage\$mTarget
string null $mTarget
ResourceLoader target for load.php links.
Definition: OutputPage.php:305
OutputPage\addInlineStyle
addInlineStyle( $style_css, $flip='noflip')
Adds inline CSS styles Internal use only.
Definition: OutputPage.php:3787
ResourceLoaderClientHtml\setModules
setModules(array $modules)
Ensure one or more modules are loaded.
Definition: ResourceLoaderClientHtml.php:88
OutputPage\userCanPreview
userCanPreview()
To make it harder for someone to slip a user a fake JavaScript or CSS preview, a random token is asso...
Definition: OutputPage.php:3427
Html\linkedStyle
static linkedStyle( $url, $media='all')
Output a "<link rel=stylesheet>" linking to the given URL for the given media type (if any).
Definition: Html.php:648
OutputPage\$mPageTitle
string $mPageTitle
The contents of.
Definition: OutputPage.php:62
ResourceLoader\inDebugMode
static inDebugMode()
Determine whether debug mode is on.
Definition: ResourceLoader.php:1761
OutputPage\setRedirectedFrom
setRedirectedFrom( $t)
Set $mRedirectedFrom, the Title of the page which redirected us to the current page.
Definition: OutputPage.php:964
ResourceLoaderClientHtml\setModuleStyles
setModuleStyles(array $modules)
Ensure the styles of one or more modules are loaded.
Definition: ResourceLoaderClientHtml.php:97
OutputPage\filterModules
filterModules(array $modules, $position=null, $type=ResourceLoaderModule::TYPE_COMBINED)
Filter an array of modules to remove insufficiently trustworthy members, and modules which are no lon...
Definition: OutputPage.php:501
WebRequest\getRequestId
static getRequestId()
Get the unique request ID.
Definition: WebRequest.php:327
OutputPage\redirect
redirect( $url, $responsecode='302')
Redirect to $url rather than displaying the normal page.
Definition: OutputPage.php:362
OutputPage\getUnprefixedDisplayTitle
getUnprefixedDisplayTitle()
Returns page display title without namespace prefix if possible.
Definition: OutputPage.php:1040
IContextSource\getConfig
getConfig()
Get the site configuration.
OutputPage\$mJsConfigVars
array $mJsConfigVars
Definition: OutputPage.php:184
$path
$path
Definition: NoLocalSettings.php:25
ParserOutput\getCategories
& getCategories()
Definition: ParserOutput.php:576
OutputPage\setPrintable
setPrintable()
Set the page as printable, i.e.
Definition: OutputPage.php:1129
OutputPage\getHeadLinksArray
getHeadLinksArray()
Definition: OutputPage.php:3474
OutputPage\adaptCdnTTL
adaptCdnTTL( $mtime, $minTTL=0, $maxTTL=0)
Get TTL in [$minTTL,$maxTTL] and pass it to lowerCdnMaxage()
Definition: OutputPage.php:2156
OutputPage\getCdnCacheEpoch
getCdnCacheEpoch( $reqTime, $maxAge)
Definition: OutputPage.php:843
OutputPage\allowClickjacking
allowClickjacking()
Turn off frame-breaking.
Definition: OutputPage.php:2351
LanguageCode\bcp47
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.
Definition: LanguageCode.php:175
OutputPage\loadSkinModules
loadSkinModules( $sk)
Transfer styles and JavaScript modules from skin.
Definition: OutputPage.php:2496
OutputPage\showFatalError
showFatalError( $message)
Output an error page.
Definition: OutputPage.php:2859
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:251
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
OutputPage\getHTML
getHTML()
Get the body HTML.
Definition: OutputPage.php:1644
Message
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:161
OutputPage\$mRevisionId
int null $mRevisionId
To include the variable {{REVISIONID}}.
Definition: OutputPage.php:259
OutputPage\parseInlineAsInterface
parseInlineAsInterface( $text, $linestart=true)
Parse wikitext in the user interface language, strip paragraph wrapper, and return the HTML.
Definition: OutputPage.php:2084
OutputPage\$mLinkHeader
$mLinkHeader
Link: header contents.
Definition: OutputPage.php:329
$keys
$keys
Definition: testCompression.php:72
OutputPage\$styles
array $styles
An array of stylesheet filenames (relative from skins path), with options for CSS media,...
Definition: OutputPage.php:275
OutputPage\isRevisionCurrent
isRevisionCurrent()
Whether the revision displayed is the latest revision of the page.
Definition: OutputPage.php:1700
Sanitizer\normalizeCharReferences
static normalizeCharReferences( $text)
Ensure that any entities and character references are legal for XML and XHTML specifically.
Definition: Sanitizer.php:1127
MWDebug\addModules
static addModules(OutputPage $out)
Add ResourceLoader modules to the OutputPage object if debugging is enabled.
Definition: MWDebug.php:125
CacheTime\isCacheable
isCacheable()
Definition: CacheTime.php:208
IContextSource\getRequest
getRequest()
OutputPage\showNewSectionLink
showNewSectionLink()
Show an "add new section" link?
Definition: OutputPage.php:1163
OutputPage\$mPageLinkTitle
string $mPageLinkTitle
Used by skin template.
Definition: OutputPage.php:151
ParserOutput\getText
getText( $options=[])
Get the output HTML.
Definition: ParserOutput.php:344
OutputPage\$mCanonicalUrl
string bool $mCanonicalUrl
Definition: OutputPage.php:57
OutputPage\makeResourceLoaderLink
makeResourceLoaderLink( $modules, $only, array $extraQuery=[])
Explicily load or embed modules on a page.
Definition: OutputPage.php:3160
OutputPage\addWikiTextTitleInternal
addWikiTextTitleInternal( $text, Title $title, $linestart, $interface, $wrapperClass=null)
Add wikitext with a custom Title object.
Definition: OutputPage.php:1858
OutputPage\getIndicators
getIndicators()
Get the indicators associated with this page.
Definition: OutputPage.php:1511
$t
$t
Definition: testCompression.php:74
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:644
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
Skin\getSkinName
getSkinName()
Definition: Skin.php:169
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
OutputPage\addJsConfigVars
addJsConfigVars( $keys, $value=null)
Add one or more variables to be set in mw.config in JavaScript.
Definition: OutputPage.php:3226
OutputPage\$mPreventClickjacking
bool $mPreventClickjacking
Controls if anti-clickjacking / frame-breaking headers will be sent.
Definition: OutputPage.php:256
Skin
The main skin class which provides methods and properties for all other skins.
Definition: Skin.php:42
OutputPage\getFollowPolicy
getFollowPolicy()
Get the current follow policy for the page as a string.
Definition: OutputPage.php:932
OutputPage\getCategories
getCategories( $type='all')
Get the list of category names this page belongs to.
Definition: OutputPage.php:1474
OutputPage\getJsConfigVars
getJsConfigVars()
Get the javascript config vars to include on this page.
Definition: OutputPage.php:3216
OutputPage\setCopyright
setCopyright( $hasCopyright)
Set whether the standard copyright should be shown for the current page.
Definition: OutputPage.php:1315
OutputPage\getTemplateIds
getTemplateIds()
Get the templates used on this page.
Definition: OutputPage.php:1754
$IP
$IP
Definition: WebStart.php:49
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:56
OutputPage\$mIsArticleRelated
bool $mIsArticleRelated
Stores "article flag" toggle.
Definition: OutputPage.php:92
Skin\isResponsive
isResponsive()
Indicates if this skin is responsive.
Definition: Skin.php:182
OutputPage\isSyndicated
isSyndicated()
Should we output feed links for this page?
Definition: OutputPage.php:1243
OutputPage\$mFeedLinksAppendQuery
$mFeedLinksAppendQuery
Definition: OutputPage.php:195
OutputPage\getFileSearchOptions
getFileSearchOptions()
Get the files used on this page.
Definition: OutputPage.php:1764
OutputPage\$mFeedLinks
$mFeedLinks
Handles the Atom / RSS links.
Definition: OutputPage.php:225
OutputPage\$mDoNothing
bool $mDoNothing
Whether output is disabled.
Definition: OutputPage.php:207
OutputPage\$mArticleBodyOnly
bool $mArticleBodyOnly
Flag if output should only contain the body of the article.
Definition: OutputPage.php:231
OutputPage\$mHasCopyright
bool $mHasCopyright
Is the content subject to copyright.
Definition: OutputPage.php:95
OutputPage\addParserOutput
addParserOutput(ParserOutput $parserOutput, $poOptions=[])
Add everything from a ParserOutput object.
Definition: OutputPage.php:2015
OutputPage\$mAdditionalBodyClasses
array $mAdditionalBodyClasses
Additional <body> classes; there are also <body> classes from other sources.
Definition: OutputPage.php:163
ContentSecurityPolicy
Definition: ContentSecurityPolicy.php:32
OutputPage\prepareErrorPage
prepareErrorPage( $pageTitle, $htmlTitle=false)
Prepare this object to display an error page; disable caching and indexing, clear the current text an...
Definition: OutputPage.php:2650
OutputPage\addTemplate
addTemplate(&$template)
Add the output of a QuickTemplate to the output buffer.
Definition: OutputPage.php:2025
OutputPage\getFeedAppendQuery
getFeedAppendQuery()
Will currently always return null.
Definition: OutputPage.php:1260
OutputPage\lowerCdnMaxage
lowerCdnMaxage( $maxage)
Set the value of the "s-maxage" part of the "Cache-control" HTTP header to $maxage if that is lower t...
Definition: OutputPage.php:2139
OutputPage\$mHTMLtitle
string $mHTMLtitle
Stores contents of "<title>" tag.
Definition: OutputPage.php:83
ParserOutput\getExtraCSPStyleSrcs
getExtraCSPStyleSrcs()
Get extra Content-Security-Policy 'style-src' directives.
Definition: ParserOutput.php:714
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:490
OutputPage\addFeedLink
addFeedLink( $format, $href)
Add a feed link to the page header.
Definition: OutputPage.php:1233
ParserOutput\preventClickjacking
preventClickjacking( $flag=null)
Get or set the prevent-clickjacking flag.
Definition: ParserOutput.php:1355
OutputPage\$mCategoryLinks
array $mCategoryLinks
Definition: OutputPage.php:122
OutputPage\transformResourcePath
static transformResourcePath(Config $config, $path)
Transform path to web-accessible static resource.
Definition: OutputPage.php:3931
OutputPage\parseAsContent
parseAsContent( $text, $linestart=true)
Parse wikitext in the page content language and return the HTML.
Definition: OutputPage.php:2040
OutputPage\getAdvertisedFeedTypes
getAdvertisedFeedTypes()
Return effective list of advertised feed types.
Definition: OutputPage.php:1198
OutputPage\setRobotPolicy
setRobotPolicy( $policy)
Set the robot policy for the page: http://www.robotstxt.org/meta.html
Definition: OutputPage.php:869
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
Definition: GlobalFunctions.php:346
OutputPage\transformFilePath
static transformFilePath( $remotePathPrefix, $localPath, $file)
Utility method for transformResourceFilePath().
Definition: OutputPage.php:3973
OutputPage\headElement
headElement(Skin $sk, $includeStyle=true)
Definition: OutputPage.php:3047
$type
$type
Definition: testCompression.php:52
OutputPage\$mStatusCode
int $mStatusCode
Definition: OutputPage.php:113