3 namespace MediaWiki\Content
;
5 use MediaWiki\MediaWikiServices
;
6 use MediaWiki\Parser\ParserOutput
;
7 use MediaWiki\Revision\RevisionRecord
;
13 * Content handler for File: files
14 * TODO: this handler is not used directly now,
15 * but instead manually called by WikitextHandler.
16 * This should be fixed in the future.
18 class FileContentHandler
extends WikitextContentHandler
{
20 public function getFieldsForSearchIndex( SearchEngine
$engine ) {
22 $fields['file_media_type'] =
23 $engine->makeSearchFieldMapping( 'file_media_type', SearchIndexField
::INDEX_TYPE_KEYWORD
);
24 $fields['file_media_type']->setFlag( SearchIndexField
::FLAG_CASEFOLD
);
25 $fields['file_mime'] =
26 $engine->makeSearchFieldMapping( 'file_mime', SearchIndexField
::INDEX_TYPE_SHORT_TEXT
);
27 $fields['file_mime']->setFlag( SearchIndexField
::FLAG_CASEFOLD
);
28 $fields['file_size'] =
29 $engine->makeSearchFieldMapping( 'file_size', SearchIndexField
::INDEX_TYPE_INTEGER
);
30 $fields['file_width'] =
31 $engine->makeSearchFieldMapping( 'file_width', SearchIndexField
::INDEX_TYPE_INTEGER
);
32 $fields['file_height'] =
33 $engine->makeSearchFieldMapping( 'file_height', SearchIndexField
::INDEX_TYPE_INTEGER
);
34 $fields['file_bits'] =
35 $engine->makeSearchFieldMapping( 'file_bits', SearchIndexField
::INDEX_TYPE_INTEGER
);
36 $fields['file_resolution'] =
37 $engine->makeSearchFieldMapping( 'file_resolution', SearchIndexField
::INDEX_TYPE_INTEGER
);
38 $fields['file_text'] =
39 $engine->makeSearchFieldMapping( 'file_text', SearchIndexField
::INDEX_TYPE_TEXT
);
43 public function getDataForSearchIndex(
45 ParserOutput
$parserOutput,
47 ?RevisionRecord
$revision = null
51 $title = $page->getTitle();
52 if ( NS_FILE
!= $title->getNamespace() ) {
55 $file = MediaWikiServices
::getInstance()->getRepoGroup()->getLocalRepo()
57 if ( !$file ||
!$file->exists() ) {
61 $handler = $file->getHandler();
63 $fileText = $handler->getEntireText( $file );
64 if ( $fileText !== false ) {
65 $fields['file_text'] = $fileText;
68 $fields['file_media_type'] = $file->getMediaType();
69 $fields['file_mime'] = $file->getMimeType();
70 $fields['file_size'] = $file->getSize();
71 $fields['file_width'] = $file->getWidth();
72 $fields['file_height'] = $file->getHeight();
73 $fields['file_bits'] = $file->getBitDepth();
74 $fields['file_resolution'] =
75 (int)floor( sqrt( $fields['file_width'] * $fields['file_height'] ) );
82 /** @deprecated class alias since 1.43 */
83 class_alias( FileContentHandler
::class, 'FileContentHandler' );