r62279 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62278‎ | r62279 | r62280 >
Date:23:10, 10 February 2010
Author:siebrand
Status:deferred
Tags:
Comment:
* fix syntax errors in MessageWebImporter.php from r62278
* run stylize.php on Translate
Modified paths:
  • /trunk/extensions/Translate/SpecialFirstSteps.php (modified) (history)
  • /trunk/extensions/Translate/SpecialSupportedLanguages.php (modified) (history)
  • /trunk/extensions/Translate/groups/MediaWikiExtensions.php (modified) (history)
  • /trunk/extensions/Translate/scripts/tm-export.php (modified) (history)
  • /trunk/extensions/Translate/utils/Html.php (modified) (history)
  • /trunk/extensions/Translate/utils/MessageWebImporter.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationEditPage.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/scripts/tm-export.php
@@ -12,7 +12,7 @@
1313 $optionsWithArgs = array( 'target' );
1414
1515 $dir = dirname( __FILE__ ); $IP = "$dir/../../..";
16 -@include("$dir/../../CorePath.php"); // Allow override
 16+@include( "$dir/../../CorePath.php" ); // Allow override
1717 define( 'TRANSLATE_CLI', 1 );
1818 require_once( "$IP/maintenance/Maintenance.php" );
1919
@@ -35,20 +35,20 @@
3636 $dbw = new DatabaseSqlite( 'server', 'user', 'password', $target_basename );
3737 swap( $wgSQLiteDataDir, $target_dirname );
3838
39 - $dbw->setFlag(DBO_TRX); // HUGE speed improvement
 39+ $dbw->setFlag( DBO_TRX ); // HUGE speed improvement
