Skip to content

Commit e6d60fa

Browse files
alistair3149claude
andcommitted
feat(share): ✨ integrate Extension:UrlShortener with the share panel
When the wiki has Extension:UrlShortener installed, the share panel gains two buttons below the copy-link field: - "Copy short URL" copies a shortened URL to the clipboard in one click and caches it for the rest of the dialog session. - "Show QR code" opens a focused QR view inside the same panel, with the short URL printed below as a fallback for anything that can't scan. Only shows when `$wgUrlShortenerEnableQrCode` is enabled. The copy-link field and the social share tiles always carry the full page URL — short URLs are reserved for the dedicated button and the QR view, so the social services receive the URL their previews and analytics expect. Implementation notes: - `useUrlShortener` composable wraps the shortenurl API. Caches the short URL and QR code separately because the API only shortens URLs above `$wgUrlShortenerQrCodeShortenLimit`, so a request for the QR can return only the QR data and no shortened URL. - `useDialogResizeAnimation` writes the dialog's inline height from a ResizeObserver on the Vue root so view swaps (default ↔️ QR) animate. Skips zero-height writes to prevent the next open from animating from 0 → measured height, and defers enabling the `height` transition to the next animation frame so the first inline write doesn't animate either. - Detection of the UrlShortener extension and the QR config flag is inlined into `ResourceLoaderHooks::getCitizenShareResourceLoaderConfig` and provided to the Vue app as `urlShortenerConfig`. - Success-state recolour: the copy field and the short-URL button both flip to the Codex success palette while carrying the "copied" label, so the affirmation is visible without reading. - Icon-style helpers extracted to `iconStyle.js` so they can be shared between the share tile grid and the new buttons. Tests cover the composables (cache hit/miss, API quirks, failure preserves cache), App.vue interaction paths, and the resize composable's close/reopen guard. Docs updated in `docs/src/customization/share.md` and `docs/src/config/extensions.md`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 97b5083 commit e6d60fa

18 files changed

Lines changed: 1485 additions & 158 deletions

File tree

docs/src/config/extensions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ Adds an Ask query mode to the command palette. Type `/smw:` to build structured
5454

