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 
644  public function addHtmlClasses( $classes ) {
645  $this->mAdditionalHtmlClasses = array_merge( $this->mAdditionalHtmlClasses, (array)$classes );
646  }
647 
653  public function getHeadItemsArray() {
654  return $this->mHeadItems;
655  }
656 
669  public function addHeadItem( $name, $value ) {
670  $this->mHeadItems[$name] = $value;
671  }
672 
679  public function addHeadItems( $values ) {
680  $this->mHeadItems = array_merge( $this->mHeadItems, (array)$values );
681  }
682 
689  public function hasHeadItem( $name ) {
690  return isset( $this->mHeadItems[$name] );
691  }
692 
699  public function addBodyClasses( $classes ) {
700  $this->mAdditionalBodyClasses = array_merge( $this->mAdditionalBodyClasses, (array)$classes );
701  }
702 
710  public function setArticleBodyOnly( $only ) {
711  $this->mArticleBodyOnly = $only;
712  }
713 
719  public function getArticleBodyOnly() {
721  }
722 
730  public function setProperty( $name, $value ) {
731  $this->mProperties[$name] = $value;
732  }
733 
741  public function getProperty( $name ) {
742  return $this->mProperties[$name] ?? null;
743  }
744 
756  public function checkLastModified( $timestamp ) {
757  if ( !$timestamp || $timestamp == '19700101000000' ) {
758  wfDebug( __METHOD__ . ": CACHE DISABLED, NO TIMESTAMP" );
759  return false;
760  }
761  $config = $this->getConfig();
762  if ( !$config->get( 'CachePages' ) ) {
763  wfDebug( __METHOD__ . ": CACHE DISABLED" );
764  return false;
765  }
766 
767  $timestamp = wfTimestamp( TS_MW, $timestamp );
768  $modifiedTimes = [
769  'page' => $timestamp,
770  'user' => $this->getUser()->getTouched(),
771  'epoch' => $config->get( 'CacheEpoch' )
772  ];
773  if ( $config->get( 'UseCdn' ) ) {
774  $modifiedTimes['sepoch'] = wfTimestamp( TS_MW, $this->getCdnCacheEpoch(
775  time(),
776  $config->get( 'CdnMaxAge' )
777  ) );
778  }
779  $this->getHookRunner()->onOutputPageCheckLastModified( $modifiedTimes, $this );
780 
781  $maxModified = max( $modifiedTimes );
782  $this->mLastModified = wfTimestamp( TS_RFC2822, $maxModified );
783 
784  $clientHeader = $this->getRequest()->getHeader( 'If-Modified-Since' );
785  if ( $clientHeader === false ) {
786  wfDebug( __METHOD__ . ": client did not send If-Modified-Since header", 'private' );
787  return false;
788  }
789 
790  # IE sends sizes after the date like this:
791  # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
792  # this breaks strtotime().
793  $clientHeader = preg_replace( '/;.*$/', '', $clientHeader );
794 
795  Wikimedia\suppressWarnings(); // E_STRICT system time warnings
796  $clientHeaderTime = strtotime( $clientHeader );
797  Wikimedia\restoreWarnings();
798  if ( !$clientHeaderTime ) {
799  wfDebug( __METHOD__
800  . ": unable to parse the client's If-Modified-Since header: $clientHeader" );
801  return false;
802  }
803  $clientHeaderTime = wfTimestamp( TS_MW, $clientHeaderTime );
804 
805  # Make debug info
806  $info = '';
807  foreach ( $modifiedTimes as $name => $value ) {
808  if ( $info !== '' ) {
809  $info .= ', ';
810  }
811  $info .= "$name=" . wfTimestamp( TS_ISO_8601, $value );
812  }
813 
814  wfDebug( __METHOD__ . ": client sent If-Modified-Since: " .
815  wfTimestamp( TS_ISO_8601, $clientHeaderTime ), 'private' );
816  wfDebug( __METHOD__ . ": effective Last-Modified: " .
817  wfTimestamp( TS_ISO_8601, $maxModified ), 'private' );
818  if ( $clientHeaderTime < $maxModified ) {
819  wfDebug( __METHOD__ . ": STALE, $info", 'private' );
820  return false;
821  }
822 
823  # Not modified
824  # Give a 304 Not Modified response code and disable body output
825  wfDebug( __METHOD__ . ": NOT MODIFIED, $info", 'private' );
826  ini_set( 'zlib.output_compression', 0 );
827  $this->getRequest()->response()->statusHeader( 304 );
828  $this->sendCacheControl();
829  $this->disable();
830 
831  // Don't output a compressed blob when using ob_gzhandler;
832  // it's technically against HTTP spec and seems to confuse
833  // Firefox when the response gets split over two packets.
835 
836  return true;
837  }
838 
844  private function getCdnCacheEpoch( $reqTime, $maxAge ) {
845  // Ensure Last-Modified is never more than $wgCdnMaxAge in the past,
846  // because even if the wiki page content hasn't changed since, static
847  // resources may have changed (skin HTML, interface messages, urls, etc.)
848  // and must roll-over in a timely manner (T46570)
849  return $reqTime - $maxAge;
850  }
851 
858  public function setLastModified( $timestamp ) {
859  $this->mLastModified = wfTimestamp( TS_RFC2822, $timestamp );
860  }
861 
870  public function setRobotPolicy( $policy ) {
871  $policy = Article::formatRobotPolicy( $policy );
872 
873  if ( isset( $policy['index'] ) ) {
874  $this->setIndexPolicy( $policy['index'] );
875  }
876  if ( isset( $policy['follow'] ) ) {
877  $this->setFollowPolicy( $policy['follow'] );
878  }
879  }
880 
887  public function getRobotPolicy() {
888  return "{$this->mIndexPolicy},{$this->mFollowPolicy}";
889  }
890 
898  public function setIndexPolicy( $policy ) {
899  $policy = trim( $policy );
900  if ( in_array( $policy, [ 'index', 'noindex' ] ) ) {
901  $this->mIndexPolicy = $policy;
902  }
903  }
904 
910  public function getIndexPolicy() {
911  return $this->mIndexPolicy;
912  }
913 
921  public function setFollowPolicy( $policy ) {
922  $policy = trim( $policy );
923  if ( in_array( $policy, [ 'follow', 'nofollow' ] ) ) {
924  $this->mFollowPolicy = $policy;
925  }
926  }
927 
933  public function getFollowPolicy() {
934  return $this->mFollowPolicy;
935  }
936 
943  public function setHTMLTitle( $name ) {
944  if ( $name instanceof Message ) {
945  $this->mHTMLtitle = $name->setContext( $this->getContext() )->text();
946  } else {
947  $this->mHTMLtitle = $name;
948  }
949  }
950 
956  public function getHTMLTitle() {
957  return $this->mHTMLtitle;
958  }
959 
965  public function setRedirectedFrom( $t ) {
966  $this->mRedirectedFrom = $t;
967  }
968 
981  public function setPageTitle( $name ) {
982  if ( $name instanceof Message ) {
983  $name = $name->setContext( $this->getContext() )->text();
984  }
985 
986  # change "<script>foo&bar</script>" to "&lt;script&gt;foo&amp;bar&lt;/script&gt;"
987  # but leave "<i>foobar</i>" alone
989  $this->mPageTitle = $nameWithTags;
990 
991  # change "<i>foo&amp;bar</i>" to "foo&bar"
992  $this->setHTMLTitle(
993  $this->msg( 'pagetitle' )->plaintextParams( Sanitizer::stripAllTags( $nameWithTags ) )
994  ->inContentLanguage()
995  );
996  }
997 
1003  public function getPageTitle() {
1004  return $this->mPageTitle;
1005  }
1006 
1014  public function setDisplayTitle( $html ) {
1015  $this->displayTitle = $html;
1016  }
1017 
1026  public function getDisplayTitle() {
1027  $html = $this->displayTitle;
1028  if ( $html === null ) {
1029  $html = $this->getTitle()->getPrefixedText();
1030  }
1031 
1033  }
1034 
1041  public function getUnprefixedDisplayTitle() {
1042  $text = $this->getDisplayTitle();
1043  $nsPrefix = $this->getTitle()->getNsText() . ':';
1044  $prefix = preg_quote( $nsPrefix, '/' );
1045 
1046  return preg_replace( "/^$prefix/i", '', $text );
1047  }
1048 
1054  public function setTitle( Title $t ) {
1055  // @phan-suppress-next-next-line PhanUndeclaredMethod
1056  // @fixme Not all implementations of IContextSource have this method!
1057  $this->getContext()->setTitle( $t );
1058  }
1059 
1065  public function setSubtitle( $str ) {
1066  $this->clearSubtitle();
1067  $this->addSubtitle( $str );
1068  }
1069 
1075  public function addSubtitle( $str ) {
1076  if ( $str instanceof Message ) {
1077  $this->mSubtitle[] = $str->setContext( $this->getContext() )->parse();
1078  } else {
1079  $this->mSubtitle[] = $str;
1080  }
1081  }
1082 
1091  public static function buildBacklinkSubtitle( Title $title, $query = [] ) {
1092  if ( $title->isRedirect() ) {
1093  $query['redirect'] = 'no';
1094  }
1095  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
1096  return wfMessage( 'backlinksubtitle' )
1097  ->rawParams( $linkRenderer->makeLink( $title, null, [], $query ) );
1098  }
1099 
1106  public function addBacklinkSubtitle( Title $title, $query = [] ) {
1107  $this->addSubtitle( self::buildBacklinkSubtitle( $title, $query ) );
1108  }
1109 
1113  public function clearSubtitle() {
1114  $this->mSubtitle = [];
1115  }
1116 
1122  public function getSubtitle() {
1123  return implode( "<br />\n\t\t\t\t", $this->mSubtitle );
1124  }
1125 
1130  public function setPrintable() {
1131  $this->mPrintable = true;
1132  }
1133 
1139  public function isPrintable() {
1140  return $this->mPrintable;
1141  }
1142 
1146  public function disable() {
1147  $this->mDoNothing = true;
1148  }
1149 
1155  public function isDisabled() {
1156  return $this->mDoNothing;
1157  }
1158 
1164  public function showNewSectionLink() {
1165  return $this->mNewSectionLink;
1166  }
1167 
1173  public function forceHideNewSectionLink() {
1175  }
1176 
1185  public function setSyndicated( $show = true ) {
1186  if ( $show ) {
1187  $this->setFeedAppendQuery( false );
1188  } else {
1189  $this->mFeedLinks = [];
1190  }
1191  }
1192 
1199  protected function getAdvertisedFeedTypes() {
1200  if ( $this->getConfig()->get( 'Feed' ) ) {
1201  return $this->getConfig()->get( 'AdvertisedFeedTypes' );
1202  } else {
1203  return [];
1204  }
1205  }
1206 
1216  public function setFeedAppendQuery( $val ) {
1217  $this->mFeedLinks = [];
1218 
1219  foreach ( $this->getAdvertisedFeedTypes() as $type ) {
1220  $query = "feed=$type";
1221  if ( is_string( $val ) ) {
1222  $query .= '&' . $val;
1223  }
1224  $this->mFeedLinks[$type] = $this->getTitle()->getLocalURL( $query );
1225  }
1226  }
1227 
1234  public function addFeedLink( $format, $href ) {
1235  if ( in_array( $format, $this->getAdvertisedFeedTypes() ) ) {
1236  $this->mFeedLinks[$format] = $href;
1237  }
1238  }
1239 
1244  public function isSyndicated() {
1245  return count( $this->mFeedLinks ) > 0;
1246  }
1247 
1252  public function getSyndicationLinks() {
1253  return $this->mFeedLinks;
1254  }
1255 
1261  public function getFeedAppendQuery() {
1263  }
1264 
1272  public function setArticleFlag( $newVal ) {
1273  $this->mIsArticle = $newVal;
1274  if ( $newVal ) {
1275  $this->mIsArticleRelated = $newVal;
1276  }
1277  }
1278 
1285  public function isArticle() {
1286  return $this->mIsArticle;
1287  }
1288 
1295  public function setArticleRelated( $newVal ) {
1296  $this->mIsArticleRelated = $newVal;
1297  if ( !$newVal ) {
1298  $this->mIsArticle = false;
1299  }
1300  }
1301 
1307  public function isArticleRelated() {
1308  return $this->mIsArticleRelated;
1309  }
1310 
1316  public function setCopyright( $hasCopyright ) {
1317  $this->mHasCopyright = $hasCopyright;
1318  }
1319 
1329  public function showsCopyright() {
1330  return $this->isArticle() || $this->mHasCopyright;
1331  }
1332 
1339  public function addLanguageLinks( array $newLinkArray ) {
1340  $this->mLanguageLinks = array_merge( $this->mLanguageLinks, $newLinkArray );
1341  }
1342 
1349  public function setLanguageLinks( array $newLinkArray ) {
1350  $this->mLanguageLinks = $newLinkArray;
1351  }
1352 
1358  public function getLanguageLinks() {
1359  return $this->mLanguageLinks;
1360  }
1361 
1367  public function addCategoryLinks( array $categories ) {
1368  if ( !$categories ) {
1369  return;
1370  }
1371 
1372  $res = $this->addCategoryLinksToLBAndGetResult( $categories );
1373 
1374  # Set all the values to 'normal'.
1375  $categories = array_fill_keys( array_keys( $categories ), 'normal' );
1376 
1377  # Mark hidden categories
1378  foreach ( $res as $row ) {
1379  if ( isset( $row->pp_value ) ) {
1380  $categories[$row->page_title] = 'hidden';
1381  }
1382  }
1383 
1384  # Add the remaining categories to the skin
1385  if ( $this->getHookRunner()->onOutputPageMakeCategoryLinks(
1386  $this, $categories, $this->mCategoryLinks )
1387  ) {
1388  $services = MediaWikiServices::getInstance();
1389  $linkRenderer = $services->getLinkRenderer();
1390  foreach ( $categories as $category => $type ) {
1391  // array keys will cast numeric category names to ints, so cast back to string
1392  $category = (string)$category;
1393  $origcategory = $category;
1394  $title = Title::makeTitleSafe( NS_CATEGORY, $category );
1395  if ( !$title ) {
1396  continue;
1397  }
1398  $services->getContentLanguage()->findVariantLink( $category, $title, true );
1399  if ( $category != $origcategory && array_key_exists( $category, $categories ) ) {
1400  continue;
1401  }
1402  $text = $services->getContentLanguage()->convertHtml( $title->getText() );
1403  $this->mCategories[$type][] = $title->getText();
1404  $this->mCategoryLinks[$type][] = $linkRenderer->makeLink( $title, new HtmlArmor( $text ) );
1405  }
1406  }
1407  }
1408 
1413  protected function addCategoryLinksToLBAndGetResult( array $categories ) {
1414  # Add the links to a LinkBatch
1415  $arr = [ NS_CATEGORY => $categories ];
1416  $lb = new LinkBatch;
1417  $lb->setArray( $arr );
1418 
1419  # Fetch existence plus the hiddencat property
1420  $dbr = wfGetDB( DB_REPLICA );
1421  $fields = array_merge(
1423  [ 'page_namespace', 'page_title', 'pp_value' ]
1424  );
1425 
1426  $res = $dbr->select( [ 'page', 'page_props' ],
1427  $fields,
1428  $lb->constructSet( 'page', $dbr ),
1429  __METHOD__,
1430  [],
1431  [ 'page_props' => [ 'LEFT JOIN', [
1432  'pp_propname' => 'hiddencat',
1433  'pp_page = page_id'
1434  ] ] ]
1435  );
1436 
1437  # Add the results to the link cache
1438  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1439  $lb->addResultToCache( $linkCache, $res );
1440 
1441  return $res;
1442  }
1443 
1449  public function setCategoryLinks( array $categories ) {
1450  $this->mCategoryLinks = [];
1451  $this->addCategoryLinks( $categories );
1452  }
1453 
1462  public function getCategoryLinks() {
1463  return $this->mCategoryLinks;
1464  }
1465 
1475  public function getCategories( $type = 'all' ) {
1476  if ( $type === 'all' ) {
1477  $allCategories = [];
1478  foreach ( $this->mCategories as $categories ) {
1479  $allCategories = array_merge( $allCategories, $categories );
1480  }
1481  return $allCategories;
1482  }
1483  if ( !isset( $this->mCategories[$type] ) ) {
1484  throw new InvalidArgumentException( 'Invalid category type given: ' . $type );
1485  }
1486  return $this->mCategories[$type];
1487  }
1488 
1498  public function setIndicators( array $indicators ) {
1499  $this->mIndicators = $indicators + $this->mIndicators;
1500  // Keep ordered by key
1501  ksort( $this->mIndicators );
1502  }
1503 
1512  public function getIndicators() {
1513  return $this->mIndicators;
1514  }
1515 
1524  public function addHelpLink( $to, $overrideBaseUrl = false ) {
1525  $this->addModuleStyles( 'mediawiki.helplink' );
1526  $text = $this->msg( 'helppage-top-gethelp' )->escaped();
1527 
1528  if ( $overrideBaseUrl ) {
1529  $helpUrl = $to;
1530  } else {
1531  $toUrlencoded = wfUrlencode( str_replace( ' ', '_', $to ) );
1532  $helpUrl = "https://www.mediawiki.org/wiki/Special:MyLanguage/$toUrlencoded";
1533  }
1534 
1535  $link = Html::rawElement(
1536  'a',
1537  [
1538  'href' => $helpUrl,
1539  'target' => '_blank',
1540  'class' => 'mw-helplink',
1541  ],
1542  $text
1543  );
1544 
1545  $this->setIndicators( [ 'mw-helplink' => $link ] );
1546  }
1547 
1556  public function disallowUserJs() {
1557  $this->reduceAllowedModules(
1558  ResourceLoaderModule::TYPE_SCRIPTS,
1559  ResourceLoaderModule::ORIGIN_CORE_INDIVIDUAL
1560  );
1561 
1562  // Site-wide styles are controlled by a config setting, see T73621
1563  // for background on why. User styles are never allowed.
1564  if ( $this->getConfig()->get( 'AllowSiteCSSOnRestrictedPages' ) ) {
1565  $styleOrigin = ResourceLoaderModule::ORIGIN_USER_SITEWIDE;
1566  } else {
1567  $styleOrigin = ResourceLoaderModule::ORIGIN_CORE_INDIVIDUAL;
1568  }
1569  $this->reduceAllowedModules(
1570  ResourceLoaderModule::TYPE_STYLES,
1571  $styleOrigin
1572  );
1573  }
1574 
1581  public function getAllowedModules( $type ) {
1582  if ( $type == ResourceLoaderModule::TYPE_COMBINED ) {
1583  return min( array_values( $this->mAllowedModules ) );
1584  } else {
1585  return $this->mAllowedModules[$type] ?? ResourceLoaderModule::ORIGIN_ALL;
1586  }
1587  }
1588 
1598  public function reduceAllowedModules( $type, $level ) {
1599  $this->mAllowedModules[$type] = min( $this->getAllowedModules( $type ), $level );
1600  }
1601 
1607  public function prependHTML( $text ) {
1608  $this->mBodytext = $text . $this->mBodytext;
1609  }
1610 
1616  public function addHTML( $text ) {
1617  $this->mBodytext .= $text;
1618  }
1619 
1629  public function addElement( $element, array $attribs = [], $contents = '' ) {
1630  $this->addHTML( Html::element( $element, $attribs, $contents ) );
1631  }
1632 
1636  public function clearHTML() {
1637  $this->mBodytext = '';
1638  }
1639 
1645  public function getHTML() {
1646  return $this->mBodytext;
1647  }
1648 
1655  public function parserOptions() {
1656  if ( !$this->mParserOptions ) {
1657  if ( !$this->getUser()->isSafeToLoad() ) {
1658  // $wgUser isn't unstubbable yet, so don't try to get a
1659  // ParserOptions for it. And don't cache this ParserOptions
1660  // either.
1662  $po->setAllowUnsafeRawHtml( false );
1663  $po->isBogus = true;
1664  return $po;
1665  }
1666 
1667  $this->mParserOptions = ParserOptions::newFromContext( $this->getContext() );
1668  $this->mParserOptions->setAllowUnsafeRawHtml( false );
1669  }
1670 
1671  return $this->mParserOptions;
1672  }
1673 
1681  public function setRevisionId( $revid ) {
1682  $val = $revid === null ? null : intval( $revid );
1683  return wfSetVar( $this->mRevisionId, $val, true );
1684  }
1685 
1691  public function getRevisionId() {
1692  return $this->mRevisionId;
1693  }
1694 
1701  public function isRevisionCurrent() {
1702  return $this->mRevisionId == 0 || $this->mRevisionId == $this->getTitle()->getLatestRevID();
1703  }
1704 
1712  public function setRevisionTimestamp( $timestamp ) {
1713  return wfSetVar( $this->mRevisionTimestamp, $timestamp, true );
1714  }
1715 
1722  public function getRevisionTimestamp() {
1724  }
1725 
1732  public function setFileVersion( $file ) {
1733  $val = null;
1734  if ( $file instanceof File && $file->exists() ) {
1735  $val = [ 'time' => $file->getTimestamp(), 'sha1' => $file->getSha1() ];
1736  }
1737  return wfSetVar( $this->mFileVersion, $val, true );
1738  }
1739 
1745  public function getFileVersion() {
1746  return $this->mFileVersion;
1747  }
1748 
1755  public function getTemplateIds() {
1756  return $this->mTemplateIds;
1757  }
1758 
1765  public function getFileSearchOptions() {
1766  return $this->mImageTimeKeys;
1767  }
1768 
1785  public function addWikiTextAsInterface(
1786  $text, $linestart = true, Title $title = null
1787  ) {
1788  if ( $title === null ) {
1789  $title = $this->getTitle();
1790  }
1791  if ( !$title ) {
1792  throw new MWException( 'Title is null' );
1793  }
1794  $this->addWikiTextTitleInternal( $text, $title, $linestart, /*interface*/true );
1795  }
1796 
1810  public function wrapWikiTextAsInterface(
1811  $wrapperClass, $text
1812  ) {
1813  $this->addWikiTextTitleInternal(
1814  $text, $this->getTitle(),
1815  /*linestart*/true, /*interface*/true,
1816  $wrapperClass
1817  );
1818  }
1819 
1835  public function addWikiTextAsContent(
1836  $text, $linestart = true, Title $title = null
1837  ) {
1838  if ( $title === null ) {
1839  $title = $this->getTitle();
1840  }
1841  if ( !$title ) {
1842  throw new MWException( 'Title is null' );
1843  }
1844  $this->addWikiTextTitleInternal( $text, $title, $linestart, /*interface*/false );
1845  }
1846 
1859  private function addWikiTextTitleInternal(
1860  $text, Title $title, $linestart, $interface, $wrapperClass = null
1861  ) {
1862  $parserOutput = $this->parseInternal(
1863  $text, $title, $linestart, $interface
1864  );
1865 
1866  $this->addParserOutput( $parserOutput, [
1867  'enableSectionEditLinks' => false,
1868  'wrapperDivClass' => $wrapperClass ?? '',
1869  ] );
1870  }
1871 
1880  public function addParserOutputMetadata( ParserOutput $parserOutput ) {
1881  $this->mLanguageLinks =
1882  array_merge( $this->mLanguageLinks, $parserOutput->getLanguageLinks() );
1883  $this->addCategoryLinks( $parserOutput->getCategories() );
1884  $this->setIndicators( $parserOutput->getIndicators() );
1885  $this->mNewSectionLink = $parserOutput->getNewSection();
1886  $this->mHideNewSectionLink = $parserOutput->getHideNewSection();
1887 
1888  if ( !$parserOutput->isCacheable() ) {
1889  $this->enableClientCache( false );
1890  }
1891  $this->mNoGallery = $parserOutput->getNoGallery();
1892  $this->mHeadItems = array_merge( $this->mHeadItems, $parserOutput->getHeadItems() );
1893  $this->addModules( $parserOutput->getModules() );
1894  $this->addModuleStyles( $parserOutput->getModuleStyles() );
1895  $this->addJsConfigVars( $parserOutput->getJsConfigVars() );
1896  $this->mPreventClickjacking = $this->mPreventClickjacking
1897  || $parserOutput->preventClickjacking();
1898  $scriptSrcs = $parserOutput->getExtraCSPScriptSrcs();
1899  foreach ( $scriptSrcs as $src ) {
1900  $this->getCSP()->addScriptSrc( $src );
1901  }
1902  $defaultSrcs = $parserOutput->getExtraCSPDefaultSrcs();
1903  foreach ( $defaultSrcs as $src ) {
1904  $this->getCSP()->addDefaultSrc( $src );
1905  }
1906  $styleSrcs = $parserOutput->getExtraCSPStyleSrcs();
1907  foreach ( $styleSrcs as $src ) {
1908  $this->getCSP()->addStyleSrc( $src );
1909  }
1910 
1911  // If $wgImagePreconnect is true, and if the output contains
1912  // images, give the user-agent a hint about foreign repos from
1913  // which those images may be served. See T123582.
1914  //
1915  // TODO: We don't have an easy way to know from which remote(s)
1916  // the image(s) will be served. For now, we only hint the first
1917  // valid one.
1918  if ( $this->getConfig()->get( 'ImagePreconnect' ) && count( $parserOutput->getImages() ) ) {
1919  $preconnect = [];
1920  $repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
1921  $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$preconnect ) {
1922  $preconnect[] = wfParseUrl( $repo->getZoneUrl( 'thumb' ) )['host'];
1923  } );
1924  $preconnect[] = wfParseUrl( $repoGroup->getLocalRepo()->getZoneUrl( 'thumb' ) )['host'];
1925  foreach ( $preconnect as $host ) {
1926  if ( $host ) {
1927  $this->addLink( [ 'rel' => 'preconnect', 'href' => '//' . $host ] );
1928  break;
1929  }
1930  }
1931  }
1932 
1933  // Template versioning...
1934  foreach ( (array)$parserOutput->getTemplateIds() as $ns => $dbks ) {
1935  if ( isset( $this->mTemplateIds[$ns] ) ) {
1936  $this->mTemplateIds[$ns] = $dbks + $this->mTemplateIds[$ns];
1937  } else {
1938  $this->mTemplateIds[$ns] = $dbks;
1939  }
1940  }
1941  // File versioning...
1942  foreach ( (array)$parserOutput->getFileSearchOptions() as $dbk => $data ) {
1943  $this->mImageTimeKeys[$dbk] = $data;
1944  }
1945 
1946  // Hooks registered in the object
1947  $parserOutputHooks = $this->getConfig()->get( 'ParserOutputHooks' );
1948  foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
1949  list( $hookName, $data ) = $hookInfo;
1950  if ( isset( $parserOutputHooks[$hookName] ) ) {
1951  $parserOutputHooks[$hookName]( $this, $parserOutput, $data );
1952  }
1953  }
1954 
1955  // Enable OOUI if requested via ParserOutput
1956  if ( $parserOutput->getEnableOOUI() ) {
1957  $this->enableOOUI();
1958  }
1959 
1960  // Include parser limit report
1961  if ( !$this->limitReportJSData ) {
1962  $this->limitReportJSData = $parserOutput->getLimitReportJSData();
1963  }
1964 
1965  // Link flags are ignored for now, but may in the future be
1966  // used to mark individual language links.
1967  $linkFlags = [];
1968  $this->getHookRunner()->onLanguageLinks( $this->getTitle(), $this->mLanguageLinks, $linkFlags );
1969  $this->getHookRunner()->onOutputPageParserOutput( $this, $parserOutput );
1970 
1971  // This check must be after 'OutputPageParserOutput' runs in addParserOutputMetadata
1972  // so that extensions may modify ParserOutput to toggle TOC.
1973  // This cannot be moved to addParserOutputText because that is not
1974  // called by EditPage for Preview.
1975  if ( $parserOutput->getTOCHTML() ) {
1976  $this->mEnableTOC = true;
1977  }
1978  }
1979 
1988  public function addParserOutputContent( ParserOutput $parserOutput, $poOptions = [] ) {
1989  $this->addParserOutputText( $parserOutput, $poOptions );
1990 
1991  $this->addModules( $parserOutput->getModules() );
1992  $this->addModuleStyles( $parserOutput->getModuleStyles() );
1993 
1994  $this->addJsConfigVars( $parserOutput->getJsConfigVars() );
1995  }
1996 
2004  public function addParserOutputText( ParserOutput $parserOutput, $poOptions = [] ) {
2005  $text = $parserOutput->getText( $poOptions );
2006  $this->getHookRunner()->onOutputPageBeforeHTML( $this, $text );
2007  $this->addHTML( $text );
2008  }
2009 
2016  public function addParserOutput( ParserOutput $parserOutput, $poOptions = [] ) {
2017  $this->addParserOutputMetadata( $parserOutput );
2018  $this->addParserOutputText( $parserOutput, $poOptions );
2019  }
2020 
2026  public function addTemplate( &$template ) {
2027  $this->addHTML( $template->getHTML() );
2028  }
2029 
2041  public function parseAsContent( $text, $linestart = true ) {
2042  return $this->parseInternal(
2043  $text, $this->getTitle(), $linestart, /*interface*/false
2044  )->getText( [
2045  'enableSectionEditLinks' => false,
2046  'wrapperDivClass' => ''
2047  ] );
2048  }
2049 
2062  public function parseAsInterface( $text, $linestart = true ) {
2063  return $this->parseInternal(
2064  $text, $this->getTitle(), $linestart, /*interface*/true
2065  )->getText( [
2066  'enableSectionEditLinks' => false,
2067  'wrapperDivClass' => ''
2068  ] );
2069  }
2070 
2085  public function parseInlineAsInterface( $text, $linestart = true ) {
2087  $this->parseAsInterface( $text, $linestart )
2088  );
2089  }
2090 
2103  private function parseInternal( $text, $title, $linestart, $interface ) {
2104  if ( $title === null ) {
2105  throw new MWException( 'Empty $mTitle in ' . __METHOD__ );
2106  }
2107 
2108  $popts = $this->parserOptions();
2109 
2110  $oldInterface = $popts->setInterfaceMessage( (bool)$interface );
2111 
2112  $parserOutput = MediaWikiServices::getInstance()->getParser()->getFreshParser()->parse(
2113  $text, $title, $popts,
2114  $linestart, true, $this->mRevisionId
2115  );
2116 
2117  $popts->setInterfaceMessage( $oldInterface );
2118 
2119  return $parserOutput;
2120  }
2121 
2127  public function setCdnMaxage( $maxage ) {
2128  $this->mCdnMaxage = min( $maxage, $this->mCdnMaxageLimit );
2129  }
2130 
2140  public function lowerCdnMaxage( $maxage ) {
2141  $this->mCdnMaxageLimit = min( $maxage, $this->mCdnMaxageLimit );
2142  $this->setCdnMaxage( $this->mCdnMaxage );
2143  }
2144 
2157  public function adaptCdnTTL( $mtime, $minTTL = 0, $maxTTL = 0 ) {
2158  $minTTL = $minTTL ?: IExpiringStore::TTL_MINUTE;
2159  $maxTTL = $maxTTL ?: $this->getConfig()->get( 'CdnMaxAge' );
2160 
2161  if ( $mtime === null || $mtime === false ) {
2162  return; // entity does not exist
2163  }
2164 
2165  $age = MWTimestamp::time() - (int)wfTimestamp( TS_UNIX, $mtime );
2166  $adaptiveTTL = max( 0.9 * $age, $minTTL );
2167  $adaptiveTTL = min( $adaptiveTTL, $maxTTL );
2168 
2169  $this->lowerCdnMaxage( (int)$adaptiveTTL );
2170  }
2171 
2179  public function enableClientCache( $state ) {
2180  return wfSetVar( $this->mEnableClientCache, $state );
2181  }
2182 
2189  public function couldBePublicCached() {
2190  if ( !$this->cacheIsFinal ) {
2191  // - The entry point handles its own caching and/or doesn't use OutputPage.
2192  // (such as load.php, AjaxDispatcher, or MediaWiki\Rest\EntryPoint).
2193  //
2194  // - Or, we haven't finished processing the main part of the request yet
2195  // (e.g. Action::show, SpecialPage::execute), and the state may still
2196  // change via enableClientCache().
2197  return true;
2198  }
2199  // e.g. various error-type pages disable all client caching
2201  }
2202 
2212  public function considerCacheSettingsFinal() {
2213  $this->cacheIsFinal = true;
2214  }
2215 
2221  public function getCacheVaryCookies() {
2222  if ( self::$cacheVaryCookies === null ) {
2223  $config = $this->getConfig();
2224  self::$cacheVaryCookies = array_values( array_unique( array_merge(
2225  SessionManager::singleton()->getVaryCookies(),
2226  [
2227  'forceHTTPS',
2228  ],
2229  $config->get( 'CacheVaryCookies' )
2230  ) ) );
2231  $this->getHookRunner()->onGetCacheVaryCookies( $this, self::$cacheVaryCookies );
2232  }
2233  return self::$cacheVaryCookies;
2234  }
2235 
2242  public function haveCacheVaryCookies() {
2243  $request = $this->getRequest();
2244  foreach ( $this->getCacheVaryCookies() as $cookieName ) {
2245  if ( $request->getCookie( $cookieName, '', '' ) !== '' ) {
2246  wfDebug( __METHOD__ . ": found $cookieName" );
2247  return true;
2248  }
2249  }
2250  wfDebug( __METHOD__ . ": no cache-varying cookies found" );
2251  return false;
2252  }
2253 
2263  public function addVaryHeader( $header, array $option = null ) {
2264  if ( $option !== null && count( $option ) > 0 ) {
2266  'The $option parameter to addVaryHeader is ignored since MediaWiki 1.34',
2267  '1.34' );
2268  }
2269  if ( !array_key_exists( $header, $this->mVaryHeader ) ) {
2270  $this->mVaryHeader[$header] = null;
2271  }
2272  }
2273 
2280  public function getVaryHeader() {
2281  // If we vary on cookies, let's make sure it's always included here too.
2282  if ( $this->getCacheVaryCookies() ) {
2283  $this->addVaryHeader( 'Cookie' );
2284  }
2285 
2286  foreach ( SessionManager::singleton()->getVaryHeaders() as $header => $options ) {
2287  $this->addVaryHeader( $header, $options );
2288  }
2289  return 'Vary: ' . implode( ', ', array_keys( $this->mVaryHeader ) );
2290  }
2291 
2297  public function addLinkHeader( $header ) {
2298  $this->mLinkHeader[] = $header;
2299  }
2300 
2306  public function getLinkHeader() {
2307  if ( !$this->mLinkHeader ) {
2308  return false;
2309  }
2310 
2311  return 'Link: ' . implode( ',', $this->mLinkHeader );
2312  }
2313 
2321  private function addAcceptLanguage() {
2322  $title = $this->getTitle();
2323  if ( !$title instanceof Title ) {
2324  return;
2325  }
2326 
2327  $lang = $title->getPageLanguage();
2328  if ( !$this->getRequest()->getCheck( 'variant' ) && $lang->hasVariants() ) {
2329  $this->addVaryHeader( 'Accept-Language' );
2330  }
2331  }
2332 
2343  public function preventClickjacking( $enable = true ) {
2344  $this->mPreventClickjacking = $enable;
2345  }
2346 
2352  public function allowClickjacking() {
2353  $this->mPreventClickjacking = false;
2354  }
2355 
2362  public function getPreventClickjacking() {
2364  }
2365 
2373  public function getFrameOptions() {
2374  $config = $this->getConfig();
2375  if ( $config->get( 'BreakFrames' ) ) {
2376  return 'DENY';
2377  } elseif ( $this->mPreventClickjacking && $config->get( 'EditPageFrameOptions' ) ) {
2378  return $config->get( 'EditPageFrameOptions' );
2379  }
2380  return false;
2381  }
2382 
2389  private function getOriginTrials() {
2390  $config = $this->getConfig();
2391 
2392  return $config->get( 'OriginTrials' );
2393  }
2394 
2395  private function getReportTo() {
2396  $config = $this->getConfig();
2397 
2398  $expiry = $config->get( 'ReportToExpiry' );
2399 
2400  if ( !$expiry ) {
2401  return false;
2402  }
2403 
2404  $endpoints = $config->get( 'ReportToEndpoints' );
2405 
2406  if ( !$endpoints ) {
2407  return false;
2408  }
2409 
2410  $output = [ 'max_age' => $expiry, 'endpoints' => [] ];
2411 
2412  foreach ( $endpoints as $endpoint ) {
2413  $output['endpoints'][] = [ 'url' => $endpoint ];
2414  }
2415 
2416  return json_encode( $output, JSON_UNESCAPED_SLASHES );
2417  }
2418 
2419  private function getFeaturePolicyReportOnly() {
2420  $config = $this->getConfig();
2421 
2422  $features = $config->get( 'FeaturePolicyReportOnly' );
2423  return implode( ';', $features );
2424  }
2425 
2429  public function sendCacheControl() {
2430  $response = $this->getRequest()->response();
2431  $config = $this->getConfig();
2432 
2433  $this->addVaryHeader( 'Cookie' );
2434  $this->addAcceptLanguage();
2435 
2436  # don't serve compressed data to clients who can't handle it
2437  # maintain different caches for logged-in users and non-logged in ones
2438  $response->header( $this->getVaryHeader() );
2439 
2440  if ( $this->mEnableClientCache ) {
2441  if (
2442  $config->get( 'UseCdn' ) &&
2443  !$response->hasCookies() &&
2444  // The client might use methods other than cookies to appear logged-in.
2445  // E.g. HTTP headers, or query parameter tokens, OAuth, etc.
2446  !SessionManager::getGlobalSession()->isPersistent() &&
2447  !$this->isPrintable() &&
2448  $this->mCdnMaxage != 0 &&
2449  !$this->haveCacheVaryCookies()
2450  ) {
2451  # We'll purge the proxy cache for anons explicitly, but require end user agents
2452  # to revalidate against the proxy on each visit.
2453  # IMPORTANT! The CDN needs to replace the Cache-Control header with
2454  # Cache-Control: s-maxage=0, must-revalidate, max-age=0
2455  wfDebug( __METHOD__ .
2456  ": local proxy caching; {$this->mLastModified} **", 'private' );
2457  # start with a shorter timeout for initial testing
2458  # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
2459  $response->header( "Cache-Control: " .
2460  "s-maxage={$this->mCdnMaxage}, must-revalidate, max-age=0" );
2461  } else {
2462  # We do want clients to cache if they can, but they *must* check for updates
2463  # on revisiting the page, after the max-age period.
2464  wfDebug( __METHOD__ . ": private caching; {$this->mLastModified} **", 'private' );
2465 
2466  if ( $response->hasCookies() || SessionManager::getGlobalSession()->isPersistent() ) {
2467  $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
2468  $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
2469  } else {
2470  $response->header(
2471  'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $config->get( 'LoggedOutMaxAge' ) ) . ' GMT'
2472  );
2473  $response->header(
2474  "Cache-Control: private, must-revalidate, max-age={$config->get( 'LoggedOutMaxAge' )}"
2475  );
2476  }
2477  }
2478  if ( $this->mLastModified ) {
2479  $response->header( "Last-Modified: {$this->mLastModified}" );
2480  }
2481  } else {
2482  wfDebug( __METHOD__ . ": no caching **", 'private' );
2483 
2484  # In general, the absence of a last modified header should be enough to prevent
2485  # the client from using its cache. We send a few other things just to make sure.
2486  $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
2487  $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
2488  $response->header( 'Pragma: no-cache' );
2489  }
2490  }
2491 
2497  public function loadSkinModules( $sk ) {
2498  foreach ( $sk->getDefaultModules() as $group => $modules ) {
2499  if ( $group === 'styles' ) {
2500  foreach ( $modules as $key => $moduleMembers ) {
2501  $this->addModuleStyles( $moduleMembers );
2502  }
2503  } else {
2504  $this->addModules( $modules );
2505  }
2506  }
2507  }
2508 
2519  public function output( $return = false ) {
2520  if ( $this->mDoNothing ) {
2521  return $return ? '' : null;
2522  }
2523 
2524  $response = $this->getRequest()->response();
2525  $config = $this->getConfig();
2526 
2527  if ( $this->mRedirect != '' ) {
2528  # Standards require redirect URLs to be absolute
2529  $this->mRedirect = wfExpandUrl( $this->mRedirect, PROTO_CURRENT );
2530 
2531  $redirect = $this->mRedirect;
2532  $code = $this->mRedirectCode;
2533 
2534  if ( $this->getHookRunner()->onBeforePageRedirect( $this, $redirect, $code ) ) {
2535  if ( $code == '301' || $code == '303' ) {
2536  if ( !$config->get( 'DebugRedirects' ) ) {
2537  $response->statusHeader( $code );
2538  }
2539  $this->mLastModified = wfTimestamp( TS_RFC2822 );
2540  }
2541  if ( $config->get( 'VaryOnXFP' ) ) {
2542  $this->addVaryHeader( 'X-Forwarded-Proto' );
2543  }
2544  $this->sendCacheControl();
2545 
2546  $response->header( "Content-Type: text/html; charset=utf-8" );
2547  if ( $config->get( 'DebugRedirects' ) ) {
2548  $url = htmlspecialchars( $redirect );
2549  print "<!DOCTYPE html>\n<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
2550  print "<p>Location: <a href=\"$url\">$url</a></p>\n";
2551  print "</body>\n</html>\n";
2552  } else {
2553  $response->header( 'Location: ' . $redirect );
2554  }
2555  }
2556 
2557  return $return ? '' : null;
2558  } elseif ( $this->mStatusCode ) {
2559  $response->statusHeader( $this->mStatusCode );
2560  }
2561 
2562  # Buffer output; final headers may depend on later processing
2563  ob_start();
2564 
2565  $response->header( 'Content-type: ' . $config->get( 'MimeType' ) . '; charset=UTF-8' );
2566  $response->header( 'Content-language: ' .
2567  MediaWikiServices::getInstance()->getContentLanguage()->getHtmlCode() );
2568 
2569  $linkHeader = $this->getLinkHeader();
2570  if ( $linkHeader ) {
2571  $response->header( $linkHeader );
2572  }
2573 
2574  // Prevent framing, if requested
2575  $frameOptions = $this->getFrameOptions();
2576  if ( $frameOptions ) {
2577  $response->header( "X-Frame-Options: $frameOptions" );
2578  }
2579 
2580  $originTrials = $this->getOriginTrials();
2581  foreach ( $originTrials as $originTrial ) {
2582  $response->header( "Origin-Trial: $originTrial", false );
2583  }
2584 
2585  $reportTo = $this->getReportTo();
2586  if ( $reportTo ) {
2587  $response->header( "Report-To: $reportTo" );
2588  }
2589 
2590  $featurePolicyReportOnly = $this->getFeaturePolicyReportOnly();
2591  if ( $featurePolicyReportOnly ) {
2592  $response->header( "Feature-Policy-Report-Only: $featurePolicyReportOnly" );
2593  }
2594 
2595  if ( $this->mArticleBodyOnly ) {
2596  $this->CSP->sendHeaders();
2597  echo $this->mBodytext;
2598  } else {
2599  // Enable safe mode if requested (T152169)
2600  if ( $this->getRequest()->getBool( 'safemode' ) ) {
2601  $this->disallowUserJs();
2602  }
2603 
2604  $sk = $this->getSkin();
2605  $this->loadSkinModules( $sk );
2606 
2607  MWDebug::addModules( $this );
2608 
2609  // Hook that allows last minute changes to the output page, e.g.
2610  // adding of CSS or Javascript by extensions, adding CSP sources.
2611  $this->getHookRunner()->onBeforePageDisplay( $this, $sk );
2612 
2613  $this->CSP->sendHeaders();
2614 
2615  try {
2616  $sk->outputPage();
2617  } catch ( Exception $e ) {
2618  ob_end_clean(); // bug T129657
2619  throw $e;
2620  }
2621  }
2622 
2623  try {
2624  // This hook allows last minute changes to final overall output by modifying output buffer
2625  $this->getHookRunner()->onAfterFinalPageOutput( $this );
2626  } catch ( Exception $e ) {
2627  ob_end_clean(); // bug T129657
2628  throw $e;
2629  }
2630 
2631  $this->sendCacheControl();
2632 
2633  if ( $return ) {
2634  return ob_get_clean();
2635  } else {
2636  ob_end_flush();
2637  return null;
2638  }
2639  }
2640 
2651  public function prepareErrorPage( $pageTitle, $htmlTitle = false ) {
2652  $this->setPageTitle( $pageTitle );
2653  if ( $htmlTitle !== false ) {
2654  $this->setHTMLTitle( $htmlTitle );
2655  }
2656  $this->setRobotPolicy( 'noindex,nofollow' );
2657  $this->setArticleRelated( false );
2658  $this->enableClientCache( false );
2659  $this->mRedirect = '';
2660  $this->clearSubtitle();
2661  $this->clearHTML();
2662  }
2663 
2676  public function showErrorPage( $title, $msg, $params = [] ) {
2677  if ( !$title instanceof Message ) {
2678  $title = $this->msg( $title );
2679  }
2680 
2681  $this->prepareErrorPage( $title );
2682 
2683  if ( $msg instanceof Message ) {
2684  if ( $params !== [] ) {
2685  trigger_error( 'Argument ignored: $params. The message parameters argument '
2686  . 'is discarded when the $msg argument is a Message object instead of '
2687  . 'a string.', E_USER_NOTICE );
2688  }
2689  $this->addHTML( $msg->parseAsBlock() );
2690  } else {
2691  $this->addWikiMsgArray( $msg, $params );
2692  }
2693 
2694  $this->returnToMain();
2695  }
2696 
2703  public function showPermissionsErrorPage( array $errors, $action = null ) {
2704  $services = MediaWikiServices::getInstance();
2705  $permissionManager = $services->getPermissionManager();
2706  foreach ( $errors as $key => $error ) {
2707  $errors[$key] = (array)$error;
2708  }
2709 
2710  // For some action (read, edit, create and upload), display a "login to do this action"
2711  // error if all of the following conditions are met:
2712  // 1. the user is not logged in
2713  // 2. the only error is insufficient permissions (i.e. no block or something else)
2714  // 3. the error can be avoided simply by logging in
2715 
2716  if ( in_array( $action, [ 'read', 'edit', 'createpage', 'createtalk', 'upload' ] )
2717  && $this->getUser()->isAnon() && count( $errors ) == 1 && isset( $errors[0][0] )
2718  && ( $errors[0][0] == 'badaccess-groups' || $errors[0][0] == 'badaccess-group0' )
2719  && ( $permissionManager->groupHasPermission( 'user', $action )
2720  || $permissionManager->groupHasPermission( 'autoconfirmed', $action ) )
2721  ) {
2722  $displayReturnto = null;
2723 
2724  # Due to T34276, if a user does not have read permissions,
2725  # $this->getTitle() will just give Special:Badtitle, which is
2726  # not especially useful as a returnto parameter. Use the title
2727  # from the request instead, if there was one.
2728  $request = $this->getRequest();
2729  $returnto = Title::newFromText( $request->getVal( 'title', '' ) );
2730  if ( $action == 'edit' ) {
2731  $msg = 'whitelistedittext';
2732  $displayReturnto = $returnto;
2733  } elseif ( $action == 'createpage' || $action == 'createtalk' ) {
2734  $msg = 'nocreatetext';
2735  } elseif ( $action == 'upload' ) {
2736  $msg = 'uploadnologintext';
2737  } else { # Read
2738  $msg = 'loginreqpagetext';
2739  $displayReturnto = Title::newMainPage();
2740  }
2741 
2742  $query = [];
2743 
2744  if ( $returnto ) {
2745  $query['returnto'] = $returnto->getPrefixedText();
2746 
2747  if ( !$request->wasPosted() ) {
2748  $returntoquery = $request->getValues();
2749  unset( $returntoquery['title'] );
2750  unset( $returntoquery['returnto'] );
2751  unset( $returntoquery['returntoquery'] );
2752  $query['returntoquery'] = wfArrayToCgi( $returntoquery );
2753  }
2754  }
2755 
2756  $title = SpecialPage::getTitleFor( 'Userlogin' );
2757  $linkRenderer = $services->getLinkRenderer();
2758  $loginUrl = $title->getLinkURL( $query, false, PROTO_RELATIVE );
2759  $loginLink = $linkRenderer->makeKnownLink(
2760  $title,
2761  $this->msg( 'loginreqlink' )->text(),
2762  [],
2763  $query
2764  );
2765 
2766  $this->prepareErrorPage( $this->msg( 'loginreqtitle' ) );
2767  $this->addHTML( $this->msg( $msg )->rawParams( $loginLink )->params( $loginUrl )->parse() );
2768 
2769  # Don't return to a page the user can't read otherwise
2770  # we'll end up in a pointless loop
2771  if ( $displayReturnto && $permissionManager->userCan(
2772  'read', $this->getUser(), $displayReturnto
2773  ) ) {
2774  $this->returnToMain( null, $displayReturnto );
2775  }
2776  } else {
2777  $this->prepareErrorPage( $this->msg( 'permissionserrors' ) );
2778  $this->addWikiTextAsInterface( $this->formatPermissionsErrorMessage( $errors, $action ) );
2779  }
2780  }
2781 
2788  public function versionRequired( $version ) {
2789  $this->prepareErrorPage( $this->msg( 'versionrequired', $version ) );
2790 
2791  $this->addWikiMsg( 'versionrequiredtext', $version );
2792  $this->returnToMain();
2793  }
2794 
2802  public function formatPermissionsErrorMessage( array $errors, $action = null ) {
2803  if ( $action == null ) {
2804  $text = $this->msg( 'permissionserrorstext', count( $errors ) )->plain() . "\n\n";
2805  } else {
2806  $action_desc = $this->msg( "action-$action" )->plain();
2807  $text = $this->msg(
2808  'permissionserrorstext-withaction',
2809  count( $errors ),
2810  $action_desc
2811  )->plain() . "\n\n";
2812  }
2813 
2814  if ( count( $errors ) > 1 ) {
2815  $text .= '<ul class="permissions-errors">' . "\n";
2816 
2817  foreach ( $errors as $error ) {
2818  $text .= '<li>';
2819  $text .= $this->msg( ...$error )->plain();
2820  $text .= "</li>\n";
2821  }
2822  $text .= '</ul>';
2823  } else {
2824  $text .= "<div class=\"permissions-errors\">\n" .
2825  $this->msg( ...reset( $errors ) )->plain() .
2826  "\n</div>";
2827  }
2828 
2829  return $text;
2830  }
2831 
2841  public function showLagWarning( $lag ) {
2842  $config = $this->getConfig();
2843  if ( $lag >= $config->get( 'SlaveLagWarning' ) ) {
2844  $lag = floor( $lag ); // floor to avoid nano seconds to display
2845  $message = $lag < $config->get( 'SlaveLagCritical' )
2846  ? 'lag-warn-normal'
2847  : 'lag-warn-high';
2848  // For grep: mw-lag-warn-normal, mw-lag-warn-high
2849  $wrap = Html::rawElement( 'div', [ 'class' => "mw-{$message}" ], "\n$1\n" );
2850  $this->wrapWikiMsg( "$wrap\n", [ $message, $this->getLanguage()->formatNum( $lag ) ] );
2851  }
2852  }
2853 
2860  public function showFatalError( $message ) {
2861  $this->prepareErrorPage( $this->msg( 'internalerror' ) );
2862 
2863  $this->addHTML( $message );
2864  }
2865 
2874  public function addReturnTo( $title, array $query = [], $text = null, $options = [] ) {
2875  $linkRenderer = MediaWikiServices::getInstance()
2876  ->getLinkRendererFactory()->createFromLegacyOptions( $options );
2877  $link = $this->msg( 'returnto' )->rawParams(
2878  $linkRenderer->makeLink( $title, $text, [], $query ) )->escaped();
2879  $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
2880  }
2881 
2890  public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) {
2891  if ( $returnto == null ) {
2892  $returnto = $this->getRequest()->getText( 'returnto' );
2893  }
2894 
2895  if ( $returntoquery == null ) {
2896  $returntoquery = $this->getRequest()->getText( 'returntoquery' );
2897  }
2898 
2899  if ( $returnto === '' ) {
2900  $returnto = Title::newMainPage();
2901  }
2902 
2903  if ( is_object( $returnto ) ) {
2904  $titleObj = $returnto;
2905  } else {
2906  $titleObj = Title::newFromText( $returnto );
2907  }
2908  // We don't want people to return to external interwiki. That
2909  // might potentially be used as part of a phishing scheme
2910  if ( !is_object( $titleObj ) || $titleObj->isExternal() ) {
2911  $titleObj = Title::newMainPage();
2912  }
2913 
2914  $this->addReturnTo( $titleObj, wfCgiToArray( $returntoquery ) );
2915  }
2916 
2917  private function getRlClientContext() {
2918  if ( !$this->rlClientContext ) {
2920  [], // modules; not relevant
2921  $this->getLanguage()->getCode(),
2922  $this->getSkin()->getSkinName(),
2923  $this->getUser()->isLoggedIn() ? $this->getUser()->getName() : null,
2924  null, // version; not relevant
2926  null, // only; not relevant
2927  $this->isPrintable(),
2928  $this->getRequest()->getBool( 'handheld' )
2929  );
2930  $this->rlClientContext = new ResourceLoaderContext(
2931  $this->getResourceLoader(),
2932  new FauxRequest( $query )
2933  );
2934  if ( $this->contentOverrideCallbacks ) {
2935  $this->rlClientContext = new DerivativeResourceLoaderContext( $this->rlClientContext );
2936  $this->rlClientContext->setContentOverrideCallback( function ( Title $title ) {
2937  foreach ( $this->contentOverrideCallbacks as $callback ) {
2938  $content = $callback( $title );
2939  if ( $content !== null ) {
2941  if ( strpos( $text, '</script>' ) !== false ) {
2942  // Proactively replace this so that we can display a message
2943  // to the user, instead of letting it go to Html::inlineScript(),
2944  // where it would be considered a server-side issue.
2945  $titleFormatted = $title->getPrefixedText();
2947  Xml::encodeJsCall( 'mw.log.error', [
2948  "Cannot preview $titleFormatted due to script-closing tag."
2949  ] )
2950  );
2951  }
2952  return $content;
2953  }
2954  }
2955  return null;
2956  } );
2957  }
2958  }
2959  return $this->rlClientContext;
2960  }
2961 
2973  public function getRlClient() {
2974  if ( !$this->rlClient ) {
2975  $context = $this->getRlClientContext();
2976  $rl = $this->getResourceLoader();
2977  $this->addModules( [
2978  'user',
2979  'user.options',
2980  ] );
2981  $this->addModuleStyles( [
2982  'site.styles',
2983  'noscript',
2984  'user.styles',
2985  ] );
2986  $this->getSkin()->setupSkinUserCss( $this );
2987 
2988  // Prepare exempt modules for buildExemptModules()
2989  $exemptGroups = [ 'site' => [], 'noscript' => [], 'private' => [], 'user' => [] ];
2990  $exemptStates = [];
2991  $moduleStyles = $this->getModuleStyles( /*filter*/ true );
2992 
2993  // Preload getTitleInfo for isKnownEmpty calls below and in ResourceLoaderClientHtml
2994  // Separate user-specific batch for improved cache-hit ratio.
2995  $userBatch = [ 'user.styles', 'user' ];
2996  $siteBatch = array_diff( $moduleStyles, $userBatch );
2997  $dbr = wfGetDB( DB_REPLICA );
3000 
3001  // Filter out modules handled by buildExemptModules()
3002  $moduleStyles = array_filter( $moduleStyles,
3003  function ( $name ) use ( $rl, $context, &$exemptGroups, &$exemptStates ) {
3004  $module = $rl->getModule( $name );
3005  if ( $module ) {
3006  $group = $module->getGroup();
3007  if ( isset( $exemptGroups[$group] ) ) {
3008  $exemptStates[$name] = 'ready';
3009  if ( !$module->isKnownEmpty( $context ) ) {
3010  // E.g. Don't output empty <styles>
3011  $exemptGroups[$group][] = $name;
3012  }
3013  return false;
3014  }
3015  }
3016  return true;
3017  }
3018  );
3019  $this->rlExemptStyleModules = $exemptGroups;
3020 
3022  'target' => $this->getTarget(),
3023  'nonce' => $this->CSP->getNonce(),
3024  // When 'safemode', disallowUserJs(), or reduceAllowedModules() is used
3025  // to only restrict modules to ORIGIN_CORE (ie. disallow ORIGIN_USER), the list of
3026  // modules enqueud for loading on this page is filtered to just those.
3027  // However, to make sure we also apply the restriction to dynamic dependencies and
3028  // lazy-loaded modules at run-time on the client-side, pass 'safemode' down to the
3029  // StartupModule so that the client-side registry will not contain any restricted
3030  // modules either. (T152169, T185303)
3031  'safemode' => ( $this->getAllowedModules( ResourceLoaderModule::TYPE_COMBINED )
3032  <= ResourceLoaderModule::ORIGIN_CORE_INDIVIDUAL
3033  ) ? '1' : null,
3034  ] );
3035  $rlClient->setConfig( $this->getJSVars() );
3036  $rlClient->setModules( $this->getModules( /*filter*/ true ) );
3037  $rlClient->setModuleStyles( $moduleStyles );
3038  $rlClient->setExemptStates( $exemptStates );
3039  $this->rlClient = $rlClient;
3040  }
3041  return $this->rlClient;
3042  }
3043 
3049  public function headElement( Skin $sk, $includeStyle = true ) {
3050  $config = $this->getConfig();
3051  $userdir = $this->getLanguage()->getDir();
3052  $sitedir = MediaWikiServices::getInstance()->getContentLanguage()->getDir();
3053 
3054  $pieces = [];
3056  $this->getRlClient()->getDocumentAttributes(),
3058  ), [ 'class' => implode( ' ', $this->mAdditionalHtmlClasses ) ] );
3059  $pieces[] = Html::htmlHeader( $htmlAttribs );
3060  $pieces[] = Html::openElement( 'head' );
3061 
3062  if ( $this->getHTMLTitle() == '' ) {
3063  $this->setHTMLTitle( $this->msg( 'pagetitle', $this->getPageTitle() )->inContentLanguage() );
3064  }
3065 
3066  if ( !Html::isXmlMimeType( $config->get( 'MimeType' ) ) ) {
3067  // Add <meta charset="UTF-8">
3068  // This should be before <title> since it defines the charset used by
3069  // text including the text inside <title>.
3070  // The spec recommends defining XHTML5's charset using the XML declaration
3071  // instead of meta.
3072  // Our XML declaration is output by Html::htmlHeader.
3073  // https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-content-type
3074  // https://html.spec.whatwg.org/multipage/semantics.html#charset
3075  $pieces[] = Html::element( 'meta', [ 'charset' => 'UTF-8' ] );
3076  }
3077 
3078  $pieces[] = Html::element( 'title', null, $this->getHTMLTitle() );
3079  $pieces[] = $this->getRlClient()->getHeadHtml( $htmlAttribs['class'] ?? null );
3080  $pieces[] = $this->buildExemptModules();
3081  $pieces = array_merge( $pieces, array_values( $this->getHeadLinksArray() ) );
3082  $pieces = array_merge( $pieces, array_values( $this->mHeadItems ) );
3083 
3084  // This library is intended to run on older browsers that MediaWiki no longer
3085  // supports as Grade A. For these Grade C browsers, we provide an experience
3086  // using only HTML and CSS. But, where standards-compliant browsers are able to
3087  // style unknown HTML elements without issue, old IE ignores these styles.
3088  // The html5shiv library fixes that.
3089  // Use an IE conditional comment to serve the script only to old IE
3090  $shivUrl = $config->get( 'ResourceBasePath' ) . '/resources/lib/html5shiv/html5shiv.js';
3091  $pieces[] = '<!--[if lt IE 9]>' .
3092  Html::linkedScript( $shivUrl, $this->CSP->getNonce() ) .
3093  '<![endif]-->';
3094 
3095  $pieces[] = Html::closeElement( 'head' );
3096 
3097  $bodyClasses = $this->mAdditionalBodyClasses;
3098  $bodyClasses[] = 'mediawiki';
3099 
3100  # Classes for LTR/RTL directionality support
3101  $bodyClasses[] = $userdir;
3102  $bodyClasses[] = "sitedir-$sitedir";
3103 
3104  $underline = $this->getUser()->getOption( 'underline' );
3105  if ( $underline < 2 ) {
3106  // The following classes can be used here:
3107  // * mw-underline-always
3108  // * mw-underline-never
3109  $bodyClasses[] = 'mw-underline-' . ( $underline ? 'always' : 'never' );
3110  }
3111 
3112  if ( $this->getLanguage()->capitalizeAllNouns() ) {
3113  # A <body> class is probably not the best way to do this . . .
3114  $bodyClasses[] = 'capitalize-all-nouns';
3115  }
3116 
3117  // Parser feature migration class
3118  // The idea is that this will eventually be removed, after the wikitext
3119  // which requires it is cleaned up.
3120  $bodyClasses[] = 'mw-hide-empty-elt';
3121 
3122  $bodyClasses[] = $sk->getPageClasses( $this->getTitle() );
3123  $bodyClasses[] = 'skin-' . Sanitizer::escapeClass( $sk->getSkinName() );
3124  $bodyClasses[] =
3125  'action-' . Sanitizer::escapeClass( Action::getActionName( $this->getContext() ) );
3126 
3127  $bodyAttrs = [];
3128  // While the implode() is not strictly needed, it's used for backwards compatibility
3129  // (this used to be built as a string and hooks likely still expect that).
3130  $bodyAttrs['class'] = implode( ' ', $bodyClasses );
3131 
3132  // Allow skins and extensions to add body attributes they need
3133  // Get ones from deprecated method
3134  if ( method_exists( $sk, 'addToBodyAttributes' ) ) {
3136  $sk->addToBodyAttributes( $this, $bodyAttrs );
3137  wfDeprecated( 'Skin::addToBodyAttributes method to add body attributes', '1.35' );
3138  }
3139 
3140  // Then run the hook, the recommended way of adding body attributes now
3141  $this->getHookRunner()->onOutputPageBodyAttributes( $this, $sk, $bodyAttrs );
3142 
3143  $pieces[] = Html::openElement( 'body', $bodyAttrs );
3144 
3145  return self::combineWrappedStrings( $pieces );
3146  }
3147 
3153  public function getResourceLoader() {
3154  if ( $this->mResourceLoader === null ) {
3155  // Lazy-initialise as needed
3156  $this->mResourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
3157  }
3158  return $this->mResourceLoader;
3159  }
3160 
3169  public function makeResourceLoaderLink( $modules, $only, array $extraQuery = [] ) {
3170  // Apply 'target' and 'origin' filters
3171  $modules = $this->filterModules( (array)$modules, null, $only );
3172 
3174  $this->getRlClientContext(),
3175  $modules,
3176  $only,
3177  $extraQuery,
3178  $this->CSP->getNonce()
3179  );
3180  }
3181 
3188  protected static function combineWrappedStrings( array $chunks ) {
3189  // Filter out empty values
3190  $chunks = array_filter( $chunks, 'strlen' );
3191  return WrappedString::join( "\n", $chunks );
3192  }
3193 
3200  public function getBottomScripts() {
3201  $chunks = [];
3202  $chunks[] = $this->getRlClient()->getBodyHtml();
3203 
3204  // Legacy non-ResourceLoader scripts
3205  $chunks[] = $this->mScripts;
3206 
3207  if ( $this->limitReportJSData ) {
3210  [ 'wgPageParseReport' => $this->limitReportJSData ]
3211  ),
3212  $this->CSP->getNonce()
3213  );
3214  }
3215 
3216  return self::combineWrappedStrings( $chunks );
3217  }
3218 
3225  public function getJsConfigVars() {
3226  return $this->mJsConfigVars;
3227  }
3228 
3235  public function addJsConfigVars( $keys, $value = null ) {
3236  if ( is_array( $keys ) ) {
3237  foreach ( $keys as $key => $value ) {
3238  $this->mJsConfigVars[$key] = $value;
3239  }
3240  return;
3241  }
3242 
3243  $this->mJsConfigVars[$keys] = $value;
3244  }
3245 
3255  public function getJSVars() {
3256  $curRevisionId = 0;
3257  $articleId = 0;
3258  $canonicalSpecialPageName = false; # T23115
3259  $services = MediaWikiServices::getInstance();
3260 
3261  $title = $this->getTitle();
3262  $ns = $title->getNamespace();
3263  $nsInfo = $services->getNamespaceInfo();
3264  $canonicalNamespace = $nsInfo->exists( $ns )
3265  ? $nsInfo->getCanonicalName( $ns )
3266  : $title->getNsText();
3267 
3268  $sk = $this->getSkin();
3269  // Get the relevant title so that AJAX features can use the correct page name
3270  // when making API requests from certain special pages (T36972).
3271  $relevantTitle = $sk->getRelevantTitle();
3272  $relevantUser = $sk->getRelevantUser();
3273 
3274  if ( $ns == NS_SPECIAL ) {
3275  list( $canonicalSpecialPageName, /*...*/ ) =
3276  $services->getSpecialPageFactory()->
3277  resolveAlias( $title->getDBkey() );
3278  } elseif ( $this->canUseWikiPage() ) {
3279  $wikiPage = $this->getWikiPage();
3280  $curRevisionId = $wikiPage->getLatest();
3281  $articleId = $wikiPage->getId();
3282  }
3283 
3284  $lang = $title->getPageViewLanguage();
3285 
3286  // Pre-process information
3287  $separatorTransTable = $lang->separatorTransformTable();
3288  $separatorTransTable = $separatorTransTable ?: [];
3289  $compactSeparatorTransTable = [
3290  implode( "\t", array_keys( $separatorTransTable ) ),
3291  implode( "\t", $separatorTransTable ),
3292  ];
3293  $digitTransTable = $lang->digitTransformTable();
3294  $digitTransTable = $digitTransTable ?: [];
3295  $compactDigitTransTable = [
3296  implode( "\t", array_keys( $digitTransTable ) ),
3297  implode( "\t", $digitTransTable ),
3298  ];
3299 
3300  $user = $this->getUser();
3301 
3302  // Internal variables for MediaWiki core
3303  $vars = [
3304  // @internal For mediawiki.page.startup
3305  'wgBreakFrames' => $this->getFrameOptions() == 'DENY',
3306 
3307  // @internal For jquery.tablesorter
3308  'wgSeparatorTransformTable' => $compactSeparatorTransTable,
3309  'wgDigitTransformTable' => $compactDigitTransTable,
3310  'wgDefaultDateFormat' => $lang->getDefaultDateFormat(),
3311  'wgMonthNames' => $lang->getMonthNamesArray(),
3312 
3313  // @internal For debugging purposes
3314  'wgRequestId' => WebRequest::getRequestId(),
3315 
3316  // @internal For mw.loader
3317  'wgCSPNonce' => $this->CSP->getNonce(),
3318  ];
3319 
3320  // Start of supported and stable config vars (for use by extensions/gadgets).
3321  $vars += [
3322  'wgCanonicalNamespace' => $canonicalNamespace,
3323  'wgCanonicalSpecialPageName' => $canonicalSpecialPageName,
3324  'wgNamespaceNumber' => $title->getNamespace(),
3325  'wgPageName' => $title->getPrefixedDBkey(),
3326  'wgTitle' => $title->getText(),
3327  'wgCurRevisionId' => $curRevisionId,
3328  'wgRevisionId' => (int)$this->getRevisionId(),
3329  'wgArticleId' => $articleId,
3330  'wgIsArticle' => $this->isArticle(),
3331  'wgIsRedirect' => $title->isRedirect(),
3332  'wgAction' => Action::getActionName( $this->getContext() ),
3333  'wgUserName' => $user->isAnon() ? null : $user->getName(),
3334  'wgUserGroups' => $user->getEffectiveGroups(),
3335  'wgCategories' => $this->getCategories(),
3336  'wgPageContentLanguage' => $lang->getCode(),
3337  'wgPageContentModel' => $title->getContentModel(),
3338  'wgRelevantPageName' => $relevantTitle->getPrefixedDBkey(),
3339  'wgRelevantArticleId' => $relevantTitle->getArticleID(),
3340  ];
3341  if ( $user->isLoggedIn() ) {
3342  $vars['wgUserId'] = $user->getId();
3343  $vars['wgUserEditCount'] = $user->getEditCount();
3344  $userReg = $user->getRegistration();
3345  $vars['wgUserRegistration'] = $userReg ? (int)wfTimestamp( TS_UNIX, $userReg ) * 1000 : null;
3346  // Get the revision ID of the oldest new message on the user's talk
3347  // page. This can be used for constructing new message alerts on
3348  // the client side.
3349  $userNewMsgRevId = $this->getLastSeenUserTalkRevId();
3350  // Only occupy precious space in the <head> when it is non-null (T53640)
3351  // mw.config.get returns null by default.
3352  if ( $userNewMsgRevId ) {
3353  $vars['wgUserNewMsgRevisionId'] = $userNewMsgRevId;
3354  }
3355  }
3356  $contLang = $services->getContentLanguage();
3357  if ( $contLang->hasVariants() ) {
3358  $vars['wgUserVariant'] = $contLang->getPreferredVariant();
3359  }
3360  // Same test as SkinTemplate
3361  $vars['wgIsProbablyEditable'] = $this->userCanEditOrCreate( $user, $title );
3362  $vars['wgRelevantPageIsProbablyEditable'] = $relevantTitle &&
3363  $this->userCanEditOrCreate( $user, $relevantTitle );
3364  foreach ( $title->getRestrictionTypes() as $type ) {
3365  // Following keys are set in $vars:
3366  // wgRestrictionCreate, wgRestrictionEdit, wgRestrictionMove, wgRestrictionUpload
3367  $vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type );
3368  }
3369  if ( $title->isMainPage() ) {
3370  $vars['wgIsMainPage'] = true;
3371  }
3372  if ( $relevantUser ) {
3373  $vars['wgRelevantUserName'] = $relevantUser->getName();
3374  }
3375  // End of stable config vars
3376 
3377  if ( $this->mRedirectedFrom ) {
3378  // @internal For skin JS
3379  $vars['wgRedirectedFrom'] = $this->mRedirectedFrom->getPrefixedDBkey();
3380  }
3381 
3382  // Allow extensions to add their custom variables to the mw.config map.
3383  // Use the 'ResourceLoaderGetConfigVars' hook if the variable is not
3384  // page-dependant but site-wide (without state).
3385  // Alternatively, you may want to use OutputPage->addJsConfigVars() instead.
3386  $this->getHookRunner()->onMakeGlobalVariablesScript( $vars, $this );
3387 
3388  // Merge in variables from addJsConfigVars last
3389  return array_merge( $vars, $this->getJsConfigVars() );
3390  }
3391 
3397  private function getLastSeenUserTalkRevId() {
3398  $services = MediaWikiServices::getInstance();
3399  $user = $this->getUser();
3400  $userHasNewMessages = $services
3401  ->getTalkPageNotificationManager()
3402  ->userHasNewMessages( $user );
3403  if ( !$userHasNewMessages ) {
3404  return null;
3405  }
3406 
3407  $timestamp = $services
3408  ->getTalkPageNotificationManager()
3409  ->getLatestSeenMessageTimestamp( $user );
3410 
3411  if ( !$timestamp ) {
3412  return null;
3413  }
3414 
3415  $revRecord = $services->getRevisionLookup()->getRevisionByTimestamp(
3416  $user->getTalkPage(),
3417  $timestamp
3418  );
3419 
3420  if ( !$revRecord ) {
3421  return null;
3422  }
3423 
3424  return $revRecord->getId();
3425  }
3426 
3436  public function userCanPreview() {
3437  $request = $this->getRequest();
3438  if (
3439  $request->getVal( 'action' ) !== 'submit' ||
3440  !$request->wasPosted()
3441  ) {
3442  return false;
3443  }
3444 
3445  $user = $this->getUser();
3446 
3447  if ( !$user->isLoggedIn() ) {
3448  // Anons have predictable edit tokens
3449  return false;
3450  }
3451  if ( !$user->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
3452  return false;
3453  }
3454 
3455  $title = $this->getTitle();
3456  $errors = MediaWikiServices::getInstance()->getPermissionManager()
3457  ->getPermissionErrors( 'edit', $user, $title );
3458  if ( count( $errors ) !== 0 ) {
3459  return false;
3460  }
3461 
3462  return true;
3463  }
3464 
3470  private function userCanEditOrCreate(
3471  User $user,
3473  ) {
3474  $pm = MediaWikiServices::getInstance()->getPermissionManager();
3475  return $pm->quickUserCan( 'edit', $user, $title )
3476  && ( $this->getTitle()->exists() ||
3477  $pm->quickUserCan( 'create', $user, $title ) );
3478  }
3479 
3483  public function getHeadLinksArray() {
3484  $tags = [];
3485  $config = $this->getConfig();
3486 
3487  $canonicalUrl = $this->mCanonicalUrl;
3488 
3489  $tags['meta-generator'] = Html::element( 'meta', [
3490  'name' => 'generator',
3491  'content' => 'MediaWiki ' . MW_VERSION,
3492  ] );
3493 
3494  if ( $config->get( 'ReferrerPolicy' ) !== false ) {
3495  // Per https://w3c.github.io/webappsec-referrer-policy/#unknown-policy-values
3496  // fallbacks should come before the primary value so we need to reverse the array.
3497  foreach ( array_reverse( (array)$config->get( 'ReferrerPolicy' ) ) as $i => $policy ) {
3498  $tags["meta-referrer-$i"] = Html::element( 'meta', [
3499  'name' => 'referrer',
3500  'content' => $policy,
3501  ] );
3502  }
3503  }
3504 
3505  $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
3506  if ( $p !== 'index,follow' ) {
3507  // http://www.robotstxt.org/wc/meta-user.html
3508  // Only show if it's different from the default robots policy
3509  $tags['meta-robots'] = Html::element( 'meta', [
3510  'name' => 'robots',
3511  'content' => $p,
3512  ] );
3513  }
3514 
3515  foreach ( $this->mMetatags as $tag ) {
3516  if ( strncasecmp( $tag[0], 'http:', 5 ) === 0 ) {
3517  $a = 'http-equiv';
3518  $tag[0] = substr( $tag[0], 5 );
3519  } elseif ( strncasecmp( $tag[0], 'og:', 3 ) === 0 ) {
3520  $a = 'property';
3521  } else {
3522  $a = 'name';
3523  }
3524  $tagName = "meta-{$tag[0]}";
3525  if ( isset( $tags[$tagName] ) ) {
3526  $tagName .= $tag[1];
3527  }
3528  $tags[$tagName] = Html::element( 'meta',
3529  [
3530  $a => $tag[0],
3531  'content' => $tag[1]
3532  ]
3533  );
3534  }
3535 
3536  foreach ( $this->mLinktags as $tag ) {
3537  $tags[] = Html::element( 'link', $tag );
3538  }
3539 
3540  # Universal edit button
3541  if ( $config->get( 'UniversalEditButton' ) && $this->isArticleRelated() ) {
3542  if ( $this->userCanEditOrCreate( $this->getUser(), $this->getTitle() ) ) {
3543  // Original UniversalEditButton
3544  $msg = $this->msg( 'edit' )->text();
3545  $tags['universal-edit-button'] = Html::element( 'link', [
3546  'rel' => 'alternate',
3547  'type' => 'application/x-wiki',
3548  'title' => $msg,
3549  'href' => $this->getTitle()->getEditURL(),
3550  ] );
3551  // Alternate edit link
3552  $tags['alternative-edit'] = Html::element( 'link', [
3553  'rel' => 'edit',
3554  'title' => $msg,
3555  'href' => $this->getTitle()->getEditURL(),
3556  ] );
3557  }
3558  }
3559 
3560  # Generally the order of the favicon and apple-touch-icon links
3561  # should not matter, but Konqueror (3.5.9 at least) incorrectly
3562  # uses whichever one appears later in the HTML source. Make sure
3563  # apple-touch-icon is specified first to avoid this.
3564  if ( $config->get( 'AppleTouchIcon' ) !== false ) {
3565  $tags['apple-touch-icon'] = Html::element( 'link', [
3566  'rel' => 'apple-touch-icon',
3567  'href' => $config->get( 'AppleTouchIcon' )
3568  ] );
3569  }
3570 
3571  if ( $config->get( 'Favicon' ) !== false ) {
3572  $tags['favicon'] = Html::element( 'link', [
3573  'rel' => 'shortcut icon',
3574  'href' => $config->get( 'Favicon' )
3575  ] );
3576  }
3577 
3578  # OpenSearch description link
3579  $tags['opensearch'] = Html::element( 'link', [
3580  'rel' => 'search',
3581  'type' => 'application/opensearchdescription+xml',
3582  'href' => wfScript( 'opensearch_desc' ),
3583  'title' => $this->msg( 'opensearch-desc' )->inContentLanguage()->text(),
3584  ] );
3585 
3586  # Real Simple Discovery link, provides auto-discovery information
3587  # for the MediaWiki API (and potentially additional custom API
3588  # support such as WordPress or Twitter-compatible APIs for a
3589  # blogging extension, etc)
3590  $tags['rsd'] = Html::element( 'link', [
3591  'rel' => 'EditURI',
3592  'type' => 'application/rsd+xml',
3593  // Output a protocol-relative URL here if $wgServer is protocol-relative.
3594  // Whether RSD accepts relative or protocol-relative URLs is completely
3595  // undocumented, though.
3596  'href' => wfExpandUrl( wfAppendQuery(
3597  wfScript( 'api' ),
3598  [ 'action' => 'rsd' ] ),
3600  ),
3601  ] );
3602 
3603  # Language variants
3604  if ( !$config->get( 'DisableLangConversion' ) ) {
3605  $lang = $this->getTitle()->getPageLanguage();
3606  if ( $lang->hasVariants() ) {
3607  $variants = $lang->getVariants();
3608  foreach ( $variants as $variant ) {
3609  $tags["variant-$variant"] = Html::element( 'link', [
3610  'rel' => 'alternate',
3611  'hreflang' => LanguageCode::bcp47( $variant ),
3612  'href' => $this->getTitle()->getLocalURL(
3613  [ 'variant' => $variant ] )
3614  ]
3615  );
3616  }
3617  # x-default link per https://support.google.com/webmasters/answer/189077?hl=en
3618  $tags["variant-x-default"] = Html::element( 'link', [
3619  'rel' => 'alternate',
3620  'hreflang' => 'x-default',
3621  'href' => $this->getTitle()->getLocalURL() ] );
3622  }
3623  }
3624 
3625  # Copyright
3626  if ( $this->copyrightUrl !== null ) {
3627  $copyright = $this->copyrightUrl;
3628  } else {
3629  $copyright = '';
3630  if ( $config->get( 'RightsPage' ) ) {
3631  $copy = Title::newFromText( $config->get( 'RightsPage' ) );
3632 
3633  if ( $copy ) {
3634  $copyright = $copy->getLocalURL();
3635  }
3636  }
3637 
3638  if ( !$copyright && $config->get( 'RightsUrl' ) ) {
3639  $copyright = $config->get( 'RightsUrl' );
3640  }
3641  }
3642 
3643  if ( $copyright ) {
3644  $tags['copyright'] = Html::element( 'link', [
3645  'rel' => 'license',
3646  'href' => $copyright ]
3647  );
3648  }
3649 
3650  # Feeds
3651  if ( $config->get( 'Feed' ) ) {
3652  $feedLinks = [];
3653 
3654  foreach ( $this->getSyndicationLinks() as $format => $link ) {
3655  # Use the page name for the title. In principle, this could
3656  # lead to issues with having the same name for different feeds
3657  # corresponding to the same page, but we can't avoid that at
3658  # this low a level.
3659 
3660  $feedLinks[] = $this->feedLink(
3661  $format,
3662  $link,
3663  # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
3664  $this->msg(
3665  "page-{$format}-feed", $this->getTitle()->getPrefixedText()
3666  )->text()
3667  );
3668  }
3669 
3670  # Recent changes feed should appear on every page (except recentchanges,
3671  # that would be redundant). Put it after the per-page feed to avoid
3672  # changing existing behavior. It's still available, probably via a
3673  # menu in your browser. Some sites might have a different feed they'd
3674  # like to promote instead of the RC feed (maybe like a "Recent New Articles"
3675  # or "Breaking news" one). For this, we see if $wgOverrideSiteFeed is defined.
3676  # If so, use it instead.
3677  $sitename = $config->get( 'Sitename' );
3678  $overrideSiteFeed = $config->get( 'OverrideSiteFeed' );
3679  if ( $overrideSiteFeed ) {
3680  foreach ( $overrideSiteFeed as $type => $feedUrl ) {
3681  // Note, this->feedLink escapes the url.
3682  $feedLinks[] = $this->feedLink(
3683  $type,
3684  $feedUrl,
3685  $this->msg( "site-{$type}-feed", $sitename )->text()
3686  );
3687  }
3688  } elseif ( !$this->getTitle()->isSpecial( 'Recentchanges' ) ) {
3689  $rctitle = SpecialPage::getTitleFor( 'Recentchanges' );
3690  foreach ( $this->getAdvertisedFeedTypes() as $format ) {
3691  $feedLinks[] = $this->feedLink(
3692  $format,
3693  $rctitle->getLocalURL( [ 'feed' => $format ] ),
3694  # For grep: 'site-rss-feed', 'site-atom-feed'
3695  $this->msg( "site-{$format}-feed", $sitename )->text()
3696  );
3697  }
3698  }
3699 
3700  # Allow extensions to change the list pf feeds. This hook is primarily for changing,
3701  # manipulating or removing existing feed tags. If you want to add new feeds, you should
3702  # use OutputPage::addFeedLink() instead.
3703  $this->getHookRunner()->onAfterBuildFeedLinks( $feedLinks );
3704 
3705  $tags += $feedLinks;
3706  }
3707 
3708  # Canonical URL
3709  if ( $config->get( 'EnableCanonicalServerLink' ) ) {
3710  if ( $canonicalUrl !== false ) {
3711  $canonicalUrl = wfExpandUrl( $canonicalUrl, PROTO_CANONICAL );
3712  } elseif ( $this->isArticleRelated() ) {
3713  // This affects all requests where "setArticleRelated" is true. This is
3714  // typically all requests that show content (query title, curid, oldid, diff),
3715  // and all wikipage actions (edit, delete, purge, info, history etc.).
3716  // It does not apply to File pages and Special pages.
3717  // 'history' and 'info' actions address page metadata rather than the page
3718  // content itself, so they may not be canonicalized to the view page url.
3719  // TODO: this ought to be better encapsulated in the Action class.
3720  $action = Action::getActionName( $this->getContext() );
3721  if ( in_array( $action, [ 'history', 'info' ] ) ) {
3722  $query = "action={$action}";
3723  } else {
3724  $query = '';
3725  }
3726  $canonicalUrl = $this->getTitle()->getCanonicalURL( $query );
3727  } else {
3728  $reqUrl = $this->getRequest()->getRequestURL();
3729  $canonicalUrl = wfExpandUrl( $reqUrl, PROTO_CANONICAL );
3730  }
3731  }
3732  if ( $canonicalUrl !== false ) {
3733  $tags[] = Html::element( 'link', [
3734  'rel' => 'canonical',
3735  'href' => $canonicalUrl
3736  ] );
3737  }
3738 
3739  // Allow extensions to add, remove and/or otherwise manipulate these links
3740  // If you want only to *add* <head> links, please use the addHeadItem()
3741  // (or addHeadItems() for multiple items) method instead.
3742  // This hook is provided as a last resort for extensions to modify these
3743  // links before the output is sent to client.
3744  $this->getHookRunner()->onOutputPageAfterGetHeadLinksArray( $tags, $this );
3745 
3746  return $tags;
3747  }
3748 
3757  private function feedLink( $type, $url, $text ) {
3758  return Html::element( 'link', [
3759  'rel' => 'alternate',
3760  'type' => "application/$type+xml",
3761  'title' => $text,
3762  'href' => $url ]
3763  );
3764  }
3765 
3775  public function addStyle( $style, $media = '', $condition = '', $dir = '' ) {
3776  $options = [];
3777  if ( $media ) {
3778  $options['media'] = $media;
3779  }
3780  if ( $condition ) {
3781  $options['condition'] = $condition;
3782  }
3783  if ( $dir ) {
3784  $options['dir'] = $dir;
3785  }
3786  $this->styles[$style] = $options;
3787  }
3788 
3796  public function addInlineStyle( $style_css, $flip = 'noflip' ) {
3797  if ( $flip === 'flip' && $this->getLanguage()->isRTL() ) {
3798  # If wanted, and the interface is right-to-left, flip the CSS
3799  $style_css = CSSJanus::transform( $style_css, true, false );
3800  }
3801  $this->mInlineStyles .= Html::inlineStyle( $style_css );
3802  }
3803 
3809  protected function buildExemptModules() {
3810  $chunks = [];
3811 
3812  // Requirements:
3813  // - Within modules provided by the software (core, skin, extensions),
3814  // styles from skin stylesheets should be overridden by styles
3815  // from modules dynamically loaded with JavaScript.
3816  // - Styles from site-specific, private, and user modules should override
3817  // both of the above.
3818  //
3819  // The effective order for stylesheets must thus be:
3820  // 1. Page style modules, formatted server-side by ResourceLoaderClientHtml.
3821  // 2. Dynamically-loaded styles, inserted client-side by mw.loader.
3822  // 3. Styles that are site-specific, private or from the user, formatted
3823  // server-side by this function.
3824  //
3825  // The 'ResourceLoaderDynamicStyles' marker helps JavaScript know where
3826  // point #2 is.
3827 
3828  // Add legacy styles added through addStyle()/addInlineStyle() here
3829  $chunks[] = implode( '', $this->buildCssLinksArray() ) . $this->mInlineStyles;
3830 
3831  // Things that go after the ResourceLoaderDynamicStyles marker
3832  $append = [];
3833  $separateReq = [ 'site.styles', 'user.styles' ];
3834  foreach ( $this->rlExemptStyleModules as $group => $moduleNames ) {
3835  if ( $moduleNames ) {
3836  $append[] = $this->makeResourceLoaderLink(
3837  array_diff( $moduleNames, $separateReq ),
3838  ResourceLoaderModule::TYPE_STYLES
3839  );
3840 
3841  foreach ( array_intersect( $moduleNames, $separateReq ) as $name ) {
3842  // These require their own dedicated request in order to support "@import"
3843  // syntax, which is incompatible with concatenation. (T147667, T37562)
3844  $append[] = $this->makeResourceLoaderLink( $name,
3845  ResourceLoaderModule::TYPE_STYLES
3846  );
3847  }
3848  }
3849  }
3850  if ( $append ) {
3851  $chunks[] = Html::element(
3852  'meta',
3853  [ 'name' => 'ResourceLoaderDynamicStyles', 'content' => '' ]
3854  );
3855  $chunks = array_merge( $chunks, $append );
3856  }
3857 
3858  return self::combineWrappedStrings( $chunks );
3859  }
3860 
3864  public function buildCssLinksArray() {
3865  $links = [];
3866 
3867  foreach ( $this->styles as $file => $options ) {
3868  $link = $this->styleLink( $file, $options );
3869  if ( $link ) {
3870  $links[$file] = $link;
3871  }
3872  }
3873  return $links;
3874  }
3875 
3883  protected function styleLink( $style, array $options ) {
3884  if ( isset( $options['dir'] ) && $this->getLanguage()->getDir() != $options['dir'] ) {
3885  return '';
3886  }
3887 
3888  if ( isset( $options['media'] ) ) {
3889  $media = self::transformCssMedia( $options['media'] );
3890  if ( $media === null ) {
3891  return '';
3892  }
3893  } else {
3894  $media = 'all';
3895  }
3896 
3897  if ( substr( $style, 0, 1 ) == '/' ||
3898  substr( $style, 0, 5 ) == 'http:' ||
3899  substr( $style, 0, 6 ) == 'https:' ) {
3900  $url = $style;
3901  } else {
3902  $config = $this->getConfig();
3903  // Append file hash as query parameter
3905  $config,
3906  $config->get( 'StylePath' ) . '/' . $style
3907  );
3908  }
3909 
3910  $link = Html::linkedStyle( $url, $media );
3911 
3912  if ( isset( $options['condition'] ) ) {
3913  $condition = htmlspecialchars( $options['condition'] );
3914  $link = "<!--[if $condition]>$link<![endif]-->";
3915  }
3916  return $link;
3917  }
3918 
3940  public static function transformResourcePath( Config $config, $path ) {
3941  global $IP;
3942 
3943  $localDir = $IP;
3944  $remotePathPrefix = $config->get( 'ResourceBasePath' );
3945  if ( $remotePathPrefix === '' ) {
3946  // The configured base path is required to be empty string for
3947  // wikis in the domain root
3948  $remotePath = '/';
3949  } else {
3950  $remotePath = $remotePathPrefix;
3951  }
3952  if ( strpos( $path, $remotePath ) !== 0 || substr( $path, 0, 2 ) === '//' ) {
3953  // - Path is outside wgResourceBasePath, ignore.
3954  // - Path is protocol-relative. Fixes T155310. Not supported by RelPath lib.
3955  return $path;
3956  }
3957  // For files in resources, extensions/ or skins/, ResourceBasePath is preferred here.
3958  // For other misc files in $IP, we'll fallback to that as well. There is, however, a fourth
3959  // supported dir/path pair in the configuration (wgUploadDirectory, wgUploadPath)
3960  // which is not expected to be in wgResourceBasePath on CDNs. (T155146)
3961  $uploadPath = $config->get( 'UploadPath' );
3962  if ( strpos( $path, $uploadPath ) === 0 ) {
3963  $localDir = $config->get( 'UploadDirectory' );
3964  $remotePathPrefix = $remotePath = $uploadPath;
3965  }
3966 
3967  $path = RelPath::getRelativePath( $path, $remotePath );
3968  return self::transformFilePath( $remotePathPrefix, $localDir, $path );
3969  }
3970 
3982  public static function transformFilePath( $remotePathPrefix, $localPath, $file ) {
3983  $hash = md5_file( "$localPath/$file" );
3984  if ( $hash === false ) {
3985  wfLogWarning( __METHOD__ . ": Failed to hash $localPath/$file" );
3986  $hash = '';
3987  }
3988  return "$remotePathPrefix/$file?" . substr( $hash, 0, 5 );
3989  }
3990 
3998  public static function transformCssMedia( $media ) {
3999  global $wgRequest;
4000 
4001  // https://www.w3.org/TR/css3-mediaqueries/#syntax
4002  $screenMediaQueryRegex = '/^(?:only\s+)?screen\b/i';
4003 
4004  // Switch in on-screen display for media testing
4005  $switches = [
4006  'printable' => 'print',
4007  'handheld' => 'handheld',
4008  ];
4009  foreach ( $switches as $switch => $targetMedia ) {
4010  if ( $wgRequest->getBool( $switch ) ) {
4011  if ( $media == $targetMedia ) {
4012  $media = '';
4013  } elseif ( preg_match( $screenMediaQueryRegex, $media ) === 1 ) {
4014  /* This regex will not attempt to understand a comma-separated media_query_list
4015  *
4016  * Example supported values for $media:
4017  * 'screen', 'only screen', 'screen and (min-width: 982px)' ),
4018  * Example NOT supported value for $media:
4019  * '3d-glasses, screen, print and resolution > 90dpi'
4020  *
4021  * If it's a print request, we never want any kind of screen stylesheets
4022  * If it's a handheld request (currently the only other choice with a switch),
4023  * we don't want simple 'screen' but we might want screen queries that
4024  * have a max-width or something, so we'll pass all others on and let the
4025  * client do the query.
4026  */
4027  if ( $targetMedia == 'print' || $media == 'screen' ) {
4028  return null;
4029  }
4030  }
4031  }
4032  }
4033 
4034  return $media;
4035  }
4036 
4045  public function addWikiMsg( ...$args ) {
4046  $name = array_shift( $args );
4047  $this->addWikiMsgArray( $name, $args );
4048  }
4049 
4058  public function addWikiMsgArray( $name, $args ) {
4059  $this->addHTML( $this->msg( $name, $args )->parseAsBlock() );
4060  }
4061 
4088  public function wrapWikiMsg( $wrap, ...$msgSpecs ) {
4089  $s = $wrap;
4090  foreach ( $msgSpecs as $n => $spec ) {
4091  if ( is_array( $spec ) ) {
4092  $args = $spec;
4093  $name = array_shift( $args );
4094  } else {
4095  $args = [];
4096  $name = $spec;
4097  }
4098  $s = str_replace( '$' . ( $n + 1 ), $this->msg( $name, $args )->plain(), $s );
4099  }
4100  $this->addWikiTextAsInterface( $s );
4101  }
4102 
4108  public function isTOCEnabled() {
4109  return $this->mEnableTOC;
4110  }
4111 
4119  public static function setupOOUI( $skinName = 'default', $dir = 'ltr' ) {
4121  $theme = $themes[$skinName] ?? $themes['default'];
4122  // For example, 'OOUI\WikimediaUITheme'.
4123  $themeClass = "OOUI\\{$theme}Theme";
4124  OOUI\Theme::setSingleton( new $themeClass() );
4125  OOUI\Element::setDefaultDir( $dir );
4126  }
4127 
4134  public function enableOOUI() {
4136  strtolower( $this->getSkin()->getSkinName() ),
4137  $this->getLanguage()->getDir()
4138  );
4139  $this->addModuleStyles( [
4140  'oojs-ui-core.styles',
4141  'oojs-ui.styles.indicators',
4142  'mediawiki.widgets.styles',
4143  'oojs-ui-core.icons',
4144  ] );
4145  }
4146 
4157  public function getCSPNonce() {
4158  return $this->CSP->getNonce();
4159  }
4160 
4167  public function getCSP() {
4168  return $this->CSP;
4169  }
4170 }
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:152
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:2343
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:2519
OutputPage\$mCategories
array $mCategories
Definition: OutputPage.php:125
ParserOutput\getEnableOOUI
getEnableOOUI()
Definition: ParserOutput.php:670
OutputPage\addBacklinkSubtitle
addBacklinkSubtitle(Title $title, $query=[])
Add a subtitle containing a backlink to a page.
Definition: OutputPage.php:1106
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:1462
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:33
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:63
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:1122
OutputPage\parseAsInterface
parseAsInterface( $text, $linestart=true)
Parse wikitext in the user interface language and return the HTML.
Definition: OutputPage.php:2062
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
OutputPage\enableClientCache
enableClientCache( $state)
Use enableClientCache(false) to force it to send nocache headers.
Definition: OutputPage.php:2179
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:329
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:40
OutputPage\getLanguageLinks
getLanguageLinks()
Get the list of language links.
Definition: OutputPage.php:1358
OutputPage\buildBacklinkSubtitle
static buildBacklinkSubtitle(Title $title, $query=[])
Build message object for a subtitle containing a backlink to a page.
Definition: OutputPage.php:1091
HtmlArmor
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:28
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:1598
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:1075
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:2321
ParserOutput
Definition: ParserOutput.php:25
Article\formatRobotPolicy
static formatRobotPolicy( $policy)
Converts a String robot policy into an associative array, to allow merging of several policies using ...
Definition: Article.php:1071
OutputPage\getJSVars
getJSVars()
Get an array containing the variables to be set in mw.config in JavaScript.
Definition: OutputPage.php:3255
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:2917
OutputPage\getDisplayTitle
getDisplayTitle()
Returns page display title.
Definition: OutputPage.php:1026
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:1860
OutputPage\setTitle
setTitle(Title $t)
Set the Title object to use.
Definition: OutputPage.php:1054
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:1329
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:1413
OutputPage\parserOptions
parserOptions()
Get/set the ParserOptions object to use for wikitext parsing.
Definition: OutputPage.php:1655
OutputPage\hasHeadItem
hasHeadItem( $name)
Check if the header item $name is already set.
Definition: OutputPage.php:689
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:152
$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:1339
OutputPage\addLinkHeader
addLinkHeader( $header)
Add an HTTP Link: header.
Definition: OutputPage.php:2297
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:1546
OutputPage\getCSP
getCSP()
Get the ContentSecurityPolicy object.
Definition: OutputPage.php:4167
OutputPage\isArticleRelated
isArticleRelated()
Return whether this page is related an article on the wiki.
Definition: OutputPage.php:1307
OutputPage\setArticleBodyOnly
setArticleBodyOnly( $only)
Set whether the output should only contain the body of the article, without any skin,...
Definition: OutputPage.php:710
OutputPage\getFrameOptions
getFrameOptions()
Get the X-Frame-Options header value (without the name part), or false if there isn't one.
Definition: OutputPage.php:2373
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:496
OutputPage\getRevisionId
getRevisionId()
Get the displayed revision ID.
Definition: OutputPage.php:1691
OutputPage\clearHTML
clearHTML()
Clear the body HTML.
Definition: OutputPage.php:1636
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:623
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1811
ParserOutput\getImages
& getImages()
Definition: ParserOutput.php:599
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:2890
OutputPage\buildCssLinksArray
buildCssLinksArray()
Definition: OutputPage.php:3864
OutputPage\addParserOutputMetadata
addParserOutputMetadata(ParserOutput $parserOutput)
Add all metadata associated with a ParserOutput object, but without the actual HTML.
Definition: OutputPage.php:1880
OutputPage\combineWrappedStrings
static combineWrappedStrings(array $chunks)
Combine WrappedString chunks and filter out empty ones.
Definition: OutputPage.php:3188
Sanitizer\mergeAttributes
static mergeAttributes( $a, $b)
Merge two sets of HTML attributes.
Definition: Sanitizer.php:798
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:2389
ParserOutput\getJsConfigVars
getJsConfigVars()
Definition: ParserOutput.php:635
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:3200
ParserOptions\newFromAnon
static newFromAnon()
Get a ParserOptions object for an anonymous user.
Definition: ParserOptions.php:1074
OutputPage\couldBePublicCached
couldBePublicCached()
Whether the output might become publicly cached.
Definition: OutputPage.php:2189
OutputPage\addHeadItems
addHeadItems( $values)
Add one or more head items to the output.
Definition: OutputPage.php:679
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:2419
$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:2788
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:1222
$s
$s
Definition: mergeMessageFileList.php:185
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:90
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:1264
OutputPage\getFileVersion
getFileVersion()
Get the displayed file version.
Definition: OutputPage.php:1745
OutputPage\getSyndicationLinks
getSyndicationLinks()
Return URLs for each supported syndication format for this page.
Definition: OutputPage.php:1252
ContextSource\canUseWikiPage
canUseWikiPage()
Check whether a WikiPage object can be get with getWikiPage().
Definition: ContextSource.php:91
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1089
ContextSource\getRequest
getRequest()
Definition: ContextSource.php:71
Title\newMainPage
static newMainPage(MessageLocalizer $localizer=null)
Create a new Title for the Main Page.
Definition: Title.php:654
OutputPage\$mRevisionId
int $mRevisionId
To include the variable {{REVISIONID}}.
Definition: OutputPage.php:259
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:619
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
ContextSource\getTitle
getTitle()
Definition: ContextSource.php:79
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:486
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:1498
LinkCache\getSelectFields
static getSelectFields()
Fields that LinkCache needs to select.
Definition: LinkCache.php:219
OutputPage\addHTML
addHTML( $text)
Append $text to the body HTML.
Definition: OutputPage.php:1616
OutputPage\parseInternal
parseInternal( $text, $title, $linestart, $interface)
Parse wikitext and return the HTML (internal implementation helper)
Definition: OutputPage.php:2103
OutputPage\getReportTo
getReportTo()
Definition: OutputPage.php:2395
OutputPage\addHeadItem
addHeadItem( $name, $value)
Add or replace a head item to the output.
Definition: OutputPage.php:669
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:1722
OutputPage\addWikiMsgArray
addWikiMsgArray( $name, $args)
Add a wikitext-formatted message to the output.
Definition: OutputPage.php:4058
OutputPage\transformCssMedia
static transformCssMedia( $media)
Transform "media" attribute based on request parameters.
Definition: OutputPage.php:3998
OutputPage\setLastModified
setLastModified( $timestamp)
Override the last modified timestamp.
Definition: OutputPage.php:858
$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:128
OutputPage\$mImageTimeKeys
array $mImageTimeKeys
Definition: OutputPage.php:190
OutputPage\showPermissionsErrorPage
showPermissionsErrorPage(array $errors, $action=null)
Output a standard permission error page.
Definition: OutputPage.php:2703
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:627
OutputPage\getLinkTags
getLinkTags()
Returns the current <link> tags.
Definition: OutputPage.php:436
OutputPage\forceHideNewSectionLink
forceHideNewSectionLink()
Forcibly hide the new section link?
Definition: OutputPage.php:1173
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:681
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:1295
OutputPage\addElement
addElement( $element, array $attribs=[], $contents='')
Shortcut for adding an Html::element via addHTML.
Definition: OutputPage.php:1629
OutputPage\addParserOutputContent
addParserOutputContent(ParserOutput $parserOutput, $poOptions=[])
Add the HTML and enhancements for it (like ResourceLoader modules) associated with a ParserOutput obj...
Definition: OutputPage.php:1988
Config
Interface for configuration instances.
Definition: Config.php:28
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:58
ParserOutput\getExtraCSPDefaultSrcs
getExtraCSPDefaultSrcs()
Get extra Content-Security-Policy 'default-src' directives.
Definition: ParserOutput.php:679
MediaWiki\Linker\LinkTarget\getNamespace
getNamespace()
Get the namespace index.
OutputPage\userCanEditOrCreate
userCanEditOrCreate(User $user, LinkTarget $title)
Definition: OutputPage.php:3470
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:62
ParserOutput\getLimitReportJSData
getLimitReportJSData()
Definition: ParserOutput.php:666
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:3757
wfDeprecatedMsg
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
Definition: GlobalFunctions.php:1061
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:1785
MWException
MediaWiki exception.
Definition: MWException.php:26
OutputPage\considerCacheSettingsFinal
considerCacheSettingsFinal()
Set the expectation that cache control will not change after this point.
Definition: OutputPage.php:2212
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:3775
OutputPage\sendCacheControl
sendCacheControl()
Send cache control HTTP headers.
Definition: OutputPage.php:2429
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1029
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:3397
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:2531
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:3883
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:1732
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2464
OutputPage\getLinkHeader
getLinkHeader()
Return a Link: header.
Definition: OutputPage.php:2306
OutputPage\getResourceLoader
getResourceLoader()
Get a ResourceLoader object associated with this OutputPage.
Definition: OutputPage.php:3153
OutputPage\isTOCEnabled
isTOCEnabled()
Whether the output has a table of contents.
Definition: OutputPage.php:4108
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:29
ContextSource\getWikiPage
getWikiPage()
Get the WikiPage object.
Definition: ContextSource.php:104
OutputPage\setFeedAppendQuery
setFeedAppendQuery( $val)
Add default feeds to the page header This is mainly kept for backward compatibility,...
Definition: OutputPage.php:1216
OutputPage\setDisplayTitle
setDisplayTitle( $html)
Same as page title but only contains name of the page, not any other text.
Definition: OutputPage.php:1014
$modules
$modules
Definition: HTMLFormElement.php:13
OutputPage\isDisabled
isDisabled()
Return whether the output will be completely disabled.
Definition: OutputPage.php:1155
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:1681
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:1272
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:1556
ContextSource\getSkin
getSkin()
Definition: ContextSource.php:136
OutputPage\setSubtitle
setSubtitle( $str)
Replace the subtitle with $str.
Definition: OutputPage.php:1065
$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:2280
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:2841
$title
$title
Definition: testCompression.php:38
OutputPage\getCacheVaryCookies
getCacheVaryCookies()
Get the list of cookie names that will influence the cache.
Definition: OutputPage.php:2221
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:644
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:910
OutputPage\addBodyClasses
addBodyClasses( $classes)
Add a class to the <body> element.
Definition: OutputPage.php:699
ParserOutput\getIndicators
getIndicators()
Definition: ParserOutput.php:567
ResourceLoaderModule\getOrigin
getOrigin()
Get this module's origin.
Definition: ResourceLoaderModule.php:144
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:912
ContextSource\setContext
setContext(IContextSource $context)
Definition: ContextSource.php:55
OutputPage\isArticle
isArticle()
Return whether the content displayed page is related to the source of the corresponding article on th...
Definition: OutputPage.php:1285
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:547
OutputPage\showErrorPage
showErrorPage( $title, $msg, $params=[])
Output a standard error page.
Definition: OutputPage.php:2676
OutputPage\addParserOutputText
addParserOutputText(ParserOutput $parserOutput, $poOptions=[])
Add the HTML associated with a ParserOutput object, without any metadata.
Definition: OutputPage.php:2004
OutputPage\getCSPNonce
getCSPNonce()
Get (and set if not yet set) the CSP nonce.
Definition: OutputPage.php:4157
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:35
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:595
OutputPage\getArticleBodyOnly
getArticleBodyOnly()
Return whether the output will contain only the body of the article.
Definition: OutputPage.php:719
OutputPage\getPreventClickjacking
getPreventClickjacking()
Get the prevent-clickjacking flag.
Definition: OutputPage.php:2362
ParserOutput\getTOCHTML
getTOCHTML()
Definition: ParserOutput.php:651
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:1835
ParserOutput\getExtraCSPScriptSrcs
getExtraCSPScriptSrcs()
Get extra Content-Security-Policy 'script-src' directives.
Definition: ParserOutput.php:688
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:4088
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:168
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:2242
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:1003
OutputPage\disable
disable()
Disable output completely, i.e.
Definition: OutputPage.php:1146
OutputPage\setIndexPolicy
setIndexPolicy( $policy)
Set the index policy for the page, but leave the follow policy un- touched.
Definition: OutputPage.php:898
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:618
OutputPage\$mResourceLoader
ResourceLoader $mResourceLoader
Definition: OutputPage.php:172
ParserOutput\getNewSection
getNewSection()
Definition: ParserOutput.php:781
$content
$content
Definition: router.php:76
Skin\getPageClasses
getPageClasses( $title)
TODO: document.
Definition: Skin.php:448
OutputPage\addCategoryLinks
addCategoryLinks(array $categories)
Add an array of categories, with names in the keys.
Definition: OutputPage.php:1367
OutputPage\setRevisionTimestamp
setRevisionTimestamp( $timestamp)
Set the timestamp of the revision which will be displayed.
Definition: OutputPage.php:1712
OutputPage\getHeadItemsArray
getHeadItemsArray()
Get an array of head items.
Definition: OutputPage.php:653
wfClearOutputBuffers
wfClearOutputBuffers()
More legible than passing a 'false' parameter to wfResetOutputBuffers():
Definition: GlobalFunctions.php:1690
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:2874
OutputPage\buildExemptModules
buildExemptModules()
Build exempt modules and legacy non-ResourceLoader styles.
Definition: OutputPage.php:3809
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:741
ParserOptions\newFromContext
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
Definition: ParserOptions.php:1113
OutputPage\addWikiMsg
addWikiMsg(... $args)
Add a wikitext-formatted message to the output.
Definition: OutputPage.php:4045
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:1524
OutputPage\formatPermissionsErrorMessage
formatPermissionsErrorMessage(array $errors, $action=null)
Format a list of error messages.
Definition: OutputPage.php:2802
ParserOutput\getOutputHooks
getOutputHooks()
Definition: ParserOutput.php:639
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:887
ParserOutput\getHideNewSection
getHideNewSection()
Definition: ParserOutput.php:777
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:943
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:1349
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:4119
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:1607
ParserOutput\getNoGallery
getNoGallery()
Definition: ParserOutput.php:615
OutputPage\$mEnableClientCache
$mEnableClientCache
Definition: OutputPage.php:228
OutputPage\getHTMLTitle
getHTMLTitle()
Return the "HTML title", i.e.
Definition: OutputPage.php:956
OutputPage\$cacheIsFinal
bool $cacheIsFinal
See OutputPage::couldBePublicCached.
Definition: OutputPage.php:74
OutputPage\clearSubtitle
clearSubtitle()
Clear the subtitles.
Definition: OutputPage.php:1113
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:4134
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:53
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:1449
OutputPage\setFollowPolicy
setFollowPolicy( $policy)
Set the follow policy for the page, but leave the index policy un- touched.
Definition: OutputPage.php:921
Content
Base interface for content objects.
Definition: Content.php:34
OutputPage\setPageTitle
setPageTitle( $name)
"Page title" means the contents of <h1>.
Definition: OutputPage.php:981
OutputPage\getRlClient
getRlClient()
Call this to freeze the module queue and JS config and create a formatter.
Definition: OutputPage.php:2973
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:756
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:603
Title
Represents a title within MediaWiki.
Definition: Title.php:42
ResourceLoaderModule
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
Definition: ResourceLoaderModule.php:38
OutputPage\setCdnMaxage
setCdnMaxage( $maxage)
Set the value of the "s-maxage" part of the "Cache-control" HTTP header.
Definition: OutputPage.php:2127
Parser\stripOuterParagraph
static stripOuterParagraph( $html)
Strip outer.
Definition: Parser.php:6263
OutputPage\getAllowedModules
getAllowedModules( $type)
Show what level of JavaScript / CSS untrustworthiness is allowed on this page.
Definition: OutputPage.php:1581
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:2263
ContentHandler\getContentText
static getContentText(Content $content=null)
Convenience function for getting flat text from a Content object.
Definition: ContentHandler.php:89
OutputPage\setProperty
setProperty( $name, $value)
Set an additional output property.
Definition: OutputPage.php:730
OutputPage\isPrintable
isPrintable()
Return whether the page is "printable".
Definition: OutputPage.php:1139
OutputPage\setSyndicated
setSyndicated( $show=true)
Add or remove feed links in the page header This is mainly kept for backward compatibility,...
Definition: OutputPage.php:1185
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:1810
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:3796
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:3436
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:965
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:330
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:1041
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:559
OutputPage\setPrintable
setPrintable()
Set the page as printable, i.e.
Definition: OutputPage.php:1130
OutputPage\getHeadLinksArray
getHeadLinksArray()
Definition: OutputPage.php:3483
OutputPage\adaptCdnTTL
adaptCdnTTL( $mtime, $minTTL=0, $maxTTL=0)
Get TTL in [$minTTL,$maxTTL] and pass it to lowerCdnMaxage()
Definition: OutputPage.php:2157
OutputPage\getCdnCacheEpoch
getCdnCacheEpoch( $reqTime, $maxAge)
Definition: OutputPage.php:844
OutputPage\allowClickjacking
allowClickjacking()
Turn off frame-breaking.
Definition: OutputPage.php:2352
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:2497
OutputPage\showFatalError
showFatalError( $message)
Output an error page.
Definition: OutputPage.php:2860
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:1645
Message
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:160
OutputPage\parseInlineAsInterface
parseInlineAsInterface( $text, $linestart=true)
Parse wikitext in the user interface language, strip paragraph wrapper, and return the HTML.
Definition: OutputPage.php:2085
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:1701
Sanitizer\normalizeCharReferences
static normalizeCharReferences( $text)
Ensure that any entities and character references are legal for XML and XHTML specifically.
Definition: Sanitizer.php:1415
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:155
IContextSource\getRequest
getRequest()
OutputPage\showNewSectionLink
showNewSectionLink()
Show an "add new section" link?
Definition: OutputPage.php:1164
OutputPage\$mPageLinkTitle
string $mPageLinkTitle
Used by skin template.
Definition: OutputPage.php:151
ParserOutput\getText
getText( $options=[])
Get the output HTML.
Definition: ParserOutput.php:346
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:3169
OutputPage\addWikiTextTitleInternal
addWikiTextTitleInternal( $text, Title $title, $linestart, $interface, $wrapperClass=null)
Add wikitext with a custom Title object.
Definition: OutputPage.php:1859
OutputPage\getIndicators
getIndicators()
Get the indicators associated with this page.
Definition: OutputPage.php:1512
$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:167
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:3235
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:40
OutputPage\getFollowPolicy
getFollowPolicy()
Get the current follow policy for the page as a string.
Definition: OutputPage.php:933
OutputPage\getCategories
getCategories( $type='all')
Get the list of category names this page belongs to.
Definition: OutputPage.php:1475
OutputPage\getJsConfigVars
getJsConfigVars()
Get the javascript config vars to include on this page.
Definition: OutputPage.php:3225
OutputPage\setCopyright
setCopyright( $hasCopyright)
Set whether the standard copyright should be shown for the current page.
Definition: OutputPage.php:1316
OutputPage\getTemplateIds
getTemplateIds()
Get the templates used on this page.
Definition: OutputPage.php:1755
$IP
$IP
Definition: WebStart.php:49
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:54
OutputPage\$mIsArticleRelated
bool $mIsArticleRelated
Stores "article flag" toggle.
Definition: OutputPage.php:92
OutputPage\isSyndicated
isSyndicated()
Should we output feed links for this page?
Definition: OutputPage.php:1244
OutputPage\$mFeedLinksAppendQuery
$mFeedLinksAppendQuery
Definition: OutputPage.php:195
OutputPage\getFileSearchOptions
getFileSearchOptions()
Get the files used on this page.
Definition: OutputPage.php:1765
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:2016
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:2651
OutputPage\addTemplate
addTemplate(&$template)
Add the output of a QuickTemplate to the output buffer.
Definition: OutputPage.php:2026
OutputPage\getFeedAppendQuery
getFeedAppendQuery()
Will currently always return null.
Definition: OutputPage.php:1261
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:2140
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:697
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:1234
ParserOutput\preventClickjacking
preventClickjacking( $flag=null)
Get or set the prevent-clickjacking flag.
Definition: ParserOutput.php:1350
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:3940
OutputPage\parseAsContent
parseAsContent( $text, $linestart=true)
Parse wikitext in the page content language and return the HTML.
Definition: OutputPage.php:2041
OutputPage\getAdvertisedFeedTypes
getAdvertisedFeedTypes()
Return effective list of advertised feed types.
Definition: OutputPage.php:1199
OutputPage\setRobotPolicy
setRobotPolicy( $policy)
Set the robot policy for the page: http://www.robotstxt.org/meta.html
Definition: OutputPage.php:870
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:3982
OutputPage\headElement
headElement(Skin $sk, $includeStyle=true)
Definition: OutputPage.php:3049
$type
$type
Definition: testCompression.php:52
OutputPage\$mStatusCode
int $mStatusCode
Definition: OutputPage.php:113