Index: trunk/extensions/TableMod/TableMod.body.php |
— | — | @@ -19,17 +19,15 @@ |
20 | 20 | public static $sort_key; |
21 | 21 | public static $sort_col; |
22 | 22 | |
23 | | - var $output = ""; |
24 | | - |
25 | 23 | function __construct($input, $args, $parser, $frame) { |
26 | 24 | $this->input = trim($input); |
27 | 25 | $this->args = $args; |
28 | 26 | $this->parser = $parser; |
29 | 27 | $this->frame = $frame; |
30 | | - |
31 | | - if (!isset($args['id'])) |
| 28 | + |
| 29 | + if (!isset($args['ident'])) |
32 | 30 | throw new TableModException(wfMsg('tablemod-error-missingid')); |
33 | | - $this->id = $args['id']; |
| 31 | + $this->id = $args['ident']; |
34 | 32 | |
35 | 33 | $this->index_column = isset($args['index']) ? $args['index'] : 0; |
36 | 34 | if (isset($args['actions'])) { |
— | — | @@ -47,8 +45,6 @@ |
48 | 46 | $this->performActions(); |
49 | 47 | } |
50 | 48 | |
51 | | - $this->generateTable(); |
52 | | - |
53 | 49 | } |
54 | 50 | |
55 | 51 | private function prepareInput() { |
— | — | @@ -114,12 +110,6 @@ |
115 | 111 | $tablemodAction[2] < 0) ) |
116 | 112 | throw new TableModException(wfMsg('tablemod-error-invalidsort')); |
117 | 113 | } |
118 | | - |
119 | | - if ($this->index_column == 0 ) { |
120 | | - foreach ($this->table['rows'] as &$row) { |
121 | | - $row[$row_cols] = ''; |
122 | | - } |
123 | | - } |
124 | 114 | } |
125 | 115 | |
126 | 116 | private function performActions() { |
— | — | @@ -198,70 +188,86 @@ |
199 | 189 | } |
200 | 190 | |
201 | 191 | private function generateTable() { |
202 | | - $this->output = '{|'.$this->table['start']."\n"; |
| 192 | + } |
| 193 | + |
| 194 | + public function tableSave() { |
| 195 | + global $tablemodContent; |
| 196 | + $output = '{|'.$this->table['start']."\n"; |
203 | 197 | if (isset($this->table['caption'])) |
204 | | - $this->output .= '|+'.$this->table['caption']."\n"; |
| 198 | + $output .= '|+'.$this->table['caption']."\n"; |
205 | 199 | |
| 200 | + |
206 | 201 | if (isset($this->table['headers'])) |
207 | | - foreach ($this->table['headers'] as $key=>$header) |
208 | | - $this->output .= "!$header >>H:$key<<\n"; |
| 202 | + foreach ($this->table['headers'] as $header) |
| 203 | + $output .= "!$header\n"; |
209 | 204 | |
210 | 205 | foreach ($this->table['rows'] as $rowkey=>$row) { |
211 | | - $this->output .= "|-\n"; |
| 206 | + $output .= "|-\n"; |
212 | 207 | |
213 | 208 | foreach ($row as $key=>$col) |
214 | | - $this->output .= "|$col >>R:$rowkey:$key<<\n"; |
| 209 | + $output .= "|$col\n"; |
215 | 210 | } |
216 | 211 | |
217 | | - $this->output .= '>>EMPTY<<'.$this->table['end']."|}"; |
218 | | - } |
| 212 | + $output .= $this->table['end']."|}"; |
219 | 213 | |
220 | | - public function tableSave() { |
221 | | - global $tablemodContent; |
222 | | - $output = preg_replace(array('/>>H:\d*<</', '/>>R:\d*:\d*<</', '/>>EMPTY<</'), '', $this->output); |
223 | | - |
224 | 214 | $article_content = $tablemodContent; |
225 | 215 | $start_tag = array(); |
226 | | - preg_match('/\<table-mod [^>]*?id="'.$this->id.'"[^>]*?>[^{]*/', $tablemodContent, $start_tag); |
| 216 | + preg_match('/\<table-mod [^>]*?id="'.$this->id.'"[^>]*?>[^{]* /', $tablemodContent, $start_tag); |
227 | 217 | $tablemodContent = str_replace($start_tag[0].$this->input, $start_tag[0].$output, $tablemodContent); |
228 | 218 | } |
229 | 219 | |
230 | 220 | public function tableOutput() { |
231 | 221 | global $wgTitle; |
232 | 222 | |
233 | | - $output = $this->output; |
| 223 | + $output = '{|'.$this->table['start']."\n"; |
| 224 | + if (isset($this->table['caption'])) |
| 225 | + $output .= '|+'.$this->table['caption']."\n"; |
234 | 226 | |
235 | | - if (($colspan = count($this->table['rows'])) == 0) { |
236 | | - $colspan = isset($this->table['headers']) ? count($this->table['headers']) : 1; |
237 | | - for ($key = 0; $key < $colspan; $key++) |
238 | | - $output = str_replace(">>H:$key<<", '', $output); |
239 | | - $output = str_replace(">>EMPTY<<", "\n|-\n| colspan=\"$colspan\" | ".wfMsg('tablemod-error-tableempty')."\n", $output); |
240 | | - } else { |
241 | | - |
242 | | - $output = str_replace(">>EMPTY<<", '', $output); |
243 | | - |
| 227 | + if (isset($this->table['headers'])) { |
244 | 228 | if (isset($this->index_actions['sort'])) { |
245 | | - if (isset($this->table['headers'])) { |
246 | | - foreach ($this->table['headers'] as $key=>$header) |
247 | | - $output = str_replace(">>H:$key<<", '<span class="plainlinks">['.$wgTitle->getFullURL(array('tablemod'=>$this->id.'|sort|'.($key+1).'|asc')).' ↑]</span><span class="plainlinks">['.$wgTitle->getFullURL(array('tablemod'=>$this->id.'|sort|'.($key+1).'|desc')).' ↓]</span>', $output); |
248 | | - } |
| 229 | + foreach ($this->table['headers'] as $key=>$header) |
| 230 | + $output .= '!'.$header.' <span class="plainlinks">['.$wgTitle->getFullURL(array('tablemod'=>$this->id.'|sort|'.($key+1).'|asc')).' ↑]</span><span class="plainlinks">['.$wgTitle->getFullURL(array('tablemod'=>$this->id.'|sort|'.($key+1).'|desc')).' ↓]</span>'."\n"; |
| 231 | + |
| 232 | + if ($this->index_column == 0) |
| 233 | + $output .= '! '."\n"; |
| 234 | + } else { |
| 235 | + foreach ($this->table['headers'] as $key=>$header) |
| 236 | + $output .= '!'.$header."\n"; |
249 | 237 | } |
| 238 | + |
| 239 | + } |
250 | 240 | |
251 | | - if (isset($this->index_actions['remove'])) { |
252 | | - $removeMsg = wfMsg('tablemod-msg-remove'); |
253 | | - for ($key = 0; $key < $colspan; $key++) |
254 | | - if ($key != $this->index_column-1) |
255 | | - $output = preg_replace("/>>R:\d*:$key<</", '', $output); |
256 | | - |
257 | | - $key = $this->index_column-1; |
258 | | - foreach ($this->table['rows'] as $rowkey=>$row) { |
259 | | - $colval = trim(preg_replace('/.*\|\s*/', '', $row[$key])); |
260 | | - $output = str_replace(">>R:$rowkey:$key<<", '<span class="plainlinks">['.$wgTitle->getFullURL(array('tablemod'=>$this->id.'|remove|'.$colval))." $removeMsg]</span>", $output); |
| 241 | + if (isset($this->index_actions['remove'])) { |
| 242 | + $removeMsg = wfMsg('tablemod-msg-remove'); |
| 243 | + |
| 244 | + foreach ($this->table['rows'] as $rowkey=>$row) { |
| 245 | + $output .= "|-\n"; |
| 246 | + |
| 247 | + if ($this->index_column > 0) { |
| 248 | + foreach ($row as $key=>$col) |
| 249 | + if ($key == $this->index_column-1) { |
| 250 | + $colval = trim(preg_replace('/.*\|\s*/', '', $col)); |
| 251 | + $output .= "|$col ".'<span class="plainlinks">['.$wgTitle->getFullURL(array('tablemod'=>$this->id.'|remove|'.$colval))." $removeMsg]</span>\n"; |
| 252 | + } else { |
| 253 | + $output .= "|$col\n"; |
| 254 | + } |
| 255 | + } else { |
| 256 | + foreach ($row as $col) |
| 257 | + $output .= "|$col\n"; |
| 258 | + $output .= '|<span class="plainlinks">['.$wgTitle->getFullURL(array('tablemod'=>$this->id.'|remove|'.$rowkey))." $removeMsg]</span>"."\n"; |
261 | 259 | } |
262 | 260 | } |
| 261 | + } else { |
| 262 | + foreach ($this->table['rows'] as $rowkey=>$row) { |
| 263 | + $output .= "|-\n"; |
263 | 264 | |
| 265 | + foreach ($row as $col) |
| 266 | + $output .= "|$col\n"; |
| 267 | + } |
264 | 268 | } |
265 | | - |
| 269 | + |
| 270 | + $output .= $this->table['end']."|}"; |
| 271 | + |
266 | 272 | return $this->doParse($output); |
267 | 273 | |
268 | 274 | } |
Index: trunk/extensions/TableMod/TableMod.i18n.php |
— | — | @@ -13,8 +13,7 @@ |
14 | 14 | 'tablemod-error-headcount' => 'This tag only supports tables single column headers when removing.', |
15 | 15 | 'tablemod-error-invalidsort' => 'Invalid sort parameters.', |
16 | 16 | 'tablemod-error-invalidaction' => 'Invalid action.', |
17 | | - 'tablemod-error-tableempty' => 'Table is empty', |
18 | | - 'tablemod-error-missingid' => 'Missing id attribute in tag.', |
| 17 | + 'tablemod-error-missingid' => 'Missing ident attribute in tag.', |
19 | 18 | ); |
20 | 19 | |
21 | 20 | $messages['sl'] = array( |
— | — | @@ -26,7 +25,6 @@ |
27 | 26 | 'tablemod-error-headcount' => 'Ta značka podpira samo eno-celične glavne oznake.', |
28 | 27 | 'tablemod-error-invalidsort' => 'Neveljavni parametri sortiranja.', |
29 | 28 | 'tablemod-error-invalidaction' => 'Neveljavna akcija.', |
30 | | - 'tablemod-error-tableempty' => 'Tabela je prazna', |
31 | | - 'tablemod-error-missingid' => 'Mankajoč id atribut v znački.', |
| 29 | + 'tablemod-error-missingid' => 'Mankajoč ident atribut v znački.', |
32 | 30 | ); |
33 | 31 | |