xref: /dokuwiki/doku.php (revision 907ac107ddb83702d2f67ebb7022711e39a62b5a)
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
45  if($ACT == 'debug'){
46    html_debug();
47    exit;
48  }
49
50  //already logged in?
51  if($_SERVER['REMOTE_USER'] && $ACT=='login') $ACT='show';
52  //handle logout
53  if($ACT=='logout'){
54    auth_logoff();
55    $ACT='login';
56  }
57
58  //handle register
59  if($ACT=='register' && register()){
60    $ACT='login';
61  }
62
63  //do saving after spam- and conflictcheck
64  if($ACT == $lang['btn_save'] && auth_quickaclcheck($ID)){
65    if(checkwordblock()){
66      //spam detected
67      $ACT = 'wordblock';
68    }elseif($DATE != 0 && @filemtime(wikiFN($ID)) > $DATE ){
69      //newer version available -> ask what to do
70      $ACT = 'conflict';
71    }else{
72      //save it
73      saveWikiText($ID,con($PRE,$TEXT,$SUF,1),$SUM); //use pretty mode for con
74      //unlock it
75      unlock($id);
76      //show it
77      header("Location: ".wl($ID, '','doku.php',true));
78      exit();
79    }
80  }
81
82  //make infos about current page available
83  $INFO = pageinfo();
84
85  //Editing: check if locked by anyone - if not lock for my self
86  if(($ACT == 'edit' || $ACT == $lang['btn_preview']) && $INFO['editable']){
87    $lockedby = checklock($ID);
88    if($lockedby){
89      $ACT = 'locked';
90    }else{
91      lock($ID);
92    }
93  }else{
94    //try to unlock
95    unlock($ID);
96  }
97
98
99  //display some infos
100  if($ACT == 'check'){
101    check();
102    $ACT = 'show';
103  }
104
105  //check which permission is needed
106  if(in_array($ACT,array('preview','wordblock','conflict','lockedby'))){
107    if($INFO['exists']){
108      $permneed = AUTH_EDIT;
109    }else{
110      $permneed = AUTH_CREATE;
111    }
112  }elseif(in_array($ACT,array('login','register','search','recent'))){
113    $permneed = AUTH_NONE;
114  }else{
115    $permneed = AUTH_READ;
116  }
117
118  //start output
119  header('Content-Type: text/html; charset='.$lang['encoding']);
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