112 else |
112 else |
113 { |
113 { |
114 $allowed = false; |
114 $allowed = false; |
115 $src = ''; |
115 $src = ''; |
116 } |
116 } |
|
117 |
|
118 $auth_edit = ( $session->get_permissions('edit_page') && ( $session->get_permissions('even_when_protected') || !$paths->page_protected ) ); |
|
119 |
117 $return = array( |
120 $return = array( |
118 'mode' => 'editor', |
121 'mode' => 'editor', |
119 'src' => $src, |
122 'src' => $src, |
120 'auth_view_source' => $allowed, |
123 'auth_view_source' => $allowed, |
121 'auth_edit' => $session->get_permissions('edit_page'), |
124 'auth_edit' => $auth_edit, |
122 'time' => time() |
125 'time' => time(), |
|
126 'require_captcha' => false, |
123 ); |
127 ); |
|
128 |
|
129 if ( $auth_edit && !$session->user_logged_in && getConfig('guest_edit_require_captcha') == '1' ) |
|
130 { |
|
131 $return['require_captcha'] = true; |
|
132 $return['captcha_id'] = $session->make_captcha(); |
|
133 } |
|
134 |
124 echo enano_json_encode($return); |
135 echo enano_json_encode($return); |
125 break; |
136 break; |
126 case "getpage": |
137 case "getpage": |
127 // echo PageUtils::getpage($paths->page, false, ( (isset($_GET['oldid'])) ? $_GET['oldid'] : false )); |
138 // echo PageUtils::getpage($paths->page, false, ( (isset($_GET['oldid'])) ? $_GET['oldid'] : false )); |
128 $revision_id = ( (isset($_GET['oldid'])) ? intval($_GET['oldid']) : 0 ); |
139 $revision_id = ( (isset($_GET['oldid'])) ? intval($_GET['oldid']) : 0 ); |
174 'date_string' => date('d M Y h:i a', $row['time_id']), |
185 'date_string' => date('d M Y h:i a', $row['time_id']), |
175 'time' => $row['time_id'] // time() ??? |
186 'time' => $row['time_id'] // time() ??? |
176 ); |
187 ); |
177 echo enano_json_encode($return); |
188 echo enano_json_encode($return); |
178 break; |
189 break; |
|
190 } |
|
191 |
|
192 // Verify captcha, if needed |
|
193 if ( !$session->user_logged_in && getConfig('guest_edit_require_captcha') == '1' ) |
|
194 { |
|
195 if ( !isset($request['captcha_id']) || !isset($request['captcha_code']) ) |
|
196 { |
|
197 die('Invalid request, need captcha metadata'); |
|
198 } |
|
199 $code_correct = strtolower($session->get_captcha($request['captcha_id'])); |
|
200 $code_input = strtolower($request['captcha_code']); |
|
201 if ( $code_correct !== $code_input ) |
|
202 { |
|
203 $return = array( |
|
204 'mode' => 'errors', |
|
205 'errors' => array($lang->get('editor_err_captcha_wrong')), |
|
206 'new_captcha' => $session->make_captcha() |
|
207 ); |
|
208 echo enano_json_encode($return); |
|
209 break; |
|
210 } |
179 } |
211 } |
180 |
212 |
181 // Verification complete. Start the PageProcessor and let it do the dirty work for us. |
213 // Verification complete. Start the PageProcessor and let it do the dirty work for us. |
182 $page = new PageProcessor($paths->page_id, $paths->namespace); |
214 $page = new PageProcessor($paths->page_id, $paths->namespace); |
183 if ( $page->update_page($request['src'], $request['summary'], ( $request['minor_edit'] == 1 )) ) |
215 if ( $page->update_page($request['src'], $request['summary'], ( $request['minor_edit'] == 1 )) ) |