X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=b0ee8158d25f5feefec079a32fcb348fcb50d5e5;hb=5397c668ab2e4a3cf5a7a9fc0202d601d1eedc0c;hp=436e2f9e42d403b1476e6cba041cbcfb4c0a17e2;hpb=346b2ff04695f9482d17afa19addc4fa827081eb;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 436e2f9e42..b0ee8158d2 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -248,6 +248,11 @@ class OutputPage extends ContextSource { */ 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 @@ -442,7 +447,7 @@ class OutputPage extends ContextSource { 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 ) @@ -512,7 +517,7 @@ class OutputPage extends ContextSource { * @return Array of module names */ public function getModuleStyles( $filter = false, $position = null ) { - return $this->getModules( $filter, $position, 'mModuleStyles' ); + return $this->getModules( $filter, $position, 'mModuleStyles' ); } /** @@ -620,6 +625,32 @@ class OutputPage extends ContextSource { 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 @@ -1251,7 +1282,7 @@ class OutputPage extends ContextSource { * @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] ) @@ -1275,7 +1306,7 @@ class OutputPage extends ContextSource { * @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 ); } /** @@ -1435,6 +1466,9 @@ class OutputPage extends ContextSource { */ 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 ); } @@ -1870,7 +1904,7 @@ class OutputPage extends ContextSource { 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 @@ -1880,7 +1914,7 @@ class OutputPage extends ContextSource { 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 @@ -1889,7 +1923,7 @@ class OutputPage extends ContextSource { $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 { @@ -2068,7 +2102,7 @@ class OutputPage extends ContextSource { $this->prepareErrorPage( $title ); - if ( $msg instanceof Message ){ + if ( $msg instanceof Message ) { $this->addHTML( $msg->parseAsBlock() ); } else { $this->addWikiMsgArray( $msg, $params ); @@ -2125,7 +2159,7 @@ class OutputPage extends ContextSource { unset( $returntoquery['title'] ); unset( $returntoquery['returnto'] ); unset( $returntoquery['returntoquery'] ); - $query['returntoquery'] = wfArrayToCGI( $returntoquery ); + $query['returntoquery'] = wfArrayToCgi( $returntoquery ); } } $loginLink = Linker::linkKnown( @@ -2269,7 +2303,7 @@ class OutputPage extends ContextSource { $pageLang = $this->getTitle()->getPageLanguage(); $params = array( - 'id' => 'wpTextbox1', + 'id' => 'wpTextbox1', 'name' => 'wpTextbox1', 'cols' => $this->getUser()->getOption( 'cols' ), 'rows' => $this->getUser()->getOption( 'rows' ), @@ -2480,7 +2514,7 @@ $templates 'mediawiki.page.startup', 'mediawiki.page.ready', ) ); - if ( $wgIncludeLegacyJavaScript ){ + if ( $wgIncludeLegacyJavaScript ) { $this->addModules( 'mediawiki.legacy.wikibits' ); } @@ -2708,7 +2742,7 @@ $templates } } - if( $group == 'noscript' ){ + if( $group == 'noscript' ) { $links .= Html::rawElement( 'noscript', array(), $link ) . "\n"; } else { $links .= $link . "\n"; @@ -3063,7 +3097,7 @@ $templates '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' ) ); @@ -3092,7 +3126,7 @@ $templates ); $tags['meta-keywords'] = Html::element( 'meta', array( 'name' => 'keywords', - 'content' => preg_replace( + 'content' => preg_replace( array_keys( $strip ), array_values( $strip ), implode( ',', $this->mKeywords ) @@ -3376,7 +3410,7 @@ $templates if ( $wgUseSiteCss ) { $moduleStyles[] = 'site'; $moduleStyles[] = 'noscript'; - if( $this->getUser()->isLoggedIn() ){ + if( $this->getUser()->isLoggedIn() ) { $moduleStyles[] = 'user.groups'; } } @@ -3512,11 +3546,15 @@ $templates * 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', @@ -3526,8 +3564,20 @@ $templates 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; + } } } } @@ -3610,7 +3660,7 @@ $templates '1.20' ); } - } else { + } else { $args = array(); $name = $spec; }