Beispiel #1
0
function tablemodRender($input, $args, $parser, $frame)
{
    global $tablemodAction, $tablemodContent, $tablemodContentChanged, $wgRequest, $wgArticle;
    if ($tablemodAction === FALSE) {
        $tablemodAction = explode('|', $wgRequest->getVal('tablemod'));
    }
    if ($tablemodContent === FALSE) {
        $tablemodContent = $wgArticle->getContent();
    }
    try {
        $mod = new TableMod($input, $args, $parser, $frame);
    } catch (TableModException $e) {
        return $e->getMessage();
    }
    $mod->tableSave();
    $parser->disableCache();
    return $mod->tableOutput();
}
Beispiel #2
0
 private function performActions()
 {
     global $tablemodAction, $tablemodContentChanged;
     if ($tablemodAction[1] == 'remove' && isset($this->index_actions['remove'])) {
         if ($this->index_column == 0) {
             unset($this->table['rows'][$tablemodAction[2]]);
         } else {
             foreach ($this->table['rows'] as $rowid => $row) {
                 if (trim(preg_replace('/.*\\|\\s*/', '', $row[$this->index_column - 1])) == $tablemodAction[2]) {
                     unset($this->table['rows'][$rowid]);
                 }
             }
         }
         $tablemodContentChanged = TRUE;
     } elseif ($tablemodAction[1] == 'sort' && isset($this->index_actions['sort'])) {
         TableMod::$sort_key = isset($tablemodAction[2]) && $tablemodAction[2] > 0 && $tablemodAction[2] <= count($this->table['headers']) ? $tablemodAction[2] : 0;
         TableMod::$sort_direction = isset($tablemodAction[3]) && $tablemodAction[3] == 'asc' ? 'asc' : 'desc';
         if ($tablemodAction[2] == 0) {
             $this->table['rows'] = array_reverse($this->table['rows']);
         } else {
             $numericCompare = true;
             TableMod::$sort_col = count($this->table['rows'][0]);
             foreach ($this->table['rows'] as &$row) {
                 $colval = trim(preg_replace('/.*\\|\\s*/', '', $row[TableMod::$sort_key - 1]));
                 $row[TableMod::$sort_col] = $colval;
                 if (!is_numeric($colval)) {
                     $numericCompare = false;
                 }
             }
             if ($numericCompare) {
                 usort($this->table['rows'], array('TableMod', 'doRowCompare'));
             } else {
                 usort($this->table['rows'], array('TableMod', 'doRowCompareString'));
             }
             foreach ($this->table['rows'] as &$row) {
                 unset($row[TableMod::$sort_col]);
             }
         }
         $tablemodContentChanged = TRUE;
     }
 }