MediaWiki REL1_31
SpecialGadgets.php
Go to the documentation of this file.
1<?php
13 public function __construct() {
14 parent::__construct( 'Gadgets', '', true );
15 }
16
21 public function execute( $par ) {
22 $parts = explode( '/', $par );
23
24 if ( count( $parts ) == 2 && $parts[0] == 'export' ) {
25 $this->showExportForm( $parts[1] );
26 } else {
27 $this->showMainForm();
28 }
29 }
30
31 private function makeAnchor( $gadgetName ) {
32 return 'gadget-' . Sanitizer::escapeId( $gadgetName, [ 'noninitial' ] );
33 }
34
38 public function showMainForm() {
39 global $wgContLang;
40
41 $output = $this->getOutput();
42 $this->setHeaders();
43 $output->setPageTitle( $this->msg( 'gadgets-title' ) );
44 $output->addWikiMsg( 'gadgets-pagetext' );
45
46 $gadgets = GadgetRepo::singleton()->getStructuredList();
47 if ( !$gadgets ) {
48 return;
49 }
50
51 $output->disallowUserJs();
52 $lang = $this->getLanguage();
53 $langSuffix = "";
54 if ( $lang->getCode() != $wgContLang->getCode() ) {
55 $langSuffix = "/" . $lang->getCode();
56 }
57
58 $listOpen = false;
59
60 $editInterfaceMessage = $this->getUser()->isAllowed( 'editinterface' )
61 ? 'edit'
62 : 'viewsource';
63
65 foreach ( $gadgets as $section => $entries ) {
66 if ( $section !== false && $section !== '' ) {
67 $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-section-$section$langSuffix" );
68 $lnkTarget = $t
69 ? $linkRenderer->makeLink( $t, $this->msg( $editInterfaceMessage )->text(),
70 [], [ 'action' => 'edit' ] )
71 : htmlspecialchars( $section );
72 $lnk = "&#160; &#160; [$lnkTarget]";
73
74 $ttext = $this->msg( "gadget-section-$section" )->parse();
75
76 if ( $listOpen ) {
77 $output->addHTML( Xml::closeElement( 'ul' ) . "\n" );
78 $listOpen = false;
79 }
80
81 $output->addHTML( Html::rawElement( 'h2', [], $ttext . $lnk ) . "\n" );
82 }
83
87 foreach ( $entries as $gadget ) {
88 $name = $gadget->getName();
89 $t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-{$name}$langSuffix" );
90 if ( !$t ) {
91 continue;
92 }
93
94 $links = [];
95 $links[] = $linkRenderer->makeLink(
96 $t,
97 $this->msg( $editInterfaceMessage )->text(),
98 [],
99 [ 'action' => 'edit' ]
100 );
101 $links[] = $linkRenderer->makeLink(
102 $this->getPageTitle( "export/{$name}" ),
103 $this->msg( 'gadgets-export' )->text()
104 );
105
106 $ttext = $this->msg( "gadget-{$name}" )->parse();
107
108 if ( !$listOpen ) {
109 $listOpen = true;
110 $output->addHTML( Xml::openElement( 'ul' ) );
111 }
112
113 $actions = '&#160;&#160;' .
114 $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $links ) )->escaped();
115 $output->addHTML(
116 Xml::openElement( 'li', [ 'id' => $this->makeAnchor( $name ) ] ) .
117 $ttext . $actions . "<br />" .
118 $this->msg( 'gadgets-uses' )->escaped() .
119 $this->msg( 'colon-separator' )->escaped()
120 );
121
122 $lnk = [];
123 foreach ( $gadget->getPeers() as $peer ) {
124 $lnk[] = Html::element(
125 'a',
126 [ 'href' => '#' . $this->makeAnchor( $peer ) ],
127 $peer
128 );
129 }
130 foreach ( $gadget->getScriptsAndStyles() as $codePage ) {
131 $t = Title::newFromText( $codePage );
132
133 if ( !$t ) {
134 continue;
135 }
136
137 $lnk[] = $linkRenderer->makeLink( $t, $t->getText() );
138 }
139 $output->addHTML( $lang->commaList( $lnk ) );
140 if ( $gadget->getLegacyScripts() ) {
141 $output->addHTML( '<br />' . Html::rawElement(
142 'span',
143 [ 'class' => 'mw-gadget-legacy errorbox' ],
144 $this->msg( 'gadgets-legacy' )->parse()
145 ) );
146 }
147
148 $rights = [];
149 foreach ( $gadget->getRequiredRights() as $right ) {
150 $rights[] = '* ' . $this->msg( "right-$right" )->plain();
151 }
152 if ( count( $rights ) ) {
153 $output->addHTML( '<br />' .
154 $this->msg( 'gadgets-required-rights', implode( "\n", $rights ), count( $rights ) )->parse()
155 );
156 }
157
158 $requiredSkins = $gadget->getRequiredSkins();
159 // $requiredSkins can be an array or true (if all skins are supported)
160 if ( is_array( $requiredSkins ) ) {
161 $skins = [];
162 $validskins = Skin::getSkinNames();
163 foreach ( $requiredSkins as $skinid ) {
164 if ( isset( $validskins[$skinid] ) ) {
165 $skins[] = $this->msg( "skinname-$skinid" )->plain();
166 } else {
167 $skins[] = $skinid;
168 }
169 }
170 if ( count( $skins ) ) {
171 $output->addHTML(
172 '<br />' .
173 $this->msg( 'gadgets-required-skins', $lang->commaList( $skins ) )
174 ->numParams( count( $skins ) )->parse()
175 );
176 }
177 }
178
179 if ( $gadget->isOnByDefault() ) {
180 $output->addHTML( '<br />' . $this->msg( 'gadgets-default' )->parse() );
181 }
182
183 $output->addHTML( Xml::closeElement( 'li' ) . "\n" );
184 }
185 }
186
187 if ( $listOpen ) {
188 $output->addHTML( Xml::closeElement( 'ul' ) . "\n" );
189 }
190 }
191
196 public function showExportForm( $gadget ) {
197 global $wgScript;
198
199 $output = $this->getOutput();
200 try {
201 $g = GadgetRepo::singleton()->getGadget( $gadget );
202 } catch ( InvalidArgumentException $e ) {
203 $output->showErrorPage( 'error', 'gadgets-not-found', [ $gadget ] );
204 return;
205 }
206
207 $this->setHeaders();
208 $output->setPageTitle( $this->msg( 'gadgets-export-title' ) );
209 $output->addWikiMsg( 'gadgets-export-text', $gadget, $g->getDefinition() );
210
211 $exportList = "MediaWiki:gadget-$gadget\n";
212 foreach ( $g->getScriptsAndStyles() as $page ) {
213 $exportList .= "$page\n";
214 }
215
216 $htmlForm = HTMLForm::factory( 'ooui', [], $this->getContext() );
217 $htmlForm
218 ->addHiddenField( 'title', SpecialPage::getTitleFor( 'Export' )->getPrefixedDBKey() )
219 ->addHiddenField( 'pages', $exportList )
220 ->addHiddenField( 'wpDownload', '1' )
221 ->addHiddenField( 'templates', '1' )
222 ->setAction( $wgScript )
223 ->setMethod( 'get' )
224 ->setSubmitText( $this->msg( 'gadgets-export-download' )->text() )
225 ->prepareForm()
226 ->displayForm( false );
227 }
228
229 protected function getGroupName() {
230 return 'wiki';
231 }
232}
$wgScript
The URL path to index.php.
static singleton()
Get the configured default GadgetRepo.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
makeAnchor( $gadgetName)
execute( $par)
Main execution function.
showExportForm( $gadget)
Exports a gadget with its dependencies in a serialized form.
showMainForm()
Displays form showing the list of installed gadgets.
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getContext()
Gets the context this SpecialPage is executed in.
msg( $key)
Wrapper around wfMessage that sets the current context.
getPageTitle( $subpage=false)
Get a self-referential title object.
getLanguage()
Shortcut to get user's language.
MediaWiki Linker LinkRenderer null $linkRenderer
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition design.txt:57
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition design.txt:18
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2255
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
Definition hooks.txt:3022
returning false will NOT prevent logging $e
Definition hooks.txt:2176
if(!isset( $args[0])) $lang