Nikerabbit has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/58885


Change subject: First step of Special:TranslateSandbox
......................................................................

First step of Special:TranslateSandbox

* Lists open requests
* Can promote or delete

Change-Id: If1747b0f803586d1d300957644649396e5acf14b
---
M Resources.php
M Translate.alias.php
M Translate.php
A TranslateSandbox.i18n.php
M _autoload.php
A resources/css/ext.translate.special.translatesandbox.css
A resources/js/ext.translate.special.translatesandbox.js
A specials/SpecialTranslateSandbox.php
8 files changed, 328 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate 
refs/changes/85/58885/1

diff --git a/Resources.php b/Resources.php
index f88a772..cd4de44 100644
--- a/Resources.php
+++ b/Resources.php
@@ -322,6 +322,18 @@
        ),
 ) + $resourcePaths;
 
+$wgResourceModules['ext.translate.special.translatesandbox'] = array(
+       'scripts' => 'resources/js/ext.translate.special.translatesandbox.js',
+       'styles' => 'resources/css/ext.translate.special.translatesandbox.css',
+       'position' => 'top',
+       'dependencies' => array(
+               'mediawiki.api',
+               'jquery.uls.grid',
+       ),
+       'messages' => array(
+       ),
+) + $resourcePaths;
+
 $wgResourceModules['ext.translate.special.translationstats'] = array(
        'scripts' => 'resources/js/ext.translate.special.translationstats.js',
        'dependencies' => array(
diff --git a/Translate.alias.php b/Translate.alias.php
index a2f6d6e..96fdbe8 100644
--- a/Translate.alias.php
+++ b/Translate.alias.php
@@ -25,6 +25,7 @@
        'PageTranslationDeletePage' => array( 'PageTranslationDeletePage' ),
        'AggregateGroups' => array( 'AggregateGroups' ),
        'SearchTranslations' => array( 'SearchTranslations' ),
+       'TranslateSandbox' => array( 'ManageTranslatorSandbox', 
'TranslateSandbox' ),
 );
 
 /** Afrikaans (Afrikaans) */
@@ -1053,4 +1054,4 @@
        'PageTranslationDeletePage' => array( '刪除譯文頁面' ),
        'AggregateGroups' => array( '聚合組' ),
        'SearchTranslations' => array( '搜尋翻譯' ),
-);
\ No newline at end of file
+);
diff --git a/Translate.php b/Translate.php
index 9bf045e..3c22d13 100644
--- a/Translate.php
+++ b/Translate.php
@@ -49,6 +49,7 @@
 $wgExtensionMessagesFiles['PageTranslation'] = "$dir/PageTranslation.i18n.php";
 $wgExtensionMessagesFiles['TranslateGroupDescriptions'] = 
"$dir/TranslateGroupDescriptions.i18n.php";
 $wgExtensionMessagesFiles['TranslateSearch'] = "$dir/TranslateSearch.i18n.php";
+$wgExtensionMessagesFiles['TranslateSandbox'] = 
"$dir/TranslateSandbox.i18n.php";
 $wgExtensionMessagesFiles['TranslateAlias'] = "$dir/Translate.alias.php";
 $wgExtensionMessagesFiles['TranslateMagic'] = "$dir/Translate.magic.php";
 
@@ -88,6 +89,7 @@
 $wgSpecialPageGroups['AggregateGroups'] = 'wiki';
 $wgSpecialPages['SearchTranslations'] = 'SpecialSearchTranslations';
 $wgSpecialPageGroups['SearchTranslations'] = 'wiki';
+$wgSpecialPages['TranslateSandbox'] = 'SpecialTranslateSandbox';
 
 // API
 $wgAPIListModules['messagecollection'] = 'ApiQueryMessageCollection';
@@ -193,6 +195,7 @@
 $wgAvailableRights[] = 'translate-manage';
 $wgAvailableRights[] = 'translate-messagereview';
 $wgAvailableRights[] = 'translate-groupreview';
+$wgAvailableRights[] = 'translate-sandboxmanage';
 
 // New rights group
 $wgGroupPermissions['translate-proofr']['translate-messagereview'] = true;
diff --git a/TranslateSandbox.i18n.php b/TranslateSandbox.i18n.php
new file mode 100644
index 0000000..b557730
--- /dev/null
+++ b/TranslateSandbox.i18n.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Translations for the sandbox feature.
+ *
+ * @file
+ * @license GPL2+
+ */
+
+$messages = array();
+
+/** English
+ * @author Nike
+ */
+$messages['en'] = array(
+       'translatesandbox' => 'Manage translator sandbox',
+       'tsb-filter-pending' => 'Pending requests',
+);
+
+/** Message documentation (Message documentation)
+ * @author Nike
+ */
+$messages['qqq'] = array(
+       'translatesandbox' => '{{doc-special|TranslateSandbox}}',
+       'tsb-filter-pending' => 'A filter option on Special:TranslateSandbox',
+);
+
diff --git a/_autoload.php b/_autoload.php
index 83aff0f..cefd26e 100644
--- a/_autoload.php
+++ b/_autoload.php
@@ -46,6 +46,7 @@
 $wgAutoloadClasses['SpecialSearchTranslations'] = 
