MediaWiki master
FileContentHandler.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Content;
4
11
22
24 public function getFieldsForSearchIndex( SearchEngine $engine ) {
25 $fields = [];
26 $fields['file_media_type'] =
27 $engine->makeSearchFieldMapping( 'file_media_type', SearchIndexField::INDEX_TYPE_KEYWORD );
28 $fields['file_media_type']->setFlag( SearchIndexField::FLAG_CASEFOLD );
29 $fields['file_mime'] =
30 $engine->makeSearchFieldMapping( 'file_mime', SearchIndexField::INDEX_TYPE_SHORT_TEXT );
31 $fields['file_mime']->setFlag( SearchIndexField::FLAG_CASEFOLD );
32 $fields['file_size'] =
33 $engine->makeSearchFieldMapping( 'file_size', SearchIndexField::INDEX_TYPE_INTEGER );
34 $fields['file_width'] =
35 $engine->makeSearchFieldMapping( 'file_width', SearchIndexField::INDEX_TYPE_INTEGER );
36 $fields['file_height'] =
37 $engine->makeSearchFieldMapping( 'file_height', SearchIndexField::INDEX_TYPE_INTEGER );
38 $fields['file_bits'] =
39 $engine->makeSearchFieldMapping( 'file_bits', SearchIndexField::INDEX_TYPE_INTEGER );
40 $fields['file_resolution'] =
41 $engine->makeSearchFieldMapping( 'file_resolution', SearchIndexField::INDEX_TYPE_INTEGER );
42 $fields['file_text'] =
43 $engine->makeSearchFieldMapping( 'file_text', SearchIndexField::INDEX_TYPE_TEXT );
44 return $fields;
45 }
46
48 public function getDataForSearchIndex(
49 WikiPage $page,
50 ParserOutput $parserOutput,
51 SearchEngine $engine,
52 ?RevisionRecord $revision = null
53 ) {
54 $fields = [];
55
56 $title = $page->getTitle();
57 if ( NS_FILE != $title->getNamespace() ) {
58 return [];
59 }
60 $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
61 ->newFile( $title );
62 if ( !$file || !$file->exists() ) {
63 return [];
64 }
65
66 $handler = $file->getHandler();
67 if ( $handler ) {
68 $fileText = $handler->getEntireText( $file );
69 if ( $fileText !== false ) {
70 $fields['file_text'] = $fileText;
71 }
72 }
73 $fields['file_media_type'] = $file->getMediaType();
74 $fields['file_mime'] = $file->getMimeType();
75 $fields['file_size'] = $file->getSize();
76 $fields['file_width'] = $file->getWidth();
77 $fields['file_height'] = $file->getHeight();
78 $fields['file_bits'] = $file->getBitDepth();
79 $fields['file_resolution'] =
80 (int)floor( sqrt( $fields['file_width'] * $fields['file_height'] ) );
81
82 return $fields;
83 }
84
85}
86
88class_alias( FileContentHandler::class, 'FileContentHandler' );
const NS_FILE
Definition Defines.php:71
Content handler for "File" page content.
getDataForSearchIndex(WikiPage $page, ParserOutput $parserOutput, SearchEngine $engine, ?RevisionRecord $revision=null)
Return fields to be indexed by search engine as representation of this document.Overriding class shou...
getFieldsForSearchIndex(SearchEngine $engine)
Get fields definition for search index.Expose title, redirect, namespace, text, source_text,...
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.
Base representation for an editable wiki page.
Definition WikiPage.php:94
getTitle()
Get the title object of the article.
Definition WikiPage.php:262
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.
Definition of a mapping for the search index field.