Issues (493)

lib/SP/Services/Wiki/DokuWikiApi.php (11 issues)

1
<?php
2
/**
3
 * sysPass
4
 *
5
 * @author    nuxsmin
6
 * @link      https://syspass.org
7
 * @copyright 2012-2019, Rubén Domínguez nuxsmin@$syspass.org
8
 *
9
 * This file is part of sysPass.
10
 *
11
 * sysPass is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * sysPass is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 *  along with sysPass.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace SP\Services\Wiki;
26
27
use InvalidArgumentException;
28
use SP\Core\Exceptions\SPException;
29
30
defined('APP_ROOT') || die();
31
32
/**
33
 * Class DokuWikiApi para realizar consultas a la API de DokuWiki
34
 *
35
 * @package SP\Services\Wiki
36
 * @deprecated
37
 */
38
class DokuWikiApi extends DokuWikiApiBase
0 ignored issues
show
Deprecated Code introduced by
The class SP\Services\Wiki\DokuWikiApiBase has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

38
class DokuWikiApi extends /** @scrutinizer ignore-deprecated */ DokuWikiApiBase
Loading history...
39
{
40
    /**
41
     * @var string
42
     */
43
    private $namespace;
44
45
    /**
46
     * Constructor
47
     *
48
     * @param string $url  La URL de conexión
49
     * @param string $user El usuario de conexión
50
     * @param string $pass La clave de conexión
51
     *
52
     * @throws SPException
53
     */
54
    public function __construct($url = null, $user = null, $pass = null)
55
    {
56
        parent::__construct();
57
58
        try {
59
            $this->setConnectionData($url, $user, $pass);
60
61
            if (!empty($this->apiUser) && SessionFactory::getDokuWikiSession() === false) {
62
                $Res = new DokuWikiApiParse($this->doLogin());
0 ignored issues
show
Deprecated Code introduced by
The class SP\Services\Wiki\DokuWikiApiParse has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

62
                $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->doLogin());
Loading history...
63
                $this->catchError($Res);
64
                $resLogin = $Res->parseParams();
65
66
                SessionFactory::setDokuWikiSession($resLogin[0]);
67
68
                if ($resLogin[0] === false) {
69
                    throw new SPException(__u('Authentication error'), SPException::WARNING);
70
                }
71
            }
72
73
            $this->namespace = $this->ConfigData->getDokuwikiNamespace();
74
        } catch (SPException $e) {
75
            $this->logException($e);
76
            throw $e;
77
        } catch (InvalidArgumentException $e) {
78
            throw new SPException($e->getMessage(), SPException::WARNING);
79
        }
80
    }
81
82
    /**
83
     * Comprobar la conexión a DokuWiki
84
     *
85
     * @param string $url  La URL de conexión
86
     * @param string $user El usuario de conexión
87
     * @param string $pass La clave de conexión
88
     *
89
     * @return DokuWikiApi
90
     * @throws SPException
91
     */
92
    public static function checkConnection($url = null, $user = null, $pass = null)
93
    {
94
        try {
95
            // Reinicializar la cookie de DokuWiki
96
            SessionFactory::setDokuWikiSession(false);
97
98
            return new DokuWikiApi($url, $user, $pass);
0 ignored issues
show
Deprecated Code introduced by
The class SP\Services\Wiki\DokuWikiApi has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

98
            return /** @scrutinizer ignore-deprecated */ new DokuWikiApi($url, $user, $pass);
Loading history...
99
        } catch (SPException $e) {
100
            throw $e;
101
        }
102
    }
103
104
    /**
105
     * Obtener el listado de páginas de la Wiki
106
     *
107
     * @return bool
108
     */
109
    public function getPageList()
110
    {
111
        try {
112
            $this->createMsg('dokuwiki.getPagelist');
113
            $this->addParam($this->namespace);
114
            $this->addParam(['depth' => 0]);
115
            $Res = new DokuWikiApiParse($this->callWiki());
0 ignored issues
show
Deprecated Code introduced by
The class SP\Services\Wiki\DokuWikiApiParse has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

115
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
116
            $this->catchError($Res);
117
118
            return $Res->parseParams();
119
        } catch (SPException $e) {
120
            $this->logException($e, __FUNCTION__);
121
            return false;
122
        }
123
    }
124
125
    /**
126
     * Realizar una búsqueda en la Wiki
127
     *
128
     * @param string $search El texto a buscar
129
     *
130
     * @return array|bool
131
     */
132
    public function getSearch($search)
133
    {
134
        try {
135
            $this->createMsg('dokuwiki.search');
136
            $this->addParam($search);
137
            $Res = new DokuWikiApiParse($this->callWiki());
0 ignored issues
show
Deprecated Code introduced by
The class SP\Services\Wiki\DokuWikiApiParse has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

137
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
138
            $this->catchError($Res);
139
140
            return $Res->parseParams();
141
        } catch (SPException $e) {
142
            $this->logException($e, __FUNCTION__);
143
            return false;
144
        }
145
    }
146
147
    /**
148
     * Obtener una página de la Wiki
149
     *
150
     * @param string $page El nombre de la página a obtener
151
     *
152
     * @return array|bool
153
     */
154
    public function getPage($page)
155
    {
156
        if (!empty($this->namespace)) {
157
            $page = $this->namespace . ':' . $page;
158
        }
159
160
        try {
161
            $this->createMsg('wiki.getPageHTML');
162
            $this->addParam($page);
163
            $Res = new DokuWikiApiParse($this->callWiki());
0 ignored issues
show
Deprecated Code introduced by
The class SP\Services\Wiki\DokuWikiApiParse has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

163
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
164
            $this->catchError($Res);
165
166
            return $Res->parseParams();
167
        } catch (SPException $e) {
168
            $this->logException($e, __FUNCTION__);
169
            return false;
170
        }
171
    }
172
173
    /**
174
     * Obtener una página de la Wiki en formato original
175
     *
176
     * @param string $page El nombre de la página a obtener
177
     *
178
     * @return array|bool
179
     */
180
    public function getRawPage($page)
181
    {
182
        try {
183
            $this->createMsg('wiki.getPage');
184
            $this->addParam($page);
185
            $Res = new DokuWikiApiParse($this->callWiki());
0 ignored issues
show
Deprecated Code introduced by
The class SP\Services\Wiki\DokuWikiApiParse has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

185
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
186
            $this->catchError($Res);
187
188
            return $Res->parseParams();
189
        } catch (SPException $e) {
190
            $this->logException($e, __FUNCTION__);
191
            return false;
192
        }
193
    }
194
195
    /**
196
     * Obtener la información de una página de la Wiki
197
     *
198
     * @param string $page El nombre de la página a obtener
199
     *
200
     * @return array|bool
201
     */
202
    public function getPageInfo($page)
203
    {
204
        if (!empty($this->namespace)) {
205
            $page = $this->namespace . ':' . $page;
206
        }
207
208
        try {
209
            $this->createMsg('wiki.getPageInfo');
210
            $this->addParam($page);
211
            $Res = new DokuWikiApiParse($this->callWiki());
0 ignored issues
show
Deprecated Code introduced by
The class SP\Services\Wiki\DokuWikiApiParse has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

211
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
212
            $this->catchError($Res);
213
214
            return $Res->parseParams();
215
        } catch (SPException $e) {
216
            $this->logException($e, __FUNCTION__);
217
            return false;
218
        }
219
    }
220
221
    /**
222
     * Obtener la versión de DokuWiki
223
     *
224
     * @return array|bool
225
     */
226
    public function getVersion()
227
    {
228
        try {
229
            $this->createMsg('dokuwiki.getVersion');
230
            $Res = new DokuWikiApiParse($this->callWiki());
0 ignored issues
show
Deprecated Code introduced by
The class SP\Services\Wiki\DokuWikiApiParse has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

230
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
231
            $this->catchError($Res);
232
233
            return $Res->parseParams();
234
        } catch (SPException $e) {
235
            $this->logException($e, __FUNCTION__);
236
            return false;
237
        }
238
    }
239
240
    /**
241
     * Obtener el nombre de la Wiki
242
     *
243
     * @return array|bool
244
     */
245
    public function getTitle()
246
    {
247
        try {
248
            $this->createMsg('dokuwiki.getTitle');
249
            $Res = new DokuWikiApiParse($this->callWiki());
0 ignored issues
show
Deprecated Code introduced by
The class SP\Services\Wiki\DokuWikiApiParse has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

249
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
250
            $this->catchError($Res);
251
252
            return $Res->parseParams();
253
        } catch (SPException $e) {
254
            $this->logException($e, __FUNCTION__);
255
            return false;
256
        }
257
    }
258
259
    /**
260
     * Obtener los permisos de la página
261
     *
262
     * @param $page
263
     *
264
     * @return array|bool
265
     */
266
    public function getAcl($page)
267
    {
268
        try {
269
            $this->createMsg('wiki.aclCheck');
270
            $this->addParam($page);
271
            $Res = new DokuWikiApiParse($this->callWiki());
0 ignored issues
show
Deprecated Code introduced by
The class SP\Services\Wiki\DokuWikiApiParse has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

271
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
272
            $this->catchError($Res);
273
274
            return $Res->parseParams();
275
        } catch (SPException $e) {
276
            $this->logException($e, __FUNCTION__);
277
            return false;
278
        }
279
    }
280
}