MediaWiki REL1_39
FileContentHandler.php
Go to the documentation of this file.
1<?php
2
4
12
13 public function getFieldsForSearchIndex( SearchEngine $engine ) {
14 $fields = [];
15 $fields['file_media_type'] =
16 $engine->makeSearchFieldMapping( 'file_media_type', SearchIndexField::INDEX_TYPE_KEYWORD );
17 $fields['file_media_type']->setFlag( SearchIndexField::FLAG_CASEFOLD );
18 $fields['file_mime'] =
19 $engine->makeSearchFieldMapping( 'file_mime', SearchIndexField::INDEX_TYPE_SHORT_TEXT );
20 $fields['file_mime']->setFlag( SearchIndexField::FLAG_CASEFOLD );
21 $fields['file_size'] =
22 $engine->makeSearchFieldMapping( 'file_size', SearchIndexField::INDEX_TYPE_INTEGER );
23 $fields['file_width'] =
24 $engine->makeSearchFieldMapping( 'file_width', SearchIndexField::INDEX_TYPE_INTEGER );
25 $fields['file_height'] =
26 $engine->makeSearchFieldMapping( 'file_height', SearchIndexField::INDEX_TYPE_INTEGER );
27 $fields['file_bits'] =
28 $engine->makeSearchFieldMapping( 'file_bits', SearchIndexField::INDEX_TYPE_INTEGER );
29 $fields['file_resolution'] =
30 $engine->makeSearchFieldMapping( 'file_resolution', SearchIndexField::INDEX_TYPE_INTEGER );
31 $fields['file_text'] =
32 $engine->makeSearchFieldMapping( 'file_text', SearchIndexField::INDEX_TYPE_TEXT );
33 return $fields;
34 }
35
36 public function getDataForSearchIndex(
37 WikiPage $page,
38 ParserOutput $parserOutput,
39 SearchEngine $engine
40 ) {
41 $fields = [];
42
43 $title = $page->getTitle();
44 if ( NS_FILE != $title->getNamespace() ) {
45 return [];
46 }
47 $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
48 ->newFile( $title );
49 if ( !$file || !$file->exists() ) {
50 return [];
51 }
52
53 $handler = $file->getHandler();
54 if ( $handler ) {
55 $fields['file_text'] = $handler->getEntireText( $file );
56 }
57 $fields['file_media_type'] = $file->getMediaType();
58 $fields['file_mime'] = $file->getMimeType();
59 $fields['file_size'] = $file->getSize();
60 $fields['file_width'] = $file->getWidth();
61 $fields['file_height'] = $file->getHeight();
62 $fields['file_bits'] = $file->getBitDepth();
63 $fields['file_resolution'] =
64 (int)floor( sqrt( $fields['file_width'] * $fields['file_height'] ) );
65
66 return $fields;
67 }
68
69}
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)
Return fields to be indexed by search engine as representation of this document.
Service locator for MediaWiki core services.
Contain a class for special pages.
makeSearchFieldMapping( $name, $type)
Create a search field definition.
Base representation for an editable wiki page.
Definition WikiPage.php:62
getTitle()
Get the title object of the article.
Definition WikiPage.php:303
Content handler for wiki text pages.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42