Commit 7b2262f8 by Scott

Add caching admin options, basic setup checks

parent ba7a0523
......@@ -86,6 +86,15 @@
*/
/*
If you wish to use caching, you must define QA_CACHE_DIRECTORY to store the cache files. The
directory must be writable by the web server. It also must be OUTSIDE the public root. For
example if your site resides in '/var/www/yoursite/public_html', then the cache directory could
be '/var/www/yoursite/qa-cache', but it cannot be '/var/www/yoursite/public_html/qa-cache'.
define('QA_CACHE_DIRECTORY', '/path/to/writable_cache_directory/');
*/
/*
If you wish, you can define QA_COOKIE_DOMAIN so that any cookies created by Q2A are assigned
to a specific domain name, instead of the full domain name of the request by default. This is
useful if you're running multiple Q2A sites on subdomains with a shared user base.
......
<?php
/*
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
File: qa-include/Q2A/Storage/CacheManager.php
Description: Handler for caching system.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
More about this license: http://www.question2answer.org/license.php
*/
/**
* Caches data (typically from database queries) to the filesystem.
*/
class Q2A_Storage_CacheManager
{
private $enabled = false;
private $error = '';
private $dir;
/**
* Creates a new CacheManager instance and checks it's set up properly.
*/
public function __construct()
{
$optEnabled = qa_opt('caching_enabled') == 1;
if (defined('QA_CACHE_DIRECTORY')) {
// expand symlinks so we compare true paths
$this->dir = realpath(QA_CACHE_DIRECTORY);
$baseDir = realpath(QA_BASE_DIR);
if (!is_writable($this->dir)) {
$this->error = qa_lang_html_sub('admin/caching_dir_error', QA_CACHE_DIRECTORY);
} elseif (strpos($this->dir, $baseDir) === 0) {
$this->error = qa_lang_html_sub('admin/caching_dir_public', QA_CACHE_DIRECTORY);
}
$this->enabled = empty($this->error) && $optEnabled;
} elseif ($optEnabled) {
$this->error = qa_lang_html('admin/caching_dir_missing');
}
}
/**
* Whether caching is available.
* @return bool
*/
public function isEnabled()
{
return $this->enabled;
}
/**
* Get the last error.
* @return string
*/
public function getError()
{
return $this->error;
}
}
......@@ -341,6 +341,11 @@
'url' => qa_path_html('admin/spam'),
);
$navigation['admin/caching']=array(
'label' => qa_lang_html('admin/caching_title'),
'url' => qa_path_html('admin/caching'),
);
$navigation['admin/stats']=array(
'label' => qa_lang_html('admin/stats_title'),
'url' => qa_path_html('admin/stats'),
......
......@@ -213,6 +213,9 @@
'avatar_q_page_q_size' => 50,
'avatar_store_size' => 400,
'avatar_users_size' => 30,
'caching_enabled' => 0,
'caching_q_time' => 5,
'caching_qlist_time' => 5,
'captcha_on_anon_post' => 1,
'captcha_on_feedback' => 1,
'captcha_on_register' => 1,
......
......@@ -53,6 +53,10 @@
'block_ips_note' => 'Use a hyphen for ranges or * to match any number. Examples: 192.168.0.4 , 192.168.0.0-192.168.0.31 , 192.168.0.*',
'block_user_popup' => 'Block user',
'block_words_note' => 'Use a * to match any letters. Examples: doh (will only match exact word doh) , doh* (will match doh or dohno) , do*h (will match doh, dooh, dough).',
'caching_dir_missing' => 'Cache directory has not been defined.',
'caching_dir_error' => 'The directory ^ defined as QA_CACHE_DIRECTORY is not writable by the web server.',
'caching_dir_public' => 'The directory ^ defined as QA_CACHE_DIRECTORY must be outside the public root.',
'caching_title' => 'Caching',
'cancel_mailing_button' => 'Cancel Mailing',
'categories' => 'Categories',
'categories_introduction' => 'To get started with categories, click the \'Add Category\' button.',
......
......@@ -45,6 +45,9 @@
'avatar_users_size' => 'Avatar size on top users page:',
'block_bad_words' => 'Censored words - separate by spaces or commas:',
'block_ips_write' => 'Blocked IP addresses - separate by spaces or commas:',
'caching_enabled' => 'Enable caching:',
'caching_q_time' => 'Cache question pages for:',
'caching_qlist_time' => 'Cache question lists for:',
'captcha_module' => 'Use captcha module:',
'captcha_on_anon_post' => 'Use captcha for anonymous posts:',
'captcha_on_feedback' => 'Use captcha on feedback form:',
......
......@@ -32,6 +32,8 @@
require_once QA_INCLUDE_DIR.'app/admin.php';
// Pages handled by this controller: general, emails, users, layout, viewing, lists, posting, permissions, feeds, spam, caching, mailing
$adminsection = strtolower(qa_request_part(1));
......@@ -71,6 +73,8 @@
'avatar_q_page_q_size' => 'number',
'avatar_store_size' => 'number',
'avatar_users_size' => 'number',
'caching_q_time' => 'number',
'caching_qlist_time' => 'number',
'columns_tags' => 'number',
'columns_users' => 'number',
'feed_number_items' => 'number',
......@@ -143,6 +147,7 @@
'avatar_allow_gravatar' => 'checkbox',
'avatar_allow_upload' => 'checkbox',
'avatar_default_show' => 'checkbox',
'caching_enabled' => 'checkbox',
'captcha_on_anon_post' => 'checkbox',
'captcha_on_feedback' => 'checkbox',
'captcha_on_register' => 'checkbox',
......@@ -636,6 +641,19 @@
$checkboxtodisplay['moderate_update_time'] = $checkboxtodisplay['moderate_edited_again'];
break;
case 'caching':
$subtitle = 'admin/caching_title';
$formstyle = 'wide';
$showoptions = array('caching_enabled', 'caching_q_time', 'caching_qlist_time');
$checkboxtodisplay = array(
'caching_q_time' => 'option_caching_enabled',
'caching_qlist_time' => 'option_caching_enabled',
);
break;
case 'mailing':
require_once QA_INCLUDE_DIR.'app/mailing.php';
......@@ -1530,6 +1548,11 @@
case 'mailing_per_minute':
$optionfield['suffix'] = qa_lang_html('admin/emails_per_minute');
break;
case 'caching_q_time':
case 'caching_qlist_time':
$optionfield['note'] = qa_lang_html_sub('main/x_minutes', '');
break;
}
if (isset($feedrequest) && $value)
......@@ -1756,6 +1779,15 @@
$qa_content['form']['fields']['mailing_body']['note'] = qa_lang_html('admin/mailing_unsubscribe');
}
break;
case 'caching':
$cacheManager = new Q2A_Storage_CacheManager;
if (!$cacheManager->isEnabled()) {
$cacheError = $cacheManager->getError();
if ($cacheError)
$qa_content['error'] = $cacheError;
}
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment