2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2005-04-12 02:07:16 +00:00
|
|
|
* See deferred.txt
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-04-14 23:10:40 +00:00
|
|
|
class SearchUpdate {
|
|
|
|
|
|
2003-12-03 00:42:31 +00:00
|
|
|
/* private */ var $mId = 0, $mNamespace, $mTitle, $mText;
|
2003-04-14 23:10:40 +00:00
|
|
|
/* private */ var $mTitleWords;
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
function SearchUpdate( $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() {
|
2004-09-24 16:24:43 +00:00
|
|
|
global $wgDBminWordLen, $wgContLang, $wgDisableSearchUpdate;
|
2003-11-09 11:45:12 +00:00
|
|
|
|
2003-12-03 00:42:31 +00:00
|
|
|
if( $wgDisableSearchUpdate || !$this->mId ) {
|
2003-11-09 11:45:12 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2004-08-22 17:24:50 +00:00
|
|
|
$fname = 'SearchUpdate::doUpdate';
|
2004-08-22 09:08:04 +00:00
|
|
|
wfProfileIn( $fname );
|
|
|
|
|
|
2004-08-21 09:51:01 +00:00
|
|
|
require_once( 'SearchEngine.php' );
|
2005-07-22 11:29:15 +00:00
|
|
|
$search = SearchEngine::create();
|
2004-12-02 19:09:40 +00:00
|
|
|
$lc = $search->legalSearchChars() . '&#;';
|
2004-07-10 03:09:26 +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,
|
|
|
|
|
Title::indexTitle( $this->mNamespace, $this->mTitle ));
|
2004-08-22 09:08:04 +00:00
|
|
|
wfProfileOut( $fname );
|
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
|
2004-09-24 16:24:43 +00:00
|
|
|
$text = $wgContLang->stripForSearch( $this->mText );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
wfProfileIn( $fname.'-regexps' );
|
2003-04-14 23:10:40 +00:00
|
|
|
$text = preg_replace( "/<\\/?\\s*[A-Za-z][A-Za-z0-9]*\\s*([^>]*?)>/",
|
2004-08-22 17:24:50 +00:00
|
|
|
' ', strtolower( " " . $text /*$this->mText*/ . " " ) ); # Strip HTML markup
|
2003-04-14 23:10:40 +00:00
|
|
|
$text = preg_replace( "/(^|\\n)\\s*==\\s+([^\\n]+)\\s+==\\s/sD",
|
|
|
|
|
"\\2 \\2 \\2 ", $text ); # Emphasize headings
|
|
|
|
|
|
|
|
|
|
# Strip external URLs
|
|
|
|
|
$uc = "A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\xA0-\\xFF";
|
|
|
|
|
$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 );
|
2004-08-22 09:08:04 +00:00
|
|
|
wfProfileOut( "$fname-regexps" );
|
2004-12-02 19:09:40 +00:00
|
|
|
$search->update($this->mId, Title::indexTitle( $this->mNamespace, $this->mTitle ),
|
|
|
|
|
$text);
|
2004-08-22 09:08:04 +00:00
|
|
|
wfProfileOut( $fname );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-27 19:51:47 +00:00
|
|
|
/**
|
|
|
|
|
* Placeholder class
|
|
|
|
|
* @package MediaWiki
|
|
|
|
|
*/
|
2004-09-30 19:18:47 +00:00
|
|
|
class SearchUpdateMyISAM extends SearchUpdate {
|
|
|
|
|
# Inherits everything
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
?>
|