1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Wicked_Api extends Horde_Registry_Api
16: {
17: 18: 19: 20: 21:
22: public $links = array(
23: 'show' => '%application%/display.php?page=|page|&version=|version|#|toc|'
24: );
25:
26: 27: 28: 29: 30: 31: 32: 33:
34: public function listPages($special = true, $no_cache = false)
35: {
36: return $GLOBALS['wicked']->getPages($special, $no_cache);
37: }
38:
39: 40: 41: 42: 43: 44: 45: 46:
47: public function getPageInfo($pagename)
48: {
49: $page = Wicked_Page::getPage($pagename);
50: return array(
51: 'page_version' => $page->_page['page_version'],
52: 'page_checksum' => md5($page->getText()),
53: 'version_created' => $page->_page['version_created'],
54: 'change_author' => $page->_page['change_author'],
55: 'change_log' => $page->_page['change_log'],
56: );
57: }
58:
59: 60: 61: 62: 63: 64: 65: 66:
67: public function getMultiplePageInfo($pagenames = array())
68: {
69: require_once dirname(__FILE__) . '/base.php';
70:
71: if (empty($pagenames)) {
72: $pagenames = $GLOBALS['wicked']->getPages(false);
73: }
74:
75: $info = array();
76:
77: foreach ($pagenames as $pagename) {
78: $page = Wicked_Page::getPage($pagename);
79: $info[$pagename] = array(
80: 'page_version' => $page->_page['page_version'],
81: 'page_checksum' => md5($page->getText()),
82: 'version_created' => $page->_page['version_created'],
83: 'change_author' => $page->_page['change_author'],
84: 'change_log' => $page->_page['change_log']
85: );
86: }
87:
88: return $info;
89: }
90:
91: 92: 93: 94: 95: 96: 97: 98:
99: public function getPageHistory($pagename)
100: {
101: $page = Wicked_Page::getPage($pagename);
102: $summaries = $GLOBALS['wicked']->getHistory($pagename);
103:
104: foreach ($summaries as $i => $summary) {
105: $summaries[$i]['page_checksum'] = md5($summary['page_text']);
106: unset($summaries[$i]['page_text']);
107: }
108:
109: return $summaries;
110: }
111:
112: 113: 114: 115: 116: 117: 118:
119: public function pageExists($pagename)
120: {
121: return $GLOBALS['wicked']->pageExists($pagename);
122: }
123:
124: 125: 126: 127: 128: 129: 130: 131:
132: public function display($pagename)
133: {
134: $page = Wicked_Page::getPage($pagename);
135: $GLOBALS['wicked']->logPageView($page->pageName());
136: return $page->displayContents(false);
137: }
138:
139: 140: 141: 142: 143: 144: 145: 146: 147:
148: public function renderPage($pagename, $format = 'Plain')
149: {
150: $page = Wicked_Page::getPage($pagename);
151: $content = $page->getProcessor()->transform($page->getText(), $format);
152: $GLOBALS['wicked']->logPageView($page->pageName());
153: return $content;
154: }
155:
156: 157: 158: 159: 160: 161: 162: 163: 164: 165:
166: public function edit($pagename, $text, $changelog = '')
167: {
168: $page = Wicked_Page::getPage($pagename);
169: if (!$page->allows(Wicked::MODE_EDIT)) {
170: throw new Wicked_Exception(sprintf(_("You don't have permission to edit \"%s\"."), $pagename));
171: }
172: if ($GLOBALS['conf']['wicked']['require_change_log'] &&
173: empty($changelog)) {
174: throw new Wicked_Exception(_("You must provide a change log."));
175: }
176:
177: try {
178: $content = $page->getText();
179: } catch (Wicked_Exception $e) {
180:
181: if ($GLOBALS['wicked']->pageExists($pagename)) {
182: throw $e;
183: }
184: $GLOBALS['wicked']->newPage($pagename, $text);
185: }
186:
187: if (trim($text) == trim($content)) {
188: throw new Wicked_Exception(_("No changes made"));
189: }
190:
191: $page->updateText($text, $changelog);
192: }
193:
194: 195: 196: 197: 198: 199: 200:
201: public function listTemplates()
202: {
203: global $wicked;
204: $templates = $wicked->getMatchingPages('Template', Wicked_Page::MATCH_ENDS);
205: $list = array(array('category' => _("Wiki Templates"),
206: 'templates' => array()));
207: foreach ($templates as $page) {
208: $list[0]['templates'][] = array('id' => $page['page_name'],
209: 'name' => $page['page_name']);
210: }
211: return $list;
212: }
213:
214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224:
225: public function getTemplate($name)
226: {
227: return $this->getPageSource($name);
228: }
229:
230: 231: 232: 233: 234: 235: 236: 237: 238:
239: public function getPageSource($pagename, $version = null)
240: {
241: global $wicked;
242:
243: $page = Wicked_Page::getPage($pagename, $version);
244:
245: if (!$page->allows(Wicked::MODE_CONTENT)) {
246: throw new Wicked_Exception(_("Permission denied."));
247: }
248:
249: if (!$page->isValid()) {
250: throw new Wicked_Exception(_("Invalid page requested."));
251: }
252:
253: return $page->getText();
254: }
255:
256: 257: 258: 259: 260: 261: 262: 263: 264:
265: public function saveTemplate($name, $data)
266: {
267: $this->edit($name, $data, 'Template Auto-fill', false);
268: }
269:
270: 271: 272: 273: 274: 275: 276: 277:
278: public function getRecentChanges($days = 3)
279: {
280: $info = array();
281: foreach ($GLOBALS['wicked']->getRecentChanges($days) as $page) {
282: $info[$page['page_name']] = array(
283: 'page_version' => $page['page_version'],
284: 'page_checksum' => md5($page['page_text']),
285: 'version_created' => $page['version_created'],
286: 'change_author' => $page['change_author'],
287: 'change_log' => $page['change_log'],
288: );
289: }
290:
291: return $info;
292: }
293: }
294: