Index: trunk/extensions/Translate/TranslateEditAddons.php |
— | — | @@ -18,125 +18,94 @@ |
19 | 19 | class TranslateEditAddons { |
20 | 20 | |
21 | 21 | /** |
22 | | - * Add some ugly navigation links below translations. |
| 22 | + * Add some tabs for navigation for users who do not use Ajax interface. |
23 | 23 | */ |
24 | | - static function addNavigation( &$outputpage, &$text ) { |
25 | | - global $wgUser, $wgTitle; |
| 24 | + static function addNavigationTabs( $skin, &$tabs ) { |
| 25 | + global $wgRequest; |
26 | 26 | |
27 | | - if ( !self::isMessageNamespace( $wgTitle ) ) { |
| 27 | + $title = $skin->getTitle(); |
| 28 | + |
| 29 | + if ( !self::isMessageNamespace( $title ) ) { |
28 | 30 | return true; |
29 | 31 | } |
30 | 32 | |
31 | | - list( $key, $code, $group ) = self::getKeyCodeGroup( $wgTitle ); |
| 33 | + list( $key, $code, $group ) = self::getKeyCodeGroup( $title ); |
32 | 34 | if ( !$group || !$code ) { |
33 | 35 | return true; |
34 | 36 | } |
35 | 37 | |
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 ); |
38 | 42 | |
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 | | - |
56 | 43 | $key = strtolower( strtr( $key, ' ', '_' ) ); |
57 | 44 | |
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; |
79 | 49 | } |
80 | 50 | |
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 | + |
82 | 55 | $id = $group->getId(); |
| 56 | + $ns = $title->getNamespace(); |
83 | 57 | |
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" ); |
87 | 60 | |
88 | | - $params = array(); |
| 61 | + $nav_params = array(); |
| 62 | + $nav_params['loadgroup'] = $id; |
| 63 | + $nav_params['action'] = $wgRequest->getText( 'action', 'edit' ); |
89 | 64 | |
90 | | - if ( $prev !== null ) { |
91 | | - $params['loadgroup'] = $id; |
92 | | - if ( !$title->exists() ) { |
93 | | - $params['action'] = 'edit'; |
94 | | - } |
| 65 | + $tabindex = 2; |
95 | 66 | |
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 ); |
98 | 74 | } |
99 | 75 | |
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 ); |
102 | 88 | |
103 | 89 | 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 ); |
112 | 96 | } |
113 | 97 | |
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 | | - |
138 | 98 | return true; |
139 | 99 | } |
140 | 100 | |
| 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 | + |
141 | 110 | /** |
142 | 111 | * Keep the usual diiba daaba hidden from translators. |
143 | 112 | */ |
— | — | @@ -154,7 +123,6 @@ |
155 | 124 | return true; |
156 | 125 | } |
157 | 126 | |
158 | | - TranslateEditAddons::addNavigation( $ignored, $object->editFormTextTop ); |
159 | 127 | $object->editFormTextTop .= self::editBoxes( $object ); |
160 | 128 | |
161 | 129 | return true; |
Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -83,12 +83,13 @@ |
84 | 84 | |
85 | 85 | // Register hooks. |
86 | 86 | $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'; |
88 | 90 | $wgHooks['AlternateEdit'][] = 'TranslateEditAddons::intro'; |
89 | 91 | $wgHooks['EditPageBeforeEditButtons'][] = 'TranslateEditAddons::buttonHack'; |
90 | 92 | $wgHooks['EditPage::showEditForm:fields'][] = 'TranslateEditAddons::keepFields'; |
91 | 93 | $wgHooks['SkinTemplateTabs'][] = 'TranslateEditAddons::tabs'; |
92 | | -# $wgHooks['ArticleAfterFetchContent'][] = 'TranslateEditAddons::customDisplay'; |
93 | 94 | |
94 | 95 | // Custom preferences |
95 | 96 | $wgDefaultUserOptions['translate'] = 0; |
Index: trunk/extensions/Translate/Translate.i18n.php |
— | — | @@ -83,11 +83,9 @@ |
84 | 84 | 'translate-edit-tmmatch' => '$1% match', |
85 | 85 | 'translate-use-suggestion' => 'Insert this suggestion in the translation area. This replaces all current content.', |
86 | 86 | |
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', |
92 | 90 | |
93 | 91 | 'translate-magic-pagename' => 'Extended MediaWiki translation', |
94 | 92 | 'translate-magic-help' => 'You can translate special pages aliases, magic words and namespace names. |