MediaWiki master
FileContentHandler.php
Go to the documentation of this file.
1<?php
2
6
14
15 public function getFieldsForSearchIndex( SearchEngine $engine ) {
16 $fields = [];
17 $fields['file_media_type'] =
18 $engine->makeSearchFieldMapping( 'file_media_type', SearchIndexField::INDEX_TYPE_KEYWORD );
19 $fields['file_media_type']->setFlag( SearchIndexField::FLAG_CASEFOLD );
20 $fields['file_mime'] =
21 $engine->makeSearchFieldMapping( 'file_mime', SearchIndexField::INDEX_TYPE_SHORT_TEXT );
22 $fields['file_mime']->setFlag( SearchIndexField::FLAG_CASEFOLD );
23 $fields['file_size'] =
24 $engine->makeSearchFieldMapping( 'file_size', SearchIndexField::INDEX_TYPE_INTEGER );
25 $fields['file_width'] =
26 $engine->makeSearchFieldMapping( 'file_width', SearchIndexField::INDEX_TYPE_INTEGER );
27 $fields['file_height'] =
28 $engine->makeSearchFieldMapping( 'file_height', SearchIndexField::INDEX_TYPE_INTEGER );
29 $fields['file_bits'] =
30 $engine->makeSearchFieldMapping( 'file_bits', SearchIndexField::INDEX_TYPE_INTEGER );
31 $fields['file_resolution'] =
32 $engine->makeSearchFieldMapping( 'file_resolution', SearchIndexField::INDEX_TYPE_INTEGER );
33 $fields['file_text'] =
34 $engine->makeSearchFieldMapping( 'file_text', SearchIndexField::INDEX_TYPE_TEXT );
35 return $fields;
36 }
37
38 public function getDataForSearchIndex(
39 WikiPage $page,
40 ParserOutput $parserOutput,
41 SearchEngine $engine,
42 ?RevisionRecord $revision = null
43 ) {
44 $fields = [];
45
46 $title = $page->getTitle();
47 if ( NS_FILE != $title->getNamespace() ) {
48 return [];
49 }
50 $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
51 ->newFile( $title );
52 if ( !$file || !$file->exists() ) {
53 return [];
54 }
55
56 $handler = $file->getHandler();
57 if ( $handler ) {
58 $fileText = $handler->getEntireText( $file );
59 if ( $fileText !== false ) {
60 $fields['file_text'] = $fileText;
61 }
62 }
63 $fields['file_media_type'] = $file->getMediaType();
64 $fields['file_mime'] = $file->getMimeType();
65 $fields['file_size'] = $file->getSize();
66 $fields['file_width'] = $file->getWidth();
67 $fields['file_height'] = $file->getHeight();
68 $fields['file_bits'] = $file->getBitDepth();
69 $fields['file_resolution'] =
70 (int)floor( sqrt( $fields['file_width'] * $fields['file_height'] ) );
71
72 return $fields;
73 }
74
75}
const NS_FILE
Definition Defines.php:70
Content handler for File: files TODO: this handler s not used directly now, but instead manually call...
getFieldsForSearchIndex(SearchEngine $engine)
Get fields definition for search index.
getDataForSearchIndex(WikiPage $page, ParserOutput $parserOutput, SearchEngine $engine, ?RevisionRecord $revision=null)
Service locator for MediaWiki core services.
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:79
getTitle()
Get the title object of the article.
Definition WikiPage.php:260
Content handler for wiki text pages.