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.
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.
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
22 class WebInstallerName
extends WebInstallerPage
{
27 public function execute() {
28 $r = $this->parent
->request
;
29 if ( $r->wasPosted() ) {
30 if ( $this->submit() ) {
37 // Encourage people to not name their site 'MediaWiki' by blanking the
38 // field. I think that was the intent with the original $GLOBALS['wgSitename']
39 // but these two always were the same so had the effect of making the
40 // installer forget $wgSitename when navigating back to this page.
41 if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
42 $this->setVar( 'wgSitename', '' );
45 // Set wgMetaNamespace to something valid before we show the form.
46 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
47 $metaNS = $this->getVar( 'wgMetaNamespace' );
50 wfMessage( 'config-ns-other-default' )->inContentLanguage()->text()
54 $this->parent
->getTextBox( [
55 'var' => 'wgSitename',
56 'label' => 'config-site-name',
57 'help' => $this->parent
->getHelpBox( 'config-site-name-help' )
59 // getRadioSet() builds a set of labeled radio buttons.
60 // For grep: The following messages are used as the item labels:
61 // config-ns-site-name, config-ns-generic, config-ns-other
62 $this->parent
->getRadioSet( [
63 'var' => '_NamespaceType',
64 'label' => 'config-project-namespace',
65 'itemLabelPrefix' => 'config-ns-',
66 'values' => [ 'site-name', 'generic', 'other' ],
67 'commonAttribs' => [ 'class' => 'enableForOther',
68 'rel' => 'config_wgMetaNamespace' ],
69 'help' => $this->parent
->getHelpBox( 'config-project-namespace-help' )
71 $this->parent
->getTextBox( [
72 'var' => 'wgMetaNamespace',
73 'label' => '', // @todo Needs a label?
74 'attribs' => [ 'readonly' => 'readonly', 'class' => 'enabledByOther' ]
76 $this->getFieldsetStart( 'config-admin-box' ) .
77 $this->parent
->getTextBox( [
78 'var' => '_AdminName',
79 'label' => 'config-admin-name',
80 'help' => $this->parent
->getHelpBox( 'config-admin-help' )
82 $this->parent
->getPasswordBox( [
83 'var' => '_AdminPassword',
84 'label' => 'config-admin-password',
86 $this->parent
->getPasswordBox( [
87 'var' => '_AdminPasswordConfirm',
88 'label' => 'config-admin-password-confirm'
90 $this->parent
->getTextBox( [
91 'var' => '_AdminEmail',
95 'label' => 'config-admin-email',
96 'help' => $this->parent
->getHelpBox( 'config-admin-email-help' )
98 $this->parent
->getCheckBox( [
99 'var' => '_Subscribe',
100 'label' => 'config-subscribe',
101 'help' => $this->parent
->getHelpBox( 'config-subscribe-help' )
103 $this->getFieldsetEnd() .
104 $this->parent
->getInfoBox( wfMessage( 'config-almost-done' )->text() ) .
105 // getRadioSet() builds a set of labeled radio buttons.
106 // For grep: The following messages are used as the item labels:
107 // config-optional-continue, config-optional-skip
108 $this->parent
->getRadioSet( [
109 'var' => '_SkipOptional',
110 'itemLabelPrefix' => 'config-optional-',
111 'values' => [ 'continue', 'skip' ]
115 // Restore the default value
116 $this->setVar( 'wgMetaNamespace', $metaNS );
126 public function submit() {
127 global $wgPasswordPolicy;
130 $this->parent
->setVarsFromRequest( [ 'wgSitename', '_NamespaceType',
131 '_AdminName', '_AdminPassword', '_AdminPasswordConfirm', '_AdminEmail',
132 '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ] );
134 // Validate site name
135 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
136 $this->parent
->showError( 'config-site-name-blank' );
141 $nsType = $this->getVar( '_NamespaceType' );
142 if ( $nsType == 'site-name' ) {
143 $name = $this->getVar( 'wgSitename' );
144 // Sanitize for namespace
145 // This algorithm should match the JS one in WebInstallerOutput.php
146 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
147 $name = str_replace( '&', '&', $name );
148 $name = preg_replace( '/__+/', '_', $name );
149 $name = ucfirst( trim( $name, '_' ) );
150 } elseif ( $nsType == 'generic' ) {
151 $name = wfMessage( 'config-ns-generic' )->text();
153 $name = $this->getVar( 'wgMetaNamespace' );
156 // Validate namespace
157 if ( strpos( $name, ':' ) !== false ) {
160 // Title-style validation
161 $title = Title
::newFromText( $name );
163 $good = $nsType == 'site-name';
165 $name = $title->getDBkey();
170 $this->parent
->showError( 'config-ns-invalid', $name );
174 // Make sure it won't conflict with any existing namespaces
176 $nsIndex = $wgContLang->getNsIndex( $name );
177 if ( $nsIndex !== false && $nsIndex !== NS_PROJECT
) {
178 $this->parent
->showError( 'config-ns-conflict', $name );
182 $this->setVar( 'wgMetaNamespace', $name );
184 // Validate username for creation
185 $name = $this->getVar( '_AdminName' );
186 if ( strval( $name ) === '' ) {
187 $this->parent
->showError( 'config-admin-name-blank' );
191 $cname = User
::getCanonicalName( $name, 'creatable' );
192 if ( $cname === false ) {
193 $this->parent
->showError( 'config-admin-name-invalid', $name );
196 $this->setVar( '_AdminName', $cname );
202 $pwd = $this->getVar( '_AdminPassword' );
203 $user = User
::newFromName( $cname );
205 $upp = new UserPasswordPolicy(
206 $wgPasswordPolicy['policies'],
207 $wgPasswordPolicy['checks']
209 $status = $upp->checkUserPasswordForGroups(
212 [ 'bureaucrat', 'sysop' ] // per Installer::createSysop()
214 $valid = $status->isGood() ?
true : $status->getMessage();
216 $valid = 'config-admin-name-invalid';
218 if ( strval( $pwd ) === '' ) {
219 // Provide a more specific and helpful message if password field is left blank
220 $msg = 'config-admin-password-blank';
221 } elseif ( $pwd !== $this->getVar( '_AdminPasswordConfirm' ) ) {
222 $msg = 'config-admin-password-mismatch';
223 } elseif ( $valid !== true ) {
226 if ( $msg !== false ) {
227 call_user_func( [ $this->parent
, 'showError' ], $msg );
228 $this->setVar( '_AdminPassword', '' );
229 $this->setVar( '_AdminPasswordConfirm', '' );
233 // Validate e-mail if provided
234 $email = $this->getVar( '_AdminEmail' );
235 if ( $email && !Sanitizer
::validateEmail( $email ) ) {
236 $this->parent
->showError( 'config-admin-error-bademail' );
239 // If they asked to subscribe to mediawiki-announce but didn't give
240 // an e-mail, show an error. Bug 29332
241 if ( !$email && $this->getVar( '_Subscribe' ) ) {
242 $this->parent
->showError( 'config-subscribe-noemail' );