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