r59829 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59828‎ | r59829 | r59830 >
Date:15:13, 8 December 2009
Author:freakolowsky
Status:deferred
Tags:
Comment:
TableMod extension fix
Modified paths:
  • /trunk/extensions/TableMod/TableMod.body.php (modified) (history)
  • /trunk/extensions/TableMod/TableMod.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TableMod/TableMod.body.php
@@ -19,17 +19,15 @@
2020 public static $sort_key;
2121 public static $sort_col;
2222
23 - var $output = "";
24 -
2523 function __construct($input, $args, $parser, $frame) {
2624 $this->input = trim($input);
2725 $this->args = $args;
2826 $this->parser = $parser;
2927 $this->frame = $frame;
30 -
31 - if (!isset($args['id']))
 28+
 29+ if (!isset($args['ident']))
3230 throw new TableModException(wfMsg('tablemod-error-missingid'));
33 - $this->id = $args['id'];
 31+ $this->id = $args['ident'];
3432
3533 $this->index_column = isset($args['index']) ? $args['index'] : 0;
3634 if (isset($args['actions'])) {
@@ -47,8 +45,6 @@
4846 $this->performActions();
4947 }
5048
51 - $this->generateTable();
52 -
5349 }
5450
5551 private function prepareInput() {
@@ -114,12 +110,6 @@
115111 $tablemodAction[2] < 0) )
116112 throw new TableModException(wfMsg('tablemod-error-invalidsort'));
117113 }
118 -
119 - if ($this->index_column == 0 ) {
120 - foreach ($this->table['rows'] as &$row) {
121 - $row[$row_cols] = '';
122 - }
123 - }
124114 }
125115
126116 private function performActions() {
@@ -198,70 +188,86 @@
199189 }
200190
201191 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";
203197 if (isset($this->table['caption']))
204 - $this->output .= '|+'.$this->table['caption']."\n";
 198+ $output .= '|+'.$this->table['caption']."\n";
205199
 200+
206201 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";
209204
210205 foreach ($this->table['rows'] as $rowkey=>$row) {
211 - $this->output .= "|-\n";
 206+ $output .= "|-\n";
212207
213208 foreach ($row as $key=>$col)
214 - $this->output .= "|$col >>R:$rowkey:$key<<\n";
 209+ $output .= "|$col\n";
215210 }
216211
217 - $this->output .= '>>EMPTY<<'.$this->table['end']."|}";
218 - }
 212+ $output .= $this->table['end']."|}";
219213
220 - public function tableSave() {
221 - global $tablemodContent;
222 - $output = preg_replace(array('/>>H:\d*<</', '/>>R:\d*:\d*<</', '/>>EMPTY<</'), '', $this->output);
223 -
224214 $article_content = $tablemodContent;
225215 $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);
227217 $tablemodContent = str_replace($start_tag[0].$this->input, $start_tag[0].$output, $tablemodContent);
228218 }
229219
230220 public function tableOutput() {
231221 global $wgTitle;
232222
233 - $output = $this->output;
 223+ $output = '{|'.$this->table['start']."\n";
 224+ if (isset($this->table['caption']))
 225+ $output .= '|+'.$this->table['caption']."\n";
234226
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'])) {
244228 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')).' &uarr;]</span><span class="plainlinks">['.$wgTitle->getFullURL(array('tablemod'=>$this->id.'|sort|'.($key+1).'|desc')).' &darr;]</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')).' &uarr;]</span><span class="plainlinks">['.$wgTitle->getFullURL(array('tablemod'=>$this->id.'|sort|'.($key+1).'|desc')).' &darr;]</span>'."\n";
 231+
 232+ if ($this->index_column == 0)
 233+ $output .= '!&nbsp;'."\n";
 234+ } else {
 235+ foreach ($this->table['headers'] as $key=>$header)
 236+ $output .= '!'.$header."\n";
249237 }
 238+
 239+ }
250240
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";
261259 }
262260 }
 261+ } else {
 262+ foreach ($this->table['rows'] as $rowkey=>$row) {
 263+ $output .= "|-\n";
263264
 265+ foreach ($row as $col)
 266+ $output .= "|$col\n";
 267+ }
264268 }
265 -
 269+
 270+ $output .= $this->table['end']."|}";
 271+
266272 return $this->doParse($output);
267273
268274 }
Index: trunk/extensions/TableMod/TableMod.i18n.php
@@ -13,8 +13,7 @@
1414 'tablemod-error-headcount' => 'This tag only supports tables single column headers when removing.',
1515 'tablemod-error-invalidsort' => 'Invalid sort parameters.',
1616 '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.',
1918 );
2019
2120 $messages['sl'] = array(
@@ -26,7 +25,6 @@
2726 'tablemod-error-headcount' => 'Ta značka podpira samo eno-celične glavne oznake.',
2827 'tablemod-error-invalidsort' => 'Neveljavni parametri sortiranja.',
2928 '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.',
3230 );
3331

Status & tagging log