MediaWiki  1.33.0
MysqlInstaller.php
Go to the documentation of this file.
1 <?php
27 
35 
36  protected $globalNames = [
37  'wgDBserver',
38  'wgDBname',
39  'wgDBuser',
40  'wgDBpassword',
41  'wgDBprefix',
42  'wgDBTableOptions',
43  ];
44 
45  protected $internalDefaults = [
46  '_MysqlEngine' => 'InnoDB',
47  '_MysqlCharset' => 'binary',
48  '_InstallUser' => 'root',
49  ];
50 
51  public $supportedEngines = [ 'InnoDB', 'MyISAM' ];
52 
53  public static $minimumVersion = '5.5.8';
54  protected static $notMiniumumVerisonMessage = 'config-mysql-old';
55 
56  public $webUserPrivs = [
57  'DELETE',
58  'INSERT',
59  'SELECT',
60  'UPDATE',
61  'CREATE TEMPORARY TABLES',
62  ];
63 
67  public function getName() {
68  return 'mysql';
69  }
70 
74  public function isCompiled() {
75  return self::checkExtension( 'mysqli' );
76  }
77 
81  public function getConnectForm() {
82  return $this->getTextBox(
83  'wgDBserver',
84  'config-db-host',
85  [],
86  $this->parent->getHelpBox( 'config-db-host-help' )
87  ) .
88  Html::openElement( 'fieldset' ) .
89  Html::element( 'legend', [], wfMessage( 'config-db-wiki-settings' )->text() ) .
90  $this->getTextBox( 'wgDBname', 'config-db-name', [ 'dir' => 'ltr' ],
91  $this->parent->getHelpBox( 'config-db-name-help' ) ) .
92  $this->getTextBox( 'wgDBprefix', 'config-db-prefix', [ 'dir' => 'ltr' ],
93  $this->parent->getHelpBox( 'config-db-prefix-help' ) ) .
94  Html::closeElement( 'fieldset' ) .
95  $this->getInstallUserBox();
96  }
97 
98  public function submitConnectForm() {
99  // Get variables from the request.
100  $newValues = $this->setVarsFromRequest( [ 'wgDBserver', 'wgDBname', 'wgDBprefix' ] );
101 
102  // Validate them.
104  if ( !strlen( $newValues['wgDBserver'] ) ) {
105  $status->fatal( 'config-missing-db-host' );
106  }
107  if ( !strlen( $newValues['wgDBname'] ) ) {
108  $status->fatal( 'config-missing-db-name' );
109  } elseif ( !preg_match( '/^[a-z0-9+_-]+$/i', $newValues['wgDBname'] ) ) {
110  $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
111  }
112  if ( !preg_match( '/^[a-z0-9_-]*$/i', $newValues['wgDBprefix'] ) ) {
113  $status->fatal( 'config-invalid-db-prefix', $newValues['wgDBprefix'] );
114  }
115  if ( !$status->isOK() ) {
116  return $status;
117  }
118 
119  // Submit user box
120  $status = $this->submitInstallUserBox();
121  if ( !$status->isOK() ) {
122  return $status;
123  }
124 
125  // Try to connect
126  $status = $this->getConnection();
127  if ( !$status->isOK() ) {
128  return $status;
129  }
133  $conn = $status->value;
134 
135  // Check version
136  return static::meetsMinimumRequirement( $conn->getServerVersion() );
137  }
138 
142  public function openConnection() {
144  try {
145  $db = Database::factory( 'mysql', [
146  'host' => $this->getVar( 'wgDBserver' ),
147  'user' => $this->getVar( '_InstallUser' ),
148  'password' => $this->getVar( '_InstallPassword' ),
149  'dbname' => false,
150  'flags' => 0,
151  'tablePrefix' => $this->getVar( 'wgDBprefix' ) ] );
152  $status->value = $db;
153  } catch ( DBConnectionError $e ) {
154  $status->fatal( 'config-connection-error', $e->getMessage() );
155  }
156 
157  return $status;
158  }
159 
160  public function preUpgrade() {
161  global $wgDBuser, $wgDBpassword;
162 
163  $status = $this->getConnection();
164  if ( !$status->isOK() ) {
165  $this->parent->showStatusError( $status );
166 
167  return;
168  }
172  $conn = $status->value;
173  $conn->selectDB( $this->getVar( 'wgDBname' ) );
174 
175  # Determine existing default character set
176  if ( $conn->tableExists( "revision", __METHOD__ ) ) {
177  $revision = $this->escapeLikeInternal( $this->getVar( 'wgDBprefix' ) . 'revision', '\\' );
178  $res = $conn->query( "SHOW TABLE STATUS LIKE '$revision'", __METHOD__ );
179  $row = $conn->fetchObject( $res );
180  if ( !$row ) {
181  $this->parent->showMessage( 'config-show-table-status' );
182  $existingSchema = false;
183  $existingEngine = false;
184  } else {
185  if ( preg_match( '/^latin1/', $row->Collation ) ) {
186  $existingSchema = 'latin1';
187  } elseif ( preg_match( '/^utf8/', $row->Collation ) ) {
188  $existingSchema = 'utf8';
189  } elseif ( preg_match( '/^binary/', $row->Collation ) ) {
190  $existingSchema = 'binary';
191  } else {
192  $existingSchema = false;
193  $this->parent->showMessage( 'config-unknown-collation' );
194  }
195  $existingEngine = $row->Engine ?? $row->Type;
196  }
197  } else {
198  $existingSchema = false;
199  $existingEngine = false;
200  }
201 
202  if ( $existingSchema && $existingSchema != $this->getVar( '_MysqlCharset' ) ) {
203  $this->setVar( '_MysqlCharset', $existingSchema );
204  }
205  if ( $existingEngine && $existingEngine != $this->getVar( '_MysqlEngine' ) ) {
206  $this->setVar( '_MysqlEngine', $existingEngine );
207  }
208 
209  # Normal user and password are selected after this step, so for now
210  # just copy these two
211  $wgDBuser = $this->getVar( '_InstallUser' );
212  $wgDBpassword = $this->getVar( '_InstallPassword' );
213  }
214 
220  protected function escapeLikeInternal( $s, $escapeChar = '`' ) {
221  return str_replace( [ $escapeChar, '%', '_' ],
222  [ "{$escapeChar}{$escapeChar}", "{$escapeChar}%", "{$escapeChar}_" ],
223  $s );
224  }
225 
231  public function getEngines() {
232  $status = $this->getConnection();
233 
237  $conn = $status->value;
238 
239  $engines = [];
240  $res = $conn->query( 'SHOW ENGINES', __METHOD__ );
241  foreach ( $res as $row ) {
242  if ( $row->Support == 'YES' || $row->Support == 'DEFAULT' ) {
243  $engines[] = $row->Engine;
244  }
245  }
246  $engines = array_intersect( $this->supportedEngines, $engines );
247 
248  return $engines;
249  }
250 
256  public function getCharsets() {
257  return [ 'binary', 'utf8' ];
258  }
259 
265  public function canCreateAccounts() {
266  $status = $this->getConnection();
267  if ( !$status->isOK() ) {
268  return false;
269  }
271  $conn = $status->value;
272 
273  // Get current account name
274  $currentName = $conn->selectField( '', 'CURRENT_USER()', '', __METHOD__ );
275  $parts = explode( '@', $currentName );
276  if ( count( $parts ) != 2 ) {
277  return false;
278  }
279  $quotedUser = $conn->addQuotes( $parts[0] ) .
280  '@' . $conn->addQuotes( $parts[1] );
281 
282  // The user needs to have INSERT on mysql.* to be able to CREATE USER
283  // The grantee will be double-quoted in this query, as required
284  $res = $conn->select( 'INFORMATION_SCHEMA.USER_PRIVILEGES', '*',
285  [ 'GRANTEE' => $quotedUser ], __METHOD__ );
286  $insertMysql = false;
287  $grantOptions = array_flip( $this->webUserPrivs );
288  foreach ( $res as $row ) {
289  if ( $row->PRIVILEGE_TYPE == 'INSERT' ) {
290  $insertMysql = true;
291  }
292  if ( $row->IS_GRANTABLE ) {
293  unset( $grantOptions[$row->PRIVILEGE_TYPE] );
294  }
295  }
296 
297  // Check for DB-specific privs for mysql.*
298  if ( !$insertMysql ) {
299  $row = $conn->selectRow( 'INFORMATION_SCHEMA.SCHEMA_PRIVILEGES', '*',
300  [
301  'GRANTEE' => $quotedUser,
302  'TABLE_SCHEMA' => 'mysql',
303  'PRIVILEGE_TYPE' => 'INSERT',
304  ], __METHOD__ );
305  if ( $row ) {
306  $insertMysql = true;
307  }
308  }
309 
310  if ( !$insertMysql ) {
311  return false;
312  }
313 
314  // Check for DB-level grant options
315  $res = $conn->select( 'INFORMATION_SCHEMA.SCHEMA_PRIVILEGES', '*',
316  [
317  'GRANTEE' => $quotedUser,
318  'IS_GRANTABLE' => 1,
319  ], __METHOD__ );
320  foreach ( $res as $row ) {
321  $regex = $this->likeToRegex( $row->TABLE_SCHEMA );
322  if ( preg_match( $regex, $this->getVar( 'wgDBname' ) ) ) {
323  unset( $grantOptions[$row->PRIVILEGE_TYPE] );
324  }
325  }
326  if ( count( $grantOptions ) ) {
327  // Can't grant everything
328  return false;
329  }
330 
331  return true;
332  }
333 
340  protected function likeToRegex( $wildcard ) {
341  $r = preg_quote( $wildcard, '/' );
342  $r = strtr( $r, [
343  '%' => '.*',
344  '_' => '.'
345  ] );
346  return "/$r/s";
347  }
348 
352  public function getSettingsForm() {
353  if ( $this->canCreateAccounts() ) {
354  $noCreateMsg = false;
355  } else {
356  $noCreateMsg = 'config-db-web-no-create-privs';
357  }
358  $s = $this->getWebUserBox( $noCreateMsg );
359 
360  // Do engine selector
361  $engines = $this->getEngines();
362  // If the current default engine is not supported, use an engine that is
363  if ( !in_array( $this->getVar( '_MysqlEngine' ), $engines ) ) {
364  $this->setVar( '_MysqlEngine', reset( $engines ) );
365  }
366 
367  $s .= Xml::openElement( 'div', [
368  'id' => 'dbMyisamWarning'
369  ] );
370  $myisamWarning = 'config-mysql-myisam-dep';
371  if ( count( $engines ) === 1 ) {
372  $myisamWarning = 'config-mysql-only-myisam-dep';
373  }
374  $s .= $this->parent->getWarningBox( wfMessage( $myisamWarning )->text() );
375  $s .= Xml::closeElement( 'div' );
376 
377  if ( $this->getVar( '_MysqlEngine' ) != 'MyISAM' ) {
378  $s .= Xml::openElement( 'script' );
379  $s .= '$(\'#dbMyisamWarning\').hide();';
380  $s .= Xml::closeElement( 'script' );
381  }
382 
383  if ( count( $engines ) >= 2 ) {
384  // getRadioSet() builds a set of labeled radio buttons.
385  // For grep: The following messages are used as the item labels:
386  // config-mysql-innodb, config-mysql-myisam
387  $s .= $this->getRadioSet( [
388  'var' => '_MysqlEngine',
389  'label' => 'config-mysql-engine',
390  'itemLabelPrefix' => 'config-mysql-',
391  'values' => $engines,
392  'itemAttribs' => [
393  'MyISAM' => [
394  'class' => 'showHideRadio',
395  'rel' => 'dbMyisamWarning'
396  ],
397  'InnoDB' => [
398  'class' => 'hideShowRadio',
399  'rel' => 'dbMyisamWarning'
400  ]
401  ]
402  ] );
403  $s .= $this->parent->getHelpBox( 'config-mysql-engine-help' );
404  }
405 
406  // If the current default charset is not supported, use a charset that is
407  $charsets = $this->getCharsets();
408  if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) {
409  $this->setVar( '_MysqlCharset', reset( $charsets ) );
410  }
411 
412  return $s;
413  }
414 
418  public function submitSettingsForm() {
419  $this->setVarsFromRequest( [ '_MysqlEngine', '_MysqlCharset' ] );
420  $status = $this->submitWebUserBox();
421  if ( !$status->isOK() ) {
422  return $status;
423  }
424 
425  // Validate the create checkbox
426  $canCreate = $this->canCreateAccounts();
427  if ( !$canCreate ) {
428  $this->setVar( '_CreateDBAccount', false );
429  $create = false;
430  } else {
431  $create = $this->getVar( '_CreateDBAccount' );
432  }
433 
434  if ( !$create ) {
435  // Test the web account
436  try {
437  Database::factory( 'mysql', [
438  'host' => $this->getVar( 'wgDBserver' ),
439  'user' => $this->getVar( 'wgDBuser' ),
440  'password' => $this->getVar( 'wgDBpassword' ),
441  'dbname' => false,
442  'flags' => 0,
443  'tablePrefix' => $this->getVar( 'wgDBprefix' )
444  ] );
445  } catch ( DBConnectionError $e ) {
446  return Status::newFatal( 'config-connection-error', $e->getMessage() );
447  }
448  }
449 
450  // Validate engines and charsets
451  // This is done pre-submit already so it's just for security
452  $engines = $this->getEngines();
453  if ( !in_array( $this->getVar( '_MysqlEngine' ), $engines ) ) {
454  $this->setVar( '_MysqlEngine', reset( $engines ) );
455  }
456  $charsets = $this->getCharsets();
457  if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) {
458  $this->setVar( '_MysqlCharset', reset( $charsets ) );
459  }
460 
461  return Status::newGood();
462  }
463 
464  public function preInstall() {
465  # Add our user callback to installSteps, right before the tables are created.
466  $callback = [
467  'name' => 'user',
468  'callback' => [ $this, 'setupUser' ],
469  ];
470  $this->parent->addInstallStep( $callback, 'tables' );
471  }
472 
476  public function setupDatabase() {
477  $status = $this->getConnection();
478  if ( !$status->isOK() ) {
479  return $status;
480  }
482  $conn = $status->value;
483  $dbName = $this->getVar( 'wgDBname' );
484  if ( !$this->databaseExists( $dbName ) ) {
485  $conn->query(
486  "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ) . "CHARACTER SET utf8",
487  __METHOD__
488  );
489  }
490  $conn->selectDB( $dbName );
491  $this->setupSchemaVars();
492 
493  return $status;
494  }
495 
501  private function databaseExists( $dbName ) {
502  $encDatabase = $this->db->addQuotes( $dbName );
503 
504  return $this->db->query(
505  "SELECT 1 FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = $encDatabase",
506  __METHOD__
507  )->numRows() > 0;
508  }
509 
513  public function setupUser() {
514  $dbUser = $this->getVar( 'wgDBuser' );
515  if ( $dbUser == $this->getVar( '_InstallUser' ) ) {
516  return Status::newGood();
517  }
518  $status = $this->getConnection();
519  if ( !$status->isOK() ) {
520  return $status;
521  }
522 
523  $this->setupSchemaVars();
524  $dbName = $this->getVar( 'wgDBname' );
525  $this->db->selectDB( $dbName );
526  $server = $this->getVar( 'wgDBserver' );
527  $password = $this->getVar( 'wgDBpassword' );
528  $grantableNames = [];
529 
530  if ( $this->getVar( '_CreateDBAccount' ) ) {
531  // Before we blindly try to create a user that already has access,
532  try { // first attempt to connect to the database
533  Database::factory( 'mysql', [
534  'host' => $server,
535  'user' => $dbUser,
536  'password' => $password,
537  'dbname' => false,
538  'flags' => 0,
539  'tablePrefix' => $this->getVar( 'wgDBprefix' )
540  ] );
541  $grantableNames[] = $this->buildFullUserName( $dbUser, $server );
542  $tryToCreate = false;
543  } catch ( DBConnectionError $e ) {
544  $tryToCreate = true;
545  }
546  } else {
547  $grantableNames[] = $this->buildFullUserName( $dbUser, $server );
548  $tryToCreate = false;
549  }
550 
551  if ( $tryToCreate ) {
552  $createHostList = [
553  $server,
554  'localhost',
555  'localhost.localdomain',
556  '%'
557  ];
558 
559  $createHostList = array_unique( $createHostList );
560  $escPass = $this->db->addQuotes( $password );
561 
562  foreach ( $createHostList as $host ) {
563  $fullName = $this->buildFullUserName( $dbUser, $host );
564  if ( !$this->userDefinitelyExists( $host, $dbUser ) ) {
565  try {
566  $this->db->begin( __METHOD__ );
567  $this->db->query( "CREATE USER $fullName IDENTIFIED BY $escPass", __METHOD__ );
568  $this->db->commit( __METHOD__ );
569  $grantableNames[] = $fullName;
570  } catch ( DBQueryError $dqe ) {
571  if ( $this->db->lastErrno() == 1396 /* ER_CANNOT_USER */ ) {
572  // User (probably) already exists
573  $this->db->rollback( __METHOD__ );
574  $status->warning( 'config-install-user-alreadyexists', $dbUser );
575  $grantableNames[] = $fullName;
576  break;
577  } else {
578  // If we couldn't create for some bizzare reason and the
579  // user probably doesn't exist, skip the grant
580  $this->db->rollback( __METHOD__ );
581  $status->warning( 'config-install-user-create-failed', $dbUser, $dqe->getMessage() );
582  }
583  }
584  } else {
585  $status->warning( 'config-install-user-alreadyexists', $dbUser );
586  $grantableNames[] = $fullName;
587  break;
588  }
589  }
590  }
591 
592  // Try to grant to all the users we know exist or we were able to create
593  $dbAllTables = $this->db->addIdentifierQuotes( $dbName ) . '.*';
594  foreach ( $grantableNames as $name ) {
595  try {
596  $this->db->begin( __METHOD__ );
597  $this->db->query( "GRANT ALL PRIVILEGES ON $dbAllTables TO $name", __METHOD__ );
598  $this->db->commit( __METHOD__ );
599  } catch ( DBQueryError $dqe ) {
600  $this->db->rollback( __METHOD__ );
601  $status->fatal( 'config-install-user-grant-failed', $dbUser, $dqe->getMessage() );
602  }
603  }
604 
605  return $status;
606  }
607 
614  private function buildFullUserName( $name, $host ) {
615  return $this->db->addQuotes( $name ) . '@' . $this->db->addQuotes( $host );
616  }
617 
625  private function userDefinitelyExists( $host, $user ) {
626  try {
627  $res = $this->db->selectRow( 'mysql.user', [ 'Host', 'User' ],
628  [ 'Host' => $host, 'User' => $user ], __METHOD__ );
629 
630  return (bool)$res;
631  } catch ( DBQueryError $dqe ) {
632  return false;
633  }
634  }
635 
642  protected function getTableOptions() {
643  $options = [];
644  if ( $this->getVar( '_MysqlEngine' ) !== null ) {
645  $options[] = "ENGINE=" . $this->getVar( '_MysqlEngine' );
646  }
647  if ( $this->getVar( '_MysqlCharset' ) !== null ) {
648  $options[] = 'DEFAULT CHARSET=' . $this->getVar( '_MysqlCharset' );
649  }
650 
651  return implode( ', ', $options );
652  }
653 
659  public function getSchemaVars() {
660  return [
661  'wgDBTableOptions' => $this->getTableOptions(),
662  'wgDBname' => $this->getVar( 'wgDBname' ),
663  'wgDBuser' => $this->getVar( 'wgDBuser' ),
664  'wgDBpassword' => $this->getVar( 'wgDBpassword' ),
665  ];
666  }
667 
668  public function getLocalSettings() {
669  $prefix = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgDBprefix' ) );
671 
672  return "# MySQL specific settings
673 \$wgDBprefix = \"{$prefix}\";
674 
675 # MySQL table options to use during installation or update
676 \$wgDBTableOptions = \"{$tblOpts}\";";
677  }
678 }
MysqlInstaller\getTableOptions
getTableOptions()
Return any table options to be applied to all tables that don't override them.
Definition: MysqlInstaller.php:642
$status
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition: hooks.txt:1266
MysqlInstaller\submitSettingsForm
submitSettingsForm()
Definition: MysqlInstaller.php:418
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:48
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
MysqlInstaller\likeToRegex
likeToRegex( $wildcard)
Convert a wildcard (as used in LIKE) to a regex Slashes are escaped, slash terminators included.
Definition: MysqlInstaller.php:340
MysqlInstaller\getEngines
getEngines()
Get a list of storage engines that are available and supported.
Definition: MysqlInstaller.php:231
MysqlInstaller\$notMiniumumVerisonMessage
static $notMiniumumVerisonMessage
Definition: MysqlInstaller.php:54
DatabaseInstaller\checkExtension
static checkExtension( $name)
Convenience function.
Definition: DatabaseInstaller.php:441
MysqlInstaller\getSettingsForm
getSettingsForm()
Definition: MysqlInstaller.php:352
captcha-old.count
count
Definition: captcha-old.py:249
MysqlInstaller\$supportedEngines
$supportedEngines
Definition: MysqlInstaller.php:51
MysqlInstaller\setupUser
setupUser()
Definition: MysqlInstaller.php:513
MysqlInstaller\userDefinitelyExists
userDefinitelyExists( $host, $user)
Try to see if the user account exists.
Definition: MysqlInstaller.php:625
DatabaseInstaller\getConnection
getConnection()
Connect to the database using the administrative user/password currently defined in the session.
Definition: DatabaseInstaller.php:181
MysqlInstaller\preInstall
preInstall()
Allow DB installers a chance to make last-minute changes before installation occurs.
Definition: MysqlInstaller.php:464
MysqlInstaller\getLocalSettings
getLocalSettings()
Get the DBMS-specific options for LocalSettings.php generation.
Definition: MysqlInstaller.php:668
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:68
DatabaseInstaller\getTextBox
getTextBox( $var, $label, $attribs=[], $helpData="")
Get a labelled text box to configure a local variable.
Definition: DatabaseInstaller.php:513
$s
$s
Definition: mergeMessageFileList.php:186
MysqlInstaller\openConnection
openConnection()
Definition: MysqlInstaller.php:142
MysqlInstaller\$minimumVersion
static $minimumVersion
Definition: MysqlInstaller.php:53
$res
$res
Definition: database.txt:21
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:108
$wgDBpassword
$wgDBpassword
Database user's password.
Definition: DefaultSettings.php:1883
php
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
MysqlInstaller\getName
getName()
Definition: MysqlInstaller.php:67
MysqlInstaller\buildFullUserName
buildFullUserName( $name, $host)
Return a formal 'User'@'Host' username for use in queries.
Definition: MysqlInstaller.php:614
MysqlInstaller\isCompiled
isCompiled()
Definition: MysqlInstaller.php:74
DatabaseInstaller\submitWebUserBox
submitWebUserBox()
Submit the form from getWebUserBox().
Definition: DatabaseInstaller.php:706
DatabaseInstaller\setupSchemaVars
setupSchemaVars()
Set appropriate schema variables in the current database connection.
Definition: DatabaseInstaller.php:341
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
MysqlInstaller\submitConnectForm
submitConnectForm()
Set variables based on the request array, assuming it was submitted via the form returned by getConne...
Definition: MysqlInstaller.php:98
DatabaseInstaller\getWebUserBox
getWebUserBox( $noCreateMsg=false)
Get a standard web-user fieldset.
Definition: DatabaseInstaller.php:679
Wikimedia\Rdbms\DBQueryError
Definition: DBQueryError.php:27
MysqlInstaller\$internalDefaults
$internalDefaults
Definition: MysqlInstaller.php:45
DatabaseInstaller\getRadioSet
getRadioSet( $params)
Get a set of labelled radio buttons.
Definition: DatabaseInstaller.php:592
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
MysqlInstaller\preUpgrade
preUpgrade()
Allow DB installers a chance to make checks before upgrade.
Definition: MysqlInstaller.php:160
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2162
DatabaseInstaller\getVar
getVar( $var, $default=null)
Get a variable, taking local defaults into account.
Definition: DatabaseInstaller.php:483
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
MysqlInstaller\getSchemaVars
getSchemaVars()
Get variables to substitute into tables.sql and the SQL patch files.
Definition: MysqlInstaller.php:659
DatabaseInstaller\submitInstallUserBox
submitInstallUserBox()
Submit a standard install user fieldset.
Definition: DatabaseInstaller.php:666
DatabaseInstaller
Base class for DBMS-specific installation helper classes.
Definition: DatabaseInstaller.php:35
MysqlInstaller\getCharsets
getCharsets()
Get a list of character sets that are available and supported.
Definition: MysqlInstaller.php:256
MysqlInstaller
Class for setting up the MediaWiki database using MySQL.
Definition: MysqlInstaller.php:34
MysqlInstaller\setupDatabase
setupDatabase()
Definition: MysqlInstaller.php:476
text
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
Definition: All_system_messages.txt:1267
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:117
$options
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 & $options
Definition: hooks.txt:1985
MysqlInstaller\$globalNames
$globalNames
Definition: MysqlInstaller.php:36
as
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
DatabaseInstaller\setVar
setVar( $name, $value)
Convenience alias for $this->parent->setVar()
Definition: DatabaseInstaller.php:500
DatabaseInstaller\getInstallUserBox
getInstallUserBox()
Get a standard install-user fieldset.
Definition: DatabaseInstaller.php:644
DatabaseInstaller\setVarsFromRequest
setVarsFromRequest( $varNames)
Convenience function to set variables based on form data.
Definition: DatabaseInstaller.php:606
Wikimedia\Rdbms\DBConnectionError
Definition: DBConnectionError.php:26
LocalSettingsGenerator\escapePhpString
static escapePhpString( $string)
Returns the escaped version of a string of php code.
Definition: LocalSettingsGenerator.php:112
MysqlInstaller\databaseExists
databaseExists( $dbName)
Try to see if a given database exists.
Definition: MysqlInstaller.php:501
MysqlInstaller\getConnectForm
getConnectForm()
Definition: MysqlInstaller.php:81
$wgDBuser
$wgDBuser
Database username.
Definition: DefaultSettings.php:1878
DatabaseInstaller\$db
Database $db
The database connection.
Definition: DatabaseInstaller.php:61
MysqlInstaller\$webUserPrivs
$webUserPrivs
Definition: MysqlInstaller.php:56
wfMessage
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 use $formDescriptor instead 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 unset offset - wrap String Wrap the message in html(usually something like "&lt
MysqlInstaller\canCreateAccounts
canCreateAccounts()
Return true if the install user can create accounts.
Definition: MysqlInstaller.php:265
MysqlInstaller\escapeLikeInternal
escapeLikeInternal( $s, $escapeChar='`')
Definition: MysqlInstaller.php:220