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
25 class PMA_StorageEngine
28 * @var string engine name
30 var $engine = 'dummy';
33 * @var string engine title/description
35 var $title = 'PMA Dummy Engine Class';
38 * @var string engine lang description
40 var $comment = 'If you read this text inside phpMyAdmin, something went wrong...';
43 * @var integer engine supported by current server
45 var $support = PMA_ENGINE_SUPPORT_NO
;
48 * returns array of storage engines
51 * @staticvar array $storage_engines storage engines
53 * @uses PMA_DBI_fetch_result()
54 * @return array of storage engines
56 static public function getStorageEngines()
58 static $storage_engines = null;
60 if (null !== $storage_engines) {
61 return $storage_engines;
64 return PMA_DBI_fetch_result('SHOW STORAGE ENGINES', 'Engine');
68 * 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')) {
94 // currently (MySQL 5.1.26) there is no way we can be informed
95 // that MyBS does not support normal table creation so
96 // we use an exception here
97 if ('MyBS' == $details['Engine']) {
100 $output .= ' <option value="' . htmlspecialchars($key). '"'
101 . (empty($details['Comment'])
102 ?
'' : ' title="' . htmlspecialchars($details['Comment']) . '"')
103 . (strtolower($key) == $selected ||
(empty($selected) && $details['Support'] == 'DEFAULT')
104 ?
' selected="selected"' : '') . '>' . "\n"
105 . ' ' . htmlspecialchars($details['Engine']) . "\n"
106 . ' </option>' . "\n";
108 $output .= '</select>' . "\n";
113 * public static final PMA_StorageEngine getEngine()
115 * Loads the corresponding engine plugin, if available.
117 * @uses str_replace()
118 * @uses file_exists()
119 * @uses PMA_StorageEngine
120 * @param string $engine The engine ID
121 * @return object The engine plugin
123 static public function getEngine($engine)
125 $engine = str_replace('/', '', str_replace('.', '', $engine));
126 $engine_lowercase_filename = strtolower($engine);
127 if (file_exists('./libraries/engines/' . $engine_lowercase_filename . '.lib.php')
128 && include_once './libraries/engines/' . $engine_lowercase_filename . '.lib.php') {
129 $class_name = 'PMA_StorageEngine_' . $engine;
130 $engine_object = new $class_name($engine);
132 $engine_object = new PMA_StorageEngine($engine);
134 return $engine_object;
138 * return true if given engine name is supported/valid, otherwise false
141 * @uses PMA_StorageEngine::getStorageEngines()
142 * @param string $engine name of engine
143 * @reutrn boolean whether $engine is valid or not
145 static public function isValid($engine)
147 $storage_engines = PMA_StorageEngine
::getStorageEngines();
148 return isset($storage_engines[$engine]);
152 * returns as HTML table of the engine's server variables
154 * @uses PMA_ENGINE_DETAILS_TYPE_SIZE
155 * @uses PMA_ENGINE_DETAILS_TYPE_NUMERIC
156 * @uses PMA_StorageEngine::getVariablesStatus()
157 * @uses $GLOBALS['strNoDetailsForEngine']
158 * @uses PMA_showHint()
159 * @uses PMA_formatByteDown()
160 * @uses PMA_formatNumber()
161 * @uses htmlspecialchars()
162 * @return string The table that was generated based on the retrieved information
164 function getHtmlVariables()
169 foreach ($this->getVariablesStatus() as $details) {
170 $ret .= '<tr class="' . ($odd_row ?
'odd' : 'even') . '">' . "\n"
172 if (!empty($details['desc'])) {
173 $ret .= ' ' . PMA_showHint($details['desc']) . "\n";
175 $ret .= ' </td>' . "\n"
176 . ' <th>' . htmlspecialchars($details['title']) . '</th>' . "\n"
177 . ' <td class="value">';
178 switch ($details['type']) {
179 case PMA_ENGINE_DETAILS_TYPE_SIZE
:
180 $parsed_size = PMA_formatByteDown($details['value']);
181 $ret .= $parsed_size[0] . ' ' . $parsed_size[1];
184 case PMA_ENGINE_DETAILS_TYPE_NUMERIC
:
185 $ret .= PMA_formatNumber($details['value']) . ' ';
188 $ret .= htmlspecialchars($details['value']) . ' ';
190 $ret .= '</td>' . "\n"
192 $odd_row = !$odd_row;
197 . ' ' . $GLOBALS['strNoDetailsForEngine'] . "\n"
200 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
207 * returns array with detailed info about engine specific server variables
209 * @uses PMA_ENGINE_DETAILS_TYPE_PLAINTEXT
210 * @uses PMA_StorageEngine::getVariables()
211 * @uses PMA_StorageEngine::getVariablesLikePattern()
212 * @uses PMA_DBI_query()
213 * @uses PMA_DBI_fetch_assoc()
214 * @uses PMA_DBI_free_result()
215 * @return array with detailed info about specific engine server variables
217 function getVariablesStatus()
219 $variables = $this->getVariables();
220 $like = $this->getVariablesLikePattern();
223 $like = " LIKE '" . $like . "' ";
228 $mysql_vars = array();
230 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
231 $res = PMA_DBI_query($sql_query);
232 while ($row = PMA_DBI_fetch_assoc($res)) {
233 if (isset($variables[$row['Variable_name']])) {
234 $mysql_vars[$row['Variable_name']] = $variables[$row['Variable_name']];
236 && strpos(strtolower($row['Variable_name']), strtolower($this->engine
)) !== 0) {
239 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
241 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
242 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
245 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
246 $mysql_vars[$row['Variable_name']]['type'] = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT
;
249 PMA_DBI_free_result($res);
257 * @uses PMA_StorageEngine::getStorageEngines()
258 * @uses PMA_ENGINE_SUPPORT_DEFAULT
259 * @uses PMA_ENGINE_SUPPORT_YES
260 * @uses PMA_ENGINE_SUPPORT_DISABLED
261 * @uses PMA_ENGINE_SUPPORT_NO
262 * @uses $this->engine
264 * @uses $this->comment
265 * @uses $this->support
266 * @param string $engine The engine ID
268 function __construct($engine)
270 $storage_engines = PMA_StorageEngine
::getStorageEngines();
271 if (!empty($storage_engines[$engine])) {
272 $this->engine
= $engine;
273 $this->title
= $storage_engines[$engine]['Engine'];
275 (isset($storage_engines[$engine]['Comment'])
276 ?
$storage_engines[$engine]['Comment']
278 switch ($storage_engines[$engine]['Support']) {
280 $this->support
= PMA_ENGINE_SUPPORT_DEFAULT
;
283 $this->support
= PMA_ENGINE_SUPPORT_YES
;
286 $this->support
= PMA_ENGINE_SUPPORT_DISABLED
;
290 $this->support
= PMA_ENGINE_SUPPORT_NO
;
296 * public String getTitle()
298 * Reveals the engine's title
300 * @return string The title
308 * public String getComment()
310 * Fetches the server's comment about this engine
311 * @uses $this->comment
312 * @return string The comment
314 function getComment()
316 return $this->comment
;
320 * public String getSupportInformationMessage()
322 * @uses $GLOBALS['strDefaultEngine']
323 * @uses $GLOBALS['strEngineAvailable']
324 * @uses $GLOBALS['strEngineDisabled']
325 * @uses $GLOBALS['strEngineUnsupported']
326 * @uses $GLOBALS['strEngineUnsupported']
327 * @uses PMA_ENGINE_SUPPORT_DEFAULT
328 * @uses PMA_ENGINE_SUPPORT_YES
329 * @uses PMA_ENGINE_SUPPORT_DISABLED
330 * @uses PMA_ENGINE_SUPPORT_NO
331 * @uses $this->support
334 * @return string The localized message.
336 function getSupportInformationMessage()
338 switch ($this->support
) {
339 case PMA_ENGINE_SUPPORT_DEFAULT
:
340 $message = $GLOBALS['strDefaultEngine'];
342 case PMA_ENGINE_SUPPORT_YES
:
343 $message = $GLOBALS['strEngineAvailable'];
345 case PMA_ENGINE_SUPPORT_DISABLED
:
346 $message = $GLOBALS['strEngineDisabled'];
348 case PMA_ENGINE_SUPPORT_NO
:
350 $message = $GLOBALS['strEngineUnsupported'];
352 return sprintf($message, htmlspecialchars($this->title
));
356 * public string[][] getVariables()
358 * Generates a list of MySQL variables that provide information about this
359 * engine. This function should be overridden when extending this class
360 * for a particular engine.
363 * @return Array The list of variables.
365 function getVariables()
371 * returns string with filename for the MySQL helppage
372 * about this storage engne
374 * @return string mysql helppage filename
376 function getMysqlHelpPage()
378 return $this->engine
. '-storage-engine';
382 * public string getVariablesLikePattern()
385 * @return string SQL query LIKE pattern
387 function getVariablesLikePattern()
393 * public String[] getInfoPages()
395 * Returns a list of available information pages with labels
398 * @return array The list
400 function getInfoPages()
406 * public String getPage()
408 * Generates the requested information page
411 * @param string $id The page ID
413 * @return string The page
414 * boolean or false on error.
416 function getPage($id)