| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\HookContainer\HookRunner; |
| 4 |
use MediaWiki\MediaWikiServices; |
| 5 |
use MediaWiki\Revision\RevisionRecord; |
| 6 |
use MediaWiki\Revision\SlotRecord; |
| 7 |
use MediaWiki\Title\Title; |
| 8 |
use Wikimedia\Rdbms\IDBAccessObject; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
trait RevisionSearchResultTrait { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
protected $mRevisionRecord = null; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
protected $mImage = null; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
protected $mTitle; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
protected $mText; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 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 |
IDBAccessObject::READ_NORMAL |
| 55 |
); |
| 56 |
if ( $title->getNamespace() === NS_FILE ) { |
| 57 |
$this->mImage = $services->getRepoGroup()->findFile( $title ); |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public function isBrokenTitle() { |
| 68 |
return $this->mTitle === null; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public function isMissingRevision() { |
| 77 |
return !$this->mRevisionRecord && !$this->mImage; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public function getTitle() { |
| 84 |
return $this->mTitle; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public function getFile() { |
| 92 |
return $this->mImage; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 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 { |
| 104 |
$this->mText = ''; |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public function getTextSnippet( $terms = [] ) { |
| 114 |
return ''; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public function getTextSnippetField() { |
| 121 |
return ''; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
public function getTitleSnippet() { |
| 128 |
return ''; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public function getTitleSnippetField() { |
| 135 |
return ''; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
public function getRedirectSnippet() { |
| 142 |
return ''; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
public function getRedirectSnippetField() { |
| 149 |
return ''; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
public function getRedirectTitle() { |
| 156 |
return null; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
public function getSectionSnippet() { |
| 163 |
return ''; |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
public function getSectionSnippetField() { |
| 170 |
return ''; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
public function getSectionTitle() { |
| 178 |
return null; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
public function getCategorySnippet() { |
| 185 |
return ''; |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
public function getCategorySnippetField() { |
| 192 |
return ''; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 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 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
public function getWordCount() { |
| 211 |
$this->initText(); |
| 212 |
return str_word_count( $this->mText ); |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
public function getByteSize() { |
| 219 |
$this->initText(); |
| 220 |
return strlen( $this->mText ); |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
public function getInterwikiPrefix() { |
| 227 |
return ''; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
public function getInterwikiNamespaceText() { |
| 234 |
return ''; |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
public function isFileMatch() { |
| 242 |
return false; |
| 243 |
} |
| 244 |
} |