r109514 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109513‎ | r109514 | r109515 >
Date:10:35, 19 January 2012
Author:sbachenberg
Status:deferred (Comments)
Tags:
Comment:
Fixed: Format Exception from last commit and added a new Error Text
Modified paths:
  • /trunk/extensions/SolrStore/SolrStore.i18n.php (modified) (history)
  • /trunk/extensions/SolrStore/SpecialSolrSearch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SolrStore/SolrStore.i18n.php
@@ -11,6 +11,7 @@
1212 $messages['en'] = array(
1313 'solrstore-desc' => 'Search semantic properties with the power of a fulltext search engine',
1414 'solrsearch' => 'SolrSearch',
 15+ 'solrstore-error' => 'Error: Please Check your Query',
1516 'solrstore-searchFieldSets' => 'SolrSearch',
1617 'solrstore-searchFieldSets-select' => 'Please select a SearchSet',
1718 'solrstore-searchFieldSets-title' => 'SolrSearch: SearchSet select',
@@ -23,6 +24,7 @@
2425 $messages['qqq'] = array(
2526 'solrstore-desc' => '{{desc}}',
2627 'solrsearch' => "The title of the Special:SolrSearch page as appearing in Special:SpecialPages. Should probably be the same as message ''solrstore-searchFieldSets''",
 28+ 'solrstore-error' => 'Currently we have just One Error Message, "Error: Please Check your Query"',
2729 'solrstore-searchFieldSets' => 'The pagetitle (heading) of the Special:SolrSearch page',
2830 'solrstore-searchFieldSets-select' => 'A SearchSet is a predefined search form for a field based search.',
2931 'solrstore-searchFieldSets-title' => 'The title of the Special:SolrSearch page. A SearchSet is a predefined search form for a field based search.',
@@ -43,10 +45,12 @@
4446
4547 /** German (Deutsch)
4648 * @author Kghbln
 49+ * @author SBachenberg
4750 */
4851 $messages['de'] = array(
4952 'solrstore-desc' => 'Ermöglicht die Suche nach semantischen Attributen mit einer Volltextsuchmaschine',
5053 'solrsearch' => 'SolrSuche',
 54+ 'solrstore-error' => 'Fehler: Bitte überprüfen Sie ihre Suchanfrage',
5155 'solrstore-searchFieldSets' => 'SolrSuche',
5256 'solrstore-searchFieldSets-select' => 'Bitte wähle ein SearchSet aus',
5357 'solrstore-searchFieldSets-title' => 'SolrSearch: SearchSet Auswahl',
Index: trunk/extensions/SolrStore/SpecialSolrSearch.php
@@ -1,564 +1,553 @@
22 <?php
33 /**
4 - * File holding the SpecialSolrSearch class
5 - *
 4+ * SolrStore: The SolrStore Extesion is Semantic Mediawiki Searchprovieder based on Apache Solr.
 5+ *
66 * This is the SpecialPage, displaying the SearchSets and Results
7 - *
8 - * @ingroup SolrStore
9 - * @file
 7+ *
 8+ * @defgroup SolrStore
109 * @author Simon Bachenberg
1110 */
12 -
13 -/**
14 - * TODO: Insert class description
15 - *
16 - * @ingroup SolrStore
17 - */
1811 class SpecialSolrSearch extends SpecialPage {
1912
20 - /**
21 - * Set up basic search parameters from the request and user settings.
22 - * Typically you'll pass $wgRequest and $wgUser.
23 - *
24 - * @param $request WebRequest
25 - * @param $user User
26 - */
27 - public function __construct() {
28 - parent::__construct( 'SolrSearch' );
29 - global $wgRequest, $wgUser, $wgOut, $wgSolrFields;
30 - $user = $wgUser;
31 - $request = $wgRequest;
32 - list( $this->limit, $this->offset ) = $request->getLimitOffset( 20, 'searchlimit' );
 13+ /**
 14+ * Set up basic search parameters from the request and user settings.
 15+ * Typically you'll pass $wgRequest and $wgUser.
 16+ *
 17+ * @param $request WebRequest
 18+ * @param $user User
 19+ */
 20+ public function __construct() {
 21+ parent::__construct("SolrSearch");
 22+ global $wgRequest, $wgUser, $wgOut, $wgSolrFields;
 23+ $user = $wgUser;
 24+ $request = $wgRequest;
 25+ list( $this->limit, $this->offset ) = $request->getLimitOffset(20, 'searchlimit');
3326
34 - $this->sk = $user->getSkin();
35 - $this->didYouMeanHtml = ''; # html of did you mean... link
36 - }
 27+ $this->sk = $user->getSkin();
 28+ $this->didYouMeanHtml = ''; # html of did you mean... link
 29+ }
3730
38 - function execute( $par ) {
39 - global $wgRequest, $wgUser, $wgOut, $wgSolrFields;
 31+ function execute($par) {
 32+ global $wgRequest, $wgUser, $wgOut, $wgSolrFields;
4033
41 - $this->setHeaders();
42 - $SpecialSolrSearch = new SpecialSolrSearch( $wgRequest, $wgUser );
 34+ $this->setHeaders();
 35+ $SpecialSolrSearch = new SpecialSolrSearch($wgRequest, $wgUser);
4336
44 - foreach ( $wgSolrFields as $set ) {
45 - if ( $par == $set->getName() ) {
46 - $fieldSet = $set;
47 - }
48 - }
 37+ # Get request data from, e.g.
 38+ $param = $wgRequest->getText('param');
4939
50 - // Strip underscores from title parameter; most of the time we'll want
51 - // text form here. But don't strip underscores from actual text params!
52 - $titleParam = str_replace( '_', ' ', $par );
53 - // Fetch the search term
54 -// $search = str_replace("\n", " ", $wgRequest->getText('solrsearch', $titleParam));
 40+ foreach ($wgSolrFields as $set) {
 41+ if ($par == $set->getName()) {
 42+ $fieldSet = $set;
 43+ }
 44+ }
 45+ # Do stuff
 46+ # ...
 47+ // Strip underscores from title parameter; most of the time we'll want
 48+ // text form here. But don't strip underscores from actual text params!
 49+ $titleParam = str_replace('_', ' ', $par);
 50+ // Fetch the search term
 51+// $search = str_replace("\n", " ", $wgRequest->getText('solrsearch', $titleParam));
5552
56 - if ( !isset( $fieldSet ) ) {
57 - $SpecialSolrSearch->showFieldSets();
58 - } else {
59 - $lable = $fieldSet->getLable();
60 - $firstTimeHere = true;
61 - foreach ( $fieldSet->getFields() as $field ) {
62 - if ( $firstTimeHere ) {
63 - $newLable['solr' . trim( $field )] = trim( $lable[0] );
64 - $firstTimeHere = false;
65 - } else {
66 - $newLable['solr' . trim( $field )] = trim( next( $lable ) );
67 - }
 53+ if (!isset($fieldSet)) {
 54+ $SpecialSolrSearch->showFieldSets();
 55+ } else {
 56+ $lable = $fieldSet->getLable();
 57+ $firstTimeHere = true;
 58+ foreach ($fieldSet->getFields() as $field) {
 59+ if ($firstTimeHere) {
 60+ $newLable ['solr' . trim($field)] = trim($lable[0]);
 61+ $firstTimeHere = false;
 62+ } else {
 63+ $newLable ['solr' . trim($field)] = trim(next($lable));
 64+ }
6865
69 - $newFields['solr' . trim( $field )] = $wgRequest->getText( 'solr' . trim( $field ) );
70 - }
71 - $fieldSet->setFields( $newFields );
72 - $fieldSet->setLable( $newLable );
 66+ $newFields ['solr' . trim($field)] = $wgRequest->getText('solr' . trim($field));
 67+ }
 68+ $fieldSet->setFields($newFields);
 69+ $fieldSet->setLable($newLable);
7370
74 - $SpecialSolrSearch->showResults( $fieldSet );
75 - }
76 - }
 71+ $SpecialSolrSearch->showResults($fieldSet);
 72+ }
 73+ }
7774
78 - /**
79 - * @param $fieldSet String
80 - */
81 - public function showFieldSets() {
82 - global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript, $wgSolrFields;
83 - wfProfileIn( __METHOD__ );
 75+ /**
 76+ * @param $fieldSet String
 77+ */
 78+ public function showFieldSets() {
 79+ global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript, $wgSolrFields;
 80+ wfProfileIn(__METHOD__);
8481
85 - $sk = $wgUser->getSkin();
 82+ $sk = $wgUser->getSkin();
8683
87 - $wgOut->setPageTitle( wfMsg( 'solrstore-searchFieldSets' ) );
88 - $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'solrstore-searchFieldSets-title', 'SolrSearch: Select FieldSet' ) ) );
8984
90 - $wgOut->setArticleRelated( false );
91 - $wgOut->addHTML( '<div class="solrsearch-fieldset">' );
92 - $wgOut->addHTML( wfMsg( 'solrstore-searchFieldSets-select' ) );
93 - $wgOut->addHTML( '<ul>' );
 85+ $wgOut->setPageTitle(wfMsg('searchFieldSets'));
 86+ $wgOut->setHTMLTitle(wfMsg('pagetitle', wfMsg('searchFieldSets-title', 'SolrSearch: Select FieldSet')));
9487
95 - // TODO: If no SearchSets exist, provide a shot Manual how to create some!
96 - foreach ( $wgSolrFields as $set ) {
97 - $name = $set->getName();
98 - $wgOut->addHTML( "<li><a href=\"$wgScript/Special:SolrSearch/$name\">$name</a></li>" );
99 - }
100 - $wgOut->addHTML( '</ul>' );
101 - $wgOut->addHTML( '</div>' );
 88+ $wgOut->setArticleRelated(false);
 89+ $wgOut->addHtml('<div class="solrsearch-fieldset">');
 90+ $wgOut->addHtml(wfMsg('searchFieldSets-select'));
 91+ $wgOut->addHtml('<ul>');
10292
103 - wfProfileOut( __METHOD__ );
104 - }
 93+ //TODO: If no SearchSets exist, provide a shot Manual how to create some!
 94+ foreach ($wgSolrFields as $set) {
 95+ $name = $set->getName();
 96+ $wgOut->addHtml("<li><a href=\"$wgScript/Special:SolrSearch/$name\">$name</a></li>");
 97+ }
 98+ $wgOut->addHtml('</ul>');
 99+ $wgOut->addHtml("</div>");
105100
106 - /**
107 - * @param $fieldSet String
108 - */
109 - public function showResults( $fieldSet ) {
110 - global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript;
111 - wfProfileIn( __METHOD__ );
 101+ wfProfileOut(__METHOD__);
 102+ }
 103+
 104+ /**
 105+ * @param $fieldSet String
 106+ */
 107+ public function showResults($fieldSet) {
 108+ global $wgOut, $wgUser, $wgDisableTextSearch, $wgContLang, $wgScript;
 109+ wfProfileIn(__METHOD__);
112110
113 - $sk = $wgUser->getSkin();
 111+ $sk = $wgUser->getSkin();
114112
115 - $this->searchEngine = SearchEngine::create();
116 - $search = & $this->searchEngine;
117 - $search->setLimitOffset( $this->limit, $this->offset );
 113+ $this->searchEngine = SearchEngine::create();
 114+ $search = & $this->searchEngine;
 115+ $search->setLimitOffset($this->limit, $this->offset);
118116
119 - $this->setupPage( $fieldSet );
 117+ $this->setupPage($fieldSet);
120118
121 - $t = Title::newFromText( $fieldSet->getName() );
 119+ $t = Title::newFromText($fieldSet->getName());
122120
123 - // Do we have title matches?
124 - $fields = $fieldSet->getFields();
 121+ //DO we have Title matches
 122+ $fields = $fieldSet->getFields();
125123
126 - // Build Solr query string from the fields
127 - if ( isset( $fields['solrsearch'] ) ) {
128 - $query = $fields['solrsearch'];
129 - } else {
130 - $query = '';
131 - }
 124+ //BUILD SOLR QUERY STRING FROM DA FIELDS
 125+ if (isset($fields['solrsearch'])) {
 126+ $query = $fields['solrsearch'];
 127+ } else {
 128+ $query = '';
 129+ }
132130
133 - foreach ( $fields as $key => $value ) {
134 - if ( $key != 'solrsearch' && !empty( $value ) ) {
135 - $query = trim( $query ) . ' ' . trim( substr( $key, 4 ) ) . ':' . '(' . ( $value ) . ')';
136 - }
137 - }
138131
139 - if ( !empty( $query ) ) {
140 - $query .= $fieldSet->getQuery();
141 - }
 132+ foreach ($fields as $key => $value) {
 133+ if ($key != 'solrsearch' && !empty($value)) {
 134+ $query = trim($query).' '.trim(substr($key, 4)) . ':' . '(' . ($value) . ')';
 135+ }
 136+ }
142137
143 - $titleMatches = $search->searchTitle( $query );
 138+ if (!empty($query)) {
 139+ $query .=$fieldSet->getQuery();
 140+ }
 141+ // TODO: More Exception Handling for Format Exceptions
 142+ try {
 143+ $titleMatches = $search->searchTitle($query);
144144
145 - if ( !( $titleMatches instanceof SearchResultTooMany ) ) {
146 - $textMatches = $search->searchText( $query );
147 - }
 145+ if (!($titleMatches instanceof SearchResultTooMany))
 146+ $textMatches = $search->searchText($query);
148147
149 - // did you mean... suggestions
150 - if ( $textMatches && $textMatches->hasSuggestion() ) {
151 - $st = SpecialPage::getTitleFor( 'SolrSearch' );
 148+ // did you mean... suggestions
 149+ if ($textMatches && $textMatches->hasSuggestion()) {
 150+ $st = SpecialPage::getTitleFor('SolrSearch');
152151
153 - # mirror Go/Search behaviour of original request ..
154 - $didYouMeanParams = array( 'solrsearch' => $textMatches->getSuggestionQuery() );
 152+ # mirror Go/Search behaviour of original request ..
 153+ $didYouMeanParams = array('solrsearch' => $textMatches->getSuggestionQuery());
155154
156 - $stParams = $didYouMeanParams;
 155+ $stParams = $didYouMeanParams;
157156
158 - $suggestionSnippet = $textMatches->getSuggestionSnippet();
 157+ $suggestionSnippet = $textMatches->getSuggestionSnippet();
159158
160 - if ( $suggestionSnippet == '' ) {
161 - $suggestionSnippet = null;
162 - }
 159+ if ($suggestionSnippet == '')
 160+ $suggestionSnippet = null;
163161
164 - $suggestLink = $sk->linkKnown(
165 - $st, $suggestionSnippet, array(), $stParams
166 - );
 162+ $suggestLink = $sk->linkKnown(
 163+ $st, $suggestionSnippet, array(), $stParams
 164+ );
167165
168 - $this->didYouMeanHtml = '<div class="searchdidyoumean">' .
169 - wfMsg( 'search-suggest', $suggestLink ) . '</div>';
170 - }
 166+ $this->didYouMeanHtml = '<div class="searchdidyoumean">'
 167+ . wfMsg('search-suggest', $suggestLink)
 168+ . '</div>';
 169+ }
 170+
 171+ } catch ( Exception $exc ) {
 172+ #Todo: Catch different Exceptions not just one for all
 173+ $textMatches = false;
 174+ $titleMatches = false;
 175+ $wgOut -> addHTML ( '<p class="solr-error">' . wfMsg ( 'solrstore-error' ) . '<p\>' );
 176+ }
 177+ // start rendering the page
 178+ $wgOut->addHtml(
 179+ Xml::openElement(
 180+ 'form', array(
 181+ 'id' => 'solrsearch',
 182+ 'method' => 'get',
 183+ 'action' => $wgScript
 184+ )
 185+ )
 186+ );
 187+ $wgOut->addHtml(
 188+ Xml::openElement('table', array('id' => 'mw-search-top-table', 'border' => 0, 'cellpadding' => 0, 'cellspacing' => 0)) .
 189+ Xml::openElement('tr') .
 190+ Xml::openElement('td') . "\n" .
 191+ $this->shortDialog($fieldSet) .
 192+ Xml::closeElement('td') .
 193+ Xml::closeElement('tr') .
 194+ Xml::closeElement('table')
 195+ );
171196
172 - // start rendering the page
173 - $wgOut->addHTML(
174 - Xml::openElement(
175 - 'form',
176 - array(
177 - 'id' => 'solrsearch',
178 - 'method' => 'get',
179 - 'action' => $wgScript
180 - )
181 - )
182 - );
183 - $wgOut->addHTML(
184 - Xml::openElement( 'table', array( 'id' => 'mw-search-top-table', 'border' => 0, 'cellpadding' => 0, 'cellspacing' => 0 ) ) .
185 - Xml::openElement( 'tr' ) .
186 - Xml::openElement( 'td' ) . "\n" .
187 - $this->shortDialog( $fieldSet ) .
188 - Xml::closeElement( 'td' ) .
189 - Xml::closeElement( 'tr' ) .
190 - Xml::closeElement( 'table' )
191 - );
 197+ // Sometimes the search engine knows there are too many hits
 198+ if ($titleMatches instanceof SearchResultTooMany) {
 199+ $wgOut->addWikiText('==' . wfMsg('toomanymatches') . "==\n");
 200+ wfProfileOut(__METHOD__);
 201+ return;
 202+ }
192203
193 - // Sometimes the search engine knows there are too many hits
194 - if ( $titleMatches instanceof SearchResultTooMany ) {
195 - $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
196 - wfProfileOut( __METHOD__ );
197 - return;
198 - }
 204+ $filePrefix = $wgContLang->getFormattedNsText(NS_FILE) . ':';
 205+ if (trim($query) === '' || $filePrefix === trim($query)) {
 206+ $wgOut->addHTML($this->formHeader($query, 0, 0));
 207+ $wgOut->addHTML('</form>');
 208+ // Empty query -- straight view of search form
 209+ wfProfileOut(__METHOD__);
 210+ return;
 211+ }
 212+ // Get number of results
 213+ $titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0;
 214+ $textMatchesNum = $textMatches ? $textMatches->numRows() : 0;
 215+ // Total initial query matches (possible false positives)
 216+ $num = $titleMatchesNum + $textMatchesNum;
199217
200 - $filePrefix = $wgContLang->getFormattedNsText( NS_FILE ) . ':';
201 - if ( trim( $query ) === '' || $filePrefix === trim( $query ) ) {
202 - $wgOut->addHTML( $this->formHeader( $query, 0, 0 ) );
203 - $wgOut->addHTML( '</form>' );
204 - // Empty query -- straight view of search form
205 - wfProfileOut( __METHOD__ );
206 - return;
207 - }
208 - // Get number of results
209 - $titleMatchesNum = $titleMatches ? $titleMatches->numRows() : 0;
210 - $textMatchesNum = $textMatches ? $textMatches->numRows() : 0;
211 - // Total initial query matches (possible false positives)
212 - $num = $titleMatchesNum + $textMatchesNum;
 218+ // Get total actual results (after second filtering, if any)
 219+ $numTitleMatches = $titleMatches && !is_null($titleMatches->getTotalHits()) ?
 220+ $titleMatches->getTotalHits() : $titleMatchesNum;
 221+ $numTextMatches = $textMatches && !is_null($textMatches->getTotalHits()) ?
 222+ $textMatches->getTotalHits() : $textMatchesNum;
213223
214 - // Get total actual results (after second filtering, if any)
215 - $numTitleMatches = $titleMatches && !is_null( $titleMatches->getTotalHits() ) ?
216 - $titleMatches->getTotalHits() : $titleMatchesNum;
217 - $numTextMatches = $textMatches && !is_null( $textMatches->getTotalHits() ) ?
218 - $textMatches->getTotalHits() : $textMatchesNum;
 224+ // get total number of results if backend can calculate it
 225+ $totalRes = 0;
 226+ if ($titleMatches && !is_null($titleMatches->getTotalHits()))
 227+ $totalRes += $titleMatches->getTotalHits();
 228+ if ($textMatches && !is_null($textMatches->getTotalHits()))
 229+ $totalRes += $textMatches->getTotalHits();
 230+ // show number of results and current offset
 231+ $wgOut->addHTML($this->formHeader($query, $num, $totalRes));
219232
220 - // get total number of results if backend can calculate it
221 - $totalRes = 0;
222 - if ( $titleMatches && !is_null( $titleMatches->getTotalHits() ) )
223 - $totalRes += $titleMatches->getTotalHits();
224 - if ( $textMatches && !is_null( $textMatches->getTotalHits() ) )
225 - $totalRes += $textMatches->getTotalHits();
226 - // show number of results and current offset
227 - $wgOut->addHTML( $this->formHeader( $query, $num, $totalRes ) );
 233+ $wgOut->addHtml(Xml::closeElement('form'));
 234+ $wgOut->addHtml("<div class='searchresults'>");
228235
229 - $wgOut->addHTML( Xml::closeElement( 'form' ) );
230 - $wgOut->addHTML( "<div class='searchresults'>" );
 236+ // prev/next links
 237+ if ($num || $this->offset) {
 238+ // Show the create link ahead
 239+ $this->showCreateLink($t);
 240+ $prevnext = wfViewPrevNext($this->offset, $this->limit, SpecialPage::getTitleFor('SolrSearch'), wfArrayToCGI(array('solrsearch' => $query)), max($titleMatchesNum, $textMatchesNum) < $this->limit
 241+ );
 242+ //$wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
 243+ wfRunHooks('SpecialSolrSearchResults', array($fieldSet, &$titleMatches, &$textMatches));
 244+ } else {
 245+ wfRunHooks('SpecialSolrSearchNoResults', array($fieldSet));
 246+ }
231247
232 - // prev/next links
233 - if ( $num || $this->offset ) {
234 - // Show the create link ahead
235 - $this->showCreateLink( $t );
236 - $prevnext = wfViewPrevNext(
237 - $this->offset,
238 - $this->limit,
239 - SpecialPage::getTitleFor( 'SolrSearch' ),
240 - wfArrayToCGI( array( 'solrsearch' => $query ) ),
241 - max( $titleMatchesNum, $textMatchesNum ) < $this->limit
242 - );
243 - // $wgOut->addHTML( "<p class='mw-search-pager-top'>{$prevnext}</p>\n" );
244 - wfRunHooks( 'SpecialSolrSearchResults', array( $fieldSet, &$titleMatches, &$textMatches ) );
245 - } else {
246 - wfRunHooks( 'SpecialSolrSearchNoResults', array( $fieldSet ) );
247 - }
 248+ if ($titleMatches) {
 249+ if ($numTitleMatches > 0) {
 250+ $wgOut->wrapWikiMsg("==$1==\n", 'titlematches');
 251+ $wgOut->addHTML($this->showMatches($titleMatches));
 252+ }
 253+ $titleMatches->free();
 254+ }
 255+ if ($textMatches) {
 256+ // output appropriate heading
 257+ if ($numTextMatches > 0 && $numTitleMatches > 0) {
 258+ // if no title matches the heading is redundant
 259+ $wgOut->wrapWikiMsg("==$1==\n", 'textmatches');
 260+ } elseif ($totalRes == 0) {
 261+ # Don't show the 'no text matches' if we received title matches
 262+ # $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
 263+ }
248264
249 - if ( $titleMatches ) {
250 - if ( $numTitleMatches > 0 ) {
251 - $wgOut->wrapWikiMsg( "==$1==\n", 'titlematches' );
252 - $wgOut->addHTML( $this->showMatches( $titleMatches ) );
253 - }
254 - $titleMatches->free();
255 - }
256 - if ( $textMatches ) {
257 - // output appropriate heading
258 - if ( $numTextMatches > 0 && $numTitleMatches > 0 ) {
259 - // if no title matches the heading is redundant
260 - $wgOut->wrapWikiMsg( "==$1==\n", 'textmatches' );
261 - } elseif ( $totalRes == 0 ) {
262 - # Don't show the 'no text matches' if we received title matches
263 - # $wgOut->wrapWikiMsg( "==$1==\n", 'notextmatches' );
264 - }
 265+ // show results
 266+ if ($numTextMatches > 0) {
 267+ $wgOut->addHTML($this->showMatches($textMatches));
 268+ }
265269
266 - // show results
267 - if ( $numTextMatches > 0 ) {
268 - $wgOut->addHTML( $this->showMatches( $textMatches ) );
269 - }
 270+ $textMatches->free();
 271+ }
270272
271 - $textMatches->free();
272 - }
 273+ $wgOut->addHtml("</div>");
273274
274 - $wgOut->addHTML( '</div>' );
 275+ if ($num || $this->offset) {
 276+ $wgOut->addHTML("<p class='mw-search-pager-bottom'>{$prevnext}</p>\n");
 277+ }
 278+ wfProfileOut(__METHOD__);
 279+ }
275280
276 - if ( $num || $this->offset ) {
277 - $wgOut->addHTML( "<p class='mw-search-pager-bottom'>{$prevnext}</p>\n" );
278 - }
279 - wfProfileOut( __METHOD__ );
280 - }
 281+ protected function showCreateLink($t) {
 282+ global $wgOut;
281283
282 - protected function showCreateLink( $t ) {
283 - global $wgOut;
 284+ // show direct page/create link if applicable
 285+ $messageName = null;
 286+ if (!is_null($t)) {
 287+ if ($t->isKnown()) {
 288+ $messageName = 'searchmenu-exists';
 289+ } elseif ($t->userCan('create')) {
 290+ $messageName = 'searchmenu-new';
 291+ } else {
 292+ $messageName = 'searchmenu-new-nocreate';
 293+ }
 294+ }
 295+ if ($messageName) {
 296+ $wgOut->wrapWikiMsg("<p class=\"mw-search-createlink\">\n$1</p>", array($messageName, wfEscapeWikiText($t->getPrefixedText())));
 297+ } else {
 298+ // preserve the paragraph for margins etc...
 299+ $wgOut->addHtml('<p></p>');
 300+ }
 301+ }
284302
285 - // show direct page/create link if applicable
286 - $messageName = null;
287 - if ( !is_null( $t ) ) {
288 - if ( $t->isKnown() ) {
289 - $messageName = 'searchmenu-exists';
290 - } elseif ( $t->userCan( 'create' ) ) {
291 - $messageName = 'searchmenu-new';
292 - } else {
293 - $messageName = 'searchmenu-new-nocreate';
294 - }
295 - }
296 - if ( $messageName ) {
297 - $wgOut->wrapWikiMsg( "<p class=\"mw-search-createlink\">\n$1</p>",
298 - array( $messageName, wfEscapeWikiText( $t->getPrefixedText() ) ) );
299 - } else {
300 - // preserve the paragraph for margins etc...
301 - $wgOut->addHtml( '<p></p>' );
302 - }
303 - }
 303+ /**
 304+ *
 305+ */
 306+ protected function setupPage($fieldSet) {
 307+ global $wgOut;
304308
305 - /**
306 - *
307 - */
308 - protected function setupPage( $fieldSet ) {
309 - global $wgOut;
 309+ if (!empty($fieldSet)) {
 310+ $wgOut->setPageTitle(wfMsg('searchresults'));
 311+ $wgOut->setHTMLTitle(wfMsg('pagetitle', wfMsg('searchresults-title', $fieldSet->getName())));
 312+ }
 313+ $wgOut->setArticleRelated(false);
 314+ $wgOut->setRobotPolicy('noindex,nofollow');
 315+ // add javascript specific to special:search
 316+ $wgOut->addModules('mediawiki.legacy.search');
 317+ $wgOut->addModules('mediawiki.special.search');
 318+ }
310319
311 - if ( !empty( $fieldSet ) ) {
312 - $wgOut->setPageTitle( wfMsg( 'searchresults' ) );
313 - $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'searchresults-title', $fieldSet->getName() ) ) );
314 - }
315 - $wgOut->setArticleRelated( false );
316 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
317 - // add JavaScript specific to Special:Search
318 - $wgOut->addModules( 'mediawiki.legacy.search' );
319 - $wgOut->addModules( 'mediawiki.special.search' );
320 - }
 320+ /**
 321+ * Show whole set of results
 322+ *
 323+ * @param $matches SearchResultSet
 324+ */
 325+ protected function showMatches(&$matches) {
 326+ global $wgContLang;
 327+ wfProfileIn(__METHOD__);
321328
322 - /**
323 - * Show whole set of results
324 - *
325 - * @param $matches SearchResultSet
326 - */
327 - protected function showMatches( &$matches ) {
328 - global $wgContLang;
329 - wfProfileIn( __METHOD__ );
 329+ $fieldSets = $wgContLang->convertForSearchResult($matches->termMatches());
330330
331 - $fieldSets = $wgContLang->convertForSearchResult( $matches->termMatches() );
 331+ $out = "";
 332+ $infoLine = $matches->getInfo();
 333+ if (!is_null($infoLine)) {
 334+ $out .= "\n<!-- {$infoLine} -->\n";
 335+ }
 336+ $out .= "<ul class='mw-search-results'>\n";
 337+ $xxx = 0;
 338+ while ($result = $matches->next()) {
 339+ $out .= $this->showHit($result, $fieldSets);
 340+ }
 341+ $out .= "</ul>\n";
332342
333 - $out = '';
334 - $infoLine = $matches->getInfo();
335 - if ( !is_null( $infoLine ) ) {
336 - $out .= "\n<!-- {$infoLine} -->\n";
337 - }
338 - $out .= "<ul class='mw-search-results'>\n";
339 - while ( $result = $matches->next() ) {
340 - $out .= $this->showHit( $result, $fieldSets );
341 - }
342 - $out .= "</ul>\n";
 343+ // convert the whole thing to desired language variant
 344+ $out = $wgContLang->convert($out);
 345+ wfProfileOut(__METHOD__);
 346+ return $out;
 347+ }
343348
344 - // convert the whole thing to desired language variant
345 - $out = $wgContLang->convert( $out );
346 - wfProfileOut( __METHOD__ );
347 - return $out;
348 - }
 349+ /**
 350+ * Format a single hit result
 351+ *
 352+ * @param $result SearchResult
 353+ * @param $fieldSets Array: terms to highlight
 354+ */
 355+ protected function showHit($result, $fieldSets) {
 356+ global $wgLang, $wgUser;
 357+ wfProfileIn(__METHOD__);
349358
350 - /**
351 - * Format a single hit result
352 - *
353 - * @param $result SearchResult
354 - * @param $fieldSets Array: terms to highlight
355 - */
356 - protected function showHit( $result, $fieldSets ) {
357 - global $wgLang, $wgUser;
358 - wfProfileIn( __METHOD__ );
 359+ if ($result->isBrokenTitle()) {
 360+ wfProfileOut(__METHOD__);
 361+ return "<!-- Broken link in search result -->\n";
 362+ }
359363
360 - if ( $result->isBrokenTitle() ) {
361 - wfProfileOut( __METHOD__ );
362 - return "<!-- Broken link in search result -->\n";
363 - }
 364+ $sk = $wgUser->getSkin();
 365+ $t = $result->getTitle();
364366
365 - $sk = $wgUser->getSkin();
366 - $t = $result->getTitle();
 367+ $titleSnippet = $result->getTitleSnippet($fieldSets);
367368
368 - $titleSnippet = $result->getTitleSnippet( $fieldSets );
 369+ if ($titleSnippet == '')
 370+ $titleSnippet = null;
369371
370 - if ( $titleSnippet == '' ) {
371 - $titleSnippet = null;
372 - }
 372+ $link_t = clone $t;
373373
374 - $link_t = clone $t;
 374+ wfRunHooks('ShowSearchHitTitle', array(&$link_t, &$titleSnippet, $result, $fieldSets, $this));
375375
376 - wfRunHooks( 'ShowSearchHitTitle', array( &$link_t, &$titleSnippet, $result, $fieldSets, $this ) );
 376+ $link = $this->sk->linkKnown(
 377+ $link_t, $titleSnippet
 378+ );
 379+ // FÜLLEN
 380+ //If page content is not readable, just return the title.
 381+ //This is not quite safe, but better than showing excerpts from non-readable pages
 382+ //Note that hiding the entry entirely would screw up paging.
 383+ // ---- HIER
 384+ if (!$t->userCanRead()) {
 385+ wfProfileOut(__METHOD__);
 386+ return "<li>{$link}</li>\n";
 387+ }
 388+ //return "<li>{$link}</li>\n";
 389+ // If the page doesn't *exist*... our search index is out of date.
 390+ // The least confusing at this point is to drop the result.
 391+ // You may get less results, but... oh well. :P
 392+ // ---- HIER
 393+ if ($result->isMissingRevision()) {
 394+ wfProfileOut(__METHOD__);
 395+ return "<!-- missing page " . htmlspecialchars($t->getPrefixedText()) . "-->\n";
 396+ }
377397
378 - $link = $this->sk->linkKnown(
379 - $link_t, $titleSnippet
380 - );
381 - // FÜLLEN
382 - // If page content is not readable, just return the title.
383 - // This is not quite safe, but better than showing excerpts from non-readable pages
384 - // Note that hiding the entry entirely would screw up paging.
385 - // ---- HIER
386 - if ( !$t->userCanRead() ) {
387 - wfProfileOut( __METHOD__ );
388 - return "<li>{$link}</li>\n";
389 - }
390 - // return "<li>{$link}</li>\n";
391 - // If the page doesn't *exist*... our search index is out of date.
392 - // The least confusing at this point is to drop the result.
393 - // You may get less results, but... oh well. :P
394 - // ---- HIER
395 - if ( $result->isMissingRevision() ) {
396 - wfProfileOut( __METHOD__ );
397 - return "<!-- missing page " . htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
398 - }
 398+ // format redirects / relevant sections
 399+ $redirectTitle = $result->getRedirectTitle();
 400+ $redirectText = $result->getRedirectSnippet($fieldSets);
 401+ $sectionTitle = $result->getSectionTitle();
 402+ $sectionText = $result->getSectionSnippet($fieldSets);
 403+ $redirect = '';
399404
400 - // format redirects / relevant sections
401 - $redirectTitle = $result->getRedirectTitle();
402 - $redirectText = $result->getRedirectSnippet( $fieldSets );
403 - $sectionTitle = $result->getSectionTitle();
404 - $sectionText = $result->getSectionSnippet( $fieldSets );
405 - $redirect = '';
 405+ if (!is_null($redirectTitle)) {
 406+ if ($redirectText == '')
 407+ $redirectText = null;
406408
407 - if ( !is_null( $redirectTitle ) ) {
408 - if ( $redirectText == '' ) {
409 - $redirectText = null;
410 - }
 409+ $redirect = "<span class='searchalttitle'>" .
 410+ wfMsg('search-redirect', $this->sk->linkKnown($redirectTitle, $redirectText)) .
 411+ "</span>";
 412+ }
411413
412 - $redirect = '<span class="searchalttitle">' .
413 - wfMsg( 'search-redirect', $this->sk->linkKnown( $redirectTitle, $redirectText ) ) .
414 - '</span>';
415 - }
 414+ $section = '';
416415
417 - $section = '';
418416
 417+ if (!is_null($sectionTitle)) {
 418+ if ($sectionText == '')
 419+ $sectionText = null;
419420
420 - if ( !is_null( $sectionTitle ) ) {
421 - if ( $sectionText == '' ) {
422 - $sectionText = null;
423 - }
 421+ $section = "<span class='searchalttitle'>" .
 422+ wfMsg('search-section', $this->sk->linkKnown($sectionTitle, $sectionText)) .
 423+ "</span>";
 424+ }
424425
425 - $section = '<span class="searchalttitle">' .
426 - wfMsg( 'search-section', $this->sk->linkKnown( $sectionTitle, $sectionText ) ) .
427 - '</span>';
428 - }
 426+ // format text extract
 427+ $extract = "<div class='searchresult'>" . $result->getTextSnippet($fieldSets) . "</div>";
429428
430 - // format text extract
431 - $extract = '<div class="searchresult">' . $result->getTextSnippet( $fieldSets ) . '</div>';
 429+ // format score
 430+ if (is_null($result->getScore())) {
 431+ // Search engine doesn't report scoring info
 432+ $score = '';
 433+ } else {
 434+ $percent = sprintf('%2.1f', $result->getScore() * 100);
 435+ $score = wfMsg('search-result-score', $wgLang->formatNum($percent)) . ' - ';
 436+ }
432437
433 - // format score
434 - if ( is_null( $result->getScore() ) ) {
435 - // Search engine doesn't report scoring info
436 - $score = '';
437 - } else {
438 - $percent = sprintf( '%2.1f', $result->getScore() * 100 );
439 - $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) ) . ' - ';
440 - }
 438+ // format description
 439+ $byteSize = $result->getByteSize();
 440+ $wordCount = $result->getWordCount();
 441+ $timestamp = $result->getTimestamp();
 442+ $size = wfMsgExt('search-result-size', array('parsemag', 'escape'), $this->sk->formatSize($byteSize), $wgLang->formatNum($wordCount));