4040
4141 $groups = MessageGroups::singleton()->getGroups();
4242 // TODO: encapsulate list of valid language codes
4343 $languages = Language::getLanguageNames( false );
4444 unset( $languages['en'] );
4545
46 - foreach( $groups as $id => $group ) {
 46+ foreach ( $groups as $id => $group ) {
4747 if ( $group->isMeta() ) continue;
4848 $this->output( "Processing: {$group->getLabel()} ", $id );
4949 $capitalized = MWNamespace::isCapitalized( $group->getNamespace() );
5050 $ns_text = $wgContLang->getNsText( $group->getNamespace() );
5151
52 - foreach ( $group->load('en') as $key => $definition ) {
 52+ foreach ( $group->load( 'en' ) as $key => $definition ) {
5353 // TODO: would be nice to do key normalisation closer to the message groups, to avoid transforming back and forth.
5454 // But how to preserve the original keys...
5555 $key = strtr( $key, ' ', '_' );
@@ -57,7 +57,7 @@
5858 $dbr = wfGetDB( DB_SLAVE );
5959 $tables = array( 'page', 'revision', 'text' );
6060 // selectFields to stfu Revision class
61 - $vars = array_merge(Revision::selectTextFields(), array( 'page_title' ), Revision::selectFields() );
 61+ $vars = array_merge( Revision::selectTextFields(), array( 'page_title' ), Revision::selectFields() );
6262 $conds = array(
6363 'page_latest = rev_id',
6464 'rev_text_id = old_id',
@@ -72,7 +72,7 @@
7373 $insert = array(
7474 'text' => $definition,
7575 'context' => "$ns_text:$key",
76 - 'length' => strlen($definition),
 76+ 'length' => strlen( $definition ),
7777 'lang' => 'en'
7878 );
7979
@@ -86,7 +86,7 @@
8787
8888 foreach ( $res as $row ) {
8989 list( , $code ) = TranslateUtils::figureMessage( $row->page_title );
90 - $revision = new Revision($row);
 90+ $revision = new Revision( $row );
9191 $insert = array(
9292 'text' => $revision->getText(),
9393 'lang' => $code,
Index: trunk/extensions/Translate/SpecialFirstSteps.php
@@ -98,7 +98,7 @@
9999 $this->out->addWikiMsg( 'translate-fs-settings-text' );
100100 $form = new HtmlTag( 'form' );
101101 $items = new TagContainer();
102 - $form->param( 'method', 'post')->content( $items );
 102+ $form->param( 'method', 'post' )->content( $items );
103103 $items[] = new RawHtml( Html::hidden( 'step', 'settings' ) );
104104 $items[] = new RawHtml( Xml::submitButton( wfMsg( 'translate-fs-settings-skip' ) ) );
105105
@@ -129,7 +129,7 @@
130130 $this->user->matchEditToken( $wgRequest->getVal( 'token' ) ) &&
131131 $wgRequest->getText( 'step' ) === 'userpage' )
132132 {
133 - $article = new Article($userpage);
 133+ $article = new Article( $userpage );
134134 $status = $article->doEdit( $wgRequest->getText( $textareaId ), $this->getTitle() );
135135 if ( $status->isOK() ) {
136136 $header->content( $header->content . wfMsg( 'translate-fs-pagetitle-done' ) );
@@ -163,7 +163,7 @@
164164
165165 $form = new HtmlTag( 'form' );
166166 $items = new TagContainer();
167 - $form->param( 'method', 'post')->content( $items );
 167+ $form->param( 'method', 'post' )->content( $items );
168168
169169 $items[] = new RawHtml( Html::hidden( 'step', 'userpage' ) );
170170 $items[] = new RawHtml( Html::hidden( 'token', $this->user->editToken() ) );
Index: trunk/extensions/Translate/SpecialSupportedLanguages.php
@@ -31,7 +31,7 @@
3232 LanguageNames::LIST_MW_AND_CLDR
3333 );
3434 $natives = Language::getLanguageNames( false );
35 - ksort($natives);
 35+ ksort( $natives );
3636
3737 $titles = array();
3838 foreach ( $natives as $code => $_ ) {
@@ -40,7 +40,7 @@
4141
4242 $dbr = wfGetDB( DB_SLAVE );
4343 $tables = array( 'page', 'revision', 'text' );
44 - $vars = array_merge(Revision::selectTextFields(), array( 'page_title', 'page_namespace' ), Revision::selectFields() );
 44+ $vars = array_merge( Revision::selectTextFields(), array( 'page_title', 'page_namespace' ), Revision::selectFields() );
4545 $conds = array(
4646 'page_latest = rev_id',
4747 'rev_text_id = old_id',
@@ -54,11 +54,11 @@
5555 $lb = new LinkBatch;
5656
5757 foreach ( $res as $row ) {
58 - $rev = new Revision($row);
 58+ $rev = new Revision( $row );
5959 $text = $rev->getText();
6060 $code = strtolower( preg_replace( '!/translators$!', '', $row->page_title ) );
6161 preg_match_all( '!{{user\|([^}|]+)!', $text, $matches, PREG_SET_ORDER );
62 - foreach( $matches as $match ) {
 62+ foreach ( $matches as $match ) {
6363 $user = Title::capitalize( $match[1], NS_USER );
6464 $lb->add( NS_USER, $user );
6565 $lb->add( NS_USER_TALK, $user );
@@ -69,7 +69,7 @@
7070 $lb->execute();
7171 global $wgUser;
7272 $skin = $wgUser->getSkin();
73 - foreach ( array_keys($users) as $code ) {
 73+ foreach ( array_keys( $users ) as $code ) {
7474 $wgOut->addWikiText( "== [$code] {$locals[$code]} - {$natives[$code]} ==" );
7575
7676 foreach ( $users[$code] as $index => $username ) {
Index: trunk/extensions/Translate/groups/MediaWikiExtensions.php
@@ -212,7 +212,7 @@
213213 $group->setDescriptionMsg( $info['descmsg'], $info['url'] );
214214 }
215215
216 - if( $group->getDescription() == '' ) {
 216+ if ( $group->getDescription() == '' ) {
217217 global $wgLang;
218218 $group->setDescription( wfMsg( 'translate-group-desc-nodesc' ) );
219219 }
Index: trunk/extensions/Translate/utils/TranslationEditPage.php
@@ -39,7 +39,7 @@
4040 $helpers = new TranslationHelpers( $this->getTitle() );
4141
4242 // jQuery borks on something, probably to :, thus, don't use special chars
43 - $id = Sanitizer::escapeId( sha1($this->getTitle()->getPrefixedText()) );
 43+ $id = Sanitizer::escapeId( sha1( $this->getTitle()->getPrefixedText() ) );
4444 $helpers->setTextareaId( $id );
4545
4646 global $wgServer, $wgScriptPath, $wgOut;
Index: trunk/extensions/Translate/utils/Html.php
@@ -84,7 +84,7 @@
8585 }
8686
8787 if ( $value === false ) {
88 - unset($this->params[$name]);
 88+ unset( $this->params[$name] );
8989 } else {
9090 $this->params[$name] = $this->assert( 'is_string', $value );
9191 }
@@ -105,7 +105,7 @@
106106 }
107107
108108 if ( $value === false ) {
109 - unset($this->style[$name]);
 109+ unset( $this->style[$name] );
110110 } else {
111111 $this->style[$name] = $this->assert( 'is_string', $value );
112112 }
@@ -130,7 +130,7 @@
131131 $style = $this->collapseStyles();
132132 if ( $style ) $params['style'] = $style;
133133
134 - if ( is_object($this->content) ) {
 134+ if ( is_object( $this->content ) ) {
135135 return Html::rawElement( $this->tag, $params, $this->content );
136136 } else {
137137 return Html::element( $this->tag, $params, $this->content );
@@ -174,14 +174,14 @@
175175 */
176176 protected function assert( $function, $value, $result = true ) {
177177 if ( $function === 'is_string' ) {
178 - if ( is_int($value) || is_float( $value ) ) $value = (string) $value;
 178+ if ( is_int( $value ) || is_float( $value ) ) $value = (string) $value;
179179 }
180180
181181 $real_result = call_user_func( $function, $value );
182182 if ( $real_result === $result ) return $value;
183183 $msg = __METHOD__ . ":expecting $function to be $result";
184184 if ( $this->strict ) {
185 - throw new MWException($msg);
 185+ throw new MWException( $msg );
186186 } else {
187187 wfWarn( $msg );
188188 return $value;
Index: trunk/extensions/Translate/utils/MessageWebImporter.php
@@ -350,7 +350,7 @@
351351
352352 $changed = array();
353353
354 - if( !$user ) {
 354+ if ( !$user ) {
355355 $user = self::getFuzzyBot();
356356 }
357357
@@ -428,19 +428,19 @@
429429 * @return section element
430430 */
431431 public static function makeSectionElement( $legend, $type, $content, $params = array() ) {
432 - if( isset( $params['container'] ) {
 432+ if ( isset( $params['container'] ) ) {
433433 $containerParams = array( 'class' => $params['container'] );
434434 } else {
435435 $containerParams = array( 'class' => "mw-tpt-sp-section mw-tpt-sp-section-type-{$type}" );
436436 }
437437
438 - if( isset( $params['legend'] ) {
 438+ if ( isset( $params['legend'] ) ) {
439439 $legendParams = array( 'class' => $params['legend'] );
440440 } else {
441441 $legendParams = array( 'class' => 'mw-translate-manage-legend' );
442442 }
443443
444 - if( isset( $params['content'] ) {
 444+ if ( isset( $params['content'] ) ) {
445445 $contentParams = array( 'class' => $params['content'] );
446446 } else {
447447 $contentParams = array( 'class' => 'mw-tpt-sp-content' );
Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -184,7 +184,7 @@
185185 }
186186 }
187187
188 - foreach( $sugFields as $field ) {
 188+ foreach ( $sugFields as $field ) {
189189 list( $text, $params, $label ) = $field;
190190 $legend = array();
191191 foreach ( $label as $acc => $links ) { $legend[] = $acc . ' ' . implode( " ", $links ); }
@@ -244,17 +244,17 @@
245245 if ( $google_json === false ) {
246246 wfWarn( __METHOD__ . ': Http::get failed' );
247247 return null;
248 - } elseif( !is_object( $response ) ) {
 248+ } elseif ( !is_object( $response ) ) {
249249 wfWarn( __METHOD__ . ': Unable to parse reply: ' . strval( $google_json ) );
250250 error_log( __METHOD__ . ': Unable to parse reply: ' . strval( $google_json ) );
251251 return null;
252252 }
253253 if ( $response->responseStatus === 200 ) {
254254 $text = $this->suggestionField( Sanitizer::decodeCharReferences( $response->responseData->translatedText ) );
255 - return Html::rawElement( 'div', null, self::legend('Google') . $text . self::clear() );
256 - } elseif( $response->responseDetails === 'invalid translation language pair' ) {
 255+ return Html::rawElement( 'div', null, self::legend( 'Google' ) . $text . self::clear() );
 256+ } elseif ( $response->responseDetails === 'invalid translation language pair' ) {
257257 $unsupported[$code] = true;
258 - $wgMemc->set( $memckey, $unsupported, 60*60*8 );
 258+ $wgMemc->set( $memckey, $unsupported, 60 * 60 * 8 );
259259 } else {
260260 wfWarn( __METHOD__ . ': ' . $response->responseDetails );
261261 error_log( __METHOD__ . ': ' . $response->responseDetails );
@@ -291,7 +291,7 @@
292292 $pairs[$target][$source] = true;
293293 }
294294
295 - $wgMemc->set( $memckey, $pairs, 60*60*24 );
 295+ $wgMemc->set( $memckey, $pairs, 60 * 60 * 24 );
296296 }
297297
298298 $codemap = array( 'no' => 'nb' );
@@ -304,7 +304,7 @@
305305
306306 $codemap = array_flip( $codemap );
307307 foreach ( $pairs[$code] as $candidate => $unused ) {
308 - $mwcode = str_replace( '_', '-', strtolower($candidate));
 308+ $mwcode = str_replace( '_', '-', strtolower( $candidate ) );
309309 if ( isset( $codemap[$mwcode] ) ) $mwcode = $codemap[$mwcode];
310310
311311 $text = TranslateUtils::getMessageContent( $page, $mwcode, $ns );
@@ -326,7 +326,7 @@
327327 $suggestions[] = Html::rawElement( 'div', null, self::legend( "Apertium ($candidate)" ) . $response . self::clear() );
328328 }
329329 }
330 - if ( !count($suggestions) ) return null;
 330+ if ( !count( $suggestions ) ) return null;
331331 return implode( "\n", $suggestions );
332332 }
333333
@@ -598,7 +598,7 @@
599599 $counter++;
600600 $id = "tmsug-" . wfTimestamp() . "-$counter";
601601 $contents = TranslateUtils::convertWhiteSpaceToHTML( $contents );
602 - return $this->adder($id) . "\n" . Html::rawElement( 'span', array( 'id' => $id ), $contents );
 602+ return $this->adder( $id ) . "\n" . Html::rawElement( 'span', array( 'id' => $id ), $contents );
603603 }
604604
605605 public static function editLink( $target, $text, $params = array() ) {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r62278Use MessageWebImporter::makeSectionElement only, and remove it from ManageGro...siebrand23:05, 10 February 2010

Status & tagging log