|
|
Line 5: |
Line 5: |
| | | |
| == Private wiki & Public www == | | == Private wiki & Public www == |
− | Thie following LocalSettings code is the current way I'm using to server public website or private wiki based on subdomain (it must be added after the WikiSkin extension is installed. If in ''wiki'' subdomain, then users are required to login to view any page at all. Once logged in, standard wiki skin is used with all personal links, and actions. If in the ''www'' subdomain, actions, personal and catlinks etc are not sent to client, and all actions except ''view'' and ''raw'' are disabled, there is no login required, but any pages not in the ''Public'' category return a ''404''.
| + | See [[Maintaining websites with a wiki]] |
− | <php>
| |
− | # WIKISKIN
| |
− | include("extensions/WikiSkin.php");
| |
− | $wgWikiSkinArticle = 'Zenovia/WikiSkin';
| |
− | | |
− | # Only allow view,edit and raw actions from www subdomain
| |
− | if (!ereg('^wiki.',$_SERVER['HTTP_HOST'])) {
| |
− | if ($_REQUEST['action'] != 'view' && $_REQUEST['action'] != 'raw' && $_REQUEST['action'] != 'render')
| |
− | $_REQUEST['action'] = 'view';
| |
− | }
| |
− | | |
− | # A function to return a 404 and die
| |
− | function wf404() {
| |
− | header('HTTP/1.0 404 Not Found');
| |
− | $err = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>404 Not Found</title></he$
| |
− | <body><h1>Not Found</h1><p>The requested URL was not found on this server.</p></body></html>';
| |
− | if (in_array('Content-Encoding: gzip',headers_list())) $err = gzencode($err);
| |
− | echo $err;
| |
− | die;
| |
− | }
| |
− | | |
− | # Return a 404 and die if www subdomain and article not in Category:Public
| |
− | $wgHooks['ArticleAfterFetchContent'][] = 'wfPublicCategory';
| |
− | function wfPublicCategory(&$article,&$text) {
| |
− | $t = $_REQUEST['title'];
| |
− | if ($article->mTitle->getText() != $t) return true;
| |
− | if (eregi('\\.(css|js)$',$t)) return true;
| |
− | if (!ereg('^wiki.',$_SERVER['HTTP_HOST'])) {
| |
− | preg_match_all('/\\[{2}(category:.+?)(\\|.+?)?\\]/i',strtolower($text),$cats);
| |
− | if (!in_array('category:public',$cats[1])) wf404();
| |
− | }
| |
− | return true;
| |
− | }
| |
− | | |
− | # No anoymous users allowed in wiki
| |
− | $wgExtensionFunctions[] = 'wfLocalSettingsArticle';
| |
− | function wfLocalSettingsArticle() {
| |
− | global $wgUser,$wgServer;
| |
− | if (ereg('^wiki.',$_SERVER['HTTP_HOST'])) {
| |
− | | |
− | # Bounce to login if anonymous
| |
− | if ($wgUser->isAnon() && $_REQUEST['title'] != 'Special:Userlogin') {
| |
− | if (array_key_exists('live',$_REQUEST)) die;
| |
− | header("Location: $wgServer/Special:Userlogin");
| |
− | }
| |
− | }
| |
− | else {
| |
− | | |
− | # Don't allow non-existent articles in www
| |
− | $t = Title::newFromText($_REQUEST['title']);
| |
− | if (is_object($t) && !$t->exists()) wf404();
| |
− | }
| |
− | }
| |
− | </php>
| |
− | The WikiSkin can compliment this private/public distinction too by allowing the returning of different content for each using the following parser-function syntax:
| |
− | :<tt><nowiki>{{#if:{{#pos:{{SERVER}}|wiki}}|PRIVATE-CONTENT|PUBLIC-CONTENT}}</nowiki></tt>
| |