PageRenderTime 63ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/installer/WebInstallerOptions.php

https://gitlab.com/link233/bootmw
PHP | 460 lines | 349 code | 42 blank | 69 comment | 37 complexity | a8b05eb18f269e8b7236d2360c77fdd3 MD5 | raw file
  1. <?php
  2. /**
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * http://www.gnu.org/copyleft/gpl.html
  17. *
  18. * @file
  19. * @ingroup Deployment
  20. */
  21. class WebInstallerOptions extends WebInstallerPage {
  22. /**
  23. * @return string|null
  24. */
  25. public function execute() {
  26. if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
  27. $this->submitSkins();
  28. return 'skip';
  29. }
  30. if ( $this->parent->request->wasPosted() ) {
  31. if ( $this->submit() ) {
  32. return 'continue';
  33. }
  34. }
  35. $emailwrapperStyle = $this->getVar( 'wgEnableEmail' ) ? '' : 'display: none';
  36. $this->startForm();
  37. $this->addHTML(
  38. # User Rights
  39. // getRadioSet() builds a set of labeled radio buttons.
  40. // For grep: The following messages are used as the item labels:
  41. // config-profile-wiki, config-profile-no-anon, config-profile-fishbowl, config-profile-private
  42. $this->parent->getRadioSet( [
  43. 'var' => '_RightsProfile',
  44. 'label' => 'config-profile',
  45. 'itemLabelPrefix' => 'config-profile-',
  46. 'values' => array_keys( $this->parent->rightsProfiles ),
  47. ] ) .
  48. $this->parent->getInfoBox( wfMessage( 'config-profile-help' )->plain() ) .
  49. # Licensing
  50. // getRadioSet() builds a set of labeled radio buttons.
  51. // For grep: The following messages are used as the item labels:
  52. // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
  53. // config-license-cc-0, config-license-pd, config-license-gfdl,
  54. // config-license-none, config-license-cc-choose
  55. $this->parent->getRadioSet( [
  56. 'var' => '_LicenseCode',
  57. 'label' => 'config-license',
  58. 'itemLabelPrefix' => 'config-license-',
  59. 'values' => array_keys( $this->parent->licenses ),
  60. 'commonAttribs' => [ 'class' => 'licenseRadio' ],
  61. ] ) .
  62. $this->getCCChooser() .
  63. $this->parent->getHelpBox( 'config-license-help' ) .
  64. # E-mail
  65. $this->getFieldsetStart( 'config-email-settings' ) .
  66. $this->parent->getCheckBox( [
  67. 'var' => 'wgEnableEmail',
  68. 'label' => 'config-enable-email',
  69. 'attribs' => [ 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ],
  70. ] ) .
  71. $this->parent->getHelpBox( 'config-enable-email-help' ) .
  72. "<div id=\"emailwrapper\" style=\"$emailwrapperStyle\">" .
  73. $this->parent->getTextBox( [
  74. 'var' => 'wgPasswordSender',
  75. 'label' => 'config-email-sender'
  76. ] ) .
  77. $this->parent->getHelpBox( 'config-email-sender-help' ) .
  78. $this->parent->getCheckBox( [
  79. 'var' => 'wgEnableUserEmail',
  80. 'label' => 'config-email-user',
  81. ] ) .
  82. $this->parent->getHelpBox( 'config-email-user-help' ) .
  83. $this->parent->getCheckBox( [
  84. 'var' => 'wgEnotifUserTalk',
  85. 'label' => 'config-email-usertalk',
  86. ] ) .
  87. $this->parent->getHelpBox( 'config-email-usertalk-help' ) .
  88. $this->parent->getCheckBox( [
  89. 'var' => 'wgEnotifWatchlist',
  90. 'label' => 'config-email-watchlist',
  91. ] ) .
  92. $this->parent->getHelpBox( 'config-email-watchlist-help' ) .
  93. $this->parent->getCheckBox( [
  94. 'var' => 'wgEmailAuthentication',
  95. 'label' => 'config-email-auth',
  96. ] ) .
  97. $this->parent->getHelpBox( 'config-email-auth-help' ) .
  98. "</div>" .
  99. $this->getFieldsetEnd()
  100. );
  101. $skins = $this->parent->findExtensions( 'skins' );
  102. $skinHtml = $this->getFieldsetStart( 'config-skins' );
  103. $skinNames = array_map( 'strtolower', $skins );
  104. $chosenSkinName = $this->getVar( 'wgDefaultSkin', $this->parent->getDefaultSkin( $skinNames ) );
  105. if ( $skins ) {
  106. $radioButtons = $this->parent->getRadioElements( [
  107. 'var' => 'wgDefaultSkin',
  108. 'itemLabels' => array_fill_keys( $skinNames, 'config-skins-use-as-default' ),
  109. 'values' => $skinNames,
  110. 'value' => $chosenSkinName,
  111. ] );
  112. foreach ( $skins as $skin ) {
  113. $skinHtml .=
  114. '<div class="config-skins-item">' .
  115. $this->parent->getCheckBox( [
  116. 'var' => "skin-$skin",
  117. 'rawtext' => $skin,
  118. 'value' => $this->getVar( "skin-$skin", true ), // all found skins enabled by default
  119. ] ) .
  120. '<div class="config-skins-use-as-default">' . $radioButtons[strtolower( $skin )] . '</div>' .
  121. '</div>';
  122. }
  123. } else {
  124. $skinHtml .=
  125. $this->parent->getWarningBox( wfMessage( 'config-skins-missing' )->plain() ) .
  126. Html::hidden( 'config_wgDefaultSkin', $chosenSkinName );
  127. }
  128. $skinHtml .= $this->parent->getHelpBox( 'config-skins-help' ) .
  129. $this->getFieldsetEnd();
  130. $this->addHTML( $skinHtml );
  131. $extensions = $this->parent->findExtensions();
  132. if ( $extensions ) {
  133. $extHtml = $this->getFieldsetStart( 'config-extensions' );
  134. foreach ( $extensions as $ext ) {
  135. $extHtml .= $this->parent->getCheckBox( [
  136. 'var' => "ext-$ext",
  137. 'rawtext' => $ext,
  138. ] );
  139. }
  140. $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) .
  141. $this->getFieldsetEnd();
  142. $this->addHTML( $extHtml );
  143. }
  144. // Having / in paths in Windows looks funny :)
  145. $this->setVar( 'wgDeletedDirectory',
  146. str_replace(
  147. '/', DIRECTORY_SEPARATOR,
  148. $this->getVar( 'wgDeletedDirectory' )
  149. )
  150. );
  151. $uploadwrapperStyle = $this->getVar( 'wgEnableUploads' ) ? '' : 'display: none';
  152. $this->addHTML(
  153. # Uploading
  154. $this->getFieldsetStart( 'config-upload-settings' ) .
  155. $this->parent->getCheckBox( [
  156. 'var' => 'wgEnableUploads',
  157. 'label' => 'config-upload-enable',
  158. 'attribs' => [ 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ],
  159. 'help' => $this->parent->getHelpBox( 'config-upload-help' )
  160. ] ) .
  161. '<div id="uploadwrapper" style="' . $uploadwrapperStyle . '">' .
  162. $this->parent->getTextBox( [
  163. 'var' => 'wgDeletedDirectory',
  164. 'label' => 'config-upload-deleted',
  165. 'attribs' => [ 'dir' => 'ltr' ],
  166. 'help' => $this->parent->getHelpBox( 'config-upload-deleted-help' )
  167. ] ) .
  168. '</div>' .
  169. $this->parent->getTextBox( [
  170. 'var' => 'wgLogo',
  171. 'label' => 'config-logo',
  172. 'attribs' => [ 'dir' => 'ltr' ],
  173. 'help' => $this->parent->getHelpBox( 'config-logo-help' )
  174. ] )
  175. );
  176. $this->addHTML(
  177. $this->parent->getCheckBox( [
  178. 'var' => 'wgUseInstantCommons',
  179. 'label' => 'config-instantcommons',
  180. 'help' => $this->parent->getHelpBox( 'config-instantcommons-help' )
  181. ] ) .
  182. $this->getFieldsetEnd()
  183. );
  184. $caches = [ 'none' ];
  185. $cachevalDefault = 'none';
  186. if ( count( $this->getVar( '_Caches' ) ) ) {
  187. // A CACHE_ACCEL implementation is available
  188. $caches[] = 'accel';
  189. $cachevalDefault = 'accel';
  190. }
  191. $caches[] = 'memcached';
  192. // We'll hide/show this on demand when the value changes, see config.js.
  193. $cacheval = $this->getVar( '_MainCacheType' );
  194. if ( !$cacheval ) {
  195. // We need to set a default here; but don't hardcode it
  196. // or we lose it every time we reload the page for validation
  197. // or going back!
  198. $cacheval = $cachevalDefault;
  199. }
  200. $hidden = ( $cacheval == 'memcached' ) ? '' : 'display: none';
  201. $this->addHTML(
  202. # Advanced settings
  203. $this->getFieldsetStart( 'config-advanced-settings' ) .
  204. # Object cache settings
  205. // getRadioSet() builds a set of labeled radio buttons.
  206. // For grep: The following messages are used as the item labels:
  207. // config-cache-none, config-cache-accel, config-cache-memcached
  208. $this->parent->getRadioSet( [
  209. 'var' => '_MainCacheType',
  210. 'label' => 'config-cache-options',
  211. 'itemLabelPrefix' => 'config-cache-',
  212. 'values' => $caches,
  213. 'value' => $cacheval,
  214. ] ) .
  215. $this->parent->getHelpBox( 'config-cache-help' ) .
  216. "<div id=\"config-memcachewrapper\" style=\"$hidden\">" .
  217. $this->parent->getTextArea( [
  218. 'var' => '_MemCachedServers',
  219. 'label' => 'config-memcached-servers',
  220. 'help' => $this->parent->getHelpBox( 'config-memcached-help' )
  221. ] ) .
  222. '</div>' .
  223. $this->getFieldsetEnd()
  224. );
  225. $this->endForm();
  226. return null;
  227. }
  228. /**
  229. * @return string
  230. */
  231. public function getCCPartnerUrl() {
  232. $server = $this->getVar( 'wgServer' );
  233. $exitUrl = $server . $this->parent->getUrl( [
  234. 'page' => 'Options',
  235. 'SubmitCC' => 'indeed',
  236. 'config__LicenseCode' => 'cc',
  237. 'config_wgRightsUrl' => '[license_url]',
  238. 'config_wgRightsText' => '[license_name]',
  239. 'config_wgRightsIcon' => '[license_button]',
  240. ] );
  241. $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
  242. '/mw-config/config-cc.css';
  243. $iframeUrl = '//creativecommons.org/license/?' .
  244. wfArrayToCgi( [
  245. 'partner' => 'MediaWiki',
  246. 'exit_url' => $exitUrl,
  247. 'lang' => $this->getVar( '_UserLang' ),
  248. 'stylesheet' => $styleUrl,
  249. ] );
  250. return $iframeUrl;
  251. }
  252. /**
  253. * @return string
  254. */
  255. public function getCCChooser() {
  256. $iframeAttribs = [
  257. 'class' => 'config-cc-iframe',
  258. 'name' => 'config-cc-iframe',
  259. 'id' => 'config-cc-iframe',
  260. 'frameborder' => 0,
  261. 'width' => '100%',
  262. 'height' => '100%',
  263. ];
  264. if ( $this->getVar( '_CCDone' ) ) {
  265. $iframeAttribs['src'] = $this->parent->getUrl( [ 'ShowCC' => 'yes' ] );
  266. } else {
  267. $iframeAttribs['src'] = $this->getCCPartnerUrl();
  268. }
  269. $wrapperStyle = ( $this->getVar( '_LicenseCode' ) == 'cc-choose' ) ? '' : 'display: none';
  270. return "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"$wrapperStyle\">\n" .
  271. Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
  272. "</div>\n";
  273. }
  274. /**
  275. * @return string
  276. */
  277. public function getCCDoneBox() {
  278. $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
  279. // If you change this height, also change it in config.css
  280. $expandJs = str_replace( '$1', '54em', $js );
  281. $reduceJs = str_replace( '$1', '70px', $js );
  282. return '<p>' .
  283. Html::element( 'img', [ 'src' => $this->getVar( 'wgRightsIcon' ) ] ) .
  284. '&#160;&#160;' .
  285. htmlspecialchars( $this->getVar( 'wgRightsText' ) ) .
  286. "</p>\n" .
  287. "<p style=\"text-align: center;\">" .
  288. Html::element( 'a',
  289. [
  290. 'href' => $this->getCCPartnerUrl(),
  291. 'onclick' => $expandJs,
  292. ],
  293. wfMessage( 'config-cc-again' )->text()
  294. ) .
  295. "</p>\n" .
  296. "<script>\n" .
  297. # Reduce the wrapper div height
  298. htmlspecialchars( $reduceJs ) .
  299. "\n" .
  300. "</script>\n";
  301. }
  302. public function submitCC() {
  303. $newValues = $this->parent->setVarsFromRequest(
  304. [ 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ] );
  305. if ( count( $newValues ) != 3 ) {
  306. $this->parent->showError( 'config-cc-error' );
  307. return;
  308. }
  309. $this->setVar( '_CCDone', true );
  310. $this->addHTML( $this->getCCDoneBox() );
  311. }
  312. /**
  313. * If the user skips this installer page, we still need to set up the default skins, but ignore
  314. * everything else.
  315. *
  316. * @return bool
  317. */
  318. public function submitSkins() {
  319. $skins = $this->parent->findExtensions( 'skins' );
  320. $this->parent->setVar( '_Skins', $skins );
  321. if ( $skins ) {
  322. $skinNames = array_map( 'strtolower', $skins );
  323. $this->parent->setVar( 'wgDefaultSkin', $this->parent->getDefaultSkin( $skinNames ) );
  324. }
  325. return true;
  326. }
  327. /**
  328. * @return bool
  329. */
  330. public function submit() {
  331. $this->parent->setVarsFromRequest( [ '_RightsProfile', '_LicenseCode',
  332. 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUploads', 'wgLogo',
  333. 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist',
  334. 'wgEmailAuthentication', '_MainCacheType', '_MemCachedServers',
  335. 'wgUseInstantCommons', 'wgDefaultSkin' ] );
  336. $retVal = true;
  337. if ( !array_key_exists( $this->getVar( '_RightsProfile' ), $this->parent->rightsProfiles ) ) {
  338. reset( $this->parent->rightsProfiles );
  339. $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) );
  340. }
  341. $code = $this->getVar( '_LicenseCode' );
  342. if ( $code == 'cc-choose' ) {
  343. if ( !$this->getVar( '_CCDone' ) ) {
  344. $this->parent->showError( 'config-cc-not-chosen' );
  345. $retVal = false;
  346. }
  347. } elseif ( array_key_exists( $code, $this->parent->licenses ) ) {
  348. // Messages:
  349. // config-license-cc-by, config-license-cc-by-sa, config-license-cc-by-nc-sa,
  350. // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
  351. // config-license-cc-choose
  352. $entry = $this->parent->licenses[$code];
  353. if ( isset( $entry['text'] ) ) {
  354. $this->setVar( 'wgRightsText', $entry['text'] );
  355. } else {
  356. $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
  357. }
  358. $this->setVar( 'wgRightsUrl', $entry['url'] );
  359. $this->setVar( 'wgRightsIcon', $entry['icon'] );
  360. } else {
  361. $this->setVar( 'wgRightsText', '' );
  362. $this->setVar( 'wgRightsUrl', '' );
  363. $this->setVar( 'wgRightsIcon', '' );
  364. }
  365. $skinsAvailable = $this->parent->findExtensions( 'skins' );
  366. $skinsToInstall = [];
  367. foreach ( $skinsAvailable as $skin ) {
  368. $this->parent->setVarsFromRequest( [ "skin-$skin" ] );
  369. if ( $this->getVar( "skin-$skin" ) ) {
  370. $skinsToInstall[] = $skin;
  371. }
  372. }
  373. $this->parent->setVar( '_Skins', $skinsToInstall );
  374. if ( !$skinsToInstall && $skinsAvailable ) {
  375. $this->parent->showError( 'config-skins-must-enable-some' );
  376. $retVal = false;
  377. }
  378. $defaultSkin = $this->getVar( 'wgDefaultSkin' );
  379. $skinsToInstallLowercase = array_map( 'strtolower', $skinsToInstall );
  380. if ( $skinsToInstall && array_search( $defaultSkin, $skinsToInstallLowercase ) === false ) {
  381. $this->parent->showError( 'config-skins-must-enable-default' );
  382. $retVal = false;
  383. }
  384. $extsAvailable = $this->parent->findExtensions();
  385. $extsToInstall = [];
  386. foreach ( $extsAvailable as $ext ) {
  387. $this->parent->setVarsFromRequest( [ "ext-$ext" ] );
  388. if ( $this->getVar( "ext-$ext" ) ) {
  389. $extsToInstall[] = $ext;
  390. }
  391. }
  392. $this->parent->setVar( '_Extensions', $extsToInstall );
  393. if ( $this->getVar( '_MainCacheType' ) == 'memcached' ) {
  394. $memcServers = explode( "\n", $this->getVar( '_MemCachedServers' ) );
  395. if ( !$memcServers ) {
  396. $this->parent->showError( 'config-memcache-needservers' );
  397. $retVal = false;
  398. }
  399. foreach ( $memcServers as $server ) {
  400. $memcParts = explode( ":", $server, 2 );
  401. if ( !isset( $memcParts[0] )
  402. || ( !IP::isValid( $memcParts[0] )
  403. && ( gethostbyname( $memcParts[0] ) == $memcParts[0] ) )
  404. ) {
  405. $this->parent->showError( 'config-memcache-badip', $memcParts[0] );
  406. $retVal = false;
  407. } elseif ( !isset( $memcParts[1] ) ) {
  408. $this->parent->showError( 'config-memcache-noport', $memcParts[0] );
  409. $retVal = false;
  410. } elseif ( $memcParts[1] < 1 || $memcParts[1] > 65535 ) {
  411. $this->parent->showError( 'config-memcache-badport', 1, 65535 );
  412. $retVal = false;
  413. }
  414. }
  415. }
  416. return $retVal;
  417. }
  418. }