Simplify config, add config options for disabling parts of the wiki
This commit is contained in:
parent
33f955ad53
commit
11ea8ddaec
94
config.php
94
config.php
|
@ -7,100 +7,40 @@
|
|||
* See LICENSE file for copyright and license details.
|
||||
*/
|
||||
|
||||
// --------------------
|
||||
// Site layout settings
|
||||
// --------------------
|
||||
|
||||
// PAGES_PATH
|
||||
//
|
||||
// The path to the raw text documents maintained by W2
|
||||
// You should not use a trailing slash.
|
||||
|
||||
define('PAGES_PATH', dirname(__FILE__). '/pages');
|
||||
|
||||
// UPLOAD_FOLDER
|
||||
//
|
||||
// The subfolder in PAGES_PATH that uploads get stored to
|
||||
define('UPLOAD_FOLDER', 'images');
|
||||
|
||||
// PAGES_EXT
|
||||
//
|
||||
// The extension of the Markdown files in the PAGES_PATH
|
||||
// folder which are displayed by W2
|
||||
define('PAGES_EXT', 'md');
|
||||
|
||||
|
||||
// BASE_URI
|
||||
//
|
||||
// The base URI for this W2 installation. You only need to change this if we guess wrong.
|
||||
// You should not use a trailing slash.
|
||||
|
||||
define('BASE_URI', str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']));
|
||||
|
||||
// SELF
|
||||
//
|
||||
// The path component of the URL to the main script, such as: /w2/index.php
|
||||
|
||||
define('SELF', $_SERVER['SCRIPT_NAME']);
|
||||
|
||||
// VIEW
|
||||
//
|
||||
// Needed only if your web server spawns PHP as a CGI instead of an internal module.
|
||||
// For example: define('VIEW', '?action=view&page=');
|
||||
|
||||
define('VIEW', '');
|
||||
|
||||
// DEFAULT_PAGE
|
||||
//
|
||||
// The name of the page to show as the "Home" page.
|
||||
// Value is a string, the title of a page (case-sensitive!)
|
||||
define('VIEW', ''); // '?action=view&page='
|
||||
|
||||
define('DEFAULT_PAGE', 'Home');
|
||||
|
||||
// CSS_FILE
|
||||
//
|
||||
// The CSS file to load to style the wiki, relative to BASE_URI
|
||||
define('SIDEBAR_PAGE', 'Sidebar');
|
||||
|
||||
define('CSS_FILE', 'css/index.css');
|
||||
|
||||
// SIDEBAR_FILE
|
||||
//
|
||||
// The name of the page to be shown as sidebar (leave empty to disable sidebar feature)
|
||||
define('PAGE_TITLE', 'spmenu wiki: ');
|
||||
|
||||
define ('SIDEBAR_PAGE', 'Sidebar');
|
||||
define('ENABLE_FAVICON', true);
|
||||
define('ENABLE_TITLE', true);
|
||||
define('ENABLE_CSS', true);
|
||||
define('ENABLE_HEAD', true);
|
||||
define('ENABLE_FOOTER', true);
|
||||
define('ENABLE_TITLEBAR', true);
|
||||
define('ENABLE_TOOLBAR', true);
|
||||
define('ENABLE_SEARCH', true);
|
||||
define('ENABLE_ALL', true);
|
||||
define('ENABLE_HOME_ICON', true);
|
||||
define('ENABLE_ALL_ICON', true);
|
||||
|
||||
// PAGE_TITLE
|
||||
//
|
||||
// A title prepended to the title head tag of all pages of the wiki
|
||||
|
||||
define ('PAGE_TITLE', 'spmenu wiki: ');
|
||||
|
||||
// ------------------
|
||||
// Interface settings
|
||||
// ------------------
|
||||
|
||||
// TITLE_DATE
|
||||
//
|
||||
// The format to use when displaying page modification times.
|
||||
// See the manual for the PHP 'date()' function for the specification:
|
||||
// http://php.net/manual/en/function.date.php
|
||||
// Note that these settings are overridden by the
|
||||
define('META_DESC', true);
|
||||
define('META_ENC', true);
|
||||
define('META_VIEWPORT', true);
|
||||
|
||||
define('TITLE_DATE', 'j M Y g:i A');
|
||||
define('TITLE_DATE_NO_TIME', 'j M Y');
|
||||
|
||||
// -----------------------------
|
||||
// Git Integration
|
||||
// -----------------------------
|
||||
|
||||
// GIT_COMMIT_ENABLED
|
||||
//
|
||||
// Enable/Disable committing changes in page folder to local git repository
|
||||
|
||||
define('GIT_COMMIT_ENABLED', false);
|
||||
|
||||
// GIT_PUSH_ENABLED
|
||||
//
|
||||
// Enable/Disable pushing changes in page folder to a remote git repository
|
||||
|
||||
define('GIT_PUSH_ENABLED', false);
|
||||
|
|
103
index.php
103
index.php
|
@ -39,32 +39,59 @@ function truncate($text, $chars) {
|
|||
function printHeader($title, $action, $html, $bodyclass="")
|
||||
{
|
||||
// TODO: Improve this garbage, I suck at PHP and this is just stuff I found on the internet.
|
||||
$nhtml = $html;
|
||||
$nhtml = preg_replace( '@<p\b[^>]*>(?=.*?<a\b[^>]*>).*?<\@p>@si', '', $nhtml);
|
||||
$nhtml = preg_replace( '@<(li)[^>]*?>.*?</\\1>@si', '', $nhtml);
|
||||
$nhtml = preg_replace( '@<(ul)[^>]*?>.*?</\\1>@si', '', $nhtml);
|
||||
$nhtml = strip_tags($nhtml);
|
||||
$nhtml = preg_replace('/\s*$^\s*/m', "\n", $nhtml);
|
||||
$nhtml = truncate($nhtml, 512);
|
||||
if (META_DESC) {
|
||||
$nhtml = $html;
|
||||
$nhtml = preg_replace( '@<p\b[^>]*>(?=.*?<a\b[^>]*>).*?<\@p>@si', '', $nhtml);
|
||||
$nhtml = preg_replace( '@<(li)[^>]*?>.*?</\\1>@si', '', $nhtml);
|
||||
$nhtml = preg_replace( '@<(ul)[^>]*?>.*?</\\1>@si', '', $nhtml);
|
||||
$nhtml = strip_tags($nhtml);
|
||||
$nhtml = preg_replace('/\s*$^\s*/m', "\n", $nhtml);
|
||||
$nhtml = truncate($nhtml, 512);
|
||||
}
|
||||
|
||||
print "<!doctype html>\n";
|
||||
print "<html lang=\"en\">\n";
|
||||
print " <head>\n";
|
||||
print " <meta charset=\"UTF-8\">\n";
|
||||
print " <meta name=\"description\" content=\"$nhtml\">\n";
|
||||
print " <link rel=\"icon\" href=\"/icons/fav.svg\"/>\n";
|
||||
print " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n";
|
||||
print " <link type=\"text/css\" rel=\"stylesheet\" href=\"" . BASE_URI . "/" . CSS_FILE ."\" />\n";
|
||||
print " <title>".PAGE_TITLE."$title</title>\n";
|
||||
print " </head>\n";
|
||||
|
||||
if (ENABLE_HEAD) {
|
||||
print " <head>\n";
|
||||
|
||||
if (META_ENC) {
|
||||
print " <meta charset=\"UTF-8\">\n";
|
||||
}
|
||||
|
||||
if (META_DESC) {
|
||||
print " <meta name=\"description\" content=\"$nhtml\">\n";
|
||||
}
|
||||
|
||||
if (META_VIEWPORT) {
|
||||
print " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n";
|
||||
}
|
||||
|
||||
if (ENABLE_FAVICON) {
|
||||
print " <link rel=\"icon\" href=\"/icons/fav.svg\"/>\n";
|
||||
}
|
||||
|
||||
if (ENABLE_CSS) {
|
||||
print " <link type=\"text/css\" rel=\"stylesheet\" href=\"" . BASE_URI . "/" . CSS_FILE ."\" />\n";
|
||||
}
|
||||
|
||||
if (ENABLE_TITLE) {
|
||||
print " <title>".PAGE_TITLE."$title</title>\n";
|
||||
}
|
||||
|
||||
print " </head>\n";
|
||||
}
|
||||
|
||||
print " <body".($bodyclass != "" ? " class=\"$bodyclass\"":"").">\n";
|
||||
}
|
||||
|
||||
function printFooter()
|
||||
{
|
||||
print " </body>\n";
|
||||
print "<p class=\"footer\">Wiki licensed under the <a href=\"https://git.speedie.site/speedie/spmenu-wiki/raw/branch/master/LICENSE\">MIT</a> license. Articles and images licensed under the CC-BY-SA 4.0 license. <a href=\"https://git.speedie.site/speedie/spmenu-wiki\">Source code</a></p>";
|
||||
print "</html>";
|
||||
if (ENABLE_FOOTER) {
|
||||
print " </body>\n";
|
||||
print "<p class=\"footer\">Wiki licensed under the <a href=\"https://git.speedie.site/speedie/spmenu-wiki/raw/branch/master/LICENSE\">MIT</a> license. Articles and images licensed under the CC-BY-SA 4.0 license. <a href=\"https://git.speedie.site/speedie/spmenu-wiki\">Source code</a></p>";
|
||||
print "</html>";
|
||||
}
|
||||
}
|
||||
|
||||
// Support functions
|
||||
|
@ -250,7 +277,7 @@ if ($action === 'view')
|
|||
$oldgitmsg = "";
|
||||
$triedSave = false;
|
||||
|
||||
if ( $action === 'all' )
|
||||
if ( $action === 'all' && ENABLE_ALL )
|
||||
{
|
||||
$pageNames = getAllPageNames();
|
||||
$filelist = array();
|
||||
|
@ -292,7 +319,7 @@ if ( $action === 'all' )
|
|||
}
|
||||
$html .= "</tbody></table>\n";
|
||||
}
|
||||
else if ( $action === 'search' )
|
||||
else if ( $action === 'search' && ENABLE_SEARCH )
|
||||
{
|
||||
$matches = 0;
|
||||
$q = $_REQUEST['q'];
|
||||
|
@ -345,11 +372,11 @@ if ( $action === 'all' )
|
|||
|
||||
$datetime = '';
|
||||
|
||||
if ( ($action === 'all'))
|
||||
if ( ($action === 'all') && ENABLE_ALL)
|
||||
{
|
||||
$title = __("All");
|
||||
}
|
||||
else if ( $action === 'search' )
|
||||
else if ( $action === 'search' && ENABLE_SEARCH )
|
||||
{
|
||||
$title = __("Search");
|
||||
}
|
||||
|
@ -370,14 +397,30 @@ if ( $action === 'all' )
|
|||
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
|
||||
printHeader($title, $action, $html);
|
||||
print " <div class=\"titlebar\"><span class=\"title\">$title</span>$datetime";
|
||||
print " </div>\n";
|
||||
print " <div class=\"toolbar\">\n";
|
||||
print " <a href=\"" . SELF . "\"><img src=\"/icons/home.svg\" alt=\"". __(DEFAULT_PAGE) . "\" title=\"". __(DEFAULT_PAGE) . "\" class=\"icon\"></a>\n";
|
||||
print " <a href=\"" . SELF . "?action=all\"><img src=\"/icons/list.svg\" alt=\"". __('All') . "\" title=\"". __('All') . "\" class=\"icon\"></a>\n";
|
||||
print " <form method=\"post\" action=\"" . SELF . "?action=search\">\n";
|
||||
print " <input class=\"search\" placeholder=\"". __('Search') ."\" size=\"20\" id=\"search\" type=\"text\" name=\"q\" />\n </form>\n";
|
||||
print " </div>\n";
|
||||
|
||||
if (ENABLE_TITLEBAR) {
|
||||
print " <div class=\"titlebar\"><span class=\"title\">$title</span>$datetime";
|
||||
print " </div>\n";
|
||||
}
|
||||
|
||||
if (ENABLE_TOOLBAR) {
|
||||
print " <div class=\"toolbar\">\n";
|
||||
|
||||
if (ENABLE_HOME_ICON) {
|
||||
print " <a href=\"" . SELF . "\"><img src=\"/icons/home.svg\" alt=\"". __(DEFAULT_PAGE) . "\" title=\"". __(DEFAULT_PAGE) . "\" class=\"icon\"></a>\n";
|
||||
}
|
||||
|
||||
if (ENABLE_ALL_ICON) {
|
||||
print " <a href=\"" . SELF . "?action=all\"><img src=\"/icons/list.svg\" alt=\"". __('All') . "\" title=\"". __('All') . "\" class=\"icon\"></a>\n";
|
||||
}
|
||||
|
||||
if (ENABLE_SEARCH) {
|
||||
print " <form method=\"post\" action=\"" . SELF . "?action=search\">\n";
|
||||
print " <input class=\"search\" placeholder=\"". __('Search') ."\" size=\"20\" id=\"search\" type=\"text\" name=\"q\" />\n </form>\n";
|
||||
}
|
||||
|
||||
print " </div>\n";
|
||||
}
|
||||
if (SIDEBAR_PAGE != '')
|
||||
{
|
||||
print " <div class=\"sidebar\">\n\n";
|
||||
|
|
Loading…
Reference in a new issue