24use Wikimedia\WrappedString;
52 foreach ( $gadgets as $thisSection ) {
53 foreach ( $thisSection as $gadgetId => $gadget ) {
54 if ( $gadget->isOnByDefault() ) {
55 $defaultOptions[
'gadget-' . $gadgetId] = 1;
74 $skin = RequestContext::getMain()->getSkin();
75 foreach ( $gadgets as $section => $thisSection ) {
81 foreach ( $thisSection as $gadget ) {
84 && $gadget->isAllowed( $user )
85 && $gadget->isSkinSupported( $skin )
87 $gname = $gadget->getName();
88 # bug 30182: dir="auto" because it's often not translated
89 $desc =
'<span dir="auto">' . $gadget->getDescription() .
'</span>';
90 $available[$desc] = $gname;
91 if ( $gadget->isEnabled( $user ) ) {
97 if ( $section !==
'' ) {
98 $section =
wfMessage(
"gadget-section-$section" )->parse();
100 if ( count( $available ) ) {
101 $options[$section] = $available;
104 $options = array_merge( $options, $available );
108 $preferences[
'gadgets-intro'] =
111 'default' =>
wfMessage(
'gadgets-prefstext' )->parseAsBlock(),
112 'section' =>
'gadgets',
116 $preferences[
'gadgets'] =
118 'type' =>
'multiselect',
119 'options' => $options,
120 'section' =>
'gadgets',
122 'prefix' =>
'gadget-',
123 'default' => $default,
134 $ids = $repo->getGadgetIds();
136 foreach ( $ids as $id ) {
138 'class' =>
'GadgetResourceLoaderModule',
150 $ids = $repo->getGadgetIds();
156 $lb->setCaller( __METHOD__ );
157 $enabledLegacyGadgets = [];
164 foreach ( $ids as $id ) {
166 $gadget = $repo->getGadget( $id );
167 }
catch ( InvalidArgumentException $e ) {
171 foreach ( $gadget->getPeers() as $peerName ) {
173 $peers[] = $repo->getGadget( $peerName );
174 }
catch ( InvalidArgumentException $e ) {
179 if ( $gadget->isEnabled( $user )
180 && $gadget->isAllowed( $user )
181 && $gadget->isSkinSupported( $skin )
183 if ( $gadget->hasModule() ) {
184 if ( $gadget->getType() ===
'styles' ) {
189 foreach ( $peers as $peer ) {
190 if ( $peer->getType() ===
'styles' ) {
200 if ( $gadget->getLegacyScripts() ) {
201 $enabledLegacyGadgets[] = $id;
207 foreach ( $enabledLegacyGadgets as $id ) {
210 $out->
addHTML( WrappedString::join(
"\n", $strings ) );
214 $special = SpecialPage::getTitleFor(
'Gadgets' );
216 return ResourceLoader::makeInlineScript(
217 Xml::encodeJsCall(
'mw.log.warn', [
218 "Gadget \"$id\" was not loaded. Please migrate it to use ResourceLoader. " .
219 'See <' . $special->getCanonicalURL() .
'>.'
241 if ( !
$title->inNamespace( NS_GADGET_DEFINITION ) ) {
248 "Tried to save non-GadgetDefinitionContent to {$title->getPrefixedText()}"
252 $validateStatus =
$content->validate();
253 if ( !$validateStatus->isGood() ) {
254 $status->
merge( $validateStatus );
268 if ( $page->
getTitle()->inNamespace( NS_GADGET_DEFINITION ) ) {
282 if (
$title->inNamespace( NS_GADGET ) ) {
283 preg_match(
'!\.(css|js)$!u',
$title->getText(),
$ext );
287 $model =
'javascript';
307 if (
$title->hasContentModel(
'GadgetDefinition' ) ) {
320 $queryPages[] = [
'SpecialGadgetUsage',
'GadgetUsage' ];
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
static getPreferences(User $user, array &$preferences)
GetPreferences hook handler.
static onDeleteUnknownPreferences(array &$where, IDatabase $db)
Prevent gadget preferences from being deleted.
static onwgQueryPages(array &$queryPages)
Add the GadgetUsage special page to the list of QueryPages.
static registerModules(ResourceLoader &$resourceLoader)
ResourceLoaderRegisterModules hook handler.
static onCodeEditorGetPageLanguage(Title $title, &$lang)
Set the CodeEditor language for Gadget definition pages.
static beforePageDisplay(OutputPage $out)
BeforePageDisplay hook handler.
static onPageContentInsertComplete(WikiPage $page)
After a new page is created in the Gadget definition namespace, invalidate the list of gadget ids.
static makeLegacyWarning( $id)
static onPageContentSaveComplete(WikiPage $wikiPage, $user, $content)
PageContentSaveComplete hook handler.
static onEditFilterMergedContent(IContextSource $context, Content $content, Status $status, $summary)
Valid gadget definition page after content is modified.
static userGetDefaultOptions(array &$defaultOptions)
UserGetDefaultOptions hook handler.
static onContentHandlerDefaultModelFor(Title $title, &$model)
Mark the Title as having a content model of javascript or css for pages in the Gadget namespace based...
static singleton()
Get the configured default GadgetRepo.
static getModuleName( $id)
Class representing a list of titles The execute() method checks them all for existence and adds them ...
This is one of the Core classes and should be read at least once by any new developers.
addModuleStyles( $modules)
Load the styles of one or more ResourceLoader modules on this page.
addHTML( $text)
Append $text to the body HTML.
addModules( $modules)
Load one or more ResourceLoader modules on this page.
ResourceLoader is a loading system for JavaScript and CSS resources.
merge( $other, $overwriteValue=false)
Merge another status object into this one.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Class representing a MediaWiki article and history.
getTitle()
Get the title object of the article.
Base interface for content objects.
Interface for objects which can provide a MediaWiki context on request.
if(!is_readable( $file)) $ext
if(!isset( $args[0])) $lang