Skip to content

Commit

Permalink
Replace AddThis with navigator.share (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
lens0021 authored May 30, 2023
1 parent 491ac40 commit a5aa250
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 114 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<hr>` tag visible on localNotice (https://github.com/femiwiki/FemiwikiSkin/pull/700)
Expand Down
2 changes: 0 additions & 2 deletions includes/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 0 additions & 7 deletions includes/HookHandler/DefaultHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}
}

/**
Expand Down
13 changes: 0 additions & 13 deletions includes/SkinFemiwiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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;
}
}
4 changes: 0 additions & 4 deletions includes/templates/skin.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,3 @@
{{/data-portlets.data-languages}}

{{>Footer}}

{{#text-add-this-pub-id}}
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid={{text-add-this-pub-id}}"></script>
{{/text-add-this-pub-id}}
66 changes: 22 additions & 44 deletions resources/skins.femiwiki.share.ui/mw.fw.ShareDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// Configuration initialization
config = config || {};

this.useAddThis = config.useAddThis;
this.addThisToolId = config.addThisToolId;
this.firebaseKey = config.firebaseKey;

// Parent constructor
Expand All @@ -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({
Expand All @@ -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);
};
Expand Down Expand Up @@ -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) {
Expand Down
65 changes: 26 additions & 39 deletions resources/skins.femiwiki.share/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
});
});
}
});
}

Expand Down
6 changes: 1 addition & 5 deletions skin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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."
Expand Down

0 comments on commit a5aa250

Please sign in to comment.