MediaWiki  1.28.0
WebInstallerOptions.php
Go to the documentation of this file.
1 <?php
23 
27  public function execute() {
28  if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
29  $this->submitSkins();
30  return 'skip';
31  }
32  if ( $this->parent->request->wasPosted() ) {
33  if ( $this->submit() ) {
34  return 'continue';
35  }
36  }
37 
38  $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ? '' : 'display: none';
39  $this->startForm();
40  $this->addHTML(
41  # User Rights
42  // getRadioSet() builds a set of labeled radio buttons.
43  // For grep: The following messages are used as the item labels:
44  // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
45  $this->parent->getRadioSet( [
46  'var' => '_RightsProfile',
47  'label' => 'config-profile',
48  'itemLabelPrefix' => 'config-profile-',
49  'values' => array_keys( $this->parent->rightsProfiles ),
50  ] ) .
51  $this->parent->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
52 
53  # Licensing
54  // getRadioSet() builds a set of labeled radio buttons.
55  // For grep: The following messages are used as the item labels:
56  // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
57  // config-license-cc-0, config-license-pd, config-license-gfdl,
58  // config-license-none, config-license-cc-choose
59  $this->parent->getRadioSet( [
60  'var' => '_LicenseCode',
61  'label' => 'config-license',
62  'itemLabelPrefix' => 'config-license-',
63  'values' => array_keys( $this->parent->licenses ),
64  'commonAttribs' => [ 'class' => 'licenseRadio' ],
65  ] ) .
66  $this->getCCChooser() .
67  $this->parent->getHelpBox( 'config-license-help' ) .
68 
69  # E-mail
70  $this->getFieldsetStart( 'config-email-settings' ) .
71  $this->parent->getCheckBox( [
72  'var' => 'wgEnableEmail',
73  'label' => 'config-enable-email',
74  'attribs' => [ 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ],
75  ] ) .
76  $this->parent->getHelpBox( 'config-enable-email-help' ) .
77  "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
78  $this->parent->getTextBox( [
79  'var' => 'wgPasswordSender',
80  'label' => 'config-email-sender'
81  ] ) .
82  $this->parent->getHelpBox( 'config-email-sender-help' ) .
83  $this->parent->getCheckBox( [
84  'var' => 'wgEnableUserEmail',
85  'label' => 'config-email-user',
86  ] ) .
87  $this->parent->getHelpBox( 'config-email-user-help' ) .
88  $this->parent->getCheckBox( [
89  'var' => 'wgEnotifUserTalk',
90  'label' => 'config-email-usertalk',
91  ] ) .
92  $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
93  $this->parent->getCheckBox( [
94  'var' => 'wgEnotifWatchlist',
95  'label' => 'config-email-watchlist',
96  ] ) .
97  $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
98  $this->parent->getCheckBox( [
99  'var' => 'wgEmailAuthentication',
100  'label' => 'config-email-auth',
101  ] ) .
102  $this->parent->getHelpBox( 'config-email-auth-help' ) .
103  "</div>" .
104  $this->getFieldsetEnd()
105  );
106 
107  $skins = $this->parent->findExtensions( 'skins' );
108  $skinHtml = $this->getFieldsetStart( 'config-skins' );
109 
110  $skinNames = array_map( 'strtolower', $skins );
111  $chosenSkinName = $this->getVar( 'wgDefaultSkin', $this->parent->getDefaultSkin( $skinNames ) );
112 
113  if ( $skins ) {
114  $radioButtons = $this->parent->getRadioElements( [
115  'var' => 'wgDefaultSkin',
116  'itemLabels' => array_fill_keys( $skinNames, 'config-skins-use-as-default' ),
117  'values' => $skinNames,
118  'value' => $chosenSkinName,
119  ] );
120 
121  foreach ( $skins as $skin ) {
122  $skinHtml .=
123  '<div class="config-skins-item">' .
124  $this->parent->getCheckBox( [
125  'var' => "skin-$skin",
126  'rawtext' => $skin,
127  'value' => $this->getVar( "skin-$skin", true ), // all found skins enabled by default
128  ] ) .
129  '<div class="config-skins-use-as-default">' . $radioButtons[strtolower( $skin )] . '</div>' .
130  '</div>';
131  }
132  } else {
133  $skinHtml .=
134  $this->parent->getWarningBox( wfMessage( 'config-skins-missing' )->plain() ) .
135  Html::hidden( 'config_wgDefaultSkin', $chosenSkinName );
136  }
137 
138  $skinHtml .= $this->parent->getHelpBox( 'config-skins-help' ) .
139  $this->getFieldsetEnd();
140  $this->addHTML( $skinHtml );
141 
142  $extensions = $this->parent->findExtensions();
143 
144  if ( $extensions ) {
145  $extHtml = $this->getFieldsetStart( 'config-extensions' );
146 
147  foreach ( $extensions as $ext ) {
148  $extHtml .= $this->parent->getCheckBox( [
149  'var' => "ext-$ext",
150  'rawtext' => $ext,
151  ] );
152  }
153 
154  $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
155  $this->getFieldsetEnd();
156  $this->addHTML( $extHtml );
157  }
158 
159  // Having / in paths in Windows looks funny :)
160  $this->setVar( 'wgDeletedDirectory',
161  str_replace(
162  '/', DIRECTORY_SEPARATOR,
163  $this->getVar( 'wgDeletedDirectory' )
164  )
165  );
166 
167  $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ? '' : 'display: none';
168  $this->addHTML(
169  # Uploading
170  $this->getFieldsetStart( 'config-upload-settings' ) .
171  $this->parent->getCheckBox( [
172  'var' => 'wgEnableUploads',
173  'label' => 'config-upload-enable',
174  'attribs' => [ 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ],
175  'help' => $this->parent->getHelpBox( 'config-upload-help' )
176  ] ) .
177  '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
178  $this->parent->getTextBox( [
179  'var' => 'wgDeletedDirectory',
180  'label' => 'config-upload-deleted',
181  'attribs' => [ 'dir' => 'ltr' ],
182  'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
183  ] ) .
184  '</div>' .
185  $this->parent->getTextBox( [
186  'var' => 'wgLogo',
187  'label' => 'config-logo',
188  'attribs' => [ 'dir' => 'ltr' ],
189  'help' => $this->parent->getHelpBox( 'config-logo-help' )
190  ] )
191  );
192  $this->addHTML(
193  $this->parent->getCheckBox( [
194  'var' => 'wgUseInstantCommons',
195  'label' => 'config-instantcommons',
196  'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
197  ] ) .
198  $this->getFieldsetEnd()
199  );
200 
201  $caches = [ 'none' ];
202  $cachevalDefault = 'none';
203 
204  if ( count( $this->getVar( '_Caches' ) ) ) {
205  // A CACHE_ACCEL implementation is available
206  $caches[] = 'accel';
207  $cachevalDefault = 'accel';
208  }
209  $caches[] = 'memcached';
210 
211  // We'll hide/show this on demand when the value changes, see config.js.
212  $cacheval = $this->getVar( '_MainCacheType' );
213  if ( !$cacheval ) {
214  // We need to set a default here; but don't hardcode it
215  // or we lose it every time we reload the page for validation
216  // or going back!
217  $cacheval = $cachevalDefault;
218  }
219  $hidden = ( $cacheval == 'memcached' ) ? '' : 'display: none';
220  $this->addHTML(
221  # Advanced settings
222  $this->getFieldsetStart( 'config-advanced-settings' ) .
223  # Object cache settings
224  // getRadioSet() builds a set of labeled radio buttons.
225  // For grep: The following messages are used as the item labels:
226  // config-cache-none, config-cache-accel, config-cache-memcached
227  $this->parent->getRadioSet( [
228  'var' => '_MainCacheType',
229  'label' => 'config-cache-options',
230  'itemLabelPrefix' => 'config-cache-',
231  'values' => $caches,
232  'value' => $cacheval,
233  ] ) .
234  $this->parent->getHelpBox( 'config-cache-help' ) .
235  "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
236  $this->parent->getTextArea( [
237  'var' => '_MemCachedServers',
238  'label' => 'config-memcached-servers',
239  'help' => $this->parent->getHelpBox( 'config-memcached-help' )
240  ] ) .
241  '</div>' .
242  $this->getFieldsetEnd()
243  );
244  $this->endForm();
245 
246  return null;
247  }
248 
252  public function getCCPartnerUrl() {
253  $server = $this->getVar( 'wgServer' );
254  $exitUrl = $server . $this->parent->getUrl( [
255  'page' => 'Options',
256  'SubmitCC' => 'indeed',
257  'config__LicenseCode' => 'cc',
258  'config_wgRightsUrl' => '[license_url]',
259  'config_wgRightsText' => '[license_name]',
260  'config_wgRightsIcon' => '[license_button]',
261  ] );
262  $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
263  '/mw-config/config-cc.css';
264  $iframeUrl = '//creativecommons.org/license/?' .
265  wfArrayToCgi( [
266  'partner' => 'MediaWiki',
267  'exit_url' => $exitUrl,
268  'lang' => $this->getVar( '_UserLang' ),
269  'stylesheet' => $styleUrl,
270  ] );
271 
272  return $iframeUrl;
273  }
274 
278  public function getCCChooser() {
279  $iframeAttribs = [
280  'class' => 'config-cc-iframe',
281  'name' => 'config-cc-iframe',
282  'id' => 'config-cc-iframe',
283  'frameborder' => 0,
284  'width' => '100%',
285  'height' => '100%',
286  ];
287  if ( $this->getVar( '_CCDone' ) ) {
288  $iframeAttribs['src'] = $this->parent->getUrl( [ 'ShowCC' => 'yes' ] );
289  } else {
290  $iframeAttribs['src'] = $this->getCCPartnerUrl();
291  }
292  $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ? '' : 'display: none';
293 
294  return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
295  Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
296  "</div>\n";
297  }
298 
302  public function getCCDoneBox() {
303  $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
304  // If you change this height, also change it in config.css
305  $expandJs = str_replace( '$1', '54em', $js );
306  $reduceJs = str_replace( '$1', '70px', $js );
307 
308  return '<p>' .
309  Html::element( 'img', [ 'src' => $this->getVar( 'wgRightsIcon' ) ] ) .
310  '&#160;&#160;' .
311  htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
312  "</p>\n" .
313  "<p style=\"text-align: center;\">" .
314  Html::element( 'a',
315  [
316  'href' => $this->getCCPartnerUrl(),
317  'onclick' => $expandJs,
318  ],
319  wfMessage( 'config-cc-again' )->text()
320  ) .
321  "</p>\n" .
322  "<script>\n" .
323  # Reduce the wrapper div height
324  htmlspecialchars( $reduceJs ) .
325  "\n" .
326  "</script>\n";
327  }
328 
329  public function submitCC() {
330  $newValues = $this->parent->setVarsFromRequest(
331  [ 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ] );
332  if ( count( $newValues ) != 3 ) {
333  $this->parent->showError( 'config-cc-error' );
334 
335  return;
336  }
337  $this->setVar( '_CCDone', true );
338  $this->addHTML( $this->getCCDoneBox() );
339  }
340 
347  public function submitSkins() {
348  $skins = $this->parent->findExtensions( 'skins' );
349  $this->parent->setVar( '_Skins', $skins );
350 
351  if ( $skins ) {
352  $skinNames = array_map( 'strtolower', $skins );
353  $this->parent->setVar( 'wgDefaultSkin', $this->parent->getDefaultSkin( $skinNames ) );
354  }
355 
356  return true;
357  }
358 
362  public function submit() {
363  $this->parent->setVarsFromRequest( [ '_RightsProfile', '_LicenseCode',
364  'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
365  'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
366  'wgEmailAuthentication', '_MainCacheType', '_MemCachedServers',
367  'wgUseInstantCommons', 'wgDefaultSkin' ] );
368 
369  $retVal = true;
370 
371  if ( !array_key_exists( $this->getVar( '_RightsProfile' ), $this->parent->rightsProfiles ) ) {
372  reset( $this->parent->rightsProfiles );
373  $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
374  }
375 
376  $code = $this->getVar( '_LicenseCode' );
377  if ( $code == 'cc-choose' ) {
378  if ( !$this->getVar( '_CCDone' ) ) {
379  $this->parent->showError( 'config-cc-not-chosen' );
380  $retVal = false;
381  }
382  } elseif ( array_key_exists( $code, $this->parent->licenses ) ) {
383  // Messages:
384  // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
385  // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
386  // config-license-cc-choose
387  $entry = $this->parent->licenses[$code];
388  if ( isset( $entry['text'] ) ) {
389  $this->setVar( 'wgRightsText', $entry['text'] );
390  } else {
391  $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
392  }
393  $this->setVar( 'wgRightsUrl', $entry['url'] );
394  $this->setVar( 'wgRightsIcon', $entry['icon'] );
395  } else {
396  $this->setVar( 'wgRightsText', '' );
397  $this->setVar( 'wgRightsUrl', '' );
398  $this->setVar( 'wgRightsIcon', '' );
399  }
400 
401  $skinsAvailable = $this->parent->findExtensions( 'skins' );
402  $skinsToInstall = [];
403  foreach ( $skinsAvailable as $skin ) {
404  $this->parent->setVarsFromRequest( [ "skin-$skin" ] );
405  if ( $this->getVar( "skin-$skin" ) ) {
406  $skinsToInstall[] = $skin;
407  }
408  }
409  $this->parent->setVar( '_Skins', $skinsToInstall );
410 
411  if ( !$skinsToInstall && $skinsAvailable ) {
412  $this->parent->showError( 'config-skins-must-enable-some' );
413  $retVal = false;
414  }
415  $defaultSkin = $this->getVar( 'wgDefaultSkin' );
416  $skinsToInstallLowercase = array_map( 'strtolower', $skinsToInstall );
417  if ( $skinsToInstall && array_search( $defaultSkin, $skinsToInstallLowercase ) === false ) {
418  $this->parent->showError( 'config-skins-must-enable-default' );
419  $retVal = false;
420  }
421 
422  $extsAvailable = $this->parent->findExtensions();
423  $extsToInstall = [];
424  foreach ( $extsAvailable as $ext ) {
425  $this->parent->setVarsFromRequest( [ "ext-$ext" ] );
426  if ( $this->getVar( "ext-$ext" ) ) {
427  $extsToInstall[] = $ext;
428  }
429  }
430  $this->parent->setVar( '_Extensions', $extsToInstall );
431 
432  if ( $this->getVar( '_MainCacheType' ) == 'memcached' ) {
433  $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
434  if ( !$memcServers ) {
435  $this->parent->showError( 'config-memcache-needservers' );
436  $retVal = false;
437  }
438 
439  foreach ( $memcServers as $server ) {
440  $memcParts = explode( ":", $server, 2 );
441  if ( !isset( $memcParts[0] )
442  || ( !IP::isValid( $memcParts[0] )
443  && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) )
444  ) {
445  $this->parent->showError( 'config-memcache-badip', $memcParts[0] );
446  $retVal = false;
447  } elseif ( !isset( $memcParts[1] ) ) {
448  $this->parent->showError( 'config-memcache-noport', $memcParts[0] );
449  $retVal = false;
450  } elseif ( $memcParts[1] < 1 || $memcParts[1] > 65535 ) {
451  $this->parent->showError( 'config-memcache-badport', 1, 65535 );
452  $retVal = false;
453  }
454  }
455  }
456 
457  return $retVal;
458  }
459 
460 }
#define the
table suitable for use with IDatabase::select()
Abstract class to define pages for the web installer.
setVar($name, $value)
either a plain
Definition: hooks.txt:1987
address of the mail
static hidden($name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:758
submitSkins()
If the user skips this installer page, we still need to set up the default skins, but ignore everythi...
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
getFieldsetStart($legend)
Get the starting tags of a fieldset.
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 in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
Definition: design.txt:25
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"&lt
static isValid($ip)
Validate an IP address.
Definition: IP.php:113
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
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned $skin
Definition: hooks.txt:1936
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration settings
Definition: globals.txt:25
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
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition: hooks.txt:802
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
wfArrayToCgi($array1, $array2=null, $prefix= '')
This function takes one or two arrays as input, and returns a CGI-style string, e.g.
getVar($var, $default=null)
$extensions
getFieldsetEnd()
Get the end tag of a fieldset.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:229
endForm($continue= 'continue', $back= 'back')