MediaWiki  master
RevisionSearchResultTrait.php
Go to the documentation of this file.
1 <?php
2 
9 
21  protected $mRevisionRecord = null;
22 
26  protected $mImage = null;
27 
31  protected $mTitle;
32 
36  protected $mText;
37 
44  protected function initFromTitle( $title ) {
45  $this->mTitle = $title;
46  if ( $title !== null ) {
47  $services = MediaWikiServices::getInstance();
48  $id = false;
49  ( new HookRunner( $services->getHookContainer() ) )->onSearchResultInitFromTitle( $title, $id );
50 
51  $this->mRevisionRecord = $services->getRevisionLookup()->getRevisionByTitle(
52  $title,
53  $id,
54  RevisionLookup::READ_NORMAL
55  );
56  if ( $title->getNamespace() === NS_FILE ) {
57  $this->mImage = $services->getRepoGroup()->findFile( $title );
58  }
59  }
60  }
61 
67  public function isBrokenTitle() {
68  return $this->mTitle === null;
69  }
70 
76  public function isMissingRevision() {
77  return !$this->mRevisionRecord && !$this->mImage;
78  }
79 
83  public function getTitle() {
84  return $this->mTitle;
85  }
86 
91  public function getFile() {
92  return $this->mImage;
93  }
94 
98  protected function initText() {
99  if ( !isset( $this->mText ) ) {
100  if ( $this->mRevisionRecord != null ) {
101  $content = $this->mRevisionRecord->getContent( SlotRecord::MAIN );
102  $this->mText = $content !== null ? $content->getTextForSearchIndex() : '';
103  } else { // TODO: can we fetch raw wikitext for commons images?
104  $this->mText = '';
105  }
106  }
107  }
108 
113  public function getTextSnippet( $terms = [] ) {
114  return '';
115  }
116 
120  public function getTextSnippetField() {
121  return '';
122  }
123 
127  public function getTitleSnippet() {
128  return '';
129  }
130 
134  public function getTitleSnippetField() {
135  return '';
136  }
137 
141  public function getRedirectSnippet() {
142  return '';
143  }
144 
148  public function getRedirectSnippetField() {
149  return '';
150  }
151 
155  public function getRedirectTitle() {
156  return null;
157  }
158 
162  public function getSectionSnippet() {
163  return '';
164  }
165 
169  public function getSectionSnippetField() {
170  return '';
171  }
172 
177  public function getSectionTitle() {
178  return null;
179  }
180 
184  public function getCategorySnippet() {
185  return '';
186  }
187 
191  public function getCategorySnippetField() {
192  return '';
193  }
194 
198  public function getTimestamp() {
199  if ( $this->mRevisionRecord ) {
200  return $this->mRevisionRecord->getTimestamp();
201  } elseif ( $this->mImage ) {
202  return $this->mImage->getTimestamp();
203  }
204  return '';
205  }
206 
210  public function getWordCount() {
211  $this->initText();
212  return str_word_count( $this->mText );
213  }
214 
218  public function getByteSize() {
219  $this->initText();
220  return strlen( $this->mText );
221  }
222 
226  public function getInterwikiPrefix() {
227  return '';
228  }
229 
233  public function getInterwikiNamespaceText() {
234  return '';
235  }
236 
241  public function isFileMatch() {
242  return false;
243  }
244 }
const NS_FILE
Definition: Defines.php:70
isMissingRevision()
Check if target page is missing, happens when index is out of date.
Title null $mTitle
getInterwikiNamespaceText()
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.
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:565
Service locator for MediaWiki core services.
Page revision base class.
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:40
Represents a title within MediaWiki.
Definition: Title.php:82
Service for looking up page revisions.
$content
Definition: router.php:76