Glaisher has uploaded a new change for review.
https://gerrit.wikimedia.org/r/293901
Change subject: Use Config instead of globals
......................................................................
Use Config instead of globals
Change-Id: Ia01150e76e3a960841c096377d005521bbfdd4d0
---
M SpecialNotifyTranslators.php
M SpecialTranslatorSignup.php
M scripts/DigestEmailer.php
3 files changed, 36 insertions(+), 35 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TranslationNotifications
refs/changes/01/293901/1
diff --git a/SpecialNotifyTranslators.php b/SpecialNotifyTranslators.php
index 4049f6e..483f67d 100644
--- a/SpecialNotifyTranslators.php
+++ b/SpecialNotifyTranslators.php
@@ -420,19 +420,22 @@
* @return string Sinup URL
*/
protected function getSignupURL() {
- global $wgTranslationNotificationsAlwaysHttpsInEmail;
-
- $urlType = $wgTranslationNotificationsAlwaysHttpsInEmail ===
false ?
- PROTO_CANONICAL :
- PROTO_HTTPS;
-
$signupURL = SpecialPage::getTitleFor( 'TranslatorSignup'
)->getFullURL(
'',
false,
- $urlType
+ $this->getUrlProtocol()
);
return $signupURL;
+ }
+
+ /**
+ * @return string
+ */
+ protected function getUrlProtocol() {
+ return $this->getConfig()->get(
'TranslationNotificationsAlwaysHttpsInEmail' ) === false
+ ? PROTO_CANONICAL
+ : PROTO_HTTPS;
}
/**
@@ -440,13 +443,7 @@
* @return string Translation URL
*/
protected function getTranslationURL( $languageCode ) {
- global $wgTranslationNotificationsAlwaysHttpsInEmail;
-
$page = TranslatablePage::newFromTitle(
$this->translatablePageTitle );
- $urlType = $wgTranslationNotificationsAlwaysHttpsInEmail ===
false ?
- PROTO_CANONICAL :
- PROTO_HTTPS;
-
$translationURL = SpecialPage::getTitleFor( 'Translate'
)->getFullURL(
[
'group' => $page->getMessageGroupId(),
@@ -454,7 +451,7 @@
'action' => 'page'
],
false,
- $urlType
+ $this->getUrlProtocol()
);
return $translationURL;
@@ -552,8 +549,6 @@
protected function sendTranslationNotificationEmail( User $user,
$languagesToNotify = []
) {
- global $wgNoReplyAddress;
-
$relevantLanguages = $this->getRelevantLanguages( $user,
$languagesToNotify );
$userFirstLanguage = Language::factory(
$this->getUserFirstLanguage( $user ) );
$emailSubject = self::getNotificationSubject(
$userFirstLanguage );
@@ -583,7 +578,7 @@
// Do not publish the sender's email, but include his/her name
$emailFrom = new MailAddress(
- $wgNoReplyAddress,
+ $this->getConfig()->get( 'NoReplyAddress' ),
$sender->getName(),
$sender->getRealName()
);
@@ -628,12 +623,13 @@
$this->notificationText
);
- global $wgLocalInterwikis;
+
$titleForMessage = $this->translatablePageTitle;
- if ( $destination === 'talkpageInOtherWiki' && count(
$wgLocalInterwikis ) ) {
- $titleForMessage =
":$wgLocalInterwikis[0]:$titleForMessage|$titleForMessage";
+ $localInterwikis = $this->getConfig->get( 'LocalInterwikis' );
+ if ( $destination === 'talkpageInOtherWiki' && count(
$localInterwikis ) ) {
+ $titleForMessage =
":$localInterwikis[0]:$titleForMessage|$titleForMessage";
}
$text = $this->msg(
diff --git a/SpecialTranslatorSignup.php b/SpecialTranslatorSignup.php
index eaf9601..00df219 100644
--- a/SpecialTranslatorSignup.php
+++ b/SpecialTranslatorSignup.php
@@ -40,8 +40,6 @@
}
protected function alterForm( HTMLForm $form ) {
- global $wgTranslationNotificationsSignupLegalMessage;
-
$form->setWrapperLegend( false );
$form->setId( 'translationnotifications-form' );
$form->setSubmitID( 'translationnotifications-submit' );
@@ -49,21 +47,23 @@
// Override FormSpecialPage. Otherwise
'translationnotifications-text'
// shown on Special:NotifyTranslators is shown here
$form->setHeaderText( $this->msg( 'translatorsignup-summary'
)->parseAsBlock() );
+ }
- if ( $wgTranslationNotificationsSignupLegalMessage ) {
+ protected function postText() {
+ $legalMsg = $this->getConfig()->get(
'TranslationNotificationsSignupLegalMessage' );
+ if ( $legalMsg ) {
// Show the legal text regarding the notifications.
// Do not show if value is empty or false.
- $legalText = Html::rawElement(
+ return Html::rawElement(
'div',
[ 'class' => 'mw-infobox' ],
- $this->msg(
$wgTranslationNotificationsSignupLegalMessage )->parseAsBlock()
+ $this->msg( $legalMsg )->parseAsBlock()
);
- $form->addPostText( $legalText );
}
+ return '';
}
protected function getFormFields() {
- global $wgTranslationNotificationsContactMethods;
$this->getOutput()->addModules(
'ext.translationnotifications.translatorsignup' );
$user = $this->getUser();
@@ -130,7 +130,9 @@
}
}
- foreach ( $wgTranslationNotificationsContactMethods as $method
=> $value ) {
+ $config = $this->getConfig();
+ $contactMethods = $config->get(
'TranslationNotificationsContactMethods' );
+ foreach ( $contactMethods as $method => $value ) {
if ( $value === false ) {
continue;
}
@@ -150,8 +152,8 @@
$m["cmethod-$method"]['disabled'] =
!$user->canReceiveEmail();
}
- global $wgLocalInterwikis;
- if ( $method === 'talkpage-elsewhere' && count(
$wgLocalInterwikis ) ) {
+ $localInterwikis = $config->get( 'LocalInterwikis' );
+ if ( $method === 'talkpage-elsewhere' && count(
$localInterwikis ) ) {
$m['cmethod-talkpage-elsewhere-loc'] = [
'type' => 'select',
'default' => $user->getOption(
'translationnotifications-cmethod-talkpage-elsewhere-loc' ),
diff --git a/scripts/DigestEmailer.php b/scripts/DigestEmailer.php
index 8f95b93..a75d0ad 100644
--- a/scripts/DigestEmailer.php
+++ b/scripts/DigestEmailer.php
@@ -42,7 +42,12 @@
}
public function sendEmails( $translators, $notifications ) {
- global $wgNoReplyAddress,
$wgTranslationNotificationsAlwaysHttpsInEmail;
+ $config = $this->getConfig();
+ // Initialize early to avoid calling these repeatedly within
the loop
+ $noReplyAddress = $config->get( 'NoReplyAddress' );
+ $urlType = $config->get(
'TranslationNotificationsAlwaysHttpsInEmail' ) === false
+ ? PROTO_CANONICAL
+ : PROTO_HTTPS;
$mailstatus = [];
foreach ( $translators as $translator ) {
@@ -91,9 +96,7 @@
$this->output( "\tSending notification since " .
date( 'D M j G:i:s T Y', $startTimeStamp ) . "
\n" );
- $urlType =
$wgTranslationNotificationsAlwaysHttpsInEmail === false ?
- PROTO_CANONICAL :
- PROTO_HTTPS;
+
foreach ( $notifications as $notification ) {
$announcedate = strtotime(
$notification['announcedate'] );
@@ -179,7 +182,7 @@
$signupURL
)->inLanguage( $firstLangCode )->text();
- $emailFrom = new MailAddress( $wgNoReplyAddress );
+ $emailFrom = new MailAddress( $noReplyAddress );
$emailTo = new MailAddress( $user );
$params = [
'to' => $emailTo,
--
To view, visit https://gerrit.wikimedia.org/r/293901
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia01150e76e3a960841c096377d005521bbfdd4d0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TranslationNotifications
Gerrit-Branch: master
Gerrit-Owner: Glaisher <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits