r71371 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71370‎ | r71371 | r71372 >
Date:17:56, 20 August 2010
Author:siebrand
Status:deferred
Tags:
Comment:
Documentation update.
Modified paths:
  • /trunk/extensions/Translate/Message.php (modified) (history)
  • /trunk/extensions/Translate/MessageChecks.php (modified) (history)
  • /trunk/extensions/Translate/MessageCollection.php (modified) (history)
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/SpecialFirstSteps.php (modified) (history)
  • /trunk/extensions/Translate/SpecialImportTranslations.php (modified) (history)
  • /trunk/extensions/Translate/SpecialLanguageStats.php (modified) (history)
  • /trunk/extensions/Translate/SpecialMyLanguage.php (modified) (history)
  • /trunk/extensions/Translate/SpecialSupportedLanguages.php (modified) (history)
  • /trunk/extensions/Translate/Translate.i18n.php (modified) (history)
  • /trunk/extensions/Translate/TranslateTasks.php (modified) (history)
  • /trunk/extensions/Translate/TranslateUtils.php (modified) (history)
  • /trunk/extensions/Translate/check-blacklist.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/SpecialMyLanguage.php
@@ -1,16 +1,21 @@
22 <?php
33 /**
4 - * Special page just to redirect the user to translated version if page,
5 - * if it exists.
 4+ * Contains logic for special page Special:MyLanguage
65 *
7 - * Usage: [[Special:MyLanguage/Page name|link text]]
8 - *
9 - * @ingroup SpecialPage
 6+ * @file
107 * @author Niklas Laxström
118 * @copyright Copyright © 2010 Niklas Laxström
129 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1310 */
1411
 12+/**
 13+ * Unlisted special page just to redirect the user to the translated version of
 14+ * a page, if it exists.
 15+ *
 16+ * Usage: [[Special:MyLanguage/Page name|link text]]
 17+ *
 18+ * @ingroup SpecialPage
 19+ */
