| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Minerva\Skins; |
| 22 |
|
| 23 |
use MediaWiki\Cache\GenderCache; |
| 24 |
use MediaWiki\Extension\Notifications\Controller\NotificationController; |
| 25 |
use MediaWiki\Html\Html; |
| 26 |
use MediaWiki\Language\Language; |
| 27 |
use MediaWiki\Linker\LinkRenderer; |
| 28 |
use MediaWiki\Linker\LinkTarget; |
| 29 |
use MediaWiki\Minerva\LanguagesHelper; |
| 30 |
use MediaWiki\Minerva\Menu\Definitions; |
| 31 |
use MediaWiki\Minerva\Menu\Main\AdvancedMainMenuBuilder; |
| 32 |
use MediaWiki\Minerva\Menu\Main\DefaultMainMenuBuilder; |
| 33 |
use MediaWiki\Minerva\Menu\Main\MainMenuDirector; |
| 34 |
use MediaWiki\Minerva\Menu\PageActions\PageActions; |
| 35 |
use MediaWiki\Minerva\Menu\User\AdvancedUserMenuBuilder; |
| 36 |
use MediaWiki\Minerva\Menu\User\DefaultUserMenuBuilder; |
| 37 |
use MediaWiki\Minerva\Menu\User\UserMenuDirector; |
| 38 |
use MediaWiki\Minerva\Permissions\IMinervaPagePermissions; |
| 39 |
use MediaWiki\Minerva\Permissions\MinervaPagePermissions; |
| 40 |
use MediaWiki\Minerva\SkinOptions; |
| 41 |
use MediaWiki\Registration\ExtensionRegistry; |
| 42 |
use MediaWiki\Revision\RevisionLookup; |
| 43 |
use MediaWiki\SpecialPage\SpecialPage; |
| 44 |
use MediaWiki\Title\NamespaceInfo; |
| 45 |
use MediaWiki\Title\Title; |
| 46 |
use MediaWiki\User\Options\UserOptionsManager; |
| 47 |
use MediaWiki\User\UserIdentityUtils; |
| 48 |
use MediaWiki\Utils\MWTimestamp; |
| 49 |
use RuntimeException; |
| 50 |
use SkinMustache; |
| 51 |
use SkinTemplate; |
| 52 |
use SpecialMobileHistory; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
class SkinMinerva extends SkinMustache { |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public const LEAD_SECTION_NUMBER = 0; |
| 64 |
|
| 65 |
|
| 66 |
public $skinname = 'minerva'; |
| 67 |
|
| 68 |
public $template = 'MinervaTemplate'; |
| 69 |
|
| 70 |
|
| 71 |
private ?array $contentNavigationUrls; |
| 72 |
|
| 73 |
private GenderCache $genderCache; |
| 74 |
private LinkRenderer $linkRenderer; |
| 75 |
private LanguagesHelper $languagesHelper; |
| 76 |
private Definitions $definitions; |
| 77 |
private PageActions $pageActions; |
| 78 |
private IMinervaPagePermissions $permissions; |
| 79 |
private SkinOptions $skinOptions; |
| 80 |
private SkinUserPageHelper $skinUserPageHelper; |
| 81 |
private NamespaceInfo $namespaceInfo; |
| 82 |
private RevisionLookup $revisionLookup; |
| 83 |
private UserIdentityUtils $userIdentityUtils; |
| 84 |
private UserOptionsManager $userOptionsManager; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public function __construct( |
| 102 |
GenderCache $genderCache, |
| 103 |
LinkRenderer $linkRenderer, |
| 104 |
LanguagesHelper $languagesHelper, |
| 105 |
Definitions $definitions, |
| 106 |
PageActions $pageActions, |
| 107 |
MinervaPagePermissions $permissions, |
| 108 |
SkinOptions $skinOptions, |
| 109 |
SkinUserPageHelper $skinUserPageHelper, |
| 110 |
NamespaceInfo $namespaceInfo, |
| 111 |
RevisionLookup $revisionLookup, |
| 112 |
UserIdentityUtils $userIdentityUtils, |
| 113 |
UserOptionsManager $userOptionsManager, |
| 114 |
$options = [] |
| 115 |
) { |
| 116 |
parent::__construct( $options ); |
| 117 |
$this->genderCache = $genderCache; |
| 118 |
$this->linkRenderer = $linkRenderer; |
| 119 |
$this->languagesHelper = $languagesHelper; |
| 120 |
$this->definitions = $definitions |
| 121 |
->setContext( $this->getContext() ); |
| 122 |
$this->pageActions = $pageActions; |
| 123 |
$this->permissions = $permissions |
| 124 |
->setContext( $this->getContext() ); |
| 125 |
$this->skinOptions = $skinOptions; |
| 126 |
$this->skinUserPageHelper = $skinUserPageHelper |
| 127 |
->setContext( $this->getContext() ) |
| 128 |
->setTitle( $this->getTitle() ); |
| 129 |
$this->namespaceInfo = $namespaceInfo; |
| 130 |
$this->revisionLookup = $revisionLookup; |
| 131 |
$this->userIdentityUtils = $userIdentityUtils; |
| 132 |
$this->userOptionsManager = $userOptionsManager; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
private function hasPageActions(): bool { |
| 139 |
$title = $this->getTitle(); |
| 140 |
return !$title->isSpecialPage() && !$title->isMainPage() && |
| 141 |
$this->getActionName() === 'view'; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
private function hasSecondaryActions(): bool { |
| 148 |
return !$this->skinUserPageHelper->isUserPage(); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
private function isFallbackEditor(): bool { |
| 155 |
return $this->getActionName() === 'edit'; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
private function getPageActions( array $nav ): ?array { |
| 165 |
if ( $this->isFallbackEditor() || !$this->hasPageActions() ) { |
| 166 |
return null; |
| 167 |
} |
| 168 |
|
| 169 |
$pageActionsDirector = $this->pageActions->getPageActionsDirector( $this->getContext() ); |
| 170 |
$sidebar = $this->buildSidebar(); |
| 171 |
$actions = $nav['actions'] ?? []; |
| 172 |
$views = $nav['views'] ?? []; |
| 173 |
return $pageActionsDirector->buildMenu( $sidebar['TOOLBOX'], $actions, $views ); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
private function getNotificationFallbackButton(): array { |
| 183 |
return [ |
| 184 |
'icon' => 'bellOutline', |
| 185 |
'href' => SpecialPage::getTitleFor( 'Mytalk' )->getLocalURL( |
| 186 |
[ 'returnto' => $this->getTitle()->getPrefixedText() ] |
| 187 |
), |
| 188 |
]; |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
private function getCombinedNotificationButton( array $alert, array $notice ): array { |
| 197 |
|
| 198 |
$combinedNotification = $alert; |
| 199 |
|
| 200 |
$notifCount = ( $alert['data']['counter-num'] ?? 0 ) + ( $notice['data']['counter-num'] ?? 0 ); |
| 201 |
$combinedNotification['data']['counter-num'] = $notifCount; |
| 202 |
|
| 203 |
if ( class_exists( NotificationController::class ) ) { |
| 204 |
$combinedNotification['data']['counter-text'] = |
| 205 |
|
| 206 |
NotificationController::formatNotificationCount( $notifCount ); |
| 207 |
} else { |
| 208 |
$combinedNotification['data']['counter-text'] = $notifCount; |
| 209 |
} |
| 210 |
|
| 211 |
$combinedNotification['text'] = $alert['data']['counter-text']; |
| 212 |
|
| 213 |
$linkClassAlert = $alert['link-class'] ?? []; |
| 214 |
$linkClassNotice = $notice['link-class'] ?? []; |
| 215 |
$hasUnseenAlerts = is_array( $linkClassAlert ) && |
| 216 |
in_array( 'mw-echo-unseen-notifications', $linkClassAlert ); |
| 217 |
$hasUnseenNotices = is_array( $linkClassNotice ) && |
| 218 |
in_array( 'mw-echo-unseen-notifications', $linkClassNotice ); |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
if ( $notifCount > 0 && ( $hasUnseenAlerts || $hasUnseenNotices ) ) { |
| 226 |
return $this->getNotificationCircleButton( $combinedNotification ); |
| 227 |
} else { |
| 228 |
return $this->getNotificationButton( $combinedNotification ); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
private function getNotificationCircleButton( array $notification ): array { |
| 243 |
$notification['icon'] = 'circle'; |
| 244 |
$linkClass = $notification['link-class'] ?? []; |
| 245 |
$linkClass[] = 'notification-count'; |
| 246 |
$linkClass[] = 'notification-unseen'; |
| 247 |
$linkClass[] = 'mw-echo-unseen-notifications'; |
| 248 |
$notification['link-class'] = $linkClass; |
| 249 |
return $notification; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
private function getNotificationButton( array $notification ): array { |
| 259 |
$linkClass = $notification['link-class']; |
| 260 |
$notification['link-class'] = array_filter( |
| 261 |
$linkClass, |
| 262 |
static function ( $class ) { |
| 263 |
return $class !== 'oo-ui-icon-bellOutline'; |
| 264 |
} |
| 265 |
); |
| 266 |
$notification['icon'] = 'bellOutline'; |
| 267 |
return $notification; |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
protected function runOnSkinTemplateNavigationHooks( SkinTemplate $skin, &$contentNavigationUrls ) { |
| 276 |
parent::runOnSkinTemplateNavigationHooks( $skin, $contentNavigationUrls ); |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
foreach ( array_keys( $contentNavigationUrls['associated-pages'] ) as $id ) { |
| 281 |
if ( in_array( $id, [ 'user_talk', 'talk' ] ) ) { |
| 282 |
$contentNavigationUrls['associated-pages'][ $id ]['rel'] = 'discussion'; |
| 283 |
} |
| 284 |
} |
| 285 |
$this->contentNavigationUrls = $contentNavigationUrls; |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
if ( $this->getUser()->isRegistered() ) { |
| 293 |
if ( count( $contentNavigationUrls['notifications'] ) === 0 ) { |
| 294 |
|
| 295 |
$contentNavigationUrls['notifications']['mytalks'] = $this->getNotificationFallbackButton(); |
| 296 |
} elseif ( $this->skinOptions->get( SkinOptions::SINGLE_ECHO_BUTTON ) ) { |
| 297 |
|
| 298 |
|
| 299 |
$alert = $contentNavigationUrls['notifications']['notifications-alert'] ?? null; |
| 300 |
$notice = $contentNavigationUrls['notifications']['notifications-notice'] ?? null; |
| 301 |
if ( $alert && $notice ) { |
| 302 |
unset( $contentNavigationUrls['notifications']['notifications-notice'] ); |
| 303 |
$contentNavigationUrls['notifications']['notifications-alert'] = |
| 304 |
$this->getCombinedNotificationButton( $alert, $notice ); |
| 305 |
} |
| 306 |
} else { |
| 307 |
|
| 308 |
$alert = $contentNavigationUrls['notifications']['notifications-alert'] ?? null; |
| 309 |
if ( $alert ) { |
| 310 |
|
| 311 |
|
| 312 |
$linkClass = $alert['link-class'] ?? []; |
| 313 |
$alert['link-class'] = array_filter( $linkClass, static function ( $class ) { |
| 314 |
return $class !== 'oo-ui-icon-bellOutline'; |
| 315 |
} ); |
| 316 |
$contentNavigationUrls['notifications']['notifications-alert'] = $alert; |
| 317 |
} |
| 318 |
} |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
public function getTemplateData(): array { |
| 326 |
$data = parent::getTemplateData(); |
| 327 |
|
| 328 |
$nav = $this->contentNavigationUrls; |
| 329 |
if ( $nav === null ) { |
| 330 |
throw new RuntimeException( 'contentNavigationUrls was not set as expected.' ); |
| 331 |
} |
| 332 |
if ( !$this->hasCategoryLinks() ) { |
| 333 |
unset( $data['html-categories'] ); |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
$isUserPage = $this->skinUserPageHelper->isUserPage(); |
| 339 |
$isUserPageAccessible = $this->skinUserPageHelper->isUserPageAccessibleToCurrentUser(); |
| 340 |
if ( $isUserPage && $isUserPageAccessible ) { |
| 341 |
$data['html-title-heading'] = $this->getUserPageHeadingHtml( $data['html-title-heading' ] ); |
| 342 |
} |
| 343 |
|
| 344 |
$usermessage = $data['html-user-message'] ?? ''; |
| 345 |
if ( $usermessage ) { |
| 346 |
$data['html-user-message'] = Html::warningBox( |
| 347 |
'<span class="minerva-icon minerva-icon--userTalk-warning"></span> ' |
| 348 |
. $usermessage, |
| 349 |
'minerva-anon-talk-message' |
| 350 |
); |
| 351 |
} |
| 352 |
$allLanguages = $data['data-portlets']['data-languages']['array-items'] ?? []; |
| 353 |
$allVariants = $data['data-portlets']['data-variants']['array-items'] ?? []; |
| 354 |
$notifications = $data['data-portlets']['data-notifications']['array-items'] ?? []; |
| 355 |
$associatedPages = $data['data-portlets']['data-associated-pages'] ?? []; |
| 356 |
|
| 357 |
return $data + [ |
| 358 |
'has-minerva-languages' => $allLanguages || $allVariants, |
| 359 |
'array-minerva-banners' => $this->prepareBanners( $data['html-site-notice'] ), |
| 360 |
'data-minerva-search-box' => $data['data-search-box'] + [ |
| 361 |
'data-btn' => [ |
| 362 |
'data-icon' => [ |
| 363 |
'icon' => 'search', |
| 364 |
], |
| 365 |
'label' => $this->msg( 'searchbutton' )->escaped(), |
| 366 |
'classes' => 'skin-minerva-search-trigger', |
| 367 |
'array-attributes' => [ |
| 368 |
[ |
| 369 |
'key' => 'id', |
| 370 |
'value' => 'searchIcon', |
| 371 |
] |
| 372 |
] |
| 373 |
], |
| 374 |
], |
| 375 |
'data-minerva-main-menu-btn' => [ |
| 376 |
'data-icon' => [ |
| 377 |
'icon' => 'menu', |
| 378 |
], |
| 379 |
'tag-name' => 'label', |
| 380 |
'classes' => 'toggle-list__toggle', |
| 381 |
'array-attributes' => [ |
| 382 |
[ |
| 383 |
'key' => 'for', |
| 384 |
'value' => 'main-menu-input', |
| 385 |
], |
| 386 |
[ |
| 387 |
'key' => 'id', |
| 388 |
'value' => 'mw-mf-main-menu-button', |
| 389 |
], |
| 390 |
[ |
| 391 |
'key' => 'aria-hidden', |
| 392 |
'value' => 'true', |
| 393 |
], |
| 394 |
[ |
| 395 |
'key' => 'data-event-name', |
| 396 |
'value' => 'ui.mainmenu', |
| 397 |
], |
| 398 |
], |
| 399 |
'text' => $this->msg( 'mobile-frontend-main-menu-button-tooltip' )->escaped(), |
| 400 |
], |
| 401 |
'data-minerva-main-menu' => $this->getMainMenu()->getMenuData( |
| 402 |
$nav, |
| 403 |
$this->buildSidebar() |
| 404 |
)['items'], |
| 405 |
'html-minerva-tagline' => $this->getTaglineHtml(), |
| 406 |
'html-minerva-user-menu' => $this->getPersonalToolsMenu( $nav['user-menu'] ), |
| 407 |
'is-minerva-beta' => $this->skinOptions->get( SkinOptions::BETA_MODE ), |
| 408 |
'data-minerva-notifications' => $notifications ? [ |
| 409 |
'array-buttons' => $this->getNotificationButtons( $notifications ), |
| 410 |
] : null, |
| 411 |
'data-minerva-tabs' => $this->getTabsData( $nav, $associatedPages ), |
| 412 |
'data-minerva-page-actions' => $this->getPageActions( $nav ), |
| 413 |
'data-minerva-secondary-actions' => $this->getSecondaryActions( $nav ), |
| 414 |
'html-minerva-subject-link' => $this->getSubjectPage(), |
| 415 |
'data-minerva-history-link' => $this->getHistoryLink( $this->getTitle() ), |
| 416 |
]; |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
public static function getNotificationButtons( array $notifications ): array { |
| 427 |
$btns = []; |
| 428 |
|
| 429 |
foreach ( $notifications as $notification ) { |
| 430 |
$linkData = $notification['array-links'][ 0 ] ?? []; |
| 431 |
$icon = $linkData['icon'] ?? null; |
| 432 |
if ( !$icon ) { |
| 433 |
continue; |
| 434 |
} |
| 435 |
$id = $notification['id'] ?? null; |
| 436 |
$classes = ''; |
| 437 |
$attributes = []; |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
foreach ( $linkData[ 'array-attributes' ] as $keyValuePair ) { |
| 443 |
if ( $keyValuePair['key'] === 'class' ) { |
| 444 |
$classes = $keyValuePair['value']; |
| 445 |
} elseif ( $keyValuePair['key'] === 'id' ) { |
| 446 |
|
| 447 |
} else { |
| 448 |
$attributes[] = $keyValuePair; |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
if ( $id ) { |
| 453 |
$attributes[] = [ |
| 454 |
'key' => 'id', |
| 455 |
'value' => $id, |
| 456 |
]; |
| 457 |
} |
| 458 |
$btns[] = [ |
| 459 |
'tag-name' => 'a', |
| 460 |
|
| 461 |
'classes' => preg_replace( '/oo-ui-icon-(bellOutline|tray)/', '', $classes ), |
| 462 |
'array-attributes' => $attributes, |
| 463 |
'data-icon' => [ |
| 464 |
'icon' => $icon, |
| 465 |
], |
| 466 |
'label' => $linkData['text'] ?? '', |
| 467 |
]; |
| 468 |
} |
| 469 |
return $btns; |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
private function isHistoryPage(): bool { |
| 476 |
return $this->getRequest()->getRawVal( 'action' ) === 'history'; |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
private function hasPageTabs(): bool { |
| 489 |
$title = $this->getTitle(); |
| 490 |
$isSpecialPageOrHistory = $title->isSpecialPage() || |
| 491 |
$this->isHistoryPage(); |
| 492 |
$subjectPage = $this->namespaceInfo->getSubjectPage( $title ); |
| 493 |
$isMainPageTalk = Title::newFromLinkTarget( $subjectPage )->isMainPage(); |
| 494 |
return ( |
| 495 |
$this->hasPageActions() && !$isMainPageTalk && |
| 496 |
$this->skinOptions->get( SkinOptions::TALK_AT_TOP ) |
| 497 |
) || ( |
| 498 |
$isSpecialPageOrHistory && |
| 499 |
$this->skinOptions->get( SkinOptions::TABS_ON_SPECIALS ) |
| 500 |
); |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
private function getTabsData( array $contentNavigationUrls, array $associatedPages ): array { |
| 509 |
$hasPageTabs = $this->hasPageTabs(); |
| 510 |
if ( !$hasPageTabs ) { |
| 511 |
return []; |
| 512 |
} |
| 513 |
return $contentNavigationUrls ? [ |
| 514 |
'items' => array_values( $contentNavigationUrls['associated-pages'] ), |
| 515 |
'id' => $associatedPages['id'] ?? null, |
| 516 |
] : []; |
| 517 |
} |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
protected function getMainMenu(): MainMenuDirector { |
| 525 |
$showMobileOptions = $this->skinOptions->get( SkinOptions::MOBILE_OPTIONS ); |
| 526 |
|
| 527 |
$showDonateLink = $this->skinOptions->get( SkinOptions::SHOW_DONATE ); |
| 528 |
$builder = $this->skinOptions->get( SkinOptions::MAIN_MENU_EXPANDED ) ? |
| 529 |
new AdvancedMainMenuBuilder( |
| 530 |
$showMobileOptions, |
| 531 |
$showDonateLink, |
| 532 |
$this->definitions |
| 533 |
) : |
| 534 |
new DefaultMainMenuBuilder( |
| 535 |
$showMobileOptions, |
| 536 |
$showDonateLink, |
| 537 |
$this->getUser(), |
| 538 |
$this->definitions, |
| 539 |
$this->userIdentityUtils |
| 540 |
); |
| 541 |
return new MainMenuDirector( $builder ); |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
private function getPersonalToolsMenu( array $personalUrls ): ?string { |
| 551 |
$builder = $this->skinOptions->get( SkinOptions::PERSONAL_MENU ) ? |
| 552 |
new AdvancedUserMenuBuilder( |
| 553 |
$this->getContext(), |
| 554 |
$this->getUser(), |
| 555 |
$this->definitions |
| 556 |
) : |
| 557 |
new DefaultUserMenuBuilder(); |
| 558 |
|
| 559 |
$userMenuDirector = new UserMenuDirector( |
| 560 |
$builder, |
| 561 |
$this->getSkin() |
| 562 |
); |
| 563 |
return $userMenuDirector->renderMenuData( $personalUrls ); |
| 564 |
} |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
protected function getSubjectPage(): string { |
| 570 |
$title = $this->getTitle(); |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
if ( $title->isTalkPage() && !$this->skinOptions->get( SkinOptions::TALK_AT_TOP ) ) { |
| 576 |
|
| 577 |
switch ( $title->getNamespace() ) { |
| 578 |
case NS_USER_TALK: |
| 579 |
$msg = 'mobile-frontend-talk-back-to-userpage'; |
| 580 |
break; |
| 581 |
case NS_PROJECT_TALK: |
| 582 |
$msg = 'mobile-frontend-talk-back-to-projectpage'; |
| 583 |
break; |
| 584 |
case NS_FILE_TALK: |
| 585 |
$msg = 'mobile-frontend-talk-back-to-filepage'; |
| 586 |
break; |
| 587 |
default: |
| 588 |
|
| 589 |
$msg = 'mobile-frontend-talk-back-to-page'; |
| 590 |
} |
| 591 |
$subjectPage = $this->namespaceInfo->getSubjectPage( $title ); |
| 592 |
|
| 593 |
return $this->linkRenderer->makeLink( |
| 594 |
$subjectPage, |
| 595 |
$this->msg( $msg, $title->getText() )->text(), |
| 596 |
[ |
| 597 |
'data-event-name' => 'talk.returnto', |
| 598 |
'class' => 'return-link' |
| 599 |
] |
| 600 |
); |
| 601 |
} else { |
| 602 |
return ''; |
| 603 |
} |
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
final protected function doEditSectionLinksHTML( array $links, Language $lang ): string { |
| 612 |
$transformedLinks = []; |
| 613 |
foreach ( $links as $key => $link ) { |
| 614 |
$transformedLinks[] = $link + [ |
| 615 |
'data-icon' => [ |
| 616 |
'icon' => $link['icon'], |
| 617 |
], |
| 618 |
]; |
| 619 |
} |
| 620 |
return parent::doEditSectionLinksHTML( $transformedLinks, $lang ); |
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
public function getPageClasses( $title ): string { |
| 629 |
$className = parent::getPageClasses( $title ); |
| 630 |
$className .= ' ' . ( $this->skinOptions->get( SkinOptions::BETA_MODE ) |
| 631 |
? 'beta' : 'stable' ); |
| 632 |
|
| 633 |
if ( $this->getUser()->isRegistered() ) { |
| 634 |
$className .= ' is-authenticated'; |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
if ( |
| 639 |
$title->getNamespace() === NS_MAIN && |
| 640 |
$this->skinOptions->get( SkinOptions::PAGE_ISSUES ) |
| 641 |
) { |
| 642 |
$className .= ' issues-group-B'; |
| 643 |
} |
| 644 |
|
| 645 |
return $className; |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
private static function resolveNightModeQueryValue( string $value ): string { |
| 654 |
switch ( $value ) { |
| 655 |
case 'day': |
| 656 |
case 'night': |
| 657 |
case 'os': |
| 658 |
return $value; |
| 659 |
case '1': |
| 660 |
return 'night'; |
| 661 |
case '2': |
| 662 |
return 'os'; |
| 663 |
default: |
| 664 |
return 'day'; |
| 665 |
} |
| 666 |
} |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
public function getHtmlElementAttributes(): array { |
| 676 |
$attributes = parent::getHtmlElementAttributes(); |
| 677 |
|
| 678 |
|
| 679 |
$webRequest = $this->getRequest(); |
| 680 |
$forceNightMode = $webRequest->getRawVal( 'minervanightmode' ); |
| 681 |
|
| 682 |
|
| 683 |
$nightModeConfig = $this->getConfig()->get( 'MinervaNightModeOptions' ); |
| 684 |
$featuresHelper = new FeaturesHelper(); |
| 685 |
$shouldDisableNightMode = $featuresHelper->shouldDisableNightMode( $nightModeConfig, |
| 686 |
$webRequest, |
| 687 |
$this->getTitle() |
| 688 |
); |
| 689 |
|
| 690 |
if ( |
| 691 |
$this->skinOptions->get( SkinOptions::NIGHT_MODE ) || $forceNightMode !== null |
| 692 |
) { |
| 693 |
$user = $this->getUser(); |
| 694 |
$value = $this->userOptionsManager->getOption( $user, 'minerva-theme' ); |
| 695 |
|
| 696 |
|
| 697 |
if ( $forceNightMode !== null && in_array( $forceNightMode, [ '1', '0', '2', 'day', 'night', 'os' ] ) ) { |
| 698 |
$value = self::resolveNightModeQueryValue( $forceNightMode ); |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
if ( $shouldDisableNightMode ) { |
| 704 |
$attributes[ 'class' ] .= ' skin-night-mode-page-disabled'; |
| 705 |
return $attributes; |
| 706 |
} |
| 707 |
|
| 708 |
$attributes[ 'class' ] .= " skin-theme-clientpref-$value"; |
| 709 |
} |
| 710 |
|
| 711 |
return $attributes; |
| 712 |
} |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
private function hasCategoryLinks(): bool { |
| 719 |
if ( !$this->skinOptions->get( SkinOptions::CATEGORIES ) ) { |
| 720 |
return false; |
| 721 |
} |
| 722 |
$categoryLinks = $this->getOutput()->getCategoryLinks(); |
| 723 |
|
| 724 |
if ( !count( $categoryLinks ) ) { |
| 725 |
return false; |
| 726 |
} |
| 727 |
return !empty( $categoryLinks['normal'] ) || !empty( $categoryLinks['hidden'] ); |
| 728 |
} |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
protected function getRelativeHistoryLink( Title $title, string $timestamp ): array { |
| 737 |
$user = $this->getUser(); |
| 738 |
$userDate = $this->getLanguage()->userDate( $timestamp, $user ); |
| 739 |
$text = $this->msg( |
| 740 |
'minerva-last-modified-date', $userDate, |
| 741 |
$this->getLanguage()->userTime( $timestamp, $user ) |
| 742 |
)->parse(); |
| 743 |
return [ |
| 744 |
|
| 745 |
'data-timestamp' => wfTimestamp( TS_UNIX, $timestamp ), |
| 746 |
'href' => $this->getHistoryUrl( $title ), |
| 747 |
'text' => $text, |
| 748 |
] + $this->getRevisionEditorData( $title ); |
| 749 |
} |
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
protected function getGenericHistoryLink( Title $title ): array { |
| 757 |
$text = $this->msg( 'mobile-frontend-history' )->plain(); |
| 758 |
return [ |
| 759 |
'href' => $this->getHistoryUrl( $title ), |
| 760 |
'text' => $text, |
| 761 |
]; |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
private function shouldUseSpecialHistory( Title $title ): bool { |
| 770 |
return ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) && |
| 771 |
SpecialMobileHistory::shouldUseSpecialHistory( $title, $this->getUser() ); |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
protected function getHistoryUrl( Title $title ): string { |
| 781 |
return $this->shouldUseSpecialHistory( $title ) ? |
| 782 |
SpecialPage::getTitleFor( 'History', $title )->getLocalURL() : |
| 783 |
$title->getLocalURL( [ 'action' => 'history' ] ); |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
protected function getHistoryLink( Title $title ): ?array { |
| 798 |
if ( !$title->exists() || |
| 799 |
$this->getActionName() !== 'view' |
| 800 |
) { |
| 801 |
return null; |
| 802 |
} |
| 803 |
|
| 804 |
$request = $this->getRequest(); |
| 805 |
if ( $request->getCheck( 'diff' ) ) { |
| 806 |
return null; |
| 807 |
} |
| 808 |
|
| 809 |
$out = $this->getOutput(); |
| 810 |
|
| 811 |
if ( !$out->getRevisionId() || !$out->isRevisionCurrent() || $title->isMainPage() ) { |
| 812 |
$historyLink = $this->getGenericHistoryLink( $title ); |
| 813 |
} else { |
| 814 |
|
| 815 |
$timestamp = $out->getRevisionTimestamp(); |
| 816 |
if ( !$timestamp ) { |
| 817 |
|
| 818 |
$timestamp = $this->revisionLookup->getTimestampFromId( $out->getRevisionId() ); |
| 819 |
} |
| 820 |
$historyLink = $this->getRelativeHistoryLink( $title, $timestamp ); |
| 821 |
} |
| 822 |
|
| 823 |
return $historyLink + [ |
| 824 |
'historyIcon' => [ |
| 825 |
'icon' => 'modified-history', |
| 826 |
'size' => 'medium' |
| 827 |
], |
| 828 |
'arrowIcon' => [ |
| 829 |
'icon' => 'expand', |
| 830 |
'size' => 'small' |
| 831 |
] |
| 832 |
]; |
| 833 |
} |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
private function getRevisionEditorData( LinkTarget $title ): array { |
| 842 |
$rev = $this->revisionLookup->getRevisionByTitle( $title ); |
| 843 |
$result = []; |
| 844 |
if ( $rev ) { |
| 845 |
$revUser = $rev->getUser(); |
| 846 |
|
| 847 |
if ( $revUser ) { |
| 848 |
$editorName = $revUser->getName(); |
| 849 |
$editorGender = $this->genderCache->getGenderOf( $revUser, __METHOD__ ); |
| 850 |
$result += [ |
| 851 |
'data-user-name' => $editorName, |
| 852 |
'data-user-gender' => $editorGender, |
| 853 |
]; |
| 854 |
} |
| 855 |
} |
| 856 |
return $result; |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
protected function getTaglineHtml(): string { |
| 864 |
$tagline = ''; |
| 865 |
|
| 866 |
$pageUser = $this->skinUserPageHelper->getPageUser(); |
| 867 |
if ( $pageUser ) { |
| 868 |
$fromDate = $pageUser->getRegistration(); |
| 869 |
|
| 870 |
if ( $this->skinUserPageHelper->isUserPageAccessibleToCurrentUser() && is_string( $fromDate ) ) { |
| 871 |
$fromDateTs = wfTimestamp( TS_UNIX, $fromDate ); |
| 872 |
|
| 873 |
|
| 874 |
$tagline = $this->msg( 'mobile-frontend-user-page-member-since', |
| 875 |
$this->getLanguage()->userDate( new MWTimestamp( $fromDateTs ), $this->getUser() ), |
| 876 |
$pageUser )->text(); |
| 877 |
|
| 878 |
|
| 879 |
$attrs = [ 'id' => 'tagline-userpage', |
| 880 |
'data-userpage-registration-date' => $fromDateTs, |
| 881 |
'data-userpage-gender' => $this->genderCache->getGenderOf( $pageUser, __METHOD__ ) ]; |
| 882 |
} |
| 883 |
} else { |
| 884 |
if ( $this->getTitle() ) { |
| 885 |
$out = $this->getOutput(); |
| 886 |
$tagline = $out->getProperty( 'wgMFDescription' ); |
| 887 |
} |
| 888 |
} |
| 889 |
|
| 890 |
$attrs[ 'class' ] = 'tagline'; |
| 891 |
return Html::element( 'div', $attrs, $tagline ); |
| 892 |
} |
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
private function getUserPageHeadingHtml( string $heading ): string { |
| 901 |
|
| 902 |
return Html::element( 'h1', |
| 903 |
|
| 904 |
[ |
| 905 |
'id' => 'firstHeading', |
| 906 |
'class' => 'firstHeading mw-first-heading mw-minerva-user-heading', |
| 907 |
], |
| 908 |
$this->skinUserPageHelper->getPageUser()->getName() |
| 909 |
); |
| 910 |
} |
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
protected function prepareBanners( string $siteNotice ): array { |
| 920 |
$banners = []; |
| 921 |
if ( $siteNotice && $this->getConfig()->get( 'MinervaEnableSiteNotice' ) ) { |
| 922 |
$banners[] = $siteNotice; |
| 923 |
} else { |
| 924 |
$banners[] = '<div id="siteNotice"></div>'; |
| 925 |
} |
| 926 |
return $banners; |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
protected function getLanguageButton(): array { |
| 934 |
return [ |
| 935 |
'array-attributes' => [ |
| 936 |
[ |
| 937 |
'key' => 'href', |
| 938 |
'value' => '#p-lang' |
| 939 |
] |
| 940 |
], |
| 941 |
'tag-name' => 'a', |
| 942 |
'classes' => 'language-selector button', |
| 943 |
'label' => $this->msg( 'mobile-frontend-language-article-heading' )->text() |
| 944 |
]; |
| 945 |
} |
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
protected function getTalkButton( Title $talkTitle, string $label ): array { |
| 954 |
return [ |
| 955 |
'array-attributes' => [ |
| 956 |
[ |
| 957 |
'key' => 'href', |
| 958 |
'value' => $talkTitle->getLinkURL(), |
| 959 |
], |
| 960 |
[ |
| 961 |
'key' => 'data-title', |
| 962 |
'value' => $talkTitle->getFullText(), |
| 963 |
] |
| 964 |
], |
| 965 |
'tag-name' => 'a', |
| 966 |
'classes' => 'talk button', |
| 967 |
'label' => $label, |
| 968 |
]; |
| 969 |
} |
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
protected function getSecondaryActions( array $contentNavigationUrls ): ?array { |
| 977 |
if ( $this->isFallbackEditor() || !$this->hasSecondaryActions() ) { |
| 978 |
return null; |
| 979 |
} |
| 980 |
|
| 981 |
$buttons = []; |
| 982 |
|
| 983 |
|
| 984 |
$title = $this->getTitle(); |
| 985 |
$subjectPage = Title::newFromLinkTarget( $this->namespaceInfo->getSubjectPage( $title ) ); |
| 986 |
$talkAtBottom = !$this->skinOptions->get( SkinOptions::TALK_AT_TOP ) || |
| 987 |
$subjectPage->isMainPage(); |
| 988 |
if ( !$this->skinUserPageHelper->isUserPage() && |
| 989 |
$this->permissions->isTalkAllowed() && $talkAtBottom && |
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
$this->getUser()->isRegistered() |
| 994 |
) { |
| 995 |
$namespaces = $contentNavigationUrls['associated-pages']; |
| 996 |
|
| 997 |
$subjectId = $title->getNamespaceKey( '' ); |
| 998 |
$talkId = $subjectId === 'main' ? 'talk' : "{$subjectId}_talk"; |
| 999 |
|
| 1000 |
if ( isset( $namespaces[$talkId] ) ) { |
| 1001 |
$talkButton = $namespaces[$talkId]; |
| 1002 |
$talkTitle = Title::newFromLinkTarget( $this->namespaceInfo->getTalkPage( $title ) ); |
| 1003 |
|
| 1004 |
$buttons['talk'] = $this->getTalkButton( $talkTitle, $talkButton['text'] ); |
| 1005 |
} |
| 1006 |
} |
| 1007 |
|
| 1008 |
if ( |
| 1009 |
$this->languagesHelper->doesTitleHasLanguagesOrVariants( $this->getOutput(), $title ) && |
| 1010 |
$title->isMainPage() |
| 1011 |
) { |
| 1012 |
$buttons['language'] = $this->getLanguageButton(); |
| 1013 |
} |
| 1014 |
|
| 1015 |
return $buttons; |
| 1016 |
} |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
protected function getJsConfigVars(): array { |
| 1023 |
return array_merge( parent::getJsConfigVars(), [ |
| 1024 |
'wgMinervaPermissions' => [ |
| 1025 |
'watchable' => $this->permissions->isAllowed( IMinervaPagePermissions::WATCHABLE ), |
| 1026 |
'watch' => $this->permissions->isAllowed( IMinervaPagePermissions::WATCH ), |
| 1027 |
], |
| 1028 |
'wgMinervaFeatures' => $this->skinOptions->getAll(), |
| 1029 |
'wgMinervaDownloadNamespaces' => $this->getConfig()->get( 'MinervaDownloadNamespaces' ), |
| 1030 |
] ); |
| 1031 |
} |
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
public function getDefaultModules(): array { |
| 1039 |
$modules = parent::getDefaultModules(); |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
if ( $this->getActionName() !== 'history' ) { |
| 1047 |
|
| 1048 |
$modules['content'] = array_diff( $modules['content'], [ |
| 1049 |
|
| 1050 |
'jquery.makeCollapsible', |
| 1051 |
|
| 1052 |
'mediawiki.toc' |
| 1053 |
] ); |
| 1054 |
|
| 1055 |
$modules['styles']['content'] = array_diff( $modules['styles']['content'], [ |
| 1056 |
|
| 1057 |
'jquery.makeCollapsible.styles', |
| 1058 |
] ); |
| 1059 |
} |
| 1060 |
|
| 1061 |
$modules['styles']['skin.page'] = $this->getPageSpecificStyles(); |
| 1062 |
$modules['styles']['skin.features'] = $this->getFeatureSpecificStyles(); |
| 1063 |
|
| 1064 |
return $modules; |
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
protected function getPageSpecificStyles(): array { |
| 1077 |
$styles = []; |
| 1078 |
$title = $this->getTitle(); |
| 1079 |
$request = $this->getRequest(); |
| 1080 |
$requestAction = $this->getActionName(); |
| 1081 |
$viewAction = $requestAction === 'view'; |
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
if ( |
| 1086 |
$title->getNamespace() !== NS_MAIN || |
| 1087 |
$request->getCheck( 'oldid' ) || |
| 1088 |
!$viewAction |
| 1089 |
) { |
| 1090 |
$styles[] = 'skins.minerva.messageBox.styles'; |
| 1091 |
} |
| 1092 |
|
| 1093 |
if ( $title->isMainPage() ) { |
| 1094 |
$styles[] = 'skins.minerva.mainPage.styles'; |
| 1095 |
} elseif ( $this->skinUserPageHelper->isUserPage() ) { |
| 1096 |
$styles[] = 'skins.minerva.userpage.styles'; |
| 1097 |
} |
| 1098 |
|
| 1099 |
if ( $this->getUser()->isRegistered() ) { |
| 1100 |
$styles[] = 'skins.minerva.loggedin.styles'; |
| 1101 |
} |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
if ( |
| 1108 |
|
| 1109 |
$title->isSpecialPage() || |
| 1110 |
( $this->isHistoryPage() && !$this->shouldUseSpecialHistory( $title ) ) || |
| 1111 |
$this->skinOptions->get( SkinOptions::PERSONAL_MENU ) || |
| 1112 |
$this->skinOptions->get( SkinOptions::TALK_AT_TOP ) || |
| 1113 |
$this->skinOptions->get( SkinOptions::HISTORY_IN_PAGE_ACTIONS ) || |
| 1114 |
$this->skinOptions->get( SkinOptions::TOOLBAR_SUBMENU ) |
| 1115 |
) { |
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
$styles[] = 'skins.minerva.amc.styles'; |
| 1120 |
} |
| 1121 |
|
| 1122 |
return $styles; |
| 1123 |
} |
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
protected function getFeatureSpecificStyles(): array { |
| 1135 |
$styles = []; |
| 1136 |
|
| 1137 |
if ( $this->hasCategoryLinks() ) { |
| 1138 |
$styles[] = 'skins.minerva.categories.styles'; |
| 1139 |
} |
| 1140 |
|
| 1141 |
if ( $this->skinOptions->get( SkinOptions::PERSONAL_MENU ) ) { |
| 1142 |
|
| 1143 |
|
| 1144 |
$styles[] = 'skins.minerva.personalMenu.icons'; |
| 1145 |
} |
| 1146 |
|
| 1147 |
if ( |
| 1148 |
$this->skinOptions->get( SkinOptions::MAIN_MENU_EXPANDED ) |
| 1149 |
) { |
| 1150 |
|
| 1151 |
|
| 1152 |
$styles[] = 'skins.minerva.mainMenu.advanced.icons'; |
| 1153 |
} |
| 1154 |
|
| 1155 |
if ( |
| 1156 |
$this->skinOptions->get( SkinOptions::PERSONAL_MENU ) || |
| 1157 |
$this->skinOptions->get( SkinOptions::TOOLBAR_SUBMENU ) |
| 1158 |
) { |
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
$styles[] = 'skins.minerva.overflow.icons'; |
| 1164 |
} |
| 1165 |
|
| 1166 |
return $styles; |
| 1167 |
} |
| 1168 |
} |