Passed
Push — devel-3.0 ( 2581df...bf8280 )
by Rubén
03:03
created

DokuWikiApi   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 240
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 98
dl 0
loc 240
rs 10
c 0
b 0
f 0
wmc 26

10 Methods

Rating   Name   Duplication   Size   Complexity  
A checkConnection() 0 9 2
A getSearch() 0 12 2
A getTitle() 0 11 2
A getPage() 0 16 3
A __construct() 0 25 6
A getVersion() 0 11 2
A getPageList() 0 13 2
A getPageInfo() 0 16 3
A getRawPage() 0 12 2
A getAcl() 0 12 2
1
<?php
2
/**
3
 * sysPass
4
 *
5
 * @author    nuxsmin
6
 * @link      https://syspass.org
7
 * @copyright 2012-2018, 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 SP\Core\Exceptions\SPException;
28
29
defined('APP_ROOT') || die();
30
31
/**
32
 * Class DokuWikiApi para realizar consultas a la API de DokuWiki
33
 *
34
 * @package SP\Services\Wiki
35
 * @deprecated
36
 */
37
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

37
class DokuWikiApi extends /** @scrutinizer ignore-deprecated */ DokuWikiApiBase
Loading history...
38
{
39
    /**
40
     * @var string
41
     */
42
    private $namespace;
43
44
    /**
45
     * Constructor
46
     *
47
     * @param string $url  La URL de conexión
48
     * @param string $user El usuario de conexión
49
     * @param string $pass La clave de conexión
50
     *
51
     * @throws \SP\Core\Exceptions\SPException
52
     */
53
    public function __construct($url = null, $user = null, $pass = null)
54
    {
55
        parent::__construct();
56
57
        try {
58
            $this->setConnectionData($url, $user, $pass);
59
60
            if (!empty($this->apiUser) && SessionFactory::getDokuWikiSession() === false) {
0 ignored issues
show
Bug introduced by
The type SP\Services\Wiki\SessionFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
61
                $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

61
                $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->doLogin());
Loading history...
62
                $this->catchError($Res);
63
                $resLogin = $Res->parseParams();
64
65
                SessionFactory::setDokuWikiSession($resLogin[0]);
66
67
                if ($resLogin[0] === false) {
68
                    throw new SPException(__('Fallo de autentificación', false), SPException::WARNING);
69
                }
70
            }
71
72
            $this->namespace = $this->ConfigData->getDokuwikiNamespace();
73
        } catch (SPException $e) {
74
            $this->logException($e);
75
            throw $e;
76
        } catch (\InvalidArgumentException $e) {
77
            throw new SPException($e->getMessage(), SPException::WARNING);
78
        }
79
    }
80
81
    /**
82
     * Comprobar la conexión a DokuWiki
83
     *
84
     * @param string $url  La URL de conexión
85
     * @param string $user El usuario de conexión
86
     * @param string $pass La clave de conexión
87
     *
88
     * @return DokuWikiApi
89
     * @throws \SP\Core\Exceptions\SPException
90
     */
91
    public static function checkConnection($url = null, $user = null, $pass = null)
92
    {
93
        try {
94
            // Reinicializar la cookie de DokuWiki
95
            SessionFactory::setDokuWikiSession(false);
96
97
            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

97
            return /** @scrutinizer ignore-deprecated */ new DokuWikiApi($url, $user, $pass);
Loading history...
98
        } catch (SPException $e) {
99
            throw $e;
100
        }
101
    }
102
103
    /**
104
     * Obtener el listado de páginas de la Wiki
105
     *
106
     * @return bool
107
     */
108
    public function getPageList()
109
    {
110
        try {
111
            $this->createMsg('dokuwiki.getPagelist');
112
            $this->addParam($this->namespace);
113
            $this->addParam(['depth' => 0]);
114
            $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

114
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
115
            $this->catchError($Res);
116
117
            return $Res->parseParams();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $Res->parseParams() returns the type array which is incompatible with the documented return type boolean.
Loading history...
118
        } catch (SPException $e) {
119
            $this->logException($e, __FUNCTION__);
120
            return false;
121
        }
122
    }
123
124
    /**
125
     * Realizar una búsqueda en la Wiki
126
     *
127
     * @param string $search El texto a buscar
128
     *
129
     * @return array|bool
130
     */
131
    public function getSearch($search)
132
    {
133
        try {
134
            $this->createMsg('dokuwiki.search');
135
            $this->addParam($search);
136
            $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

136
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
137
            $this->catchError($Res);
138
139
            return $Res->parseParams();
140
        } catch (SPException $e) {
141
            $this->logException($e, __FUNCTION__);
142
            return false;
143
        }
144
    }
145
146
    /**
147
     * Obtener una página de la Wiki
148
     *
149
     * @param string $page El nombre de la página a obtener
150
     *
151
     * @return array|bool
152
     */
153
    public function getPage($page)
154
    {
155
        if (!empty($this->namespace)) {
156
            $page = $this->namespace . ':' . $page;
157
        }
158
159
        try {
160
            $this->createMsg('wiki.getPageHTML');
161
            $this->addParam($page);
162
            $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

162
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
163
            $this->catchError($Res);
164
165
            return $Res->parseParams();
166
        } catch (SPException $e) {
167
            $this->logException($e, __FUNCTION__);
168
            return false;
169
        }
170
    }
171
172
    /**
173
     * Obtener una página de la Wiki en formato original
174
     *
175
     * @param string $page El nombre de la página a obtener
176
     *
177
     * @return array|bool
178
     */
179
    public function getRawPage($page)
180
    {
181
        try {
182
            $this->createMsg('wiki.getPage');
183
            $this->addParam($page);
184
            $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

184
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
185
            $this->catchError($Res);
186
187
            return $Res->parseParams();
188
        } catch (SPException $e) {
189
            $this->logException($e, __FUNCTION__);
190
            return false;
191
        }
192
    }
193
194
    /**
195
     * Obtener la información de una página de la Wiki
196
     *
197
     * @param string $page El nombre de la página a obtener
198
     *
199
     * @return array|bool
200
     */
201
    public function getPageInfo($page)
202
    {
203
        if (!empty($this->namespace)) {
204
            $page = $this->namespace . ':' . $page;
205
        }
206
207
        try {
208
            $this->createMsg('wiki.getPageInfo');
209
            $this->addParam($page);
210
            $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

210
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
211
            $this->catchError($Res);
212
213
            return $Res->parseParams();
214
        } catch (SPException $e) {
215
            $this->logException($e, __FUNCTION__);
216
            return false;
217
        }
218
    }
219
220
    /**
221
     * Obtener la versión de DokuWiki
222
     *
223
     * @return array|bool
224
     */
225
    public function getVersion()
226
    {
227
        try {
228
            $this->createMsg('dokuwiki.getVersion');
229
            $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

229
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
230
            $this->catchError($Res);
231
232
            return $Res->parseParams();
233
        } catch (SPException $e) {
234
            $this->logException($e, __FUNCTION__);
235
            return false;
236
        }
237
    }
238
239
    /**
240
     * Obtener el nombre de la Wiki
241
     *
242
     * @return array|bool
243
     */
244
    public function getTitle()
245
    {
246
        try {
247
            $this->createMsg('dokuwiki.getTitle');
248
            $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

248
            $Res = /** @scrutinizer ignore-deprecated */ new DokuWikiApiParse($this->callWiki());
Loading history...
249
            $this->catchError($Res);
250
251
            return $Res->parseParams();
252
        } catch (SPException $e) {
253
            $this->logException($e, __FUNCTION__);
254
            return false;
255
        }
256
    }
257
258
    /**
259
     * Obtener los permisos de la página
260
     *
261
     * @param $page
262
     *
263
     * @return array|bool
264
     */
265
    public function getAcl($page)
266
    {
267
        try {
268
            $this->createMsg('wiki.aclCheck');
269
            $this->addParam($page);
270
            $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

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