MediaWiki fundraising/REL1_35
WebInstallerName.php
Go to the documentation of this file.
1<?php
23
25
29 public function execute() {
30 $r = $this->parent->request;
31 if ( $r->wasPosted() && $this->submit() ) {
32 return 'continue';
33 }
34
35 $this->startForm();
36
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', '' );
43 }
44
45 // Set wgMetaNamespace to something valid before we show the form.
46 // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
47 $metaNS = $this->getVar( 'wgMetaNamespace' );
48 $this->setVar(
49 'wgMetaNamespace',
50 wfMessage( 'config-ns-other-default' )->inContentLanguage()->text()
51 );
52
53 $pingbackInfo = ( new Pingback() )->getSystemInfo();
54 // Database isn't available in config yet, so take it
55 // from the installer
56 $pingbackInfo['database'] = $this->getVar( 'wgDBtype' );
57
58 $this->addHTML(
59 $this->parent->getTextBox( [
60 'var' => 'wgSitename',
61 'label' => 'config-site-name',
62 'help' => $this->parent->getHelpBox( 'config-site-name-help' )
63 ] ) .
64 // getRadioSet() builds a set of labeled radio buttons.
65 // For grep: The following messages are used as the item labels:
66 // config-ns-site-name, config-ns-generic, config-ns-other
67 $this->parent->getRadioSet( [
68 'var' => '_NamespaceType',
69 'label' => 'config-project-namespace',
70 'itemLabelPrefix' => 'config-ns-',
71 'values' => [ 'site-name', 'generic', 'other' ],
72 'commonAttribs' => [ 'class' => 'enableForOther',
73 'rel' => 'config_wgMetaNamespace' ],
74 'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
75 ] ) .
76 $this->parent->getTextBox( [
77 'var' => 'wgMetaNamespace',
78 'label' => '', // @todo Needs a label?
79 'attribs' => [ 'class' => 'enabledByOther' ]
80 ] ) .
81 $this->getFieldsetStart( 'config-admin-box' ) .
82 $this->parent->getTextBox( [
83 'var' => '_AdminName',
84 'label' => 'config-admin-name',
85 'help' => $this->parent->getHelpBox( 'config-admin-help' )
86 ] ) .
87 $this->parent->getPasswordBox( [
88 'var' => '_AdminPassword',
89 'label' => 'config-admin-password',
90 ] ) .
91 $this->parent->getPasswordBox( [
92 'var' => '_AdminPasswordConfirm',
93 'label' => 'config-admin-password-confirm'
94 ] ) .
95 $this->parent->getTextBox( [
96 'var' => '_AdminEmail',
97 'attribs' => [
98 'dir' => 'ltr',
99 ],
100 'label' => 'config-admin-email',
101 'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
102 ] ) .
103 // @phan-suppress-next-line SecurityCheck-DoubleEscaped taint cannot track the helpbox from the rest
104 $this->parent->getCheckBox( [
105 'var' => '_Subscribe',
106 'label' => 'config-subscribe',
107 'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
108 ] ) .
109 // @phan-suppress-next-line SecurityCheck-DoubleEscaped taint cannot track the helpbox from the rest
110 $this->parent->getCheckBox( [
111 'var' => 'wgPingback',
112 'label' => 'config-pingback',
113 'help' => $this->parent->getHelpBox(
114 'config-pingback-help',
115 FormatJson::encode( $pingbackInfo, true )
116 ),
117 'value' => true,
118 ] ) .
119 $this->getFieldsetEnd() .
120 $this->parent->getInfoBox( wfMessage( 'config-almost-done' )->plain() ) .
121 // getRadioSet() builds a set of labeled radio buttons.
122 // For grep: The following messages are used as the item labels:
123 // config-optional-continue, config-optional-skip
124 $this->parent->getRadioSet( [
125 'var' => '_SkipOptional',
126 'itemLabelPrefix' => 'config-optional-',
127 'values' => [ 'continue', 'skip' ]
128 ] )
129 );
130
131 // Restore the default value
132 $this->setVar( 'wgMetaNamespace', $metaNS );
133
134 $this->endForm();
135
136 return 'output';
137 }
138
142 public function submit() {
143 global $wgPasswordPolicy;
144
145 $retVal = true;
146 $this->parent->setVarsFromRequest( [ 'wgSitename', '_NamespaceType',
147 '_AdminName', '_AdminPassword', '_AdminPasswordConfirm', '_AdminEmail',
148 '_Subscribe', '_SkipOptional', 'wgMetaNamespace', 'wgPingback' ] );
149
150 // Validate site name
151 if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
152 $this->parent->showError( 'config-site-name-blank' );
153 $retVal = false;
154 }
155
156 // Fetch namespace
157 $nsType = $this->getVar( '_NamespaceType' );
158 if ( $nsType == 'site-name' ) {
159 $name = $this->getVar( 'wgSitename' );
160 // Sanitize for namespace
161 // This algorithm should match the JS one in WebInstallerOutput.php
162 $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
163 $name = str_replace( '&', '&amp;', $name );
164 $name = preg_replace( '/__+/', '_', $name );
165 $name = ucfirst( trim( $name, '_' ) );
166 } elseif ( $nsType == 'generic' ) {
167 $name = wfMessage( 'config-ns-generic' )->text();
168 } else { // other
169 $name = $this->getVar( 'wgMetaNamespace' );
170 }
171
172 // Validate namespace
173 if ( strpos( $name, ':' ) !== false ) {
174 $good = false;
175 } else {
176 // Title-style validation
177 $title = Title::newFromText( $name );
178 if ( !$title ) {
179 $good = $nsType == 'site-name';
180 } else {
181 $name = $title->getDBkey();
182 $good = true;
183 }
184 }
185 if ( !$good ) {
186 $this->parent->showError( 'config-ns-invalid', $name );
187 $retVal = false;
188 }
189
190 // Make sure it won't conflict with any existing namespaces
191 $nsIndex = MediaWikiServices::getInstance()->getContentLanguage()->getNsIndex( $name );
192 if ( $nsIndex !== false && $nsIndex !== NS_PROJECT ) {
193 $this->parent->showError( 'config-ns-conflict', $name );
194 $retVal = false;
195 }
196
197 $this->setVar( 'wgMetaNamespace', $name );
198
199 // Validate username for creation
200 $name = $this->getVar( '_AdminName' );
201 if ( strval( $name ) === '' ) {
202 $this->parent->showError( 'config-admin-name-blank' );
203 $cname = $name;
204 $retVal = false;
205 } else {
206 $cname = User::getCanonicalName( $name, 'creatable' );
207 if ( $cname === false ) {
208 $this->parent->showError( 'config-admin-name-invalid', $name );
209 $retVal = false;
210 } else {
211 $this->setVar( '_AdminName', $cname );
212 }
213 }
214
215 // Validate password
216 $msg = false;
217 $pwd = $this->getVar( '_AdminPassword' );
218 $user = User::newFromName( $cname );
219 if ( $user ) {
220 $upp = new UserPasswordPolicy(
221 $wgPasswordPolicy['policies'],
222 $wgPasswordPolicy['checks']
223 );
224 $status = $upp->checkUserPasswordForGroups(
225 $user,
226 $pwd,
227 [ 'bureaucrat', 'sysop', 'interface-admin' ] // per Installer::createSysop()
228 );
229 $valid = $status->isGood() ? true : $status->getMessage();
230 } else {
231 $valid = 'config-admin-name-invalid';
232 }
233 if ( strval( $pwd ) === '' ) {
234 // Provide a more specific and helpful message if password field is left blank
235 $msg = 'config-admin-password-blank';
236 } elseif ( $pwd !== $this->getVar( '_AdminPasswordConfirm' ) ) {
237 $msg = 'config-admin-password-mismatch';
238 } elseif ( $valid !== true ) {
239 $msg = $valid;
240 }
241 if ( $msg !== false ) {
242 call_user_func( [ $this->parent, 'showError' ], $msg );
243 $this->setVar( '_AdminPassword', '' );
244 $this->setVar( '_AdminPasswordConfirm', '' );
245 $retVal = false;
246 }
247
248 // Validate e-mail if provided
249 $email = $this->getVar( '_AdminEmail' );
250 if ( $email && !Sanitizer::validateEmail( $email ) ) {
251 $this->parent->showError( 'config-admin-error-bademail' );
252 $retVal = false;
253 }
254 // If they asked to subscribe to mediawiki-announce but didn't give
255 // an e-mail, show an error. T31332
256 if ( !$email && $this->getVar( '_Subscribe' ) ) {
257 $this->parent->showError( 'config-subscribe-noemail' );
258 $retVal = false;
259 }
260
261 return $retVal;
262 }
263
264}
$wgPasswordPolicy
Password policy for the wiki.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Send information about this MediaWiki instance to MediaWiki.org.
Definition Pingback.php:32
Check if a user's password complies with any password policies that apply to that user,...
Abstract class to define pages for the web installer.
setVar( $name, $value)
endForm( $continue='continue', $back='back')
getVar( $var, $default=null)
const NS_PROJECT
Definition Defines.php:74
return true
Definition router.php:92