jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/392013 )
Change subject: Turn the topics navigation (bottom footer) into an editable MediaWiki: message ...................................................................... Turn the topics navigation (bottom footer) into an editable MediaWiki: message The syntax of [[MediaWiki:Webplatform-bottom-footer]] is similar to that of [[MediaWiki:Sidebar]]: * Page name|Displayed text * Another page|some-interface-message-name The skin class parseItem(), getMessageAsArray() and getBottomFooterLinks() methods originate from Wikia codebase and thus are licensed under GPLv2+. See https://github.com/Wikia/app/blob/dev/includes/wikia/GlobalFunctions.php for the current Wikia versions of these methods (well, the first two, anyway) as well as a full history of authors. These particular methods are copied from ShoutWiki's version of the Monaco skin and changed to non-static methods (to make use of RequestContext where appropriate) and old (long) array syntax converted to short array syntax. Change-Id: Iad79bd61f679d38ce9eb2b20023f3fd86835bff4 --- M SkinWebPlatform.class.php M WebPlatformTemplate.class.php M i18n/en.json M i18n/qqq.json 4 files changed, 119 insertions(+), 8 deletions(-) Approvals: jenkins-bot: Verified Isarra: Looks good to me, approved diff --git a/SkinWebPlatform.class.php b/SkinWebPlatform.class.php index 887052e..bf17b57 100644 --- a/SkinWebPlatform.class.php +++ b/SkinWebPlatform.class.php @@ -70,4 +70,108 @@ parent::setupSkinUserCss( $out ); $out->addModuleStyles( 'skins.webplatform.css' ); } + + /** + * Parses MediaWiki:Webplatform-bottom-footer + * @return array + */ + public function getBottomFooterLinks() { + $nodes = []; + $lines = $this->getMessageAsArray( 'Webplatform-bottom-footer' ); + if ( !$lines ) { + return $nodes; + } + + foreach ( $lines as $line ) { + $depth = strrpos( $line, '*' ); + if ( $depth === 0 ) { + $nodes[] = $this->parseItem( $line ); + } + } + + return $nodes; + } + + /** + * Parse one line from MediaWiki message to array with indexes 'text', 'href', + * 'org' and 'desc' + * + * @param string $line Name of a MediaWiki: message + * @return array + */ + public function parseItem( $line ) { + $href = false; + + // 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], '[]' ); + + // $line_temp now contains page name or URL as the 0th array element + // and the link description as the 1st array element + if ( count( $line_temp ) >= 2 && $line_temp[1] != '' ) { + $msgObj = $this->msg( $line_temp[0] ); + $link = ( $msgObj->isDisabled() ? $line_temp[0] : trim( $msgObj->inContentLanguage()->text() ) ); + $textObj = $this->msg( trim( $line_temp[1] ) ); + $line = ( !$textObj->isDisabled() ? $textObj->text() : trim( $line_temp[1] ) ); + } else { + $line = $link = trim( $line_temp[0] ); + } + + $descText = null; + if ( count( $line_temp ) > 2 && $line_temp[2] != '' ) { + $desc = $line_temp[2]; + $descObj = $this->msg( $desc ); + if ( $descObj->isDisabled() ) { + $descText = $desc; + } else { + $descText = $descObj->text(); + } + } + + $lineObj = $this->msg( $line ); + if ( $lineObj->isDisabled() ) { + $text = $line; + } else { + $text = $lineObj->text(); + } + + if ( $link != null ) { + if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) { + $href = $link; + } else { + $title = Title::newFromText( $link ); + if ( $title ) { + $title = $title->fixSpecialName(); + $href = $title->getLocalURL(); + } else { + $href = '#'; + } + } + } + + return [ + 'text' => $text, + 'href' => $href, + 'org' => $line_temp[0], + 'desc' => $descText + ]; + } + + /** + * @param string $messageKey Name of a MediaWiki: message + * @return array|null Array if $messageKey has been given, otherwise null + */ + public function getMessageAsArray( $messageKey ) { + $messageObj = $this->msg( $messageKey )->inContentLanguage(); + if ( !$messageObj->isDisabled() ) { + $lines = explode( "\n", $messageObj->text() ); + if ( count( $lines ) > 0 ) { + return $lines; + } + } + return null; + } } diff --git a/WebPlatformTemplate.class.php b/WebPlatformTemplate.class.php index 7a9148f..12005ba 100644 --- a/WebPlatformTemplate.class.php +++ b/WebPlatformTemplate.class.php @@ -181,18 +181,23 @@ } ?> + <?php + // Bottom navigation footer, if enabled + $links = $this->getSkin()->getBottomFooterLinks(); + if ( count( $links ) > 0 ) { + ?> <div class="topics-nav"> <ul> - <li><a href="http://docs.webplatform.org/wiki/beginners">Beginners</a></li> - <li><a href="http://docs.webplatform.org/wiki/concepts">Concepts</a></li> - <li><a href="http://docs.webplatform.org/wiki/html">HTML</a></li> - <li><a href="http://docs.webplatform.org/wiki/css">CSS</a></li> - <li><a href="http://docs.webplatform.org/wiki/concepts/accessibility">Accessibility</a></li> - <li><a href="http://docs.webplatform.org/wiki/javascript">JavaScript</a></li> - <li><a href="http://docs.webplatform.org/wiki/dom">DOM</a></li> - <li><a href="http://docs.webplatform.org/wiki/svg">SVG</a></li> + <?php + foreach ( $links as $key => $val ) { + echo $this->makeListItem( $key, $val ); + } + ?> </ul> </div> + <?php + } + ?> <div class="visualClear"></div> diff --git a/i18n/en.json b/i18n/en.json index a75e8be..b879a3e 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -4,5 +4,6 @@ "Samantha Nguyen" ] }, + "webplatform-bottom-footer": "", "webplatform-desc": "A skin featuring a stylized table of contents, built-in breadcrumbs, and a vibrant accent palette" } diff --git a/i18n/qqq.json b/i18n/qqq.json index bdcda1d..75caceb 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -4,5 +4,6 @@ "Samantha Nguyen" ] }, + "webplatform-bottom-footer": "The syntax for this message is similar to that of [[MediaWiki:Sidebar]], i.e. a bulleted list separated by newlines. If this message has any content, then that content will be used to render a list of links at the bottom of each page.", "webplatform-desc": "{{desc|name=WebPlatform|url=https://www.mediawiki.org/wiki/Skin:WebPlatform|what=skin}}" } -- To view, visit https://gerrit.wikimedia.org/r/392013 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iad79bd61f679d38ce9eb2b20023f3fd86835bff4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/skins/webplatform Gerrit-Branch: master Gerrit-Owner: Jack Phoenix <j...@countervandalism.net> Gerrit-Reviewer: Isarra <zhoris...@gmail.com> Gerrit-Reviewer: SamanthaNguyen <samanthanguyen1...@gmail.com> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits