diff --git a/admin.php b/admin.php
index 1fe5fe3..eacb9f2 100644
--- a/admin.php
+++ b/admin.php
@@ -5,6 +5,18 @@
defined('PHPWG_ROOT_PATH') or exit(1);
+/**
+ * Get a HTTP user-agent that conforms to the WMF User-Agent Policy.
+ * @link https://foundation.wikimedia.org/wiki/Policy:Wikimedia_Foundation_User-Agent_Policy
+ * @return string
+ */
+function wikimediacommons_useragent(): string
+{
+ $user_prefs = userprefs_get_param(WIKIMEDIACOMMONS_ID);
+ $username = isset($user_prefs['username']) ? 'User:'.$user_prefs['username'] : '';
+ return trim('piwigo/wikimedia-commons-plugin '.get_absolute_root_url().' '.$username);
+}
+
// Main navigation.
$tab = $_GET['tab'] ?? 'settings';
if (in_array($tab, array('settings', 'oauth'))) {
diff --git a/admin/oauth.php b/admin/oauth.php
index 7686ca9..570febd 100644
--- a/admin/oauth.php
+++ b/admin/oauth.php
@@ -20,7 +20,7 @@
$conf[WIKIMEDIACOMMONS_ID]['key'],
$conf[WIKIMEDIACOMMONS_ID]['secret']
));
-$oauth_client_conf->setUserAgent('piwigo/wikimedia-commons-plugin '.get_absolute_root_url());
+$oauth_client_conf->setUserAgent(wikimediacommons_useragent());
$client = new Client($oauth_client_conf);
if (isset($_GET['returnto'])) {
$client->setCallback(WIKIMEDIACOMMONS_ADMIN.'-oauth&returnto='.urlencode($_GET['returnto']));
diff --git a/admin/photo.php b/admin/photo.php
index d0efd2f..335a3d5 100644
--- a/admin/photo.php
+++ b/admin/photo.php
@@ -3,9 +3,9 @@
defined('PHPWG_ROOT_PATH') or exit(1);
use Addwiki\Mediawiki\Api\Client\Action\Request\ActionRequest;
-use Addwiki\Mediawiki\Api\Client\Auth\OAuthOwnerConsumer;
use Addwiki\Mediawiki\Api\Client\MediaWiki;
use Piwigo\Plugin\WikimediaCommons\CommonsFileUploader;
+use Piwigo\Plugin\WikimediaCommons\OAuthOwnerConsumer;
check_status(ACCESS_ADMINISTRATOR);
@@ -87,7 +87,7 @@ function getWikitext($row): string
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound
$information = "{{Information\n"
."| description = \n"
- ."| date = {{taken on|".$row['date_creation']."|locationn=}}\n"
+ ."| date = {{taken on|".$row['date_creation']."|location=}}\n"
."| source = $source\n"
."| author = ".$row['author']."\n"
."| permission = \n"
@@ -134,6 +134,7 @@ function uploadToCommons(array $row, string $title, string $text, string $captio
$user_prefs['access_key'],
$user_prefs['access_secret']
);
+ $auth_method->setIdentifierForUserAgent(wikimediacommons_useragent());
$api = MediaWiki::newFromPage(
$conf[WIKIMEDIACOMMONS_ID]['endpoint'],
$auth_method
diff --git a/language/en_UK/plugin.lang.php b/language/en_UK/plugin.lang.php
index 2cef0e1..9e88a92 100644
--- a/language/en_UK/plugin.lang.php
+++ b/language/en_UK/plugin.lang.php
@@ -14,6 +14,7 @@
$lang['Key:'] = 'Key:';
$lang['Secret:'] = 'Secret:';
$lang['With this form you can upload a photo from here to Wikimedia Commons.'] = 'With this form you can upload a photo from here to Wikimedia Commons.';
+$lang['Connect to Wikimedia Commons'] = 'Connect to Wikimedia Commons';
$lang['You are logged in as %s.'] = 'You are logged in as %s.';
$lang['Disconnect from Wikimedia Commons.'] = 'Disconnect from Wikimedia Commons.';
$lang['Filename on Commons:'] = 'Filename on Commons:';
diff --git a/main.inc.php b/main.inc.php
index a703c46..7c264bf 100644
--- a/main.inc.php
+++ b/main.inc.php
@@ -1,7 +1,7 @@
identifierForUserAgent = $identifier;
+ }
+
+ public function identifierForUserAgent(): ?string {
+ return $this->identifierForUserAgent ?? parent::identifierForUserAgent();
+ }
+}