r101140 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101139‎ | r101140 | r101141 >
Date:15:28, 28 October 2011
Author:nikerabbit
Status:resolved (Comments)
Tags:
Comment:
Instead of displaying ugly API errors to unprivileged users, tell them to ask permission from $wgTranslatePermissionUrl
Modified paths:
  • /trunk/extensions/Translate/README (modified) (history)
  • /trunk/extensions/Translate/Translate.i18n.php (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/resources/ext.translate.quickedit.js (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationEditPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Translate.php
@@ -340,7 +340,15 @@
341341 */
342342 $wgTranslateSupportUrl = false;
343343
 344+/**
 345+ * When unprivileged users opens a translation editor, he will
 346+ * see message stating that speical permission is needed for translating
 347+ * messages. If this variable is defined, there is a button which will
 348+ * take the user to that page to ask for permission.
 349+ */
 350+$wgTranslatePermissionUrl = 'Project:Translator';
344351
 352+
345353 # === Page translation feature ===
346354
347355 /**
Index: trunk/extensions/Translate/README
@@ -30,6 +30,7 @@
3131
3232 == Change log ==
3333 * 2011-10-28
 34+- New configuration variable $wgTranslatePermissionUrl
3435 - Message review feature, available to users in translate-proofr group
3536 - Message collections can now have properties and allow filtering on them
3637 This is still work in progress and is likely to get improvements over time
Index: trunk/extensions/Translate/utils/TranslationEditPage.php
@@ -60,7 +60,7 @@
6161 * disabled all other output.
6262 */
6363 public function execute() {
64 - global $wgOut, $wgServer, $wgScriptPath;
 64+ global $wgOut, $wgServer, $wgScriptPath, $wgUser;
6565
6666 $wgOut->disable();
6767
@@ -91,6 +91,11 @@
9292 'lang' => $targetLang->getCode(),
9393 'dir' => $targetLang->getDir(),
9494 );
 95+
 96+ if ( !$wgUser->isAllowed( 'translate' ) ) {
 97+ $textareaParams['readonly'] = 'readonly';
 98+ }
 99+
95100 $textarea = Html::element( 'textarea', $textareaParams, $translation );
96101
97102 $hidden = array();
@@ -125,6 +130,14 @@
126131
127132 $support = $this->getSupportButton( $this->getTitle() );
128133
 134+ if ( $wgUser->isAllowed( 'translate' ) ) {
 135+ $bottom = "$summary$save$saveAndNext$skip$history$support";
 136+ } else {
 137+ $text = wfMessage( 'translate-edit-nopermission' )->escaped();
 138+ $button = $this->getPermissionPageButton();
 139+ $bottom = "$text $button$skip$history$support";
 140+ }
 141+
129142 // Use the api to submit edits
130143 $formParams = array(
131144 'action' => "{$wgServer}{$wgScriptPath}/api.php",
@@ -134,7 +147,7 @@
135148 $form = Html::rawElement( 'form', $formParams,
136149 implode( "\n", $hidden ) . "\n" .
137150 $helpers->getBoxes( $this->suggestions ) . "\n" .
138 - "$textarea\n$summary$save$saveAndNext$skip$history$support"
 151+ "$textarea\n$bottom"
139152 );
140153
141154 echo Html::rawElement( 'div', array( 'class' => 'mw-ajax-dialog' ), $form );
@@ -211,4 +224,23 @@
212225 return $support;
213226 }
214227
 228+ protected function getPermissionPageButton() {
 229+ global $wgTranslatePermissionUrl;
 230+ if ( !$wgTranslatePermissionUrl ) return '';
 231+
 232+ $title = Title::newFromText( $wgTranslatePermissionUrl );
 233+ if ( !$title ) return '';
 234+
 235+ $button = Html::element(
 236+ 'input',
 237+ array(
 238+ 'class' => 'mw-translate-askpermission',
 239+ 'type' => 'button',
 240+ 'value' => wfMsg( 'translate-edit-askpermission' ),
 241+ 'data-load-url' => $title->getLocalUrl(),
 242+ )
 243+ );
 244+ return $button;
 245+ }
 246+
215247 }
Index: trunk/extensions/Translate/Translate.i18n.php
@@ -6660,6 +6660,8 @@
66616661 'translate-edit-tmmatch' => 'Vastaavuus $1%',
66626662 'translate-use-suggestion' => 'Korvaa nykyinen käännös tällä ehdotuksella.',
66636663 'translate-edit-tab-list' => 'Viestiluettelo',
 6664+ 'translate-edit-nopermission' => 'You need permission to translate messages.',
 6665+ 'translate-edit-askpermission' => 'Request permission',
66646666 'translate-magic-pagename' => 'Laajennettu MediaWikin kääntäminen',
66656667 'translate-magic-help' => 'Voit kääntää toimintosivujen vaihtoehtoisia nimiä, taikasanoja ja nimiavaruuksien nimiä.
66666668
Index: trunk/extensions/Translate/resources/ext.translate.quickedit.js
@@ -104,7 +104,7 @@
105105 return false;
106106 } );
107107
108 - form.find( '.mw-translate-support' ).click( function() {
 108+ form.find( '.mw-translate-support,.mw-translate-askpermission' ).click( function() {
109109 // Can use .data() only with 1.4.3 or newer
110110 window.open( $(this).attr('data-load-url') );
111111 return false;

Follow-up revisions

RevisionCommit summaryAuthorDate
r102280Followup r101140 - place messages in correct placenikerabbit13:42, 7 November 2011

Comments

#Comment by Santhosh.thottingal (talk | contribs)   11:29, 7 November 2011

The two new messages 'translate-edit-nopermission' and 'translate-edit-askpermission' should be added at en section. These messages were removed from latest revisions by localization update and its broken at translatewiki now.

#Comment by Santhosh.thottingal (talk | contribs)   11:42, 7 November 2011

Does it make sense to use 'Special:FirstSteps' as default value for $wgTranslatePermissionUrl ?

#Comment by Nikerabbit (talk | contribs)   13:43, 7 November 2011

Special:FirstSteps is still quite much translatewiki.net specific.

Status & tagging log