diff --git a/includes/menu/Definitions.php b/includes/menu/Definitions.php index fc776c3..e7be356 100644 --- a/includes/menu/Definitions.php +++ b/includes/menu/Definitions.php @@ -69,13 +69,12 @@ final class Definitions { * @throws MWException */ public function insertContributionsMenuItem( Group $group ) { - $group->insert( 'contribs' ) - ->addComponent( - $this->context->msg( 'mobile-frontend-main-menu-contributions' )->escaped(), - SpecialPage::getTitleFor( 'Contributions', $this->user->getName() )->getLocalURL(), - MinervaUI::iconClass( 'contributions', 'before' ), - [ 'data-event-name' => 'contributions' ] - ); + $group->insertEntry( new SingleMenuEntry( + 'contributions', + $this->context->msg( 'mobile-frontend-main-menu-contributions' )->escaped(), + SpecialPage::getTitleFor( 'Contributions', $this->user->getName() )->getLocalURL() + + ) ); } /** @@ -100,14 +99,11 @@ final class Definitions { $watchlistQuery['filter'] = $filter; } } - - $group->insert( 'watchlist' ) - ->addComponent( - $this->context->msg( 'mobile-frontend-main-menu-watchlist' )->escaped(), - $watchTitle->getLocalURL( $watchlistQuery ), - MinervaUI::iconClass( 'watchlist', 'before' ), - [ 'data-event-name' => 'watchlist' ] - ); + $group->insertEntry( new SingleMenuEntry( + 'watchlist', + $this->context->msg( 'mobile-frontend-main-menu-watchlist' )->escaped(), + $watchTitle->getLocalURL( $watchlistQuery ) + ) ); } /** @@ -174,14 +170,11 @@ final class Definitions { * @param Group $group */ public function insertHomeItem( Group $group ) { - // Home link - $group->insert( 'home' ) - ->addComponent( - $this->context->msg( 'mobile-frontend-home-button' )->escaped(), - Title::newMainPage()->getLocalURL(), - MinervaUI::iconClass( 'home', 'before' ), - [ 'data-event-name' => 'home' ] - ); + $group->insertEntry( new SingleMenuEntry( + 'home', + $this->context->msg( 'mobile-frontend-home-button' )->escaped(), + Title::newMainPage()->getLocalURL() + ) ); } /** @@ -226,14 +219,13 @@ final class Definitions { public function insertMobileOptionsItem( Group $group ) { $title = $this->context->getTitle(); $returnToTitle = $title->getPrefixedText(); - $group->insert( 'settings' ) - ->addComponent( - $this->context->msg( 'mobile-frontend-main-menu-settings' )->escaped(), - SpecialPage::getTitleFor( 'MobileOptions' )-> - getLocalURL( [ 'returnto' => $returnToTitle ] ), - MinervaUI::iconClass( 'settings', 'before' ), - [ 'data-event-name' => 'settings' ] - ); + + $group->insertEntry( new SingleMenuEntry( + 'settings', + $this->context->msg( 'mobile-frontend-main-menu-settings' )->escaped(), + SpecialPage::getTitleFor( 'MobileOptions' ) + ->getLocalURL( [ 'returnto' => $returnToTitle ] ) + ) ); } /** @@ -242,13 +234,13 @@ final class Definitions { * @throws MWException */ public function insertPreferencesItem( Group $group ) { - $group->insert( 'preferences' ) - ->addComponent( - $this->context->msg( 'preferences' )->escaped(), - SpecialPage::getTitleFor( 'Preferences' )->getLocalURL(), - MinervaUI::iconClass( 'settings', 'before' ), - [ 'data-event-name' => 'preferences' ] - ); + $group->insertEntry( new SingleMenuEntry( + 'preferences', + $this->context->msg( 'preferences' )->escaped(), + SpecialPage::getTitleFor( 'Preferences' )->getLocalURL(), + true, + 'settings' + ) ); } /** @@ -284,13 +276,13 @@ final class Definitions { * @throws MWException */ public function insertSpecialPages( Group $group ) { - $group->insert( 'specialpages' ) - ->addComponent( + $group->insertEntry( + new SingleMenuEntry( + 'specialpages', $this->context->msg( 'specialpages' )->escaped(), - SpecialPage::getTitleFor( 'Specialpages' )->getLocalURL(), - MinervaUI::iconClass( 'specialpages', 'before' ), - [ 'data-event-name' => 'specialpages' ] - ); + SpecialPage::getTitleFor( 'Specialpages' )->getLocalURL() + ) + ); } /** @@ -313,13 +305,11 @@ final class Definitions { return; } - $group->insert( 'communityportal' ) - ->addComponent( - $title->getText(), - $title->getLocalURL(), - MinervaUI::iconClass( 'communityportal', 'before' ), - [ 'data-event-name' => 'community-portal' ] - ); + $group->insertEntry( new SingleMenuEntry( + 'communityportal', + $title->getText(), + $title->getLocalURL() + ) ); } /** diff --git a/includes/menu/SingleMenuEntry.php b/includes/menu/SingleMenuEntry.php new file mode 100644 index 0000000..eca0b03 --- /dev/null +++ b/includes/menu/SingleMenuEntry.php @@ -0,0 +1,77 @@ +name = $name; + $this->component = [ + 'text' => $text, + 'href' => $url, + 'class' => MinervaUI::iconClass( $iconName ?? $name, 'before' ), + ]; + if ( $trackClicks !== false ) { + $this->component['data-event-name'] = $trackClicks === true ? $name : $trackClicks; + } + } + + /** + * @inheritDoc + */ + public function getName() { + return $this->name; + } + + /** + * @inheritDoc + */ + public function getCSSClasses(): array { + return []; + } + + /** + * @inheritDoc + */ + public function getComponents(): array { + return [ $this->component ]; + } +} diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php index 8bf622d..2811e34 100644 --- a/includes/skins/SkinMinerva.php +++ b/includes/skins/SkinMinerva.php @@ -486,9 +486,9 @@ class SkinMinerva extends SkinTemplate { */ protected function getRelativeHistoryLink( Title $title, $timestamp ) { $user = $this->getUser(); + $userDate = $this->getLanguage()->userDate( $timestamp, $user ); $text = $this->msg( - 'minerva-last-modified-date', - $this->getLanguage()->userDate( $timestamp, $user ), + 'minerva-last-modified-date', $userDate, $this->getLanguage()->userTime( $timestamp, $user ) )->parse(); return [