MediaWiki  master
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'] =
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'] =
30  $engine->makeSearchFieldMapping( 'file_resolution', SearchIndexField::INDEX_TYPE_INTEGER );
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 }
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
const INDEX_TYPE_TEXT
TEXT fields are suitable for natural language and may be subject to analysis such as stemming...
Content handler for File: files TODO: this handler s not used directly now, but instead manually call...
getFieldsForSearchIndex(SearchEngine $engine)
getTitle()
Get the title object of the article.
Definition: WikiPage.php:298
makeSearchFieldMapping( $name, $type)
Create a search field definition.
const FLAG_CASEFOLD
Generic field flags.
const NS_FILE
Definition: Defines.php:66
const INDEX_TYPE_KEYWORD
KEYWORD fields are indexed without any processing, so are appropriate for e.g.
getDataForSearchIndex(WikiPage $page, ParserOutput $parserOutput, SearchEngine $engine)
Content handler for wiki text pages.
const INDEX_TYPE_SHORT_TEXT
SHORT_TEXT is meant to be used with short text made of mostly ascii technical information.