PMA\libraries\plugins\export\ExportMediawiki::exportData PHP Метод

exportData() публичный Метод

Outputs the content of a table in MediaWiki format
public exportData ( string $db, string $table, string $crlf, string $error_url, string $sql_query, array $aliases = [] ) : boolean
$db string database name
$table string table name
$crlf string the end of line sequence
$error_url string the url to go back in case of error
$sql_query string SQL query for obtaining data
$aliases array Aliases of db/table/columns
Результат boolean Whether it succeeded
    public function exportData($db, $table, $crlf, $error_url, $sql_query, $aliases = array())
    {
        $db_alias = $db;
        $table_alias = $table;
        $this->initAlias($aliases, $db_alias, $table_alias);
        // Print data comment
        $output = $this->_exportComment("Table data for " . PMA\libraries\Util::backquote($table_alias));
        // Begin the table construction
        // Use the "wikitable" class for style
        // Use the "sortable"  class for allowing tables to be sorted by column
        $output .= "{| class=\"wikitable sortable\" style=\"text-align:center;\"" . $this->_exportCRLF();
        // Add the table name
        if (isset($GLOBALS['mediawiki_caption'])) {
            $output .= "|+'''" . $table_alias . "'''" . $this->_exportCRLF();
        }
        // Add the table headers
        if (isset($GLOBALS['mediawiki_headers'])) {
            // Get column names
            $column_names = $GLOBALS['dbi']->getColumnNames($db, $table);
            // Add column names as table headers
            if (!is_null($column_names)) {
                // Use '|-' for separating rows
                $output .= "|-" . $this->_exportCRLF();
                // Use '!' for separating table headers
                foreach ($column_names as $column) {
                    if (!empty($aliases[$db]['tables'][$table]['columns'][$column])) {
                        $column = $aliases[$db]['tables'][$table]['columns'][$column];
                    }
                    $output .= " ! " . $column . "" . $this->_exportCRLF();
                }
            }
        }
        // Get the table data from the database
        $result = $GLOBALS['dbi']->query($sql_query, null, PMA\libraries\DatabaseInterface::QUERY_UNBUFFERED);
        $fields_cnt = $GLOBALS['dbi']->numFields($result);
        while ($row = $GLOBALS['dbi']->fetchRow($result)) {
            $output .= "|-" . $this->_exportCRLF();
            // Use '|' for separating table columns
            for ($i = 0; $i < $fields_cnt; ++$i) {
                $output .= " | " . $row[$i] . "" . $this->_exportCRLF();
            }
        }
        // End table construction
        $output .= "|}" . str_repeat($this->_exportCRLF(), 2);
        return PMA_exportOutputHandler($output);
    }