2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Library for extracting information about the available storage engines
13 define('PMA_ENGINE_SUPPORT_NO', 0);
14 define('PMA_ENGINE_SUPPORT_DISABLED', 1);
15 define('PMA_ENGINE_SUPPORT_YES', 2);
16 define('PMA_ENGINE_SUPPORT_DEFAULT', 3);
18 define('PMA_ENGINE_DETAILS_TYPE_PLAINTEXT', 0);
19 define('PMA_ENGINE_DETAILS_TYPE_SIZE', 1);
20 define('PMA_ENGINE_DETAILS_TYPE_NUMERIC', 2); //Has no effect yet...
21 define('PMA_ENGINE_DETAILS_TYPE_BOOLEAN', 3); // 'ON' or 'OFF'
24 * base Storage Engine Class
27 class PMA_StorageEngine
30 * @var string engine name
32 var $engine = 'dummy';
35 * @var string engine title/description
37 var $title = 'PMA Dummy Engine Class';
40 * @var string engine lang description
42 var $comment = 'If you read this text inside phpMyAdmin, something went wrong...';
45 * @var integer engine supported by current server
47 var $support = PMA_ENGINE_SUPPORT_NO
;
50 * returns array of storage engines
53 * @staticvar array $storage_engines storage engines
55 * @uses PMA_DBI_fetch_result()
56 * @return array of storage engines
58 static public function getStorageEngines()
60 static $storage_engines = null;
62 if (null !== $storage_engines) {
63 return $storage_engines;
66 return PMA_DBI_fetch_result('SHOW STORAGE ENGINES', 'Engine');
70 * returns HTML code for storage engine select box
74 * @uses PMA_StorageEngine::getStorageEngines()
76 * @uses htmlspecialchars()
77 * @param string $name The name of the select form element
78 * @param string $id The ID of the form field
79 * @param string $selected The selected engine
80 * @param boolean $offerUnavailableEngines
81 * Should unavailable storage engines be offered?
82 * @return string html selectbox
84 static public function getHtmlSelect($name = 'engine', $id = null,
85 $selected = null, $offerUnavailableEngines = false)
87 $selected = strtolower($selected);
88 $output = '<select name="' . $name . '"'
89 . (empty($id) ?
'' : ' id="' . $id . '"') . '>' . "\n";
91 foreach (PMA_StorageEngine
::getStorageEngines() as $key => $details) {
92 if (!$offerUnavailableEngines
93 && ($details['Support'] == 'NO' ||
$details['Support'] == 'DISABLED')) {
96 // currently (MySQL 5.1.26) there is no way we can be informed
97 // that PBMS does not support normal table creation so
98 // we use an exception here
99 if ('PBMS' == $details['Engine']) {
102 $output .= ' <option value="' . htmlspecialchars($key). '"'
103 . (empty($details['Comment'])
104 ?
'' : ' title="' . htmlspecialchars($details['Comment']) . '"')
105 . (strtolower($key) == $selected ||
(empty($selected) && $details['Support'] == 'DEFAULT')
106 ?
' selected="selected"' : '') . '>' . "\n"
107 . ' ' . htmlspecialchars($details['Engine']) . "\n"
108 . ' </option>' . "\n";
110 $output .= '</select>' . "\n";
115 * public static final PMA_StorageEngine getEngine()
117 * Loads the corresponding engine plugin, if available.
119 * @uses str_replace()
120 * @uses file_exists()
121 * @uses PMA_StorageEngine
122 * @param string $engine The engine ID
123 * @return object The engine plugin
125 static public function getEngine($engine)
127 $engine = str_replace('/', '', str_replace('.', '', $engine));
128 $engine_lowercase_filename = strtolower($engine);
129 if (file_exists('./libraries/engines/' . $engine_lowercase_filename . '.lib.php')
130 && include_once './libraries/engines/' . $engine_lowercase_filename . '.lib.php') {
131 $class_name = 'PMA_StorageEngine_' . $engine;
132 $engine_object = new $class_name($engine);
134 $engine_object = new PMA_StorageEngine($engine);
136 return $engine_object;
140 * return true if given engine name is supported/valid, otherwise false
143 * @uses PMA_StorageEngine::getStorageEngines()
144 * @param string $engine name of engine
145 * @return boolean whether $engine is valid or not
147 static public function isValid($engine)
149 $storage_engines = PMA_StorageEngine
::getStorageEngines();
150 return isset($storage_engines[$engine]);
154 * returns as HTML table of the engine's server variables
156 * @uses PMA_ENGINE_DETAILS_TYPE_SIZE
157 * @uses PMA_ENGINE_DETAILS_TYPE_NUMERIC
158 * @uses PMA_StorageEngine::getVariablesStatus()
159 * @uses $GLOBALS['strNoDetailsForEngine']
160 * @uses PMA_showHint()
161 * @uses PMA_formatByteDown()
162 * @uses PMA_formatNumber()
163 * @uses htmlspecialchars()
164 * @return string The table that was generated based on the retrieved information
166 function getHtmlVariables()
171 foreach ($this->getVariablesStatus() as $details) {
172 $ret .= '<tr class="' . ($odd_row ?
'odd' : 'even') . '">' . "\n"
174 if (!empty($details['desc'])) {
175 $ret .= ' ' . PMA_showHint($details['desc']) . "\n";
177 $ret .= ' </td>' . "\n"
178 . ' <th>' . htmlspecialchars($details['title']) . '</th>' . "\n"
179 . ' <td class="value">';
180 switch ($details['type']) {
181 case PMA_ENGINE_DETAILS_TYPE_SIZE
:
182 $parsed_size = PMA_formatByteDown($details['value']);
183 $ret .= $parsed_size[0] . ' ' . $parsed_size[1];
186 case PMA_ENGINE_DETAILS_TYPE_NUMERIC
:
187 $ret .= PMA_formatNumber($details['value']) . ' ';
190 $ret .= htmlspecialchars($details['value']) . ' ';
192 $ret .= '</td>' . "\n"
194 $odd_row = !$odd_row;
199 . ' ' . $GLOBALS['strNoDetailsForEngine'] . "\n"
202 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
209 * returns array with detailed info about engine specific server variables
211 * @uses PMA_ENGINE_DETAILS_TYPE_PLAINTEXT
212 * @uses PMA_StorageEngine::getVariables()
213 * @uses PMA_StorageEngine::getVariablesLikePattern()
214 * @uses PMA_DBI_query()
215 * @uses PMA_DBI_fetch_assoc()
216 * @uses PMA_DBI_free_result()
217 * @return array with detailed info about specific engine server variables
219 function getVariablesStatus()
221 $variables = $this->getVariables();
222 $like = $this->getVariablesLikePattern();
225 $like = " LIKE '" . $like . "' ";
230 $mysql_vars = array();
232 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
233 $res = PMA_DBI_query($sql_query);
234 while ($row = PMA_DBI_fetch_assoc($res)) {
235 if (isset($variables[$row['Variable_name']])) {
236 $mysql_vars[$row['Variable_name']] = $variables[$row['Variable_name']];
238 && strpos(strtolower($row['Variable_name']), strtolower($this->engine
)) !== 0) {
241 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
243 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
244 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
247 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
248 $mysql_vars[$row['Variable_name']]['type'] = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT
;
251 PMA_DBI_free_result($res);
259 * @uses PMA_StorageEngine::getStorageEngines()
260 * @uses PMA_ENGINE_SUPPORT_DEFAULT
261 * @uses PMA_ENGINE_SUPPORT_YES
262 * @uses PMA_ENGINE_SUPPORT_DISABLED
263 * @uses PMA_ENGINE_SUPPORT_NO
264 * @uses $this->engine
266 * @uses $this->comment
267 * @uses $this->support
268 * @param string $engine The engine ID
270 function __construct($engine)
272 $storage_engines = PMA_StorageEngine
::getStorageEngines();
273 if (!empty($storage_engines[$engine])) {
274 $this->engine
= $engine;
275 $this->title
= $storage_engines[$engine]['Engine'];
277 (isset($storage_engines[$engine]['Comment'])
278 ?
$storage_engines[$engine]['Comment']
280 switch ($storage_engines[$engine]['Support']) {
282 $this->support
= PMA_ENGINE_SUPPORT_DEFAULT
;
285 $this->support
= PMA_ENGINE_SUPPORT_YES
;
288 $this->support
= PMA_ENGINE_SUPPORT_DISABLED
;
292 $this->support
= PMA_ENGINE_SUPPORT_NO
;
298 * public String getTitle()
300 * Reveals the engine's title
302 * @return string The title
310 * public String getComment()
312 * Fetches the server's comment about this engine
313 * @uses $this->comment
314 * @return string The comment
316 function getComment()
318 return $this->comment
;
322 * public String getSupportInformationMessage()
324 * @uses $GLOBALS['strDefaultEngine']
325 * @uses $GLOBALS['strEngineAvailable']
326 * @uses $GLOBALS['strEngineDisabled']
327 * @uses $GLOBALS['strEngineUnsupported']
328 * @uses $GLOBALS['strEngineUnsupported']
329 * @uses PMA_ENGINE_SUPPORT_DEFAULT
330 * @uses PMA_ENGINE_SUPPORT_YES
331 * @uses PMA_ENGINE_SUPPORT_DISABLED
332 * @uses PMA_ENGINE_SUPPORT_NO
333 * @uses $this->support
336 * @return string The localized message.
338 function getSupportInformationMessage()
340 switch ($this->support
) {
341 case PMA_ENGINE_SUPPORT_DEFAULT
:
342 $message = $GLOBALS['strDefaultEngine'];
344 case PMA_ENGINE_SUPPORT_YES
:
345 $message = $GLOBALS['strEngineAvailable'];
347 case PMA_ENGINE_SUPPORT_DISABLED
:
348 $message = $GLOBALS['strEngineDisabled'];
350 case PMA_ENGINE_SUPPORT_NO
:
352 $message = $GLOBALS['strEngineUnsupported'];
354 return sprintf($message, htmlspecialchars($this->title
));
358 * public string[][] getVariables()
360 * Generates a list of MySQL variables that provide information about this
361 * engine. This function should be overridden when extending this class
362 * for a particular engine.
365 * @return Array The list of variables.
367 function getVariables()
373 * returns string with filename for the MySQL helppage
374 * about this storage engne
376 * @return string mysql helppage filename
378 function getMysqlHelpPage()
380 return $this->engine
. '-storage-engine';
384 * public string getVariablesLikePattern()
387 * @return string SQL query LIKE pattern
389 function getVariablesLikePattern()
395 * public String[] getInfoPages()
397 * Returns a list of available information pages with labels
400 * @return array The list
402 function getInfoPages()
408 * public String getPage()
410 * Generates the requested information page
413 * @param string $id The page ID
415 * @return string The page
416 * boolean or false on error.
418 function getPage($id)