Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(components): rewrite template data partials into CitizenComponent components #846

Merged
merged 38 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
85b8fe3
refactor(core): ♻️ convert main menu to use Components
alistair3149 May 9, 2024
f12c0f2
ci: 👷 lint code to MediaWiki standards
May 9, 2024
74a8f62
test: 🚨 namespace existing tests
alistair3149 May 9, 2024
174c899
test: 🚨 fix various error
alistair3149 May 9, 2024
434fbe3
test: 🚨 populate sidebarData in MainMenu test
alistair3149 May 9, 2024
b490915
test: 🚨 provide mainmenu data
alistair3149 May 9, 2024
2a737f3
test: 🚨 remove id test since we set it in Mustache
alistair3149 May 9, 2024
736f6b7
refactor(core): ♻️ add link and menu list item components
alistair3149 May 9, 2024
5c2c51c
ci: 👷 lint code to MediaWiki standards
May 9, 2024
85146db
test: 🚨 fix test name
alistair3149 May 9, 2024
7da7041
fix: 🐛 use older class for now
alistair3149 May 9, 2024
b6c7b83
refactor(core): ♻️ make content sidebar a component
alistair3149 May 10, 2024
a7b5d33
ci: 👷 lint code to MediaWiki standards
May 10, 2024
9c38c23
refactor(core): ♻️ class clean ups and implement sitestats component
alistair3149 May 14, 2024
a322855
refactor(core): ♻️ remove unneeded call_user_func
alistair3149 May 14, 2024
a7c7904
ci: 👷 lint code to MediaWiki standards
May 14, 2024
3769e06
refactor(core): ♻️ move searchBox to components
alistair3149 May 14, 2024
ff5356e
test: 🚨 remove unused test
alistair3149 May 14, 2024
195259d
refactor(core): ♻️ move page heading to components
alistair3149 May 14, 2024
fe3eee5
refactor(core): ♻️ merge tagline into page headings
alistair3149 May 14, 2024
badc3ed
test: 🚨 remove unused test
alistair3149 May 14, 2024
8f5ec9b
ci: 👷 lint code to MediaWiki standards
May 14, 2024
b70e760
fix(core): 🐛 add missing classes
alistair3149 May 14, 2024
ddd17e5
refactor(core): ♻️ move page footer to components
alistair3149 May 14, 2024
dc0e080
refactor(core): ♻️ add container for site notice
alistair3149 May 14, 2024
baaa9ad
test: 🚨 remove unused test
alistair3149 May 14, 2024
7981ff9
docs: 📚️ mark fixme unit test
alistair3149 May 14, 2024
513a97e
refactor(core): ♻️ rename content sidebar to page sidebar
alistair3149 May 14, 2024
cdb6c2d
refactor(core): ♻️ move site footer to components
alistair3149 May 14, 2024
199e011
ci: 👷 lint code to MediaWiki standards
May 14, 2024
6efe095
refactor(core): ♻️ rebuild user info in user menu
alistair3149 May 15, 2024
862fa63
ci: 👷 lint code to MediaWiki standards
May 15, 2024
9efb492
refactor(core): ♻️ handle anon
alistair3149 May 15, 2024
143cd0e
feat(core): ✨ add temp user handling
alistair3149 May 15, 2024
7c64872
feat(core): ✨ tweak user info styles
alistair3149 May 15, 2024
84f2a81
test: 🚨 remove unused test
alistair3149 May 15, 2024
d8afbf5
test: 🚨 fix test
alistair3149 May 15, 2024
e2cc430
test: 🚨 fix test
alistair3149 May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@
"citizen-feature-custom-width-name": "Width",
"citizen-feature-custom-width-standard-label": "Standard",
"citizen-feature-custom-width-wide-label": "Wide",
"citizen-feature-custom-width-full-label": "Full"
"citizen-feature-custom-width-full-label": "Full",

