Skip to content

Commit

Permalink
Introduce configurations for phases
Browse files Browse the repository at this point in the history
  • Loading branch information
lens0021 committed Jul 29, 2021
1 parent dbedfd8 commit 393fd3e
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 12 deletions.
4 changes: 3 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
"femiwiki.css": "/* CSS placed here will affect users of the Femiwiki skin */",
"femiwiki.js": "/* Any JavaScript here will be loaded for users using the Femiwiki skin */",
"skin-femiwiki-desktop-switch-confirm": "Editing in mobile view is not supported yet. Would {{GENDER:|you}} like to switch to desktop view?",
"skin-femiwiki-desktop-switch-canceled": "Editing is canceled."
"skin-femiwiki-desktop-switch-canceled": "Editing is canceled.",
"prefs-femiwiki-large-elements-label": "User Larger Elements",
"prefs-femiwiki-large-elements-help": "The elements on the screen will be replaced by larger ones. This option lets you preview large elements."
}
4 changes: 3 additions & 1 deletion i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
"skin-femiwiki-share-facebook": "페이스북",
"skin-femiwiki-share-twitter": "트위터",
"skin-femiwiki-desktop-switch-confirm": "모바일 보기에서는 이 편집이 아직 지원되지 않습니다. 데스크톱 보기로 전환하시겠습니까?",
"skin-femiwiki-desktop-switch-canceled": "편집이 취소되었습니다."
"skin-femiwiki-desktop-switch-canceled": "편집이 취소되었습니다.",
"prefs-femiwiki-large-elements-label": "더 큰 요소 사용",
"prefs-femiwiki-large-elements-help": "화면의 요소들이 더 큰 요소들로 교체될 것입니다. 이 옵션은 큰 요소들을 미리 표시하게 합니다."
}
4 changes: 3 additions & 1 deletion i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@
"femiwiki.css": "",
"femiwiki.js": "",
"skin-femiwiki-desktop-switch-confirm": "Confirm text for dialog to switch desktop view when the user tried to edit in mobile view",
"skin-femiwiki-desktop-switch-canceled": "Text for notification that is shown switching for editing is canceled."
"skin-femiwiki-desktop-switch-canceled": "Text for notification that is shown switching for editing is canceled.",
"prefs-femiwiki-large-elements-label": "Label for the checkbox to enable larger elements via Special:Preferences.",
"prefs-femiwiki-large-elements-help": "Detail explaining the operation of the prefs-femiwiki-large-elements-label checkbox."
}
7 changes: 6 additions & 1 deletion includes/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ final class Constants {
/**
* @var string
*/
public const COOKIE_KEY_USE_LEGACY = 'UseLegacy';
public const CONFIG_KEY_SMALL_ELEMENTS_FOR_ANONYMOUS_USER = 'FemiwikiLegacySmallElementsForAnonymousUser';

/**
* @var string
*/
public const PREF_KEY_LARGER_ELEMENTS = "FemiwikiUseLargerElements";
}
13 changes: 10 additions & 3 deletions includes/SkinFemiwiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,22 @@ class SkinFemiwiki extends SkinMustache {
* @inheritDoc
*/
public function __construct( $options = [] ) {
$loggedIn = $this->getUser()->isLoggedIn();
$user = $this->getUser();
$loggedIn = $user->isLoggedIn();
$config = $this->getConfig();
$userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();

if ( $loggedIn ) {
$options['scripts'][] = 'skins.femiwiki.notifications';
}
if ( $this->shouldShowShare() ) {
$options['scripts'][] = 'skins.femiwiki.share';
}
if ( $loggedIn && $this->getRequest()->getCookie( Constants::COOKIE_KEY_USE_LEGACY ) ) {
$options['styles'][] = 'skins.femiwiki.legacy';
if (
( !$loggedIn && $config->get( Constants::CONFIG_KEY_SMALL_ELEMENTS_FOR_ANONYMOUS_USER ) )
|| ( $loggedIn && $userOptionsLookup->getOption( $user, Constants::PREF_KEY_LARGER_ELEMENTS, '0' ) === '0' )
) {
$options['styles'][] = 'skins.femiwiki.smallElements';
}
parent::__construct( $options );
}
Expand Down
30 changes: 30 additions & 0 deletions includes/SmallElementsHooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace MediaWiki\Skins\Femiwiki;

class SmallElementsHooks implements \MediaWiki\Preferences\Hook\GetPreferencesHook {
/**
* @inheritDoc
*/
public function onGetPreferences( $user, &$preferences ) {
$newPrefs = [
Constants::PREF_KEY_LARGER_ELEMENTS => [
'type' => 'toggle',
'label-message' => 'prefs-femiwiki-large-elements-label',
'help-message' => 'prefs-femiwiki-large-elements-help',
'section' => 'rendering/skin/skin-prefs',
'hide-if' => [ '!==', 'wpskin', Constants::SKIN_NAME ],
]
];

$skinSectionIndex = array_search( 'skin', array_keys( $prefs ) );
if ( $skinSectionIndex !== false ) {
$newSectionIndex = $skinSectionIndex + 1;
$preferences = array_slice( $preferences, 0, $newSectionIndex, true )
+ $newPrefs
+ array_slice( $preferences, $newSectionIndex, null, true );
} else {
$preferences += $newPrefs;
}
}
}
File renamed without changes.
16 changes: 11 additions & 5 deletions skin.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@
"print.less"
]
},
"skins.femiwiki.legacy": {
"skins.femiwiki.smallElements": {
"class": "ResourceLoaderSkinModule",
"features": {
"content-parser-output": false,
"toc": false
},
"targets": ["desktop", "mobile"],
"position": "top",
"styles": ["skins.femiwiki.legacy/styles.less"]
"styles": ["skins.femiwiki.smallElements/styles.less"]
},
"skins.femiwiki.xeicon": {
"class": "ResourceLoaderSkinModule",
Expand Down Expand Up @@ -182,7 +182,11 @@
}
},
"HookHandlers": {
"default": { "class": "MediaWiki\\Skins\\Femiwiki\\Hooks" }
"default": { "class": "MediaWiki\\Skins\\Femiwiki\\Hooks" },
"SmallElements": {
"class": "MediaWiki\\Skins\\Femiwiki\\SmallElementsHooks",
"services": ["UserOptionsLookup"]
}
},
"Hooks": {
"BeforePageDisplay": "MediaWiki\\Skins\\Femiwiki\\Hooks::onBeforePageDisplay",
Expand All @@ -191,7 +195,8 @@
"PersonalUrls": "MediaWiki\\Skins\\Femiwiki\\Hooks::onPersonalUrls",
"ResourceLoaderGetConfigVars": "MediaWiki\\Skins\\Femiwiki\\Hooks::onResourceLoaderGetConfigVars",
"UserMailerTransformContent": "MediaWiki\\Skins\\Femiwiki\\Hooks::onUserMailerTransformContent",
"SkinTemplateNavigation": "MediaWiki\\Skins\\Femiwiki\\Hooks::onSkinTemplateNavigation"
"SkinTemplateNavigation": "MediaWiki\\Skins\\Femiwiki\\Hooks::onSkinTemplateNavigation",
"GetPreferences": "SmallElements"
},
"config": {
"FemiwikiFirebaseKey": { "value": "" },
Expand All @@ -200,7 +205,8 @@
"FemiwikiHeadItems": { "value": false },
"FemiwikiAddThisId": { "value": false },
"FemiwikiUsePageLangForHeading": { "value": true },
"FemiwikiShowFooterIcons": { "value": false }
"FemiwikiShowFooterIcons": { "value": false },
"FemiwikiLegacySmallElementsForAnonymousUser": { "value": true }
},
"OOUIThemePaths": {
"Femiwiki": {
Expand Down

0 comments on commit 393fd3e

Please sign in to comment.