r66868 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66867‎ | r66868 | r66869 >
Date:11:08, 25 May 2010
Author:siebrand
Status:deferred
Tags:
Comment:
Update code formatting.
Modified paths:
  • /trunk/extensions/Translate/tag/PageTranslationHooks.php (modified) (history)
  • /trunk/extensions/Translate/tag/RenderJob.php (modified) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslation.php (modified) (history)
  • /trunk/extensions/Translate/tag/TPParse.php (modified) (history)
  • /trunk/extensions/Translate/tag/TPSection.php (modified) (history)
  • /trunk/extensions/Translate/tag/TranslatablePage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/tag/TranslatablePage.php
@@ -60,7 +60,9 @@
6161
6262 public static function newFromRevision( Title $title, $revision ) {
6363 $rev = Revision::newFromTitle( $title, $revision );
64 - if ( $rev === null ) throw new MWException( 'Revision is null' );
 64+ if ( $rev === null ) {
 65+ throw new MWException( 'Revision is null' );
 66+ }
6567
6668 $obj = new self( $title );
6769 $obj->source = 'revision';
@@ -104,8 +106,12 @@
105107 }
106108 }
107109
108 - if ( !is_string( $this->text ) ) throw new MWException( 'We have no text' );
 110+ if ( !is_string( $this->text ) ) {
 111+ throw new MWException( 'We have no text' );
 112+ }
 113+
109114 $this->init = true;
 115+
110116 return $this->text;
111117 }
112118
@@ -135,7 +141,9 @@
136142 * page.
137143 */
138144 public function getParse() {
139 - if ( isset( $this->cachedParse ) ) return $this->cachedParse;
 145+ if ( isset( $this->cachedParse ) ) {
 146+ return $this->cachedParse;
 147+ }
140148
141149 $text = $this->getText();
142150
@@ -149,8 +157,11 @@
150158 $re = '~(<translate>)\s*(.*?)(</translate>)~s';
151159 $matches = array();
152160 $ok = preg_match_all( $re, $text, $matches, PREG_OFFSET_CAPTURE );
153 - if ( $ok === 0 ) break; // No matches
154161
 162+ if ( $ok === 0 ) {
 163+ break; // No matches
 164+ }
 165+
155166 // Do-placehold for the whole stuff
156167 $ph = self::getUniq();
157168 $start = $matches[0][0][1];
@@ -183,6 +194,7 @@
184195 foreach ( $tagPlaceHolders as $ph => $value ) {
185196 $prettyTemplate = str_replace( $ph, '[...]', $prettyTemplate );
186197 }
 198+
187199 if ( strpos( $text, '<translate>' ) !== false ) {
188200 throw new TPException( array( 'pt-parse-open', $prettyTemplate ) );
189201 } elseif ( strpos( $text, '</translate>' ) !== false ) {
@@ -209,11 +221,13 @@
210222
211223 public static function armourNowiki( &$holders, $text ) {
212224 $re = '~(<nowiki>)(.*?)(</nowiki>)~';
 225+
213226 while ( preg_match( $re, $text, $matches ) ) {
214227 $ph = self::getUniq();
215228 $text = str_replace( $matches[0], $ph, $text );
216229 $holders[$ph] = $matches[0];
217230 }
 231+
218232 return $text;
219233 }
220234
@@ -221,6 +235,7 @@
222236 foreach ( $holders as $ph => $value ) {
223237 $text = str_replace( $ph, $value, $text );
224238 }
 239+
225240 return $text;
226241 }
227242
@@ -229,6 +244,7 @@
230245 */
231246 protected static function getUniq() {
232247 static $i = 0;
 248+
233249 return "\x7fUNIQ" . dechex( mt_rand( 0, 0x7fffffff ) ) . dechex( mt_rand( 0, 0x7fffffff ) ) . '|' . $i++;
234250 }
235251
@@ -247,7 +263,7 @@
248264 protected function sectionise( &$sections, $text ) {
249265 $flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE;
250266 $parts = preg_split( '~(\s*\n\n\s*|\s*$)~', $text, -1, $flags );
251 -
 267+
252268 $template = '';
253269 foreach ( $parts as $_ ) {
254270 if ( trim( $_ ) === '' ) {
@@ -258,6 +274,7 @@
259275 $template .= $ph;
260276 }
261277 }
 278+
262279 return $template;
263280 }
264281
@@ -275,6 +292,7 @@
276293 $re = '~<!--T:(.*?)-->~';
277294 $matches = array();
278295 $count = preg_match_all( $re, $content, $matches, PREG_SET_ORDER );
 296+
279297 if ( $count > 1 ) {
280298 throw new TPException( array( 'pt-shake-multiple', $content ) );
281299 }
@@ -291,6 +309,7 @@
292310 $rer2 = '~\s*<!--T:(.*?)-->\n~'; // Sections with title
293311 $content = preg_replace( $rer1, '', $content );
294312 $content = preg_replace( $rer2, '', $content );
 313+
295314 if ( preg_match( $re, $content ) === 1 ) {
296315 throw new TPException( array( 'pt-shake-position', $content ) );
297316 } elseif ( trim( $content ) === '' ) {
@@ -316,12 +335,13 @@
317336 }
318337
319338 protected function addTag( $tag, $revision, $value = null ) {
320 -
321339 $dbw = wfGetDB( DB_MASTER );
322340
323341 $id = $this->getTagId( $tag );
324342
325 - if ( is_object( $revision ) ) throw new MWException( 'Got object, excepted id' );
 343+ if ( is_object( $revision ) ) {
 344+ throw new MWException( 'Got object, excepted id' );
 345+ }
326346
327347 $conds = array(
328348 'rt_page' => $this->getTitle()->getArticleId(),
@@ -329,13 +349,18 @@
330350 'rt_revision' => $revision
331351 );
332352 $dbw->delete( 'revtag', $conds, __METHOD__ );
333 - if ( $value !== null ) $conds['rt_value'] = serialize( implode( '|', $value ) );
 353+
 354+ if ( $value !== null ) {
 355+ $conds['rt_value'] = serialize( implode( '|', $value ) );
 356+ }
 357+
334358 $dbw->insert( 'revtag', $conds, __METHOD__ );
335359 }
336360
337361 public function getMarkedTag( $db = DB_SLAVE ) {
338362 return $this->getTag( 'tp:mark' );
339363 }
 364+
340365 public function getReadyTag( $db = DB_SLAVE ) {
341366 return $this->getTag( 'tp:tag' );
342367 }
@@ -359,14 +384,18 @@
360385
361386 $id = $this->getTagId( $tag );
362387
363 - if ( !$this->getTitle()->exists() ) return false;
 388+ if ( !$this->getTitle()->exists() ) {
 389+ return false;
 390+ }
364391
365392 $fields = 'rt_revision';
366393 $conds = array(
367394 'rt_page' => $this->getTitle()->getArticleId(),
368395 'rt_type' => $id,
369396 );
 397+
370398 $options = array( 'ORDER BY' => 'rt_revision DESC' );
 399+
371400 return $db->selectField( 'revtag', $fields, $conds, __METHOD__, $options );
372401 }
373402
@@ -377,7 +406,10 @@
378407 'group' => 'page|' . $this->getTitle()->getPrefixedText(),
379408 'task' => 'view'
380409 );
381 - if ( $code ) $params['language'] = $code;
 410+ if ( $code ) {
 411+ $params['language'] = $code;
 412+ }
 413+
