MediaWiki  1.34.0
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 }
SearchIndexField\INDEX_TYPE_KEYWORD
const INDEX_TYPE_KEYWORD
KEYWORD fields are indexed without any processing, so are appropriate for e.g.
Definition: SearchIndexField.php:23
ParserOutput
Definition: ParserOutput.php:25
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
SearchIndexField\INDEX_TYPE_SHORT_TEXT
const INDEX_TYPE_SHORT_TEXT
SHORT_TEXT is meant to be used with short text made of mostly ascii technical information.
Definition: SearchIndexField.php:36
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:47
NS_FILE
const NS_FILE
Definition: Defines.php:66
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
SearchIndexField\FLAG_CASEFOLD
const FLAG_CASEFOLD
Generic field flags.
Definition: SearchIndexField.php:44
WikiPage\getTitle
getTitle()
Get the title object of the article.
Definition: WikiPage.php:298
FileContentHandler\getDataForSearchIndex
getDataForSearchIndex(WikiPage $page, ParserOutput $parserOutput, SearchEngine $engine)
Return fields to be indexed by search engine as representation of this document.
Definition: FileContentHandler.php:36
$title
$title
Definition: testCompression.php:34
WikitextContentHandler
Content handler for wiki text pages.
Definition: WikitextContentHandler.php:33
FileContentHandler
Content handler for File: files TODO: this handler s not used directly now, but instead manually call...
Definition: FileContentHandler.php:11
SearchEngine
Contain a class for special pages.
Definition: SearchEngine.php:34
SearchEngine\makeSearchFieldMapping
makeSearchFieldMapping( $name, $type)
Create a search field definition.
Definition: SearchEngine.php:744
SearchIndexField\INDEX_TYPE_INTEGER
const INDEX_TYPE_INTEGER
Definition: SearchIndexField.php:24
FileContentHandler\getFieldsForSearchIndex
getFieldsForSearchIndex(SearchEngine $engine)
Get fields definition for search index.
Definition: FileContentHandler.php:13
SearchIndexField\INDEX_TYPE_TEXT
const INDEX_TYPE_TEXT
TEXT fields are suitable for natural language and may be subject to analysis such as stemming.
Definition: SearchIndexField.php:18