xref: /dokuwiki/inc/deprecated.php (revision 06053dca2fac9a1da4eb1accf8c2488942da5d2a)
1<?php
2// phpcs:ignoreFile -- this file violates PSR-12 by definition
3/**
4 * These classes and functions are deprecated and will be removed in future releases
5 *
6 * Note: when adding to this file, please also add appropriate actions to _test/rector.php
7 */
8
9use dokuwiki\Debug\DebugHelper;
10
11/**
12 * @deprecated since 2021-11-11 use \dokuwiki\Remote\IXR\Client instead!
13 */
14class IXR_Client extends \dokuwiki\Remote\IXR\Client
15{
16    /**
17     * @inheritdoc
18     * @deprecated 2021-11-11
19     */
20    public function __construct($server, $path = false, $port = 80, $timeout = 15, $timeout_io = null)
21    {
22        DebugHelper::dbgDeprecatedFunction(dokuwiki\Remote\IXR\Client::class);
23        parent::__construct($server, $path, $port, $timeout, $timeout_io);
24    }
25}
26/**
27 * @deprecated since 2021-11-11 use \IXR\Client\ClientMulticall instead!
28 */
29class IXR_ClientMulticall extends \IXR\Client\ClientMulticall
30{
31    /**
32     * @inheritdoc
33     * @deprecated 2021-11-11
34     */
35    public function __construct($server, $path = false, $port = 80)
36    {
37        DebugHelper::dbgDeprecatedFunction(IXR\Client\ClientMulticall::class);
38        parent::__construct($server, $path, $port);
39    }
40}
41/**
42 * @deprecated since 2021-11-11 use \IXR\Server\Server instead!
43 */
44class IXR_Server extends \IXR\Server\Server
45{
46    /**
47     * @inheritdoc
48     * @deprecated 2021-11-11
49     */
50    public function __construct($callbacks = false, $data = false, $wait = false)
51    {
52        DebugHelper::dbgDeprecatedFunction(IXR\Server\Server::class);
53        parent::__construct($callbacks, $data, $wait);
54    }
55}
56/**
57 * @deprecated since 2021-11-11 use \IXR\Server\IntrospectionServer instead!
58 */
59class IXR_IntrospectionServer extends \IXR\Server\IntrospectionServer
60{
61    /**
62     * @inheritdoc
63     * @deprecated 2021-11-11
64     */
65    public function __construct()
66    {
67        DebugHelper::dbgDeprecatedFunction(IXR\Server\IntrospectionServer::class);
68        parent::__construct();
69    }
70}
71/**
72 * @deprecated since 2021-11-11 use \IXR\Request\Request instead!
73 */
74class IXR_Request extends \IXR\Request\Request
75{
76    /**
77     * @inheritdoc
78     * @deprecated 2021-11-11
79     */
80    public function __construct($method, $args)
81    {
82        DebugHelper::dbgDeprecatedFunction(IXR\Request\Request::class);
83        parent::__construct($method, $args);
84    }
85}
86/**
87 * @deprecated since 2021-11-11 use \IXR\Message\Message instead!
88 */
89class IXR_Message extends IXR\Message\Message
90{
91    /**
92     * @inheritdoc
93     * @deprecated 2021-11-11
94     */
95    public function __construct($message)
96    {
97        DebugHelper::dbgDeprecatedFunction(IXR\Message\Message::class);
98        parent::__construct($message);
99    }
100}
101/**
102 * @deprecated since 2021-11-11 use \IXR\Message\Error instead!
103 */
104class IXR_Error extends \IXR\Message\Error
105{
106    /**
107     * @inheritdoc
108     * @deprecated 2021-11-11
109     */
110    public function __construct($code, $message)
111    {
112        DebugHelper::dbgDeprecatedFunction(IXR\Message\Error::class);
113        parent::__construct($code, $message);
114    }
115}
116/**
117 * @deprecated since 2021-11-11 use \IXR\DataType\Date instead!
118 */
119class IXR_Date extends \IXR\DataType\Date
120{
121    /**
122     * @inheritdoc
123     * @deprecated 2021-11-11
124     */
125    public function __construct($time)
126    {
127        DebugHelper::dbgDeprecatedFunction(IXR\DataType\Date::class);
128        parent::__construct($time);
129    }
130}
131/**
132 * @deprecated since 2021-11-11 use \IXR\DataType\Base64 instead!
133 */
134class IXR_Base64 extends \IXR\DataType\Base64
135{
136    /**
137     * @inheritdoc
138     * @deprecated 2021-11-11
139     */
140    public function __construct($data)
141    {
142        DebugHelper::dbgDeprecatedFunction(IXR\DataType\Base64::class);
143        parent::__construct($data);
144    }
145}
146/**
147 * @deprecated since 2021-11-11 use \IXR\DataType\Value instead!
148 */
149class IXR_Value extends \IXR\DataType\Value
150{
151    /**
152     * @inheritdoc
153     * @deprecated 2021-11-11
154     */
155    public function __construct($data, $type = null)
156    {
157        DebugHelper::dbgDeprecatedFunction(IXR\DataType\Value::class);
158        parent::__construct($data, $type);
159    }
160}
161
162/**
163 * print a newline terminated string
164 *
165 * You can give an indention as optional parameter
166 *
167 * @author Andreas Gohr <andi@splitbrain.org>
168 *
169 * @param string $string  line of text
170 * @param int    $indent  number of spaces indention
171 * @deprecated 2023-08-31 use echo instead
172 */
173function ptln($string, $indent = 0)
174{
175    DebugHelper::dbgDeprecatedFunction('echo');
176    echo str_repeat(' ', $indent) . "$string\n";
177}
178
179/**
180 * Adds/updates the search index for the given page
181 *
182 * Locking is handled internally.
183 *
184 * @param string        $page   name of the page to index
185 * @param boolean       $verbose    print status messages
186 * @param boolean       $force  force reindexing even when the index is up to date
187 * @return string|boolean  the function completed successfully
188 *
189 * @deprecated 2026-04-07 use Indexer class instead
190 */
191function idx_addPage($page, $verbose = false, $force = false)
192{
193    DebugHelper::dbgDeprecatedFunction('dokuwiki\Search\Indexer::addPage()');
194    try {
195        (new dokuwiki\Search\Indexer())->addPage($page, $force);
196        return true;
197    } catch (\dokuwiki\Search\Exception\SearchException $e) {
198        return false;
199    }
200}
201
202/**
203 * Create an instance of the indexer.
204 *
205 * @return dokuwiki\Search\Indexer
206 *
207 * @deprecated 2026-04-07 use dokuwiki\Search\Indexer directly
208 */
209function idx_get_indexer()
210{
211    DebugHelper::dbgDeprecatedFunction(dokuwiki\Search\Indexer::class);
212    return new dokuwiki\Search\Indexer();
213}
214
215/**
216 * Read the list of words in an index (if it exists).
217 *
218 * @param string $idx
219 * @param string $suffix
220 * @return array
221 *
222 * @deprecated 2026-04-07 use Index classes directly
223 */
224function idx_getIndex($idx, $suffix)
225{
226    DebugHelper::dbgDeprecatedFunction('Index classes');
227    global $conf;
228    $fn = $conf['indexdir'] . '/' . $idx . $suffix . '.idx';
229    if (!file_exists($fn)) return [];
230    return file($fn);
231}
232
233/**
234 * Find tokens in the fulltext index
235 *
236 * @param array $words list of words to search for
237 * @return array list of pages found
238 *
239 * @deprecated 2026-04-07 use CollectionSearch on PageFulltextCollection instead
240 */
241function idx_lookup(&$words)
242{
243    DebugHelper::dbgDeprecatedFunction(dokuwiki\Search\Collection\CollectionSearch::class);
244    return (new dokuwiki\Search\Indexer())->lookup($words);
245}
246
247/**
248 * Get the list of lengths indexed in the wiki.
249 *
250 * @return array
251 *
252 * @deprecated 2026-04-07 use PageFulltextCollection::getTokenIndexMaximum() instead
253 */
254function idx_listIndexLengths()
255{
256    DebugHelper::dbgDeprecatedFunction('PageFulltextCollection::getTokenIndexMaximum()');
257    global $conf;
258    $idx = [];
259    $files = glob($conf['indexdir'] . '/i*.idx');
260    if ($files) {
261        foreach ($files as $file) {
262            if (preg_match('/i(\d+)\.idx$/', $file, $match)) {
263                $idx[] = (int)$match[1];
264            }
265        }
266        sort($idx);
267    }
268    return $idx;
269}
270
271/**
272 * Get the word lengths that have been indexed.
273 *
274 * @param array|int $filter
275 * @return array
276 *
277 * @deprecated 2026-04-07 use PageFulltextCollection::getTokenIndexMaximum() instead
278 */
279function idx_indexLengths($filter)
280{
281    DebugHelper::dbgDeprecatedFunction('PageFulltextCollection::getTokenIndexMaximum()');
282    global $conf;
283    $idx = [];
284    if (is_array($filter)) {
285        $path = $conf['indexdir'] . "/i";
286        foreach (array_keys($filter) as $key) {
287            if (file_exists($path . $key . '.idx'))
288                $idx[] = $key;
289        }
290    } else {
291        $lengths = idx_listIndexLengths();
292        foreach ($lengths as $length) {
293            if ((int)$length >= (int)$filter)
294                $idx[] = $length;
295        }
296    }
297    return $idx;
298}
299
300/**
301 * Execute a fulltext search
302 *
303 * @param string $query search query
304 * @param array $highlight words to highlight
305 * @param string|null $sort sorting order
306 * @param int|string|null $after only show results after this date
307 * @param int|string|null $before only show results before this date
308 * @return array
309 *
310 * @deprecated 2026-04-07 use dokuwiki\Search\FulltextSearch::pageSearch() instead
311 */
312function ft_pageSearch($query, &$highlight, $sort = null, $after = null, $before = null)
313{
314    DebugHelper::dbgDeprecatedFunction(dokuwiki\Search\FulltextSearch::class . '::pageSearch()');
315    if (!is_array($highlight)) $highlight = [];
316    return (new dokuwiki\Search\FulltextSearch())->pageSearch($query, $highlight, $sort, $after, $before);
317}
318
319/**
320 * Returns the backlinks for a given page
321 *
322 * @param string $id page id
323 * @param bool $ignore_perms
324 * @return string[]
325 *
326 * @deprecated 2026-04-07 use dokuwiki\Search\MetadataSearch::backlinks() instead
327 */
328function ft_backlinks($id, $ignore_perms = false)
329{
330    DebugHelper::dbgDeprecatedFunction(dokuwiki\Search\MetadataSearch::class . '::backlinks()');
331    return (new dokuwiki\Search\MetadataSearch())->backlinks($id, $ignore_perms);
332}
333
334/**
335 * Returns the pages that use a given media file
336 *
337 * @param string $id media id
338 * @param bool $ignore_perms
339 * @return string[]
340 *
341 * @deprecated 2026-04-07 use dokuwiki\Search\MetadataSearch::mediause() instead
342 */
343function ft_mediause($id, $ignore_perms = false)
344{
345    DebugHelper::dbgDeprecatedFunction(dokuwiki\Search\MetadataSearch::class . '::mediause()');
346    return (new dokuwiki\Search\MetadataSearch())->mediause($id, $ignore_perms);
347}
348
349/**
350 * Quicksearch for pagenames
351 *
352 * @param string $id page id
353 * @param bool $in_ns match namespace
354 * @param bool $in_title search in title
355 * @param int|string|null $after
356 * @param int|string|null $before
357 * @return string[]
358 *
359 * @deprecated 2026-04-07 use dokuwiki\Search\MetadataSearch::pageLookup() instead
360 */
361function ft_pageLookup($id, $in_ns = false, $in_title = false, $after = null, $before = null)
362{
363    DebugHelper::dbgDeprecatedFunction(dokuwiki\Search\MetadataSearch::class . '::pageLookup()');
364    return (new dokuwiki\Search\MetadataSearch())->pageLookup($id, $in_ns, $in_title, $after, $before);
365}
366
367/**
368 * Creates a snippet extract
369 *
370 * @param string $id page id
371 * @param array $highlight words to highlight
372 * @return string
373 *
374 * @deprecated 2026-04-07 use dokuwiki\Search\FulltextSearch::snippet() instead
375 */
376function ft_snippet($id, $highlight)
377{
378    DebugHelper::dbgDeprecatedFunction(dokuwiki\Search\FulltextSearch::class . '::snippet()');
379    return (new dokuwiki\Search\FulltextSearch())->snippet($id, $highlight);
380}
381
382/**
383 * Sort pages based on their namespace level first, then alphabetically
384 *
385 * @param string $a
386 * @param string $b
387 * @return int
388 *
389 * @deprecated 2026-04-07 use Utf8\Sort functions directly
390 */
391function ft_pagesorter($a, $b)
392{
393    DebugHelper::dbgDeprecatedFunction('Utf8\\Sort');
394    $diff = substr_count($a, ':') - substr_count($b, ':');
395    return $diff ?: dokuwiki\Utf8\Sort::strcmp($a, $b);
396}
397
398/**
399 * Wrap a search term in regex boundary checks
400 *
401 * @param string $term
402 * @return string
403 *
404 * @deprecated 2026-04-07 use dokuwiki\Search\FulltextSearch::snippetRePreprocess() instead
405 */
406function ft_snippet_re_preprocess($term)
407{
408    DebugHelper::dbgDeprecatedFunction(dokuwiki\Search\FulltextSearch::class . '::snippetRePreprocess()');
409    return (new dokuwiki\Search\FulltextSearch())->snippetRePreprocess($term);
410}
411
412/**
413 * Parse a search query into its components
414 *
415 * @param mixed $Indexer ignored (legacy parameter)
416 * @param string $query search query
417 * @return array parsed query structure
418 *
419 * @deprecated 2026-04-07 use dokuwiki\Search\Query\QueryParser::convert() instead
420 */
421function ft_queryParser($Indexer, $query)
422{
423    DebugHelper::dbgDeprecatedFunction(dokuwiki\Search\Query\QueryParser::class . '::convert()');
424    return (new dokuwiki\Search\Query\QueryParser())->convert($query);
425}
426