"citizen-user-info-text-anon": "Your IP address will be publicly visible if you make any edits.",
"citizen-user-info-text-temp": "This temporary account was created after an edit was made without an account on this browser and device."
}
4 changes: 3 additions & 1 deletion i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@
"citizen-feature-custom-width-name": "Heading label for page width",
"citizen-feature-custom-width-standard-label": "Label for standard page width. An adjective that describes \"text\" ({{msg-mw|Citizen-feature-custom-width-name}}).",
"citizen-feature-custom-width-wide-label": "Label for wide page width. An adjective that describes \"text\" ({{msg-mw|Citizen-feature-custom-width-name}}).",
"citizen-feature-custom-width-full-label": "Label for full page width. An adjective that describes \"text\" ({{msg-mw|Citizen-feature-custom-width-name}})."
"citizen-feature-custom-width-full-label": "Label for full page width. An adjective that describes \"text\" ({{msg-mw|Citizen-feature-custom-width-name}}).",
"citizen-user-info-text-anon": "Description in the user menu when user is not logged in.",
"citizen-user-info-text-temp": "Description in the user menu when user is using a temporary account."
}
17 changes: 17 additions & 0 deletions includes/Components/CitizenComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare( strict_types=1 );

namespace MediaWiki\Skins\Citizen\Components;

/**
* Component interface for managing Citizen-modified components
*
* @internal
*/
interface CitizenComponent {
/**
* @return array of Mustache compatible data
*/
public function getTemplateData(): array;
}
44 changes: 44 additions & 0 deletions includes/Components/CitizenComponentFooter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare( strict_types=1 );

namespace MediaWiki\Skins\Citizen\Components;

use MessageLocalizer;

/**
* CitizenComponentFooter component
* FIXME: Need unit test
*/
class CitizenComponentFooter implements CitizenComponent {
/** @var MessageLocalizer */
private $localizer;

/** @var array */
private $footerData;

/**
* @param MessageLocalizer $localizer
* @param array $footerData
*/
public function __construct(
MessageLocalizer $localizer,
array $footerData
) {
$this->localizer = $localizer;
$this->footerData = $footerData;
}

/**
* @inheritDoc
*/
public function getTemplateData(): array {
$localizer = $this->localizer;
$footerData = $this->footerData;

return $footerData + [
'msg-citizen-footer-desc' => $localizer->msg( "citizen-footer-desc" )->inContentLanguage()->parse(),
'msg-citizen-footer-tagline' => $localizer->msg( "citizen-footer-tagline" )->inContentLanguage()->parse()
];
}
}
80 changes: 80 additions & 0 deletions includes/Components/CitizenComponentLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare( strict_types=1 );

namespace MediaWiki\Skins\Citizen\Components;

/**
* TODO: Update to new classes when we move to MW 1.43
* - MediaWiki\Html\Html
* - MediaWiki\Linker\Linker
*/
use Html;
use Linker;
use MessageLocalizer;

/**
* CitizenComponentLink component
*/
class CitizenComponentLink implements CitizenComponent {
/** @var MessageLocalizer */
private $localizer;
/** @var string */
private $icon;
/** @var string */
private $href;
/** @var string */
private $text;
/** @var string */
private $accessKeyHint;

/**
* @param string $href
* @param string $text
* @param null|string $icon
* @param null|MessageLocalizer $localizer for generation of tooltip and access keys
* @param null|string $accessKeyHint will be used to derive HTML attributes such as title, accesskey
* and aria-label ("$accessKeyHint-label")
*/
public function __construct( string $href, string $text, $icon = null, $localizer = null, $accessKeyHint = null ) {
$this->href = $href;
$this->text = $text;
$this->icon = $icon;
$this->localizer = $localizer;
$this->accessKeyHint = $accessKeyHint;
}

/**
* @inheritDoc
*/
public function getTemplateData(): array {
$localizer = $this->localizer;
$accessKeyHint = $this->accessKeyHint;
$additionalAttributes = [];
if ( $localizer ) {
$msg = $localizer->msg( $accessKeyHint . '-label' );
if ( $msg->exists() ) {
$additionalAttributes[ 'aria-label' ] = $msg->text();
}
}
return [
'href' => $this->href,
'icon' => $this->icon,
'text' => $this->text,
'array-attributes' => [
[
'key' => 'href',
'value' => $this->href
]
],
'html-attributes' => $localizer && $accessKeyHint ? Html::expandAttributes(
Linker::tooltipAndAccesskeyAttribs(
$accessKeyHint,
[],
[],
$localizer
) + $additionalAttributes
) : '',
];
}
}
43 changes: 43 additions & 0 deletions includes/Components/CitizenComponentMainMenu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare( strict_types=1 );

