-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSphinxSearchUpdate.php
65 lines (53 loc) · 1.85 KB
/
SphinxSearchUpdate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Pluggable Sphinx search engine for MediaWiki 1.16+ and Sphinx 0.99+ (real-time indexing)
* http://wiki.4intra.net/SphinxSearchEngine
* (c) 2011, Vitaliy Filippov
* License: GPL 3.0 or later (see http://www.fsf.org/licenses/gpl.html)
*/
// 1.18 compatibility
if (!interface_exists('DeferrableUpdate'))
{
interface DeferrableUpdate
{
function doUpdate();
}
}
// Similar to standard SearchUpdate, but does not refuck the text
// using mysterious regexes, does not remove any links etc
class SearchUpdate implements DeferrableUpdate
{
var $mId, $mTitle, $mText;
function __construct($id, $title, $text = false)
{
$this->mTitle = $title instanceof Title ? $title : Title::newFromText($title);
if ($this->mTitle)
{
$this->mId = $id;
$this->mText = $text;
}
else
wfDebug(__CLASS__." object created with invalid title '$title'\n");
}
function doUpdate()
{
global $wgContLang, $wgDisableSearchUpdate, $wgVersion;
if ($wgDisableSearchUpdate || !$this->mId)
return false;
wfProfileIn(__METHOD__);
$search = SearchEngine::create();
if ($this->mText === false)
{
$a = new WikiPage($this->mTitle);
$this->mText = version_compare($wgVersion, '1.21', '>=') ? $a->getContent() : $a->getText();
}
if ($this->mText instanceof Content)
$this->mText = $this->mText->getTextForSearchIndex();
// Language-specific strip/conversion
$text = $wgContLang->normalizeForSearch($this->mText);
wfRunHooks('SearchUpdate', array($this->mId, $this->mTitle->getNamespace(), $this->mTitle->getText(), &$text));
// Perform the actual update
$search->update($this->mId, $this->mTitle, $text);
wfProfileOut(__METHOD__);
}
}