"$dir/specials/SpecialSearchTranslations.php";
 $wgAutoloadClasses['SpecialSupportedLanguages'] = 
"$dir/specials/SpecialSupportedLanguages.php";
 $wgAutoloadClasses['SpecialTranslate'] = "$dir/specials/SpecialTranslate.php";
+$wgAutoloadClasses['SpecialTranslateSandbox'] = 
"$dir/specials/SpecialTranslateSandbox.php";
 $wgAutoloadClasses['SpecialTranslationStats'] = 
"$dir/specials/SpecialTranslationStats.php";
 $wgAutoloadClasses['SpecialTranslations'] = 
"$dir/specials/SpecialTranslations.php";
 /**@}*/
diff --git a/resources/css/ext.translate.special.translatesandbox.css 
b/resources/css/ext.translate.special.translatesandbox.css
new file mode 100644
index 0000000..624cb71
--- /dev/null
+++ b/resources/css/ext.translate.special.translatesandbox.css
@@ -0,0 +1,114 @@
+/**
+ * CSS for special page.
+ * @author Niklas Laxström
+ * @license GPL2+
+ */
+
+/* Panes */
+.filter.pane,
+.search.pane {
+       border-bottom: 1px solid #575656;
+       height: 50px;
+       line-height: 50px;
+       font-size: 24px;
+}
+
+.requets.pane,
+.details.pane {
+       border-top: 1px solid #d3d2d2;
+}
+
+/* Requests pane */
+.request {
+       height: 50px;
+       border-right: 1px solid #c9c8c8;
+       border-bottom: 1px solid #c9c8c8;
+       cursor: pointer;
+}
+
+.request:first-child {
+       height: 51px;
+       border-top: 1px solid #c9c8c8;
+}
+
+.request .amount {
+       height: 100%;
+       line-height: 48px;
+       font-size: 40px;
+       text-align: center;
+       color: #96989a;
+       background-color: #f7f8f8;
+}
+
+.request .username,
+.request .selector {
+       height: 30px;
+       line-height: 30px;
+       font-size: 16px;
+       text-wrap: nowrap;
+}
+
+.request .email,
+.request .signup-age {
+       height: 20px;
+       line-height: 20px;
+       font-size: 12px;
+       color: #6c6d70;
+       text-wrap: nowrap;
+}
+
+.request .username,
+.request .email {
+       padding-left: 10px;
+       overflow: ellipsis;
+}
+
+.request .signup-age {
+       text-align: center;
+       overflow: hidden;
+}
+
+.request .proofread-marker {
+       background-color: #3e8dc5;
+       width: 10px;
+       height: 10px;
+       position: absolute;
+       top: 50%;
+       left: 5%;
+       margin-top: -5px;
+       -webkit-border-radius: 5px;
+       -moz-border-radius: 5px;
+       border-radius: 5px;
+}
+
+/* Details pane */
+
+.details.pane > div {
+       padding: 20px 0 0 20px;
+}
+
+.details.pane .username {
+       font-size: 30px;
+}
+
+.details.pane .email {
+       font-size: 14px;
+       color: #6c6d70;
+}
+
+.details.pane .languages {
+       color: #6c6d70;
+       font-size: 14px;
+}
+
+.details.pane .languages span {
+       margin-right: 2em;
+}
+
+.details.pane .actions {
+       font-size: 26px;
+}
+
+.actions .button {
+       margin-right: 1.5em;
+}
diff --git a/resources/js/ext.translate.special.translatesandbox.js 
b/resources/js/ext.translate.special.translatesandbox.js
new file mode 100644
index 0000000..6749001
--- /dev/null
+++ b/resources/js/ext.translate.special.translatesandbox.js
@@ -0,0 +1,69 @@
+/**
+ * JS for special page.
+ * @author Niklas Laxström
+ * @license GPL2+
+ */
+
+(function ( $, mw ) {
+       function doApiAction( options ) {
+               var api = new mw.Api();
+               
+               options = $.extend( {}, {
+                       action: 'translatesandbox',
+                       token: $( '#token' ).val()
+               }, options );
+               
+               api.post( options )
+                       .done( function () { window.alert( 'Success' ); } )
+                       .fail( function () { window.alert( 'Failure' ); } )
+               ;
+       }
+
+       $( document ).ready( function () {
+               var $requests, $detailsPane;
+               
+               $detailsPane = $( '.details.pane' );
+               
+               $requests = $( '.requests .request' );
+               $requests.on( 'click', function () {
+                       var $this = $( this );
+
+                       $detailsPane.empty().append(
+                               $( '<div>' )
+                                       .addClass( 'username row' )
+                                       .text( $this.find( '.username' ).text() 
),
+                               $( '<div>' )
+                                       .addClass( 'email row' )
+                                       .text( $this.find( '.email' ).text() ),
+                               $( '<div>' )
+                                       .addClass( 'languages row' )
+                                       .append(
+                                               $( '<span>' ).text( 'Afrikaans' 
),
+                                               $( '<span>' ).text( 'español' )
+                                        ),
+                               $( '<div>' )
+                                       .addClass( 'actions row' )
+                                       .append(
+                                               $( '<button>' )
+                                                       .addClass( 'accept 
primary button' )
+                                                       .text( 'Accept' )
+                                                       .on( 'click', function 
() {
+                                                               doApiAction( {
+                                                                       userid: 
$this.data( 'data' ).id,
+                                                                       'do': 
'promote'
+                                                               } );
+                                                       } ),
+                                               $( '<button>' )
+                                                       .addClass( 'delete 
destructive button' )
+                                                       .text( 'Delete' )
+                                                       .on( 'click', function 
() {
+                                                               doApiAction( {
+                                                                       userid: 
$this.data( 'data' ).id,
+                                                                       'do': 
'delete'
+                                                               } );
+                                                       } )
+                                        )
+                       );
+               } );
+       } );
+}( jQuery, mediaWiki ) );
diff --git a/specials/SpecialTranslateSandbox.php 
b/specials/SpecialTranslateSandbox.php
new file mode 100644
index 0000000..126b552
--- /dev/null
+++ b/specials/SpecialTranslateSandbox.php
@@ -0,0 +1,101 @@
+<?php
+/**
+ * Contains logic for special page ...
+ *
+ * @file
+ * @author Niklas Laxström
+ * @license GPL2+
+ */
+
+/**
+ * Special page for managing sandboxed users.
+ *
+ * @ingroup SpecialPage TranslateSpecialPage
+ */
+class SpecialTranslateSandbox extends SpecialPage {
+       function __construct() {
+               global $wgTranslateUseSandbox;
+               parent::__construct( 'TranslateSandbox', 
'translate-sandboxmanage', $wgTranslateUseSandbox );
+       }
+
+       public function execute( $params ) {
+               $this->checkPermissions();
+               $out = $this->getOutput();
+               $out->addModules( 'ext.translate.special.translatesandbox' );
+               $this->showPage();
+       }
+
+       /**
+        * Generates the whole page html and appends it to output
+        */
+       protected function showPage() {
+               // Easier to do this way than in JS
+               $token = Html::hidden( 'token', 
ApiTranslateSandbox::getToken(), array( 'id' => 'token' ) );
+
+               $out = $this->getOutput();
+               $out->addHtml( <<<HTML
+<div class="grid">
+       <div class="row">
+               <div class="four columns pane 
filter">{$this->makeFilter()}</div>
+               <div class="eight columns pane search"></div>
+       </div>
+       <div class="row">
+               <div class="four columns pane 
requests">{$this->makeList()}</div>
+               <div class="eight columns pane details"></div>
+       </div>
+       $token
+</div>
+HTML
+               );
+       }
+
+       protected function makeFilter() {
+               return $this->msg( 'tsb-filter-pending' )->escaped();
+       }
+
+       protected function makeList() {
+               $items = array();
+
+               $users = TranslateSandbox::getUsers();
+               foreach ( $users as $user ) {
+                       $items[] = $this->makeRequestItem( $user );
+               }
+
+               return "\n\n" . implode( "\n", $items ) . "\n\n";
+       }
+
+       protected function makeRequestItem( User $user ) {
+               $data = array(
+                       'name' => $user->getName(),
+                       'email' => $user->getEmail(),
+                       'registration' => $user->getRegistration(),
+                       'translations' => 0,
+                       'id' => $user->getId(),
+               );
+
+               $dataEnc = htmlspecialchars( FormatJson::encode( $data ) );
+
+               $nameEnc = htmlspecialchars( $data['name'] );
+               $emailEnc = htmlspecialchars( $data['email'] );
+               $countEnc = htmlspecialchars( $data['translations'] );
+               $timestamp = new MWTimestamp( $data['registration'] );
+               $agoEnc = htmlspecialchars( $timestamp->getHumanTimestamp() );
+
+       return <<<HTML
+<div class="row request" data-data="$dataEnc">
+       <div class="three columns amount">
+               <div class="proofread-marker"></div>
+               <div class="translation-count">$countEnc</div>
+       </div>
+       <div class="six columns details">
+               <div class="row username">$nameEnc</div>
+               <div class="row email">$emailEnc</div>
+       </div>
+       <div class="three columns approval">
+               <div class="row selector"></div>
+               <div class="row signup-age">$agoEnc</div>
+       </div>
+</div>
+HTML;
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/58885
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If1747b0f803586d1d300957644649396e5acf14b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <niklas.laxst...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to