MediaWiki  1.32.5
SpecialGadgets.php
Go to the documentation of this file.
1 <?php
13 
14 class SpecialGadgets extends SpecialPage {
15  public function __construct() {
16  parent::__construct( 'Gadgets', '', true );
17  }
18 
23  public function execute( $par ) {
24  $parts = explode( '/', $par );
25 
26  if ( count( $parts ) == 2 && $parts[0] == 'export' ) {
27  $this->showExportForm( $parts[1] );
28  } else {
29  $this->showMainForm();
30  }
31  }
32 
33  private function makeAnchor( $gadgetName ) {
34  return 'gadget-' . Sanitizer::escapeId( $gadgetName, [ 'noninitial' ] );
35  }
36 
40  public function showMainForm() {
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->equals( MediaWikiServices::getInstance()->getContentLanguage() ) ) {
55  $langSuffix = "/" . $lang->getCode();
56  }
57 
58  $listOpen = false;
59 
60  $editInterfaceMessage = $this->getUser()->isAllowed( 'editinterface' )
61  ? 'edit'
62  : 'viewsource';
63 
64  $linkRenderer = $this->getLinkRenderer();
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  $nameHtml = $this->msg( "gadget-{$name}" )->parse();
107 
108  if ( !$listOpen ) {
109  $listOpen = true;
110  $output->addHTML( Html::openElement( 'ul' ) );
111  }
112 
113  $actionsHtml = '&#160;&#160;' .
114  $this->msg( 'parentheses' )->rawParams( $lang->pipeList( $links ) )->escaped();
115  $output->addHTML(
116  Html::openElement( 'li', [ 'id' => $this->makeAnchor( $name ) ] ) .
117  $nameHtml . $actionsHtml
118  );
119  // Whether the next portion of the list item contents needs
120  // a line break between it and the next portion.
121  // This is set to false after lists, but true after lines of text.
122  $needLineBreakAfter = true;
123 
124  // Portion: Show files, dependencies, speers
125  if ( $needLineBreakAfter ) {
126  $output->addHTML( '<br />' );
127  }
128  $output->addHTML(
129  $this->msg( 'gadgets-uses' )->escaped() .
130  $this->msg( 'colon-separator' )->escaped()
131  );
132  $lnk = [];
133  foreach ( $gadget->getPeers() as $peer ) {
134  $lnk[] = Html::element(
135  'a',
136  [ 'href' => '#' . $this->makeAnchor( $peer ) ],
137  $peer
138  );
139  }
140  foreach ( $gadget->getScriptsAndStyles() as $codePage ) {
141  $t = Title::newFromText( $codePage );
142  if ( !$t ) {
143  continue;
144  }
145  $lnk[] = $linkRenderer->makeLink( $t, $t->getText() );
146  }
147  $output->addHTML( $lang->commaList( $lnk ) );
148 
149  // Portion: Legacy scripts
150  if ( $gadget->getLegacyScripts() ) {
151  if ( $needLineBreakAfter ) {
152  $output->addHTML( '<br />' );
153  }
154  $output->addHTML( Html::rawElement(
155  'span',
156  [ 'class' => 'mw-gadget-legacy errorbox' ],
157  $this->msg( 'gadgets-legacy' )->parse()
158  ) );
159  $needLineBreakAfter = true;
160  }
161 
162  // Portion: Show required rights (optional)
163  $rights = [];
164  foreach ( $gadget->getRequiredRights() as $right ) {
165  $rights[] = '* ' . Html::element(
166  'code',
167  [ 'title' => $this->msg( "right-$right" )->plain() ],
168  $right
169  );
170  }
171  if ( $rights ) {
172  if ( $needLineBreakAfter ) {
173  $output->addHTML( '<br />' );
174  }
175  $output->addHTML(
176  $this->msg( 'gadgets-required-rights', implode( "\n", $rights ), count( $rights ) )->parse()
177  );
178  $needLineBreakAfter = false;
179  }
180 
181  // Portion: Show required skins (optional)
182  $requiredSkins = $gadget->getRequiredSkins();
183  // $requiredSkins can be an array, or true (if all skins are supported)
184  if ( is_array( $requiredSkins ) ) {
185  $skins = [];
186  $validskins = Skin::getSkinNames();
187  foreach ( $requiredSkins as $skinid ) {
188  if ( isset( $validskins[$skinid] ) ) {
189  $skins[] = $this->msg( "skinname-$skinid" )->plain();
190  } else {
191  $skins[] = $skinid;
192  }
193  }
194  if ( $skins ) {
195  if ( $needLineBreakAfter ) {
196  $output->addHTML( '<br />' );
197  }
198  $output->addHTML(
199  $this->msg( 'gadgets-required-skins', $lang->commaList( $skins ) )
200  ->numParams( count( $skins ) )->parse()
201  );
202  $needLineBreakAfter = true;
203  }
204  }
205 
206  // Portion: Show on by default (optional)
207  if ( $gadget->isOnByDefault() ) {
208  if ( $needLineBreakAfter ) {
209  $output->addHTML( '<br />' );
210  }
211  $output->addHTML( $this->msg( 'gadgets-default' )->parse() );
212  $needLineBreakAfter = true;
213  }
214 
215  $output->addHTML( Html::closeElement( 'li' ) . "\n" );
216  }
217  }
218 
219  if ( $listOpen ) {
220  $output->addHTML( Html::closeElement( 'ul' ) . "\n" );
221  }
222  }
223 
228  public function showExportForm( $gadget ) {
229  global $wgScript;
230 
231  $output = $this->getOutput();
232  try {
233  $g = GadgetRepo::singleton()->getGadget( $gadget );
234  } catch ( InvalidArgumentException $e ) {
235  $output->showErrorPage( 'error', 'gadgets-not-found', [ $gadget ] );
236  return;
237  }
238 
239  $this->setHeaders();
240  $output->setPageTitle( $this->msg( 'gadgets-export-title' ) );
241  $output->addWikiMsg( 'gadgets-export-text', $gadget, $g->getDefinition() );
242 
243  $exportList = "MediaWiki:gadget-$gadget\n";
244  foreach ( $g->getScriptsAndStyles() as $page ) {
245  $exportList .= "$page\n";
246  }
247 
248  $htmlForm = HTMLForm::factory( 'ooui', [], $this->getContext() );
249  $htmlForm
250  ->addHiddenField( 'title', SpecialPage::getTitleFor( 'Export' )->getPrefixedDBKey() )
251  ->addHiddenField( 'pages', $exportList )
252  ->addHiddenField( 'wpDownload', '1' )
253  ->addHiddenField( 'templates', '1' )
254  ->setAction( $wgScript )
255  ->setMethod( 'get' )
256  ->setSubmitText( $this->msg( 'gadgets-export-download' )->text() )
257  ->prepareForm()
258  ->displayForm( false );
259  }
260 
261  protected function getGroupName() {
262  return 'wiki';
263  }
264 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:678
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:280
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:796
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:725
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
captcha-old.count
count
Definition: captcha-old.py:249
$wgScript
$wgScript
The URL path to index.php.
Definition: DefaultSettings.php:185
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:82
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:755
SpecialGadgets\showExportForm
showExportForm( $gadget)
Exports a gadget with its dependencies in a serialized form.
Definition: SpecialGadgets.php:228
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
Skin\getSkinNames
static getSkinNames()
Fetch the set of available skins.
Definition: Skin.php:57
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:310
HTMLForm\factory
static factory( $displayFormat)
Construct a HTMLForm object for given display type.
Definition: HTMLForm.php:286
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
SpecialGadgets\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialGadgets.php:261
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:531
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:735
$output
$output
Definition: SyntaxHighlight.php:334
GadgetRepo\singleton
static singleton()
Get the configured default GadgetRepo.
Definition: GadgetRepo.php:88
SpecialGadgets\showMainForm
showMainForm()
Displays form showing the list of installed gadgets.
Definition: SpecialGadgets.php:40
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:698
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:573
SpecialGadgets\makeAnchor
makeAnchor( $gadgetName)
Definition: SpecialGadgets.php:33
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2221
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:36
plain
either a plain
Definition: hooks.txt:2105
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:908
text
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
Definition: All_system_messages.txt:1267
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:119
SpecialGadgets\__construct
__construct()
Definition: SpecialGadgets.php:15
$section
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:3098
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
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:252
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:72
$t
$t
Definition: testCompression.php:69
SpecialPage\$linkRenderer
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:66
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
MediaWikiServices
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
SpecialGadgets
Definition: SpecialGadgets.php:14
SpecialGadgets\execute
execute( $par)
Main execution function.
Definition: SpecialGadgets.php:23