public function Fire() { if ($this->input->do == 'submit') { $bug = new Bug($this->input->bug_id); try { $bug->FetchInto(); } catch (phalanx\data\ModelException $e) { EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('BUG_ID_NOT_FOUND'))); return; } $body = trim($this->input->body); if (empty($body)) { EventPump::Pump()->RaiseEvent(new StandardErrorEvent(l10n::S('COMMENT_MISSING_BODY'))); return; } $comment = new Comment(); $comment->bug_id = $bug_id; $comment->post_user_id = Bugdar::$auth->current_user(); $comment->post_date = time(); $comment->body = $body; $comment->Insert(); $this->comment_id = $comment->comment_id; $search = new SearchEngine(); $search->IndexBug($bug); EventPump::Pump()->PostEvent(new StandardSuccessEvent('view_bug/' . $bug_id, l10n::S('USER_REGISTER_SUCCESS'))); } }
public function isBookingStillAvailable() { $searchEngine = new SearchEngine($this->searchCriteria); $availableRooms = $searchEngine->runSearchForRoom($this->room->id); if ($availableRooms == null) { $this->errors = $searchEngine->errors; return false; } $roomCount = sizeof($availableRooms); return $roomCount > 0; }
function perform() { // get the search terms that have already been validated... $this->_searchTerms = $this->_request->getValue("searchTerms"); // check if the search feature is disabled in this site... $config =& Config::getConfig(); if (!$config->getValue("search_engine_enabled")) { $this->_view = new ErrorView($this->_blogInfo, "error_search_engine_disabled"); $this->setCommonData(); return false; } // create the view and make sure that it hasn't been cached $this->_view = new BlogTemplatedView($this->_blogInfo, VIEW_SEARCH_TEMPLATE, array("searchTerms" => $this->_searchTerms)); if ($this->_view->isCached()) { return true; } $searchEngine = new SearchEngine(); $searchResults = $searchEngine->search($this->_blogInfo->getId(), $this->_searchTerms); // MARKWU: I add the searchterms variable for smarty/plog template $searchTerms = $searchEngine->getAdaptSearchTerms($this->_searchTerms); // if no search results, return an error message if (count($searchResults) == 0) { $this->_view = new ErrorView($this->_blogInfo, "error_no_search_results"); $this->setCommonData(); return true; } // if only one search result, we can see it straight away if (count($searchResults) == 1) { // we have to refill the $_REQUEST array, since the next action // is going to need some of the parameters $request =& HttpVars::getRequest(); $searchResult = array_pop($searchResults); $article = $searchResult->getArticle(); $request["articleId"] = $article->getId(); $request["blogId"] = $this->_blogInfo->getId(); HttpVars::setRequest($request); // since there is only one article, we can use the ViewArticleAction action // to display that article, instead of copy-pasting the code and doing it here. // You just have to love MVC and OOP :) return Controller::setForwardAction("ViewArticle"); } // or else, show a list with all the posts that match the requested // search terms $this->_view->setValue("searchresults", $searchResults); // MARKWU: Now, I can use the searchterms to get the keyword $this->_view->setValue("searchterms", $searchTerms); // MARKWU: $config =& Config::getConfig(); $urlmode = $config->getValue("request_format_mode"); $this->_view->setValue("urlmode", $urlmode); $this->setCommonData(); return true; }
/** * @dataProvider provideSearch * @covers SearchEngine::defaultPrefixSearch */ public function testSearchWithOffset(array $case) { $this->search->setLimitOffset(3, 1); $results = $this->search->defaultPrefixSearch($case['query']); $results = array_map(function (Title $t) { return $t->getPrefixedText(); }, $results); // We don't expect the first result when offsetting array_shift($case['results']); // And sometimes we expect a different last result $expected = isset($case['offsetresult']) ? array_merge($case['results'], $case['offsetresult']) : $case['results']; $this->assertEquals($expected, $results, $case[0]); }
protected function execute(InputInterface $input, OutputInterface $output) { $style = new OutputFormatterStyle('red', 'yellow', array('bold', 'blink')); $output->getFormatter()->setStyle('fire', $style); $style = new OutputFormatterStyle('green', 'default', array('bold')); $output->getFormatter()->setStyle('start', $style); $style = new OutputFormatterStyle('black', 'default', array('bold')); $output->getFormatter()->setStyle('end', $style); $searchEngine = new SearchEngine($this->getContainer()->get('doctrine')->getManager(), array()); $output->writeln('<fire>Clearing existing index</fire>'); $searchEngine->clearIndex(); $output->writeln('<start>Indexing started</start>'); $searchEngine->index(); $output->writeln('<end>Index generated successfully</end>'); }
public function goResult($term) { global $wgOut; # Try to go to page as entered. $t = Title::newFromText($term); # If the string cannot be used to create a title if (is_null($t)) { return $this->showResults($term); } # If there's an exact or very near match, jump right there. $t = SearchEngine::getNearMatch($term); if (!is_null($t)) { $wgOut->redirect($t->getFullURL()); return; } # No match, generate an edit URL $t = Title::newFromText($term); if (!is_null($t)) { global $wgGoToEdit; wfRunHooks('SpecialSearchNogomatch', array(&$t)); # If the feature is enabled, go straight to the edit page if ($wgGoToEdit) { $wgOut->redirect($t->getFullURL(array('action' => 'edit'))); return; } } }
function provideSearchOptionsTests() { $defaultNS = SearchEngine::defaultNamespaces(); $EMPTY_REQUEST = array(); $NO_USER_PREF = null; return array(array($EMPTY_REQUEST, $NO_USER_PREF, 'default', $defaultNS, 'Bug 33270: No request nor user preferences should give default profile'), array(array('ns5' => 1), $NO_USER_PREF, 'advanced', array(5), 'Web request with specific NS should override user preference'), array($EMPTY_REQUEST, array('searchNs2' => 1, 'searchNs14' => 1), 'advanced', array(2, 14), 'Bug 33583: search with no option should honor User search preferences')); }
/** * @param $context ResourceLoaderContext * @return array */ protected function getConfig($context) { global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension, $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgVariantArticlePath, $wgActionPaths, $wgUseAjax, $wgVersion, $wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgEnableMWSuggest, $wgSitename, $wgFileExtensions, $wgExtensionAssetsPath, $wgCookiePrefix, $wgResourceLoaderMaxQueryLength; $mainPage = Title::newMainPage(); /** * Namespace related preparation * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces. * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive. */ $namespaceIds = $wgContLang->getNamespaceIds(); $caseSensitiveNamespaces = array(); foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) { $namespaceIds[$wgContLang->lc($name)] = $index; if (!MWNamespace::isCapitalized($index)) { $caseSensitiveNamespaces[] = $index; } } // Build list of variables $vars = array('wgLoadScript' => $wgLoadScript, 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $wgStylePath, 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $wgArticlePath, 'wgScriptPath' => $wgScriptPath, 'wgScriptExtension' => $wgScriptExtension, 'wgScript' => $wgScript, 'wgVariantArticlePath' => $wgVariantArticlePath, 'wgActionPaths' => (object) $wgActionPaths, 'wgServer' => $wgServer, 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgVersion' => $wgVersion, 'wgEnableAPI' => $wgEnableAPI, 'wgEnableWriteAPI' => $wgEnableWriteAPI, 'wgDefaultDateFormat' => $wgContLang->getDefaultDateFormat(), 'wgMonthNames' => $wgContLang->getMonthNamesArray(), 'wgMonthNamesShort' => $wgContLang->getMonthAbbreviationsArray(), 'wgMainPageTitle' => $mainPage ? $mainPage->getPrefixedText() : null, 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgSiteName' => $wgSitename, 'wgFileExtensions' => array_values($wgFileExtensions), 'wgDBname' => $wgDBname, 'wgFileCanRotate' => BitmapHandler::canRotate(), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $wgExtensionAssetsPath, 'wgCookiePrefix' => $wgCookiePrefix, 'wgResourceLoaderMaxQueryLength' => $wgResourceLoaderMaxQueryLength, 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgSassParams' => SassUtil::getSassSettings()); if ($wgUseAjax && $wgEnableMWSuggest) { $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate(); } wfRunHooks('ResourceLoaderGetConfigVars', array(&$vars)); return $vars; }
static function getSearchEngine() { if (!self::$searchEngine) { self::$searchEngine = SearchEngine::create(); } return self::$searchEngine; }
/** * Loads the search type objects. */ public static function loadSearchTypeObjects() { if (self::$searchTypeObjects !== null) { return; } // get cache WCF::getCache()->addResource('searchableMessageTypes-' . PACKAGE_ID, WCF_DIR . 'cache/cache.searchableMessageTypes-' . PACKAGE_ID . '.php', WCF_DIR . 'lib/system/cache/CacheBuilderSearchableMessageType.class.php'); self::$searchTypeData = WCF::getCache()->get('searchableMessageTypes-' . PACKAGE_ID); // get objects self::$searchTypeObjects = array(); foreach (self::$searchTypeData as $type) { // calculate class path $path = ''; if (empty($type['packageDir'])) { $path = WCF_DIR; } else { $path = FileUtil::getRealPath(WCF_DIR . $type['packageDir']); } // include class file if (!file_exists($path . $type['classPath'])) { throw new SystemException("unable to find class file '" . $path . $type['classPath'] . "'", 11000); } require_once $path . $type['classPath']; // create instance $className = StringUtil::getClassName($type['classPath']); if (!class_exists($className)) { throw new SystemException("unable to find class '" . $className . "'", 11001); } self::$searchTypeObjects[$type['typeName']] = new $className(); } }
function parseQuery($filteredText, $fulltext) { global $wgContLang; $lc = SearchEngine::legalSearchChars(); $searchon = ''; $this->searchTerms = array(); # FIXME: This doesn't handle parenthetical expressions. if (preg_match_all('/([-+<>~]?)(([' . $lc . ']+)(\\*?)|"[^"]*")/', $filteredText, $m, PREG_SET_ORDER)) { foreach ($m as $terms) { if ($searchon !== '') { $searchon .= ' '; } if ($this->strictMatching && $terms[1] == '') { $terms[1] = '+'; } $searchon .= $terms[1] . $wgContLang->stripForSearch($terms[2]); if (!empty($terms[3])) { $regexp = preg_quote($terms[3], '/'); if ($terms[4]) { $regexp .= "[0-9A-Za-z_]+"; } } else { $regexp = preg_quote(str_replace('"', '', $terms[2]), '/'); } $this->searchTerms[] = $regexp; } wfDebug("Would search with '{$searchon}'\n"); wfDebug("Match with /\\b" . implode('\\b|\\b', $this->searchTerms) . "\\b/\n"); } else { wfDebug("Can't understand search query '{$this->filteredText}'\n"); } $searchon = preg_replace('/(\\s+)/', '&', $searchon); $searchon = $this->db->strencode($searchon); return $searchon; }
public function execute($parameters) { global $wgOut, $wgRequest, $wgDisableTextSearch, $wgScript; $this->setHeaders(); list($limit, $offset) = wfCheckLimits(); $wgOut->addWikiText(wfMsgForContentNoTrans('proofreadpage_specialpage_text')); $this->searchList = null; $this->searchTerm = $wgRequest->getText('key'); $this->suppressSqlOffset = false; if (!$wgDisableTextSearch) { $self = $this->getTitle(); $wgOut->addHTML(Xml::openElement('form', array('action' => $wgScript)) . Html::hidden('title', $this->getTitle()->getPrefixedText()) . Xml::input('limit', false, $limit, array('type' => 'hidden')) . Xml::openElement('fieldset') . Xml::element('legend', null, wfMsg('proofreadpage_specialpage_legend')) . Xml::input('key', 20, $this->searchTerm) . ' ' . Xml::submitButton(wfMsg('ilsubmit')) . Xml::closeElement('fieldset') . Xml::closeElement('form')); if ($this->searchTerm) { $index_namespace = $this->index_namespace; $index_ns_index = MWNamespace::getCanonicalIndex(strtolower(str_replace(' ', '_', $index_namespace))); $searchEngine = SearchEngine::create(); $searchEngine->setLimitOffset($limit, $offset); $searchEngine->setNamespaces(array($index_ns_index)); $searchEngine->showRedirects = false; $textMatches = $searchEngine->searchText($this->searchTerm); $escIndex = preg_quote($index_namespace, '/'); $this->searchList = array(); while ($result = $textMatches->next()) { $title = $result->getTitle(); if ($title->getNamespace() == $index_ns_index) { array_push($this->searchList, $title->getDBkey()); } } $this->suppressSqlOffset = true; } } parent::execute($parameters); }
public static function logHttpReferer() { global $cookie; if (!isset($cookie->id_connections) or !Validate::isUnsignedId($cookie->id_connections)) { return false; } if (!isset($_SERVER['HTTP_REFERER']) and !Configuration::get('TRACKING_DIRECT_TRAFFIC')) { return false; } $source = new ConnectionsSource(); if (isset($_SERVER['HTTP_REFERER']) and Validate::isAbsoluteUrl($_SERVER['HTTP_REFERER'])) { if (preg_replace('/^www./', '', parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST)) == preg_replace('/^www./', '', Tools::getHttpHost(false, false)) and !strncmp(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH), parse_url('http://' . Tools::getHttpHost(false, false) . __PS_BASE_URI__, PHP_URL_PATH), strlen(__PS_BASE_URI__))) { return false; } if (Validate::isAbsoluteUrl(strval($_SERVER['HTTP_REFERER']))) { $source->http_referer = strval($_SERVER['HTTP_REFERER']); $source->keywords = trim(SearchEngine::getKeywords(strval($_SERVER['HTTP_REFERER']))); if (!Validate::isMessage($source->keywords)) { return false; } } } $source->id_connections = intval($cookie->id_connections); $source->request_uri = Tools::getHttpHost(false, false); if (isset($_SERVER['REDIRECT_URL'])) { $source->request_uri .= strval($_SERVER['REDIRECT_URL']); } elseif (isset($_SERVER['REQUEST_URI'])) { $source->request_uri .= strval($_SERVER['REQUEST_URI']); } if (!Validate::isUrl($source->request_uri)) { unset($source->request_uri); } return $source->add(); }
/** * Do not go to a near match if query prefixed with ~ * * @param $searchterm String * @return Title */ public static function getNearMatch( $searchterm ) { if ( $searchterm[ 0 ] === '~' ) { return null; } else { return parent::getNearMatch( $searchterm ); } }
/** * carry out the search and execute it */ function perform() { $search = new SearchEngine(); // execute the search and check if there is any result $results = $search->siteSearch($this->_searchTerms); if (!$results || empty($results)) { // if not, then quit $this->_view = new SummaryView("summaryerror"); $this->_view->setErrorMessage($this->_locale->tr("error_no_search_results")); return false; } // but if so, then continue... $this->_view = new SummaryView("searchresults"); $this->_view->setValue("searchresults", $results); $this->setCommonData(); return true; }
/** * @return string */ function efOpenSearchXmlTemplate() { global $wgCanonicalServer, $wgScriptPath; $ns = implode( '|', SearchEngine::defaultNamespaces() ); if( !$ns ) { $ns = '0'; } return $wgCanonicalServer . $wgScriptPath . '/api.php?action=opensearch&format=xml&search={searchTerms}&namespace=' . $ns; }
public function getFieldsForSearchIndex(SearchEngine $engine) { $fields['file_media_type'] = $engine->makeSearchFieldMapping('file_media_type', SearchIndexField::INDEX_TYPE_KEYWORD); $fields['file_media_type']->setFlag(SearchIndexField::FLAG_CASEFOLD); $fields['file_mime'] = $engine->makeSearchFieldMapping('file_mime', SearchIndexField::INDEX_TYPE_SHORT_TEXT); $fields['file_mime']->setFlag(SearchIndexField::FLAG_CASEFOLD); $fields['file_size'] = $engine->makeSearchFieldMapping('file_size', SearchIndexField::INDEX_TYPE_INTEGER); $fields['file_width'] = $engine->makeSearchFieldMapping('file_width', SearchIndexField::INDEX_TYPE_INTEGER); $fields['file_height'] = $engine->makeSearchFieldMapping('file_height', SearchIndexField::INDEX_TYPE_INTEGER); $fields['file_bits'] = $engine->makeSearchFieldMapping('file_bits', SearchIndexField::INDEX_TYPE_INTEGER); $fields['file_resolution'] = $engine->makeSearchFieldMapping('file_resolution', SearchIndexField::INDEX_TYPE_INTEGER); $fields['file_text'] = $engine->makeSearchFieldMapping('file_text', SearchIndexField::INDEX_TYPE_TEXT); return $fields; }
public static function provideSearchOptionsTests() { $defaultNS = SearchEngine::defaultNamespaces(); $EMPTY_REQUEST = array(); $NO_USER_PREF = null; return array(array($EMPTY_REQUEST, $NO_USER_PREF, 'default', $defaultNS, 'Bug 33270: No request nor user preferences should give default profile'), array(array('ns5' => 1), $NO_USER_PREF, 'advanced', array(5), 'Web request with specific NS should override user preference'), array($EMPTY_REQUEST, array('searchNs2' => 1, 'searchNs14' => 1) + array_fill_keys(array_map(function ($ns) { return "searchNs{$ns}"; }, $defaultNS), 0), 'advanced', array(2, 14), 'Bug 33583: search with no option should honor User search preferences' . ' and have all other namespace disabled')); }
public function DoCheck() { AssetLoadManager::register('tableList'); // Search engine $vo_search_config_settings = SearchEngine::checkPluginConfiguration(); $this->view->setVar('search_config_settings', $vo_search_config_settings); $this->view->setVar('search_config_engine_name', SearchEngine::getPluginEngineName()); // Media $t_media = new Media(); $va_plugin_names = $t_media->getPluginNames(); $va_plugins = array(); foreach ($va_plugin_names as $vs_plugin_name) { if ($va_plugin_status = $t_media->checkPluginStatus($vs_plugin_name)) { $va_plugins[$vs_plugin_name] = $va_plugin_status; } } $this->view->setVar('media_config_plugin_list', $va_plugins); // PDF Rendering $t_pdf_renderer = new PDFRenderer(); $va_plugin_names = PDFRenderer::getAvailablePDFRendererPlugins(); $va_plugins = array(); foreach ($va_plugin_names as $vs_plugin_name) { if ($va_plugin_status = $t_pdf_renderer->checkPluginStatus($vs_plugin_name)) { $va_plugins[$vs_plugin_name] = $va_plugin_status; } } $this->view->setVar('pdf_renderer_config_plugin_list', $va_plugins); // Application plugins $va_plugin_names = ApplicationPluginManager::getPluginNames(); $va_plugins = array(); foreach ($va_plugin_names as $vs_plugin_name) { if ($va_plugin_status = ApplicationPluginManager::checkPluginStatus($vs_plugin_name)) { $va_plugins[$vs_plugin_name] = $va_plugin_status; } } $this->view->setVar('application_config_plugin_list', $va_plugins); // Barcode generation $vb_gd_is_available = caMediaPluginGDInstalled(true); $va_barcode_components = array(); $va_gd = array('name' => 'GD', 'description' => _t('GD is a graphics processing library required for all barcode generation.')); if (!$vb_gd_is_available) { $va_gd['errors'][] = _t('Is not installed; barcode printing will not be possible.'); } $va_gd['available'] = $vb_gd_is_available; $va_barcode_components['GD'] = $va_gd; $this->view->setVar('barcode_config_component_list', $va_barcode_components); // General system configuration issues if (!(bool) $this->request->config->get('dont_do_expensive_configuration_checks_in_web_ui')) { ConfigurationCheck::performExpensive(); if (ConfigurationCheck::foundErrors()) { $this->view->setVar('configuration_check_errors', ConfigurationCheck::getErrors()); } } $this->render('config_check_html.php'); }
public static function onResourceLoaderGetConfigVarsWithContext(&$vars, $context) { global $wgUseAjax; $skin = $context->getSkin(); if ($skin == 'monobook' || $skin == 'uncyclopedia') { if (!empty($wgUseAjax)) { $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate(); } } return true; }
function efGoToCategory_SpecialSearchNogomatch($t) { global $wgOut, $wgRequest; $term = $wgRequest->getText('search'); if (!empty($term) && strpos('category:', strtolower($term)) !== 0) { $term = "Category:{$term}"; } $title = SearchEngine::getNearMatch($term); if (!is_null($title)) { $wgOut->redirect($title->getFullURL()); } return true; }
function __construct($target, $table) { $fp = @fsockopen(common_config('sphinx', 'server'), common_config('sphinx', 'port')); if (!$fp) { $this->connected = false; return; } fclose($fp); parent::__construct($target, $table); $this->sphinx = new SphinxClient(); $this->sphinx->setServer(common_config('sphinx', 'server'), common_config('sphinx', 'port')); $this->connected = true; }
public function testAugmentorSearch() { $this->search->setNamespaces([0, 1, 4]); $resultSet = $this->search->searchText('smithee'); // Not using mock since PHPUnit mocks do not work properly with references in params $this->mergeMwGlobalArrayValue('wgHooks', ['SearchResultsAugment' => [[$this, 'addAugmentors']]]); $this->search->augmentSearchResults($resultSet); for ($result = $resultSet->next(); $result; $result = $resultSet->next()) { $id = $result->getTitle()->getArticleID(); $augmentData = "Result:{$id}:" . $result->getTitle()->getText(); $augmentData2 = "Result2:{$id}:" . $result->getTitle()->getText(); $this->assertEquals(['testSet' => $augmentData, 'testRow' => $augmentData2], $result->getExtensionData()); } }
/** * @param ApiPageSet $resultPageSet */ private function run($resultPageSet = null) { $params = $this->extractRequestParams(); $search = $params['search']; $limit = $params['limit']; $namespaces = $params['namespace']; $offset = $params['offset']; $searchEngine = SearchEngine::create(); $searchEngine->setLimitOffset($limit + 1, $offset); $searchEngine->setNamespaces($namespaces); $titles = $searchEngine->extractTitles($searchEngine->completionSearchWithVariants($search)); if ($resultPageSet) { $resultPageSet->setRedirectMergePolicy(function (array $current, array $new) { if (!isset($current['index']) || $new['index'] < $current['index']) { $current['index'] = $new['index']; } return $current; }); if (count($titles) > $limit) { $this->setContinueEnumParameter('offset', $offset + $params['limit']); array_pop($titles); } $resultPageSet->populateFromTitles($titles); foreach ($titles as $index => $title) { $resultPageSet->setGeneratorData($title, array('index' => $index + $offset + 1)); } } else { $result = $this->getResult(); $count = 0; foreach ($titles as $title) { if (++$count > $limit) { $this->setContinueEnumParameter('offset', $offset + $params['limit']); break; } $vals = array('ns' => intval($title->getNamespace()), 'title' => $title->getPrefixedText()); if ($title->isSpecialPage()) { $vals['special'] = true; } else { $vals['pageid'] = intval($title->getArticleId()); } $fit = $result->addValue(array('query', $this->getModuleName()), null, $vals); if (!$fit) { $this->setContinueEnumParameter('offset', $offset + $count - 1); break; } } $result->addIndexedTagName(array('query', $this->getModuleName()), $this->getModulePrefix()); } }
public function Fire() { if ($this->input->do == 'search') { $search = new SearchEngine(); $results = $search->SearchByQueryString($this->input->query_string); $hits = array(); $id_list = array(); foreach ($results as $result) { $hits[$result->bug_id] = $result; $id_list[] = $result->bug_id; } if (count($id_list) < 1) { return; } $bugs = Bugdar::$db->Query("\n SELECT bugs.*, users.alias as reporting_alias\n FROM " . TABLE_PREFIX . "bugs bugs\n LEFT JOIN " . TABLE_PREFIX . "users users\n ON (bugs.reporting_user_id = users.user_id)\n WHERE bugs.bug_id IN (" . implode(',', $id_list) . ")\n LIMIT 30\n "); while ($bug = $bugs->FetchObject()) { $lucene_hit = $hits[$bug->bug_id]; $hits[$bug->bug_id] = $bug; $hits[$bug->bug_id]->lucene_hit = $lucene_hit; $hits[$bug->bug_id]->score = $lucene_hit->score; } $this->hits = $hits; } }
/** * @param array $terms Terms to highlight * @return string Highlighted text snippet, null (and not '') if not supported */ function getTextSnippet($terms) { global $wgAdvancedSearchHighlighting; $this->initText(); // TODO: make highliter take a content object. Make ContentHandler a factory for SearchHighliter. list($contextlines, $contextchars) = $this->searchEngine->userHighlightPrefs(); $h = new SearchHighlighter(); if (count($terms) > 0) { if ($wgAdvancedSearchHighlighting) { return $h->highlightText($this->mText, $terms, $contextlines, $contextchars); } else { return $h->highlightSimple($this->mText, $terms, $contextlines, $contextchars); } } else { return $h->highlightNone($this->mText, $contextlines, $contextchars); } }
private function run($resultPageSet = null) { global $wgUser; // XX Added to minimize perf issues with full text searching if ($wgUser->isAnon()) { $this->dieUsage("Search query api is disabled", 'param-search'); } $params = $this->extractRequestParams(); $limit = $params['limit']; $query = $params['search']; if (is_null($query) || empty($query)) { $this->dieUsage("empty search string is not allowed", 'param-search'); } $search = SearchEngine::create(); $search->setLimitOffset($limit + 1, $params['offset']); $search->setNamespaces($params['namespace']); $search->showRedirects = $params['redirects']; if ($params['what'] == 'text') { $matches = $search->searchText($query); } else { $matches = $search->searchTitle($query); } $data = array(); $count = 0; while ($result = $matches->next()) { if (++$count > $limit) { // We've reached the one extra which shows that there are additional items to be had. Stop here... $this->setContinueEnumParameter('offset', $params['offset'] + $params['limit']); break; } $title = $result->getTitle(); if (is_null($resultPageSet)) { $data[] = array('ns' => intval($title->getNamespace()), 'title' => $title->getPrefixedText()); } else { $data[] = $title; } } if (is_null($resultPageSet)) { $result = $this->getResult(); $result->setIndexedTagName($data, 'p'); $result->addValue('query', $this->getModuleName(), $data); } else { $resultPageSet->populateFromTitles($data); } }
public static function logHttpReferer(Cookie $cookie = null) { if (!$cookie) { $cookie = Context::getContext()->cookie; } if (!isset($cookie->id_connections) || !Validate::isUnsignedId($cookie->id_connections)) { return false; } // If the referrer is not correct, we drop the connection if (isset($_SERVER['HTTP_REFERER']) && !Validate::isAbsoluteUrl($_SERVER['HTTP_REFERER'])) { return false; } // If there is no referrer and we do not want to save direct traffic (as opposed to referral traffic), we drop the connection if (!isset($_SERVER['HTTP_REFERER']) && !Configuration::get('TRACKING_DIRECT_TRAFFIC')) { return false; } $source = new ConnectionsSource(); // There are a few more operations if there is a referrer if (isset($_SERVER['HTTP_REFERER'])) { // If the referrer is internal (i.e. from your own website), then we drop the connection $parsed = parse_url($_SERVER['HTTP_REFERER']); $parsed_host = parse_url(Tools::getProtocol() . Tools::getHttpHost(false, false) . __PS_BASE_URI__); if (!isset($parsed['host']) || (!isset($parsed['path']) || !isset($parsed_host['path']))) { return false; } if (preg_replace('/^www./', '', $parsed['host']) == preg_replace('/^www./', '', Tools::getHttpHost(false, false)) && !strncmp($parsed['path'], $parsed_host['path'], strlen(__PS_BASE_URI__))) { return false; } $source->http_referer = substr($_SERVER['HTTP_REFERER'], 0, ConnectionsSource::$uri_max_size); $source->keywords = substr(trim(SearchEngine::getKeywords($_SERVER['HTTP_REFERER'])), 0, ConnectionsSource::$uri_max_size); } $source->id_connections = (int) $cookie->id_connections; $source->request_uri = Tools::getHttpHost(false, false); if (isset($_SERVER['REQUEST_URI'])) { $source->request_uri .= $_SERVER['REQUEST_URI']; } elseif (isset($_SERVER['REDIRECT_URL'])) { $source->request_uri .= $_SERVER['REDIRECT_URL']; } if (!Validate::isUrl($source->request_uri)) { $source->request_uri = ''; } $source->request_uri = substr($source->request_uri, 0, ConnectionsSource::$uri_max_size); return $source->add(); }
function parseQuery($filteredText, $fulltext) { global $wgDBminWordLen, $wgContLang; $field = $this->getIndexField($fulltext); # on non mysql4 database: get list of words we don't want to search for require_once 'FulltextStoplist.php'; $lc = SearchEngine::legalSearchChars() . '()'; $q = preg_replace("/([()])/", " \\1 ", $filteredText); $q = preg_replace("/\\s+/", " ", $q); $w = explode(' ', trim($q)); $last = $cond = ''; foreach ($w as $word) { $word = $wgContLang->stripForSearch($word); if ('and' == $word || 'or' == $word || 'not' == $word || '(' == $word || ')' == $word) { $cond .= ' ' . strtoupper($word); $last = ''; } else { if (strlen($word) < $wgDBminWordLen) { continue; } else { if (FulltextStoplist::inList($word)) { continue; } else { if ('' != $last) { $cond .= ' AND'; } $cond .= " (MATCH ({$field}) AGAINST ('" . $this->db->strencode($word) . "'))"; $last = $word; $this->searchTerms[] = "\\b" . preg_quote($word, '/') . "\\b"; } } } } if (0 == count($this->searchTerms)) { # No searchable terms remaining. # We have to return a term for the query or we get an SQL error. return "0"; } return '(' . $cond . ' )'; }
public static function logHttpReferer(Cookie $cookie = null) { if (!$cookie) { $cookie = Context::getContext()->cookie; } if (!isset($cookie->id_connections) || !Validate::isUnsignedId($cookie->id_connections)) { return false; } if (!isset($_SERVER['HTTP_REFERER']) && !Configuration::get('TRACKING_DIRECT_TRAFFIC')) { return false; } $source = new ConnectionsSource(); if (isset($_SERVER['HTTP_REFERER']) && Validate::isAbsoluteUrl($_SERVER['HTTP_REFERER'])) { $parsed = parse_url($_SERVER['HTTP_REFERER']); $parsed_host = parse_url(Tools::getProtocol() . Tools::getHttpHost(false, false) . __PS_BASE_URI__); if (preg_replace('/^www./', '', $parsed['host']) == preg_replace('/^www./', '', Tools::getHttpHost(false, false)) && !strncmp($parsed['path'], $parsed_host['path'], strlen(__PS_BASE_URI__))) { return false; } if (Validate::isAbsoluteUrl(strval($_SERVER['HTTP_REFERER']))) { $source->http_referer = substr(strval($_SERVER['HTTP_REFERER']), 0, ConnectionsSource::$uri_max_size); $source->keywords = trim(SearchEngine::getKeywords(strval($_SERVER['HTTP_REFERER']))); if (!Validate::isMessage($source->keywords)) { return false; } } } $source->id_connections = (int) $cookie->id_connections; $source->request_uri = Tools::getHttpHost(false, false); if (isset($_SERVER['REDIRECT_URL'])) { $source->request_uri .= strval($_SERVER['REDIRECT_URL']); } elseif (isset($_SERVER['REQUEST_URI'])) { $source->request_uri .= strval($_SERVER['REQUEST_URI']); } if (!Validate::isUrl($source->request_uri)) { $source->request_uri = ''; } $source->request_uri = substr($source->request_uri, 0, ConnectionsSource::$uri_max_size); return $source->add(); }