Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/91549
Change subject: Add Special:Thanks as a non-JS fallback
......................................................................
Add Special:Thanks as a non-JS fallback
If the user has JavaScript disabled, clicking
on "thank" will send the user to Special:Thanks
with the revision id already filled in. When
submitted, the form calls the API internally
and then shows the user an error or confirmation
message.
The API was modified to return the user ID of the
editor who is being thanked if a new notification
was created.
Bug: 49161
Change-Id: I7ba4664b92bb0da425784350487ed0e7ca352b4e
---
M ApiThank.php
A SpecialThanks.php
M Thanks.hooks.php
M Thanks.i18n.php
M Thanks.php
5 files changed, 101 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Thanks
refs/changes/49/91549/1
diff --git a/ApiThank.php b/ApiThank.php
index 7febee5..7550981 100644
--- a/ApiThank.php
+++ b/ApiThank.php
@@ -63,6 +63,7 @@
$agent->getRequest()->setSessionData(
"thanks-thanked-{$rev->getId()}", true );
// Set success message
$result['success'] = '1';
+ $result['recipient'] = $recipient;
// Log it if we're supposed to log it
if ( $wgThanksLogging ) {
$logEntry = new ManualLogEntry(
'thanks', 'thank' );
diff --git a/SpecialThanks.php b/SpecialThanks.php
new file mode 100644
index 0000000..3b5dfc4
--- /dev/null
+++ b/SpecialThanks.php
@@ -0,0 +1,89 @@
+<?php
+
+class SpecialThanks extends FormSpecialPage {
+
+ /** @var array $result */
+ protected $result;
+
+ public function __construct() {
+ parent::__construct( 'Thanks' );
+ }
+
+ /**
+ * HTMLForm fields
+ * @return Array
+ */
+ protected function getFormFields() {
+ return array(
+ 'revid' => array(
+ 'id' => 'mw-thanks-form-revid',
+ 'name' => 'spamlist',
+ 'type' => 'text',
+ 'label-message' => 'thanks-form-revid',
+ 'default' => $this->getRequest()->getText(
'revid' ),
+ )
+ );
+ }
+
+ /**
+ * Make it look pretty
+ * @param HTMLForm $form
+ */
+ protected function alterForm( HTMLForm $form ) {
+ $form->setDisplayFormat( 'vform' );
+ $form->setWrapperLegend( false );
+ }
+
+ /**
+ * Calls the API internally
+ * @param array $data
+ * @return Status
+ */
+ public function onSubmit( array $data ) {
+ if ( !isset( $data['revid'] ) ) {
+ return Status::newFatal( 'thanks-error-invalidrevision'
);
+ }
+
+ $request = new DerivativeRequest(
+ $this->getRequest(),
+ array(
+ 'action' => 'thank',
+ 'rev' => (int)$data['revid'],
+ 'source' => 'specialpage',
+ 'token' => $this->getUser()->getEditToken(),
+ ),
+ true
+ );
+
+ $api = new ApiMain(
+ $request,
+ true // enable write?
+ );
+
+ try {
+ $api->execute();
+ } catch ( UsageException $e ) {
+ return Status::newFatal( $e->getCodeString() );
+ }
+
+ $result = $api->getResult()->getData();
+ $this->result = $result['result'];
+
+ return Status::newGood();
+
+ }
+
+ /**
+ * Display a message to the user
+ */
+ public function onSuccess() {
+ $out = $this->getOutput();
+ if ( !isset( $this->result['recipient'] ) ) {
+ $out->addWikiMsg( 'thanks-already-thanked',
$this->getUser()->getName() );
+ } else {
+ $recipient = User::newFromId(
$this->result['recipient'] );
+ $link = '[[User:' . $recipient->getName() . '|' .
$recipient->getName() . ']]';
+ $out->addWikiMsg( 'thanks-thanked-notice', $link,
$recipient );
+ }
+ }
+}
\ No newline at end of file
diff --git a/Thanks.hooks.php b/Thanks.hooks.php
index 63b13b5..7fc9121 100644
--- a/Thanks.hooks.php
+++ b/Thanks.hooks.php
@@ -66,7 +66,7 @@
'a',
array(
'class' => 'mw-thanks-thank-link',
- 'href' => '#',
+ 'href' => Title::newFromText( 'Special:Thanks'
)->getFullURL( array( 'revid' => $rev->getId() )),
'title' => $tooltip,
'data-revision-id' => $rev->getId(),
),
diff --git a/Thanks.i18n.php b/Thanks.i18n.php
index 4ad56dc..1d739c1 100644
--- a/Thanks.i18n.php
+++ b/Thanks.i18n.php
@@ -23,6 +23,9 @@
'thanks-thank-tooltip' => '{{GENDER:$1|Send}} a thank you notification
to this {{GENDER:$2|user}}',
'thanks-confirmation' => 'Do you want to {{GENDER:$1|thank}} $2 for
this edit?',
'thanks-thanked-notice' => '$1 was notified that you liked
{{GENDER:$2|his|her|their}} edit.',
+ 'thanks' => 'Send thanks',
+ 'thanks-form-revid' => 'Revision ID for edit',
+ 'thanks-already-thanked' => '{{GENDER:$1|You}} have already sent thanks
for this edit.',
'echo-pref-subscription-edit-thank' => 'Thanks me for my edit',
'echo-pref-tooltip-edit-thank' => 'Notify me when someone thanks me for
an edit I made.',
'echo-category-title-edit-thank' => 'Thanks',
@@ -82,6 +85,9 @@
Parameters:
* $1 - the username of the user that was thanked
* $2 - the gender of the user that was thanked',
+ 'thanks' => '{{doc-special|Thanks}}',
+ 'thanks-form-revid' => 'Label for form field where the user inputs the
revision id',
+ 'thanks-already-thanked' => 'Message shown to user if they have already
sent thanks for this edit. $1 is the user\'s username.',
'echo-pref-subscription-edit-thank' => 'Option for getting
notifications when someone thanks the user for their edit.
This is the conclusion of the sentence begun by the header:
{{msg-mw|Prefs-echosubscriptions}}.',
diff --git a/Thanks.php b/Thanks.php
index f79a2aa..66db6b4 100644
--- a/Thanks.php
+++ b/Thanks.php
@@ -45,11 +45,15 @@
$wgAutoloadClasses['EchoThanksFormatter'] = $dir . '/ThanksFormatter.php';
$wgAutoloadClasses['ApiThank'] = $dir . '/ApiThank.php';
$wgAutoloadClasses['ThanksLogFormatter'] = $dir . '/ThanksLogFormatter.php';
+$wgAutoloadClasses['SpecialThanks'] = $dir . '/SpecialThanks.php';
$wgExtensionMessagesFiles['Thanks'] = $dir . '/Thanks.i18n.php';
// Register APIs
$wgAPIModules['thank'] = 'ApiThank';
+// Register special page
+$wgSpecialPages['Thanks'] = 'SpecialThanks';
+
// Register hooks
$wgHooks['HistoryRevisionTools'][] = 'ThanksHooks::insertThankLink';
$wgHooks['DiffRevisionTools'][] = 'ThanksHooks::insertThankLink';
--
To view, visit https://gerrit.wikimedia.org/r/91549
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7ba4664b92bb0da425784350487ed0e7ca352b4e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Thanks
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits