X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=259e28085174ca708113a8485ce5b821e1ccdb33;hb=7a79b017a03c78ddc0b8bf8762346957bef71936;hp=3bb217560a20c9b24a35d31cefc40bd3e4af02bf;hpb=566635008a4ccd11dfdaac1a6ef9ff428f75251c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 3bb217560a..259e280851 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -182,12 +182,14 @@ class OutputPage extends ContextSource { protected $mFeedLinksAppendQuery = null; - /** - * @var int - * The level of 'untrustworthiness' allowed for modules loaded on this page. + /** @var array + * What level of 'untrustworthiness' is allowed in CSS/JS modules loaded on this page? * @see ResourceLoaderModule::$origin + * ResourceLoaderModule::ORIGIN_ALL is assumed unless overridden; */ - protected $mAllowedModuleOrigin = ResourceLoaderModule::ORIGIN_ALL; + protected $mAllowedModules = array( + ResourceLoaderModule::TYPE_COMBINED => ResourceLoaderModule::ORIGIN_ALL, + ); /** @var bool Whether output is disabled. If this is true, the 'output' method will do nothing. */ protected $mDoNothing = false; @@ -364,6 +366,16 @@ class OutputPage extends ContextSource { array_push( $this->mMetatags, array( $name, $val ) ); } + /** + * Returns the current tags + * + * @since 1.25 + * @return array + */ + public function getMetaTags() { + return $this->mMetatags; + } + /** * Add a new \ tag to the page header. * @@ -375,6 +387,16 @@ class OutputPage extends ContextSource { array_push( $this->mLinktags, $linkarr ); } + /** + * Returns the current tags + * + * @since 1.25 + * @return array + */ + public function getLinkTags() { + return $this->mLinktags; + } + /** * Add a new \ with "rel" attribute set to "meta" * @@ -396,6 +418,17 @@ class OutputPage extends ContextSource { $this->mCanonicalUrl = $url; } + /** + * Returns the URL to be used for the if + * one is set. + * + * @since 1.25 + * @return bool|string + */ + public function getCanonicalUrl() { + return $this->mCanonicalUrl; + } + /** * Get the value of the "rel" attribute for metadata links * @@ -753,7 +786,7 @@ class OutputPage extends ContextSource { // bug 44570: the core page itself may not change, but resources might $modifiedTimes['sepoch'] = wfTimestamp( TS_MW, time() - $config->get( 'SquidMaxage' ) ); } - wfRunHooks( 'OutputPageCheckLastModified', array( &$modifiedTimes ) ); + Hooks::run( 'OutputPageCheckLastModified', array( &$modifiedTimes ) ); $maxModified = max( $modifiedTimes ); $this->mLastModified = wfTimestamp( TS_RFC2822, $maxModified ); @@ -1000,17 +1033,29 @@ class OutputPage extends ContextSource { } /** - * Add a subtitle containing a backlink to a page + * Build message object for a subtitle containing a backlink to a page * * @param Title $title Title to link to * @param array $query Array of additional parameters to include in the link + * @return Message + * @since 1.25 */ - public function addBacklinkSubtitle( Title $title, $query = array() ) { + public static function buildBacklinkSubtitle( Title $title, $query = array() ) { if ( $title->isRedirect() ) { $query['redirect'] = 'no'; } - $this->addSubtitle( $this->msg( 'backlinksubtitle' ) - ->rawParams( Linker::link( $title, null, array(), $query ) ) ); + return wfMessage( 'backlinksubtitle' ) + ->rawParams( Linker::link( $title, null, array(), $query ) ); + } + + /** + * Add a subtitle containing a backlink to a page + * + * @param Title $title Title to link to + * @param array $query Array of additional parameters to include in the link + */ + public function addBacklinkSubtitle( Title $title, $query = array() ) { + $this->addSubtitle( self::buildBacklinkSubtitle( $title, $query ) ); } /** @@ -1030,7 +1075,7 @@ class OutputPage extends ContextSource { } /** - * Set the page as printable, i.e. it'll be displayed with with all + * Set the page as printable, i.e. it'll be displayed with all * print styles included */ public function setPrintable() { @@ -1280,7 +1325,7 @@ class OutputPage extends ContextSource { } # Add the remaining categories to the skin - if ( wfRunHooks( + if ( Hooks::run( 'OutputPageMakeCategoryLinks', array( &$this, $categories, &$this->mCategoryLinks ) ) ) { @@ -1359,53 +1404,59 @@ class OutputPage extends ContextSource { } /** - * Restrict the page to loading modules bundled the software. + * Do not allow scripts which can be modified by wiki users to load on this page; + * only allow scripts bundled with, or generated by, the software. + * Site-wide styles are controlled by a config setting, since they can be + * used to create a custom skin/theme, but not user-specific ones. * - * Disallows the queue to contain any modules which can be modified by wiki - * users to load on this page. + * @todo this should be given a more accurate name */ public function disallowUserJs() { - $this->reduceAllowedModuleOrigin( ResourceLoaderModule::ORIGIN_CORE_INDIVIDUAL ); + $this->reduceAllowedModules( + ResourceLoaderModule::TYPE_SCRIPTS, + ResourceLoaderModule::ORIGIN_CORE_INDIVIDUAL + ); + + // Site-wide styles are controlled by a config setting, see bug 71621 + // for background on why. User styles are never allowed. + if ( $this->getConfig()->get( 'AllowSiteCSSOnRestrictedPages' ) ) { + $styleOrigin = ResourceLoaderModule::ORIGIN_USER_SITEWIDE; + } else { + $styleOrigin = ResourceLoaderModule::ORIGIN_CORE_INDIVIDUAL; + } + $this->reduceAllowedModules( + ResourceLoaderModule::TYPE_STYLES, + $styleOrigin + ); } /** - * Get the level of JavaScript / CSS untrustworthiness allowed on this page. - * + * Show what level of JavaScript / CSS untrustworthiness is allowed on this page * @see ResourceLoaderModule::$origin - * @param string $type Unused: Module origin allowance used to be fragmented by - * ResourceLoaderModule TYPE_ constants. + * @param string $type ResourceLoaderModule TYPE_ constant * @return int ResourceLoaderModule ORIGIN_ class constant */ - public function getAllowedModules( $type = null ) { - return $this->mAllowedModuleOrigin; + public function getAllowedModules( $type ) { + if ( $type == ResourceLoaderModule::TYPE_COMBINED ) { + return min( array_values( $this->mAllowedModules ) ); + } else { + return isset( $this->mAllowedModules[$type] ) + ? $this->mAllowedModules[$type] + : ResourceLoaderModule::ORIGIN_ALL; + } } /** * Set the highest level of CSS/JS untrustworthiness allowed * * @deprecated since 1.24 Raising level of allowed untrusted content is no longer supported. - * Use reduceAllowedModuleOrigin() instead. - * + * Use reduceAllowedModules() instead * @param string $type ResourceLoaderModule TYPE_ constant - * @param int $level ResourceLoaderModule ORIGIN_ constant + * @param int $level ResourceLoaderModule class constant */ public function setAllowedModules( $type, $level ) { wfDeprecated( __METHOD__, '1.24' ); - $this->reduceAllowedModuleOrigin( $level ); - } - - /** - * Limit the highest level of CSS/JS untrustworthiness allowed. - * - * @deprecated since 1.24 Module allowance is no longer fragmented by content type. - * Use reduceAllowedModuleOrigin() instead. - * - * @param string $type ResourceLoaderModule TYPE_ constant - * @param int $level ResourceLoaderModule ORIGIN_ class constant - */ - public function reduceAllowedModules( $type, $level ) { - wfDeprecated( __METHOD__, '1.24' ); - $this->reduceAllowedModuleOrigin( $level ); + $this->reduceAllowedModules( $type, $level ); } /** @@ -1414,10 +1465,11 @@ class OutputPage extends ContextSource { * If passed the same or a higher level than the current level of untrustworthiness set, the * level will remain unchanged. * + * @param string $type * @param int $level ResourceLoaderModule class constant */ - public function reduceAllowedModuleOrigin( $level ) { - $this->mAllowedModuleOrigin = min( $this->mAllowedModuleOrigin, $level ); + public function reduceAllowedModules( $type, $level ) { + $this->mAllowedModules[$type] = min( $this->getAllowedModules( $type ), $level ); } /** @@ -1574,6 +1626,7 @@ class OutputPage extends ContextSource { * @param string $text * @param bool $linestart Is this the start of a line? * @param bool $interface Is this text in the user interface language? + * @throws MWException */ public function addWikiText( $text, $linestart = true, $interface = true ) { $title = $this->getTitle(); // Work around E_STRICT @@ -1713,8 +1766,8 @@ class OutputPage extends ContextSource { // Link flags are ignored for now, but may in the future be // used to mark individual language links. $linkFlags = array(); - wfRunHooks( 'LanguageLinks', array( $this->getTitle(), &$this->mLanguageLinks, &$linkFlags ) ); - wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) ); + Hooks::run( 'LanguageLinks', array( $this->getTitle(), &$this->mLanguageLinks, &$linkFlags ) ); + Hooks::run( 'OutputPageParserOutput', array( &$this, $parserOutput ) ); } /** @@ -1743,7 +1796,7 @@ class OutputPage extends ContextSource { */ public function addParserOutputText( $parserOutput ) { $text = $parserOutput->getText(); - wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) ); + Hooks::run( 'OutputPageBeforeHTML', array( &$this, &$text ) ); $this->addHTML( $text ); } @@ -1868,7 +1921,7 @@ class OutputPage extends ContextSource { ), $config->get( 'CacheVaryCookies' ) ); - wfRunHooks( 'GetCacheVaryCookies', array( $this, &$cookies ) ); + Hooks::run( 'GetCacheVaryCookies', array( $this, &$cookies ) ); } return $cookies; } @@ -2131,7 +2184,7 @@ class OutputPage extends ContextSource { $redirect = $this->mRedirect; $code = $this->mRedirectCode; - if ( wfRunHooks( "BeforePageRedirect", array( $this, &$redirect, &$code ) ) ) { + if ( Hooks::run( "BeforePageRedirect", array( $this, &$redirect, &$code ) ) ) { if ( $code == '301' || $code == '303' ) { if ( !$config->get( 'DebugRedirects' ) ) { $message = HttpStatus::getMessage( $code ); @@ -2208,7 +2261,7 @@ class OutputPage extends ContextSource { // Hook that allows last minute changes to the output page, e.g. // adding of CSS or Javascript by extensions. - wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) ); + Hooks::run( 'BeforePageDisplay', array( &$this, &$sk ) ); wfProfileIn( 'Output-skin' ); $sk->outputPage(); @@ -2216,7 +2269,7 @@ class OutputPage extends ContextSource { } // This hook allows last minute changes to final overall output by modifying output buffer - wfRunHooks( 'AfterFinalPageOutput', array( $this ) ); + Hooks::run( 'AfterFinalPageOutput', array( $this ) ); $this->sendCacheControl(); @@ -2645,7 +2698,7 @@ class OutputPage extends ContextSource { // Allow skins and extensions to add body attributes they need $sk->addToBodyAttributes( $this, $bodyAttrs ); - wfRunHooks( 'OutputPageBodyAttributes', array( $this, $sk, &$bodyAttrs ) ); + Hooks::run( 'OutputPageBodyAttributes', array( $this, $sk, &$bodyAttrs ) ); $ret .= Html::openElement( 'body', $bodyAttrs ) . "\n"; @@ -3154,6 +3207,7 @@ class OutputPage extends ContextSource { 'wgMonthNames' => $lang->getMonthNamesArray(), 'wgMonthNamesShort' => $lang->getMonthAbbreviationsArray(), 'wgRelevantPageName' => $relevantTitle->getPrefixedDBkey(), + 'wgRelevantArticleId' => $relevantTitle->getArticleId(), ); if ( $user->isLoggedIn() ) { @@ -3194,7 +3248,7 @@ class OutputPage extends ContextSource { // Use the 'ResourceLoaderGetConfigVars' hook if the variable is not // page-dependant but site-wide (without state). // Alternatively, you may want to use OutputPage->addJsConfigVars() instead. - wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars, $this ) ); + Hooks::run( 'MakeGlobalVariablesScript', array( &$vars, $this ) ); // Merge in variables from addJsConfigVars last return array_merge( $vars, $this->getJsConfigVars() );