1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
<?php
/**
* Special:Gadgets, provides a preview of MediaWiki:Gadgets.
*
* @file
* @ingroup SpecialPage
* @author Daniel Kinzler, brightbyte.de
* @copyright © 2007 Daniel Kinzler
* @license GNU General Public License 2.0 or later
*/
class SpecialGadgets extends SpecialPage {
/**
* Constructor
*/
function __construct() {
parent::__construct( 'Gadgets', '', true );
}
/**
* Main execution function
* @param $par Parameters passed to the page
*/
function execute( $par ) {
$parts = explode( '/', $par );
if ( count( $parts ) == 2 && $parts[0] == 'export' ) {
$this->showExportForm( $parts[1] );
} else {
$this->showMainForm();
}
}
/**
* Displays form showing the list of installed gadgets
*/
public function showMainForm() {
global $wgOut, $wgUser, $wgLang, $wgContLang;
$skin = $wgUser->getSkin();
$this->setHeaders();
$wgOut->setPagetitle( wfMsg( "gadgets-title" ) );
$wgOut->addWikiMsg( 'gadgets-pagetext' );
$gadgets = Gadget::loadStructuredList();
if ( !$gadgets ) return;
$lang = "";
if ( $wgLang->getCode() != $wgContLang->getCode() ) {
$lang = "/" . $wgLang->getCode();
}
$listOpen = false;
$msgOpt = array( 'parseinline', 'parsemag' );
$editInterfaceAllowed = $wgUser->isAllowed( 'editinterface' );
foreach ( $gadgets as $section => $entries ) {
if ( $section !== false && $section !== '' ) {
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-section-$section$lang" );
if ( $editInterfaceAllowed ) {
$lnkTarget = $t
? $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) )
: htmlspecialchars( $section );
$lnk = "    [$lnkTarget]";
} else {
$lnk = '';
}
$ttext = wfMsgExt( "gadget-section-$section", $msgOpt );
if ( $listOpen ) {
$wgOut->addHTML( Xml::closeElement( 'ul' ) . "\n" );
$listOpen = false;
}
$wgOut->addHTML( Html::rawElement( 'h2', array(), $ttext . $lnk ) . "\n" );
}
foreach ( $entries as $gadget ) {
$t = Title::makeTitleSafe( NS_MEDIAWIKI, "Gadget-{$gadget->getName()}$lang" );
if ( !$t ) {
continue;
}
$links = array();
if ( $editInterfaceAllowed ) {
$links[] = $skin->link( $t, wfMsgHTML( 'edit' ), array(), array( 'action' => 'edit' ) );
}
$links[] = $skin->link( $this->getTitle( "export/{$gadget->getName()}" ), wfMsgHtml( 'gadgets-export' ) );
$ttext = wfMsgExt( "gadget-{$gadget->getName()}", $msgOpt );
if ( !$listOpen ) {
$listOpen = true;
$wgOut->addHTML( Xml::openElement( 'ul' ) );
}
$lnk = '  ' . wfMsg( 'parentheses', $wgLang->pipeList( $links ) );
$wgOut->addHTML( Xml::openElement( 'li' ) .
$ttext . $lnk . "<br />" .
wfMsgHTML( 'gadgets-uses' ) . wfMsg( 'colon-separator' )
);
$lnk = array();
foreach ( $gadget->getScriptsAndStyles() as $codePage ) {
$t = Title::makeTitleSafe( NS_MEDIAWIKI, $codePage );
if ( !$t ) {
continue;
}
$lnk[] = $skin->link( $t, htmlspecialchars( $t->getText() ) );
}
$wgOut->addHTML( $wgLang->commaList( $lnk ) );
$rights = array();
foreach ( $gadget->getRequiredRights() as $right ) {
$rights[] = '* ' . wfMessage( "right-$right" )->plain();
}
if ( count( $rights ) ) {
$wgOut->addHTML( '<br />' .
wfMessage( 'gadgets-required-rights', implode( "\n", $rights ), count( $rights ) )->parse()
);
}
$skins = array();
$validskins = Skin::getSkinNames();
foreach ( $gadget->getRequiredSkins() as $skinid ) {
if ( isset( $validskins[$skinid] ) ) {
$skins[] = wfMessage( "skinname-$skinid" )->plain();
} else {
$skins[] = $skinid;
}
}
if ( count( $skins ) ) {
$wgOut->addHTML( '<br />' .
wfMessage( 'gadgets-required-skins', $wgLang->commaList( $skins ), count( $skins ) )->parse()
);
}
if ( $gadget->isOnByDefault() ) {
$wgOut->addHTML( '<br />' . wfMessage( 'gadgets-default' )->parse() );
}
$wgOut->addHTML( Xml::closeElement( 'li' ) . "\n" );
}
}
if ( $listOpen ) {
$wgOut->addHTML( Xml::closeElement( 'ul' ) . "\n" );
}
}
/**
* Exports a gadget with its dependencies in a serialized form
* @param $gadget String Name of gadget to export
*/
public function showExportForm( $gadget ) {
global $wgOut, $wgScript;
$gadgets = Gadget::loadList();
if ( !isset( $gadgets[$gadget] ) ) {
$wgOut->showErrorPage( 'error', 'gadgets-not-found', array( $gadget ) );
return;
}
$g = $gadgets[$gadget];
$this->setHeaders();
$wgOut->setPagetitle( wfMsg( "gadgets-export-title" ) );
$wgOut->addWikiMsg( 'gadgets-export-text', $gadget, $g->getDefinition() );
$exportList = "MediaWiki:gadget-$gadget\n";
foreach ( $g->getScriptsAndStyles() as $page ) {
$exportList .= "MediaWiki:$page\n";
}
$wgOut->addHTML( Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) )
. Html::hidden( 'title', SpecialPage::getTitleFor( 'Export' )->getPrefixedDBKey() )
. Html::hidden( 'pages', $exportList )
. Html::hidden( 'wpDownload', '1' )
. Html::hidden( 'templates', '1' )
. Xml::submitButton( wfMsg( 'gadgets-export-download' ) )
. Html::closeElement( 'form' )
);
}
}
|