var $mKeywords = array();
var $mLinktags = array();
+ var $mCanonicalUrl = false;
/// Additional stylesheets. Looks like this is for extensions. Might be replaced by resource loader.
var $mExtStyles = array();
*/
private $mRedirectedFrom = null;
+ /**
+ * Additional key => value data
+ */
+ private $mProperties = array();
+
/**
* Constructor for OutputPage. This should not be called directly.
* Instead a new RequestContext should be created and it will implicitly create
}
/**
- * Add a new \<link\> tag to the page header
+ * Add a new \<link\> tag to the page header.
+ *
+ * Note: use setCanonicalUrl() for rel=canonical.
*
* @param $linkarr Array: associative array of attributes.
*/
$this->addLink( $linkarr );
}
+ /**
+ * Set the URL to be used for the <link rel=canonical>. This should be used
+ * in preference to addLink(), to avoid duplicate link tags.
+ */
+ function setCanonicalUrl( $url ) {
+ $this->mCanonicalUrl = $url;
+ }
+
/**
* Get the value of the "rel" attribute for metadata links
*
protected function filterModules( $modules, $position = null, $type = ResourceLoaderModule::TYPE_COMBINED ) {
$resourceLoader = $this->getResourceLoader();
$filteredModules = array();
- foreach( $modules as $val ){
+ foreach( $modules as $val ) {
$module = $resourceLoader->getModule( $val );
if( $module instanceof ResourceLoaderModule
&& $module->getOrigin() <= $this->getAllowedModules( $type )
* @return Array of module names
*/
public function getModuleStyles( $filter = false, $position = null ) {
- return $this->getModules( $filter, $position, 'mModuleStyles' );
+ return $this->getModules( $filter, $position, 'mModuleStyles' );
}
/**
return $this->mArticleBodyOnly;
}
+ /**
+ * Set an additional output property
+ * @since 1.21
+ *
+ * @param string $name
+ * @param mixed $value
+ */
+ public function setProperty( $name, $value ) {
+ $this->mProperties[$name] = $value;
+ }
+
+ /**
+ * Get an additional output property
+ * @since 1.21
+ *
+ * @param $name
+ * @return mixed: Property value or null if not found
+ */
+ public function getProperty( $name ) {
+ if ( isset( $this->mProperties[$name] ) ) {
+ return $this->mProperties[$name];
+ } else {
+ return null;
+ }
+ }
+
/**
* checkLastModified tells the client to use the client-cached page if
* possible. If successful, the OutputPage is disabled so that
* @return Int ResourceLoaderModule ORIGIN_ class constant
*/
public function getAllowedModules( $type ) {
- if( $type == ResourceLoaderModule::TYPE_COMBINED ){
+ if( $type == ResourceLoaderModule::TYPE_COMBINED ) {
return min( array_values( $this->mAllowedModules ) );
} else {
return isset( $this->mAllowedModules[$type] )
* @param $level Int ResourceLoaderModule class constant
*/
public function reduceAllowedModules( $type, $level ) {
- $this->mAllowedModules[$type] = min( $this->getAllowedModules($type), $level );
+ $this->mAllowedModules[$type] = min( $this->getAllowedModules( $type ), $level );
}
/**
*/
public function addWikiText( $text, $linestart = true, $interface = true ) {
$title = $this->getTitle(); // Work arround E_STRICT
+ if ( !$title ) {
+ throw new MWException( 'Title is null' );
+ }
$this->addWikiTextTitle( $text, $title, $linestart, /*tidy*/false, $interface );
}
wfDebug( __METHOD__ . ": proxy caching with ESI; {$this->mLastModified} **\n", false );
# start with a shorter timeout for initial testing
# header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
- $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
+ $response->header( 'Surrogate-Control: max-age=' . $wgSquidMaxage . '+' . $this->mSquidMaxage . ', content="ESI/1.0"');
$response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
} else {
# We'll purge the proxy cache for anons explicitly, but require end user agents
wfDebug( __METHOD__ . ": local proxy caching; {$this->mLastModified} **\n", false );
# start with a shorter timeout for initial testing
# header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
- $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
+ $response->header( 'Cache-Control: s-maxage=' . $this->mSquidMaxage . ', must-revalidate, max-age=0' );
}
} else {
# We do want clients to cache if they can, but they *must* check for updates
$response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
$response->header( "Cache-Control: private, must-revalidate, max-age=0" );
}
- if($this->mLastModified) {
+ if( $this->mLastModified ) {
$response->header( "Last-Modified: {$this->mLastModified}" );
}
} else {
$this->prepareErrorPage( $title );
- if ( $msg instanceof Message ){
+ if ( $msg instanceof Message ) {
$this->addHTML( $msg->parseAsBlock() );
} else {
$this->addWikiMsgArray( $msg, $params );
unset( $returntoquery['title'] );
unset( $returntoquery['returnto'] );
unset( $returntoquery['returntoquery'] );
- $query['returntoquery'] = wfArrayToCGI( $returntoquery );
+ $query['returntoquery'] = wfArrayToCgi( $returntoquery );
}
}
$loginLink = Linker::linkKnown(
$pageLang = $this->getTitle()->getPageLanguage();
$params = array(
- 'id' => 'wpTextbox1',
+ 'id' => 'wpTextbox1',
'name' => 'wpTextbox1',
'cols' => $this->getUser()->getOption( 'cols' ),
'rows' => $this->getUser()->getOption( 'rows' ),
'mediawiki.page.startup',
'mediawiki.page.ready',
) );
- if ( $wgIncludeLegacyJavaScript ){
+ if ( $wgIncludeLegacyJavaScript ) {
$this->addModules( 'mediawiki.legacy.wikibits' );
}
}
}
- if( $group == 'noscript' ){
+ if( $group == 'noscript' ) {
$links .= Html::rawElement( 'noscript', array(), $link ) . "\n";
} else {
$links .= $link . "\n";
$tags = array();
+ $canonicalUrl = $this->mCanonicalUrl;
+
if ( $addContentType ) {
if ( $wgHtml5 ) {
# More succinct than <meta http-equiv=Content-Type>, has the
'http-equiv' => 'Content-Type',
'content' => "$wgMimeType; charset=UTF-8"
) );
- $tags['meta-content-style-type'] = Html::element( 'meta', array( // bug 15835
+ $tags['meta-content-style-type'] = Html::element( 'meta', array( // bug 15835
'http-equiv' => 'Content-Style-Type',
'content' => 'text/css'
) );
);
$tags['meta-keywords'] = Html::element( 'meta', array(
'name' => 'keywords',
- 'content' => preg_replace(
+ 'content' => preg_replace(
array_keys( $strip ),
array_values( $strip ),
implode( ',', $this->mKeywords )
);
}
} else {
- $tags['canonical'] = Html::element( 'link', array(
- 'rel' => 'canonical',
- 'href' => $this->getTitle()->getCanonicalUrl()
- ) );
+ $canonicalUrl = $this->getTitle()->getLocalURL();
}
}
}
}
}
}
+
+ # Canonical URL
+ global $wgEnableCanonicalServerLink;
+ if ( $wgEnableCanonicalServerLink ) {
+ if ( $canonicalUrl !== false ) {
+ $canonicalUrl = wfExpandUrl( $canonicalUrl, PROTO_CANONICAL );
+ } else {
+ $reqUrl = $this->getRequest()->getRequestURL();
+ $canonicalUrl = wfExpandUrl( $reqUrl, PROTO_CANONICAL );
+ }
+ }
+ if ( $canonicalUrl !== false ) {
+ $tags[] = Html::element( 'link', array(
+ 'rel' => 'canonical',
+ 'href' => $canonicalUrl
+ ) );
+ }
+
return $tags;
}
if ( $wgUseSiteCss ) {
$moduleStyles[] = 'site';
$moduleStyles[] = 'noscript';
- if( $this->getUser()->isLoggedIn() ){
+ if( $this->getUser()->isLoggedIn() ) {
$moduleStyles[] = 'user.groups';
}
}
* Transform "media" attribute based on request parameters
*
* @param $media String: current value of the "media" attribute
- * @return String: modified value of the "media" attribute
+ * @return String: modified value of the "media" attribute, or null to skip
+ * this stylesheet
*/
public static function transformCssMedia( $media ) {
global $wgRequest, $wgHandheldForIPhone;
+ // http://www.w3.org/TR/css3-mediaqueries/#syntax
+ $screenMediaQueryRegex = '/^(?:only\s+)?screen\b/i';
+
// Switch in on-screen display for media testing
$switches = array(
'printable' => 'print',
if( $wgRequest->getBool( $switch ) ) {
if( $media == $targetMedia ) {
$media = '';
- } elseif( $media == 'screen' ) {
- return null;
+ } elseif( preg_match( $screenMediaQueryRegex, $media ) === 1 ) {
+ // This regex will not attempt to understand a comma-separated media_query_list
+ //
+ // Example supported values for $media: 'screen', 'only screen', 'screen and (min-width: 982px)' ),
+ // Example NOT supported value for $media: '3d-glasses, screen, print and resolution > 90dpi'
+ //
+ // If it's a print request, we never want any kind of screen styesheets
+ // If it's a handheld request (currently the only other choice with a switch),
+ // we don't want simple 'screen' but we might want screen queries that
+ // have a max-width or something, so we'll pass all others on and let the
+ // client do the query.
+ if( $targetMedia == 'print' || $media == 'screen' ) {
+ return null;
+ }
}
}
}
'1.20'
);
}
- } else {
+ } else {
$args = array();
$name = $spec;
}