MediaWiki  1.29.1
FileContentHandler.php
Go to the documentation of this file.
1 <?php
2 
10 
12  $fields['file_media_type'] =
13  $engine->makeSearchFieldMapping( 'file_media_type', SearchIndexField::INDEX_TYPE_KEYWORD );
14  $fields['file_media_type']->setFlag( SearchIndexField::FLAG_CASEFOLD );
15  $fields['file_mime'] =
16  $engine->makeSearchFieldMapping( 'file_mime', SearchIndexField::INDEX_TYPE_SHORT_TEXT );
17  $fields['file_mime']->setFlag( SearchIndexField::FLAG_CASEFOLD );
18  $fields['file_size'] =
19  $engine->makeSearchFieldMapping( 'file_size', SearchIndexField::INDEX_TYPE_INTEGER );
20  $fields['file_width'] =
21  $engine->makeSearchFieldMapping( 'file_width', SearchIndexField::INDEX_TYPE_INTEGER );
22  $fields['file_height'] =
23  $engine->makeSearchFieldMapping( 'file_height', SearchIndexField::INDEX_TYPE_INTEGER );
24  $fields['file_bits'] =
25  $engine->makeSearchFieldMapping( 'file_bits', SearchIndexField::INDEX_TYPE_INTEGER );
26  $fields['file_resolution'] =
27  $engine->makeSearchFieldMapping( 'file_resolution', SearchIndexField::INDEX_TYPE_INTEGER );
28  $fields['file_text'] =
29  $engine->makeSearchFieldMapping( 'file_text', SearchIndexField::INDEX_TYPE_TEXT );
30  return $fields;
31  }
32 
33  public function getDataForSearchIndex(
37  ) {
38  $fields = [];
39 
40  $title = $page->getTitle();
41  if ( NS_FILE != $title->getNamespace() ) {
42  return [];
43  }
44  $file = wfLocalFile( $title );
45  if ( !$file || !$file->exists() ) {
46  return [];
47  }
48 
49  $handler = $file->getHandler();
50  if ( $handler ) {
51  $fields['file_text'] = $handler->getEntireText( $file );
52  }
53  $fields['file_media_type'] = $file->getMediaType();
54  $fields['file_mime'] = $file->getMimeType();
55  $fields['file_size'] = $file->getSize();
56  $fields['file_width'] = $file->getWidth();
57  $fields['file_height'] = $file->getHeight();
58  $fields['file_bits'] = $file->getBitDepth();
59  $fields['file_resolution'] =
60  (int)floor( sqrt( $fields['file_width'] * $fields['file_height'] ) );
61 
62  return $fields;
63  }
64 
65 }
SearchIndexField\INDEX_TYPE_KEYWORD
const INDEX_TYPE_KEYWORD
Definition: SearchIndexField.php:11
ParserOutput
Definition: ParserOutput.php:24
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:24
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:36
NS_FILE
const NS_FILE
Definition: Defines.php:68
SearchIndexField\FLAG_CASEFOLD
const FLAG_CASEFOLD
Generic field flags.
Definition: SearchIndexField.php:32
php
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
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
$page
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2536
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:33
$engine
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition: hooks.txt:2782
WikitextContentHandler
Content handler for wiki text pages.
Definition: WikitextContentHandler.php:31
FileContentHandler
Content handler for File: files TODO: this handler s not used directly now, but instead manually call...
Definition: FileContentHandler.php:9
$handler
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub 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:783
SearchEngine
Contain a class for special pages.
Definition: SearchEngine.php:34
SearchIndexField\INDEX_TYPE_INTEGER
const INDEX_TYPE_INTEGER
Definition: SearchIndexField.php:12
wfLocalFile
wfLocalFile( $title)
Get an object referring to a locally registered file.
Definition: GlobalFunctions.php:3112
$parserOutput
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context $parserOutput
Definition: hooks.txt:1049
FileContentHandler\getFieldsForSearchIndex
getFieldsForSearchIndex(SearchEngine $engine)
Get fields definition for search index.
Definition: FileContentHandler.php:11
SearchIndexField\INDEX_TYPE_TEXT
const INDEX_TYPE_TEXT
Field types.
Definition: SearchIndexField.php:10