1: <?php
2: /**
3: * Wicked_Sync defines an API for implementing synchronization backends for
4: * Wicked.
5: *
6: * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (GPL). If you
9: * did not receive this file, see http://www.horde.org/licenses/gpl.
10: *
11: * @author Duck <duck@obala.net>
12: * @package Wicked
13: */
14: abstract class Wicked_Sync
15: {
16: /**
17: * Hash containing connection parameters.
18: *
19: * @var array
20: */
21: protected $_params = array();
22:
23: /**
24: * Attempts to return a concrete Wicked_Sync instance based on $driver.
25: *
26: * @param string $driver The type of the concrete Wicked_Sync subclass
27: * to return. The class name is based on the
28: * sync driver ($driver). The code is
29: * dynamically included.
30: *
31: * @param array $params A hash containing any additional configuration
32: * or connection parameters a subclass might need.
33: *
34: * @return Wicked_Sync The newly created concrete Wicked_Sync
35: * instance, or false on an error.
36: */
37: public function factory($driver = 'Wicked', $params = array())
38: {
39: $driver = Horde_String::ucfirst(basename($driver));
40: $class = 'Wicked_Sync_' . $driver;
41:
42: if (!class_exists($class)) {
43: return false;
44: }
45:
46: if (empty($params['user'])) {
47: $params['user'] = $GLOBALS['registry']->getAuth();
48: }
49: if (empty($params['password'])) {
50: $params['password'] = $GLOBALS['registry']->getAuthCredential('password');
51: }
52: return new $class($params);
53: }
54:
55: /**
56: * Constructs a new Wicked driver object.
57: *
58: * @param array $params A hash containing connection parameters.
59: */
60: public function __construct(array $params = array())
61: {
62: $this->_params = $params;
63: }
64:
65: /**
66: * Returns a list of available pages.
67: *
68: * @return array An array of all available pages.
69: * @throws Wicked_Exception
70: */
71: abstract function listPages();
72:
73: /**
74: * Get the wiki source of a page specified by its name.
75: *
76: * @param string $name The name of the page to fetch
77: *
78: * @return array Page data.
79: * @throws Wicked_Exception
80: */
81: abstract function getPageSource($pageName);
82:
83: /**
84: * Return basic page information.
85: *
86: * @param string $pageName Page name
87: *
88: * @return array Page data.
89: * @throws Wicked_Exception
90: */
91: abstract function getPageInfo($pageName);
92:
93: /**
94: * Return basic information of .multiple pages
95: *
96: * @param array $pages Page names to get info for
97: *
98: * @return array Pages data.
99: * @throws Wicked_Exception
100: */
101: abstract function getMultiplePageInfo($pages = array());
102:
103: /**
104: * Return page history.
105: *
106: * @param string $pagename Page name
107: *
108: * @return array An array of page parameters.
109: * @throws Wicked_Exception
110: */
111: abstract function getPageHistory($pagename);
112:
113: /**
114: * Updates content of a wiki page. If the page does not exist it is
115: * created.
116: *
117: * @param string $pagename Page to edit
118: * @param string $text Page content
119: * @param string $changelog Description of the change
120: *
121: * @throws Wicked_Exception
122: */
123: abstract function editPage($pagename, $text, $changelog = '');
124: }
125: