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