Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/78946
Change subject: [WIP] Allow the user to provide a translatable page as the
message text
......................................................................
[WIP] Allow the user to provide a translatable page as the message text
The user would just put the page name in the subject and body fields of the
form.
The preview would show the message in English, but the message will be sent in
the content language ($wgLanguageCode).
Change-Id: Ia95b63ad99b796721630233d158899f9477ca1ba
---
M SpecialMassMessage.php
1 file changed, 67 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MassMessage
refs/changes/46/78946/1
diff --git a/SpecialMassMessage.php b/SpecialMassMessage.php
index cb34c1c..b29c322 100644
--- a/SpecialMassMessage.php
+++ b/SpecialMassMessage.php
@@ -23,6 +23,11 @@
*/
protected $state;
+ /**
+ * @var array
+ */
+ protected $translations = array();
+
function __construct() {
parent::__construct( 'MassMessage', 'massmessage' );
}
@@ -138,6 +143,41 @@
}
/**
+ * Attempts to use the Translate extension to provide localized messages
+ * @param $name string
+ * @param $code string
+ * @return bool|string false if no message available, string is
localized text
+ */
+ function overrideTranslations( $name, $code ) {
+ $key = $name . $code;
+
+ if ( isset( $this->translations[$key] ) ) {
+ // Use cached version
+ return $this->translations[$key];
+ }
+ if ( !class_exists( 'TranslatablePage' ) ) {
+ // not installed
+ return false;
+ }
+ $title = Title::newFromText( $name );
+ if ( !$title->exists() ) {
+ return false;
+ }
+ if ( !TranslatablePage::isSourcePage( $title ) ) {
+ return false;
+ }
+
+ $page = TranslatablePage::newFromTitle( $title );
+ $group = $page->getMessageGroup();
+ $collection = $group->initCollection( $code );
+ $text = $page->getParse()->getTranslationPageText( $collection
);
+ $this->translations[$key] = $text; // Cache it
+ return $text;
+
+
+ }
+
+ /**
* Callback function
* Does some basic verification of data
* Decides whether to show the preview screen
@@ -230,6 +270,17 @@
$subject = $data['subject'];
$message = $data['message'];
+ // See if the page is translatable...
+ // Since we're previewing, just use English for now
+ $subj = $this->overrideTranslations( $subject, 'en' );
+ $msg = $this->overrideTranslations( $message, 'en' );
+ if ( $subj !== false ) {
+ $subject = $subj;
+ }
+ if ( $msg !== false ) {
+ $message = $msg;
+ }
+
// Convert into a content object
$content = ContentHandler::makeContent( $message, $firstTarget
);
@@ -260,18 +311,33 @@
* @return Status
*/
function submit( $data ) {
+ global $wgConf;
$spamlist = $this->getSpamlist( $data['spamlist'] );
// Log it.
$this->logToWiki( $spamlist, $data['subject'] );
+ // Store the message keys in case we override them
+ $data['subjectkey'] = $data['subject'];
+ $data['messagekey'] = $data['message'];
+
// Insert it into the job queue.
$pages = MassMessage::getParserFunctionTargets( $spamlist,
$this->getContext() );
$pages = MassMessage::normalizeSpamList( $pages );
foreach ( $pages as $page ) {
+ $dbname = $page['dbname'];
+ $lang = $wgConf->get( 'wgLanguageCode', $dbname );
+ $subj = $this->overrideTranslations(
$data['subjectkey'], $lang );
+ $msg = $this->overrideTranslations(
$data['messagekey'], $lang );
+ if ( $subj !== false ) {
+ $data['subject'] = $subj;
+ }
+ if ( $msg !== false ) {
+ $data['message'] = $subj;
+ }
$title = Title::newFromText( $page['title'] );
$job = new MassMessageJob( $title, $data );
- JobQueueGroup::singleton( $page['dbname'] )->push( $job
);
+ JobQueueGroup::singleton( $dbname )->push( $job );
}
return $this->status;
--
To view, visit https://gerrit.wikimedia.org/r/78946
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia95b63ad99b796721630233d158899f9477ca1ba
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MassMessage
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits