Movatterモバイル変換


[0]ホーム

URL:


Jump to content
MediaWiki
Search

Manual:Hooks/EditPage::showEditForm:initial

From mediawiki.org
<Manual:Hooks
EditPage::showEditForm:initial
Available from version 1.6.0
Called just before the preview and edit form are rendered
Define function:
publicstaticfunctiononEditPage_showEditForm_initial(EditPage$editPage,OutputPage$output){...}
Attach hook:Inextension.json:
{"Hooks":{"EditPage::showEditForm:initial":"MediaWiki\\Extension\\MyExtension\\Hooks::onEditPageshowEditForminitial"}}
Called from:File(s):EditPage.php
Interface:EditPage__showEditForm_initialHook.php

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

Details

[edit]
  • $editPage: the currentEditPage object.
  • $output: theOutputPage object (added in version 1.20.0).

Notes

[edit]

You can do something like:

if($editPage->formtype=='preview'){// performing a preview.}

to only take action on certain types of edits.

Inject HTML

[edit]

There are many locations withinEditPage::showEditForm:initial that allow a user to inject HTML. These hook locations are represented by member variables of theEditPage object. (Note that it is not clear how you are able to inject text using this hook prior to MW 1.9!)

$editPage->editFormPageTop                 // MW >= 1.9$editPage->editFormTextTop                 // MW >= 1.9$editPage->editFormTextBeforeContent       // MW >= 1.12$editPage->editFormTextAfterWarn           // MW >= 1.9$editPage->editFormTextAfterTools          // MW >= 1.9$editPage->editFormTextBottom              // MW >= 1.9

To inject your HTML, append your HTML to one of the aforementioned member variables, e.g.

$editPage->editFormPageTop .= "<span>Hello World!</span>";

Some hook locations are inside forms; some not. Those inside the form allow you to inject HTML form elements.

  • Inside form
    • editFormTextBeforeContent
    • editFormTextAfterWarn
    • editFormTextAfterTools
    • editFormTextBottom
  • Outside form
    • editFormPageTop
    • editFormTextTop

Normally, we useEditPage::showEditForm:fieldsfor form elements, but there may be some circumstances for which it is necessary to use the aforementioned hook locations.

Readonly

[edit]

In readonly mode, there is a similarEditPage::showReadOnlyForm:initial-hook

Retrieved from "https://www.mediawiki.org/w/index.php?title=Manual:Hooks/EditPage::showEditForm:initial&oldid=6852434"
Categories:

[8]ページ先頭

©2009-2025 Movatter.jp