441443
442 - // format description
443 - $byteSize = $result->getByteSize();
444 - $wordCount = $result->getWordCount();
445 - $timestamp = $result->getTimestamp();
446 - $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
447 - $this->sk->formatSize( $byteSize ), $wgLang->formatNum( $wordCount ) );
 444+ if ($t->getNamespace() == NS_CATEGORY) {
 445+ $cat = Category::newFromTitle($t);
 446+ $size = wfMsgExt('search-result-category-size', array('parsemag', 'escape'), $wgLang->formatNum($cat->getPageCount()), $wgLang->formatNum($cat->getSubcatCount()), $wgLang->formatNum($cat->getFileCount()));
 447+ }
448448
449 - if ( $t->getNamespace() == NS_CATEGORY ) {
450 - $cat = Category::newFromTitle( $t );
451 - $size = wfMsgExt( 'search-result-category-size', array( 'parsemag', 'escape' ),
452 - $wgLang->formatNum( $cat->getPageCount() ),
453 - $wgLang->formatNum( $cat->getSubcatCount() ),
454 - $wgLang->formatNum( $cat->getFileCount() ) );
455 - }
 449+ $date = $wgLang->timeanddate($timestamp);
456450
457 - $date = $wgLang->timeanddate( $timestamp );
 451+ // link to related articles if supported
 452+ $related = '';
 453+ if ($result->hasRelated()) {
 454+ $st = SpecialPage::getTitleFor('SolrSearch');
 455+ $stParams = array('solrsearch' => wfMsgForContent('searchrelated') . ':' . $t->getPrefixedText());
 456+ $related = ' -- ' . $sk->linkKnown($st, wfMsg('search-relatedarticle'), array(), $stParams);
 457+ }
