MediaWiki REL1_34
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'] =
17 $fields['file_media_type']->setFlag( SearchIndexField::FLAG_CASEFOLD );
18 $fields['file_mime'] =
20 $fields['file_mime']->setFlag( SearchIndexField::FLAG_CASEFOLD );
21 $fields['file_size'] =
23 $fields['file_width'] =
25 $fields['file_height'] =
27 $fields['file_bits'] =
29 $fields['file_resolution'] =
31 $fields['file_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}
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.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Contain a class for special pages.
makeSearchFieldMapping( $name, $type)
Create a search field definition.
Class representing a MediaWiki article and history.
Definition WikiPage.php:47
getTitle()
Get the title object of the article.
Definition WikiPage.php:298
Content handler for wiki text pages.
const NS_FILE
Definition Defines.php:75
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42