382414 return $translate->getFullURL( $params );
383415 }
384416
@@ -394,6 +426,7 @@
395427 'rt_type' => $id,
396428 );
397429 $options = array( 'ORDER BY' => 'rt_revision DESC' );
 430+
398431 return $db->select( 'revtag', $fields, $conds, __METHOD__, $options );
399432 }
400433
@@ -407,9 +440,12 @@
408441 array(
409442 'page_namespace' => $this->getTitle()->getNamespace(),
410443 "page_title LIKE '$likePattern'"
411 - ), __METHOD__ );
 444+ ),
 445+ __METHOD__
 446+ );
412447
413448 $titles = TitleArray::newFromResult( $res );
 449+
414450 return $titles;
415451 }
416452
@@ -418,19 +454,23 @@
419455 global $wgMemc, $wgRequest;
420456 $memcKey = wfMemcKey( 'pt', 'status', $this->getTitle()->getPrefixedText() );
421457 $cache = $wgMemc->get( $memcKey );
 458+
422459 if ( !$force && $wgRequest->getText( 'action' ) !== 'purge' ) {
423 - if ( is_array( $cache ) ) return $cache;
 460+ if ( is_array( $cache ) ) {
 461+ return $cache;
 462+ }
424463 }
425464
426465 $titles = $this->getTranslationPages();
427466
428467 // Calculate percentages for the available translations
429468 $group = MessageGroups::getGroup( 'page|' . $this->getTitle()->getPrefixedText() );
430 - if ( !$group instanceof WikiPageMessageGroup ) return null;
 469+ if ( !$group instanceof WikiPageMessageGroup ) {
 470+ return null;
 471+ }
431472
432473 $markedRevs = $this->getMarkedRevs( 'tp:mark' );
433474
434 -
435475 $temp = array();
436476 foreach ( $titles as $t ) {
437477 list( , $code ) = TranslateUtils::figureMessage( $t->getText() );
@@ -439,19 +479,22 @@
440480 $percent = $this->getPercentageInternal( $collection, $markedRevs );
441481 // To avoid storing 40 decimals of inaccuracy, truncate to two decimals
442482 $temp[$collection->code] = sprintf( '%.2f', $percent );
443 -
444483 }
 484+
445485 // Content language is always up-to-date
446486 global $wgContLang;
447487 $temp[$wgContLang->getCode()] = 1.00;
448488
449489 $wgMemc->set( $memcKey, $temp, 60 * 60 * 12 );
 490+