namespace MediaWiki\Skins\Citizen\Components;

/**
* CitizenComponentMainMenu component
*/
class CitizenComponentMainMenu implements CitizenComponent {
/** @var array */
private $sidebarData;

/**
* @param array $sidebarData
*/
public function __construct( array $sidebarData ) {
$this->sidebarData = $sidebarData;
}

/**
* @inheritDoc
*/
public function getTemplateData(): array {
$portletsRest = [];
foreach ( $this->sidebarData[ 'array-portlets-rest' ] as $data ) {
/**
* Remove toolbox from main menu as we moved it to article tools
* TODO: Move handling to SkinCitizen.php after we convert pagetools to component
*/
if ( $data['id'] === 'p-tb' ) {
continue;
}
$portletsRest[] = ( new CitizenComponentMenu( $data ) )->getTemplateData();
}
$firstPortlet = new CitizenComponentMenu( $this->sidebarData['data-portlets-first'] );

return [
'data-portlets-first' => $firstPortlet->getTemplateData(),
'array-portlets-rest' => $portletsRest
];
}
}
52 changes: 52 additions & 0 deletions includes/Components/CitizenComponentMenu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare( strict_types=1 );

namespace MediaWiki\Skins\Citizen\Components;

use Countable;

/**
* CitizenComponentMenu component
*/
class CitizenComponentMenu implements CitizenComponent, Countable {
/** @var array */
private $data;

/**
* @param array $data
*/
public function __construct( array $data ) {
$this->data = $data;
}

/**
* Counts how many items the menu has.
*
* @return int
*/
public function count(): int {
$items = $this->data['array-list-items'] ?? null;
if ( $items ) {
return count( $items );
}
$htmlItems = $this->data['html-items'] ?? '';
return substr_count( $htmlItems, '<li' );
}

/**
* @inheritDoc
*/
public function getTemplateData(): array {
return $this->data + [
'class' => '',
'label' => '',
'html-tooltip' => '',
'label-class' => '',
'html-before-portal' => '',
'html-items' => '',
'html-after-portal' => '',
'array-list-items' => null,
];
}
}
39 changes: 39 additions & 0 deletions includes/Components/CitizenComponentMenuListItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare( strict_types=1 );

namespace MediaWiki\Skins\Citizen\Components;

/**
* CitizenComponentMenuListItem component
*/
class CitizenComponentMenuListItem implements CitizenComponent {
/** @var CitizenComponentLink */
private $link;
/** @var string */
private $class;
/** @var string */
private $id;

/**
* @param CitizenComponentLink $link
* @param string $class
* @param string $id
*/
public function __construct( CitizenComponentLink $link, string $class = '', string $id = '' ) {
$this->link = $link;
$this->class = $class;
$this->id = $id;
}

/**
* @inheritDoc
*/
public function getTemplateData(): array {
return [
'array-links' => $this->link->getTemplateData(),
'item-class' => $this->class,
'item-id' => $this->id,
];
}
}
46 changes: 46 additions & 0 deletions includes/Components/CitizenComponentPageFooter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare( strict_types=1 );

namespace MediaWiki\Skins\Citizen\Components;

use MessageLocalizer;

/**
* CitizenComponentPageFooter component
* FIXME: Need unit test
*/
class CitizenComponentPageFooter implements CitizenComponent {
/** @var MessageLocalizer */
private $localizer;

/** @var array */
private $footerData;

/**
* @param MessageLocalizer $localizer
* @param array $footerData
*/
public function __construct(
MessageLocalizer $localizer,
array $footerData
) {
$this->localizer = $localizer;
$this->footerData = $footerData;
}

/**
* @inheritDoc
*/
public function getTemplateData(): array {
$footerData = $this->footerData;

// Add label to footer-info to use in PageFooter
foreach ( $footerData['array-items'] as &$item ) {
$msgKey = 'citizen-page-info-' . $item['name'];
$item['label'] = $this->localizer->msg( $msgKey )->text();
}

return $footerData;
}
}
Loading
Loading