*/
use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
use MediaWiki\Session\SessionManager;
use WrappedString\WrappedString;
use WrappedString\WrappedStringList;
*/
private $copyrightUrl;
+ /** @var array Profiling data */
+ private $limitReportJSData = [];
+
/**
* Constructor for OutputPage. This should not be called directly.
* Instead a new RequestContext should be created and it will implicitly create
if ( $module instanceof ResourceLoaderModule
&& $module->getOrigin() <= $this->getAllowedModules( $type )
&& ( is_null( $position ) || $module->getPosition() == $position )
- && ( !$this->mTarget || in_array( $this->mTarget, $module->getTargets() ) )
) {
+ if ( $this->mTarget && !in_array( $this->mTarget, $module->getTargets() ) ) {
+ $this->warnModuleTargetFilter( $module->getName() );
+ continue;
+ }
$filteredModules[] = $val;
}
}
return $filteredModules;
}
+ private function warnModuleTargetFilter( $moduleName ) {
+ static $warnings = [];
+ if ( isset( $warnings[$this->mTarget][$moduleName] ) ) {
+ return;
+ }
+ $warnings[$this->mTarget][$moduleName] = true;
+ $this->getResourceLoader()->getLogger()->debug(
+ 'Module "{module}" not loadable on target "{target}".',
+ [
+ 'module' => $moduleName,
+ 'target' => $this->mTarget,
+ ]
+ );
+ }
+
/**
* Get the list of modules to include on this page
*
'epoch' => $config->get( 'CacheEpoch' )
];
if ( $config->get( 'UseSquid' ) ) {
- // bug 44570: the core page itself may not change, but resources might
+ // T46570: the core page itself may not change, but resources might
$modifiedTimes['sepoch'] = wfTimestamp( TS_MW, time() - $config->get( 'SquidMaxage' ) );
}
Hooks::run( 'OutputPageCheckLastModified', [ &$modifiedTimes, $this ] );
if ( $title->isRedirect() ) {
$query['redirect'] = 'no';
}
+ $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
return wfMessage( 'backlinksubtitle' )
- ->rawParams( Linker::link( $title, null, [], $query ) );
+ ->rawParams( $linkRenderer->makeLink( $title, null, [], $query ) );
}
/**
}
}
+ // Avoid PHP 7.1 warning of passing $this by reference
+ $outputPage = $this;
# Add the remaining categories to the skin
if ( Hooks::run(
'OutputPageMakeCategoryLinks',
- [ &$this, $categories, &$this->mCategoryLinks ] )
+ [ &$outputPage, $categories, &$this->mCategoryLinks ] )
) {
+ $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
foreach ( $categories as $category => $type ) {
// array keys will cast numeric category names to ints, so cast back to string
$category = (string)$category;
}
$text = $wgContLang->convertHtml( $title->getText() );
$this->mCategories[$type][] = $title->getText();
- $this->mCategoryLinks[$type][] = Linker::link( $title, $text );
+ $this->mCategoryLinks[$type][] = $linkRenderer->makeLink( $title, new HtmlArmor( $text ) );
}
}
}
ResourceLoaderModule::ORIGIN_CORE_INDIVIDUAL
);
- // Site-wide styles are controlled by a config setting, see bug 71621
+ // Site-wide styles are controlled by a config setting, see T73621
// for background on why. User styles are never allowed.
if ( $this->getConfig()->get( 'AllowSiteCSSOnRestrictedPages' ) ) {
$styleOrigin = ResourceLoaderModule::ORIGIN_USER_SITEWIDE;
}
}
- // enable OOUI if requested via ParserOutput
+ // Enable OOUI if requested via ParserOutput
if ( $parserOutput->getEnableOOUI() ) {
$this->enableOOUI();
}
+ // Include parser limit report
+ if ( !$this->limitReportJSData ) {
+ $this->limitReportJSData = $parserOutput->getLimitReportJSData();
+ }
+
// Link flags are ignored for now, but may in the future be
// used to mark individual language links.
$linkFlags = [];
+ // Avoid PHP 7.1 warning of passing $this by reference
+ $outputPage = $this;
Hooks::run( 'LanguageLinks', [ $this->getTitle(), &$this->mLanguageLinks, &$linkFlags ] );
- Hooks::run( 'OutputPageParserOutput', [ &$this, $parserOutput ] );
+ Hooks::run( 'OutputPageParserOutput', [ &$outputPage, $parserOutput ] );
}
/**
*/
public function addParserOutputText( $parserOutput ) {
$text = $parserOutput->getText();
- Hooks::run( 'OutputPageBeforeHTML', [ &$this, &$text ] );
+ // Avoid PHP 7.1 warning of passing $this by reference
+ $outputPage = $this;
+ Hooks::run( 'OutputPageBeforeHTML', [ &$outputPage, &$text ] );
$this->addHTML( $text );
}
* if there isn't one. This is used by Skin to determine whether to enable
* JavaScript frame-breaking, for clients that don't support X-Frame-Options.
*
- * @return string
+ * @return string|false
*/
public function getFrameOptions() {
$config = $this->getConfig();
$response->header( "Content-Type: text/html; charset=utf-8" );
if ( $config->get( 'DebugRedirects' ) ) {
$url = htmlspecialchars( $redirect );
- print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
+ print "<!DOCTYPE html>\n<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
print "<p>Location: <a href=\"$url\">$url</a></p>\n";
print "</body>\n</html>\n";
} else {
}
MWDebug::addModules( $this );
+ // Avoid PHP 7.1 warning of passing $this by reference
+ $outputPage = $this;
// Hook that allows last minute changes to the output page, e.g.
// adding of CSS or Javascript by extensions.
- Hooks::run( 'BeforePageDisplay', [ &$this, &$sk ] );
+ Hooks::run( 'BeforePageDisplay', [ &$outputPage, &$sk ] );
try {
$sk->outputPage();
) {
$displayReturnto = null;
- # Due to bug 32276, if a user does not have read permissions,
+ # Due to T34276, if a user does not have read permissions,
# $this->getTitle() will just give Special:Badtitle, which is
# not especially useful as a returnto parameter. Use the title
# from the request instead, if there was one.
$query['returntoquery'] = wfArrayToCgi( $returntoquery );
}
}
- $loginLink = Linker::linkKnown(
+ $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
+ $loginLink = $linkRenderer->makeKnownLink(
SpecialPage::getTitleFor( 'Userlogin' ),
- $this->msg( 'loginreqlink' )->escaped(),
+ $this->msg( 'loginreqlink' )->text(),
[],
$query
);
* @param array $options Options array to pass to Linker
*/
public function addReturnTo( $title, array $query = [], $text = null, $options = [] ) {
+ $linkRenderer = MediaWikiServices::getInstance()
+ ->getLinkRendererFactory()->createFromLegacyOptions( $options );
$link = $this->msg( 'returnto' )->rawParams(
- Linker::link( $title, $text, [], $query, $options ) )->escaped();
+ $linkRenderer->makeLink( $title, $text, [], $query ) )->escaped();
$this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
}
'site.styles',
'noscript',
'user.styles',
- 'user.cssprefs',
] );
$this->getSkin()->setupSkinUserCss( $this );
$bodyClasses[] = $userdir;
$bodyClasses[] = "sitedir-$sitedir";
+ $underline = $this->getUser()->getOption( 'underline' );
+ if ( $underline < 2 ) {
+ // The following classes can be used here:
+ // * mw-underline-always
+ // * mw-underline-never
+ $bodyClasses[] = 'mw-underline-' . ( $underline ? 'always' : 'never' );
+ }
+
if ( $this->getLanguage()->capitalizeAllNouns() ) {
# A <body> class is probably not the best way to do this . . .
$bodyClasses[] = 'capitalize-all-nouns';
}
}
+ if ( $this->limitReportJSData ) {
+ $chunks[] = ResourceLoader::makeInlineScript(
+ ResourceLoader::makeConfigSetScript(
+ [ 'wgPageParseReport' => $this->limitReportJSData ]
+ )
+ );
+ }
+
return self::combineWrappedStrings( $chunks );
}
$curRevisionId = 0;
$articleId = 0;
- $canonicalSpecialPageName = false; # bug 21115
+ $canonicalSpecialPageName = false; # T23115
$title = $this->getTitle();
$ns = $title->getNamespace();
$sk = $this->getSkin();
// Get the relevant title so that AJAX features can use the correct page name
- // when making API requests from certain special pages (bug 34972).
+ // when making API requests from certain special pages (T36972).
$relevantTitle = $sk->getRelevantTitle();
$relevantUser = $sk->getRelevantUser();
}
foreach ( $this->mMetatags as $tag ) {
- if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
+ if ( strncasecmp( $tag[0], 'http:', 5 ) === 0 ) {
$a = 'http-equiv';
$tag[0] = substr( $tag[0], 5 );
+ } elseif ( strncasecmp( $tag[0], 'og:', 3 ) === 0 ) {
+ $a = 'property';
} else {
$a = 'name';
}
protected function buildExemptModules() {
global $wgContLang;
- $resourceLoader = $this->getResourceLoader();
$chunks = [];
// Things that go after the ResourceLoaderDynamicStyles marker
$append = [];
*/
public static function transformResourcePath( Config $config, $path ) {
global $IP;
+
+ $localDir = $IP;
$remotePathPrefix = $config->get( 'ResourceBasePath' );
if ( $remotePathPrefix === '' ) {
// The configured base path is required to be empty string for
} else {
$remotePath = $remotePathPrefix;
}
- if ( strpos( $path, $remotePath ) !== 0 ) {
- // Path is outside wgResourceBasePath, ignore.
+ if ( strpos( $path, $remotePath ) !== 0 || substr( $path, 0, 2 ) === '//' ) {
+ // - Path is outside wgResourceBasePath, ignore.
+ // - Path is protocol-relative. Fixes T155310. Not supported by RelPath lib.
return $path;
}
+ // For files in resources, extensions/ or skins/, ResourceBasePath is preferred here.
+ // For other misc files in $IP, we'll fallback to that as well. There is, however, a fourth
+ // supported dir/path pair in the configuration (wgUploadDirectory, wgUploadPath)
+ // which is not expected to be in wgResourceBasePath on CDNs. (T155146)
+ $uploadPath = $config->get( 'UploadPath' );
+ if ( strpos( $path, $uploadPath ) === 0 ) {
+ $localDir = $config->get( 'UploadDirectory' );
+ $remotePathPrefix = $remotePath = $uploadPath;
+ }
+
$path = RelPath\getRelativePath( $path, $remotePath );
- return self::transformFilePath( $remotePathPrefix, $IP, $path );
+ return self::transformFilePath( $remotePathPrefix, $localDir, $path );
}
/**
* $wgOut->addWikiText( "<div class='error'>\n"
* . wfMessage( 'some-error' )->plain() . "\n</div>" );
*
- * The newline after the opening div is needed in some wikitext. See bug 19226.
+ * The newline after the opening div is needed in some wikitext. See T21226.
*
* @param string $wrap
*/