MediaWiki master
FileContentHandler.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Content;
4
10use WikiPage;
11
19
20 public function getFieldsForSearchIndex( SearchEngine $engine ) {
21 $fields = [];
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 );
40 return $fields;
41 }
42
43 public function getDataForSearchIndex(
44 WikiPage $page,
45 ParserOutput $parserOutput,
46 SearchEngine $engine,
47 ?RevisionRecord $revision = null
48 ) {
49 $fields = [];
50
51 $title = $page->getTitle();
52 if ( NS_FILE != $title->getNamespace() ) {
53 return [];
54 }
55 $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
56 ->newFile( $title );
57 if ( !$file || !$file->exists() ) {
58 return [];
59 }
60
61 $handler = $file->getHandler();
62 if ( $handler ) {
63 $fileText = $handler->getEntireText( $file );
64 if ( $fileText !== false ) {
65 $fields['file_text'] = $fileText;
66 }
67 }
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'] ) );
76
77 return $fields;
78 }
79
80}
81
83class_alias( FileContentHandler::class, 'FileContentHandler' );
const NS_FILE
Definition Defines.php:71
Content handler for File: files TODO: this handler is not used directly now, but instead manually cal...
getDataForSearchIndex(WikiPage $page, ParserOutput $parserOutput, SearchEngine $engine, ?RevisionRecord $revision=null)
Return fields to be indexed by search engine as representation of this document.
getFieldsForSearchIndex(SearchEngine $engine)
Get fields definition for search index.
Content handler for wiki text pages.
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
ParserOutput is a rendering of a Content object or a message.
Page revision base class.
Contain a class for special pages.
makeSearchFieldMapping( $name, $type)
Create a search field definition.
Base representation for an editable wiki page.
Definition WikiPage.php:84
getTitle()
Get the title object of the article.
Definition WikiPage.php:252
Definition of a mapping for the search index field.