MediaWiki master
RevisionSearchResultTrait.php
Go to the documentation of this file.
1<?php
2
8
20 protected $mRevisionRecord = null;
21
25 protected $mImage = null;
26
30 protected $mTitle;
31
35 protected $mText;
36
43 protected function initFromTitle( $title ) {
44 $this->mTitle = $title;
45 if ( $title !== null ) {
46 $services = MediaWikiServices::getInstance();
47 $id = false;
48 ( new HookRunner( $services->getHookContainer() ) )->onSearchResultInitFromTitle( $title, $id );
49
50 $this->mRevisionRecord = $services->getRevisionLookup()->getRevisionByTitle(
51 $title,
52 $id,
53 IDBAccessObject::READ_NORMAL
54 );
55 if ( $title->getNamespace() === NS_FILE ) {
56 $this->mImage = $services->getRepoGroup()->findFile( $title );
57 }
58 }
59 }
60
66 public function isBrokenTitle() {
67 return $this->mTitle === null;
68 }
69
75 public function isMissingRevision() {
76 return !$this->mRevisionRecord && !$this->mImage;
77 }
78
82 public function getTitle() {
83 return $this->mTitle;
84 }
85
90 public function getFile() {
91 return $this->mImage;
92 }
93
97 protected function initText() {
98 if ( !isset( $this->mText ) ) {
99 if ( $this->mRevisionRecord != null ) {
100 $content = $this->mRevisionRecord->getContent( SlotRecord::MAIN );
101 $this->mText = $content !== null ? $content->getTextForSearchIndex() : '';
102 } else { // TODO: can we fetch raw wikitext for commons images?
103 $this->mText = '';
104 }
105 }
106 }
107
112 public function getTextSnippet( $terms = [] ) {
113 return '';
114 }
115
119 public function getTextSnippetField() {
120 return '';
121 }
122
126 public function getTitleSnippet() {
127 return '';
128 }
129
133 public function getTitleSnippetField() {
134 return '';
135 }
136
140 public function getRedirectSnippet() {
141 return '';
142 }
143
147 public function getRedirectSnippetField() {
148 return '';
149 }
150
154 public function getRedirectTitle() {
155 return null;
156 }
157
161 public function getSectionSnippet() {
162 return '';
163 }
164
168 public function getSectionSnippetField() {
169 return '';
170 }
171
176 public function getSectionTitle() {
177 return null;
178 }
179
183 public function getCategorySnippet() {
184 return '';
185 }
186
190 public function getCategorySnippetField() {
191 return '';
192 }
193
197 public function getTimestamp() {
198 if ( $this->mRevisionRecord ) {
199 return $this->mRevisionRecord->getTimestamp();
200 } elseif ( $this->mImage ) {
201 return $this->mImage->getTimestamp();
202 }
203 return '';
204 }
205
209 public function getWordCount() {
210 $this->initText();
211 return str_word_count( $this->mText );
212 }
213
217 public function getByteSize() {
218 $this->initText();
219 return strlen( $this->mText );
220 }
221
225 public function getInterwikiPrefix() {
226 return '';
227 }
228
232 public function getInterwikiNamespaceText() {
233 return '';
234 }
235
240 public function isFileMatch() {
241 return false;
242 }
243}
const NS_FILE
Definition Defines.php:70
isMissingRevision()
Check if target page is missing, happens when index is out of date.
Title null $mTitle
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:73
getTimestamp()
Get the 14-character timestamp of the file upload.
Definition File.php:2307
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