2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Library for extracting information about the available storage engines
12 define('PMA_ENGINE_SUPPORT_NO', 0);
13 define('PMA_ENGINE_SUPPORT_DISABLED', 1);
14 define('PMA_ENGINE_SUPPORT_YES', 2);
15 define('PMA_ENGINE_SUPPORT_DEFAULT', 3);
17 define('PMA_ENGINE_DETAILS_TYPE_PLAINTEXT', 0);
18 define('PMA_ENGINE_DETAILS_TYPE_SIZE', 1);
19 define('PMA_ENGINE_DETAILS_TYPE_NUMERIC', 2); //Has no effect yet...
20 define('PMA_ENGINE_DETAILS_TYPE_BOOLEAN', 3); // 'ON' or 'OFF'
23 * base Storage Engine Class
26 class PMA_StorageEngine
29 * @var string engine name
31 var $engine = 'dummy';
34 * @var string engine title/description
36 var $title = 'PMA Dummy Engine Class';
39 * @var string engine lang description
41 var $comment = 'If you read this text inside phpMyAdmin, something went wrong...';
44 * @var integer engine supported by current server
46 var $support = PMA_ENGINE_SUPPORT_NO
;
49 * returns array of storage engines
52 * @staticvar array $storage_engines storage engines
54 * @uses PMA_DBI_fetch_result()
55 * @return array of storage engines
57 static public function getStorageEngines()
59 static $storage_engines = null;
61 if (null !== $storage_engines) {
62 return $storage_engines;
65 return PMA_DBI_fetch_result('SHOW STORAGE ENGINES', 'Engine');
69 * returns HTML code for storage engine select box
72 * @uses PMA_StorageEngine::getStorageEngines()
74 * @uses htmlspecialchars()
75 * @param string $name The name of the select form element
76 * @param string $id The ID of the form field
77 * @param string $selected The selected engine
78 * @param boolean $offerUnavailableEngines
79 * Should unavailable storage engines be offered?
80 * @return string html selectbox
82 static public function getHtmlSelect($name = 'engine', $id = null,
83 $selected = null, $offerUnavailableEngines = false)
85 $selected = strtolower($selected);
86 $output = '<select name="' . $name . '"'
87 . (empty($id) ?
'' : ' id="' . $id . '"') . '>' . "\n";
89 foreach (PMA_StorageEngine
::getStorageEngines() as $key => $details) {
90 if (!$offerUnavailableEngines
91 && ($details['Support'] == 'NO' ||
$details['Support'] == 'DISABLED')) {
95 $output .= ' <option value="' . htmlspecialchars($key). '"'
96 . (empty($details['Comment'])
97 ?
'' : ' title="' . htmlspecialchars($details['Comment']) . '"')
98 . (strtolower($key) == $selected ||
(empty($selected) && $details['Support'] == 'DEFAULT')
99 ?
' selected="selected"' : '') . '>' . "\n"
100 . ' ' . htmlspecialchars($details['Engine']) . "\n"
101 . ' </option>' . "\n";
103 $output .= '</select>' . "\n";
108 * public static final PMA_StorageEngine getEngine()
110 * Loads the corresponding engine plugin, if available.
112 * @uses str_replace()
113 * @uses file_exists()
114 * @uses PMA_StorageEngine
115 * @param string $engine The engine ID
116 * @return object The engine plugin
118 static public function getEngine($engine)
120 $engine = str_replace('/', '', str_replace('.', '', $engine));
121 $engine_lowercase_filename = strtolower($engine);
122 if (file_exists('./libraries/engines/' . $engine_lowercase_filename . '.lib.php')
123 && include_once './libraries/engines/' . $engine_lowercase_filename . '.lib.php') {
124 $class_name = 'PMA_StorageEngine_' . $engine;
125 $engine_object = new $class_name($engine);
127 $engine_object = new PMA_StorageEngine($engine);
129 return $engine_object;
133 * return true if given engine name is supported/valid, otherwise false
136 * @uses PMA_StorageEngine::getStorageEngines()
137 * @param string $engine name of engine
138 * @return boolean whether $engine is valid or not
140 static public function isValid($engine)
142 if ($engine == "PBMS") {
145 $storage_engines = PMA_StorageEngine
::getStorageEngines();
146 return isset($storage_engines[$engine]);
150 * returns as HTML table of the engine's server variables
152 * @uses PMA_ENGINE_DETAILS_TYPE_SIZE
153 * @uses PMA_ENGINE_DETAILS_TYPE_NUMERIC
154 * @uses PMA_StorageEngine::getVariablesStatus()
155 * @uses PMA_showHint()
156 * @uses PMA_formatByteDown()
157 * @uses PMA_formatNumber()
158 * @uses htmlspecialchars()
159 * @return string The table that was generated based on the retrieved information
161 function getHtmlVariables()
166 foreach ($this->getVariablesStatus() as $details) {
167 $ret .= '<tr class="' . ($odd_row ?
'odd' : 'even') . '">' . "\n"
169 if (!empty($details['desc'])) {
170 $ret .= ' ' . PMA_showHint($details['desc']) . "\n";
172 $ret .= ' </td>' . "\n"
173 . ' <th>' . htmlspecialchars($details['title']) . '</th>' . "\n"
174 . ' <td class="value">';
175 switch ($details['type']) {
176 case PMA_ENGINE_DETAILS_TYPE_SIZE
:
177 $parsed_size = $this->resolveTypeSize($details['value']);
178 $ret .= $parsed_size[0] . ' ' . $parsed_size[1];
181 case PMA_ENGINE_DETAILS_TYPE_NUMERIC
:
182 $ret .= PMA_formatNumber($details['value']) . ' ';
185 $ret .= htmlspecialchars($details['value']) . ' ';
187 $ret .= '</td>' . "\n"
189 $odd_row = !$odd_row;
194 . ' ' . __('There is no detailed status information available for this storage engine.') . "\n"
197 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
204 * returns the engine specific handling for
205 * PMA_ENGINE_DETAILS_TYPE_SIZE type variables.
207 * This function should be overridden when
208 * PMA_ENGINE_DETAILS_TYPE_SIZE type needs to be
209 * handled differently for a particular engine.
211 * @return string the formatted value and its unit
213 function resolveTypeSize($value)
215 return PMA_formatByteDown($value);
219 * returns array with detailed info about engine specific server variables
221 * @uses PMA_ENGINE_DETAILS_TYPE_PLAINTEXT
222 * @uses PMA_StorageEngine::getVariables()
223 * @uses PMA_StorageEngine::getVariablesLikePattern()
224 * @uses PMA_DBI_query()
225 * @uses PMA_DBI_fetch_assoc()
226 * @uses PMA_DBI_free_result()
227 * @return array with detailed info about specific engine server variables
229 function getVariablesStatus()
231 $variables = $this->getVariables();
232 $like = $this->getVariablesLikePattern();
235 $like = " LIKE '" . $like . "' ";
240 $mysql_vars = array();
242 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
243 $res = PMA_DBI_query($sql_query);
244 while ($row = PMA_DBI_fetch_assoc($res)) {
245 if (isset($variables[$row['Variable_name']])) {
246 $mysql_vars[$row['Variable_name']] = $variables[$row['Variable_name']];
248 && strpos(strtolower($row['Variable_name']), strtolower($this->engine
)) !== 0) {
251 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
253 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
254 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
257 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
258 $mysql_vars[$row['Variable_name']]['type'] = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT
;
261 PMA_DBI_free_result($res);
266 function engine_init() {}
271 * @uses PMA_StorageEngine::getStorageEngines()
272 * @uses PMA_ENGINE_SUPPORT_DEFAULT
273 * @uses PMA_ENGINE_SUPPORT_YES
274 * @uses PMA_ENGINE_SUPPORT_DISABLED
275 * @uses PMA_ENGINE_SUPPORT_NO
276 * @uses $this->engine
278 * @uses $this->comment
279 * @uses $this->support
280 * @param string $engine The engine ID
282 function __construct($engine)
284 $storage_engines = PMA_StorageEngine
::getStorageEngines();
285 if (!empty($storage_engines[$engine])) {
286 $this->engine
= $engine;
287 $this->title
= $storage_engines[$engine]['Engine'];
289 (isset($storage_engines[$engine]['Comment'])
290 ?
$storage_engines[$engine]['Comment']
292 switch ($storage_engines[$engine]['Support']) {
294 $this->support
= PMA_ENGINE_SUPPORT_DEFAULT
;
297 $this->support
= PMA_ENGINE_SUPPORT_YES
;
300 $this->support
= PMA_ENGINE_SUPPORT_DISABLED
;
304 $this->support
= PMA_ENGINE_SUPPORT_NO
;
307 $this->engine_init();
312 * public String getTitle()
314 * Reveals the engine's title
316 * @return string The title
324 * public String getComment()
326 * Fetches the server's comment about this engine
327 * @uses $this->comment
328 * @return string The comment
330 function getComment()
332 return $this->comment
;
336 * public String getSupportInformationMessage()
338 * @uses PMA_ENGINE_SUPPORT_DEFAULT
339 * @uses PMA_ENGINE_SUPPORT_YES
340 * @uses PMA_ENGINE_SUPPORT_DISABLED
341 * @uses PMA_ENGINE_SUPPORT_NO
342 * @uses $this->support
345 * @return string The localized message.
347 function getSupportInformationMessage()
349 switch ($this->support
) {
350 case PMA_ENGINE_SUPPORT_DEFAULT
:
351 $message = __('%s is the default storage engine on this MySQL server.');
353 case PMA_ENGINE_SUPPORT_YES
:
354 $message = __('%s is available on this MySQL server.');
356 case PMA_ENGINE_SUPPORT_DISABLED
:
357 $message = __('%s has been disabled for this MySQL server.');
359 case PMA_ENGINE_SUPPORT_NO
:
361 $message = __('This MySQL server does not support the %s storage engine.');
363 return sprintf($message, htmlspecialchars($this->title
));
367 * public string[][] getVariables()
369 * Generates a list of MySQL variables that provide information about this
370 * engine. This function should be overridden when extending this class
371 * for a particular engine.
374 * @return Array The list of variables.
376 function getVariables()
382 * returns string with filename for the MySQL helppage
383 * about this storage engne
385 * @return string mysql helppage filename
387 function getMysqlHelpPage()
389 return $this->engine
. '-storage-engine';
393 * public string getVariablesLikePattern()
396 * @return string SQL query LIKE pattern
398 function getVariablesLikePattern()
404 * public String[] getInfoPages()
406 * Returns a list of available information pages with labels
409 * @return array The list
411 function getInfoPages()
417 * public String getPage()
419 * Generates the requested information page
422 * @param string $id The page ID
424 * @return string The page
425 * boolean or false on error.
427 function getPage($id)