MediaWiki  1.27.2
WebInstallerName.php
Go to the documentation of this file.
1 <?php
23 
27  public function execute() {
28  $r = $this->parent->request;
29  if ( $r->wasPosted() ) {
30  if ( $this->submit() ) {
31  return 'continue';
32  }
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  $this->addHTML(
54  $this->parent->getTextBox( [
55  'var' => 'wgSitename',
56  'label' => 'config-site-name',
57  'help' => $this->parent->getHelpBox( 'config-site-name-help' )
58  ] ) .
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' )
70  ] ) .
71  $this->parent->getTextBox( [
72  'var' => 'wgMetaNamespace',
73  'label' => '', // @todo Needs a label?
74  'attribs' => [ 'readonly' => 'readonly', 'class' => 'enabledByOther' ]
75  ] ) .
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' )
81  ] ) .
82  $this->parent->getPasswordBox( [
83  'var' => '_AdminPassword',
84  'label' => 'config-admin-password',
85  ] ) .
86  $this->parent->getPasswordBox( [
87  'var' => '_AdminPasswordConfirm',
88  'label' => 'config-admin-password-confirm'
89  ] ) .
90  $this->parent->getTextBox( [
91  'var' => '_AdminEmail',
92  'attribs' => [
93  'dir' => 'ltr',
94  ],
95  'label' => 'config-admin-email',
96  'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
97  ] ) .
98  $this->parent->getCheckBox( [
99  'var' => '_Subscribe',
100  'label' => 'config-subscribe',
101  'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
102  ] ) .
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' ]
112  ] )
113  );
114 
115  // Restore the default value
116  $this->setVar( 'wgMetaNamespace', $metaNS );
117 
118  $this->endForm();
119 
120  return 'output';
121  }
122 
126  public function submit() {
127  global $wgPasswordPolicy;
128 
129  $retVal = true;
130  $this->parent->setVarsFromRequest( [ 'wgSitename', '_NamespaceType',
131  '_AdminName', '_AdminPassword', '_AdminPasswordConfirm', '_AdminEmail',
132  '_Subscribe', '_SkipOptional', 'wgMetaNamespace' ] );
133 
134  // Validate site name
135  if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
136  $this->parent->showError( 'config-site-name-blank' );
137  $retVal = false;
138  }
139 
140  // Fetch namespace
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( '&', '&amp;', $name );
148  $name = preg_replace( '/__+/', '_', $name );
149  $name = ucfirst( trim( $name, '_' ) );
150  } elseif ( $nsType == 'generic' ) {
151  $name = wfMessage( 'config-ns-generic' )->text();
152  } else { // other
153  $name = $this->getVar( 'wgMetaNamespace' );
154  }
155 
156  // Validate namespace
157  if ( strpos( $name, ':' ) !== false ) {
158  $good = false;
159  } else {
160  // Title-style validation
162  if ( !$title ) {
163  $good = $nsType == 'site-name';
164  } else {
165  $name = $title->getDBkey();
166  $good = true;
167  }
168  }
169  if ( !$good ) {
170  $this->parent->showError( 'config-ns-invalid', $name );
171  $retVal = false;
172  }
173 
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 );
179  $retVal = false;
180  }
181 
182  $this->setVar( 'wgMetaNamespace', $name );
183 
184  // Validate username for creation
185  $name = $this->getVar( '_AdminName' );
186  if ( strval( $name ) === '' ) {
187  $this->parent->showError( 'config-admin-name-blank' );
188  $cname = $name;
189  $retVal = false;
190  } else {
191  $cname = User::getCanonicalName( $name, 'creatable' );
192  if ( $cname === false ) {
193  $this->parent->showError( 'config-admin-name-invalid', $name );
194  $retVal = false;
195  } else {
196  $this->setVar( '_AdminName', $cname );
197  }
198  }
199 
200  // Validate password
201  $msg = false;
202  $pwd = $this->getVar( '_AdminPassword' );
203  $user = User::newFromName( $cname );
204  if ( $user ) {
205  $upp = new UserPasswordPolicy(
206  $wgPasswordPolicy['policies'],
207  $wgPasswordPolicy['checks']
208  );
209  $status = $upp->checkUserPasswordForGroups(
210  $user,
211  $pwd,
212  [ 'bureaucrat', 'sysop' ] // per Installer::createSysop()
213  );
214  $valid = $status->isGood() ? true : $status->getMessage();
215  } else {
216  $valid = 'config-admin-name-invalid';
217  }
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 ) {
224  $msg = $valid;
225  }
226  if ( $msg !== false ) {
227  call_user_func( [ $this->parent, 'showError' ], $msg );
228  $this->setVar( '_AdminPassword', '' );
229  $this->setVar( '_AdminPasswordConfirm', '' );
230  $retVal = false;
231  }
232 
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' );
237  $retVal = false;
238  }
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' );
243  $retVal = false;
244  }
245 
246  return $retVal;
247  }
248 
249 }
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
Definition: User.php:568
Abstract class to define pages for the web installer.
setVar($name, $value)
static getCanonicalName($name, $validate= 'valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid...
Definition: User.php:1050
Check if a user's password complies with any password policies that apply to that user...
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:277
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
const NS_PROJECT
Definition: Defines.php:73
getFieldsetStart($legend)
Get the starting tags of a fieldset.
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 and may include noclasses after processing 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
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
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
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
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
getVar($var, $default=null)
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition: design.txt:56
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1004
static validateEmail($addr)
Does a string look like an e-mail address?
Definition: Sanitizer.php:1904
getFieldsetEnd()
Get the end tag of a fieldset.
endForm($continue= 'continue', $back= 'back')
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310