r75809 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75808‎ | r75809 | r75810 >
Date:18:14, 1 November 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
* (bug 25741) Add more data to list=search's srprop. Patch by Brad Jorsch
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySearch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQuerySearch.php
@@ -139,6 +139,35 @@
140140 if ( isset( $prop['timestamp'] ) ) {
141141 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $result->getTimestamp() );
142142 }
 143+ if ( !is_null( $result->getScore() ) ) {
 144+ if ( isset( $prop['score'] ) ) {
 145+ $vals['score'] = $result->getScore();
 146+ }
 147+ }
 148+ if ( isset( $prop['titlesnippet'] ) ) {
 149+ $vals['titlesnippet'] = $result->getTitleSnippet( $terms );
 150+ }
 151+ if ( !is_null( $result->getRedirectTitle() ) ) {
 152+ if ( isset( $prop['redirecttitle'] ) ) {
 153+ $vals['redirecttitle'] = $result->getRedirectTitle();
 154+ }
 155+ if ( isset( $prop['redirectsnippet'] ) ) {
 156+ $vals['redirectsnippet'] = $result->getRedirectSnippet( $terms );
 157+ }
 158+ }
 159+ if ( !is_null( $result->getSectionTitle() ) ) {
 160+ if ( isset( $prop['sectiontitle'] ) ) {
 161+ $vals['sectiontitle'] = $result->getSectionTitle();
 162+ }
 163+ if ( isset( $prop['sectionsnippet'] ) ) {
 164+ $vals['sectionsnippet'] = $result->getSectionSnippet();
 165+ }
 166+ }
 167+ if ( isset( $prop['hasrelated'] ) ) {
 168+ if ( $result->hasRelated() ) {
 169+ $vals['hasrelated'] = "";
 170+ }
 171+ }
143172
144173 // Add item to results and see whether it fits
145174 $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ),
@@ -198,7 +227,14 @@
199228 'size',
200229 'wordcount',
201230 'timestamp',
 231+ 'score',
202232 'snippet',
 233+ 'titlesnippet',
 234+ 'redirecttitle',
 235+ 'redirectsnippet',
 236+ 'sectiontitle',
 237+ 'sectionsnippet',
 238+ 'hasrelated',
203239 ),
204240 ApiBase::PARAM_ISMULTI => true,
205241 ),
@@ -222,10 +258,17 @@
223259 'info' => 'What metadata to return',
224260 'prop' => array(
225261 'What properties to return',
226 - ' size - Adds the size of the page in bytes',
227 - ' wordcount - Adds the word count of the page',
228 - ' timestamp - Adds the timestamp of when the page was last edited',
229 - ' snippet - Adds a parsed snippet of the page',
 262+ ' size - Adds the size of the page in bytes',
 263+ ' wordcount - Adds the word count of the page',
 264+ ' timestamp - Adds the timestamp of when the page was last edited',
 265+ ' score - Adds the score (if any) from the search engine',
 266+ ' snippet - Adds a parsed snippet of the page',
 267+ ' titlesnippet - Adds a parsed snippet of the page title',
 268+ ' redirectsnippet - Adds a parsed snippet of the redirect',
 269+ ' redirecttitle - Adds a parsed snippet of the redirect title',
 270+ ' sectionsnippet - Adds a parsed snippet of the matching section',
 271+ ' sectiontitle - Adds a parsed snippet of the matching section title',
 272+ ' hasrelated - Indicates whether a related search is available',
230273 ),
231274 'redirects' => 'Include redirect pages in the search',
232275 'offset' => 'Use this value to continue paging (return by query)',
Index: trunk/phase3/RELEASE-NOTES
@@ -470,7 +470,8 @@
471471 ApiRsdServiceApis for extensions to add their own service to the services
472472 list.
473473 * The HTML of diff output markers has changed. Hyphens are now minus signs,
474 - empty markers are now filled with non-breaking-space characters.
 474+ empty markers are now filled with non-breaking-space characters
 475+* (bug 25741) Add more data to list=search's srprop
475476
476477 === Languages updated in 1.17 ===
477478

Follow-up revisions

RevisionCommit summaryAuthorDate
r76300Minor followup r75809, don't use nested if's unnecesserilyreedy12:23, 8 November 2010

Comments

#Comment by Catrope (talk | contribs)   11:36, 8 November 2010
+				if ( !is_null( $result->getScore() ) ) {
+					if ( isset( $prop['score'] ) ) {
+						$vals['score'] = $result->getScore();
+					}
+				}
[...]
+				if ( isset( $prop['hasrelated'] ) ) {
+					if ( $result->hasRelated() ) {
+						$vals['hasrelated'] = "";
+					}
+				}

Just use &&

#Comment by Bryan (talk | contribs)   20:19, 16 November 2010
+					if ( isset( $prop['redirecttitle'] ) ) {
+						$vals['redirecttitle'] = $result->getRedirectTitle();
+					}
...
+					if ( isset( $prop['sectiontitle'] ) ) {
+						$vals['sectiontitle'] = $result->getSectionTitle();
+					}

Those functions return a Title, not a string, so you need to call getPrefixedText()

Also all those function may return null and I'm not sure if the formatter likes that.

#Comment by Bryan (talk | contribs)   20:26, 16 November 2010

Ignore that comment, apparently I'm not awake enough to do CR.

Status & tagging log