MediaWiki REL1_34
RevisionSearchResultTrait.php
Go to the documentation of this file.
1<?php
2
4
16 protected $mRevision = null;
17
21 protected $mImage = null;
22
26 protected $mTitle;
27
31 protected $mText;
32
39 protected function initFromTitle( $title ) {
40 $this->mTitle = $title;
41 $services = MediaWikiServices::getInstance();
42 if ( !is_null( $this->mTitle ) ) {
43 $id = false;
44 Hooks::run( 'SearchResultInitFromTitle', [ $title, &$id ] );
45 $this->mRevision = Revision::newFromTitle(
46 $this->mTitle, $id, Revision::READ_NORMAL );
47 if ( $this->mTitle->getNamespace() === NS_FILE ) {
48 $this->mImage = $services->getRepoGroup()->findFile( $this->mTitle );
49 }
50 }
51 }
52
58 public function isBrokenTitle() {
59 return is_null( $this->mTitle );
60 }
61
67 public function isMissingRevision() {
68 return !$this->mRevision && !$this->mImage;
69 }
70
74 public function getTitle() {
75 return $this->mTitle;
76 }
77
82 public function getFile() {
83 return $this->mImage;
84 }
85
89 protected function initText() {
90 if ( !isset( $this->mText ) ) {
91 if ( $this->mRevision != null ) {
92 $content = $this->mRevision->getContent();
93 $this->mText = $content !== null ? $content->getTextForSearchIndex() : '';
94 } else { // TODO: can we fetch raw wikitext for commons images?
95 $this->mText = '';
96 }
97 }
98 }
99
104 public function getTextSnippet( $terms = [] ) {
105 return '';
106 }
107
111 public function getTitleSnippet() {
112 return '';
113 }
114
118 public function getRedirectSnippet() {
119 return '';
120 }
121
125 public function getRedirectTitle() {
126 return null;
127 }
128
132 public function getSectionSnippet() {
133 return '';
134 }
135
140 public function getSectionTitle() {
141 return null;
142 }
143
147 public function getCategorySnippet() {
148 return '';
149 }
150
154 public function getTimestamp() {
155 if ( $this->mRevision ) {
156 return $this->mRevision->getTimestamp();
157 } elseif ( $this->mImage ) {
158 return $this->mImage->getTimestamp();
159 }
160 return '';
161 }
162
166 public function getWordCount() {
167 $this->initText();
168 return str_word_count( $this->mText );
169 }
170
174 public function getByteSize() {
175 $this->initText();
176 return strlen( $this->mText );
177 }
178
182 public function getInterwikiPrefix() {
183 return '';
184 }
185
189 public function getInterwikiNamespaceText() {
190 return '';
191 }
192
197 public function isFileMatch() {
198 return false;
199 }
200}
isMissingRevision()
Check if target page is missing, happens when index is out of date.
getTextSnippet( $terms=[])
initFromTitle( $title)
Initialize from a Title and if possible initializes a corresponding Revision 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:61
getTimestamp()
Get the 14-character timestamp of the file upload.
Definition File.php:2120
MediaWikiServices is the service locator for the application scope of MediaWiki.
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
Definition Revision.php:138
Represents a title within MediaWiki.
Definition Title.php:42
const NS_FILE
Definition Defines.php:75
$content
Definition router.php:78