MediaWiki master
RevisionSearchResult.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Search;
4
5use IDBAccessObject;
10
17
21 protected $mRevisionRecord = null;
22
26 protected $mImage = null;
27
31 protected $mTitle;
32
36 protected $mText;
37
41 public function __construct( $title ) {
42 $this->mTitle = $title;
43 $this->initFromTitle( $title );
44 }
45
52 protected function initFromTitle( $title ) {
53 $this->mTitle = $title;
54 if ( $title !== null && $title->canExist() ) {
56 $id = false;
57 ( new HookRunner( $services->getHookContainer() ) )->onSearchResultInitFromTitle( $title, $id );
58
59 $this->mRevisionRecord = $services->getRevisionLookup()->getRevisionByTitle(
60 $title,
61 $id,
62 IDBAccessObject::READ_NORMAL
63 );
64 if ( $title->getNamespace() === NS_FILE ) {
65 $this->mImage = $services->getRepoGroup()->findFile( $title );
66 }
67 }
68 }
69
75 public function isBrokenTitle() {
76 return $this->mTitle === null;
77 }
78
84 public function isMissingRevision() {
85 return !$this->mRevisionRecord && !$this->mImage;
86 }
87
91 public function getTitle() {
92 return $this->mTitle;
93 }
94
99 public function getFile() {
100 return $this->mImage;
101 }
102
106 protected function initText() {
107 if ( $this->mText === null ) {
108 if ( $this->mRevisionRecord != null ) {
109 $content = $this->mRevisionRecord->getContent( SlotRecord::MAIN );
110 $this->mText = $content !== null ? $content->getTextForSearchIndex() : '';
111 } else { // TODO: can we fetch raw wikitext for commons images?
112 $this->mText = '';
113 }
114 }
115 }
116
121 public function getTextSnippet( $terms = [] ) {
122 return '';
123 }
124
128 public function getTitleSnippet() {
129 return '';
130 }
131
135 public function getRedirectSnippet() {
136 return '';
137 }
138
142 public function getRedirectTitle() {
143 return null;
144 }
145
149 public function getSectionSnippet() {
150 return '';
151 }
152
157 public function getSectionTitle() {
158 return null;
159 }
160
164 public function getCategorySnippet() {
165 return '';
166 }
167
171 public function getTimestamp() {
172 if ( $this->mRevisionRecord ) {
173 return $this->mRevisionRecord->getTimestamp();
174 } elseif ( $this->mImage ) {
175 return $this->mImage->getTimestamp();
176 }
177 return '';
178 }
179
183 public function getWordCount() {
184 $this->initText();
185 return str_word_count( $this->mText );
186 }
187
191 public function getByteSize() {
192 $this->initText();
193 return strlen( $this->mText );
194 }
195
199 public function getInterwikiPrefix() {
200 return '';
201 }
202
206 public function getInterwikiNamespaceText() {
207 return '';
208 }
209
214 public function isFileMatch() {
215 return false;
216 }
217}
218
220class_alias( RevisionSearchResult::class, 'RevisionSearchResult' );
const NS_FILE
Definition Defines.php:57
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:80
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Page revision base class.
Value object representing a content slot associated with a page revision.
SearchResult class based on the revision information.
getFile()
Get the file for this page, if one exists.
MediaWiki FileRepo File File null $mImage
isBrokenTitle()
Check if this is result points to an invalid title.
isFileMatch()
Did this match file contents (eg: PDF/DJVU)?
isMissingRevision()
Check if target page is missing, happens when index is out of date.
initText()
Lazy initialization of article text from DB.
initFromTitle( $title)
Initialize from a Title and if possible initializes a corresponding RevisionRecord and File.
MediaWiki Revision RevisionRecord null $mRevisionRecord
An abstract base class representing a search engine result.
Represents a title within MediaWiki.
Definition Title.php:69
Definition of a mapping for the search index field.
Helper trait for implementations \DAO.