-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathMySQLDocumentation.php
More file actions
114 lines (102 loc) · 3.42 KB
/
MySQLDocumentation.php
File metadata and controls
114 lines (102 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* Generate HTML for MySQL Documentation
*/
declare(strict_types=1);
namespace PhpMyAdmin\Html;
use PhpMyAdmin\Core;
use PhpMyAdmin\Util;
use Twig\Attribute\AsTwigFunction;
use function __;
use function defined;
use function file_exists;
use function htmlspecialchars;
/**
* Generate HTML for MySQL Documentation
*/
class MySQLDocumentation
{
/**
* Displays a link to the official MySQL documentation
*
* @param string $link contains name of page/anchor that is being linked
* @param bool $bigIcon whether to use big icon (like in left frame)
* @param string|null $url href attribute
* @param string|null $text text of link
* @param string $anchor anchor to page part
*
* @return string the html link
*/
#[AsTwigFunction('show_mysql_docu', isSafe: ['html'])]
public static function show(
string $link,
bool $bigIcon = false,
string|null $url = null,
string|null $text = null,
string $anchor = '',
): string {
if ($url === null) {
$url = Util::getMySQLDocuURL($link, $anchor);
}
$openLink = '<a href="' . htmlspecialchars($url) . '" target="mysql_doc">';
$closeLink = '</a>';
if ($bigIcon) {
$html = $openLink . Generator::getImage('b_sqlhelp', __('Documentation')) . $closeLink;
} elseif ($text !== null) {
$html = $openLink . $text . $closeLink;
} else {
$html = Generator::showDocumentationLink($url, 'mysql_doc');
}
return $html;
}
/**
* Displays a link to the phpMyAdmin documentation
*
* @param string $page Page in documentation
* @param string $anchor Optional anchor in page
* @param bool $bbcode Optional flag indicating whether to output bbcode
* @param bool $disableTabIndex Optional flag indicating that a negative tabindex should be set on the link
*
* @return string the html link
*/
#[AsTwigFunction('show_docu', isSafe: ['html'])]
public static function showDocumentation(
string $page,
string $anchor = '',
bool $bbcode = false,
bool $disableTabIndex = false,
): string {
return Generator::showDocumentationLink(
self::getDocumentationLink($page, $anchor),
'documentation',
$bbcode,
$disableTabIndex,
);
}
/**
* Returns link to documentation.
*
* @param string $page Page in documentation
* @param string $anchor Optional anchor in page
* @param string $pathPrefix Optional path in case it is called in a folder (e.g. setup)
*
* @return string URL
*/
#[AsTwigFunction('get_docu_link', isSafe: ['html'])]
public static function getDocumentationLink(string $page, string $anchor = '', string $pathPrefix = './'): string
{
/* Construct base URL */
$url = $page . '.html';
if ($anchor !== '') {
$url .= '#' . $anchor;
}
/**
* Check if we have built local documentation, however
* provide consistent URL for testsuite
*/
if (! defined('TESTSUITE') && @file_exists(ROOT_PATH . 'docs/html/index.html')) {
return $pathPrefix . 'docs/html/' . $url;
}
return Core::linkURL('https://docs.phpmyadmin.net/en/latest/' . $url);
}
}