X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSkin.php;h=f2939d48d6b3517707a6e77471d01bf8d5040d20;hb=75086e9f35ad0fb8edded9111b3e76f45675b9d5;hp=17da161abe3bfbeba3798e057238d34cb6c5c1ef;hpb=b128fd1b0536e1553a3a2254ecdc23e986ab5361;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Skin.php b/includes/Skin.php index 17da161abe..f2939d48d6 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -3,8 +3,9 @@ * @defgroup Skins Skins */ -if ( ! defined( 'MEDIAWIKI' ) ) +if ( !defined( 'MEDIAWIKI' ) ) { die( 1 ); +} /** * The main skin class that provide methods and properties for all other skins. @@ -24,36 +25,41 @@ class Skin extends Linker { /**#@-*/ protected $mRevisionId; // The revision ID we're looking at, null if not applicable. protected $skinname = 'standard'; - // @fixme Should be protected :-\ + // @todo Fixme: should be protected :-\ var $mTitle = null; /** Constructor, call parent constructor */ - function Skin() { parent::__construct(); } + function __construct() { + parent::__construct(); + } /** * Fetch the set of available skins. * @return array of strings - * @static */ static function getSkinNames() { global $wgValidSkinNames; static $skinsInitialised = false; + if ( !$skinsInitialised ) { # Get a list of available skins # Build using the regular expression '^(.*).php$' # Array keys are all lower case, array value keep the case used by filename # wfProfileIn( __METHOD__ . '-init' ); + global $wgStyleDirectory; + $skinDir = dir( $wgStyleDirectory ); # while code from www.php.net - while( false !== ( $file = $skinDir->read() ) ) { + while ( false !== ( $file = $skinDir->read() ) ) { // Skip non-PHP files, hidden files, and '.dep' includes $matches = array(); - if( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) { + + if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) { $aSkin = $matches[1]; - $wgValidSkinNames[strtolower($aSkin)] = $aSkin; + $wgValidSkinNames[strtolower( $aSkin )] = $aSkin; } } $skinDir->close(); @@ -71,10 +77,13 @@ class Skin extends Linker { */ public static function getUsableSkins() { global $wgSkipSkins; + $usableSkins = self::getSkinNames(); + foreach ( $wgSkipSkins as $skip ) { unset( $usableSkins[$skip] ); } + return $usableSkins; } @@ -82,21 +91,21 @@ class Skin extends Linker { * Normalize a skin preference value to a form that can be loaded. * If a skin can't be found, it will fall back to the configured * default (or the old 'Classic' skin if that's broken). - * @param string $key + * @param $key String: 'monobook', 'standard', etc. * @return string - * @static */ static function normalizeKey( $key ) { global $wgDefaultSkin; + $skinNames = Skin::getSkinNames(); - if( $key == '' ) { + if ( $key == '' ) { // Don't return the default immediately; // in a misconfiguration we need to fall back. $key = $wgDefaultSkin; } - if( isset( $skinNames[$key] ) ) { + if ( isset( $skinNames[$key] ) ) { return $key; } @@ -105,24 +114,26 @@ class Skin extends Linker { $fallback = array( 0 => $wgDefaultSkin, 1 => 'nostalgia', - 2 => 'cologneblue' ); + 2 => 'cologneblue' + ); - if( isset( $fallback[$key] ) ){ + if ( isset( $fallback[$key] ) ) { $key = $fallback[$key]; } - if( isset( $skinNames[$key] ) ) { + if ( isset( $skinNames[$key] ) ) { return $key; + } else if ( isset( $skinNames[$wgDefaultSkin] ) ) { + return $wgDefaultSkin; } else { - return 'monobook'; + return 'vector'; } } /** * Factory method for loading a skin of a given type - * @param string $key 'monobook', 'standard', etc + * @param $key String: 'monobook', 'standard', etc. * @return Skin - * @static */ static function &newFromKey( $key ) { global $wgStyleDirectory; @@ -131,24 +142,27 @@ class Skin extends Linker { $skinNames = Skin::getSkinNames(); $skinName = $skinNames[$key]; - $className = 'Skin'.ucfirst($key); + $className = 'Skin' . ucfirst( $key ); # Grab the skin class and initialise it. if ( !class_exists( $className ) ) { // Preload base classes to work around APC/PHP5 bug $deps = "{$wgStyleDirectory}/{$skinName}.deps.php"; - if( file_exists( $deps ) ) include_once( $deps ); + + if ( file_exists( $deps ) ) { + include_once( $deps ); + } require_once( "{$wgStyleDirectory}/{$skinName}.php" ); # Check if we got if not failback to default skin - if( !class_exists( $className ) ) { + if ( !class_exists( $className ) ) { # DO NOT die if the class isn't found. This breaks maintenance # scripts and can cause a user account to be unrecoverable # except by SQL manipulation if a previously valid skin name # is no longer valid. wfDebug( "Skin class does not exist: $className\n" ); - $className = 'SkinMonobook'; - require_once( "{$wgStyleDirectory}/MonoBook.php" ); + $className = 'SkinVector'; + require_once( "{$wgStyleDirectory}/Vector.php" ); } } $skin = new $className; @@ -168,25 +182,29 @@ class Skin extends Linker { function qbSetting() { global $wgOut, $wgUser; - if ( $wgOut->isQuickbarSuppressed() ) { return 0; } + if ( $wgOut->isQuickbarSuppressed() ) { + return 0; + } + $q = $wgUser->getOption( 'quickbar', 0 ); + return $q; } function initPage( OutputPage $out ) { - global $wgFavicon, $wgAppleTouchIcon; + global $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI; wfProfileIn( __METHOD__ ); # Generally the order of the favicon and apple-touch-icon links # should not matter, but Konqueror (3.5.9 at least) incorrectly - # uses whichever one appears later in the HTML source. Make sure + # uses whichever one appears later in the HTML source. Make sure # apple-touch-icon is specified first to avoid this. - if( false !== $wgAppleTouchIcon ) { + if ( false !== $wgAppleTouchIcon ) { $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) ); } - if( false !== $wgFavicon ) { + if ( false !== $wgFavicon ) { $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) ); } @@ -196,7 +214,19 @@ class Skin extends Linker { 'type' => 'application/opensearchdescription+xml', 'href' => wfScript( 'opensearch_desc' ), 'title' => wfMsgForContent( 'opensearch-desc' ), - )); + ) ); + + if ( $wgEnableAPI ) { + # Real Simple Discovery link, provides auto-discovery information + # for the MediaWiki API (and potentially additional custom API + # support such as WordPress or Twitter-compatible APIs for a + # blogging extension, etc) + $out->addLink( array( + 'rel' => 'EditURI', + 'type' => 'application/rsd+xml', + 'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ) ), + ) ); + } $this->addMetadataLinks( $out ); @@ -226,23 +256,41 @@ class Skin extends Linker { } $lb = new LinkBatch( $titles ); + $lb->setCaller( __METHOD__ ); $lb->execute(); } + /** + * Adds metadata links below to the HTML output. + *
    + *
  1. Creative Commons + *
    See http://wiki.creativecommons.org/Extend_Metadata. + *
  2. + *
  3. Dublin Core
  4. + *
  5. Use hreflang to specify canonical and alternate links + *
    See http://www.google.com/support/webmasters/bin/answer.py?answer=189077 + *
  6. + *
  7. Copyright
  8. + *
      + * + * @param $out Object: instance of OutputPage + */ function addMetadataLinks( OutputPage $out ) { global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf; + global $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang; global $wgRightsPage, $wgRightsUrl; - if( $out->isArticleRelated() ) { + if ( $out->isArticleRelated() ) { # note: buggy CC software only reads first "meta" link - if( $wgEnableCreativeCommonsRdf ) { + if ( $wgEnableCreativeCommonsRdf ) { $out->addMetadataLink( array( 'title' => 'Creative Commons', 'type' => 'application/rdf+xml', 'href' => $this->mTitle->getLocalURL( 'action=creativecommons' ) ) ); } - if( $wgEnableDublinCoreRdf ) { + + if ( $wgEnableDublinCoreRdf ) { $out->addMetadataLink( array( 'title' => 'Dublin Core', 'type' => 'application/rdf+xml', @@ -250,17 +298,43 @@ class Skin extends Linker { ); } } + + if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks + && $wgContLang->hasVariants() ) { + + $urlvar = $wgContLang->getURLVariant(); + + if ( !$urlvar ) { + $variants = $wgContLang->getVariants(); + foreach ( $variants as $_v ) { + $out->addLink( array( + 'rel' => 'alternate', + 'hreflang' => $_v, + 'href' => $this->mTitle->getLocalURL( '', $_v ) ) + ); + } + } else { + $out->addLink( array( + 'rel' => 'canonical', + 'href' => $this->mTitle->getFullURL() ) + ); + } + } + $copyright = ''; - if( $wgRightsPage ) { + if ( $wgRightsPage ) { $copy = Title::newFromText( $wgRightsPage ); - if( $copy ) { + + if ( $copy ) { $copyright = $copy->getLocalURL(); } } - if( !$copyright && $wgRightsUrl ) { + + if ( !$copyright && $wgRightsUrl ) { $copyright = $wgRightsUrl; } - if( $copyright ) { + + if ( $copyright ) { $out->addLink( array( 'rel' => 'copyright', 'href' => $copyright ) @@ -271,7 +345,7 @@ class Skin extends Linker { /** * Set some local variables */ - protected function setMembers(){ + protected function setMembers() { global $wgUser; $this->mUser = $wgUser; $this->userpage = $wgUser->getUserPage()->getPrefixedText(); @@ -280,7 +354,7 @@ class Skin extends Linker { /** * Set the title - * @param Title $t The title to use + * @param $t Title object to use */ public function setTitle( $t ) { $this->mTitle = $t; @@ -291,6 +365,10 @@ class Skin extends Linker { return $this->mTitle; } + /** + * Outputs the HTML generated by other functions. + * @param $out Object: instance of OutputPage + */ function outputPage( OutputPage $out ) { global $wgDebugComments; wfProfileIn( __METHOD__ ); @@ -303,12 +381,6 @@ class Skin extends Linker { $out->out( $out->headElement( $this ) ); - $out->out( "\ngetBodyOptions(); - foreach ( $ops as $name => $val ) { - $out->out( " $name='$val'" ); - } - $out->out( ">\n" ); if ( $wgDebugComments ) { $out->out( "\n" ); @@ -322,7 +394,7 @@ class Skin extends Linker { $out->out( $afterContent ); - $out->out( $this->bottomScripts() ); + $out->out( $this->bottomScripts( $out ) ); $out->out( wfReportTime() ); @@ -331,67 +403,30 @@ class Skin extends Linker { } static function makeVariablesScript( $data ) { - if( $data ) { - $r = array(); - foreach ( $data as $name => $value ) { - $encValue = Xml::encodeJsVar( $value ); - $r[] = "$name=$encValue"; - } - $js = 'var ' . implode( ",\n", $r ) . ';'; - return Html::inlineScript( "\n$js\n" ); + if ( $data ) { + return Html::inlineScript( + ResourceLoader::makeLoaderConditionalScript( ResourceLoader::makeConfigSetScript( $data ) ) + ); } else { return ''; - } + } } /** * Make a