r79356 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79355‎ | r79356 | r79357 >
Date:17:37, 31 December 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Some improvements to Special:Translations: display language name, enable sorting, display count
Modified paths:
  • /trunk/extensions/Translate/SpecialTranslations.php (modified) (history)
  • /trunk/extensions/Translate/Translate.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Translate.i18n.php
@@ -207,6 +207,7 @@
208208 'translations-summary' => 'Enter a message name below to show all available translations.',
209209 'translate-translations-no-message' => '"$1" is not a translatable message',
210210 'translate-translations-none' => 'There are no translations for "$1"',
 211+ 'translate-translations-count' => 'Found {{PLURAL:$1|one translation|$1 translations}}.',
211212 'translate-translations-fieldset-title' => 'Message',
212213 'translate-translations-messagename' => 'Name:',
213214 'translate-translations-project' => 'Project:',
Index: trunk/extensions/Translate/SpecialTranslations.php
@@ -71,20 +71,18 @@
7272 * @return \string HTML for fieldset.
7373 */
7474 function namespaceMessageForm( Title $title = null ) {
75 - global $wgContLang, $wgScript, $wgTranslateMessageNamespaces;
 75+ global $wgScript;
7676
77 - $t = $this->getTitle();
78 -
7977 $namespaces = new XmlSelect( 'namespace', 'namespace' );
8078 $namespaces->setDefault( $title->getNamespace() );
8179
82 - foreach ( $wgTranslateMessageNamespaces as $ns ) {
83 - $namespaces->addOption( $wgContLang->getFormattedNsText( $ns ), $ns );
 80+ foreach ( $this->getSortedNamespaces() as $text => $index ) {
 81+ $namespaces->addOption( $text, $index );
8482 }
8583
8684 $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
8785 $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
88 - $out .= Html::hidden( 'title', $t->getPrefixedText() );
 86+ $out .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() );
8987 $out .= Xml::openElement( 'fieldset' );
9088 $out .= Xml::element( 'legend', null, wfMsg( 'translate-translations-fieldset-title' ) );
9189 $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
@@ -114,13 +112,30 @@
115113 }
116114
117115 /**
 116+ * Returns sorted array of namespaces.
 117+ *
 118+ * @return \arrayof{String,Integer}
 119+ */
 120+ public function getSortedNamespaces() {
 121+ global $wgTranslateMessageNamespaces, $wgContLang;
 122+
 123+ $nslist = array();
 124+ foreach ( $wgTranslateMessageNamespaces as $ns ) {
 125+ $nslist[$wgContLang->getFormattedNsText( $ns )] = $ns;
 126+ }
 127+ ksort( $nslist );
 128+
 129+ return $nslist;
 130+ }
 131+
 132+ /**
118133 * Builds a table with all translations of $title.
119134 *
120135 * @param $title Title (default: null)
121136 * @return void
122137 */
123138 function showTranslations( Title $title ) {
124 - global $wgOut, $wgUser;
 139+ global $wgOut, $wgUser, $wgLang;
125140
126141 $sk = $wgUser->getSkin();
127142
@@ -131,7 +146,6 @@
132147
133148 if ( !$inMessageGroup ) {
134149 $wgOut->addWikiMsg( 'translate-translations-no-message', $title->getPrefixedText() );
135 -
136150 return;
137151 }
138152
@@ -152,13 +166,12 @@
153167
154168 if ( !$res->numRows() ) {
155169 $wgOut->addWikiMsg( 'translate-translations-no-message', $title->getPrefixedText() );
156 -
157170 return;
 171+ } else {
 172+ $wgOut->addWikiMsg( 'translate-translations-count', $wgLang->formatNum( $res->numRows() ) );
158173 }
159174
160 - /**
161 - * Normal output.
162 - */
 175+ // Normal output.
163176 $titles = array();
164177
165178 foreach ( $res as $s ) {
@@ -168,7 +181,7 @@
169182 $pageInfo = TranslateUtils::getContents( $titles, $namespace );
170183
171184 $tableheader = Xml::openElement( 'table', array(
172 - 'class' => 'mw-sp-translate-table'
 185+ 'class' => 'mw-sp-translate-table sortable'
173186 ) );
174187
175188 $tableheader .= Xml::openElement( 'tr' );
@@ -176,23 +189,24 @@
177190 $tableheader .= Xml::element( 'th', null, wfMsg( 'allmessagescurrent' ) );
178191 $tableheader .= Xml::closeElement( 'tr' );
179192
180 - /**
181 - * Adapted version of TranslateUtils:makeListing() by Nikerabbit.
182 - */
 193+ // Adapted version of TranslateUtils:makeListing() by Nikerabbit.
183194 $out = $tableheader;
184195
185196 $canTranslate = $wgUser->isAllowed( 'translate' );
186197
187198 $ajaxPageList = array();
188 - $historyText = "&#160;<sup>" . wfMsg( 'translate-translations-history-short' ) . "</sup>&#160;";
 199+ $historyText = "&#160;<sup>" . wfMsgHtml( 'translate-translations-history-short' ) . "</sup>&#160;";
189200
190201 foreach ( $res as $s ) {
191202 $key = $s->page_title;
192203 $tTitle = Title::makeTitle( $s->page_namespace, $key );
193204 $ajaxPageList[] = $tTitle->getDBkey();
194205
195 - $text = htmlspecialchars( $this->getCode( $s->page_title ) );
 206+ $code = $this->getCode( $s->page_title );
196207
 208+ $text = TranslateUtils::getLanguageName( $code, false, $wgLang->getCode() ) . " ($code)";
 209+ $text = htmlspecialchars( $text );
 210+
197211 if ( $canTranslate ) {
198212 $tools['edit'] = TranslationHelpers::ajaxEditLink(
199213 $tTitle,

Status & tagging log