1520 class SpecialMyLanguage extends UnlistedSpecialPage {
1621 /**
1722 * Construct
Index: trunk/extensions/Translate/MessageCollection.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * An extension to ease the translation of Mediawiki
 4+ * This file contains classes that implements message collections.
55 *
66 * @ingroup Extensions
77 * @file
@@ -9,6 +9,9 @@
1010 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1111 */
1212
 13+/**
 14+ * @todo Needs documentation.
 15+ */
1316 class MessageCollection implements ArrayAccess, Iterator, Countable {
1417 /**
1518 * It is handy to store the language code here.
Index: trunk/extensions/Translate/SpecialLanguageStats.php
@@ -1,17 +1,23 @@
22 <?php
 3+/**
 4+ * Contains logic for special page Special:LanguageStats.
 5+ *
 6+ * @file
 7+ * @author Siebrand Mazeland
 8+ * @author Niklas Laxström
 9+ * @copyright Copyright © 2008-2010 Siebrand Mazeland, Niklas Laxström
 10+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 11+ */
312
413 /**
5 - * Implements a special page which givens translation statistics for a given
6 - * set of message groups. Message group names can be entered (pipe separated)
7 - * into the form, or added as a parameter in the URL.
 14+ * Implements includable special page Special:LanguageStats which provides
 15+ * translation statistics for all defined message groups.
816 *
917 * Loosely based on the statistics code in phase3/maintenance/language
1018 *
11 - * Use {{Special:LanguageStats/nl/1}} to show for 'nl' and suppres complete.
 19+ * Use {{Special:LanguageStats/nl/1}} to show for 'nl' and suppres completely
 20+ * translated groups.
1221 *
13 - * @author Siebrand Mazeland
14 - * @copyright Copyright © 2008-2010 Siebrand Mazeland
15 - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1622 * @ingroup SpecialPage
1723 */
1824 class SpecialLanguageStats extends IncludableSpecialPage {
@@ -62,7 +68,7 @@
6369 /**
6470 * HTML for the top form.
6571 * @param $code \string A language code (default empty, example: 'en').
66 - * @param $suppressComplete \bool If completely translated groups should be suppressed.
 72+ * @param $suppressComplete \bool If completely translated groups should be suppressed (default: false).
6773 * @return \string HTML
6874 */
6975 function buildLanguageForm( $code = '', $suppressComplete = false ) {
@@ -108,6 +114,7 @@
109115
110116 /**
111117 * Statistics table element (heading or regular cell)
 118+ *
112119 * @todo document
113120 * @param $in \string
114121 * @param $bgcolor \string
@@ -190,6 +197,7 @@
191198 /**
192199 * HTML for language statistics.
193200 * Copied and adaped from groupStatistics.php by Nikerabbit
 201+ *
194202 * @param $code \string A language code (default empty, example: 'en').
195203 * @param $suppressComplete \bool If completely translated groups should be suppressed
196204 * @return \string HTML
@@ -325,7 +333,11 @@
326334 }
327335
328336 /**
329 - * @todo name does not match behaviour.
 337+ * Used to circumvent ugly tooltips when newlines are used in the
 338+ * message content ("x\ny" becomes "x y").
 339+ *
 340+ * @todo Name does not match behaviour.
 341+ * @todo Make this a static helper function somewhere?
330342 */
331343 private static function newlineToWordSeparator( $text ) {
332344 $wordSeparator = wfMsg( 'word-separator' );
Index: trunk/extensions/Translate/MessageChecks.php
@@ -1,12 +1,13 @@
22 <?php
33 /**
 4+ * Message checking framework.
 5+ *
46 * @file
57 * @defgroup MessageCheckers Message Checkers
 8+ *
69 */
710
811 /**
9 - * Message checking framework.
10 - *
1112 * Message checkers try to find common mistakes so that translators can fix
1213 * them quickly. To implement your own checks, extend this class and add a
1314 * method of the following type:
Index: trunk/extensions/Translate/SpecialFirstSteps.php
@@ -1,13 +1,19 @@
22 <?php
 3+/**
 4+ * Contains logic for special page Special:FirstSteps to guide users through
 5+ * the process of becoming a translator.
 6+ *
 7+ * @file
 8+ * @author Niklas Laxström
 9+ * @copyright Copyright © 2010, Niklas Laxström
 10+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 11+ */
312
413 /**
514 * Implements a special page which assists users to become translators.
615 * Currently it is tailored for the needs of translatewiki.net
716 *
817 * @ingroup SpecialPage
9 - * @author Niklas Laxström
10 - * @copyright Copyright © 2010, Niklas Laxström
11 - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1218 */
1319 class SpecialFirstSteps extends UnlistedSpecialPage {
1420 protected $skin, $user, $out;
@@ -44,6 +50,7 @@
4551 $this->out->addHtml( $header );
4652 return $step;
4753 }
 54+
4855 if ( $this->user->isLoggedIn() ) {
4956 $header->content( $header->content . wfMsg( 'translate-fs-pagetitle-done' ) );
5057 $this->out->addHtml( $header );
@@ -66,6 +73,7 @@
6774 list( $su_before, $su_after ) = explode( '|||', $tag, 2 );
6875
6976 $this->out->addWikiMsg( 'translate-fs-signup-text', $li_before, $li_after, $su_before, $su_after );
 77+
7078 return $step_message;
7179 }
7280
@@ -80,6 +88,7 @@
8189 $this->out->addHtml( $header );
8290 return $step;
8391 }
 92+
8493 if ( $this->user->getOption( 'language' ) !== 'en' || $wgRequest->getText( 'step' ) === 'settings' ) {
8594 $header->content( $header->content . wfMsg( 'translate-fs-pagetitle-done' ) );
8695 $this->out->addHtml( $header );
@@ -88,6 +97,7 @@
8998
9099 $this->out->addHtml( $header->style( 'opacity', false ) );
91100 $this->out->addWikiMsg( 'translate-fs-settings-text' );
 101+
92102 $form = new HtmlTag( 'form' );
93103 $items = new TagContainer();
94104 $form->param( 'method', 'post' )->content( $items );
@@ -122,10 +132,12 @@
123133 {
124134 $article = new Article( $userpage );
125135 $status = $article->doEdit( $wgRequest->getText( $textareaId ), $this->getTitle() );
 136+
126137 if ( $status->isOK() ) {
127138 $header->content( $header->content . wfMsg( 'translate-fs-pagetitle-done' ) );
128139 $this->out->addHtml( $header );
129140 $this->out->addWikiMsg( 'translate-fs-userpage-done' );
 141+
130142 return false;
131143 } else {
132144 $this->out->addWikiText( $status->getWikiText() );
@@ -137,9 +149,11 @@
138150 $revision = Revision::newFromTitle( $userpage );
139151 $text = $revision->getText();
140152 $preload = $text;
 153+
141154 if ( preg_match( '/{{#babel:/i', $text ) ) {
142155 $header->content( $header->content . wfMsg( 'translate-fs-pagetitle-done' ) );
143156 $this->out->addHtml( $header );
 157+
144158 return false;
145159 }
146160 }
@@ -164,6 +178,7 @@
165179 $items[] = new RawHtml( Xml::submitButton( wfMsg( 'translate-fs-userpage-submit' ) ) );
166180
167181 $this->out->addHtml( $form );
 182+
168183 return $step_message;
169184 }
170185
@@ -182,6 +197,7 @@
183198 $this->out->addHtml( $header );
184199 return $step;
185200 }
 201+
186202 $this->out->addHtml( $header->style( 'opacity', false ) );
187203 $this->out->addWikiMsg( 'translate-fs-permissions-text' );
188204
@@ -196,6 +212,7 @@
197213 if ( $step ) {
198214 $header->style( 'opacity', 0.4 );
199215 $this->out->addHtml( $header );
 216+
200217 return $step;
201218 }
202219
@@ -219,6 +236,7 @@
220237 if ( $this->user->isEmailConfirmed() ) {
221238 $header->content( $header->content . wfMsg( 'translate-fs-pagetitle-done' ) );
222239 $this->out->addHtml( $header );
 240+
223241 return $step; // Start translating step
224242 }
225243
Index: trunk/extensions/Translate/SpecialSupportedLanguages.php
@@ -1,13 +1,24 @@
22 <?php
33 /**
4 - * @todo Needs documentation
5 - * @ingroup SpecialPage
 4+ * Contains logic for special page Special:SupportedLanguages
 5+ *
 6+ * @file
67 * @author Niklas Laxström
78 * @author Siebrand Mazeland
89 * @copyright Copyright © 2010, Niklas Laxström, Siebrand Mazeland
910 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1011 */
1112
 13+/**
 14+ * Implements unlisted special page Special:SupportedLanguages. The wiki
 15+ * administrator must define NS_PORTAL, otherwise this page does not work.
 16+ * This page displays a list of language portals for all portals corresponding
 17+ * with a language code defined for MediaWiki and a subpage called
 18+ * "translators". The subpage "translators" must contain the template
 19+ * [[:{{ns:template}}:User|User]], taking a user name as parameter.
 20+ *
 21+ * @ingroup SpecialPage
 22+ */
1223 class SpecialSupportedLanguages extends UnlistedSpecialPage {
1324 public function __construct() {
1425 parent::__construct( 'SupportedLanguages' );
@@ -66,6 +77,7 @@
6778 $rev = new Revision( $row );
6879 $text = $rev->getText();
6980 $code = strtolower( preg_replace( '!/translators$!', '', $row->page_title ) );
 81+
7082 preg_match_all( '!{{[Uu]ser\|([^}|]+)!', $text, $matches, PREG_SET_ORDER );
7183 foreach ( $matches as $match ) {
7284 $user = Title::capitalize( $match[1], NS_USER );
@@ -76,7 +88,9 @@
7789 }
7890
7991 $lb->execute();
 92+
8093 global $wgUser;
 94+
8195 $skin = $wgUser->getSkin();
8296 $portalBaseText = wfMsg( 'portal' );
8397
@@ -90,7 +104,6 @@
91105
92106 foreach ( array_keys( $users ) as $code ) {
93107 $portalTitle = Title::makeTitleSafe( NS_PORTAL, $code );
94 -
95108 $portalText = $portalBaseText;
96109
97110 /**
Index: trunk/extensions/Translate/SpecialImportTranslations.php
@@ -1,14 +1,19 @@
22 <?php
3 -
43 /**
5 - * Special page to import Gettext (.po) files exported using Translate extension.
6 - * Does not support general Gettext files.
 4+ * Contains logic for special page Special:ImportTranslations.
75 *
8 - * @ingroup SpecialPage
 6+ * @file
97 * @author Niklas Laxström
108 * @copyright Copyright © 2009-2010, Niklas Laxström
119 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1210 */
 11+
 12+/**
 13+ * Special page to import Gettext (.po) files exported using Translate extension.
 14+ * Does not support generic Gettext files.
 15+ *
 16+ * @ingroup SpecialPage
 17+ */
1318 class SpecialImportTranslations extends SpecialPage {
1419 /**
1520 * Set up and fill some dependencies.
@@ -87,6 +92,7 @@
8893
8994 $importer = new MessageWebImporter( $this->getTitle(), $group, $code );
9095 $alldone = $importer->execute( $messages );
 96+
9197 if ( $alldone ) {
9298 $this->deleteCachedData();
9399 }
@@ -191,18 +197,30 @@
192198 }
193199 } elseif ( $source === 'local' ) {
194200 $filename = $this->request->getFileTempname( 'upload-local' );
195 - if ( !is_uploaded_file( $filename ) ) return array( 'ul-failed' );
 201+ if ( !is_uploaded_file( $filename ) ) {
 202+ return array( 'ul-failed' );
 203+ }
 204+
196205 $filedata = file_get_contents( $filename );
 206+
197207 return array( 'ok' );
198208 } elseif ( $source === 'wiki' ) {
199209 $filetitle = $this->request->getText( 'upload-wiki' );
200210 $title = Title::newFromText( $filetitle, NS_FILE );
201 - if ( !$title ) return array( 'invalid-title', $filetitle );
 211+
 212+ if ( !$title ) {
 213+ return array( 'invalid-title', $filetitle );
 214+ }
 215+
202216 $file = wfLocalFile( $title );
203 - if ( !$file || !$file->exists() ) return array( 'no-such-file', $title->getPrefixedText() );
204217
 218+ if ( !$file || !$file->exists() ) {
 219+ return array( 'no-such-file', $title->getPrefixedText() );
 220+ }
 221+
205222 $filename = $file->getPath();
206223 $filedata = file_get_contents( $filename );
 224+
207225 return array( 'ok' );
208226 } else {
209227 return array( 'type-not-supported', $source );
@@ -256,22 +274,28 @@
257275
258276 protected function setCachedData( $data ) {
259277 global $wgMemc;
 278+
260279 $key = wfMemcKey( 'translate', 'webimport', $this->user->getId() );
 280+
261281 /**
262 - * 15 minutes.
 282+ * Cache 15 minutes.
263283 */
264284 $wgMemc->set( $key, $data, 60 * 15 );
265285 }
266286
267287 protected function getCachedData() {
268288 global $wgMemc;
 289+
269290 $key = wfMemcKey( 'translate', 'webimport', $this->user->getId() );
 291+
270292 return $wgMemc->get( $key );
271293 }
272294
273295 protected function deleteCachedData() {
274296 global $wgMemc;
 297+
275298 $key = wfMemcKey( 'translate', 'webimport', $this->user->getId() );
 299+
276300 return $wgMemc->delete( $key );
277301 }
278302 }
Index: trunk/extensions/Translate/check-blacklist.php
@@ -2,17 +2,19 @@
33 /**
44 * List of checks that should not be performed.
55 *
6 - * The array takes input of arrays which define constraints. Checks which match
7 - * those constrains are skipped. Possible constrains are <tt>group</tt>,
8 - * <tt>check</tt>, <tt>code</tt> and <tt>message</tt>.
96 * @todo Use YAML?
10 - *
 7+ * @file
118 * @author Niklas Laxström
129 * @copyright Copyright © 2008-2010, Niklas Laxström
1310 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1411 */
 12+
 13+/**
 14+ * The array takes input of arrays which define constraints. Checks which match
 15+ * those constrains are skipped. Possible constrains are <tt>group</tt>,
 16+ * <tt>check</tt>, <tt>code</tt> and <tt>message</tt>.
 17+ */
1518 $checkBlacklist = array(
16 -
1719 array(
1820 'check' => 'plural',
1921 'code' => array( 'az', 'bo', 'dz', 'id', 'fa', 'gan', 'gan-hans',
Index: trunk/extensions/Translate/MessageGroups.php
@@ -1,7 +1,8 @@
22 <?php
33 /**
 4+ * Message groups
 5+ *
46 * @todo: needs documentation
5 - *
67 * @file
78 * @author Niklas Laxström
89 * @copyright Copyright © 2008-2010, Niklas Laxström
@@ -249,6 +250,7 @@
250251
251252 /**
252253 * @todo: needs documentation
 254+ * @deprecated
253255 */
254256 class CoreMessageGroup extends MessageGroupOld {
255257 protected $label = 'MediaWiki';
@@ -369,6 +371,7 @@
370372
371373 /**
372374 * @todo: needs documentation
 375+ * @deprecated
373376 */
374377 class ExtensionMessageGroup extends MessageGroupOld {
375378 protected $magicFile, $aliasFile;
@@ -531,6 +534,7 @@
532535
533536 /**
534537 * @todo: needs documentation
 538+ * @deprecated
535539 */
536540 class AliasMessageGroup extends ExtensionMessageGroup {
537541 protected $dataSource;
@@ -611,6 +615,7 @@
612616
613617 /**
614618 * @todo: needs documentation
 619+ * @deprecated
615620 */
616621 class CoreMostUsedMessageGroup extends CoreMessageGroup {
617622 protected $label = 'MediaWiki (most used)';
@@ -641,6 +646,7 @@
642647
643648 /**
644649 * @todo: needs documentation
 650+ * @deprecated
645651 */
646652 class GettextMessageGroup extends MessageGroupOld {
647653 protected $type = 'gettext';
@@ -719,6 +725,7 @@
720726
721727 /**
722728 * @todo: needs documentation
 729+ * @deprecated
723730 */
724731 class WikiMessageGroup extends MessageGroupOld {
725732 protected $source = null;
@@ -780,6 +787,7 @@
781788
782789 /**
783790 * @todo: needs documentation
 791+ * @deprecated
784792 */
785793 class WikiPageMessageGroup extends WikiMessageGroup {
786794 protected $title;
Index: trunk/extensions/Translate/Message.php
@@ -1,12 +1,16 @@
22 <?php
33 /**
4 - * @todo Needs documentation.
 4+ * Classes for message objects.
 5+ *
56 * @file
67 * @author Niklas Laxström
78 * @copyright Copyright © 2008-2010, Niklas Laxström
89 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
910 */
1011
 12+/**
 13+ * @todo Needs documentation.
 14+ */
1115 abstract class TMessage {
1216 protected $key;
1317 protected $definition;
@@ -48,24 +52,34 @@
4953 $this->tags[] = $tag;
5054 }
5155
52 -
5356 public function key() {
5457 return $this->key;
5558 }
 59+
5660 public function definition() {
5761 return $this->definition;
5862 }
 63+
5964 public function translation() {
60 - if ( !isset( $this->row ) ) return $this->infile();
 65+ if ( !isset( $this->row ) ) {
 66+ return $this->infile();
 67+ }
 68+
6169 return Revision::getRevisionText( $this->row );
6270 }
6371 public function author() {
64 - if ( !isset( $this->row ) ) return null;
 72+ if ( !isset( $this->row ) ) {
 73+ return null;
 74+ }
 75+
6576 return $this->row->rev_user_text;
6677 }
6778
6879 public function infile() {
69 - if ( !isset( $this->infile ) ) return null;
 80+ if ( !isset( $this->infile ) ) {
 81+ return null;
 82+ }
 83+
7084 return $this->infile;
7185 }
7286
@@ -80,12 +94,16 @@
8195 class FatMessage extends TMessage {
8296 protected $translation = null;
8397 protected $infile = null;
 98+
8499 public function setTranslation( $text ) {
85100 $this->translation = $text;
86101 }
87102
88103 public function translation() {
89 - if ( $this->translation === null ) return $this->infile;
 104+ if ( $this->translation === null ) {
 105+ return $this->infile;
 106+ }
 107+
90108 return $this->translation;
91109 }
92110
Index: trunk/extensions/Translate/TranslateTasks.php
@@ -3,10 +3,10 @@
44 * Different tasks which encapsulate the processing of messages to requested
55 * format for the web interface.
66 *
 7+ * @file
78 * @author Niklas Laxström
89 * @copyright Copyright © 2007-2008 Niklas Laxström
910 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
10 - * @file
1111 */
1212
1313 /**
Index: trunk/extensions/Translate/Translate.i18n.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * Translations of Translate extension.
 4+ * Translations for the core of the Translate extension.
55 *
66 * @file
77 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
Index: trunk/extensions/Translate/TranslateUtils.php
@@ -1,6 +1,6 @@
22 <?php
33 /**
4 - * This class contains some static helper functions for other classes.
 4+ * This file contains classes with static helper functions for other classes.
55 *
66 * @file
77 * @author Niklas Laxström
@@ -8,6 +8,9 @@
99 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1010 */
1111
 12+/**
 13+ * @todo Needs documentation.
 14+ */
1215 class TranslateUtils {
1316 const MSG = 'translate-';
1417
@@ -337,6 +340,9 @@
338341 }
339342 }
340343
 344+/**
 345+ * @todo Needs documentation.
 346+ */
341347 class HTMLSelector {
342348 private $options = array();
343349 private $selected = false;

Status & tagging log