- function showResults()
- {
- global $wgUser, $wgTitle, $wgOut, $wgLang, $wgDisableTextSearch;
- $fname = "SearchEngine::showResults";
-
- $search = $_REQUEST['search'];
-
- $powersearch = $this->powersearch(); /* Need side-effects here? */
-
- $wgOut->setPageTitle( wfMsg( "searchresults" ) );
- $q = wfMsg( "searchquery", htmlspecialchars( $this->mUsertext ) );
- $wgOut->setSubtitle( $q );
- $wgOut->setArticleFlag( false );
- $wgOut->setRobotpolicy( "noindex,nofollow" );
-
- $sk = $wgUser->getSkin();
- $text = wfMsg( "searchresulttext", $sk->makeKnownLink(
- wfMsg( "searchhelppage" ), wfMsg( "searchingwikipedia" ) ) );
- $wgOut->addHTML( $text );
-
- $this->parseQuery();
- if ( "" == $this->mTitlecond || "" == $this->mTextcond ) {
- $wgOut->addHTML( "<h2>" . wfMsg( "badquery" ) . "</h2>\n" .
- "<p>" . wfMsg( "badquerytext" ) );
- return;
- }
- list( $limit, $offset ) = wfCheckLimits( 20, "searchlimit" );
-
- $searchnamespaces = $this->queryNamespaces();
- $redircond = $this->searchRedirects();
-
- $sql = "SELECT cur_id,cur_namespace,cur_title," .
- "cur_text FROM cur,searchindex " .
- "WHERE cur_id=si_page AND {$this->mTitlecond} " .
- "{$searchnamespaces} {$redircond}" .
- "LIMIT {$offset}, {$limit}";
- $res1 = wfQuery( $sql, $fname );
- $num = wfNumRows($res1);
-
- if ( $wgDisableTextSearch ) {
- $res2 = 0;
- } else {
- $sql = "SELECT cur_id,cur_namespace,cur_title," .
- "cur_text FROM cur,searchindex " .
- "WHERE cur_id=si_page AND {$this->mTextcond} " .
- "{$searchnamespaces} {$redircond} " .
- "LIMIT {$offset}, {$limit}";
- $res2 = wfQuery( $sql, $fname );
- $num = $num + wfNumRows($res2);
- }
-
- if ( $num == $limit ) {
- $top = wfShowingResults( $offset, $limit);
- } else {
- $top = wfShowingResultsNum( $offset, $limit, $num );
- }
- $wgOut->addHTML( "<p>{$top}\n" );
-
- # For powersearch
-
- $a2l = "" ;
- $akk = array_keys( $this->addtoquery ) ;
- foreach ( $akk AS $ak ) {
- $a2l .= "&{$ak}={$this->addtoquery[$ak]}" ;
- }
-
- $sl = wfViewPrevNext( $offset, $limit, "",
- "search=" . wfUrlencode( $this->mUsertext ) . $a2l );
- $wgOut->addHTML( "<br>{$sl}\n" );
-
- $foundsome = false;
-
- if ( 0 == wfNumRows( $res1 ) ) {
- $wgOut->addHTML( "<h2>" . wfMsg( "notitlematches" ) .
- "</h2>\n" );
- } else {
- $foundsome = true;
- $off = $offset + 1;
- $wgOut->addHTML( "<h2>" . wfMsg( "titlematches" ) .
- "</h2>\n<ol start='{$off}'>" );
-
- while ( $row = wfFetchObject( $res1 ) ) {
- $this->showHit( $row );
+ /**
+ * Set the maximum number of results to return
+ * and how many to skip before returning the first.
+ *
+ * @param int $limit
+ * @param int $offset
+ * @access public
+ */
+ function setLimitOffset( $limit, $offset = 0 ) {
+ $this->limit = IntVal( $limit );
+ $this->offset = IntVal( $offset );
+ }
+
+ /**
+ * Set which namespaces the search should include.
+ * Give an array of namespace index numbers.
+ *
+ * @param array $namespaces
+ * @access public
+ */
+ function setNamespaces( $namespaces ) {
+ $this->namespaces = $namespaces;
+ }
+
+ /**
+ * Make a list of searchable namespaces and their canonical names.
+ * @return array
+ * @access public
+ */
+ function searchableNamespaces() {
+ global $wgContLang;
+ $arr = array();
+ foreach( $wgContLang->getNamespaces() as $ns => $name ) {
+ if( $ns >= NS_MAIN ) {
+ $arr[$ns] = $name;