xref: /dokuwiki/doku.php (revision a5ccc4f04046c0aa8d881975b192300fc41c9978)
1<?php
2/**
3 * DokuWiki mainscript
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9  define('DOKUWIKIVERSION','2005-01-14');
10
11  ini_set('short_open_tag',"1");
12  require_once("conf/dokuwiki.php");
13  require_once("inc/common.php");
14  require_once("inc/html.php");
15  require_once("inc/parser.php");
16  require_once("lang/en/lang.php");
17  require_once("lang/".$conf['lang']."/lang.php");
18  setCorrectLocale();
19  require_once("inc/auth.php");
20
21  //import variables
22  $QUERY = trim($_REQUEST['id']);
23  $ID    = cleanID($_REQUEST['id']);
24  $REV   = $_REQUEST['rev'];
25  $ACT   = $_REQUEST['do'];
26  $IDX   = $_REQUEST['idx'];
27  $DATE  = $_REQUEST['date'];
28  $RANGE = $_REQUEST['lines'];
29  $HIGH  = $_REQUEST['s'];
30  if(empty($HIGH)) $HIGH = getGoogleQuery();
31
32  $TEXT  = cleanText($_POST['wikitext']);
33  $PRE   = cleanText($_POST['prefix']);
34  $SUF   = cleanText($_POST['suffix']);
35  $SUM   = $_REQUEST['summary'];
36
37  //we accept the do param as HTTP header, too:
38  if(!empty($_SERVER['HTTP_X_DOKUWIKI_DO'])){
39    $ACT = trim(strtolower($_SERVER['HTTP_X_DOKUWIKI_DO']));
40  }
41
42  if(!empty($IDX)) $ACT='index';
43  //set defaults
44  if(empty($ID))  $ID  = $conf['start'];
45  if(empty($ACT)) $ACT = 'show';
46
47  header('Content-Type: text/html; charset='.$lang['encoding']);
48
49  if($ACT == 'debug'){
50    html_debug();
51    exit;
52  }
53
54  //already logged in?
55  if($_SERVER['REMOTE_USER'] && $ACT=='login') $ACT='show';
56  //handle logout
57  if($ACT=='logout'){
58    auth_logoff();
59    $ACT='login';
60  }
61
62  //handle register
63  if($ACT=='register' && register()){
64    $ACT='login';
65  }
66
67  //do saving after spam- and conflictcheck
68  if($ACT == $lang['btn_save'] && auth_quickaclcheck($ID)){
69    if(checkwordblock()){
70      //spam detected
71      $ACT = 'wordblock';
72    }elseif($DATE != 0 && @filemtime(wikiFN($ID)) > $DATE ){
73      //newer version available -> ask what to do
74      $ACT = 'conflict';
75    }else{
76      //save it
77      saveWikiText($ID,con($PRE,$TEXT,$SUF,1),$SUM); //use pretty mode for con
78      //unlock it
79      unlock($id);
80      //show it
81      header("Location: ".wl($ID, '','doku.php',true));
82      exit();
83    }
84  }
85
86  //make infos about current page available
87  $INFO = pageinfo();
88
89  //Editing: check if locked by anyone - if not lock for my self
90  if(($ACT == 'edit' || $ACT == $lang['btn_preview']) && $INFO['editable']){
91    $lockedby = checklock($ID);
92    if($lockedby){
93      $ACT = 'locked';
94    }else{
95      lock($ID);
96    }
97  }else{
98    //try to unlock
99    unlock($ID);
100  }
101
102
103  //display some infos
104  if($ACT == 'check'){
105    check();
106    $ACT = 'show';
107  }
108
109  //check which permission is needed
110  if(in_array($ACT,array('preview','wordblock','conflict','lockedby'))){
111    if($INFO['exists']){
112      $permneed = AUTH_EDIT;
113    }else{
114      $permneed = AUTH_CREATE;
115    }
116  }elseif(in_array($ACT,array('revisions','show','edit'))){
117    $permneed = AUTH_READ;
118  }else{
119    $permneed = AUTH_NONE;
120  }
121
122  //start output
123  if(substr($ACT,0,6) != 'export') html_header();
124  if(html_acl($permneed)){
125    if($ACT == 'edit'){
126      html_edit();
127    }elseif($ACT == $lang['btn_preview']){
128      html_edit($TEXT);
129      html_show($TEXT);
130    }elseif($ACT == 'wordblock'){
131      html_edit($TEXT,'wordblock');
132    }elseif($ACT == 'search' && !empty($QUERY)){
133      html_search();
134    }elseif($ACT == 'revisions'){
135      html_revisions();
136    }elseif($ACT == 'diff'){
137      html_diff();
138    }elseif($ACT == 'recent'){
139      html_recent();
140    }elseif($ACT == 'index'){
141      html_index($IDX);
142    }elseif($ACT == 'backlink'){
143      html_backlinks();
144    }elseif($ACT == 'conflict'){
145      html_conflict(con($PRE,$TEXT,$SUF),$SUM);
146      html_diff(con($PRE,$TEXT,$SUF),false);
147    }elseif($ACT == 'locked'){
148      html_locked($lockedby);
149    }elseif($ACT == 'login'){
150      html_login();
151    }elseif($ACT == 'register' && $conf['openregister']){
152      html_register();
153    }elseif($ACT == 'export_html'){
154      html_head();
155			print "<body>\n";
156			print parsedWiki($ID,$REV,false);
157			print "</body>\n</html>\n";
158		}elseif($ACT == 'export_raw'){
159			header("Content-Type: text/plain");
160      print rawWiki($ID,$REV);
161    }else{
162      $ACT='show';
163      html_show();
164    }
165  }
166  if(substr($ACT,0,6) != 'export') html_footer();
167
168?>
169