458458
459 - // link to related articles if supported
460 - $related = '';
461 - if ( $result->hasRelated() ) {
462 - $st = SpecialPage::getTitleFor( 'SolrSearch' );
463 - $stParams = array( 'solrsearch' => wfMsgForContent( 'searchrelated' ) . ':' . $t->getPrefixedText() );
464 - $related = ' -- ' . $sk->linkKnown( $st, wfMsg( 'search-relatedarticle' ), array(), $stParams );
465 - }
 459+ // Include a thumbnail for media files...
 460+ // WE HAVE NEVER TESTED THIS HERE!!!
 461+ if ($t->getNamespace() == NS_FILE) {
 462+ $img = wfFindFile($t);
 463+ if ($img) {
 464+ $thumb = $img->transform(array('width' => 120, 'height' => 120));
 465+ if ($thumb) {
 466+ $desc = wfMsg('parentheses', $img->getShortDesc());
 467+ wfProfileOut(__METHOD__);
 468+ // Float doesn't seem to interact well with the bullets.
 469+ // Table messes up vertical alignment of the bullets.
 470+ // Bullets are therefore disabled (didn't look great anyway).
 471+ return "<li>" .
 472+ '<table class="searchResultImage">' .
 473+ '<tr>' .
 474+ '<td width="120" align="center" valign="top">' .
 475+ $thumb->toHtml(array('desc-link' => true)) .
 476+ '</td>' .
 477+ '<td valign="top">' .
 478+ $link .
 479+ $extract .
 480+ "<div class='mw-search-result-data'>{$score}{$desc}{$date}{$related}</div>" .
 481+ '</td>' .
 482+ '</tr>' .
 483+ '</table>' .
 484+ "</li>\n";
 485+ }
 486+ }
 487+ }
