MediaWiki  master
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'] =
21  $fields['file_mime']->setFlag( SearchIndexField::FLAG_CASEFOLD );
22  $fields['file_size'] =
24  $fields['file_width'] =
26  $fields['file_height'] =
28  $fields['file_bits'] =
30  $fields['file_resolution'] =
31  $engine->makeSearchFieldMapping( 'file_resolution', SearchIndexField::INDEX_TYPE_INTEGER );
32  $fields['file_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:77
getTitle()
Get the title object of the article.
Definition: WikiPage.php:258
Content handler for wiki text pages.
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