diff --git a/Refreshed.skin.php b/Refreshed.skin.php index 3e4e80e..66065ae 100644 --- a/Refreshed.skin.php +++ b/Refreshed.skin.php @@ -1,559 +1,706 @@ addMeta( 'viewport', 'width=device-width' ); $min = $this->getRequest()->getFuzzyBool( 'debug' ) ? '.src' : '.min'; // add jQuery Mobile touch events /*$out->addHeadItem( 'jquerymobiletouchevents', Html::element( 'script', array( 'src' => htmlspecialchars( $wgLocalStylePath ) . "/Refreshed/refreshed/jquery.mobile.custom{$min}.js", 'type' => 'text/javascript' ) ) );*/ // shouldn't this be loaded with ResourceLoader???/what is it? // prevent iOS from zooming out when the sidebar is opened $out->addHeadItem( 'viewportforios', Html::element( 'meta', array( 'name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0' ) ) ); // Inject webfont loader CSS file inline here so that it'll work even for IE11 // Conditional comments aren't supported in IE10+ so we have no way of loading // this just for IE, so better to have all font declarations here (and // maybe one day we'll rename the file to just "fontloader.css" or something) // Based on some quick-ish testing on 25 July 2016, it appears that font // declarations need to be loaded before they're used so that they work // under IE(11). // See https://phabricator.wikimedia.org/T134653 for more info. $out->addHeadItem( 'webfontfix', Html::element( 'link', array( 'href' => $wgLocalStylePath . '/Refreshed/refreshed/iefontfix.css', 'rel' => 'stylesheet' ) ) ); // Add JavaScript via ResourceLoader $out->addModules( 'skins.refreshed.js' ); } function setupSkinUserCss( OutputPage $out ) { - global $wgStylePath; - parent::setupSkinUserCss( $out ); // Add CSS via ResourceLoader $out->addModuleStyles( array( 'mediawiki.skinning.interface', 'mediawiki.skinning.content.externallinks', 'skins.refreshed' ) ); } } class RefreshedTemplate extends BaseTemplate { + /** + * Parses MediaWiki:Refreshed-wiki-dropdown. + * Forked from Games' parseSidebarMenu(), which in turn was forked from + * Monaco's parseSidebarMenu(), but none of these three methods are + * identical. + * + * @param string $messageKey Message name + * @return array + */ + private function parseDropDownMenu( $messageKey ) { + $lines = $this->getLines( $messageKey ); + $nodes = array(); + $i = 0; + + if ( is_array( $lines ) ) { + foreach ( $lines as $line ) { + # ignore empty lines + if ( strlen( $line ) == 0 ) { + continue; + } + + $node = self::parseItem( $line ); + for ( $x = $i; $x >= 0; $x-- ) { + if ( $x == 0 ) { + break; + } + } + + $nodes[$i + 1] = $node; + $i++; + } + } + + return $nodes; + } + + /** + * Parse one pipe-separated line from MediaWiki message to array with + * indexes 'logo', 'href' and 'wiki_name'. + * + * @param string $line Line (beginning with a *) from a MediaWiki: message + * @return array + */ + public static function parseItem( $line ) { + // trim spaces and asterisks from line and then split it to maximum three chunks + $line_temp = explode( '|', trim( $line, '* ' ), 3 ); + + // trim [ and ] from line to have just http://en.wikipedia.org instead + // of [http://en.wikipedia.org] for external links + $line_temp[0] = trim( $line_temp[0], '[]' ); + + if ( count( $line_temp ) >= 2 && $line_temp[1] != '' ) { + $logo = trim( $line_temp[1] ); + } else { + $logo = trim( $line_temp[0] ); + } + + if ( + isset( $line_temp[2] ) && + preg_match( '/^(?:' . wfUrlProtocols() . ')/', $line_temp[2] ) + ) + { + $href = $line_temp[2]; + } else { + $href = '#'; + } + + return array( + 'logo' => $logo, + 'href' => $href, + 'wiki_name' => $line_temp[0] + ); + } + + /** + * @param string $messageKey Name of a MediaWiki: message + * @return array|null Array if $messageKey has been given, otherwise null + */ + private function getMessageAsArray( $messageKey ) { + $messageObj = $this->getSkin()->msg( $messageKey )->inContentLanguage(); + if ( !$messageObj->isDisabled() ) { + $lines = explode( "\n", $messageObj->text() ); + if ( count( $lines ) > 0 ) { + return $lines; + } + } + return null; + } + + /** + * @param string $messageKey Name of a MediaWiki: message + * @return array + */ + private function getLines( $messageKey ) { + $title = Title::newFromText( $messageKey, NS_MEDIAWIKI ); + $revision = Revision::newFromTitle( $title ); + if ( is_object( $revision ) ) { + if ( trim( $revision->getText() ) != '' ) { + $temp = $this->getMessageAsArray( $messageKey ); + if ( count( $temp ) > 0 ) { + wfDebugLog( 'Refreshed', sprintf( 'Get LOCAL %s, which contains %s lines', $messageKey, count( $temp ) ) ); + $lines = $temp; + } + } + } + + if ( empty( $lines ) ) { + $lines = $this->getMessageAsArray( $messageKey ); + wfDebugLog( 'Refreshed', sprintf( 'Get %s, which contains %s lines', $messageKey, count( $lines ) ) ); + } + + return $lines; + } public function execute() { - global $wgStylePath, $wgRefreshedHeader, $wgMemc; + global $wgMemc; $skin = $this->getSkin(); + $config = $skin->getConfig(); $user = $skin->getUser(); // Title processing $titleBase = $skin->getTitle(); $title = $titleBase->getSubjectPage(); $titleNamespace = $titleBase->getNamespace(); - $refreshedImagePath = "$wgStylePath/Refreshed/refreshed/images"; - $key = wfMemcKey( 'refreshed', 'header' ); $headerNav = $wgMemc->get( $key ); if ( !$headerNav ) { $headerNav = array(); $skin->addToSidebar( $headerNav, 'refreshed-navigation' ); - $wgMemc->set( $key, $headerNav , 60 * 60 * 24 ); // 24 hours + $wgMemc->set( $key, $headerNav, 60 * 60 * 24 ); // 24 hours + } + + $dropdownCacheKey = wfMemcKey( 'refreshed', 'dropdownmenu' ); + $dropdownNav = $wgMemc->get( $dropdownCacheKey ); + if ( !$dropdownNav ) { + $dropdownNav = $this->parseDropDownMenu( 'Refreshed-wiki-dropdown' ); + $wgMemc->set( $dropdownCacheKey, $dropdownNav, 60 * 60 * 24 ); // 24 hours + } + + $thisWikiURLMsg = $skin->msg( 'refreshed-this-wiki-url' ); + if ( $thisWikiURLMsg->isDisabled() ) { + $thisWikiURL = htmlspecialchars( Title::newMainPage()->getFullURL() ); + } else { + $thisWikiURL = $skin->msg( 'refreshed-this-wiki-url' )->escaped(); + } + $thisWikiWordmarkLogo = $skin->msg( 'refreshed-this-wiki-wordmark' )->escaped(); + $logoImgElement = Html::element( 'img', array( + 'src' => $thisWikiWordmarkLogo, + 'alt' => $config->get( 'Sitename' ), + 'width' => 144, + 'height' => 30 + ) ); + $thisWikiMobileLogo = $skin->msg( 'refreshed-this-wiki-mobile-logo' ); + $thisWikiMobileLogoImgElement = ''; + if ( !$thisWikiMobileLogo->isDisabled() ) { + $thisWikiMobileLogoImgElement = Html::element( 'img', array( + 'src' => $thisWikiMobileLogo->escaped(), + 'alt' => $config->get( 'Sitename' ), + // 'width' => ???, + // 'height' => ??? + ) ); } // Output the tag and whatnot $this->html( 'headelement' ); ?>
- +
- +
isDisabled() ) { // if a mobile logo has been defined ?>
- +
getId(), 'l' ); $avatarImage = $avatar->getAvatarURL( array( 'width' => 30, 'class' => 'avatar' ) ); ?> getName() ?> data['loggedin'] ) { // if no SocialProfile but user is logged in ?> getName() ?> getMsg( 'login' )->text() ?>
$sub ) { ?>
data['sitenotice'] ) { ?>
html( 'newtalk' ) ?>

html( 'title' ) ?>

msg( 'tagline' ) ?>
data['subtitle'] || $this->data['undelete'] ) { ?>
html( 'userlangattributes' ) ?>>html( 'subtitle' ) ?>html( 'undelete' ) ?>
getIndicators(); } ?>
data['content_actions'] ); $pageTab = key( $this->data['content_actions'] ); $isEditing = in_array( $skin->getRequest()->getText( 'action' ), array( 'edit', 'submit' ) ); // determining how many tools need to be generated $totalSmallToolsToGenerate = 0; $listOfToolsToGenerate = array( 'wikiglyph wikiglyph-speech-bubbles' => 'ca-talk', 'wikiglyph wikiglyph-pencil-lock-full' => 'ca-viewsource', 'wikiglyph wikiglyph-pencil' => 'ca-edit', 'wikiglyph wikiglyph-clock' => 'ca-history', 'wikiglyph wikiglyph-trash' => 'ca-delete', 'wikiglyph wikiglyph-move' => 'ca-move', 'wikiglyph wikiglyph-lock' => 'ca-protect', 'wikiglyph wikiglyph-unlock' => 'ca-unprotect', 'wikiglyph wikiglyph-star' => 'ca-watch', 'wikiglyph wikiglyph-unstar' => 'ca-unwatch' ); foreach ( $this->data['content_actions'] as $action ) { if ( in_array( $action['id'], $listOfToolsToGenerate ) ) { // if the icon in question is one of the listed ones $totalSmallToolsToGenerate++; } } if ( MWNamespace::isTalk( $titleNamespace ) ) { // if talk namespace $totalSmallToolsToGenerate--; // remove a tool (the talk page tool) if the user is on a talk page } if ( $totalSmallToolsToGenerate > 0 && !$isEditing ) { // if there's more than zero tools to be generated and the user isn't editing a page ?>
data['content_actions'] as $action ) { if ( $smallToolBeingTested > $amountOfSmallToolsToSkipInFront ) { // if we're not supposed to skip this tool (e.g. if we're supposed to skip the first 2 tools and we're at the 3rd tool, then the boolean is true) // @todo Maybe write a custom makeLink()-like function for generating this code? if ( in_array( $action['id'], $listOfToolsToGenerate ) ) { // if the icon being rendered is one of the listed ones (if we're supposed to generate this tool) ?>
3 ) { ?>
html( 'bodytext' ) ?>
html( 'catlinks' ); if ( $this->data['dataAfterContent'] ) { $this->html( 'dataAfterContent' ); } ?>
printTrail(); echo Html::closeElement( 'body' ); echo Html::closeElement( 'html' ); } } diff --git a/i18n/en.json b/i18n/en.json index 9264548..0e1d115 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -1,7 +1,11 @@ { "@metadata": { "authors": [] }, "refreshed-advert": "Advertisement", - "refreshed-navigation": "-" + "refreshed-navigation": "-", + "refreshed-this-wiki-mobile-logo": "-", + "refreshed-this-wiki-url": "-", + "refreshed-this-wiki-wordmark": "", + "refreshed-wiki-dropdown": "" } diff --git a/i18n/qqq.json b/i18n/qqq.json index 762a00f..cdf0929 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -1,5 +1,9 @@ { "@metadata": [], "refreshed-advert": "The header shown above the footer advert", - "refreshed-navigation": "Navigational menus in Refreshed's header, following a similar format to MediaWiki:Sidebar" + "refreshed-navigation": "Navigational menus in Refreshed's header, following a similar format to MediaWiki:Sidebar", + "refreshed-this-wiki-mobile-logo": "URL to the mobile wordmark logo, if any", + "refreshed-this-wiki-url": "URL to the wiki's main page or some other page where clicking the wiki wordmark should take the user to; if not customized, which is the default, the user is taken to the wiki's main page", + "refreshed-this-wiki-wordmark": "URL to the wiki's wordmark logo (which should be 144x30px), because the Refreshed skin does not use [[mediawikiwiki:Manual:$wgLogo|$wgLogo]]", + "refreshed-wiki-dropdown": "Message for configuring the wiki dropdown menu.\nThe syntax is:* Name of the wiki|URL to the wiki's logo|Wiki's URL\nEntries are separated by newlines.\nFor example:\n* English Wikipedia|http://www.example.com/images/wikipedia-wordmark-logo.svg|https://en.wikipedia.org\n* Brickipedia|http://images.brickimedia.org/b/b4/Brickipedia.svg|http://en.brickimedia.org/" } diff --git a/skin.json b/skin.json index f9a2932..61a52f5 100644 --- a/skin.json +++ b/skin.json @@ -1,84 +1,77 @@ { "name": "Refreshed", "version": "3.1.2", "author": [ "Adam Carter", "George Barnick", "MtMNC", "ShermanTheMythran", "Jack Phoenix", "Drew1200", "SirComputer", "Seaside98", "Cody Nguyen", "Lewis Cawte" ], "url": "https://www.mediawiki.org/wiki/Skin:Refreshed", "description": "A clean, modern MediaWiki skin with extensive CSS customisability", "license-name": "GPL-2.0+", "type": "skin", "ValidSkinNames": { "refreshed": "Refreshed" }, "MessagesDirs": { "SkinRefreshed": [ "i18n" ] }, "AutoloadClasses": { "SkinRefreshed": "Refreshed.skin.php", "RefreshedTemplate": "Refreshed.skin.php" }, - "config": { - "RefreshedHeader": { - "img": "\"\"", - "url": "http://meta.brickimedia.org/wiki/Main_Page", - "dropdown": {} - } - }, "ResourceFileModulePaths": { "localBasePath": "", "remoteSkinPath": "Refreshed" }, "ResourceModules": { "skins.refreshed": { "styles": { "refreshed/wikifont/wikiglyphs.css": { "media": "screen" }, "refreshed/main.css": { "media": "screen" }, "refreshed/small.css": { "media": "(max-width: 600px)" }, "refreshed/medium.css": { "media": "(min-width: 601px) and (max-width: 1000px)" }, "refreshed/big.css": { "media": "(min-width: 1001px)" }, "refreshed/print.css": { "media": "print" } }, "position": "top" }, "skins.refreshed.js": { "scripts": [ "refreshed/refreshed.js" ], "dependencies": [ "mediawiki.api", "mediawiki.util" ], "position": "bottom" } }, "ResourceModuleSkinStyles": { "refreshed": { "+mediawiki.special.preferences": "refreshed/preferences.css" } }, "manifest_version": 1 }