MessageCache invalidation improvements
[mediawiki.git] / includes / content / FileContentHandler.php
blob26f119065df95e7d447e6405739a5b5ea52b8cc7
1 <?php
3 /**
4 * Content handler for File: files
5 * TODO: this handler s not used directly now,
6 * but instead manually called by WikitextHandler.
7 * This should be fixed in the future.
8 */
9 class FileContentHandler extends WikitextContentHandler {
11 public function getFieldsForSearchIndex( SearchEngine $engine ) {
12 $fields['file_media_type'] =
13 $engine->makeSearchFieldMapping( 'file_media_type', SearchIndexField::INDEX_TYPE_KEYWORD );
14 $fields['file_media_type']->setFlag( SearchIndexField::FLAG_CASEFOLD );
15 $fields['file_mime'] =
16 $engine->makeSearchFieldMapping( 'file_mime', SearchIndexField::INDEX_TYPE_SHORT_TEXT );
17 $fields['file_mime']->setFlag( SearchIndexField::FLAG_CASEFOLD );
18 $fields['file_size'] =
19 $engine->makeSearchFieldMapping( 'file_size', SearchIndexField::INDEX_TYPE_INTEGER );
20 $fields['file_width'] =
21 $engine->makeSearchFieldMapping( 'file_width', SearchIndexField::INDEX_TYPE_INTEGER );
22 $fields['file_height'] =
23 $engine->makeSearchFieldMapping( 'file_height', SearchIndexField::INDEX_TYPE_INTEGER );
24 $fields['file_bits'] =
25 $engine->makeSearchFieldMapping( 'file_bits', SearchIndexField::INDEX_TYPE_INTEGER );
26 $fields['file_resolution'] =
27 $engine->makeSearchFieldMapping( 'file_resolution', SearchIndexField::INDEX_TYPE_INTEGER );
28 $fields['file_text'] =
29 $engine->makeSearchFieldMapping( 'file_text', SearchIndexField::INDEX_TYPE_TEXT );
30 return $fields;
33 public function getDataForSearchIndex( WikiPage $page, ParserOutput $parserOutput,
34 SearchEngine $engine ) {
35 $fields = [];
37 $title = $page->getTitle();
38 if ( NS_FILE != $title->getNamespace() ) {
39 return [];
41 $file = wfLocalFile( $title );
42 if ( !$file || !$file->exists() ) {
43 return [];
46 $handler = $file->getHandler();
47 if ( $handler ) {
48 $fields['file_text'] = $handler->getEntireText( $file );
50 $fields['file_media_type'] = $file->getMediaType();
51 $fields['file_mime'] = $file->getMimeType();
52 $fields['file_size'] = $file->getSize();
53 $fields['file_width'] = $file->getWidth();
54 $fields['file_height'] = $file->getHeight();
55 $fields['file_bits'] = $file->getBitDepth();
56 $fields['file_resolution'] =
57 (int)floor( sqrt( $fields['file_width'] * $fields['file_height'] ) );
59 return $fields;