MediaWiki REL1_33
FileContentHandler.php
Go to the documentation of this file.
1<?php
2
10
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;
31 }
32
33 public function getDataForSearchIndex(
34 WikiPage $page,
35 ParserOutput $parserOutput,
37 ) {
38 $fields = [];
39
40 $title = $page->getTitle();
41 if ( NS_FILE != $title->getNamespace() ) {
42 return [];
43 }
44 $file = wfLocalFile( $title );
45 if ( !$file || !$file->exists() ) {
46 return [];
47 }
48
49 $handler = $file->getHandler();
50 if ( $handler ) {
51 $fields['file_text'] = $handler->getEntireText( $file );
52 }
53 $fields['file_media_type'] = $file->getMediaType();
54 $fields['file_mime'] = $file->getMimeType();
55 $fields['file_size'] = $file->getSize();
56 $fields['file_width'] = $file->getWidth();
57 $fields['file_height'] = $file->getHeight();
58 $fields['file_bits'] = $file->getBitDepth();
59 $fields['file_resolution'] =
60 (int)floor( sqrt( $fields['file_width'] * $fields['file_height'] ) );
61
62 return $fields;
63 }
64
65}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfLocalFile( $title)
Get an object referring to a locally registered file.
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)
Return fields to be indexed by search engine as representation of this document.
Contain a class for special pages.
Class representing a MediaWiki article and history.
Definition WikiPage.php:45
Content handler for wiki text pages.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition hooks.txt:894
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition hooks.txt:2925
const NS_FILE
Definition Defines.php:79
const INDEX_TYPE_TEXT
TEXT fields are suitable for natural language and may be subject to analysis such as stemming.
const INDEX_TYPE_SHORT_TEXT
SHORT_TEXT is meant to be used with short text made of mostly ascii technical information.
const INDEX_TYPE_KEYWORD
KEYWORD fields are indexed without any processing, so are appropriate for e.g.
const FLAG_CASEFOLD
Generic field flags.