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