466488
467 - // Include a thumbnail for media files...
468 - // WE HAVE NEVER TESTED THIS HERE!
469 - if ( $t->getNamespace() == NS_FILE ) {
470 - $img = wfFindFile( $t );
471 - if ( $img ) {
472 - $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
473 - if ( $thumb ) {
474 - $desc = wfMsg( 'parentheses', $img->getShortDesc() );
475 - wfProfileOut( __METHOD__ );
476 - // Float doesn't seem to interact well with the bullets.
477 - // Table messes up vertical alignment of the bullets.
478 - // Bullets are therefore disabled (didn't look great anyway).
479 - return '<li>' .
480 - '<table class="searchResultImage">' .
481 - '<tr>' .
482 - '<td width="120" align="center" valign="top">' .
483 - $thumb->toHtml( array( 'desc-link' => true ) ) .
484 - '</td>' .
485 - '<td valign="top">' .
486 - $link .
487 - $extract .
488 - "<div class='mw-search-result-data'>{$score}{$desc}{$date}{$related}</div>" .
489 - '</td>' .
490 - '</tr>' .
491 - '</table>' .
492 - "</li>\n";
493 - }
494 - }
495 - }
 489+ wfProfileOut(__METHOD__);
 490+ // HIER kommt die score ausgabe:
 491+ return "<li><div class='mw-search-result-heading'>{$link} {$redirect} {$section}</div> {$extract}\n" .
 492+ "<div class='mw-search-result-data'>{$score}{$date}{$related}</div>" .
 493+ "</li>\n";
 494+ }
