MediaWiki master
RevisionSearchResultTrait.php
Go to the documentation of this file.
1<?php
2
10
22 protected $mRevisionRecord = null;
23
27 protected $mImage = null;
28
32 protected $mTitle;
33
37 protected $mText;
38
45 protected function initFromTitle( $title ) {
46 $this->mTitle = $title;
47 if ( $title !== null ) {
48 $services = MediaWikiServices::getInstance();
49 $id = false;
50 ( new HookRunner( $services->getHookContainer() ) )->onSearchResultInitFromTitle( $title, $id );
51
52 $this->mRevisionRecord = $services->getRevisionLookup()->getRevisionByTitle(
53 $title,
54 $id,
55 IDBAccessObject::READ_NORMAL
56 );
57 if ( $title->getNamespace() === NS_FILE ) {
58 $this->mImage = $services->getRepoGroup()->findFile( $title );
59 }
60 }
61 }
62
68 public function isBrokenTitle() {
69 return $this->mTitle === null;
70 }
71
77 public function isMissingRevision() {
78 return !$this->mRevisionRecord && !$this->mImage;
79 }
80
84 public function getTitle() {
85 return $this->mTitle;
86 }
87
92 public function getFile() {
93 return $this->mImage;
94 }
95
99 protected function initText() {
100 if ( $this->mText === null ) {
101 if ( $this->mRevisionRecord != null ) {
102 $content = $this->mRevisionRecord->getContent( SlotRecord::MAIN );
103 $this->mText = $content !== null ? $content->getTextForSearchIndex() : '';
104 } else { // TODO: can we fetch raw wikitext for commons images?
105 $this->mText = '';
106 }
107 }
108 }
109
114 public function getTextSnippet( $terms = [] ) {
115 return '';
116 }
117
121 public function getTextSnippetField() {
122 return '';
123 }
124
128 public function getTitleSnippet() {
129 return '';
130 }
131
135 public function getTitleSnippetField() {
136 return '';
137 }
138
142 public function getRedirectSnippet() {
143 return '';
144 }
145
149 public function getRedirectSnippetField() {
150 return '';
151 }
152
156 public function getRedirectTitle() {
157 return null;
158 }
159
163 public function getSectionSnippet() {
164 return '';
165 }
166
170 public function getSectionSnippetField() {
171 return '';
172 }
173
178 public function getSectionTitle() {
179 return null;
180 }
181
185 public function getCategorySnippet() {
186 return '';
187 }
188
192 public function getCategorySnippetField() {
193 return '';
194 }
195
199 public function getTimestamp() {
200 if ( $this->mRevisionRecord ) {
201 return $this->mRevisionRecord->getTimestamp();
202 } elseif ( $this->mImage ) {
203 return $this->mImage->getTimestamp();
204 }
205 return '';
206 }
207
211 public function getWordCount() {
212 $this->initText();
213 return str_word_count( $this->mText );
214 }
215
219 public function getByteSize() {
220 $this->initText();
221 return strlen( $this->mText );
222 }
223
227 public function getInterwikiPrefix() {
228 return '';
229 }
230
234 public function getInterwikiNamespaceText() {
235 return '';
236 }
237
242 public function isFileMatch() {
243 return false;
244 }
245}
const NS_FILE
Definition Defines.php:71
isMissingRevision()
Check if target page is missing, happens when index is out of date.
Title null $mTitle
string null $mText
getTextSnippet( $terms=[])
initFromTitle( $title)
Initialize from a Title and if possible initializes a corresponding RevisionRecord and File.
isFileMatch()
Did this match file contents (eg: PDF/DJVU)?
isBrokenTitle()
Check if this is result points to an invalid title.
File null $mImage
trait RevisionSearchResultTrait
Transitional trait used to share the methods between SearchResult and RevisionSearchResult.
getFile()
Get the file for this page, if one exists.
initText()
Lazy initialization of article text from DB.
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:93
getTimestamp()
Get the 14-character timestamp of the file upload.
Definition File.php:2395
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Service locator for MediaWiki core services.
Page revision base class.
Value object representing a content slot associated with a page revision.
Represents a title within MediaWiki.
Definition Title.php:78
Interface for database access objects.