From a5aa25039f54a2f32eccdf489b375e91ca02f018 Mon Sep 17 00:00:00 2001 From: Lens0021 / Leslie Date: Tue, 30 May 2023 22:27:46 +0900 Subject: [PATCH] Replace AddThis with navigator.share (#715) --- CHANGELOG.md | 4 ++ includes/Constants.php | 2 - includes/HookHandler/DefaultHooks.php | 7 -- includes/SkinFemiwiki.php | 13 ---- includes/templates/skin.mustache | 4 -- .../mw.fw.ShareDialog.js | 66 +++++++------------ resources/skins.femiwiki.share/init.js | 65 ++++++++---------- skin.json | 6 +- 8 files changed, 53 insertions(+), 114 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 003e3c6d..22344c9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Versions and bullets are arranged chronologically from latest to oldest. +## 3.3.0 + +- AddThis is removed. Instead, Web Share API will be used on supported browsers. (https://github.com/femiwiki/FemiwikiSkin/pull/714) + ## 3.2.0 - Make `
` tag visible on localNotice (https://github.com/femiwiki/FemiwikiSkin/pull/700) diff --git a/includes/Constants.php b/includes/Constants.php index abdddd97..96f16dcb 100644 --- a/includes/Constants.php +++ b/includes/Constants.php @@ -19,8 +19,6 @@ final class Constants { /** @var string */ public const CONFIG_ADD_LINK_CLASS = 'FemiwikiAddLinkClass'; /** @var string */ - public const CONFIG_ADD_THIS_ID = 'FemiwikiAddThisId'; - /** @var string */ public const CONFIG_FIREBASE_KEY = 'FemiwikiFirebaseKey'; /** @var string */ public const CONFIG_HEAD_ITEMS = 'FemiwikiHeadItems'; diff --git a/includes/HookHandler/DefaultHooks.php b/includes/HookHandler/DefaultHooks.php index 2b7762aa..39141fd1 100644 --- a/includes/HookHandler/DefaultHooks.php +++ b/includes/HookHandler/DefaultHooks.php @@ -27,15 +27,8 @@ public function __construct( ConfigFactory $configFactory ) { */ public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void { $firebaseKey = $config->get( Constants::CONFIG_FIREBASE_KEY ); - $addThisId = $config->get( Constants::CONFIG_ADD_THIS_ID ); $vars['wgFemiwikiFirebaseKey'] = $firebaseKey; - if ( $addThisId ) { - $vars['wgFemiwikiUseAddThis'] = true; - if ( is_array( $addThisId ) && isset( $addThisId['tool'] ) ) { - $vars['wgFemiwikiAddThisToolId'] = $addThisId['tool']; - } - } } /** diff --git a/includes/SkinFemiwiki.php b/includes/SkinFemiwiki.php index e13ab926..f9396fe1 100644 --- a/includes/SkinFemiwiki.php +++ b/includes/SkinFemiwiki.php @@ -57,7 +57,6 @@ public function getTemplateData(): array { 'html-share-button' => $this->getShare(), 'data-toolbox' => $toolbox, 'html-lastmod' => $this->lastModified(), - 'text-add-this-pub-id' => $this->getAddThisPubId(), 'has-footer-icons' => $config->get( Constants::CONFIG_KEY_SHOW_FOOTER_ICONS ), 'has-indicator' => count( $parentData['array-indicators'] ) !== 0, @@ -179,16 +178,4 @@ public function initPage( OutputPage $out ) { $out->enableOOUI(); parent::initPage( $out ); } - - /** @return string|null */ - private function getAddThisPubId() { - $config = $this->getConfig()->get( Constants::CONFIG_ADD_THIS_ID ); - if ( !$config ) { - return null; - } - if ( is_array( $config ) ) { - return $config['pub'] ?? null; - } - return $config; - } } diff --git a/includes/templates/skin.mustache b/includes/templates/skin.mustache index 6064fa5d..5539c52c 100644 --- a/includes/templates/skin.mustache +++ b/includes/templates/skin.mustache @@ -17,7 +17,3 @@ {{/data-portlets.data-languages}} {{>Footer}} - -{{#text-add-this-pub-id}} - -{{/text-add-this-pub-id}} diff --git a/resources/skins.femiwiki.share.ui/mw.fw.ShareDialog.js b/resources/skins.femiwiki.share.ui/mw.fw.ShareDialog.js index f98ad56b..6b7ff16e 100644 --- a/resources/skins.femiwiki.share.ui/mw.fw.ShareDialog.js +++ b/resources/skins.femiwiki.share.ui/mw.fw.ShareDialog.js @@ -8,8 +8,6 @@ // Configuration initialization config = config || {}; - this.useAddThis = config.useAddThis; - this.addThisToolId = config.addThisToolId; this.firebaseKey = config.firebaseKey; // Parent constructor @@ -32,29 +30,17 @@ this.$element.addClass('mw-fw-ui-shareDialog'); // Make SNS Buttons - if (this.useAddThis) { - // AddThis - this.$addThis = document.createElement('div'); - this.$addThis.classList.add('addthis_inline_share_toolbox'); - if (this.addThisToolId) { - this.$addThis.classList.add( - 'addthis_inline_share_toolbox_' + this.addThisToolId - ); - } - addthis.layers.refresh(); - } else { - var items = []; - this.twitterButton = new OO.ui.ButtonWidget({ - framed: false, - icon: 'newWindow', - label: mw.msg('skin-femiwiki-share-twitter'), - }); - items.push(this.twitterButton); - this.twitterButton.$element.addClass('mw-fw-ui-twitterButton'); - this.mediaButtonGroup = new OO.ui.ButtonGroupWidget({ - items: items, - }); - } + var items = []; + this.twitterButton = new OO.ui.ButtonWidget({ + framed: false, + icon: 'newWindow', + label: mw.msg('skin-femiwiki-share-twitter'), + }); + items.push(this.twitterButton); + this.twitterButton.$element.addClass('mw-fw-ui-twitterButton'); + this.mediaButtonGroup = new OO.ui.ButtonGroupWidget({ + items: items, + }); // Create a TextForm to copy this.urlWidget = new OO.ui.TextInputWidget({ @@ -69,11 +55,7 @@ }); // Append elements - if (this.useAddThis) { - this.content.$element.append(this.$addThis); - } else { - this.content.$element.append(this.mediaButtonGroup.$element); - } + this.content.$element.append(this.mediaButtonGroup.$element); this.content.$element.append(this.urlWidget.$element); this.$body.append(this.content.$element); }; @@ -106,20 +88,16 @@ mw.fw.ShareDialog.prototype.updateUrl = function (url) { this.urlWidget.setValue(url); - if (this.useAddThis) { - addthis.layers.refresh(url); - } else { - var tweet = - mw.config.get('wgPageName').replace(/_/g, ' ') + - ' ' + - url + - ' #' + - mw.config.get('wgSiteName'); - - this.twitterButton.setHref( - 'https://twitter.com/intent/tweet?text=' + encodeURIComponent(tweet) - ); - } + var tweet = + mw.config.get('wgPageName').replace(/_/g, ' ') + + ' ' + + url + + ' #' + + mw.config.get('wgSiteName'); + + this.twitterButton.setHref( + 'https://twitter.com/intent/tweet?text=' + encodeURIComponent(tweet) + ); }; mw.fw.ShareDialog.prototype.createShortUrl = function (url) { diff --git a/resources/skins.femiwiki.share/init.js b/resources/skins.femiwiki.share/init.js index a1e60b05..4fb83e4a 100644 --- a/resources/skins.femiwiki.share/init.js +++ b/resources/skins.femiwiki.share/init.js @@ -3,49 +3,36 @@ function init() { OO.ui.infuse($('#p-share')).on('click', function () { - var windowManager, shareDialog; - var firebaseKey = firebaseKey || mw.config.get('wgFemiwikiFirebaseKey'); - var useAddThis = useAddThis || mw.config.get('wgFemiwikiUseAddThis'); - var addThisToolId = - addThisToolId || mw.config.get('wgFemiwikiAddThisToolId'); + if (navigator.share) { + navigator.share({ + url: window.location.href, + title: mw.config.get('wgPageName').replace(/_/g, ' '), + }); + } else { + var windowManager, shareDialog; + var firebaseKey = firebaseKey || mw.config.get('wgFemiwikiFirebaseKey'); - if (useAddThis) { - addthis_config = addthis_config || {}; - addthis_config['services_exclude'] = 'print'; - addthis_config['ui_language'] = mw.config.get('wgUserLanguage'); - addthis_share = addthis_share || {}; - addthis_share = { - passthrough: { - twitter: { - text: mw.config.get('wgPageName').replace(/_/g, ' '), - hashtags: mw.config.get('wgSiteName'), - }, - }, - }; - } + mw.loader.using(['skins.femiwiki.share.ui']).done(function () { + windowManager = windowManager || OO.ui.getWindowManager(); + if (shareDialog === undefined) { + shareDialog = new mw.fw.ShareDialog({ + firebaseKey: firebaseKey, + }); + windowManager.addWindows([shareDialog]); + } - mw.loader.using(['skins.femiwiki.share.ui']).done(function () { - windowManager = windowManager || OO.ui.getWindowManager(); - if (shareDialog === undefined) { - shareDialog = new mw.fw.ShareDialog({ - useAddThis: useAddThis, - addThisToolId: addThisToolId, - firebaseKey: firebaseKey, + windowManager.openWindow(shareDialog, { + url: window.location.href, + actions: [ + { + action: 'accept', + label: mw.msg('skin-femiwiki-share-dismiss'), + flags: 'primary', + }, + ], }); - windowManager.addWindows([shareDialog]); - } - - windowManager.openWindow(shareDialog, { - url: window.location.href, - actions: [ - { - action: 'accept', - label: mw.msg('skin-femiwiki-share-dismiss'), - flags: 'primary', - }, - ], }); - }); + } }); } diff --git a/skin.json b/skin.json index 72657bb6..d89424ab 100644 --- a/skin.json +++ b/skin.json @@ -4,7 +4,7 @@ "namemsg": "skinname-femiwiki", "type": "skin", "author": "[https://femiwiki.com/ Femiwiki Team]", - "version": "3.2.0", + "version": "3.3.0", "url": "https://github.com/femiwiki/FemiwikiSkin", "descriptionmsg": "femiwiki-desc", "license-name": "AGPL-3.0-or-later", @@ -228,10 +228,6 @@ "value": false, "description": "@var array Additional head items used as parameter for OutputPage::addHeadItems()." }, - "FemiwikiAddThisId": { - "value": false, - "description": "@var array with keys,'pub': An AddThis profile ID., 'tool': An toolbox id. See https://www.addthis.com/academy/how-to-install-addthis-code/." - }, "FemiwikiUsePageLangForHeading": { "value": true, "description": "@var boolean Use the page language for the page heading. See https://phabricator.wikimedia.org/T36514 for further problems."