496495
497 - wfProfileOut( __METHOD__ );
498 - // HIER kommt die score ausgabe:
499 - return "<li><div class='mw-search-result-heading'>{$link} {$redirect} {$section}</div> {$extract}\n" .
500 - "<div class='mw-search-result-data'>{$score}{$date}{$related}</div>" .
501 - "</li>\n";
502 - }
 496+ protected function formHeader($fieldSet, $resultsShown, $totalNum) {
 497+ global $wgLang;
503498
504 - protected function formHeader( $fieldSet, $resultsShown, $totalNum ) {
505 - global $wgLang;
 499+ $out = Xml::openElement('div', array('class' => 'mw-search-formheader'));
506500
507 - $out = Xml::openElement( 'div', array( 'class' => 'mw-search-formheader' ) );
 501+ // Results-info
 502+ if ($resultsShown > 0) {
 503+ if ($totalNum > 0) {
 504+ $top = wfMsgExt('showingresultsheader', array('parseinline'), $wgLang->formatNum($this->offset + 1), $wgLang->formatNum($this->offset + $resultsShown), $wgLang->formatNum($totalNum), $wgLang->formatNum($resultsShown)
 505+ );
 506+ } elseif ($resultsShown >= $this->limit) {
 507+ $top = wfShowingResults($this->offset, $this->limit);
 508+ } else {
 509+ $top = wfShowingResultsNum($this->offset, $this->limit, $resultsShown);
 510+ }
 511+ $out .= Xml::tags('div', array('class' => 'results-info'), Xml::tags('ul', null, Xml::tags('li', null, $top)));
 512+ }
508513
509 - // Results-info
510 - if ( $resultsShown > 0 ) {
511 - if ( $totalNum > 0 ) {
512 - $top = wfMsgExt(
513 - 'showingresultsheader',
514 - array( 'parseinline' ),
515 - $wgLang->formatNum( $this->offset + 1 ),
516 - $wgLang->formatNum( $this->offset + $resultsShown ),
517 - $wgLang->formatNum( $totalNum ),
518 - $wgLang->formatNum( $resultsShown )
519 - );
520 - } elseif ( $resultsShown >= $this->limit ) {
521 - $top = wfShowingResults( $this->offset, $this->limit );
522 - } else {
523 - $top = wfShowingResultsNum( $this->offset, $this->limit, $resultsShown );
524 - }
525 - $out .= Xml::tags( 'div', array( 'class' => 'results-info' ), Xml::tags( 'ul', null, Xml::tags( 'li', null, $top ) ) );
526 - }
 514+ $out .= Xml::element('div', array('style' => 'clear:both'), '', false);
 515+ $out .= Xml::closeElement('div');
527516
528 - $out .= Xml::element( 'div', array( 'style' => 'clear:both' ), '', false );
529 - $out .= Xml::closeElement( 'div' );
 517+ return $out;
 518+ }
530519
531 - return $out;
532 - }
 520+ protected function shortDialog($fieldSet) {
 521+ $searchTitle = SpecialPage::getTitleFor('SolrSearch');
533522
534 - protected function shortDialog( $fieldSet ) {
535 - $searchTitle = SpecialPage::getTitleFor( 'SolrSearch' );
536523
537 - if ( $fieldSet->getName() != 'search' ) {
538 - $out = Html::hidden( 'title', $searchTitle->getPrefixedText() . '/' . $fieldSet->getName() ) . "\n";
539 - } else {
540 - $out = Html::hidden( 'title', $searchTitle->getPrefixedText() ) . "\n";
541 - }
542 - // Term box
 524+ if ($fieldSet->getName() != 'search') {
 525+ $out = Html::hidden('title', $searchTitle->getPrefixedText() . '/' . $fieldSet->getName()) . "\n";
 526+ } else {
 527+ $out = Html::hidden('title', $searchTitle->getPrefixedText()) . "\n";
 528+ }
 529+ // Term box
543530
544 - $lable = $fieldSet->getLable();
545 - $out .= '<table>';
 531+ $lable = $fieldSet->getLable();
 532+ $out .= '<table>';
546533
547 - foreach ( $fieldSet->getFields() as $key => $value ) {
548 - $out .= '<tr>';
549 - if ( isset( $lable[$key] ) ) {
550 - $out .= '<th>' . $lable[$key] . '</th>';
551 - }
552 - $out .= '<td>';
553 - $out .= Html::input( $key, $value, $key, array(
554 - 'id' => $key,
555 - 'size' => '50',
556 - 'autofocus'
557 - ) ) . "\n";
558 - $out .= '</td></tr>';
559 - }
560 - $out .= '<table>';
561 - $out .= Xml::submitButton( wfMsg( 'searchbutton' ) ) . "\n";
562 - return $out . $this->didYouMeanHtml;
563 - }
 534+ foreach ($fieldSet->getFields() as $key => $value) {
 535+ $out .= '<tr>';
 536+ if (isset($lable[$key])) {
 537+ $out .= '<th>' . $lable[$key] . '</th>';
 538+ }
 539+ $out .= '<td>';
 540+ $out .= Html::input($key, $value, $key, array(
 541+ 'id' => $key,
 542+ 'size' => '50',
 543+ 'autofocus'
 544+ )) . "\n";
 545+ $out .= '</td></tr>';
 546+ }
 547+ $out .= '<table>';
 548+ $out .= Xml::submitButton(wfMsg('searchbutton')) . "\n";
 549+ return $out . $this->didYouMeanHtml;
 550+ }
564551
565552 }
 553+
 554+?>
\ No newline at end of file

Comments

#Comment by SBachenberg (talk | contribs)   10:44, 19 January 2012

Sorry NetBeans destroyed the Format, I'll re-commit it again.

#Comment by Nikerabbit (talk | contribs)   12:23, 19 January 2012

Please don't use Title Case.

Status & tagging log