1<?php 2 3/** 4 * this is an example AJAX call handler 5 * it returns a slice of the dokuwiki page 6 * the AJAX call must pass in two parameters: 7 * id (a string) and slice (a stringified JSON object). 8 * note that a sectok must also be passed in for logged in users. 9 * the class name can be arbitrary, but the name of this script 10 * must be the same as the function call, i.e., example.php 11 * respond to the AJAX call componnets.example. 12 */ 13 14class Components_AJAX_Example extends Doku_AJAX { 15 public function __construct() { 16 parent::__construct( 17 // required parameters 18 array( 19 'id' => 'string', 20 'range' => 'array' 21 ) 22 // no optional parameters 23 ); 24 } 25 26 // the name of the function call 27 public function name() { return 'example'; } 28 29 // check if the call is authorized 30 // here we require the user to have edit right 31 // for these people can see the raw wiki text anyway, 32 // so there is no information leak for us. 33 protected function auth($params) { 34 $id = cleanID($params['id']); 35 return auth_quickaclcheck($id) >= AUTH_EDIT; 36 } 37 38 // make the actuall call, and return the result 39 protected function call($params) { 40 $id = cleanID($params['id']); 41 if (!file_exists(wikiFN($id))) 42 // return an error and exit; 43 $this->error(404); 44 $range = $params['range']; 45 if (!isset($range['from']) || !isset($range['to'])) 46 // an error with a specific message, and exit 47 $this->error(400, "range must have a from proterty and a to property"); 48 // return the slice 49 return rawWikiSlices($range['from'] . '-' . $range['to'], $id)[1]; 50 } 51}