2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2010-08-08 10:44:59 +00:00
|
|
|
* Search index updater
|
|
|
|
|
*
|
2005-04-12 02:07:16 +00:00
|
|
|
* See deferred.txt
|
2010-08-08 10:44:59 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Search
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Database independant search index updater
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Search
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2011-09-10 06:50:30 +00:00
|
|
|
class SearchUpdate implements DeferrableUpdate {
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2011-04-18 19:03:14 +00:00
|
|
|
private $mId = 0, $mNamespace, $mTitle, $mText;
|
|
|
|
|
private $mTitleWords;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2010-08-30 16:52:51 +00:00
|
|
|
function __construct( $id, $title, $text = false ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
$nt = Title::newFromText( $title );
|
2003-12-03 00:42:31 +00:00
|
|
|
if( $nt ) {
|
|
|
|
|
$this->mId = $id;
|
|
|
|
|
$this->mText = $text;
|
|
|
|
|
|
|
|
|
|
$this->mNamespace = $nt->getNamespace();
|
|
|
|
|
$this->mTitle = $nt->getText(); # Discard namespace
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2003-12-03 00:42:31 +00:00
|
|
|
$this->mTitleWords = $this->mTextWords = array();
|
|
|
|
|
} else {
|
|
|
|
|
wfDebug( "SearchUpdate object created with invalid title '$title'\n" );
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
function doUpdate() {
|
2005-12-04 18:27:59 +00:00
|
|
|
global $wgContLang, $wgDisableSearchUpdate;
|
2003-11-09 11:45:12 +00:00
|
|
|
|
2003-12-03 00:42:31 +00:00
|
|
|
if( $wgDisableSearchUpdate || !$this->mId ) {
|
2011-10-16 03:27:12 +00:00
|
|
|
return;
|
2003-11-09 11:45:12 +00:00
|
|
|
}
|
2010-12-07 10:51:57 +00:00
|
|
|
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
2004-08-22 09:08:04 +00:00
|
|
|
|
2005-07-22 11:29:15 +00:00
|
|
|
$search = SearchEngine::create();
|
2007-01-09 19:56:23 +00:00
|
|
|
$lc = SearchEngine::legalSearchChars() . '&#;';
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-06-01 02:31:45 +00:00
|
|
|
if( $this->mText === false ) {
|
2004-12-02 19:09:40 +00:00
|
|
|
$search->updateTitle($this->mId,
|
2010-03-09 04:19:55 +00:00
|
|
|
$search->normalizeText( Title::indexTitle( $this->mNamespace, $this->mTitle ) ) );
|
2010-12-07 10:51:57 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2003-04-14 23:10:40 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2003-11-09 11:45:12 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
# Language-specific strip/conversion
|
2010-02-02 15:09:01 +00:00
|
|
|
$text = $wgContLang->normalizeForSearch( $this->mText );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2010-12-07 10:51:57 +00:00
|
|
|
wfProfileIn( __METHOD__ . '-regexps' );
|
2009-11-04 15:18:30 +00:00
|
|
|
$text = preg_replace( "/<\\/?\\s*[A-Za-z][^>]*?>/",
|
2009-10-30 15:25:37 +00:00
|
|
|
' ', $wgContLang->lc( " " . $text . " " ) ); # Strip HTML markup
|
2005-11-03 23:27:36 +00:00
|
|
|
$text = preg_replace( "/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/sD",
|
|
|
|
|
"\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
# Strip external URLs
|
2011-11-30 00:37:35 +00:00
|
|
|
$uc = "A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\x80-\\xFF";
|
2003-04-14 23:10:40 +00:00
|
|
|
$protos = "http|https|ftp|mailto|news|gopher";
|
|
|
|
|
$pat = "/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
|
|
|
|
|
$text = preg_replace( $pat, "\\1 \\3", $text );
|
|
|
|
|
|
|
|
|
|
$p1 = "/([^\\[])\\[({$protos}):[{$uc}]+]/";
|
|
|
|
|
$p2 = "/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
|
|
|
|
|
$text = preg_replace( $p1, "\\1 ", $text );
|
|
|
|
|
$text = preg_replace( $p2, "\\1 \\3 ", $text );
|
|
|
|
|
|
|
|
|
|
# Internal image links
|
|
|
|
|
$pat2 = "/\\[\\[image:([{$uc}]+)\\.(gif|png|jpg|jpeg)([^{$uc}])/i";
|
|
|
|
|
$text = preg_replace( $pat2, " \\1 \\3", $text );
|
|
|
|
|
|
|
|
|
|
$text = preg_replace( "/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
|
|
|
|
|
"\\1\\2 \\2\\3", $text ); # Handle [[game]]s
|
|
|
|
|
|
|
|
|
|
# Strip all remaining non-search characters
|
|
|
|
|
$text = preg_replace( "/[^{$lc}]+/", " ", $text );
|
|
|
|
|
|
|
|
|
|
# Handle 's, s'
|
2004-08-22 09:08:04 +00:00
|
|
|
#
|
|
|
|
|
# $text = preg_replace( "/([{$lc}]+)'s /", "\\1 \\1's ", $text );
|
|
|
|
|
# $text = preg_replace( "/([{$lc}]+)s' /", "\\1s ", $text );
|
|
|
|
|
#
|
|
|
|
|
# These tail-anchored regexps are insanely slow. The worst case comes
|
|
|
|
|
# when Japanese or Chinese text (ie, no word spacing) is written on
|
|
|
|
|
# a wiki configured for Western UTF-8 mode. The Unicode characters are
|
|
|
|
|
# expanded to hex codes and the "words" are very long paragraph-length
|
|
|
|
|
# monstrosities. On a large page the above regexps may take over 20
|
|
|
|
|
# seconds *each* on a 1GHz-level processor.
|
|
|
|
|
#
|
|
|
|
|
# Following are reversed versions which are consistently fast
|
|
|
|
|
# (about 3 milliseconds on 1GHz-level processor).
|
|
|
|
|
#
|
|
|
|
|
$text = strrev( preg_replace( "/ s'([{$lc}]+)/", " s'\\1 \\1", strrev( $text ) ) );
|
|
|
|
|
$text = strrev( preg_replace( "/ 's([{$lc}]+)/", " s\\1", strrev( $text ) ) );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
|
|
|
|
# Strip wiki '' and '''
|
|
|
|
|
$text = preg_replace( "/''[']*/", " ", $text );
|
2010-12-07 10:51:57 +00:00
|
|
|
wfProfileOut( __METHOD__ . '-regexps' );
|
2007-04-10 02:18:42 +00:00
|
|
|
|
|
|
|
|
wfRunHooks( 'SearchUpdate', array( $this->mId, $this->mNamespace, $this->mTitle, &$text ) );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-04-10 02:18:42 +00:00
|
|
|
# Perform the actual update
|
2010-03-09 04:19:55 +00:00
|
|
|
$search->update($this->mId, $search->normalizeText( Title::indexTitle( $this->mNamespace, $this->mTitle ) ),
|
|
|
|
|
$search->normalizeText( $text ) );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-12-07 10:51:57 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-27 19:51:47 +00:00
|
|
|
/**
|
|
|
|
|
* Placeholder class
|
2010-08-08 10:44:59 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Search
|
2005-01-27 19:51:47 +00:00
|
|
|
*/
|
2004-09-30 19:18:47 +00:00
|
|
|
class SearchUpdateMyISAM extends SearchUpdate {
|
|
|
|
|
# Inherits everything
|
|
|
|
|
}
|