450491 return $temp;
451492 }
452493
453494 protected function getPercentageInternal( $collection, $markedRevs ) {
454495 $count = count( $collection );
455 - if ( $count === 0 ) return 0;
 496+ if ( $count === 0 ) {
 497+ return 0;
 498+ }
456499
457500 // We want to get fuzzy though
458501 $collection->filter( 'hastranslation', false );
@@ -463,7 +506,9 @@
464507 $score = 1;
465508
466509 // Fuzzy halves score
467 - if ( $message->hasTag( 'fuzzy' ) ) $score *= 0.5;
 510+ if ( $message->hasTag( 'fuzzy' ) ) {
 511+ $score *= 0.5;
 512+ }
468513
469514 // Reduce 20% for every newer revision than what is translated against
470515 $rev = $this->getTransrev( $key . '/' . $collection->code );
@@ -498,8 +543,8 @@
499544 'rt_type' => $id,
500545 );
501546 $options = array( 'ORDER BY' => 'rt_revision DESC' );
 547+
502548 return $db->selectField( 'revtag', $fields, $conds, __METHOD__, $options );
503 -
504549 }
505550
506551 protected function getTagId( $tag ) {
@@ -509,7 +554,7 @@
510555 }
511556
512557 global $wgTranslateStaticTags;
513 - if ( is_array($wgTranslateStaticTags) ) {
 558+ if ( is_array( $wgTranslateStaticTags ) ) {
514559 return $wgTranslateStaticTags[$tag];
515560 }
516561
@@ -524,21 +569,34 @@
525570 array( 'rtt_name' => $validTags ),
526571 __METHOD__
527572 );
 573+
528574 foreach ( $res as $r ) {
529575 $tagcache[$r->rtt_name] = $r->rtt_id;
530576 }
531577 }
 578+
532579 return $tagcache[$tag];
533580 }
534581
535582 public static function isTranslationPage( Title $title ) {
536583 list( $key, $code ) = TranslateUtils::figureMessage( $title->getText() );
537 - if ( $key === '' || $code === '' ) return false;
 584+
 585+ if ( $key === '' || $code === '' ) {
 586+ return false;
 587+ }
 588+
538589 $newtitle = self::changeTitleText( $title, $key );
539 - if ( !$newtitle ) return false;
 590+
 591+ if ( !$newtitle ) {
 592+ return false;
 593+ }
 594+
540595 $page = TranslatablePage::newFromTitle( $newtitle );
541596
542 - if ( $page->getMarkedTag() === false ) return false;
 597+ if ( $page->getMarkedTag() === false ) {
 598+ return false;
 599+ }
 600+
543601 return $page;
544602 }
545603
@@ -561,4 +619,3 @@
562620 return $this->msg;
563621 }
564622 }
565 -
Index: trunk/extensions/Translate/tag/RenderJob.php
@@ -1,5 +1,4 @@
22 <?php
3 -
43 /**
54 * Job for updating translation pages.
65 *
@@ -19,6 +18,7 @@
2019 $job->setUser( $wgTranslateFuzzyBotName );
2120 $job->setFlags( EDIT_FORCE_BOT );
2221 $job->setSummary( wfMsgForContent( 'tpt-render-summary' ) );
 22+
2323 return $job;
2424 }
2525
@@ -83,7 +83,6 @@
8484 return $this->params['flags'];
8585 }
8686
87 -
8887 public function setSummary( $summary ) {
8988 $this->params['summary'] = $summary;
9089 }
@@ -92,7 +91,6 @@
9392 return $this->params['summary'];
9493 }
9594
96 -
9795 public function setUser( $user ) {
9896 if ( $user instanceof User ) {
9997 $this->params['user'] = $user->getName();
@@ -100,6 +98,7 @@
10199 $this->params['user'] = $user;
102100 }
103101 }
 102+
104103 /**
105104 * Get a user object for doing edits.
106105 */
@@ -107,4 +106,3 @@
108107 return User::newFromName( $this->params['user'], false );
109108 }
110109 }
111 -
Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php
@@ -11,7 +11,7 @@
1212
1313 class SpecialPageTranslation extends SpecialPage {
1414 function __construct() {
15 - SpecialPage::SpecialPage( 'PageTranslation' );
 15+ parent::__construct( 'PageTranslation' );
1616 }
1717
1818 public function execute( $parameters ) {
@@ -31,6 +31,7 @@
3232 } else {
3333 $this->listPages();
3434 }
 35+
3536 return;
3637 }
3738
@@ -41,7 +42,7 @@
4243 }
4344
4445 // Check permissions
45 - if (!$this->user->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
 46+ if ( !$this->user->matchEditToken( $wgRequest->getText( 'token' ) ) ) {
4647 $wgOut->permissionRequired( 'pagetranslation' );
4748 return;
4849 }
@@ -63,6 +64,7 @@
6465 // Get the latest revision
6566 $revision = $title->getLatestRevID();
6667 }
 68+
