MediaWiki  1.30.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  'wgDBmysql5',
44  ];
45 
46  protected $internalDefaults = [
47  '_MysqlEngine' => 'InnoDB',
48  '_MysqlCharset' => 'binary',
49  '_InstallUser' => 'root',
50  ];
51 
52  public $supportedEngines = [ 'InnoDB', 'MyISAM' ];
53 
54  public static $minimumVersion = '5.5.8';
55  protected static $notMiniumumVerisonMessage = 'config-mysql-old';
56 
57  public $webUserPrivs = [
58  'DELETE',
59  'INSERT',
60  'SELECT',
61  'UPDATE',
62  'CREATE TEMPORARY TABLES',
63  ];
64 
68  public function getName() {
69  return 'mysql';
70  }
71 
75  public function isCompiled() {
76  return self::checkExtension( 'mysql' ) || self::checkExtension( 'mysqli' );
77  }
78 
82  public function getConnectForm() {
83  return $this->getTextBox(
84  'wgDBserver',
85  'config-db-host',
86  [],
87  $this->parent->getHelpBox( 'config-db-host-help' )
88  ) .
89  Html::openElement( 'fieldset' ) .
90  Html::element( 'legend', [], wfMessage( 'config-db-wiki-settings' )->text() ) .
91  $this->getTextBox( 'wgDBname', 'config-db-name', [ 'dir' => 'ltr' ],
92  $this->parent->getHelpBox( 'config-db-name-help' ) ) .
93  $this->getTextBox( 'wgDBprefix', 'config-db-prefix', [ 'dir' => 'ltr' ],
94  $this->parent->getHelpBox( 'config-db-prefix-help' ) ) .
95  Html::closeElement( 'fieldset' ) .
96  $this->getInstallUserBox();
97  }
98 
99  public function submitConnectForm() {
100  // Get variables from the request.
101  $newValues = $this->setVarsFromRequest( [ 'wgDBserver', 'wgDBname', 'wgDBprefix' ] );
102 
103  // Validate them.
105  if ( !strlen( $newValues['wgDBserver'] ) ) {
106  $status->fatal( 'config-missing-db-host' );
107  }
108  if ( !strlen( $newValues['wgDBname'] ) ) {
109  $status->fatal( 'config-missing-db-name' );
110  } elseif ( !preg_match( '/^[a-z0-9+_-]+$/i', $newValues['wgDBname'] ) ) {
111  $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
112  }
113  if ( !preg_match( '/^[a-z0-9_-]*$/i', $newValues['wgDBprefix'] ) ) {
114  $status->fatal( 'config-invalid-db-prefix', $newValues['wgDBprefix'] );
115  }
116  if ( !$status->isOK() ) {
117  return $status;
118  }
119 
120  // Submit user box
121  $status = $this->submitInstallUserBox();
122  if ( !$status->isOK() ) {
123  return $status;
124  }
125 
126  // Try to connect
127  $status = $this->getConnection();
128  if ( !$status->isOK() ) {
129  return $status;
130  }
134  $conn = $status->value;
135 
136  // Check version
137  return static::meetsMinimumRequirement( $conn->getServerVersion() );
138  }
139 
143  public function openConnection() {
145  try {
146  $db = Database::factory( 'mysql', [
147  'host' => $this->getVar( 'wgDBserver' ),
148  'user' => $this->getVar( '_InstallUser' ),
149  'password' => $this->getVar( '_InstallPassword' ),
150  'dbname' => false,
151  'flags' => 0,
152  'tablePrefix' => $this->getVar( 'wgDBprefix' ) ] );
153  $status->value = $db;
154  } catch ( DBConnectionError $e ) {
155  $status->fatal( 'config-connection-error', $e->getMessage() );
156  }
157 
158  return $status;
159  }
160 
161  public function preUpgrade() {
163 
164  $status = $this->getConnection();
165  if ( !$status->isOK() ) {
166  $this->parent->showStatusError( $status );
167 
168  return;
169  }
173  $conn = $status->value;
174  $conn->selectDB( $this->getVar( 'wgDBname' ) );
175 
176  # Determine existing default character set
177  if ( $conn->tableExists( "revision", __METHOD__ ) ) {
178  $revision = $this->escapeLikeInternal( $this->getVar( 'wgDBprefix' ) . 'revision', '\\' );
179  $res = $conn->query( "SHOW TABLE STATUS LIKE '$revision'", __METHOD__ );
180  $row = $conn->fetchObject( $res );
181  if ( !$row ) {
182  $this->parent->showMessage( 'config-show-table-status' );
183  $existingSchema = false;
184  $existingEngine = false;
185  } else {
186  if ( preg_match( '/^latin1/', $row->Collation ) ) {
187  $existingSchema = 'latin1';
188  } elseif ( preg_match( '/^utf8/', $row->Collation ) ) {
189  $existingSchema = 'utf8';
190  } elseif ( preg_match( '/^binary/', $row->Collation ) ) {
191  $existingSchema = 'binary';
192  } else {
193  $existingSchema = false;
194  $this->parent->showMessage( 'config-unknown-collation' );
195  }
196  if ( isset( $row->Engine ) ) {
197  $existingEngine = $row->Engine;
198  } else {
199  $existingEngine = $row->Type;
200  }
201  }
202  } else {
203  $existingSchema = false;
204  $existingEngine = false;
205  }
206 
207  if ( $existingSchema && $existingSchema != $this->getVar( '_MysqlCharset' ) ) {
208  $this->setVar( '_MysqlCharset', $existingSchema );
209  }
210  if ( $existingEngine && $existingEngine != $this->getVar( '_MysqlEngine' ) ) {
211  $this->setVar( '_MysqlEngine', $existingEngine );
212  }
213 
214  # Normal user and password are selected after this step, so for now
215  # just copy these two
216  $wgDBuser = $this->getVar( '_InstallUser' );
217  $wgDBpassword = $this->getVar( '_InstallPassword' );
218  }
219 
225  protected function escapeLikeInternal( $s, $escapeChar = '`' ) {
226  return str_replace( [ $escapeChar, '%', '_' ],
227  [ "{$escapeChar}{$escapeChar}", "{$escapeChar}%", "{$escapeChar}_" ],
228  $s );
229  }
230 
236  public function getEngines() {
237  $status = $this->getConnection();
238 
242  $conn = $status->value;
243 
244  $engines = [];
245  $res = $conn->query( 'SHOW ENGINES', __METHOD__ );
246  foreach ( $res as $row ) {
247  if ( $row->Support == 'YES' || $row->Support == 'DEFAULT' ) {
248  $engines[] = $row->Engine;
249  }
250  }
251  $engines = array_intersect( $this->supportedEngines, $engines );
252 
253  return $engines;
254  }
255 
261  public function getCharsets() {
262  return [ 'binary', 'utf8' ];
263  }
264 
270  public function canCreateAccounts() {
271  $status = $this->getConnection();
272  if ( !$status->isOK() ) {
273  return false;
274  }
276  $conn = $status->value;
277 
278  // Get current account name
279  $currentName = $conn->selectField( '', 'CURRENT_USER()', '', __METHOD__ );
280  $parts = explode( '@', $currentName );
281  if ( count( $parts ) != 2 ) {
282  return false;
283  }
284  $quotedUser = $conn->addQuotes( $parts[0] ) .
285  '@' . $conn->addQuotes( $parts[1] );
286 
287  // The user needs to have INSERT on mysql.* to be able to CREATE USER
288  // The grantee will be double-quoted in this query, as required
289  $res = $conn->select( 'INFORMATION_SCHEMA.USER_PRIVILEGES', '*',
290  [ 'GRANTEE' => $quotedUser ], __METHOD__ );
291  $insertMysql = false;
292  $grantOptions = array_flip( $this->webUserPrivs );
293  foreach ( $res as $row ) {
294  if ( $row->PRIVILEGE_TYPE == 'INSERT' ) {
295  $insertMysql = true;
296  }
297  if ( $row->IS_GRANTABLE ) {
298  unset( $grantOptions[$row->PRIVILEGE_TYPE] );
299  }
300  }
301 
302  // Check for DB-specific privs for mysql.*
303  if ( !$insertMysql ) {
304  $row = $conn->selectRow( 'INFORMATION_SCHEMA.SCHEMA_PRIVILEGES', '*',
305  [
306  'GRANTEE' => $quotedUser,
307  'TABLE_SCHEMA' => 'mysql',
308  'PRIVILEGE_TYPE' => 'INSERT',
309  ], __METHOD__ );
310  if ( $row ) {
311  $insertMysql = true;
312  }
313  }
314 
315  if ( !$insertMysql ) {
316  return false;
317  }
318 
319  // Check for DB-level grant options
320  $res = $conn->select( 'INFORMATION_SCHEMA.SCHEMA_PRIVILEGES', '*',
321  [
322  'GRANTEE' => $quotedUser,
323  'IS_GRANTABLE' => 1,
324  ], __METHOD__ );
325  foreach ( $res as $row ) {
326  $regex = $this->likeToRegex( $row->TABLE_SCHEMA );
327  if ( preg_match( $regex, $this->getVar( 'wgDBname' ) ) ) {
328  unset( $grantOptions[$row->PRIVILEGE_TYPE] );
329  }
330  }
331  if ( count( $grantOptions ) ) {
332  // Can't grant everything
333  return false;
334  }
335 
336  return true;
337  }
338 
345  protected function likeToRegex( $wildcard ) {
346  $r = preg_quote( $wildcard, '/' );
347  $r = strtr( $r, [
348  '%' => '.*',
349  '_' => '.'
350  ] );
351  return "/$r/s";
352  }
353 
357  public function getSettingsForm() {
358  if ( $this->canCreateAccounts() ) {
359  $noCreateMsg = false;
360  } else {
361  $noCreateMsg = 'config-db-web-no-create-privs';
362  }
363  $s = $this->getWebUserBox( $noCreateMsg );
364 
365  // Do engine selector
366  $engines = $this->getEngines();
367  // If the current default engine is not supported, use an engine that is
368  if ( !in_array( $this->getVar( '_MysqlEngine' ), $engines ) ) {
369  $this->setVar( '_MysqlEngine', reset( $engines ) );
370  }
371 
372  $s .= Xml::openElement( 'div', [
373  'id' => 'dbMyisamWarning'
374  ] );
375  $myisamWarning = 'config-mysql-myisam-dep';
376  if ( count( $engines ) === 1 ) {
377  $myisamWarning = 'config-mysql-only-myisam-dep';
378  }
379  $s .= $this->parent->getWarningBox( wfMessage( $myisamWarning )->text() );
380  $s .= Xml::closeElement( 'div' );
381 
382  if ( $this->getVar( '_MysqlEngine' ) != 'MyISAM' ) {
383  $s .= Xml::openElement( 'script' );
384  $s .= '$(\'#dbMyisamWarning\').hide();';
385  $s .= Xml::closeElement( 'script' );
386  }
387 
388  if ( count( $engines ) >= 2 ) {
389  // getRadioSet() builds a set of labeled radio buttons.
390  // For grep: The following messages are used as the item labels:
391  // config-mysql-innodb, config-mysql-myisam
392  $s .= $this->getRadioSet( [
393  'var' => '_MysqlEngine',
394  'label' => 'config-mysql-engine',
395  'itemLabelPrefix' => 'config-mysql-',
396  'values' => $engines,
397  'itemAttribs' => [
398  'MyISAM' => [
399  'class' => 'showHideRadio',
400  'rel' => 'dbMyisamWarning'
401  ],
402  'InnoDB' => [
403  'class' => 'hideShowRadio',
404  'rel' => 'dbMyisamWarning'
405  ]
406  ]
407  ] );
408  $s .= $this->parent->getHelpBox( 'config-mysql-engine-help' );
409  }
410 
411  // If the current default charset is not supported, use a charset that is
412  $charsets = $this->getCharsets();
413  if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) {
414  $this->setVar( '_MysqlCharset', reset( $charsets ) );
415  }
416 
417  // Do charset selector
418  if ( count( $charsets ) >= 2 ) {
419  // getRadioSet() builds a set of labeled radio buttons.
420  // For grep: The following messages are used as the item labels:
421  // config-mysql-binary, config-mysql-utf8
422  $s .= $this->getRadioSet( [
423  'var' => '_MysqlCharset',
424  'label' => 'config-mysql-charset',
425  'itemLabelPrefix' => 'config-mysql-',
426  'values' => $charsets
427  ] );
428  $s .= $this->parent->getHelpBox( 'config-mysql-charset-help' );
429  }
430 
431  return $s;
432  }
433 
437  public function submitSettingsForm() {
438  $this->setVarsFromRequest( [ '_MysqlEngine', '_MysqlCharset' ] );
439  $status = $this->submitWebUserBox();
440  if ( !$status->isOK() ) {
441  return $status;
442  }
443 
444  // Validate the create checkbox
445  $canCreate = $this->canCreateAccounts();
446  if ( !$canCreate ) {
447  $this->setVar( '_CreateDBAccount', false );
448  $create = false;
449  } else {
450  $create = $this->getVar( '_CreateDBAccount' );
451  }
452 
453  if ( !$create ) {
454  // Test the web account
455  try {
456  Database::factory( 'mysql', [
457  'host' => $this->getVar( 'wgDBserver' ),
458  'user' => $this->getVar( 'wgDBuser' ),
459  'password' => $this->getVar( 'wgDBpassword' ),
460  'dbname' => false,
461  'flags' => 0,
462  'tablePrefix' => $this->getVar( 'wgDBprefix' )
463  ] );
464  } catch ( DBConnectionError $e ) {
465  return Status::newFatal( 'config-connection-error', $e->getMessage() );
466  }
467  }
468 
469  // Validate engines and charsets
470  // This is done pre-submit already so it's just for security
471  $engines = $this->getEngines();
472  if ( !in_array( $this->getVar( '_MysqlEngine' ), $engines ) ) {
473  $this->setVar( '_MysqlEngine', reset( $engines ) );
474  }
475  $charsets = $this->getCharsets();
476  if ( !in_array( $this->getVar( '_MysqlCharset' ), $charsets ) ) {
477  $this->setVar( '_MysqlCharset', reset( $charsets ) );
478  }
479 
480  return Status::newGood();
481  }
482 
483  public function preInstall() {
484  # Add our user callback to installSteps, right before the tables are created.
485  $callback = [
486  'name' => 'user',
487  'callback' => [ $this, 'setupUser' ],
488  ];
489  $this->parent->addInstallStep( $callback, 'tables' );
490  }
491 
495  public function setupDatabase() {
496  $status = $this->getConnection();
497  if ( !$status->isOK() ) {
498  return $status;
499  }
501  $conn = $status->value;
502  $dbName = $this->getVar( 'wgDBname' );
503  if ( !$conn->selectDB( $dbName ) ) {
504  $conn->query(
505  "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ) . "CHARACTER SET utf8",
506  __METHOD__
507  );
508  $conn->selectDB( $dbName );
509  }
510  $this->setupSchemaVars();
511 
512  return $status;
513  }
514 
518  public function setupUser() {
519  $dbUser = $this->getVar( 'wgDBuser' );
520  if ( $dbUser == $this->getVar( '_InstallUser' ) ) {
521  return Status::newGood();
522  }
523  $status = $this->getConnection();
524  if ( !$status->isOK() ) {
525  return $status;
526  }
527 
528  $this->setupSchemaVars();
529  $dbName = $this->getVar( 'wgDBname' );
530  $this->db->selectDB( $dbName );
531  $server = $this->getVar( 'wgDBserver' );
532  $password = $this->getVar( 'wgDBpassword' );
533  $grantableNames = [];
534 
535  if ( $this->getVar( '_CreateDBAccount' ) ) {
536  // Before we blindly try to create a user that already has access,
537  try { // first attempt to connect to the database
538  Database::factory( 'mysql', [
539  'host' => $server,
540  'user' => $dbUser,
541  'password' => $password,
542  'dbname' => false,
543  'flags' => 0,
544  'tablePrefix' => $this->getVar( 'wgDBprefix' )
545  ] );
546  $grantableNames[] = $this->buildFullUserName( $dbUser, $server );
547  $tryToCreate = false;
548  } catch ( DBConnectionError $e ) {
549  $tryToCreate = true;
550  }
551  } else {
552  $grantableNames[] = $this->buildFullUserName( $dbUser, $server );
553  $tryToCreate = false;
554  }
555 
556  if ( $tryToCreate ) {
557  $createHostList = [
558  $server,
559  'localhost',
560  'localhost.localdomain',
561  '%'
562  ];
563 
564  $createHostList = array_unique( $createHostList );
565  $escPass = $this->db->addQuotes( $password );
566 
567  foreach ( $createHostList as $host ) {
568  $fullName = $this->buildFullUserName( $dbUser, $host );
569  if ( !$this->userDefinitelyExists( $host, $dbUser ) ) {
570  try {
571  $this->db->begin( __METHOD__ );
572  $this->db->query( "CREATE USER $fullName IDENTIFIED BY $escPass", __METHOD__ );
573  $this->db->commit( __METHOD__ );
574  $grantableNames[] = $fullName;
575  } catch ( DBQueryError $dqe ) {
576  if ( $this->db->lastErrno() == 1396 /* ER_CANNOT_USER */ ) {
577  // User (probably) already exists
578  $this->db->rollback( __METHOD__ );
579  $status->warning( 'config-install-user-alreadyexists', $dbUser );
580  $grantableNames[] = $fullName;
581  break;
582  } else {
583  // If we couldn't create for some bizzare reason and the
584  // user probably doesn't exist, skip the grant
585  $this->db->rollback( __METHOD__ );
586  $status->warning( 'config-install-user-create-failed', $dbUser, $dqe->getMessage() );
587  }
588  }
589  } else {
590  $status->warning( 'config-install-user-alreadyexists', $dbUser );
591  $grantableNames[] = $fullName;
592  break;
593  }
594  }
595  }
596 
597  // Try to grant to all the users we know exist or we were able to create
598  $dbAllTables = $this->db->addIdentifierQuotes( $dbName ) . '.*';
599  foreach ( $grantableNames as $name ) {
600  try {
601  $this->db->begin( __METHOD__ );
602  $this->db->query( "GRANT ALL PRIVILEGES ON $dbAllTables TO $name", __METHOD__ );
603  $this->db->commit( __METHOD__ );
604  } catch ( DBQueryError $dqe ) {
605  $this->db->rollback( __METHOD__ );
606  $status->fatal( 'config-install-user-grant-failed', $dbUser, $dqe->getMessage() );
607  }
608  }
609 
610  return $status;
611  }
612 
619  private function buildFullUserName( $name, $host ) {
620  return $this->db->addQuotes( $name ) . '@' . $this->db->addQuotes( $host );
621  }
622 
630  private function userDefinitelyExists( $host, $user ) {
631  try {
632  $res = $this->db->selectRow( 'mysql.user', [ 'Host', 'User' ],
633  [ 'Host' => $host, 'User' => $user ], __METHOD__ );
634 
635  return (bool)$res;
636  } catch ( DBQueryError $dqe ) {
637  return false;
638  }
639  }
640 
647  protected function getTableOptions() {
648  $options = [];
649  if ( $this->getVar( '_MysqlEngine' ) !== null ) {
650  $options[] = "ENGINE=" . $this->getVar( '_MysqlEngine' );
651  }
652  if ( $this->getVar( '_MysqlCharset' ) !== null ) {
653  $options[] = 'DEFAULT CHARSET=' . $this->getVar( '_MysqlCharset' );
654  }
655 
656  return implode( ', ', $options );
657  }
658 
664  public function getSchemaVars() {
665  return [
666  'wgDBTableOptions' => $this->getTableOptions(),
667  'wgDBname' => $this->getVar( 'wgDBname' ),
668  'wgDBuser' => $this->getVar( 'wgDBuser' ),
669  'wgDBpassword' => $this->getVar( 'wgDBpassword' ),
670  ];
671  }
672 
673  public function getLocalSettings() {
674  $dbmysql5 = wfBoolToStr( $this->getVar( 'wgDBmysql5', true ) );
675  $prefix = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgDBprefix' ) );
677 
678  return "# MySQL specific settings
679 \$wgDBprefix = \"{$prefix}\";
680 
681 # MySQL table options to use during installation or update
682 \$wgDBTableOptions = \"{$tblOpts}\";
683 
684 # Experimental charset support for MySQL 5.0.
685 \$wgDBmysql5 = {$dbmysql5};";
686  }
687 }
MysqlInstaller\getTableOptions
getTableOptions()
Return any table options to be applied to all tables that don't override them.
Definition: MysqlInstaller.php:647
MysqlInstaller\submitSettingsForm
submitSettingsForm()
Definition: MysqlInstaller.php:437
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:45
$user
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 account $user
Definition: hooks.txt:244
MysqlInstaller\likeToRegex
likeToRegex( $wildcard)
Convert a wildcard (as used in LIKE) to a regex Slashes are escaped, slash terminators included.
Definition: MysqlInstaller.php:345
MysqlInstaller\getEngines
getEngines()
Get a list of storage engines that are available and supported.
Definition: MysqlInstaller.php:236
MysqlInstaller\$notMiniumumVerisonMessage
static $notMiniumumVerisonMessage
Definition: MysqlInstaller.php:55
DatabaseInstaller\checkExtension
static checkExtension( $name)
Convenience function.
Definition: DatabaseInstaller.php:438
MysqlInstaller\getSettingsForm
getSettingsForm()
Definition: MysqlInstaller.php:357
captcha-old.count
count
Definition: captcha-old.py:249
MysqlInstaller\$supportedEngines
$supportedEngines
Definition: MysqlInstaller.php:52
text
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
MysqlInstaller\setupUser
setupUser()
Definition: MysqlInstaller.php:518
MysqlInstaller\userDefinitelyExists
userDefinitelyExists( $host, $user)
Try to see if the user account exists.
Definition: MysqlInstaller.php:630
DatabaseInstaller\getConnection
getConnection()
Connect to the database using the administrative user/password currently defined in the session.
Definition: DatabaseInstaller.php:179
$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. '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). '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:1245
MysqlInstaller\preInstall
preInstall()
Allow DB installers a chance to make last-minute changes before installation occurs.
Definition: MysqlInstaller.php:483
MysqlInstaller\getLocalSettings
getLocalSettings()
Get the DBMS-specific options for LocalSettings.php generation.
Definition: MysqlInstaller.php:673
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
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:510
$s
$s
Definition: mergeMessageFileList.php:188
MysqlInstaller\openConnection
openConnection()
Definition: MysqlInstaller.php:143
MysqlInstaller\$minimumVersion
static $minimumVersion
Definition: MysqlInstaller.php:54
$res
$res
Definition: database.txt:21
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
$wgDBpassword
$wgDBpassword
Database user's password.
Definition: DefaultSettings.php:1792
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:68
MysqlInstaller\buildFullUserName
buildFullUserName( $name, $host)
Return a formal 'User'@'Host' username for use in queries.
Definition: MysqlInstaller.php:619
wfBoolToStr
wfBoolToStr( $value)
Convenience function converts boolean values into "true" or "false" (string) values.
Definition: GlobalFunctions.php:2975
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:309
MysqlInstaller\isCompiled
isCompiled()
Definition: MysqlInstaller.php:75
DatabaseInstaller\submitWebUserBox
submitWebUserBox()
Submit the form from getWebUserBox().
Definition: DatabaseInstaller.php:698
DatabaseInstaller\setupSchemaVars
setupSchemaVars()
Set appropriate schema variables in the current database connection.
Definition: DatabaseInstaller.php:339
MysqlInstaller\submitConnectForm
submitConnectForm()
Set variables based on the request array, assuming it was submitted via the form returned by getConne...
Definition: MysqlInstaller.php:99
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
DatabaseInstaller\getWebUserBox
getWebUserBox( $noCreateMsg=false)
Get a standard web-user fieldset.
Definition: DatabaseInstaller.php:671
Wikimedia\Rdbms\DBQueryError
Definition: DBQueryError.php:27
MysqlInstaller\$internalDefaults
$internalDefaults
Definition: MysqlInstaller.php:46
DatabaseInstaller\getRadioSet
getRadioSet( $params)
Get a set of labelled radio buttons.
Definition: DatabaseInstaller.php:589
MysqlInstaller\preUpgrade
preUpgrade()
Allow DB installers a chance to make checks before upgrade.
Definition: MysqlInstaller.php:161
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2141
DatabaseInstaller\getVar
getVar( $var, $default=null)
Get a variable, taking local defaults into account.
Definition: DatabaseInstaller.php:480
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:664
DatabaseInstaller\submitInstallUserBox
submitInstallUserBox()
Submit a standard install user fieldset.
Definition: DatabaseInstaller.php:658
DatabaseInstaller
Base class for DBMS-specific installation helper classes.
Definition: DatabaseInstaller.php:33
MysqlInstaller\getCharsets
getCharsets()
Get a list of character sets that are available and supported.
Definition: MysqlInstaller.php:261
MysqlInstaller
Class for setting up the MediaWiki database using MySQL.
Definition: MysqlInstaller.php:34
MysqlInstaller\setupDatabase
setupDatabase()
Definition: MysqlInstaller.php:495
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:118
$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:1965
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
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:251
DatabaseInstaller\setVar
setVar( $name, $value)
Convenience alias for $this->parent->setVar()
Definition: DatabaseInstaller.php:497
DatabaseInstaller\getInstallUserBox
getInstallUserBox()
Get a standard install-user fieldset.
Definition: DatabaseInstaller.php:636
DatabaseInstaller\setVarsFromRequest
setVarsFromRequest( $varNames)
Convenience function to set variables based on form data.
Definition: DatabaseInstaller.php:603
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\getConnectForm
getConnectForm()
Definition: MysqlInstaller.php:82
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 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
$wgDBuser
$wgDBuser
Database username.
Definition: DefaultSettings.php:1787
DatabaseInstaller\$db
Database $db
The database connection.
Definition: DatabaseInstaller.php:59
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
MysqlInstaller\$webUserPrivs
$webUserPrivs
Definition: MysqlInstaller.php:57
MysqlInstaller\canCreateAccounts
canCreateAccounts()
Return true if the install user can create accounts.
Definition: MysqlInstaller.php:270
MysqlInstaller\escapeLikeInternal
escapeLikeInternal( $s, $escapeChar='`')
Definition: MysqlInstaller.php:225