MediaWiki  1.29.1
GadgetDefinitionContent.php
Go to the documentation of this file.
1 <?php
24 
25  public function __construct( $text ) {
26  parent::__construct( $text, 'GadgetDefinition' );
27  }
28 
29  public function isValid() {
30  // parent::isValid() is called in validate()
31  return $this->validate()->isOK();
32  }
33 
41  public function beautifyJSON() {
42  // @todo we should normalize entries in module.scripts and module.styles
43  return FormatJson::encode( $this->getAssocArray(), "\t", FormatJson::UTF8_OK );
44  }
45 
55  protected function fillParserOutput( Title $title, $revId,
57  ) {
58  parent::fillParserOutput( $title, $revId, $options, $generateHtml, $output );
59  $assoc = $this->getAssocArray();
60  foreach ( [ 'scripts', 'styles' ] as $type ) {
61  foreach ( $assoc['module'][$type] as $page ) {
62  $title = Title::makeTitleSafe( NS_GADGET, $page );
63  if ( $title ) {
64  $output->addLink( $title );
65  }
66  }
67  }
68  }
69 
70 
74  public function validate() {
75  if ( !parent::isValid() ) {
76  return $this->getData();
77  }
78 
79  $validator = new GadgetDefinitionValidator();
80  return $validator->validate( $this->getAssocArray() );
81  }
82 
89  public function getAssocArray() {
90  $info = wfObjectToArray( $this->getData()->getValue() );
92  $handler = $this->getContentHandler();
93  $info = wfArrayPlus2d( $info, $handler->getDefaultMetadata() );
94 
95  return $info;
96  }
97 
104  return array_merge(
105  parent::getDeletionUpdates( $page, $parserOutput ),
106  [ new GadgetDefinitionDeletionUpdate( $page->getTitle()->getText() ) ]
107  );
108  }
109 
117  public function getSecondaryDataUpdates( Title $title, Content $old = null,
118  $recursive = true, ParserOutput $parserOutput = null
119  ) {
120  return array_merge(
121  parent::getSecondaryDataUpdates( $title, $old, $recursive, $parserOutput ),
122  [ new GadgetDefinitionSecondaryDataUpdate( $title->getText() ) ]
123  );
124  }
125 }
ParserOptions
Set options of the Parser.
Definition: ParserOptions.php:33
ParserOutput
Definition: ParserOutput.php:24
GadgetDefinitionContent\beautifyJSON
beautifyJSON()
Pretty-print JSON.
Definition: GadgetDefinitionContent.php:41
GadgetDefinitionContent\__construct
__construct( $text)
Definition: GadgetDefinitionContent.php:25
wfArrayPlus2d
wfArrayPlus2d(array $baseArray, array $newValues)
Merges two (possibly) 2 dimensional arrays into the target array ($baseArray).
Definition: GlobalFunctions.php:3682
wfObjectToArray
wfObjectToArray( $objOrArray, $recursive=true)
Recursively converts the parameter (an object) to an array with the same data.
Definition: GlobalFunctions.php:292
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:36
$generateHtml
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 called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state $generateHtml
Definition: hooks.txt:1049
$type
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 my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2536
GadgetDefinitionContent\validate
validate()
Definition: GadgetDefinitionContent.php:74
GadgetDefinitionContent\getDeletionUpdates
getDeletionUpdates(WikiPage $page, ParserOutput $parserOutput=null)
Definition: GadgetDefinitionContent.php:103
FormatJson\UTF8_OK
const UTF8_OK
Skip escaping most characters above U+007F for readability and compactness.
Definition: FormatJson.php:34
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
GadgetDefinitionContent\getSecondaryDataUpdates
getSecondaryDataUpdates(Title $title, Content $old=null, $recursive=true, ParserOutput $parserOutput=null)
Definition: GadgetDefinitionContent.php:117
FormatJson\encode
static encode( $value, $pretty=false, $escaping=0)
Returns the JSON representation of a value.
Definition: FormatJson.php:127
JsonContent
Represents the content of a JSON content.
Definition: JsonContent.php:15
AbstractContent\getContentHandler
getContentHandler()
Definition: AbstractContent.php:86
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
GadgetDefinitionDeletionUpdate
DataUpdate to run whenever a page in the Gadget definition is deleted.
Definition: GadgetDefinitionDeletionUpdate.php:27
GadgetDefinitionContent\getAssocArray
getAssocArray()
Get the JSON content as an associative array with all fields filled out, populating defaults as neces...
Definition: GadgetDefinitionContent.php:89
$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
$output
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 called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object & $output
Definition: hooks.txt:1049
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:538
GadgetDefinitionContent\fillParserOutput
fillParserOutput(Title $title, $revId, ParserOptions $options, $generateHtml, ParserOutput &$output)
Register some links.
Definition: GadgetDefinitionContent.php:55
GadgetDefinitionContent
Definition: GadgetDefinitionContent.php:23
GadgetDefinitionContent\isValid
isValid()
Definition: GadgetDefinitionContent.php:29
GadgetDefinitionValidator
Class responsible for validating Gadget definition contents.
Definition: GadgetDefinitionValidator.php:8
GadgetDefinitionSecondaryDataUpdate
Definition: GadgetDefinitionSecondaryDataUpdate.php:23
$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
JsonContent\getData
getData()
Decodes the JSON string.
Definition: JsonContent.php:49
Content
Base interface for content objects.
Definition: Content.php:34
Title
Represents a title within MediaWiki.
Definition: Title.php:39
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$revId
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 called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context $revId
Definition: hooks.txt:1049
$options
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 called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1049
$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