r67680 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67679‎ | r67680 | r67681 >
Date:01:33, 9 June 2010
Author:kaldari
Status:ok
Tags:
Comment:
only show translation interface when needed, begin switch from notice/template terms to campaign/banner terms, allow more chars in message names
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.i18n.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialNoticeTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php
@@ -9,43 +9,43 @@
1010
1111 $messages['en'] = array(
1212 'centralnotice' => 'Central notice admin',
13 - 'noticetemplate' => 'Central notice template',
 13+ 'noticetemplate' => 'Central notice banner',
1414 'centralnotice-desc' => 'Adds a central sitenotice',
1515 'centralnotice-summary' => 'This module allows you to edit your currently setup central notices.
1616 It can also be used to add or remove old notices.',
17 - 'centralnotice-query' => 'Modify current notices',
18 - 'centralnotice-notice-name' => 'Notice name',
 17+ 'centralnotice-query' => 'Modify current campaigns',
 18+ 'centralnotice-notice-name' => 'Campaign name',
1919 'centralnotice-end-date' => 'End date',
2020 'centralnotice-enabled' => 'Enabled',
2121 'centralnotice-modify' => 'Submit',
2222 'centralnotice-preview' => 'Preview',
23 - 'centralnotice-add-new' => 'Add a new central notice',
 23+ 'centralnotice-add-new' => 'Add a new campaign',
2424 'centralnotice-remove' => 'Remove',
2525 'centralnotice-translate-heading' => 'Translation for $1',
26 - 'centralnotice-manage' => 'Manage central notice',
 26+ 'centralnotice-manage' => 'Manage campaigns',
2727 'centralnotice-add' => 'Add',
28 - 'centralnotice-add-notice' => 'Add a notice',
29 - 'centralnotice-add-template' => 'Add a template',
30 - 'centralnotice-show-notices' => 'Show notices',
31 - 'centralnotice-list-templates' => 'List templates',
 28+ 'centralnotice-add-notice' => 'Add a campaign',
 29+ 'centralnotice-add-template' => 'Add a banner',
 30+ 'centralnotice-show-notices' => 'Show campaigns',
 31+ 'centralnotice-list-templates' => 'List banners',
3232 'centralnotice-translations' => 'Translations',
3333 'centralnotice-translate-to' => 'Translate to',
3434 'centralnotice-translate' => 'Translate',
3535 'centralnotice-english' => 'English',
36 - 'centralnotice-template-name' => 'Template name',
37 - 'centralnotice-templates' => 'Templates',
 36+ 'centralnotice-template-name' => 'Banner name',
 37+ 'centralnotice-templates' => 'Banners',
3838 'centralnotice-weight' => 'Weight',
3939 'centralnotice-locked' => 'Locked',
40 - 'centralnotice-notices' => 'Notices',
41 - 'centralnotice-notice-exists' => 'Notice already exists.
 40+ 'centralnotice-notices' => 'Campaigns',
 41+ 'centralnotice-notice-exists' => 'Campaign already exists.
4242 Not adding',
43 - 'centralnotice-template-exists' => 'Template already exists.
 43+ 'centralnotice-template-exists' => 'Banner already exists.
4444 Not adding',
45 - 'centralnotice-notice-doesnt-exist' => 'Notice does not exist.
 45+ 'centralnotice-notice-doesnt-exist' => 'Campaign does not exist.
4646 Nothing to remove',
47 - 'centralnotice-template-still-bound' => 'Template is still bound to a notice.
 47+ 'centralnotice-template-still-bound' => 'Banner is still bound to a campaign.
4848 Not removing.',
49 - 'centralnotice-template-body' => 'Template body:',
 49+ 'centralnotice-template-body' => 'Banner body:',
5050 'centralnotice-day' => 'Day',
5151 'centralnotice-year' => 'Year',
5252 'centralnotice-month' => 'Month',
@@ -55,21 +55,21 @@
5656 'centralnotice-project-name' => 'Project name',
5757 'centralnotice-start-date' => 'Start date',
5858 'centralnotice-start-time' => 'Start time (UTC)',
59 - 'centralnotice-assigned-templates' => 'Assigned templates',
60 - 'centralnotice-no-templates' => 'No templates found.
 59+ 'centralnotice-assigned-templates' => 'Assigned banners',
 60+ 'centralnotice-no-templates' => 'No banners found.
6161 Add some!',
62 - 'centralnotice-no-templates-assigned' => 'No templates assigned to notice.
 62+ 'centralnotice-no-templates-assigned' => 'No banners assigned to campaign.
6363 Add some!',
64 - 'centralnotice-available-templates' => 'Available templates',
65 - 'centralnotice-template-already-exists' => 'Template is already tied to campaign.
 64+ 'centralnotice-available-templates' => 'Available banners',
 65+ 'centralnotice-template-already-exists' => 'Banner is already tied to campaign.
6666 Not adding',
67 - 'centralnotice-preview-template' => 'Preview template',
 67+ 'centralnotice-preview-template' => 'Preview banner',
6868 'centralnotice-start-hour' => 'Start time',
6969 'centralnotice-change-lang' => 'Change translation language',
7070 'centralnotice-weights' => 'Weights',
71 - 'centralnotice-notice-is-locked' => 'Notice is locked.
 71+ 'centralnotice-notice-is-locked' => 'Campaign is locked.
7272 Not removing',
73 - 'centralnotice-overlap' => 'Notice overlaps within the time of another notice.
 73+ 'centralnotice-overlap' => 'Campaign overlaps within the time of another campaign.
7474 Not adding',
7575 'centralnotice-invalid-date-range' => 'Invalid date range.
7676 Not updating',
@@ -77,16 +77,17 @@
7878 Not adding',
7979 'centralnotice-confirm-delete' => 'Are you sure you want to delete this item?
8080 This action will be unrecoverable.',
81 - 'centralnotice-no-notices-exist' => 'No notices exist.
 81+ 'centralnotice-no-notices-exist' => 'No campaigns exist.
8282 Add one below.',
83 - 'centralnotice-no-templates-translate' => 'There are not any templates to edit translations for',
 83+ 'centralnotice-no-templates-translate' => 'There are not any banners to edit translations for',
8484 'centralnotice-number-uses' => 'Uses',
85 - 'centralnotice-edit-template' => 'Edit template',
 85+ 'centralnotice-edit-template' => 'Edit banner',
 86+ 'centralnotice-edit-template-summary' => 'To create a localizable message, enclose a hyphenated string in three curly brackets, e.g. {{{jimbo-quote}}}.',
8687 'centralnotice-message' => 'Message',
8788 'centralnotice-message-not-set' => 'Message not set',
8889 'centralnotice-clone' => 'Clone',
89 - 'centralnotice-clone-notice' => 'Create a copy of the template',
90 - 'centralnotice-preview-all-template-translations' => 'Preview all available translations of template',
 90+ 'centralnotice-clone-notice' => 'Create a copy of the banner',
 91+ 'centralnotice-preview-all-template-translations' => 'Preview all available translations of banner',
9192
9293 'right-centralnotice-admin' => 'Manage central notices',
9394 'right-centralnotice-translate' => 'Translate central notices',
@@ -118,14 +119,14 @@
119120 'centralnotice-translate-heading' => 'Fieldset label. $1 is a name of a template.',
120121 'centralnotice-add' => '{{Identical|Add}}',
121122 'centralnotice-translate' => '{{Identical|Translate}}',
122 - 'centralnotice-notice-exists' => 'Errore message displayed in Special:CentralNotice when trying to add a notice with the same name of another notice',
123 - 'centralnotice-template-exists' => 'Errore message displayed in Special:NoticeTemplate when trying to add a template with the same name of another template',
 123+ 'centralnotice-notice-exists' => 'Error message displayed in Special:CentralNotice when trying to add a notice with the same name of another notice',
 124+ 'centralnotice-template-exists' => 'Error message displayed in Special:NoticeTemplate when trying to add a template with the same name of another template',
124125 'centralnotice-start-date' => 'Used in Special:CentralNotice.
125126
126127 {{Identical|Start date}}',
127128 'centralnotice-start-time' => 'Used in Special:CentralNotice',
128129 'centralnotice-available-templates' => 'Used in Special:NoticeTemplate',
129 - 'centralnotice-notice-is-locked' => 'Errore message displayed in Special:CentralNotice when trying to delete a locked notice',
 130+ 'centralnotice-notice-is-locked' => 'Error message displayed in Special:CentralNotice when trying to delete a locked notice',
130131 'centralnotice-invalid-date-range' => '{{Identical|Date}}',
131132 'centralnotice-no-notices-exist' => 'Used in Special:CentralNotice when there are no notices',
132133 'centralnotice-number-uses' => 'Column header in table with sitenotice campaign information.
Index: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php
@@ -326,129 +326,134 @@
327327 );
328328
329329 // Build HTML
330 - if ( $this->editable ) {
331 - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
332 - }
333 - $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-translate-heading', $currentTemplate ) );
334 - $htmlOut .= Xml::openElement( 'table',
335 - array (
336 - 'cellpadding' => 9,
337 - 'width' => '100%'
338 - )
339 - );
340 -
341 - // Headers
342 - $htmlOut .= Xml::element( 'th', array( 'width' => '15%' ), wfMsg( 'centralnotice-message' ) );
343 - $htmlOut .= Xml::element( 'th', array( 'width' => '5%' ), wfMsg ( 'centralnotice-number-uses' ) );
344 - $htmlOut .= Xml::element( 'th', array( 'width' => '40%' ), wfMsg ( 'centralnotice-english' ) );
345 - $languages = Language::getLanguageNames();
346 - $htmlOut .= Xml::element( 'th', array( 'width' => '40%' ), $languages[$wpUserLang] );
347 -
 330+
