MediaWiki  master
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 }
getRedirectTitle
getRedirectTitle()
Definition: RevisionSearchResultTrait.php:132
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:154
getSectionSnippet
getSectionSnippet()
Definition: RevisionSearchResultTrait.php:139
getByteSize
getByteSize()
Definition: RevisionSearchResultTrait.php:181
NS_FILE
const NS_FILE
Definition: Defines.php:75
Revision\RevisionLookup
Service for looking up page revisions.
Definition: RevisionLookup.php:38
isFileMatch
isFileMatch()
Did this match file contents (eg: PDF/DJVU)?
Definition: RevisionSearchResultTrait.php:204
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:63
$mTitle
Title null $mTitle
Definition: RevisionSearchResultTrait.php:29
getSectionTitle
getSectionTitle()
Definition: RevisionSearchResultTrait.php:147
getWordCount
getWordCount()
Definition: RevisionSearchResultTrait.php:173
$title
$title
Definition: testCompression.php:38
$mImage
File $mImage
Definition: RevisionSearchResultTrait.php:24
$content
$content
Definition: router.php:76
isMissingRevision
isMissingRevision()
Check if target page is missing, happens when index is out of date.
Definition: RevisionSearchResultTrait.php:74
Hooks\runner
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition: Hooks.php:172
$mText
string $mText
Definition: RevisionSearchResultTrait.php:34
initFromTitle
initFromTitle( $title)
Initialize from a Title and if possible initializes a corresponding RevisionRecord and File.
Definition: RevisionSearchResultTrait.php:42
getInterwikiNamespaceText
getInterwikiNamespaceText()
Definition: RevisionSearchResultTrait.php:196
Title
Represents a title within MediaWiki.
Definition: Title.php:42
getCategorySnippet
getCategorySnippet()
Definition: RevisionSearchResultTrait.php:154
initText
initText()
Lazy initialization of article text from DB.
Definition: RevisionSearchResultTrait.php:96
getTitle
getTitle()
Definition: RevisionSearchResultTrait.php:81
getTimestamp
getTimestamp()
Definition: RevisionSearchResultTrait.php:161
getTextSnippet
getTextSnippet( $terms=[])
Definition: RevisionSearchResultTrait.php:111
getInterwikiPrefix
getInterwikiPrefix()
Definition: RevisionSearchResultTrait.php:189
getTitleSnippet
getTitleSnippet()
Definition: RevisionSearchResultTrait.php:118
RevisionSearchResultTrait
trait RevisionSearchResultTrait
Transitional trait used to share the methods between SearchResult and RevisionSearchResult.
Definition: RevisionSearchResultTrait.php:15
isBrokenTitle
isBrokenTitle()
Check if this is result points to an invalid title.
Definition: RevisionSearchResultTrait.php:65
getFile
getFile()
Get the file for this page, if one exists.
Definition: RevisionSearchResultTrait.php:89
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39
getRedirectSnippet
getRedirectSnippet()
Definition: RevisionSearchResultTrait.php:125