6769 $page = TranslatablePage::newFromRevision( $title, $revision );
6870 if ( !$page instanceof TranslatablePage ) {
6971 $wgOut->addWikiMsg( 'tpt-notsuitable', $title->getPrefixedText(), $revision );
@@ -85,6 +87,7 @@
8688 // This will modify the sections to include name property
8789 $error = false;
8890 $sections = $this->checkInput( $page, $error );
 91+
8992 // Non-fatal error which prevents saving
9093 if ( $error === false && $wgRequest->wasPosted() ) {
9194 $err = $this->markForTranslation( $page, $sections );
@@ -94,8 +97,10 @@
9598 $this->showSuccess( $page );
9699 $this->listPages();
97100 }
 101+
98102 return;
99103 }
 104+
100105 $this->showPage( $page, $sections );
101106 }
102107
@@ -106,6 +111,7 @@
107112 $num = $wgLang->formatNum( $page->getParse()->countSections() );
108113 $link = SpecialPage::getTitleFor( 'Translate' )->getFullUrl(
109114 array( 'group' => 'page|' . $page->getTitle()->getPrefixedText() ) );
 115+
110116 $wgOut->addWikiMsg( 'tpt-saveok', $titleText, $num, $link );
111117 }
112118
@@ -123,6 +129,7 @@
124130 'GROUP BY' => 'page_id, rtt_id',
125131 );
126132 $res = $dbr->select( $tables, $vars, $conds, __METHOD__, $options );
 133+
127134 return $res;
128135 }
129136
@@ -141,22 +148,32 @@
142149 $pages[$r->page_id] = array();
143150 $pages[$r->page_id]['title'] = Title::newFromRow( $r );
144151 }
 152+
