MediaWiki REL1_35
RevisionSearchResultTrait.php
Go to the documentation of this file.
1<?php
2
7
19 protected $mRevisionRecord = null;
20
24 protected $mImage = null;
25
29 protected $mTitle;
30
34 protected $mText;
35
42 protected function initFromTitle( $title ) {
43 $this->mTitle = $title;
44 if ( $title !== null ) {
45 $services = MediaWikiServices::getInstance();
46 $id = false;
47 Hooks::runner()->onSearchResultInitFromTitle( $title, $id );
48
49 $this->mRevisionRecord = $services->getRevisionLookup()->getRevisionByTitle(
50 $title,
51 $id,
52 RevisionLookup::READ_NORMAL
53 );
54 if ( $title->getNamespace() === NS_FILE ) {
55 $this->mImage = $services->getRepoGroup()->findFile( $title );
56 }
57 }
58 }
59
65 public function isBrokenTitle() {
66 return $this->mTitle === null;
67 }
68
74 public function isMissingRevision() {
75 return !$this->mRevisionRecord && !$this->mImage;
76 }
77
81 public function getTitle() {
82 return $this->mTitle;
83 }
84
89 public function getFile() {
90 return $this->mImage;
91 }
92
96 protected function initText() {
97 if ( !isset( $this->mText ) ) {
98 if ( $this->mRevisionRecord != null ) {
99 $content = $this->mRevisionRecord->getContent( SlotRecord::MAIN );
100 $this->mText = $content !== null ? $content->getTextForSearchIndex() : '';
101 } else { // TODO: can we fetch raw wikitext for commons images?
102 $this->mText = '';
103 }
104 }
105 }
106
111 public function getTextSnippet( $terms = [] ) {
112 return '';
113 }
114
118 public function getTitleSnippet() {
119 return '';
120 }
121
125 public function getRedirectSnippet() {
126 return '';
127 }
128
132 public function getRedirectTitle() {
133 return null;
134 }
135
139 public function getSectionSnippet() {
140 return '';
141 }
142
147 public function getSectionTitle() {
148 return null;
149 }
150
154 public function getCategorySnippet() {
155 return '';
156 }
157
161 public function getTimestamp() {
162 if ( $this->mRevisionRecord ) {
163 return $this->mRevisionRecord->getTimestamp();
164 } elseif ( $this->mImage ) {
165 return $this->mImage->getTimestamp();
166 }
167 return '';
168 }
169
173 public function getWordCount() {
174 $this->initText();
175 return str_word_count( $this->mText );
176 }
177
181 public function getByteSize() {
182 $this->initText();
183 return strlen( $this->mText );
184 }
185
189 public function getInterwikiPrefix() {
190 return '';
191 }
192
196 public function getInterwikiNamespaceText() {
197 return '';
198 }
199
204 public function isFileMatch() {
205 return false;
206 }
207}
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.
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:63
getTimestamp()
Get the 14-character timestamp of the file upload.
Definition File.php:2249
MediaWikiServices is the service locator for the application scope of MediaWiki.
Page revision base class.
Value object representing a content slot associated with a page revision.
Represents a title within MediaWiki.
Definition Title.php:42
const NS_FILE
Definition Defines.php:76
Service for looking up page revisions.
$content
Definition router.php:76