MediaWiki  1.29.2
SpecialGadgets.php
Go to the documentation of this file.
1 <?php
12 class SpecialGadgets extends SpecialPage {
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() {
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 
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  $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 ) {
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  $output->addHTML( Html::openElement( 'form', [ 'method' => 'get', 'action' => $wgScript ] )
217  . Html::hidden( 'title', SpecialPage::getTitleFor( 'Export' )->getPrefixedDBKey() )
218  . Html::hidden( 'pages', $exportList )
219  . Html::hidden( 'wpDownload', '1' )
220  . Html::hidden( 'templates', '1' )
221  . Xml::submitButton( $this->msg( 'gadgets-export-download' )->text() )
222  . Html::closeElement( 'form' )
223  );
224  }
225 
226  protected function getGroupName() {
227  return 'wiki';
228  }
229 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:628
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:265
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:675
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
captcha-old.count
count
Definition: captcha-old.py:225
text
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:12
$wgScript
$wgScript
The URL path to index.php.
Definition: DefaultSettings.php:202
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
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:705
SpecialGadgets\showExportForm
showExportForm( $gadget)
Exports a gadget with its dependencies in a serialized form.
Definition: SpecialGadgets.php:196
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
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:49
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:309
$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
SpecialGadgets\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialGadgets.php:226
$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
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:484
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:685
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
GadgetRepo\singleton
static singleton()
Get the configured default GadgetRepo.
Definition: GadgetRepo.php:53
SpecialGadgets\showMainForm
showMainForm()
Displays form showing the list of installed gadgets.
Definition: SpecialGadgets.php:38
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:746
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:538
SpecialGadgets\makeAnchor
makeAnchor( $gadgetName)
Definition: SpecialGadgets.php:31
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2122
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:746
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:36
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:856
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:118
SpecialGadgets\__construct
__construct()
Definition: SpecialGadgets.php:13
$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:2929
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:251
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:70
$t
$t
Definition: testCompression.php:67
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:231
SpecialGadgets
Definition: SpecialGadgets.php:12
SpecialGadgets\execute
execute( $par)
Main execution function.
Definition: SpecialGadgets.php:21
Xml\submitButton
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:459
$wgContLang
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 content language as $wgContLang
Definition: design.txt:56