145153 $pages[$r->page_id][$r->rtt_name] = $r->rt_revision;
146154 }
147155
148156 // Pages where mark <= tag
149157 $items = array();
150158 foreach ( $pages as $index => $page ) {
151 - if ( !isset( $page['tp:mark'] ) ) continue;
152 - if ( !isset( $page['tp:tag'] ) ) continue;
153 - if ( $page['tp:mark'] > $page['tp:tag'] ) continue;
 159+ if ( !isset( $page['tp:mark'] ) ) {
 160+ continue;
 161+ }
 162+
 163+ if ( !isset( $page['tp:tag'] ) ) {
 164+ continue;
 165+ }
 166+
 167+ if ( $page['tp:mark'] > $page['tp:tag'] ) {
 168+ continue;
 169+ }
 170+
154171 $link = $this->user->getSkin()->link( $page['title'] );
155172 $acts = $this->actionLinks( $page['title'], $page['tp:mark'], 'old' );
156173 $items[] = "<li>$link ($acts) </li>";
157174 unset( $pages[$index] );
158175 }
159176
160 - if ( count($items) ) {
 177+ if ( count( $items ) ) {
161178 $wgOut->addWikiMsg( 'tpt-old-pages', count( $items ) );
162179 $wgOut->addHtml( Html::rawElement( 'ol', null, implode( "\n", $items ) ) );
163180 $wgOut->addHtml( '<hr />' );
@@ -165,15 +182,22 @@
166183 // Pages which are never marked
167184 $items = array();
168185 foreach ( $pages as $index => $page ) {
169 - if ( isset( $page['tp:mark'] ) ) continue;
170 - if ( !isset( $page['tp:tag'] ) ) continue;
 186+ if ( isset( $page['tp:mark'] ) ) {
 187+ continue;
 188+ }
 189+
 190+ if ( !isset( $page['tp:tag'] ) ) {
 191+ continue;
 192+ }
 193+
171194 $link = $this->user->getSkin()->link( $page['title'] );
172195 $acts = $this->actionLinks( $page['title'], $page['tp:tag'], 'old' );
173196 $items[] = "<li>$link ($acts) </li>";
 197+
174198 unset( $pages[$index] );
175199 }
176200
177 - if ( count($items) ) {
 201+ if ( count( $items ) ) {
178202 $wgOut->addWikiMsg( 'tpt-new-pages', count( $items ) );
179203 $wgOut->addHtml( Html::rawElement( 'ol', null, implode( "\n", $items ) ) );
180204 $wgOut->addHtml( '<hr />' );
@@ -186,15 +210,15 @@
187211 $link = $this->user->getSkin()->link( $page['title'] );
188212 $acts = $this->actionLinks( $page['title'], $page['tp:tag'], 'stuck' );
189213 $items[] = "<li>$link ($acts) </li>";
 214+
190215 unset( $pages[$index] );
191216 }
192217
193 - if ( count($items) ) {
 218+ if ( count( $items ) ) {
194219 $wgOut->addWikiMsg( 'tpt-other-pages', count( $items ) );
195220 $wgOut->addHtml( Html::rawElement( 'ol', null, implode( "\n", $items ) ) );
196221 $wgOut->addHtml( '<hr />' );
197222 }
198 -
199223 }
200224
201225 protected function actionLinks( $title, $rev, $old = 'old' ) {
@@ -220,8 +244,10 @@
221245 if ( $this->user->isAllowed( 'pagetranslation' ) ) {
222246 $token = $this->user->editToken();
223247
224 - if ( ( $old === 'new' && $latest === $rev ) ||
225 - ( $old === 'old' && $latest !== $rev ) ) {
 248+ if (
 249+ ( $old === 'new' && $latest === $rev ) ||
 250+ ( $old === 'old' && $latest !== $rev )
 251+ ) {
226252 $actions[] = $this->user->getSkin()->link(
227253 $this->getTitle(),
228254 wfMsgHtml( 'tpt-rev-mark-new' ),
@@ -270,7 +296,9 @@
271297 // the new id only after it is saved into db and the page.
272298 // Do not allow changing names for old sections
273299 $s->name = $s->id;
274 - if ( $s->type !== 'new' ) continue;
 300+ if ( $s->type !== 'new' ) {
 301+ continue;
 302+ }
275303
276304 $name = $wgRequest->getText( 'tpt-sect-' . $s->id, $s->id );
277305
@@ -279,6 +307,7 @@
280308 NS_TRANSLATIONS,
281309 $page->getTitle()->getPrefixedText() . '/' . $name . '/foo'
282310 );
 311+
283312 if ( trim( $name ) === '' || !$sectionTitle ) {
284313 $wgOut->addWikiMsg( 'tpt-badsect', $name, $s->id );
285314 $error = true;
@@ -340,6 +369,7 @@
341370 $deletedSections = $page->getParse()->getDeletedSections();
342371 if ( count( $deletedSections ) ) {
343372 $wgOut->wrapWikiMsg( '==$1==', 'tpt-sections-deleted' );
 373+
344374 foreach ( $deletedSections as $s ) {
345375 $name = wfMsgHtml( 'tpt-section-deleted', htmlspecialchars( $s->id ) );
346376 $text = TranslateUtils::convertWhiteSpaceToHTML( $s->getText() );
@@ -349,7 +379,6 @@
350380
351381 // Display template changes if applicable
352382 if ( $page->getMarkedTag() !== false ) {
353 -
354383 $newTemplate = $page->getParse()->getTemplatePretty();
355384 $oldPage = TranslatablePage::newFromRevision( $page->getTitle(), $page->getMarkedTag() );
356385 $oldTemplate = $oldPage->getParse()->getTemplatePretty();
@@ -383,7 +412,6 @@
384413 * - Invalidates caches
385414 */
386415 public function markForTranslation( TranslatablePage $page, Array $sections ) {
387 -
388416 // Add the section markers to the source page
389417 $article = new Article( $page->getTitle() );
390418 $status = $article->doEdit(
@@ -393,7 +421,9 @@
394422 $page->getRevision() // Based-on revision
395423 );
396424
397 - if ( !$status->isOK() ) return array( 'tpt-edit-failed', $status->getWikiText() );
 425+ if ( !$status->isOK() ) {
 426+ return array( 'tpt-edit-failed', $status->getWikiText() );
 427+ }
398428
399429 $newrevision = $status->value['revision'];
400430
@@ -411,6 +441,7 @@
412442
413443 $inserts = array();
414444 $changed = array();
 445+
415446 foreach ( $sections as $s ) {
416447 if ( $s->type === 'changed' ) $changed[] = $s->name;
417448 $inserts[] = array(
@@ -421,7 +452,9 @@
422453 }
423454
424455 // Don't add stuff is no changes, use the plain null instead for prettiness
425 - if ( !count( $changed ) ) $changed = null;
 456+ if ( !count( $changed ) ) {
 457+ $changed = null;
 458+ }
426459
427460 $dbw = wfGetDB( DB_MASTER );
428461 $dbw->delete( 'translate_sections', array( 'trs_page' => $page->getTitle()->getArticleId() ), __METHOD__ );
@@ -442,10 +475,14 @@
443476 }
444477
445478 public function addFuzzyTags( $page, $changed ) {
446 - if ( !count( $changed ) ) return;
 479+ if ( !count( $changed ) ) {
 480+ return;
 481+ }
 482+
447483 $titles = array();
448484 $prefix = $page->getTitle()->getPrefixedText();
449485 $db = wfGetDB( DB_MASTER );
 486+
450487 foreach ( $changed as $c ) {
451488 $title = Title::makeTitleSafe( NS_TRANSLATIONS, "$prefix/$c" );
452489 if ( $title ) {
@@ -470,6 +507,7 @@
471508 'rt_revision' => $r->page_latest,
472509 );
473510 }
 511+
474512 if ( count( $inserts ) ) {
475513 $db->replace( 'revtag', array( 'rt_type_page_revision' ), $inserts, __METHOD__ );
476514 }
@@ -478,16 +516,18 @@
479517 public function setupRenderJobs( TranslatablePage $page ) {
480518 $titles = $page->getTranslationPages();
481519 $jobs = array();
 520+
482521 foreach ( $titles as $t ) {
483522 $jobs[] = RenderJob::newJob( $t );
484523 }
485524
486525 if ( count( $jobs ) < 10 ) {
487 - foreach ( $jobs as $j ) $j->run();
 526+ foreach ( $jobs as $j ) {
 527+ $j->run();
 528+ }
488529 } else {
489530 // Use the job queue
490531 Job::batchInsert( $jobs );
491532 }
492533 }
493 -
494534 }
Index: trunk/extensions/Translate/tag/TPParse.php
@@ -7,6 +7,7 @@
88 * @copyright Copyright © 2009-2010 Niklas Laxström
99 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1010 */
 11+
1112 class TPParse {
1213 protected $title = null;
1314
@@ -32,8 +33,8 @@
3334 foreach ( $sections as $ph => $s ) {
3435 $text = str_replace( $ph, "<!--T:{$s->id}-->", $text );
3536 }
 37+
3638 return $text;
37 -
3839 }
3940
4041 public function getSectionsForSave() {
@@ -45,7 +46,10 @@
4647 $highest = max( $highest, $key );
4748 }
4849
49 - foreach ( $sections as $_ ) $highest = max( $_->id, $highest );
 50+ foreach ( $sections as $_ ) {
 51+ $highest = max( $_->id, $highest );
 52+ }
 53+
5054 foreach ( $sections as $s ) {
5155 $s->type = 'old';
5256
@@ -68,17 +72,21 @@
6973
7074 public function getDeletedSections() {
7175 $sections = $this->getSectionsForSave();
 76+ $deleted = $this->dbSections;
7277
73 - $deleted = $this->dbSections;
7478 foreach ( $sections as $s ) {
75 - if ( isset( $deleted[$s->id] ) )
 79+ if ( isset( $deleted[$s->id] ) ) {
7680 unset( $deleted[$s->id] );
 81+ }
7782 }
 83+
7884 return $deleted;
7985 }
8086
8187 protected function loadFromDatabase() {
82 - if ( $this->dbSections !== null ) return;
 88+ if ( $this->dbSections !== null ) {
 89+ return;
 90+ }
8391
8492 $this->dbSections = array();
8593
@@ -99,9 +107,11 @@
100108
101109 public function getSourcePageText() {
102110 $text = $this->template;
 111+
103112 foreach ( $this->sections as $ph => $s ) {
104113 $text = str_replace( $ph, $s->getMarkedText(), $text );
105114 }
 115+
106116 return $text;
107117 }
108118
@@ -156,10 +166,11 @@
157167 foreach ( $variables as $key => $value ) {
158168 $text = str_replace( $key, $value, $text );
159169 }
 170+
160171 return $text;
161172 }
162173
163174 protected static function replaceTagCb( $matches ) {
164175 return $matches[2];
165176 }
166 -}
\ No newline at end of file
 177+}
Index: trunk/extensions/Translate/tag/PageTranslationHooks.php
@@ -1,12 +1,12 @@
22 <?php
33
44 class PageTranslationHooks {
5 -
65 // Uuugly hack
76 static $allowTargetEdit = false;
87
98 public static function renderTagPage( $parser, &$text, $state ) {
109 $title = $parser->getTitle();
 10+
1111 if ( strpos( $text, '<translate>' ) !== false ) {
1212 $nowiki = array();
1313 $text = TranslatablePage::armourNowiki( $nowiki, $text );
@@ -23,6 +23,7 @@
2424 list( , $code ) = TranslateUtils::figureMessage( $title->getText() );
2525 $parser->mOptions->setTargetLanguage( Language::factory( $code ) );
2626 }
 27+
2728 return true;
2829 }
2930
@@ -40,6 +41,7 @@
4142 $namespace = $title->getNamespace();
4243 $text = $title->getDBkey();
4344 list( $key, ) = TranslateUtils::figureMessage( $text );
 45+
4446 return TranslateUtils::messageKeyToGroup( $namespace, $key );
4547 }
4648
@@ -50,14 +52,21 @@
5153 // Some checks
5254
5355 // We are only interested in the translations namespace
54 - if ( $title->getNamespace() != NS_TRANSLATIONS ) return true;
 56+ if ( $title->getNamespace() != NS_TRANSLATIONS ) {
 57+ return true;
 58+ }
 59+
5560 // Do not trigger renders for fuzzy
56 - if ( strpos( $text, TRANSLATE_FUZZY ) !== false ) return true;
 61+ if ( strpos( $text, TRANSLATE_FUZZY ) !== false ) {
 62+ return true;
 63+ }
5764
5865 // Figure out the group
5966 $groupKey = self::titleToGroup( $title );
6067 $group = MessageGroups::getGroup( $groupKey );
61 - if ( !$group instanceof WikiPageMessageGroup ) return;
 68+ if ( !$group instanceof WikiPageMessageGroup ) {
 69+ return;
 70+ }
6271
6372 // Finally we know the title and can construct a Translatable page
6473 $page = TranslatablePage::newFromTitle( $group->title );
@@ -75,7 +84,9 @@
7685 }
7786
7887 protected static function addSectionTag( Title $title, $revision, $pageRevision ) {
79 - if ( $pageRevision === null ) throw new MWException( 'Page revision is null' );
 88+ if ( $pageRevision === null ) {
 89+ throw new MWException( 'Page revision is null' );
 90+ }
8091
8192 $dbw = wfGetDB( DB_MASTER );
8293
@@ -129,6 +140,7 @@
130141 public static function addSidebar( $out, $tpl ) {
131142 // TODO: fixme
132143 return true;
 144+
133145 global $wgLang;
134146
135147 // Sort by translation percentage
@@ -137,7 +149,7 @@
138150 foreach ( $status as $code => $percent ) {
139151 $name = TranslateUtils::getLanguageName( $code, false, $wgLang->getCode() );
140152 $percent = $wgLang->formatNum( round( 100 * $percent ) );
141 - $label = "$name ($percent%)";
 153+ $label = "$name ($percent%)"; // FIXME: i18n
142154
143155 $_title = TranslateTagUtils::codefyTitle( $title, $code );
144156
@@ -156,8 +168,6 @@
157169 return true;
158170 }
159171
160 -
161 -
162172 public static function languages( $data, $params, $parser ) {
163173 $title = $parser->getTitle();
164174
@@ -166,10 +176,15 @@
167177 if ( $page->getMarkedTag() === false ) {
168178 $page = TranslatablePage::isTranslationPage( $title );
169179 }
170 - if ( $page === false || $page->getMarkedTag() === false ) return '';
171180
 181+ if ( $page === false || $page->getMarkedTag() === false ) {
 182+ return '';
 183+ }
 184+
172185 $status = $page->getTranslationPercentages();
173 - if ( !$status ) return '';
 186+ if ( !$status ) {
 187+ return '';
 188+ }
174189
175190 // Fix title
176191 $title = $page->getTitle();
@@ -202,8 +217,8 @@
203218
204219 $percent = Xml::element( 'img', array(
205220 'src' => TranslateUtils::assetPath( "images/prog-$image.png" ),
206 - 'alt' => "$percent%",
207 - 'title' => "$percent%",
 221+ 'alt' => "$percent%", // FIXME: i18n
 222+ 'title' => "$percent%", // FIXME: i18n
208223 'width' => '9',
209224 'height' => '9',
210225 ) );
@@ -217,6 +232,7 @@
218233 if ( $code === $wgLang->getCode() ) {
219234 $label = Html::rawElement( 'b', null, $label );
220235 }
 236+
221237 if ( $parser->getTitle()->getText() === $_title->getText() ) {
222238 $languages[] = "$label";
223239 } else {
@@ -242,13 +258,17 @@
243259
244260 // To display nice error for editpage
245261 public static function tpSyntaxCheckForEditPage( $editpage, $text, $section, &$error, $summary ) {
246 - if ( strpos( $text, '<translate>' ) === false ) return true;
 262+ if ( strpos( $text, '<translate>' ) === false ) {
 263+ return true;
 264+ }
 265+
247266 $page = TranslatablePage::newFromText( $editpage->mTitle, $text );
248267 try {
249268 $page->getParse();
250269 } catch ( TPException $e ) {
251270 $error .= Html::rawElement( 'div', array( 'class' => 'error' ), $e->getMessage() );
252271 }
 272+
253273 return true;
254274 }
255275
@@ -259,7 +279,9 @@
260280 public static function tpSyntaxCheck( $article, $user, $text, $summary,
261281 $minor, $_, $_, $flags, $status ) {
262282 // Quick escape on normal pages
263 - if ( strpos( $text, '<translate>' ) === false ) return true;
 283+ if ( strpos( $text, '<translate>' ) === false ) {
 284+ return true;
 285+ }
264286
265287 $page = TranslatablePage::newFromText( $article->getTitle(), $text );
266288 try {
@@ -275,10 +297,14 @@
276298 public static function addTranstag( $article, $user, $text, $summary,
277299 $minor, $_, $_, $flags, $revision ) {
278300 // We are not interested in null revisions
279 - if ( $revision === null ) return true;
 301+ if ( $revision === null ) {
 302+ return true;
 303+ }
280304
281305 // Quick escape on normal pages
282 - if ( strpos( $text, '</translate>' ) === false ) return true;
 306+ if ( strpos( $text, '</translate>' ) === false ) {
 307+ return true;
 308+ }
283309
284310 // Add the ready tag
285311 $page = TranslatablePage::newFromTitle( $article->getTitle() );
@@ -295,7 +321,7 @@
296322 if ( $title->getNamespace() == NS_TRANSLATIONS && $action === 'edit' ) {
297323 $group = self::titleToGroup( $title );
298324 if ( $group === null ) {
299 - // No group means that the page is currently not
 325+ // No group means that the page is currently not
300326 // registered to any page translation message groups
301327 $result = array( 'tpt-unknown-page' );
302328 return false;
@@ -304,11 +330,12 @@
305331 return true;
306332 }
307333
308 -
309334 // Case 2: Target pages
310335 $page = TranslatablePage::isTranslationPage( $title );
311336 if ( $page !== false ) {
312 - if ( self::$allowTargetEdit ) return true;
 337+ if ( self::$allowTargetEdit ) {
 338+ return true;
 339+ }
313340
314341 if ( $page->getMarkedTag() ) {
315342 list( , $code ) = TranslateUtils::figureMessage( $title->getText() );
@@ -326,6 +353,7 @@
327354
328355 public static function schemaUpdates() {
329356 global $wgExtNewTables;
 357+
330358 $dir = dirname( __FILE__ ) . '/..';
331359 $wgExtNewTables[] = array( 'translate_sections', "$dir/translate.sql" );
332360 $wgExtNewTables[] = array( 'revtag_type', "$dir/revtags.sql" );
@@ -336,9 +364,11 @@
337365 // TODO: fix the name
338366 public static function test( &$article, &$outputDone, &$pcache ) {
339367 global $wgOut;
 368+
340369 if ( !$article->getOldID() ) {
341370 self::header( $article->getTitle() );
342371 }
 372+
343373 return true;
344374 }
345375
@@ -356,9 +386,7 @@
357387 }
358388 }
359389
360 - protected static function sourcePageHeader( TranslatablePage $page,
361 - $marked, $ready ) {
362 -
 390+ protected static function sourcePageHeader( TranslatablePage $page, $marked, $ready ) {
363391 global $wgUser, $wgLang;
364392
365393 $title = $page->getTitle();
@@ -375,6 +403,7 @@
376404 'language' => $wgLang->getCode(),
377405 'task' => 'view'
378406 );
 407+
379408 $translate = SpecialPage::getTitleFor( 'Translate' );
380409 $linkDesc = wfMsgHtml( 'translate-tag-translate-link-desc' );
381410 $actions[] = $sk->link( $translate, $linkDesc, array(), $par );
@@ -399,16 +428,18 @@
400429 }
401430 }
402431
403 - if ( !count( $actions ) ) return;
 432+ if ( !count( $actions ) ) {
 433+ return;
 434+ }
 435+
404436 $legend = Html::rawElement(
405437 'div',
406438 array( 'style' => 'font-size: x-small; text-align: center;' ),
407439 $wgLang->semicolonList( $actions )
408440 ) . Html::element( 'hr' );
409 -
 441+
410442 global $wgOut;
411443 $wgOut->addHTML( $legend );
412 -
413444 }
414445
415446 protected static function translationPageHeader( Title $title ) {
@@ -416,7 +447,9 @@
417448
418449 // Check if applicable
419450 $page = TranslatablePage::isTranslationPage( $title );
420 - if ( $page === false ) return;
 451+ if ( $page === false ) {
 452+ return;
 453+ }
421454
422455 list( , $code ) = TranslateUtils::figureMessage( $title->getText() );
423456
@@ -429,7 +462,7 @@
430463
431464 // Output
432465 $wrap = '<div style="font-size: x-small; text-align: center">$1</div>';
433 -
 466+
434467 $wgOut->wrapWikiMsg( $wrap, array( 'tpt-translation-intro', $url, $titleText, $per ) );
435468
436469 if ( ( (int) $per ) < 100 ) {
@@ -437,7 +470,6 @@
438471 $wgOut->wrapWikiMsg( $wrap, array( 'tpt-translation-intro-fuzzy' ) );
439472 }
440473 $wgOut->addHTML( '<hr />' );
441 -
442474 }
443475
444476 public static function parserTestTables( &$tables ) {
@@ -455,10 +487,14 @@
456488 if ( $page->getMarkedTag() === false ) {
457489 $page = TranslatablePage::isTranslationPage( $title );
458490 }
459 - if ( $page === false || $page->getMarkedTag() === false ) return true;
460491
 492+ if ( $page === false || $page->getMarkedTag() === false ) {
 493+ return true;
 494+ }
 495+
461496 $export = array( $page->getTitle()->getPrefixedText() ); // Source page
462497 $titles = $page->getTranslationPages();
 498+
463499 foreach ( $titles as $title ) {
464500 $export[] = $title->getPrefixedText();
465501 }
@@ -469,7 +505,7 @@
470506 $linkText = wfMsgHtml( 'tpt-download-page' );
471507
472508 print "<li id=\"t-export-translationpages\"><a href=\"$href\" rel=\"nofollow\">$linkText</a></li>";
 509+
473510 return true;
474511 }
475 -
476512 }
Index: trunk/extensions/Translate/tag/TPSection.php
@@ -26,9 +26,11 @@
2727 $count = 0;
2828
2929 $text = preg_replace( $re, $rep, $this->text, 1, $count );
 30+
3031 if ( $count === 0 ) {
3132 $text = $header . "\n" . $this->text;
3233 }
 34+
3335 return $text;
3436 }
3537
@@ -41,9 +43,11 @@
4244 $matches = array();
4345 preg_match_all( $re, $this->text, $matches, PREG_SET_ORDER );
4446 $vars = array();
 47+
4548 foreach ( $matches as $m ) {
4649 $vars['$' . $m[1]] = $m[2];
4750 }
 51+
4852 return $vars;
4953 }
50 -}
\ No newline at end of file
 54+}

Status & tagging log