Translation update done using Pootle.
[phpmyadmin/dkf.git] / libraries / StorageEngine.class.php
blob711f709e1b76727ab7c7f2d679e12d73339a117e
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Library for extracting information about the available storage engines
6 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
11 * defines
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'
23 /**
24 * base Storage Engine Class
25 * @package phpMyAdmin
27 class PMA_StorageEngine
29 /**
30 * @var string engine name
32 var $engine = 'dummy';
34 /**
35 * @var string engine title/description
37 var $title = 'PMA Dummy Engine Class';
39 /**
40 * @var string engine lang description
42 var $comment = 'If you read this text inside phpMyAdmin, something went wrong...';
44 /**
45 * @var integer engine supported by current server
47 var $support = PMA_ENGINE_SUPPORT_NO;
49 /**
50 * returns array of storage engines
52 * @static
53 * @staticvar array $storage_engines storage engines
54 * @access public
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');
69 /**
70 * returns HTML code for storage engine select box
72 * @static
73 * @uses PMA_StorageEngine::getStorageEngines()
74 * @uses strtolower()
75 * @uses htmlspecialchars()
76 * @param string $name The name of the select form element
77 * @param string $id The ID of the form field
78 * @param string $selected The selected engine
79 * @param boolean $offerUnavailableEngines
80 * Should unavailable storage engines be offered?
81 * @return string html selectbox
83 static public function getHtmlSelect($name = 'engine', $id = null,
84 $selected = null, $offerUnavailableEngines = false)
86 $selected = strtolower($selected);
87 $output = '<select name="' . $name . '"'
88 . (empty($id) ? '' : ' id="' . $id . '"') . '>' . "\n";
90 foreach (PMA_StorageEngine::getStorageEngines() as $key => $details) {
91 if (!$offerUnavailableEngines
92 && ($details['Support'] == 'NO' || $details['Support'] == 'DISABLED')) {
93 continue;
95 // currently (MySQL 5.1.26) there is no way we can be informed
96 // that PBMS does not support normal table creation so
97 // we use an exception here
98 if ('PBMS' == $details['Engine']) {
99 continue;
101 $output .= ' <option value="' . htmlspecialchars($key). '"'
102 . (empty($details['Comment'])
103 ? '' : ' title="' . htmlspecialchars($details['Comment']) . '"')
104 . (strtolower($key) == $selected || (empty($selected) && $details['Support'] == 'DEFAULT')
105 ? ' selected="selected"' : '') . '>' . "\n"
106 . ' ' . htmlspecialchars($details['Engine']) . "\n"
107 . ' </option>' . "\n";
109 $output .= '</select>' . "\n";
110 return $output;
114 * public static final PMA_StorageEngine getEngine()
116 * Loads the corresponding engine plugin, if available.
118 * @uses str_replace()
119 * @uses file_exists()
120 * @uses PMA_StorageEngine
121 * @param string $engine The engine ID
122 * @return object The engine plugin
124 static public function getEngine($engine)
126 $engine = str_replace('/', '', str_replace('.', '', $engine));
127 $engine_lowercase_filename = strtolower($engine);
128 if (file_exists('./libraries/engines/' . $engine_lowercase_filename . '.lib.php')
129 && include_once './libraries/engines/' . $engine_lowercase_filename . '.lib.php') {
130 $class_name = 'PMA_StorageEngine_' . $engine;
131 $engine_object = new $class_name($engine);
132 } else {
133 $engine_object = new PMA_StorageEngine($engine);
135 return $engine_object;
139 * return true if given engine name is supported/valid, otherwise false
141 * @static
142 * @uses PMA_StorageEngine::getStorageEngines()
143 * @param string $engine name of engine
144 * @return boolean whether $engine is valid or not
146 static public function isValid($engine)
148 $storage_engines = PMA_StorageEngine::getStorageEngines();
149 return isset($storage_engines[$engine]);
153 * returns as HTML table of the engine's server variables
155 * @uses PMA_ENGINE_DETAILS_TYPE_SIZE
156 * @uses PMA_ENGINE_DETAILS_TYPE_NUMERIC
157 * @uses PMA_StorageEngine::getVariablesStatus()
158 * @uses __('There is no detailed status information available for this storage engine.')
159 * @uses PMA_showHint()
160 * @uses PMA_formatByteDown()
161 * @uses PMA_formatNumber()
162 * @uses htmlspecialchars()
163 * @return string The table that was generated based on the retrieved information
165 function getHtmlVariables()
167 $odd_row = false;
168 $ret = '';
170 foreach ($this->getVariablesStatus() as $details) {
171 $ret .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
172 . ' <td>' . "\n";
173 if (!empty($details['desc'])) {
174 $ret .= ' ' . PMA_showHint($details['desc']) . "\n";
176 $ret .= ' </td>' . "\n"
177 . ' <th>' . htmlspecialchars($details['title']) . '</th>' . "\n"
178 . ' <td class="value">';
179 switch ($details['type']) {
180 case PMA_ENGINE_DETAILS_TYPE_SIZE:
181 $parsed_size = $this->resolveTypeSize($details['value']);
182 $ret .= $parsed_size[0] . '&nbsp;' . $parsed_size[1];
183 unset($parsed_size);
184 break;
185 case PMA_ENGINE_DETAILS_TYPE_NUMERIC:
186 $ret .= PMA_formatNumber($details['value']) . ' ';
187 break;
188 default:
189 $ret .= htmlspecialchars($details['value']) . ' ';
191 $ret .= '</td>' . "\n"
192 . '</tr>' . "\n";
193 $odd_row = !$odd_row;
196 if (! $ret) {
197 $ret = '<p>' . "\n"
198 . ' ' . __('There is no detailed status information available for this storage engine.') . "\n"
199 . '</p>' . "\n";
200 } else {
201 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
204 return $ret;
208 * returns the engine specific handling for
209 * PMA_ENGINE_DETAILS_TYPE_SIZE type variables.
211 * This function should be overridden when
212 * PMA_ENGINE_DETAILS_TYPE_SIZE type needs to be
213 * handled differently for a particular engine.
215 * @return string the formatted value and its unit
217 function resolveTypeSize($value)
219 return PMA_formatByteDown($value);
223 * returns array with detailed info about engine specific server variables
225 * @uses PMA_ENGINE_DETAILS_TYPE_PLAINTEXT
226 * @uses PMA_StorageEngine::getVariables()
227 * @uses PMA_StorageEngine::getVariablesLikePattern()
228 * @uses PMA_DBI_query()
229 * @uses PMA_DBI_fetch_assoc()
230 * @uses PMA_DBI_free_result()
231 * @return array with detailed info about specific engine server variables
233 function getVariablesStatus()
235 $variables = $this->getVariables();
236 $like = $this->getVariablesLikePattern();
238 if ($like) {
239 $like = " LIKE '" . $like . "' ";
240 } else {
241 $like = '';
244 $mysql_vars = array();
246 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
247 $res = PMA_DBI_query($sql_query);
248 while ($row = PMA_DBI_fetch_assoc($res)) {
249 if (isset($variables[$row['Variable_name']])) {
250 $mysql_vars[$row['Variable_name']] = $variables[$row['Variable_name']];
251 } elseif (! $like
252 && strpos(strtolower($row['Variable_name']), strtolower($this->engine)) !== 0) {
253 continue;
255 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
257 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
258 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
261 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
262 $mysql_vars[$row['Variable_name']]['type'] = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT;
265 PMA_DBI_free_result($res);
267 return $mysql_vars;
271 * Constructor
273 * @uses PMA_StorageEngine::getStorageEngines()
274 * @uses PMA_ENGINE_SUPPORT_DEFAULT
275 * @uses PMA_ENGINE_SUPPORT_YES
276 * @uses PMA_ENGINE_SUPPORT_DISABLED
277 * @uses PMA_ENGINE_SUPPORT_NO
278 * @uses $this->engine
279 * @uses $this->title
280 * @uses $this->comment
281 * @uses $this->support
282 * @param string $engine The engine ID
284 function __construct($engine)
286 $storage_engines = PMA_StorageEngine::getStorageEngines();
287 if (!empty($storage_engines[$engine])) {
288 $this->engine = $engine;
289 $this->title = $storage_engines[$engine]['Engine'];
290 $this->comment =
291 (isset($storage_engines[$engine]['Comment'])
292 ? $storage_engines[$engine]['Comment']
293 : '');
294 switch ($storage_engines[$engine]['Support']) {
295 case 'DEFAULT':
296 $this->support = PMA_ENGINE_SUPPORT_DEFAULT;
297 break;
298 case 'YES':
299 $this->support = PMA_ENGINE_SUPPORT_YES;
300 break;
301 case 'DISABLED':
302 $this->support = PMA_ENGINE_SUPPORT_DISABLED;
303 break;
304 case 'NO':
305 default:
306 $this->support = PMA_ENGINE_SUPPORT_NO;
312 * public String getTitle()
314 * Reveals the engine's title
315 * @uses $this->title
316 * @return string The title
318 function getTitle()
320 return $this->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 __('%s is the default storage engine on this MySQL server.')
339 * @uses __('%s is available on this MySQL server.')
340 * @uses __('%s has been disabled for this MySQL server.')
341 * @uses __('This MySQL server does not support the %s storage engine.')
342 * @uses __('This MySQL server does not support the %s storage engine.')
343 * @uses PMA_ENGINE_SUPPORT_DEFAULT
344 * @uses PMA_ENGINE_SUPPORT_YES
345 * @uses PMA_ENGINE_SUPPORT_DISABLED
346 * @uses PMA_ENGINE_SUPPORT_NO
347 * @uses $this->support
348 * @uses $this->title
349 * @uses sprintf
350 * @return string The localized message.
352 function getSupportInformationMessage()
354 switch ($this->support) {
355 case PMA_ENGINE_SUPPORT_DEFAULT:
356 $message = __('%s is the default storage engine on this MySQL server.');
357 break;
358 case PMA_ENGINE_SUPPORT_YES:
359 $message = __('%s is available on this MySQL server.');
360 break;
361 case PMA_ENGINE_SUPPORT_DISABLED:
362 $message = __('%s has been disabled for this MySQL server.');
363 break;
364 case PMA_ENGINE_SUPPORT_NO:
365 default:
366 $message = __('This MySQL server does not support the %s storage engine.');
368 return sprintf($message, htmlspecialchars($this->title));
372 * public string[][] getVariables()
374 * Generates a list of MySQL variables that provide information about this
375 * engine. This function should be overridden when extending this class
376 * for a particular engine.
378 * @abstract
379 * @return Array The list of variables.
381 function getVariables()
383 return array();
387 * returns string with filename for the MySQL helppage
388 * about this storage engne
390 * @return string mysql helppage filename
392 function getMysqlHelpPage()
394 return $this->engine . '-storage-engine';
398 * public string getVariablesLikePattern()
400 * @abstract
401 * @return string SQL query LIKE pattern
403 function getVariablesLikePattern()
405 return false;
409 * public String[] getInfoPages()
411 * Returns a list of available information pages with labels
413 * @abstract
414 * @return array The list
416 function getInfoPages()
418 return array();
422 * public String getPage()
424 * Generates the requested information page
426 * @abstract
427 * @param string $id The page ID
429 * @return string The page
430 * boolean or false on error.
432 function getPage($id)
434 return false;