348331 // Pull text and respect any inc: markup
349332 $bodyPage = Title::newFromText( "Centralnotice-template-{$currentTemplate}", NS_MEDIAWIKI );
350333 $curRev = Revision::newFromTitle( $bodyPage );
351334 $body = $curRev ? $curRev->getText() : '';
352 -
 335+
 336+ // Extract message fields from the template body
353337 $fields = array();
354 - preg_match_all( '/\{\{\{([A-Za-z0-9\_\-}]+)\}\}\}/', $body, $fields );
355 -
356 - // Remove duplicates
357 - $filteredFields = array();
358 - foreach ( $fields[1] as $field ) {
359 - $filteredFields[$field] = array_key_exists( $field, $filteredFields ) ? $filteredFields[$field] + 1 : 1;
360 - }
361 -
362 - // Rows
363 - foreach ( $filteredFields as $field => $count ) {
364 - // Message
365 - $message = ( $wpUserLang == 'en' ) ? "Centralnotice-{$currentTemplate}-{$field}" : "Centralnotice-{$currentTemplate}-{$field}/{$wpUserLang}";
366 -
367 - // English value
368 - $htmlOut .= Xml::openElement( 'tr' );
369 -
370 - $title = Title::newFromText( "MediaWiki:{$message}" );
371 - $htmlOut .= Xml::tags( 'td', null,
372 - $sk->makeLinkObj( $title, htmlspecialchars( $field ) )
373 - );
374 -
375 - $htmlOut .= Xml::element( 'td', null, $count );
376 -
377 - // English text
378 - $englishText = wfMsg( 'centralnotice-message-not-set' );
379 - $englishTextExists = false;
380 - if ( Title::newFromText( "Centralnotice-{$currentTemplate}-{$field}", NS_MEDIAWIKI )->exists() ) {
381 - $englishText = wfMsgExt( "Centralnotice-{$currentTemplate}-{$field}",
382 - array( 'language' => 'en' )
383 - );
384 - $englishTextExists = true;
 338+ preg_match_all( '/\{\{\{([A-Za-z0-9\_\-\x{00C0}-\x{00D6}\x{00D8}-\x{00F6}\x{00F8}-\x{00FF}]+)\}\}\}/u', $body, $fields );
 339+
 340+ // If there are any messages in the template, display translation tools.
 341+ if ( count( $fields[0] ) > 0 ) {
 342+ if ( $this->editable ) {
 343+ $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
385344 }
386 - $htmlOut .= Xml::tags( 'td', null,
387 - Xml::element( 'span',
388 - array( 'style' => 'font-style:italic;' . ( !$englishTextExists ? 'color:silver' : '' ) ),
389 - $englishText
 345+ $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-translate-heading', $currentTemplate ) );
 346+ $htmlOut .= Xml::openElement( 'table',
 347+ array (
 348+ 'cellpadding' => 9,
 349+ 'width' => '100%'
390350 )
391351 );
392 -
393 - // Foreign text input
394 - $foreignText = '';
395 - $foreignTextExists = false;
396 - if ( Title::newFromText( $message, NS_MEDIAWIKI )->exists() ) {
397 - $foreignText = wfMsgExt( "Centralnotice-{$currentTemplate}-{$field}",
398 - array( 'language' => $wpUserLang )
 352+
 353+ // Headers
 354+ $htmlOut .= Xml::element( 'th', array( 'width' => '15%' ), wfMsg( 'centralnotice-message' ) );
 355+ $htmlOut .= Xml::element( 'th', array( 'width' => '5%' ), wfMsg ( 'centralnotice-number-uses' ) );
 356+ $htmlOut .= Xml::element( 'th', array( 'width' => '40%' ), wfMsg ( 'centralnotice-english' ) );
 357+ $languages = Language::getLanguageNames();
 358+ $htmlOut .= Xml::element( 'th', array( 'width' => '40%' ), $languages[$wpUserLang] );
 359+
 360+ // Remove duplicate message fields
 361+ $filteredFields = array();
 362+ foreach ( $fields[1] as $field ) {
 363+ $filteredFields[$field] = array_key_exists( $field, $filteredFields ) ? $filteredFields[$field] + 1 : 1;
 364+ }
 365+
 366+ // Rows
 367+ foreach ( $filteredFields as $field => $count ) {
 368+ // Message
 369+ $message = ( $wpUserLang == 'en' ) ? "Centralnotice-{$currentTemplate}-{$field}" : "Centralnotice-{$currentTemplate}-{$field}/{$wpUserLang}";
 370+
 371+ // English value
 372+ $htmlOut .= Xml::openElement( 'tr' );
 373+
 374+ $title = Title::newFromText( "MediaWiki:{$message}" );
 375+ $htmlOut .= Xml::tags( 'td', null,
 376+ $sk->makeLinkObj( $title, htmlspecialchars( $field ) )
399377 );
400 - $foreignTextExists = true;
 378+
 379+ $htmlOut .= Xml::element( 'td', null, $count );
 380+
 381+ // English text
 382+ $englishText = wfMsg( 'centralnotice-message-not-set' );
 383+ $englishTextExists = false;
 384+ if ( Title::newFromText( "Centralnotice-{$currentTemplate}-{$field}", NS_MEDIAWIKI )->exists() ) {
 385+ $englishText = wfMsgExt( "Centralnotice-{$currentTemplate}-{$field}",
 386+ array( 'language' => 'en' )
 387+ );
 388+ $englishTextExists = true;
 389+ }
 390+ $htmlOut .= Xml::tags( 'td', null,
 391+ Xml::element( 'span',
 392+ array( 'style' => 'font-style:italic;' . ( !$englishTextExists ? 'color:silver' : '' ) ),
 393+ $englishText
 394+ )
 395+ );
 396+
 397+ // Foreign text input
 398+ $foreignText = '';
 399+ $foreignTextExists = false;
 400+ if ( Title::newFromText( $message, NS_MEDIAWIKI )->exists() ) {
 401+ $foreignText = wfMsgExt( "Centralnotice-{$currentTemplate}-{$field}",
 402+ array( 'language' => $wpUserLang )
 403+ );
 404+ $foreignTextExists = true;
 405+ }
 406+ $htmlOut .= Xml::tags( 'td', null,
 407+ Xml::input( "updateText[{$wpUserLang}][{$currentTemplate}-{$field}]", '', $foreignText,
 408+ wfArrayMerge( $readonly,
 409+ array( 'style' => 'width:100%;' . ( !$foreignTextExists ? 'color:red' : '' ) ) )
 410+ )
 411+ );
 412+ $htmlOut .= Xml::closeElement( 'tr' );
401413 }
402 - $htmlOut .= Xml::tags( 'td', null,
403 - Xml::input( "updateText[{$wpUserLang}][{$currentTemplate}-{$field}]", '', $foreignText,
404 - wfArrayMerge( $readonly,
405 - array( 'style' => 'width:100%;' . ( !$foreignTextExists ? 'color:red' : '' ) ) )
 414+ if ( $this->editable ) {
 415+ $htmlOut .= Xml::hidden( 'token', $token );
 416+ $htmlOut .= Xml::hidden( 'wpUserLanguage', $wpUserLang );
 417+ $htmlOut .= Xml::openElement( 'tr' );
 418+ $htmlOut .= Xml::tags( 'td', array( 'colspan' => 4 ),
 419+ Xml::submitButton( wfMsg( 'centralnotice-modify' ), array( 'name' => 'update' ) )
 420+ );
 421+ $htmlOut .= Xml::closeElement( 'tr' );
 422+ }
 423+
 424+ $htmlOut .= Xml::closeElement( 'table' );
 425+ $htmlOut .= Xml::closeElement( 'fieldset' );
 426+
 427+ if ( $this->editable ) {
 428+ $htmlOut .= Xml::closeElement( 'form' );
 429+ }
 430+
 431+ /*
 432+ * Show language selection form
 433+ */
 434+ $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
 435+ $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-change-lang' ) );
 436+ $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) );
 437+ list( $lsLabel, $lsSelect ) = Xml::languageSelector( $wpUserLang );
 438+
 439+ $newPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' );
 440+
 441+ $htmlOut .= Xml::tags( 'tr', null,
 442+ Xml::tags( 'td', null, $lsLabel ) .
 443+ Xml::tags( 'td', null, $lsSelect ) .
 444+ Xml::tags( 'td', array( 'colspan' => 2 ),
 445+ Xml::submitButton( wfMsg( 'centralnotice-modify' ) )
406446 )
407447 );
408 - $htmlOut .= Xml::closeElement( 'tr' );
409 - }
410 - if ( $this->editable ) {
411 - $htmlOut .= Xml::hidden( 'token', $token );
412 - $htmlOut .= Xml::hidden( 'wpUserLanguage', $wpUserLang );
413 - $htmlOut .= Xml::openElement( 'tr' );
414 - $htmlOut .= Xml::tags( 'td', array( 'colspan' => 4 ),
415 - Xml::submitButton( wfMsg( 'centralnotice-modify' ), array( 'name' => 'update' ) )
 448+ $htmlOut .= Xml::tags( 'tr', null,
 449+ Xml::tags( 'td', null, '' ) .
 450+ Xml::tags( 'td', null, $sk->makeLinkObj( $newPage, wfMsgHtml( 'centralnotice-preview-all-template-translations' ), "template=$currentTemplate&wpUserLanguage=all" ) )
416451 );
417 - $htmlOut .= Xml::closeElement( 'tr' );
418 - }
419 -
420 - $htmlOut .= Xml::closeElement( 'table' );
421 - $htmlOut .= Xml::closeElement( 'fieldset' );
422 -
423 - if ( $this->editable ) {
 452+ $htmlOut .= Xml::closeElement( 'table' );
 453+ $htmlOut .= Xml::closeElement( 'fieldset' );
424454 $htmlOut .= Xml::closeElement( 'form' );
425455 }
426456
427457 /*
428 - * Show language selection form
429 - */
430 - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
431 - $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-change-lang' ) );
432 - $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) );
433 - list( $lsLabel, $lsSelect ) = Xml::languageSelector( $wpUserLang );
434 -
435 - $newPage = SpecialPage::getTitleFor( 'NoticeTemplate', 'view' );
436 -
437 - $htmlOut .= Xml::tags( 'tr', null,
438 - Xml::tags( 'td', null, $lsLabel ) .
439 - Xml::tags( 'td', null, $lsSelect ) .
440 - Xml::tags( 'td', array( 'colspan' => 2 ),
441 - Xml::submitButton( wfMsg( 'centralnotice-modify' ) )
442 - )
443 - );
444 - $htmlOut .= Xml::tags( 'tr', null,
445 - Xml::tags( 'td', null, '' ) .
446 - Xml::tags( 'td', null, $sk->makeLinkObj( $newPage, wfMsgHtml( 'centralnotice-preview-all-template-translations' ), "template=$currentTemplate&wpUserLanguage=all" ) )
447 - );
448 - $htmlOut .= Xml::closeElement( 'table' );
449 - $htmlOut .= Xml::closeElement( 'fieldset' );
450 - $htmlOut .= Xml::closeElement( 'form' );
451 -
452 - /*
453458 * Show edit form
454459 */
455460 if ( $this->editable ) {
@@ -456,6 +461,7 @@
457462 $htmlOut .= Xml::hidden( 'wpMethod', 'editTemplate' );
458463 }
459464 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-edit-template' ) );
 465+ $htmlOut .= wfMsg( 'centralnotice-edit-template-summary' );
460466 $htmlOut .= Xml::openElement( 'table',
461467 array(
462468 'cellpadding' => 9,

Status & tagging log