5555
Only needed if you use [TemplateStyles](https://www.mediawiki.org/wiki/Extension:TemplateStyles). Enables CSS variables in TemplateStyles, including Citizen's design tokens.
5656

57+
### [UrlShortener](https://www.mediawiki.org/wiki/Extension:UrlShortener)
58+
59+
Adds a "Copy short URL" button to the share panel for one-click clipboard copy, plus a QR code view when `$wgUrlShortenerEnableQrCode` is enabled. See [Share](../features/share.md#short-urls-and-qr-codes) for details.
60+
5761
## Gadget enhancements
5862

5963
Some on-wiki gadgets pair particularly well with Citizen. Unlike extensions, gadgets are installed wiki-side (see [Extension:Gadgets](https://www.mediawiki.org/wiki/Extension:Gadgets)) and enabled per-user from `Special:Preferences`.

docs/src/features/share.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ When the panel opens, it always shows a copy-link field, so sharing always works
1717

1818
Citizen doesn't ship with a built-in service list. The right services depend on your audience — a German federated wiki may want Diaspora; a corporate intranet may want none at all. You pick.
1919

20+
## Short URLs and QR codes
21+
22+
When [Extension:UrlShortener](https://www.mediawiki.org/wiki/Extension:UrlShortener) is installed, the share panel adds two buttons below the copy-link field:
23+
24+
- **Copy short URL** — copies a shortened URL to the clipboard in one click. The result is reused for the rest of the session, so clicking again or reopening the panel is instant.
25+
- **Show QR code** — opens a focused QR view inside the same panel, with the short URL printed below as a fallback for anything that can't scan. Only appears when `$wgUrlShortenerEnableQrCode` is enabled.
26+
27+
The copy-link field and the share tiles always use the full page URL — short URLs are reserved for the dedicated button and the QR view. If UrlShortener isn't installed, neither button appears and the rest of the panel works the same.
28+
2029
## Adding share services
2130

2231
Create the page `MediaWiki:Citizen-share-services.json` on your wiki and paste a JSON array of service entries. Save the page, and the new services appear the next time anyone opens the panel.

i18n/en.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@
3737
"citizen-share": "Share this page",
3838
"citizen-share-copy-link": "Copy link",
3939
"citizen-share-copied": "URL copied to clipboard!",
40+
"citizen-share-copy-short-url": "Copy short URL",
41+
"citizen-share-short-url-copied": "Short URL copied!",
42+
"citizen-share-short-url-error": "Couldn't generate a short URL.",
43+
"citizen-share-show-qr": "Show QR code",
44+
"citizen-share-qr-title": "QR code",
45+
"citizen-share-qr-scan-hint": "Scan to open on another device",
46+
"citizen-share-qr-error": "Couldn't generate a QR code.",
47+
"citizen-share-qr-retry": "Try again",
48+
"citizen-share-back": "Back",
4049

4150
"citizen-tagline": "-",
4251
"citizen-tagline-ns-talk": "Discussion page of {{SUBJECTPAGENAME}}",

i18n/qqq.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@
4242
"citizen-share": "Label for button to share the current page",
4343
"citizen-share-copy-link": "Label for button to copy the current URL to the clipboard",
4444
"citizen-share-copied": "Message to notify users that the current URL is copied to the clipboard",
45+
"citizen-share-copy-short-url": "Label for a button in the share panel that fetches a shortened URL from Extension:UrlShortener and writes it to the clipboard.",
46+
"citizen-share-short-url-copied": "Confirmation label shown briefly in the same button after a successful short-URL copy.",
47+
"citizen-share-short-url-error": "Toast notification shown when the share panel fails to fetch a short URL from Extension:UrlShortener (e.g. URL not in the allowed-domains list).",
48+
"citizen-share-show-qr": "Label for a button in the share panel that switches the panel to a focused QR-code view.",
49+
"citizen-share-qr-title": "Heading shown at the top of the QR-code view inside the share panel.",
50+
"citizen-share-qr-scan-hint": "Helper text shown beside the QR code suggesting that the user scan it with another device (e.g. a phone).",
51+
"citizen-share-qr-error": "Error message shown in the QR-code view when fetching the QR code from Extension:UrlShortener fails.",
52+
"citizen-share-qr-retry": "Label on the retry button shown when the QR code fails to load.",
53+
"citizen-share-back": "Accessible label / tooltip for the back-arrow button that returns the share panel from the QR view to the default share view.",
4554
"citizen-tagline": "{{notranslate}}\n\nTagline for Citizen skin only",
4655
"citizen-tagline-ns-talk": "Tagline for pages in talk namespace",
4756
"citizen-tagline-ns-project": "Tagline for pages in project namespace",

includes/Hooks/ResourceLoaderHooks.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function getCitizenCommandPaletteResourceLoaderConfig(
7373
* Passes config variables to skins.citizen.share ResourceLoader module.
7474
* @param RL\Context $context
7575
* @param Config $config
76-
* @return array
76+
* @return array{services: array, urlShortener: array{available: bool, qrAvailable: bool}}
7777
*/
7878
public static function getCitizenShareResourceLoaderConfig(
7979
RL\Context $context,
@@ -88,7 +88,19 @@ public static function getCitizenShareResourceLoaderConfig(
8888
$mwServices->getUrlUtils()
8989
);
9090

91-
return $provider->getServiceOptions() ?? [];
91+
$extensionRegistry = ExtensionRegistry::getInstance();
92+
$urlShortenerLoaded = $extensionRegistry->isLoaded( 'UrlShortener' );
93+
$qrAvailable = $urlShortenerLoaded
94+
&& $config->has( 'UrlShortenerEnableQrCode' )
95+
&& (bool)$config->get( 'UrlShortenerEnableQrCode' );
96+
97+
return [
98+
'services' => $provider->getServiceOptions() ?? [],
99+
'urlShortener' => [
100+
'available' => $urlShortenerLoaded,
101+
'qrAvailable' => $qrAvailable,
102+
],
103+
];
92104
}
93105

94106
/**

0 commit comments

Comments
 (0)