Movatterモバイル変換


[0]ホーム

URL:


Jump to content
MediaWiki
Search

Manual:Hooks/LoadExtensionSchemaUpdates

From mediawiki.org
<Manual:Hooks
Translate this page
Languages:
LoadExtensionSchemaUpdates
Available fromversion 1.10.1
Fired when MediaWiki is updated to allow extensions to register updates for the database schema
Define function:
publicstaticfunctiononLoadExtensionSchemaUpdates(DatabaseUpdater$updater){...}
Attach hook:Inextension.json:
{"Hooks":{"LoadExtensionSchemaUpdates":"MediaWiki\\Extension\\MyExtension\\Hooks::onLoadExtensionSchemaUpdates"}}
Called from:File(s):installer/DatabaseUpdater.php
Function(s):__construct
Interface:LoadExtensionSchemaUpdatesHook.php

For more information about attaching hooks, seeManual:Hooks.
For examples of extensions using this hook, seeCategory:LoadExtensionSchemaUpdates extensions.

Usage

[edit]
If your extension requires changes to the database when MediaWiki is updated, use this hook to add them to the updater using methods likeDatabaseUpdater::addExtensionTable(),DatabaseUpdater::modifyExtensionField(), etc.
WarningWarning:
  • If your extension is used on any production WMF-hosted wiki please follow theSchema change guide.
  • Handlers for this hook must not directly modify the database using methods likeDatabaseUpdater::addTable(),DatabaseUpdater::dropField(), etc. They must only register updates, using methods likeDatabaseUpdater::addExtensionTable(),DatabaseUpdater::modifyExtensionField(), etc.
  • Your extension should not modify any MW core database. Instead, the extension should create new tables with foreign key to the relevant MW table.

Summary

[edit]
  1. Create your hook as indicated below. The example shows how to setup the hook function. If you have more than one schema update, you can put them in the same function. Make sure you are using the methods withExtension in the name toregister the updates, rather than execute them directly.
  2. Make sure the hook has access to any necessary SQL files, which are usually located in ansql/ directory.
  3. Format theSQL files correctly. See theArticleFeedbackv5 SQL, and the correspondinghooks file, for some examples.
  4. From the command line run thephp maintenance/run.php update script to update your wiki’s database with your extension’sLoadExtensionSchemaUpdates hook. See theupdate.php manual for more information.

>= 1.25

[edit]

Extension registration was introduced in MW 1.25, and so the Hooks section ofextension.json should be used instead of$wgHooks.For example:

"Hooks":{"LoadExtensionSchemaUpdates":"MediaWiki\\Extension\\ExtensionName\\Hooks::onLoadExtensionSchemaUpdates"}

And inExtensionName/includes/Hooks.php:

namespaceMediaWiki\Extension\ExtensionName;useDatabaseUpdater;classHooks{publicstaticfunctiononLoadExtensionSchemaUpdates(DatabaseUpdater$updater){// Register an SQL patch for changing the field$updater->modifyExtensionField('tablename','name_of_field',__DIR__.'/sql/patch_file_changing_field.sql');}}

The code of the hook callback is the same as for earlier versions (see below).

See also

[edit]
Engines
Current
Former
Technical documentation
Configuration
Development
Core tables
Current
Former
Retrieved from "https://www.mediawiki.org/w/index.php?title=Manual:Hooks/LoadExtensionSchemaUpdates&oldid=7680954"
Categories:

[8]ページ先頭

©2009-2025 Movatter.jp