Index: trunk/extensions/Translate/TranslateTasks.php |
— | — | @@ -124,19 +124,9 @@ |
125 | 125 | } |
126 | 126 | |
127 | 127 | protected function output() { |
128 | | - $tableheader = TranslateUtils::tableHeader( $this->group->getLabel() ); |
129 | | - $tablefooter = Xml::closeElement( 'table' ); |
130 | | - |
131 | | - return |
132 | | - $tableheader . |
133 | | - TranslateUtils::makeListing( |
134 | | - $this->collection, |
135 | | - $this->group->getId(), |
136 | | - false, |
137 | | - $this->group->namespaces, |
138 | | - $this->getId() |
139 | | - ) . |
140 | | - $tablefooter; |
| 128 | + $table = new MessageTable( $this->collection, $this->group ); |
| 129 | + $table->appendEditLinkParams( 'loadtask', $this->getId() ); |
| 130 | + return $table->fullTable(); |
141 | 131 | } |
142 | 132 | |
143 | 133 | } |
— | — | @@ -250,19 +240,11 @@ |
251 | 241 | } |
252 | 242 | |
253 | 243 | protected function output() { |
254 | | - $tableheader = TranslateUtils::tableHeader( $this->group->getLabel() ); |
255 | | - $tablefooter = Xml::closeElement( 'table' ); |
| 244 | + $table = new MessageTable( $this->collection, $this->group ); |
| 245 | + $table->appendEditLinkParams( 'loadtask', $this->getId() ); |
| 246 | + $table->setReviewMode(); |
256 | 247 | |
257 | | - return |
258 | | - $tableheader . |
259 | | - TranslateUtils::makeListing( |
260 | | - $this->collection, |
261 | | - $this->group->getId(), |
262 | | - true, /* Review mode */ |
263 | | - $this->group->namespaces, |
264 | | - $this->getId() |
265 | | - ) . |
266 | | - $tablefooter; |
| 248 | + return $table->fullTable(); |
267 | 249 | } |
268 | 250 | |
269 | 251 | } |
Index: trunk/extensions/Translate/_autoload.php |
— | — | @@ -70,6 +70,7 @@ |
71 | 71 | $wgAutoloadClasses['TranslateToolbox'] = $dir . 'utils/ToolBox.php'; |
72 | 72 | |
73 | 73 | $wgAutoloadClasses['MessageIndex'] = $dir . 'utils/MessageIndex.php'; |
| 74 | +$wgAutoloadClasses['MessageTable'] = $dir . 'utils/MessageTable.php'; |
74 | 75 | |
75 | 76 | # predefined groups |
76 | 77 | $wgAutoloadClasses['PremadeMediawikiExtensionGroups'] = $dir . 'groups/MediaWikiExtensions.php'; |
Index: trunk/extensions/Translate/utils/MessageTable.php |
— | — | @@ -0,0 +1,168 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Pretty-formatter for message collections |
| 5 | + * |
| 6 | + * @author Niklas Laxström |
| 7 | + * @copyright Copyright © 2007-2009 Niklas Laxström |
| 8 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 9 | + */ |
| 10 | +class MessageTable { |
| 11 | + |
| 12 | + protected $reviewMode = false; |
| 13 | + protected $collection = null; |
| 14 | + protected $group = null; |
| 15 | + protected $editLinkParams = array(); |
| 16 | + |
| 17 | + protected $headers = array( |
| 18 | + 'table' => array( 'msg', 'allmessagesname' ), |
| 19 | + 'current' => array( 'msg', 'allmessagescurrent' ), |
| 20 | + 'default' => array( 'msg', 'allmessagesdefault' ), |
| 21 | + ); |
| 22 | + |
| 23 | + public function __construct( MessageCollection $collection, MessageGroup $group ) { |
| 24 | + $this->collection = $collection; |
| 25 | + $this->group = $group; |
| 26 | + $this->setHeaderText( 'table', $group->getLabel() ); |
| 27 | + $this->appendEditLinkParams( 'loadgroup', $group->getId() ); |
| 28 | + } |
| 29 | + |
| 30 | + public function setEditLinkParams( array $array ) { |
| 31 | + $this->editLinkParams = $array; |
| 32 | + } |
| 33 | + |
| 34 | + public function appendEditLinkParams( $key, $value ) { |
| 35 | + $this->editLinkParams[$key] = $value; |
| 36 | + } |
| 37 | + |
| 38 | + public function setReviewMode( $mode = true ) { |
| 39 | + $this->reviewMode = $mode; |
| 40 | + } |
| 41 | + |
| 42 | + public function setHeaderTextMessage( $type, $value ) { |
| 43 | + if ( !isset($this->headers[$type]) ) throw new MWException( "Unexpected type $type" ); |
| 44 | + $this->headers[$type] = array( 'msg', $value ); |
| 45 | + } |
| 46 | + |
| 47 | + public function setHeaderText( $type, $value ) { |
| 48 | + if ( !isset($this->headers[$type]) ) throw new MWException( "Unexpected type $type" ); |
| 49 | + $this->headers[$type] = array( 'raw', htmlspecialchars($value) ); |
| 50 | + } |
| 51 | + |
| 52 | + |
| 53 | + public function header() { |
| 54 | + $tableheader = Xml::openElement( 'table', array( |
| 55 | + 'class' => 'mw-sp-translate-table', |
| 56 | + 'border' => '1', |
| 57 | + 'cellspacing' => '0' ) |
| 58 | + ); |
| 59 | + |
| 60 | + if ( $this->reviewMode ) { |
| 61 | + $tableheader .= Xml::openElement( 'tr' ); |
| 62 | + $tableheader .= Xml::element( 'th', |
| 63 | + array( 'rowspan' => '2' ), |
| 64 | + $this->headerText( 'table' ) |
| 65 | + ); |
| 66 | + $tableheader .= Xml::tags( 'th', null, $this->headerText( 'default' ) ); |
| 67 | + $tableheader .= Xml::closeElement( 'tr' ); |
| 68 | + |
| 69 | + $tableheader .= Xml::openElement( 'tr' ); |
| 70 | + $tableheader .= Xml::tags( 'th', null, $this->headerText( 'current' ) ); |
| 71 | + $tableheader .= Xml::closeElement( 'tr' ); |
| 72 | + } else { |
| 73 | + $tableheader .= Xml::openElement( 'tr' ); |
| 74 | + $tableheader .= Xml::tags( 'th', null, $this->headerText( 'table' ) ); |
| 75 | + $tableheader .= Xml::tags( 'th', null, $this->headerText( 'current' )); |
| 76 | + $tableheader .= Xml::closeElement( 'tr' ); |
| 77 | + } |
| 78 | + |
| 79 | + return $tableheader; |
| 80 | + } |
| 81 | + |
| 82 | + public function contents() { |
| 83 | + |
| 84 | + global $wgUser; |
| 85 | + $sk = $wgUser->getSkin(); |
| 86 | + wfLoadExtensionMessages( 'Translate' ); |
| 87 | + |
| 88 | + $uimsg = array(); |
| 89 | + foreach ( array( 'optional' ) as $msg ) { |
| 90 | + $uimsg[$msg] = wfMsgHtml( 'translate-'.$msg ); |
| 91 | + } |
| 92 | + |
| 93 | + $output = ''; |
| 94 | + |
| 95 | + foreach ( $this->collection as $key => $m ) { |
| 96 | + |
| 97 | + $tools = array(); |
| 98 | + $title = $this->keyToTitle( $key ); |
| 99 | + |
| 100 | + $original = $m->definition; |
| 101 | + $message = $m->translation ? $m->translation : $original; |
| 102 | + |
| 103 | + global $wgLang; |
| 104 | + $niceTitle = htmlspecialchars( $wgLang->truncate( $key, - 30 ) ); |
| 105 | + |
| 106 | + $tools['edit'] = $sk->link( |
| 107 | + $title, |
| 108 | + $niceTitle, |
| 109 | + array(), |
| 110 | + array( 'action' => 'edit' ) + $this->editLinkParams, |
| 111 | + 'known' |
| 112 | + ); |
| 113 | + |
| 114 | + $anchor = 'msg_' . $key; |
| 115 | + $anchor = Xml::element( 'a', array( 'name' => $anchor, 'href' => "#$anchor" ), "↓" ); |
| 116 | + |
| 117 | + $extra = ''; |
| 118 | + if ( $m->optional ) $extra = '<br />' . $uimsg['optional']; |
| 119 | + |
| 120 | + $leftColumn = $anchor . $tools['edit'] . $extra; |
| 121 | + |
| 122 | + if ( $this->reviewMode ) { |
| 123 | + $output .= Xml::tags( 'tr', array( 'class' => 'orig' ), |
| 124 | + Xml::tags( 'td', array( 'rowspan' => '2' ), $leftColumn ) . |
| 125 | + Xml::tags( 'td', null, TranslateUtils::convertWhiteSpaceToHTML( $original ) ) |
| 126 | + ); |
| 127 | + |
| 128 | + $output .= Xml::tags( 'tr', array( 'class' => 'new' ), |
| 129 | + Xml::tags( 'td', null, TranslateUtils::convertWhiteSpaceToHTML( $message ) ) . |
| 130 | + Xml::closeElement( 'tr' ) |
| 131 | + ); |
| 132 | + } else { |
| 133 | + $output .= Xml::tags( 'tr', array( 'class' => 'def' ), |
| 134 | + Xml::tags( 'td', null, $leftColumn ) . |
| 135 | + Xml::tags( 'td', null, TranslateUtils::convertWhiteSpaceToHTML( $message ) ) |
| 136 | + ); |
| 137 | + } |
| 138 | + |
| 139 | + } |
| 140 | + |
| 141 | + return $output; |
| 142 | + } |
| 143 | + |
| 144 | + public function fullTable() { |
| 145 | + return $this->header() . $this->contents() . '</table>'; |
| 146 | + } |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | + protected function headerText( $type ) { |
| 151 | + if ( !isset($this->headers[$type]) ) throw new MWException( "Unexpected type $type" ); |
| 152 | + |
| 153 | + list( $format, $value ) = $this->headers[$type]; |
| 154 | + if ( $format === 'msg' ) { |
| 155 | + return wfMsgExt( $value, array( 'parsemag', 'escapenoentities' ) ); |
| 156 | + } elseif ( $format === 'raw' ) { |
| 157 | + return $value; |
| 158 | + } else { |
| 159 | + throw new MWException( "Unexcepted format $format" ); |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + protected function keyToTitle( $key ) { |
| 164 | + $titleText = TranslateUtils::title( $key, $this->collection->code ); |
| 165 | + $namespace = $this->group->namespaces[0]; |
| 166 | + return Title::makeTitle( $namespace, $titleText ); |
| 167 | + } |
| 168 | + |
| 169 | +} |
\ No newline at end of file |
Index: trunk/extensions/Translate/TranslateUtils.php |
— | — | @@ -135,107 +135,6 @@ |
136 | 136 | return $rows; |
137 | 137 | } |
138 | 138 | |
139 | | - /* Table output helpers */ |
140 | | - |
141 | | - public static function tableHeader( $title = '' ) { |
142 | | - $tableheader = Xml::openElement( 'table', array( |
143 | | - 'class' => 'mw-sp-translate-table', |
144 | | - 'border' => '1', |
145 | | - 'cellspacing' => '0' ) |
146 | | - ); |
147 | | - |
148 | | - $tableheader .= Xml::openElement( 'tr' ); |
149 | | - $tableheader .= Xml::element( 'th', |
150 | | - array( 'rowspan' => '2' ), |
151 | | - $title ? $title : wfMsgHtml( 'allmessagesname' ) |
152 | | - ); |
153 | | - $tableheader .= Xml::element( 'th', null, wfMsgHtml( 'allmessagesdefault' ) ); |
154 | | - $tableheader .= Xml::closeElement( 'tr' ); |
155 | | - |
156 | | - $tableheader .= Xml::openElement( 'tr' ); |
157 | | - $tableheader .= Xml::element( 'th', null, wfMsgHtml( 'allmessagescurrent' ) ); |
158 | | - $tableheader .= Xml::closeElement( 'tr' ); |
159 | | - |
160 | | - return $tableheader; |
161 | | - } |
162 | | - |
163 | | - // Todo: extract to own class |
164 | | - public static function makeListing( MessageCollection $messages, $group, |
165 | | - $review = false, array $namespaces, $task = '' ) { |
166 | | - |
167 | | - global $wgUser; |
168 | | - $sk = $wgUser->getSkin(); |
169 | | - wfLoadExtensionMessages( 'Translate' ); |
170 | | - |
171 | | - $uimsg = array(); |
172 | | - foreach ( array( 'edit', 'optional' ) as $msg ) { |
173 | | - $uimsg[$msg] = wfMsgHtml( self::MSG . $msg ); |
174 | | - } |
175 | | - |
176 | | - $output = ''; |
177 | | - |
178 | | - foreach ( $messages as $key => $m ) { |
179 | | - |
180 | | - $tools = array(); |
181 | | - |
182 | | - $title = Title::makeTitle( |
183 | | - $namespaces[0], |
184 | | - self::title( $key, $messages->code ) |
185 | | - ); |
186 | | - |
187 | | - $original = $m->definition; |
188 | | - $message = $m->translation ? $m->translation : $original; |
189 | | - |
190 | | - global $wgLang; |
191 | | - $niceTitle = htmlspecialchars( $wgLang->truncate( $key, - 30 ) ); |
192 | | - |
193 | | - // FIXME: always true, else{} obsolete? |
194 | | - if ( 1 || $wgUser->isAllowed( 'translate' ) ) { |
195 | | - $tools['edit'] = $sk->link( |
196 | | - $title, |
197 | | - $niceTitle, |
198 | | - array(), |
199 | | - array( |
200 | | - 'action' => 'edit', |
201 | | - 'loadgroup' => $group, |
202 | | - 'loadtask' => $task |
203 | | - ), |
204 | | - 'known' |
205 | | - ); |
206 | | - } else { |
207 | | - $tools['edit'] = ''; |
208 | | - } |
209 | | - |
210 | | - $anchor = 'msg_' . $key; |
211 | | - $anchor = Xml::element( 'a', array( 'name' => $anchor, 'href' => "#$anchor" ), "↓" ); |
212 | | - |
213 | | - $extra = ''; |
214 | | - if ( $m->optional ) $extra = '<br />' . $uimsg['optional']; |
215 | | - |
216 | | - $leftColumn = $anchor . $tools['edit'] . $extra; |
217 | | - |
218 | | - if ( $review ) { |
219 | | - $output .= Xml::tags( 'tr', array( 'class' => 'orig' ), |
220 | | - Xml::tags( 'td', array( 'rowspan' => '2' ), $leftColumn ) . |
221 | | - Xml::tags( 'td', null, TranslateUtils::convertWhiteSpaceToHTML( $original ) ) |
222 | | - ); |
223 | | - |
224 | | - $output .= Xml::tags( 'tr', array( 'class' => 'new' ), |
225 | | - Xml::tags( 'td', null, TranslateUtils::convertWhiteSpaceToHTML( $message ) ) . |
226 | | - Xml::closeElement( 'tr' ) |
227 | | - ); |
228 | | - } else { |
229 | | - $output .= Xml::tags( 'tr', array( 'class' => 'def' ), |
230 | | - Xml::tags( 'td', null, $leftColumn ) . |
231 | | - Xml::tags( 'td', null, TranslateUtils::convertWhiteSpaceToHTML( $message ) ) |
232 | | - ); |
233 | | - } |
234 | | - |
235 | | - } |
236 | | - |
237 | | - return $output; |
238 | | - } |
239 | | - |
240 | 139 | /* Some other helpers for ouput*/ |
241 | 140 | |
242 | 141 | public static function selector( $name, $options ) { |