Skip to content

Commit

Permalink
feat(core): ✨ add last modified to sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair3149 committed May 8, 2024
1 parent 4f7e3a4 commit 89b5ff1
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 21 deletions.
5 changes: 1 addition & 4 deletions includes/Partials/PageTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
use MediaWiki\MediaWikiServices;

final class PageTools extends Partial {
/** @var null|array for caching purposes */
private $languages;

/**
* Get page-related tools template data
* TODO: Break this down and clean up when 1.39
Expand Down Expand Up @@ -83,7 +80,7 @@ public function getPageToolsData( $parentData ): array {
* till Desktop Improvements
*
* @param array sidebarData
* @return bool
* @return array
*/
private function getArticleToolsData( $sidebarData ) {
$data = [
Expand Down
20 changes: 6 additions & 14 deletions includes/Partials/Partial.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,30 @@

namespace MediaWiki\Skins\Citizen\Partials;

use Language;
use MediaWiki\Skins\Citizen\GetConfigTrait;
use MediaWiki\Skins\Citizen\SkinCitizen;
use MediaWiki\Title\Title;
use OutputPage;

/**
* The base class for all skin partials
* TODO: Use SkinComponentRegistryContext
*/
abstract class Partial {

use GetConfigTrait;

/**
* @var SkinCitizen
*/
/** @var SkinCitizen */
protected $skin;

/**
* Needed for trait
*
* @var OutputPage
*/
/** @var OutputPage */
protected $out;

/**
* @var Title
*/
/** @var Title */
protected $title;

/**
* @var User
*/
/** @var User */
protected $user;

/**
Expand Down
104 changes: 104 additions & 0 deletions includes/Partials/Sidebar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* Citizen - A responsive skin developed for the Star Citizen Wiki
*
* This file is part of Citizen.
*
* Citizen is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Citizen is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Citizen. If not, see <https://www.gnu.org/licenses/>.
*
* @file
* @ingroup Skins
*/

declare( strict_types=1 );

namespace MediaWiki\Skins\Citizen\Partials;

/**
* Based on SkinComponentLastModified.php in MediaWiki core
* TODO: Use core instead when update to MW 1.43
*/
final class Sidebar extends Partial {
/** @var Language */
private $language;

/** @var string|null|false */
private $timestamp;

/**
* Get sidebar template data
*
* @param array $parentData
* @return array html
*/
public function getSidebarData( $parentData ): array {
$data = [
'data-sidebar-lastmod' => $this->getLastModData()
];

return $data;
}

/**
* Build last modified template data
* TODO: Use relative time instead (#700)
*
* @return array|null
*/
private function getLastModData() {
$skin = $this->skin;
$out = $this->out;
$user = $this->user;
$title = $this->title;
$language = $skin->getLanguage();
$timestamp = $out->getRevisionTimestamp();

if ( $timestamp ) {
$d = $language->userDate( $timestamp, $user );
$t = $language->userTime( $timestamp, $user );
$s = ' ' . $skin->msg( 'lastmodifiedat', $d, $t )->parse();
} else {
return;
}

$items = [
'id' => 'lm-time',
'class' => 'mw-list-item',
'array-links' => [
'array-attributes' => [
[
'key' => 'href',
'value' => $title->getLocalURL( [ 'diff' => '' ] )
],
[
'key' => 'title',
'value' => $s
],
[
'key' => 'data-timestamp',
'value' => wfTimestamp( TS_UNIX, $timestamp )
]
],
'icon' => 'history',
'text' => sprintf( '%s - %s', $d, $t )
]
];

return [
'id' => 'citizen-sidebar-lastmod',
'label' => $skin->msg( 'citizen-page-info-lastmod' ),
'array-list-items' => $items
];
}
}
3 changes: 3 additions & 0 deletions includes/SkinCitizen.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use MediaWiki\Skins\Citizen\Partials\Metadata;
use MediaWiki\Skins\Citizen\Partials\PageTitle;
use MediaWiki\Skins\Citizen\Partials\PageTools;
use MediaWiki\Skins\Citizen\Partials\Sidebar;
use MediaWiki\Skins\Citizen\Partials\Tagline;
use MediaWiki\Skins\Citizen\Partials\Theme;
use SkinMustache;
Expand Down Expand Up @@ -77,6 +78,7 @@ public function getTemplateData(): array {
$pageTitle = new PageTitle( $this );
$tagline = new Tagline( $this );
$bodycontent = new BodyContent( $this );
$sidebar = new Sidebar( $this );
$footer = new Footer( $this );
$tools = new PageTools( $this );

Expand Down Expand Up @@ -118,6 +120,7 @@ public function getTemplateData(): array {
'data-footer' => $footer->decorateFooterData( $parentData['data-footer'] ),
];

$data += $sidebar->getSidebarData( $parentData );
$data += $tools->getPageToolsData( $parentData );

return array_merge( $parentData, $data );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.citizen-body-sidebar {
--size-icon: 1rem;

@media ( min-width: @min-width-breakpoint-desktop ) {
display: flex;
flex-direction: column;
grid-area: sidebar;
gap: var( --space-xs );
gap: var( --space-sm );
padding-left: var( --space-xs );
margin-top: var( --space-sm ); // align with first paragraph
// Avoid padding clipping
Expand All @@ -17,6 +19,7 @@
}

.citizen-menu .mw-list-item a {
gap: var( --space-xs );
border-radius: var( --border-radius--small );
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.citizen-toc {
--size-icon: 1rem;
font-size: var( --font-size-small );
line-height: var( --line-height-xs );

Expand Down
1 change: 1 addition & 0 deletions templates/Icon.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span class="citizen-ui-icon mw-ui-icon-{{.}} mw-ui-icon-wikimedia-{{.}}"></span>
4 changes: 4 additions & 0 deletions templates/Link.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<a data-mw="interface"{{#array-attributes}} {{key}}="{{value}}"{{/array-attributes}}>{{!
}}{{#icon}}{{>Icon}}{{/icon}}{{!
}}<span>{{text}}</span>{{!
}}</a>
5 changes: 4 additions & 1 deletion templates/Menu.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
</div>
{{/label}}
{{{html-before-portal}}}
<ul>{{{html-items}}}</ul>
<ul>
{{#array-list-items}}{{>MenuListItem}}{{/array-list-items}}
{{#html-items}}{{{.}}}{{/html-items}}
</ul>
{{{html-after-portal}}}
</nav>
6 changes: 6 additions & 0 deletions templates/MenuListItem.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<li id="{{id}}" class="{{class}}">{{!
}}{{#array-links}}{{!
}}{{>Link}}{{!
}}{{/array-links}}{{!
}}{{text}}{{!
}}</li>

0 comments on commit 89b5ff1

Please sign in to comment.