Translation update done using Pootle.
[phpmyadmin-themes.git] / libraries / StorageEngine.class.php
blob71b363625c846da7a410b984e6e762d3c5024a0f
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Library for extracting information about the available storage engines
6 * @package phpMyAdmin
7 */
9 /**
10 * defines
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'
22 /**
23 * base Storage Engine Class
24 * @package phpMyAdmin
26 class PMA_StorageEngine
28 /**
29 * @var string engine name
31 var $engine = 'dummy';
33 /**
34 * @var string engine title/description
36 var $title = 'PMA Dummy Engine Class';
38 /**
39 * @var string engine lang description
41 var $comment = 'If you read this text inside phpMyAdmin, something went wrong...';
43 /**
44 * @var integer engine supported by current server
46 var $support = PMA_ENGINE_SUPPORT_NO;
48 /**
49 * returns array of storage engines
51 * @static
52 * @staticvar array $storage_engines storage engines
53 * @access public
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');
68 /**
69 * returns HTML code for storage engine select box
71 * @static
72 * @uses PMA_StorageEngine::getStorageEngines()
73 * @uses strtolower()
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')) {
92 continue;
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";
104 return $output;
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);
126 } else {
127 $engine_object = new PMA_StorageEngine($engine);
129 return $engine_object;
133 * return true if given engine name is supported/valid, otherwise false
135 * @static
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") {
143 return TRUE;
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()
163 $odd_row = false;
164 $ret = '';
166 foreach ($this->getVariablesStatus() as $details) {
167 $ret .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
168 . ' <td>' . "\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] . '&nbsp;' . $parsed_size[1];
179 unset($parsed_size);
180 break;
181 case PMA_ENGINE_DETAILS_TYPE_NUMERIC:
182 $ret .= PMA_formatNumber($details['value']) . ' ';
183 break;
184 default:
185 $ret .= htmlspecialchars($details['value']) . ' ';
187 $ret .= '</td>' . "\n"
188 . '</tr>' . "\n";
189 $odd_row = !$odd_row;
192 if (! $ret) {
193 $ret = '<p>' . "\n"
194 . ' ' . __('There is no detailed status information available for this storage engine.') . "\n"
195 . '</p>' . "\n";
196 } else {
197 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
200 return $ret;
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();
234 if ($like) {
235 $like = " LIKE '" . $like . "' ";
236 } else {
237 $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']];
247 } elseif (! $like
248 && strpos(strtolower($row['Variable_name']), strtolower($this->engine)) !== 0) {
249 continue;
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);
263 return $mysql_vars;
266 function engine_init() {}
269 * Constructor
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
277 * @uses $this->title
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'];
288 $this->comment =
289 (isset($storage_engines[$engine]['Comment'])
290 ? $storage_engines[$engine]['Comment']
291 : '');
292 switch ($storage_engines[$engine]['Support']) {
293 case 'DEFAULT':
294 $this->support = PMA_ENGINE_SUPPORT_DEFAULT;
295 break;
296 case 'YES':
297 $this->support = PMA_ENGINE_SUPPORT_YES;
298 break;
299 case 'DISABLED':
300 $this->support = PMA_ENGINE_SUPPORT_DISABLED;
301 break;
302 case 'NO':
303 default:
304 $this->support = PMA_ENGINE_SUPPORT_NO;
306 } else {
307 $this->engine_init();
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 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
343 * @uses $this->title
344 * @uses sprintf
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.');
352 break;
353 case PMA_ENGINE_SUPPORT_YES:
354 $message = __('%s is available on this MySQL server.');
355 break;
356 case PMA_ENGINE_SUPPORT_DISABLED:
357 $message = __('%s has been disabled for this MySQL server.');
358 break;
359 case PMA_ENGINE_SUPPORT_NO:
360 default:
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.
373 * @abstract
374 * @return Array The list of variables.
376 function getVariables()
378 return array();
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()
395 * @abstract
396 * @return string SQL query LIKE pattern
398 function getVariablesLikePattern()
400 return false;
404 * public String[] getInfoPages()
406 * Returns a list of available information pages with labels
408 * @abstract
409 * @return array The list
411 function getInfoPages()
413 return array();
417 * public String getPage()
419 * Generates the requested information page
421 * @abstract
422 * @param string $id The page ID
424 * @return string The page
425 * boolean or false on error.
427 function getPage($id)
429 return false;