diff options
Diffstat (limited to 'srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src')
11 files changed, 1815 insertions, 0 deletions
diff --git a/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/KBDocumentation.php b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/KBDocumentation.php new file mode 100644 index 0000000..958f1ad --- /dev/null +++ b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/KBDocumentation.php @@ -0,0 +1,75 @@ +<?php +declare(strict_types = 1); +namespace Williamdes\MariaDBMySQLKBS; + +use \stdClass; +use \JsonSerializable; + +class KBDocumentation extends stdClass implements JsonSerializable +{ + + /** + * The URL + * + * @var string + */ + private $url; + + /** + * The anchor + * + * @var string + */ + private $anchor = null; + + /** + * Create a KBEntry object + * + * @param string $url The url + * @param string|null $anchor The anchor + */ + public function __construct(string $url, ?string $anchor = null) + { + $this->url = $url; + if ($anchor !== null) { + $this->anchor = $anchor; + } + } + + /** + * Get the url + * + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * Get the anchor + * + * @return string|null + */ + public function getAnchor(): ?string + { + return $this->anchor; + } + + /** + * Used for json_encode function + * This can seem useless, do not remove it. + * + * @return array + */ + public function jsonSerialize(): array + { + $outObj = array(); + $outObj['url'] = $this->url; + if ($this->anchor !== null) { + $outObj['anchor'] = $this->anchor; + } + return $outObj; + } + +} diff --git a/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/KBEntry.php b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/KBEntry.php new file mode 100644 index 0000000..7ff7e9c --- /dev/null +++ b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/KBEntry.php @@ -0,0 +1,151 @@ +<?php +declare(strict_types = 1); +namespace Williamdes\MariaDBMySQLKBS; + +use \stdClass; +use \JsonSerializable; + +class KBEntry extends stdClass implements JsonSerializable +{ + + /** + * The name of the variable + * + * @var string + */ + private $name; + + /** + * Type of variable + * + * @var string + */ + private $type = null; + + /** + * Is dynamic ? + * + * @var bool + */ + private $dynamic = null; + + /** + * Documentations + * + * @var KBDocumentation[] + */ + private $docs = null; + + /** + * Create a KBEntry object + * + * @param string $name The name of the variable + * @param string|null $type Type of variable + * @param bool|null $dynamic Is dynamic ? + */ + public function __construct(string $name, ?string $type, ?bool $dynamic) + { + $this->name = $name; + if ($type !== null) { + $this->type = $type; + } + if ($dynamic !== null) { + $this->dynamic = $dynamic; + } + } + + /** + * Get the variable name + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * Is the variable dynamic + * + * @return bool|null + */ + public function isDynamic(): ?bool + { + return $this->dynamic; + } + + /** + * Get the variable type + * + * @return string|null + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * Variable has documentations + * + * @return bool + */ + public function hasDocumentations(): bool + { + if ($this->docs === null) { + return false; + } else { + return count($this->docs) > 0; + } + } + + /** + * Get all documentations + * + * @return KBDocumentation[] + */ + public function getDocumentations(): array + { + return $this->docs; + } + + /** + * Add documentation link + * + * @param string $url The URL + * @param string|null $anchor The anchor + * @return KBDocumentation + */ + public function addDocumentation(string $url, ?string $anchor = null ): KBDocumentation + { + $this->url = $url; + if ($this->docs === null) { + $this->docs = array(); + } + $kbd = new KBDocumentation($url, $anchor); + $this->docs[] = $kbd; + return $kbd; + } + + /** + * Used for json_encode function + * This can seem useless, do not remove it. + * + * @return array + */ + public function jsonSerialize(): array + { + $outObj = array(); + $outObj['name'] = $this->name; + if ($this->type !== null) { + $outObj['type'] = $this->type; + } + if ($this->dynamic !== null) { + $outObj['dynamic'] = $this->dynamic; + } + if ($this->docs !== null) { + $outObj['docs'] = $this->docs; + } + return $outObj; + } + +} diff --git a/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/KBException.php b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/KBException.php new file mode 100644 index 0000000..05eea91 --- /dev/null +++ b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/KBException.php @@ -0,0 +1,12 @@ +<?php +declare(strict_types = 1); +namespace Williamdes\MariaDBMySQLKBS; + +use \Exception; + +/** + * KBException class + */ +class KBException extends Exception +{ +} diff --git a/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/MariaDB.js b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/MariaDB.js new file mode 100644 index 0000000..a6f3c01 --- /dev/null +++ b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/MariaDB.js @@ -0,0 +1,271 @@ +'use strict'; + +const common = require(__dirname + '/common'); +const cleaner = require(__dirname + '/cleaner'); + +/** + * Create a doc element + * @param {Element} element The root element + * @returns object The doc object + */ +const createDoc = function($, element) { + let doc = { + id: $(element).attr('id'), + name: $(element) + .text() + .trim(), + }; + try { + /* jshint -W083 */ + // Parse ul > li + const ulElementList = $(element) + .nextAll() + .not('p') + .first(); + if (ulElementList.find('li > strong').length === 0) { + return { id: null }; + } + ulElementList.find('li').each((i, elementDescr) => { + const valueKey = $(elementDescr); + const key = valueKey + .find('strong') + .text() + .toLowerCase() + .trim(); + const value = $(elementDescr) + .text() + .replace(valueKey.find('strong').text(), '') + .trim(); + switch (key) { + case 'dynamic:': + doc.dynamic = value.toLowerCase() === 'yes'; + break; + case 'scope:': + doc.scope = value + .toLowerCase() + .split(',') + .map(item => { + if (item.match(/session/)) { + return 'session'; + } else if (item.match(/global/)) { + return 'global'; + } else { + return item.trim(); + } + }); + doc.scope = doc.scope.filter(function(e) { + return e === 0 || e; + }); + break; + case 'type:': + doc.type = cleaner.cleanType(value.toLowerCase()); + break; + case 'data type:': + /* + * Default method, <li> has a <code> child + * Example: <li><strong>Data Type:</strong> <code>numeric</code></li> + */ + let dataType = valueKey.find('code'); + if (dataType.length > 0) { + doc.type = cleaner.cleanType( + dataType + .first() + .text() + .toLowerCase() + .trim() + ); + } else { + /* + * Fallback method, <li> has text + * Example: <li><strong>Data Type:</strong> boolean</li> + */ + let dataType = value.replace(/undefined/gi, ''); + dataType = dataType.toLowerCase().trim(); + if (dataType !== '') { + doc.type = cleaner.cleanType(dataType); + } else if (dataType === '') { + console.log('Empty datatype found for : ' + doc.id); + } else { + console.log('No datatype found for : ' + doc.id); + } + } + break; + case 'description:': + doc.type = cleaner.cleanType(value.toLowerCase()); + break; + case 'default value:': + case 'default:': + doc.default = cleaner.cleanDefault( + valueKey + .text() + .replace(valueKey.find('strong').text(), '') + .trim() + ); + break; + case 'valid values:': + doc.validValues = valueKey + .find('code') + .get() + .map(el => $(el).text()); + break; + case 'range:': + doc.range = valueKey + .find('code') + .get() + .map(el => $(el).text()); + if (doc.range.length === 1) { + // try x-y + doc.range = doc.range[0].split('-').map(item => item.trim()); + } + if (doc.range.length === 1) { + // try x to y + doc.range = doc.range[0].split('to').map(item => item.trim()); + } + if (doc.range[1] !== undefined) { + doc.range[1] = parseFloat(doc.range[1]); + } + if (doc.range.length === 1) { + // try x upwards + if (value.includes('upwards')) { + doc.range[1] = value; + } + } + // Could be oneday a float + doc.range = { + from: parseFloat(doc.range[0]), + to: doc.range[1], + }; + doc.range = cleaner.cleanRange(doc.range); + + break; + case 'commandline:': + if ( + typeof value === 'string' && + (value.toLowerCase() !== 'no' && + value.toLowerCase() !== 'none' && + value.toLowerCase() !== 'n/a' && + value.toLowerCase() !== 'no commandline option') + ) { + doc.cli = cleaner.cleanCli(value, true); + } + break; + default: + break; + } + }); + /* jshint +W083 */ + } catch (e) { + console.error(e); + console.log('Error at : #' + doc.id); + } + if (doc.type !== undefined) { + if (doc.type === 'numeric') { + doc.type = 'integer'; + } + } + return doc; +}; + +function parsePage($, cbSuccess) { + var anchors = []; + $('.anchored_heading').each(function(i, el) { + let doc = createDoc($, el); + if (doc.id && typeof doc.id === 'string') { + anchors.push(doc); + } + }); + cbSuccess(anchors); +} + +const KB_URL = 'https://mariadb.com/kb/en/library/documentation/'; + +const storageEngines = ['aria', 'myrocks', 'cassandra', 'galera-cluster', 'mroonga', 'myisam', 'tokudb', 'connect']; + +const systemVariables = ['xtradbinnodb-server', 'mariadb-audit-plugin', 'ssltls', 'performance-schema']; + +const custom = [ + { + url: 'columns-storage-engines-and-plugins/storage-engines/spider/spider-server-system-variables/', + name: 'spider-server-system-variables', + }, + { + url: 'semisynchronous-replication/', + name: 'semisynchronous-replication-system-variables', + }, + { + url: 'replication-and-binary-log-server-system-variables/', + name: 'replication-and-binary-log-server-system-variables', + }, + { + url: 'gtid/', + name: 'gtid-system-variables', + }, + { + url: 'replication/optimization-and-tuning/system-variables/server-system-variables/', + name: 'server-system-variables', + }, + { + url: 'system-versioned-tables/', + name: 'versioned-tables-system-variables', + }, +]; + +const status = [ + 'server', + 'galera-cluster', + 'aria-server', + 'cassandra', + 'mroonga', + 'spider-server', + 'sphinx', + 'tokudb', + 'xtradbinnodb-server', + 'replication-and-binary-log', + 'oqgraph-system-and', + 'thread-pool-system-and', + 'ssltls', + 'mariadb-audit-plugin', + 'semisynchronous-replication-plugin', +]; + +const pages = []; + +storageEngines.forEach(se => { + pages.push({ + url: KB_URL + 'columns-storage-engines-and-plugins/storage-engines/' + se + '/' + se + '-system-variables/', + name: se + '-system-variables', + }); +}); + +custom.forEach(cu => { + pages.push({ + url: KB_URL + cu.url, + name: cu.name, + }); +}); + +status.forEach(statusName => { + pages.push({ + url: KB_URL + statusName + '-status-variables/', + name: statusName + '-status-variables', + }); +}); + +systemVariables.forEach(systemVariableName => { + pages.push({ + url: KB_URL + systemVariableName + '-system-variables/', + name: systemVariableName + '-system-variables', + }); +}); + +module.exports = { + run: () => { + /*var pages = [ + { + url: 'http://7.2.local/Global%20Transaction%20ID%20-%20MariaDB%20Knowledge%20Base.html', + name: 'gtid-system-variables' + } + ]*/ + return common.processDataExtraction(pages, 'mariadb-', parsePage); + }, +}; diff --git a/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/MySQL.js b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/MySQL.js new file mode 100644 index 0000000..99f4561 --- /dev/null +++ b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/MySQL.js @@ -0,0 +1,251 @@ +'use strict'; + +const common = require(__dirname + '/common'); +const cleaner = require(__dirname + '/cleaner'); + +/** + * Complete a doc element with info found in table + * @param {HTMLTableRowElement[]} rows The table rows + * @param {Object} doc The doc object + */ +function completeDoc($, rows, doc) { + $(rows).each((i, elem) => { + let tds = $(elem).find('td'); // first is key and last is value + var name = tds + .first() + .text() + .toLowerCase() + .trim(); + var value = tds.last(); + switch (name) { + case 'dynamic': + doc.dynamic = + value + .text() + .toLowerCase() + .trim() === 'yes'; + break; + case 'name': + doc.name = value.text().trim(); + break; + case 'system variable': + // Do not overwrite the name + if (typeof doc.name === 'undefined') { + doc.name = value + .text() + .toLowerCase() + .trim(); + } + break; + case 'scope': + let scope = value.text().toLowerCase(); + if (scope === 'both') { + // found on mysql-cluster-options-variables.html + doc.scope = ['global', 'session']; + } else if (scope != '') { + doc.scope = scope.split(',').map(item => { + if (item.match(/session/)) { + return 'session'; + } else if (item.match(/global/)) { + return 'global'; + } else { + return item.trim(); + } + }); + } + if (doc.scope !== undefined) { + doc.scope = doc.scope.filter(function(e) { + return e === 0 || e; + }); + } + break; + case 'type': + let type = value + .text() + .toLowerCase() + .trim(); + if (type != '') { + doc.type = cleaner.cleanType(type); + } + break; + case 'default value': + case 'default, range': + doc.default = cleaner.cleanDefault(value.text().trim()); + break; + case 'valid values': + doc.validValues = $(value) + .find('code') + .get() + .map(el => $(el).text()); + break; + case 'minimum value': + if (doc.range == undefined) { + doc.range = {}; + } + doc.range.from = parseFloat(value.text().trim()); + break; + case 'maximum value': + if (doc.range == undefined) { + doc.range = {}; + } + doc.range.to = parseFloat(value.text().trim()); + break; + case 'command-line format': + doc.cli = cleaner.cleanCli(value.text().trim()); + break; + case 'command line': + if (typeof doc.cli !== 'string') { + doc.cli = + value + .text() + .toLowerCase() + .trim() === 'yes'; + } + break; + } + }); +} + +/** + * Create a doc element + * @param {Element} element The root element + * @returns object The doc object + */ +function createDoc($, element, doc) { + completeDoc($, $(element).find('tbody > tr'), doc); + if (doc.range !== undefined) { + doc.range = cleaner.cleanRange(doc.range); + } + + if (doc.name && doc.name.match(cleaner.regexCli)) { + delete doc.name; + } + + return doc; +} + +function parsePage($, cbSuccess) { + var anchors = []; + $('.informaltable, .table') + .filter(function(i, elem) { + return ( + $(elem) + .find('th') + .first() + .text() === 'Property' + ); + }) + .each(function(i, elem) { + let doc = { + id: $(elem) + .prevAll() + .find('a') + .filter(function(i, el) { + return typeof $(el).attr('name') === 'string' && typeof $(el).attr('class') === 'undefined'; + }) + .first() + .attr('name'), + }; + if (typeof doc.id !== 'string') { + doc.id = $(elem) + .prevAll() + .find('.link') + .first() + .attr('href') + .split('#')[1]; + } + createDoc($, elem, doc); + if (typeof doc.cli === 'boolean') { + doc.cli = $(elem) + .prevAll() + .find('.option') + .first() + .text(); + if (doc.cli === '') { + delete doc.cli; + } + } + if (!doc.name && doc.cli) { + var matches = doc.cli.match(cleaner.regexCli); + doc.name = matches[2].replace(/-/g, '_'); + } + anchors.push(doc); + }); + + cbSuccess(anchors); +} + +const KB_URL = 'https://dev.mysql.com/doc/refman/8.0/en/'; +const KB_URL57 = 'https://dev.mysql.com/doc/refman/5.7/en/'; + +const pages = [ + { + url: KB_URL + 'server-system-variables.html', + name: 'server-system-variables', + }, + { + url: KB_URL + 'innodb-parameters.html', + name: 'innodb-parameters', + }, + { + url: KB_URL + 'performance-schema-system-variables.html', + name: 'performance-schema-system-variables', + }, + { + url: KB_URL + 'x-plugin-options-system-variables.html', + name: 'x-plugin-options-system-variables', + }, + { + url: KB_URL + 'replication-options-binary-log.html', + name: 'replication-options-binary-log', + }, + { + url: KB_URL57 + 'replication-options-binary-log.html', + name: 'replication-options-binary-log_5.7', + }, + { + url: KB_URL + 'pluggable-authentication-system-variables.html', + name: 'pluggable-authentication-system-variables', + }, + { + url: KB_URL + 'audit-log-reference.html', + name: 'audit-log-reference', + }, + { + url: KB_URL + 'replication-options-gtids.html', + name: 'replication-options-gtids', + }, + { + url: KB_URL + 'replication-options-slave.html', + name: 'replication-options-slave', + }, + { + url: KB_URL + 'replication-options-master.html', + name: 'replication-options-master', + }, + { + url: KB_URL + 'replication-options.html', + name: 'replication-options', + }, + { + url: KB_URL57 + 'mysql-cluster-options-variables.html', + name: 'mysql-cluster-options-variables', + }, + { + url: KB_URL + 'server-options.html', + name: 'server-options', + }, + { + url: KB_URL + 'version-tokens-reference.html', + name: 'version-tokens-reference', + }, +]; + +module.exports = { + parsePage: parsePage, + createDoc: createDoc, + completeDoc: completeDoc, + run: () => { + return common.processDataExtraction(pages, 'mysql-', parsePage); + }, +}; diff --git a/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/Search.php b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/Search.php new file mode 100644 index 0000000..12f8ded --- /dev/null +++ b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/Search.php @@ -0,0 +1,167 @@ +<?php +declare(strict_types = 1); +namespace Williamdes\MariaDBMySQLKBS; + +use \stdClass; + +class Search +{ + + /** + * Loaded data + * + * @var mixed + */ + public static $data; + + /** + * Data is loaded + * + * @var bool + */ + public static $loaded = false; + + public const ANY = -1; + public const MYSQL = 1; + public const MARIADB = 2; + public const DS = DIRECTORY_SEPARATOR; + public static $DATA_DIR = __DIR__.self::DS."..".self::DS."dist".self::DS; + + /** + * Load data from disk + * + * @return void + * @throws KBException + */ + public static function loadData(): void + { + if (Search::$loaded === false) { + $filePath = Search::$DATA_DIR."merged-ultraslim.json"; + $contents = @file_get_contents($filePath); + if ($contents === false) { + throw new KBException("$filePath does not exist !"); + } + Search::$data = json_decode($contents); + Search::$loaded = true; + } + } + + /** + * Load test data + * + * @param SlimData $slimData The SlimData object + * @return void + */ + public static function loadTestData(SlimData $slimData): void + { + Search::$data = json_decode((string) json_encode($slimData)); + Search::$loaded = true; + } + + /** + * get the first link to doc available + * + * @param string $name Name of variable + * @param int $type (optional) Type of link Search::MYSQL/Search::MARIADB/Search::ANY + * @return string + * @throws KBException + */ + public static function getByName(string $name, int $type = Search::ANY): string + { + self::loadData(); + $kbEntrys = self::getVariable($name); + if (isset($kbEntrys->a)) { + foreach ($kbEntrys->a as $kbEntry) { + if ($type === Search::ANY) { + return Search::$data->urls[$kbEntry->u]."#".$kbEntry->a; + } elseif ($type === Search::MYSQL) { + if ($kbEntry->t === Search::MYSQL) { + return Search::$data->urls[$kbEntry->u]."#".$kbEntry->a; + } + } elseif ($type === Search::MARIADB) { + if ($kbEntry->t === Search::MARIADB) { + return Search::$data->urls[$kbEntry->u]."#".$kbEntry->a; + } + } + } + } + + throw new KBException("$name does not exist for this type of documentation !"); + } + + /** + * Get a variable + * + * @param string $name Name of variable + * @return stdClass + * @throws KBException + */ + public static function getVariable(string $name): stdClass + { + self::loadData(); + if (isset(Search::$data->vars->{$name})) { + return Search::$data->vars->{$name}; + } else { + throw new KBException("$name does not exist !"); + } + } + + /** + * get the type of the variable + * + * @param string $name Name of variable + * @return string + * @throws KBException + */ + public static function getVariableType(string $name): string + { + self::loadData(); + $kbEntry = self::getVariable($name); + if (isset($kbEntry->t)) { + return Search::$data->varTypes->{$kbEntry->t}; + } else { + throw new KBException("$name does have a known type !"); + } + } + + /** + * Return the list of static variables + * + * @return array + */ + public static function getStaticVariables(): array + { + return self::getVariablesWithDynamic(false); + } + + /** + * Return the list of dynamic variables + * + * @return array + */ + public static function getDynamicVariables(): array + { + return self::getVariablesWithDynamic(true); + } + + /** + * Return the list of variables having dynamic = $dynamic + * + * @param bool $dynamic dynamic=true/dynamic=false + * @return array + */ + public static function getVariablesWithDynamic(bool $dynamic): array + { + self::loadData(); + $staticVars = array(); + foreach (Search::$data->vars as $name => $var) { + if (isset($var->d)) { + if ($var->d === $dynamic) { + $staticVars[] = $name; + } + } + } + return $staticVars; + } + +} diff --git a/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/SlimData.php b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/SlimData.php new file mode 100644 index 0000000..fc7cd42 --- /dev/null +++ b/srcs/phpmyadmin/vendor/williamdes/mariadb-mysql-kbs/src/SlimData.php @@ -0,0 +1,162 @@ +<?php +declare(strict_types = 1); +namespace Williamdes\MariaDBMySQLKBS; + +use \stdClass; +use \JsonSerializable; + +class SlimData extends stdClass implements JsonSerializable +{ + + /** + * Variables + * + * @var KBEntry[] + */ + private $vars = array(); + + /** + * File revision + * + * @var float + */ + private $version = 1; + + /** + * Urls + * + * @var string[] + */ + private $urls = array(); + + /** + * Types of documentation + * + * @var array<string, string|int> + */ + private $types = array("MYSQL" => 1, "MARIADB" => 2); + + /** + * Types of variables + * + * @var array<string, string|int> + */ + private $varTypes = array( + "string" => 1, + "boolean" => 2, + "integer" => 3, + "numeric" => 4, + "enumeration" => 5, + "set" => 6, + "directory name" => 7, + "file name" => 8, + "byte" => 9 + ); + + /** + * Create a slimData object + * + * @param float|nu |
