MediaWiki  1.23.6
SearchResult.php
Go to the documentation of this file.
1 <?php
30 class SearchResult {
31 
35  protected $mRevision = null;
36 
40  protected $mImage = null;
41 
45  protected $mTitle;
46 
50  protected $mText;
51 
58  public static function newFromTitle( $title ) {
59  $result = new self();
60  $result->initFromTitle( $title );
61  return $result;
62  }
63 
70  public static function newFromRow( $row ) {
71  $result = new self();
72  $result->initFromRow( $row );
73  return $result;
74  }
75 
76  public function __construct( $row = null ) {
77  if ( !is_null( $row ) ) {
78  // Backwards compatibility with pre-1.17 callers
79  $this->initFromRow( $row );
80  }
81  }
82 
89  protected function initFromRow( $row ) {
90  $this->initFromTitle( Title::makeTitle( $row->page_namespace, $row->page_title ) );
91  }
92 
99  protected function initFromTitle( $title ) {
100  $this->mTitle = $title;
101  if ( !is_null( $this->mTitle ) ) {
102  $id = false;
103  wfRunHooks( 'SearchResultInitFromTitle', array( $title, &$id ) );
104  $this->mRevision = Revision::newFromTitle(
105  $this->mTitle, $id, Revision::READ_NORMAL );
106  if ( $this->mTitle->getNamespace() === NS_FILE ) {
107  $this->mImage = wfFindFile( $this->mTitle );
108  }
109  }
110  }
111 
117  function isBrokenTitle() {
118  return is_null( $this->mTitle );
119  }
120 
126  function isMissingRevision() {
127  return !$this->mRevision && !$this->mImage;
128  }
129 
133  function getTitle() {
134  return $this->mTitle;
135  }
136 
141  function getFile() {
142  return $this->mImage;
143  }
144 
148  function getScore() {
149  return null;
150  }
151 
155  protected function initText() {
156  if ( !isset( $this->mText ) ) {
157  if ( $this->mRevision != null ) {
158  $this->mText = SearchEngine::create()
159  ->getTextFromContent( $this->mTitle, $this->mRevision->getContent() );
160  } else { // TODO: can we fetch raw wikitext for commons images?
161  $this->mText = '';
162  }
163  }
164  }
165 
170  function getTextSnippet( $terms ) {
171  global $wgAdvancedSearchHighlighting;
172  $this->initText();
173 
174  // TODO: make highliter take a content object. Make ContentHandler a factory for SearchHighliter.
175  list( $contextlines, $contextchars ) = SearchEngine::userHighlightPrefs();
176  $h = new SearchHighlighter();
177  if ( $wgAdvancedSearchHighlighting ) {
178  return $h->highlightText( $this->mText, $terms, $contextlines, $contextchars );
179  } else {
180  return $h->highlightSimple( $this->mText, $terms, $contextlines, $contextchars );
181  }
182  }
183 
187  function getTitleSnippet() {
188  return '';
189  }
190 
194  function getRedirectSnippet() {
195  return '';
196  }
197 
201  function getRedirectTitle() {
202  return null;
203  }
204 
208  function getSectionSnippet() {
209  return '';
210  }
211 
215  function getSectionTitle() {
216  return null;
217  }
218 
222  function getTimestamp() {
223  if ( $this->mRevision ) {
224  return $this->mRevision->getTimestamp();
225  } elseif ( $this->mImage ) {
226  return $this->mImage->getTimestamp();
227  }
228  return '';
229  }
230 
234  function getWordCount() {
235  $this->initText();
236  return str_word_count( $this->mText );
237  }
238 
242  function getByteSize() {
243  $this->initText();
244  return strlen( $this->mText );
245  }
246 
250  function hasRelated() {
251  return false;
252  }
253 
257  function getInterwikiPrefix() {
258  return '';
259  }
260 
264  function getInterwikiNamespaceText() {
265  return '';
266  }
267 
271  function isFileMatch() {
272  return false;
273  }
274 }
SearchResult\getSectionTitle
getSectionTitle()
Definition: SearchResult.php:211
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
SearchResult\hasRelated
hasRelated()
Definition: SearchResult.php:246
SearchResult\getTitle
getTitle()
Definition: SearchResult.php:129
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
SearchResult\$mImage
File $mImage
Definition: SearchResult.php:38
SearchResult\__construct
__construct( $row=null)
Definition: SearchResult.php:72
SearchResult\getTimestamp
getTimestamp()
Definition: SearchResult.php:218
SearchEngine\userHighlightPrefs
static userHighlightPrefs()
Find snippet highlight settings for all users.
Definition: SearchEngine.php:382
NS_FILE
const NS_FILE
Definition: Defines.php:85
SearchResult\getSectionSnippet
getSectionSnippet()
Definition: SearchResult.php:204
SearchResult\getTitleSnippet
getTitleSnippet()
Definition: SearchResult.php:183
SearchResult\initFromRow
initFromRow( $row)
Initialize from a database row.
Definition: SearchResult.php:85
Revision
Definition: Revision.php:26
SearchResult\getInterwikiPrefix
getInterwikiPrefix()
Definition: SearchResult.php:253
IDBAccessObject\READ_NORMAL
const READ_NORMAL
Definition: IDBAccessObject.php:53
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:50
SearchResult\$mRevision
Revision $mRevision
Definition: SearchResult.php:34
SearchResult
Definition: SearchResult.php:30
SearchResult\getFile
getFile()
Get the file for this page, if one exists.
Definition: SearchResult.php:137
SearchResult\getTextSnippet
getTextSnippet( $terms)
Definition: SearchResult.php:166
SearchResult\isFileMatch
isFileMatch()
Did this match file contents (eg: PDF/DJVU)?
Definition: SearchResult.php:267
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4010
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
SearchResult\$mTitle
Title $mTitle
Definition: SearchResult.php:42
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
Revision\newFromTitle
static newFromTitle( $title, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given title.
Definition: Revision.php:106
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
SearchResult\getByteSize
getByteSize()
Definition: SearchResult.php:238
SearchHighlighter
Highlight bits of wikitext.
Definition: SearchHighlighter.php:29
SearchResult\initText
initText()
Lazy initialization of article text from DB.
Definition: SearchResult.php:151
SearchResult\getRedirectSnippet
getRedirectSnippet()
Definition: SearchResult.php:190
SearchResult\getWordCount
getWordCount()
Definition: SearchResult.php:230
Title
Represents a title within MediaWiki.
Definition: Title.php:35
SearchResult\newFromRow
static newFromRow( $row)
Return a new SearchResult and initializes it with a row.
Definition: SearchResult.php:66
SearchResult\$mText
String $mText
Definition: SearchResult.php:46
SearchResult\isMissingRevision
isMissingRevision()
Check if target page is missing, happens when index is out of date.
Definition: SearchResult.php:122
SearchResult\getRedirectTitle
getRedirectTitle()
Definition: SearchResult.php:197
SearchResult\initFromTitle
initFromTitle( $title)
Initialize from a Title and if possible initializes a corresponding Revision and File.
Definition: SearchResult.php:95
wfFindFile
wfFindFile( $title, $options=array())
Find a file.
Definition: GlobalFunctions.php:3702
SearchResult\getScore
getScore()
Definition: SearchResult.php:144
SearchResult\getInterwikiNamespaceText
getInterwikiNamespaceText()
Definition: SearchResult.php:260
SearchResult\newFromTitle
static newFromTitle( $title)
Return a new SearchResult and initializes it with a title.
Definition: SearchResult.php:54
SearchEngine\create
static create( $type=null)
Load up the appropriate search engine class for the currently active database backend,...
Definition: SearchEngine.php:447
SearchResult\isBrokenTitle
isBrokenTitle()
Check if this is result points to an invalid title.
Definition: SearchResult.php:113