MediaWiki  master
FileContentHandler.php
Go to the documentation of this file.
1 <?php
2 
4 
12 
14  $fields['file_media_type'] =
15  $engine->makeSearchFieldMapping( 'file_media_type', SearchIndexField::INDEX_TYPE_KEYWORD );
16  $fields['file_media_type']->setFlag( SearchIndexField::FLAG_CASEFOLD );
17  $fields['file_mime'] =
19  $fields['file_mime']->setFlag( SearchIndexField::FLAG_CASEFOLD );
20  $fields['file_size'] =
22  $fields['file_width'] =
24  $fields['file_height'] =
26  $fields['file_bits'] =
28  $fields['file_resolution'] =
29  $engine->makeSearchFieldMapping( 'file_resolution', SearchIndexField::INDEX_TYPE_INTEGER );
30  $fields['file_text'] =
32  return $fields;
33  }
34 
35  public function getDataForSearchIndex(
36  WikiPage $page,
37  ParserOutput $parserOutput,
39  ) {
40  $fields = [];
41 
42  $title = $page->getTitle();
43  if ( NS_FILE != $title->getNamespace() ) {
44  return [];
45  }
46  $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
47  ->newFile( $title );
48  if ( !$file || !$file->exists() ) {
49  return [];
50  }
51 
52  $handler = $file->getHandler();
53  if ( $handler ) {
54  $fields['file_text'] = $handler->getEntireText( $file );
55  }
56  $fields['file_media_type'] = $file->getMediaType();
57  $fields['file_mime'] = $file->getMimeType();
58  $fields['file_size'] = $file->getSize();
59  $fields['file_width'] = $file->getWidth();
60  $fields['file_height'] = $file->getHeight();
61  $fields['file_bits'] = $file->getBitDepth();
62  $fields['file_resolution'] =
63  (int)floor( sqrt( $fields['file_width'] * $fields['file_height'] ) );
64 
65  return $fields;
66  }
67 
68 }
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Definition: router.php:42
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition: hooks.txt:780
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:294
makeSearchFieldMapping( $name, $type)
Create a search field definition.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
const FLAG_CASEFOLD
Generic field flags.
const NS_FILE
Definition: Defines.php:66
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition: hooks.txt:2898
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
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.