$profile = new ProfileSection( __METHOD__ );
$search = $this->getSearchEngine();
- // Request an extra result to determine whether a "next page" link is useful
- $search->setLimitOffset( $this->limit + 1, $this->offset );
+ $search->setLimitOffset( $this->limit, $this->offset );
$search->setNamespaces( $this->namespaces );
$this->saveNamespaces();
$search->prefix = $this->mPrefix;
$rewritten = $search->replacePrefixes( $term );
$titleMatches = $search->searchTitle( $rewritten );
- if ( !( $titleMatches instanceof SearchResultTooMany ) ) {
- $textMatches = $search->searchText( $rewritten );
- }
+ $textMatches = $search->searchText( $rewritten );
$textStatus = null;
if ( $textMatches instanceof Status ) {
)
)
);
+
+ // Get number of results
+ $titleMatchesNum = $textMatchesNum = $numTitleMatches = $numTextMatches = 0;
+ if ( $titleMatches ) {
+ $titleMatchesNum = $titleMatches->numRows();
+ $numTitleMatches = $titleMatches->getTotalHits();
+ }
+ if ( $textMatches ) {
+ $textMatchesNum = $textMatches->numRows();
+ $numTextMatches = $textMatches->getTotalHits();
+ }
+ $num = $titleMatchesNum + $textMatchesNum;
+ $totalRes = $numTitleMatches + $numTextMatches;
+
$out->addHtml(
# This is an awful awful ID name. It's not a table, but we
# named it poorly from when this was a table so now we're
# stuck with it
Xml::openElement( 'div', array( 'id' => 'mw-search-top-table' ) ) .
- $this->shortDialog( $term ) .
- Xml::closeElement( 'div' )
+ $this->shortDialog( $term, $num, $totalRes ) .
+ Xml::closeElement( 'div' ) .
+ $this->formHeader( $term ) .
+ Xml::closeElement( 'form' )
);
- // Sometimes the search engine knows there are too many hits
- if ( $titleMatches instanceof SearchResultTooMany ) {
- $out->wrapWikiMsg( "==$1==\n", 'toomanymatches' );
-
- return;
- }
-
$filePrefix = $wgContLang->getFormattedNsText( NS_FILE ) . ':';
if ( trim( $term ) === '' || $filePrefix === trim( $term ) ) {
- $out->addHTML( $this->formHeader( $term, 0, 0 ) );
- $out->addHtml( $this->getProfileForm( $this->profile, $term ) );
- $out->addHTML( '</form>' );
-
// Empty query -- straight view of search form
return;
}
- // Get number of results
- $titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0;
- $textMatchesNum = $textMatches ? $textMatches->numRows() : 0;
- // Total initial query matches (possible false positives)
- $num = $titleMatchesNum + $textMatchesNum;
-
- // Get total actual results (after second filtering, if any)
- $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
- $titleMatches->getTotalHits() : $titleMatchesNum;
- $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
- $textMatches->getTotalHits() : $textMatchesNum;
-
- // get total number of results if backend can calculate it
- $totalRes = 0;
- if ( $titleMatches && !is_null( $titleMatches->getTotalHits() ) ) {
- $totalRes += $titleMatches->getTotalHits();
- }
- if ( $textMatches && !is_null( $textMatches->getTotalHits() ) ) {
- $totalRes += $textMatches->getTotalHits();
- }
-
- // show number of results and current offset
- $out->addHTML( $this->formHeader( $term, $num, $totalRes ) );
- $out->addHtml( $this->getProfileForm( $this->profile, $term ) );
-
- $out->addHtml( Xml::closeElement( 'form' ) );
$out->addHtml( "<div class='searchresults'>" );
// prev/next links
$this->offset,
$this->limit,
$this->powerSearchOptions() + array( 'search' => $term ),
- max( $titleMatchesNum, $textMatchesNum ) <= $this->limit
+ $this->limit + $this->offset >= $totalRes
);
}
wfRunHooks( 'SpecialSearchResults', array( $term, &$titleMatches, &$textMatches ) );
if ( $num === 0 ) {
if ( $textStatus ) {
$out->addHTML( '<div class="error">' .
- htmlspecialchars( $textStatus->getWikiText( 'search-error' ) ) . '</div>' );
+ $textStatus->getMessage( 'search-error' ) . '</div>' );
} else {
$out->wrapWikiMsg( "<p class=\"mw-search-nonefound\">\n$1</p>",
array( 'search-nonefound', wfEscapeWikiText( $term ) ) );
if ( $title->isKnown() ) {
$messageName = 'searchmenu-exists';
- } elseif ( $title->userCan( 'create', $this->getUser() ) ) {
+ } elseif ( $title->quickUserCan( 'create', $this->getUser() ) ) {
$messageName = 'searchmenu-new';
} else {
$messageName = 'searchmenu-new-nocreate';
if ( $user->isLoggedIn() &&
!is_null( $request->getVal( 'nsRemember' ) ) &&
- $user->matchEditToken( $request->getVal( 'nsToken' ) )
+ $user->matchEditToken(
+ $request->getVal( 'nsToken' ),
+ 'searchnamespace',
+ $request
+ )
) {
// Reset namespace preferences: namespaces are not searched
// when they're not mentioned in the URL parameters.
$out = "<ul class='mw-search-results'>\n";
$result = $matches->next();
- $count = 0;
- while ( $result && $count < $this->limit ) {
+ while ( $result ) {
$out .= $this->showHit( $result, $terms );
$result = $matches->next();
- $count++;
}
$out .= "</ul>\n";
return $out;
}
- /**
- * @param string $profile
- * @param string $term
- * @return string
- */
- protected function getProfileForm( $profile, $term ) {
- // Hidden stuff
- $opts = array();
- $opts['profile'] = $this->profile;
-
- if ( $profile === 'advanced' ) {
- return $this->powerSearchBox( $term, $opts );
- } else {
- $form = '';
- wfRunHooks( 'SpecialSearchProfileForm', array( $this, &$form, $profile, $term, $opts ) );
-
- return $form;
- }
- }
-
/**
* Generates the power search box at [[Special:Search]]
*
$remember = '';
$user = $this->getUser();
if ( $user->isLoggedIn() ) {
- $remember .= Html::hidden( 'nsToken', $user->getEditToken() ) .
+ $remember .= Html::hidden(
+ 'nsToken',
+ $user->getEditToken(
+ 'searchnamespace',
+ $this->getRequest()
+ )
+ ) .
Xml::checkLabel(
wfMessage( 'powersearch-remember' )->text(),
'nsRemember',
/**
* @param string $term
- * @param int $resultsShown
- * @param int $totalNum
* @return string
*/
- protected function formHeader( $term, $resultsShown, $totalNum ) {
+ protected function formHeader( $term ) {
$out = Xml::openElement( 'div', array( 'class' => 'mw-search-formheader' ) );
$bareterm = $term;
}
$out .= Xml::closeElement( 'ul' );
$out .= Xml::closeElement( 'div' );
-
- // Results-info
- if ( $resultsShown > 0 ) {
- if ( $totalNum > 0 ) {
- $top = $this->msg( 'showingresultsheader' )
- ->numParams( $this->offset + 1, $this->offset + $resultsShown, $totalNum )
- ->params( wfEscapeWikiText( $term ) )
- ->numParams( $resultsShown )
- ->parse();
- } elseif ( $resultsShown >= $this->limit ) {
- $top = $this->msg( 'showingresults' )
- ->numParams( $this->limit, $this->offset + 1 )
- ->parse();
- } else {
- $top = $this->msg( 'showingresultsnum' )
- ->numParams( $this->limit, $this->offset + 1, $resultsShown )
- ->parse();
- }
- $out .= Xml::tags( 'div', array( 'class' => 'results-info' ),
- Xml::tags( 'ul', null, Xml::tags( 'li', null, $top ) )
- );
- }
-
$out .= Xml::element( 'div', array( 'style' => 'clear:both' ), '', false );
$out .= Xml::closeElement( 'div' );
+ // Hidden stuff
+ $opts = array();
+ $opts['profile'] = $this->profile;
+
+ if ( $this->profile === 'advanced' ) {
+ $out .= $this->powerSearchBox( $term, $opts );
+ } else {
+ $form = '';
+ wfRunHooks( 'SpecialSearchProfileForm', array( $this, &$form, $this->profile, $term, $opts ) );
+ $out .= $form;
+ }
+
return $out;
}
* @param string $term
* @return string
*/
- protected function shortDialog( $term ) {
+ protected function shortDialog( $term, $resultsShown, $totalNum ) {
$out = Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
$out .= Html::hidden( 'profile', $this->profile ) . "\n";
// Term box
array( 'class' => array( 'mw-ui-button', 'mw-ui-progressive' ) )
) . "\n";
+ // Results-info
+ if ( $totalNum > 0 ) {
+ $top = $this->msg( 'showingresultsheader' )
+ ->numParams( $this->offset + 1, $this->offset + $resultsShown, $totalNum )
+ ->params( wfEscapeWikiText( $term ) )
+ ->numParams( $resultsShown )
+ ->parse();
+ $out .= Xml::tags( 'div', array( 'class' => 'results-info' ), $top );
+ }
+
return $out . $this->didYouMeanHtml;
}