r74066 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74065‎ | r74066 | r74067 >
Date:13:11, 1 October 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Replace ugly navigation links with cool tabs
Modified paths:
  • /trunk/extensions/Translate/Translate.i18n.php (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/TranslateEditAddons.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/TranslateEditAddons.php
@@ -18,125 +18,94 @@
1919 class TranslateEditAddons {
2020
2121 /**
22 - * Add some ugly navigation links below translations.
 22+ * Add some tabs for navigation for users who do not use Ajax interface.
2323 */
24 - static function addNavigation( &$outputpage, &$text ) {
25 - global $wgUser, $wgTitle;
 24+ static function addNavigationTabs( $skin, &$tabs ) {
 25+ global $wgRequest;
2626
27 - if ( !self::isMessageNamespace( $wgTitle ) ) {
 27+ $title = $skin->getTitle();
 28+
 29+ if ( !self::isMessageNamespace( $title ) ) {
2830 return true;
2931 }
3032
31 - list( $key, $code, $group ) = self::getKeyCodeGroup( $wgTitle );
 33+ list( $key, $code, $group ) = self::getKeyCodeGroup( $title );
3234 if ( !$group || !$code ) {
3335 return true;
3436 }
3537
36 - if ( $group instanceof MessageGroupBase ) {
37 - $cache = new MessageGroupCache( $group );
 38+ $collection = $group->initCollection( 'en' );
 39+ $collection->filter( 'optional' );
 40+ $keys = array_keys( $collection->keys() );
 41+ $count = count( $keys );
3842
39 - if ( !$cache->exists() ) {
40 - return true;
41 - }
42 -
43 - $keys = $cache->getKeys();
44 - $defs = array();
45 -
46 - foreach ( $keys as $_ ) {
47 - $defs[$_] = $cache->get( $_ );
48 - }
49 -
50 - $skip = array_merge( $group->getTags( 'ignored' ), $group->getTags( 'optional' ) );
51 - } else {
52 - $defs = $group->getDefinitions();
53 - $skip = array_merge( $group->getIgnored(), $group->getOptional() );
54 - }
55 -
5643 $key = strtolower( strtr( $key, ' ', '_' ) );
5744
58 - $next = $prev = $def = null;
59 - foreach ( array_keys( $defs ) as $tkey ) {
60 - if ( in_array( $tkey, $skip ) ) {
61 - continue;
62 - }
63 -
64 - /*
65 - * Keys can have mixed case, but they have to be unique in a case
66 - * insensitive manner. It is therefore safe and a must to use case
67 - * insensitive comparison method.
68 - */
69 - if ( $key === strtolower( strtr( $tkey, ' ', '_' ) ) ) {
70 - $next = true;
71 - $def = $defs[$tkey];
72 - continue;
73 - } elseif ( $next === true ) {
74 - $next = $tkey;
75 - break;
76 - }
77 -
78 - $prev = $tkey;
 45+ $next = $prev = null;
 46+ foreach ( $keys as $index => $tkey ) {
 47+ if ( $key === strtolower( strtr( $tkey, ' ', '_' ) ) ) break;
 48+ if ( $index === $count -1 ) $index = -666;
7949 }
8050
81 - $skin = $wgUser->getSkin();
 51+ if ( isset( $keys[$index-1] ) ) $prev = $keys[$index-1];
 52+ if ( isset( $keys[$index+1] ) ) $next = $keys[$index+1];
 53+
 54+
8255 $id = $group->getId();
 56+ $ns = $title->getNamespace();
8357
84 - $ns = $wgTitle->getNamespace();
85 - $title = Title::makeTitleSafe( $ns, "$prev/$code" );
86 - $prevLink = wfMsgHtml( 'translate-edit-goto-no-prev' );
 58+ $translate = SpecialPage::getTitleFor( 'Translate' );
 59+ $fragment = htmlspecialchars( "#msg_$key" );
8760
88 - $params = array();
 61+ $nav_params = array();
 62+ $nav_params['loadgroup'] = $id;
 63+ $nav_params['action'] = $wgRequest->getText( 'action', 'edit' );
8964
90 - if ( $prev !== null ) {
91 - $params['loadgroup'] = $id;
92 - if ( !$title->exists() ) {
93 - $params['action'] = 'edit';
94 - }
 65+ $tabindex = 2;
9566
96 - $prevLink = $skin->link( $title,
97 - wfMsgHtml( 'translate-edit-goto-prev' ), array(), $params );
 67+ if ( $prev !== null ) {
 68+ $linktitle = Title::makeTitleSafe( $ns, "$prev/$code" );
 69+ $data = array(
 70+ 'text' => wfMsg( 'translate-edit-tab-prev' ),
 71+ 'href' => $linktitle->getLocalUrl( $nav_params ),
 72+ );
 73+ self::addTab( $skin, $tabs, 'prev', $data, $tabindex );
9874 }
9975
100 - $title = Title::makeTitleSafe( $ns, "$next/$code" );
101 - $nextLink = wfMsgHtml( 'translate-edit-goto-no-next' );
 76+ $params = array(
 77+ 'group' => $id,
 78+ 'language' => $code,
 79+ 'task' => 'view',
 80+ 'offset' => max( 0, $index - 250 ),
 81+ 'limit' => 500,
 82+ );
 83+ $data = array(
 84+ 'text' => wfMsg( 'translate-edit-tab-list' ),
 85+ 'href' => $translate->getLocalUrl( $params ) . $fragment,
 86+ );
 87+ self::addTab( $skin, $tabs, 'list', $data, $tabindex );
10288
10389 if ( $next !== null && $next !== true ) {
104 - $params['loadgroup'] = $id;
105 -
106 - if ( !$title->exists() ) {
107 - $params['action'] = 'edit';
108 - }
109 -
110 - $nextLink = $skin->link( $title,
111 - wfMsgHtml( 'translate-edit-goto-next' ), array(), $params );
 90+ $linktitle = Title::makeTitleSafe( $ns, "$next/$code" );
 91+ $data = array(
 92+ 'text' => wfMsg( 'translate-edit-tab-next' ),
 93+ 'href' => $linktitle->getLocalUrl( $nav_params ),
 94+ );
 95+ self::addTab( $skin, $tabs, 'next', $data, $tabindex );
11296 }
11397
114 - $title = SpecialPage::getTitleFor( 'Translate' );
115 - $title->mFragment = "msg_$next";
116 - $list = $skin->link(
117 - $title,
118 - wfMsgHtml( 'translate-edit-goto-list' ),
119 - array(),
120 - array(
121 - 'group' => $id,
122 - 'language' => $code
123 - )
124 - );
125 -
126 - $def = TranslateUtils::convertWhiteSpaceToHTML( $def );
127 -
128 - $text .= <<<EOEO
129 -<hr />
130 -<ul class="mw-translate-nav-prev-next-list">
131 -<li>$prevLink</li>
132 -<li>$nextLink</li>
133 -<li>$list</li>
134 -</ul><hr />
135 -<div class="mw-translate-definition-preview">$def</div>
136 -EOEO;
137 -
13898 return true;
13999 }
140100
 101+ protected static function addTab( $skin, &$tabs, $name, $data, &$index ) {
 102+ if ( $skin instanceof SkinVector ) {
 103+ $data['class'] = false; // Vector needs it for some reason
 104+ $tabs['namespaces'][$name] = $data;
 105+ } else {
 106+ array_splice( $tabs, $index++, 0, array( $name => $data ) );
 107+ }
 108+ }
 109+
141110 /**
142111 * Keep the usual diiba daaba hidden from translators.
143112 */
@@ -154,7 +123,6 @@
155124 return true;
156125 }
157126
158 - TranslateEditAddons::addNavigation( $ignored, $object->editFormTextTop );
159127 $object->editFormTextTop .= self::editBoxes( $object );
160128
161129 return true;
Index: trunk/extensions/Translate/Translate.php
@@ -83,12 +83,13 @@
8484
8585 // Register hooks.
8686 $wgHooks['EditPage::showEditForm:initial'][] = 'TranslateEditAddons::addTools';
87 -$wgHooks['OutputPageBeforeHTML'][] = 'TranslateEditAddons::addNavigation';
 87+$wgHooks['SkinTemplateTabs'][] = 'TranslateEditAddons::addNavigationTabs';
 88+// Same for Vector skin
 89+$wgHooks['SkinTemplateNavigation'][] = 'TranslateEditAddons::addNavigationTabs';
8890 $wgHooks['AlternateEdit'][] = 'TranslateEditAddons::intro';
8991 $wgHooks['EditPageBeforeEditButtons'][] = 'TranslateEditAddons::buttonHack';
9092 $wgHooks['EditPage::showEditForm:fields'][] = 'TranslateEditAddons::keepFields';
9193 $wgHooks['SkinTemplateTabs'][] = 'TranslateEditAddons::tabs';
92 -# $wgHooks['ArticleAfterFetchContent'][] = 'TranslateEditAddons::customDisplay';
9394
9495 // Custom preferences
9596 $wgDefaultUserOptions['translate'] = 0;
Index: trunk/extensions/Translate/Translate.i18n.php
@@ -83,11 +83,9 @@
8484 'translate-edit-tmmatch' => '$1% match',
8585 'translate-use-suggestion' => 'Insert this suggestion in the translation area. This replaces all current content.',
8686
87 - 'translate-edit-goto-no-prev' => 'No previous message',
88 - 'translate-edit-goto-no-next' => 'No next message',
89 - 'translate-edit-goto-prev' => 'Edit previous message',
90 - 'translate-edit-goto-next' => 'Edit next message',
91 - 'translate-edit-goto-list' => 'Back to the list',
 87+ 'translate-edit-tab-prev' => '<<<',
 88+ 'translate-edit-tab-next' => '>>>',
 89+ 'translate-edit-tab-list' => 'Message list',
9290
9391 'translate-magic-pagename' => 'Extended MediaWiki translation',
9492 'translate-magic-help' => 'You can translate special pages aliases, magic words and namespace names.

Status & tagging log