From 078dbb8e566691463276fc34c47cdb1fe676200b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Sat, 25 Mar 2017 21:41:03 +0100 Subject: [PATCH] EditPage: Refactor getCheckboxes() to allow changing the format getCheckboxes() directly generated the HTML for the "This is a minor edit" and "Watch this page" checkboxes, and allowed extensions to add more HTML checkboxes (and modify existing ones) using the 'EditPageBeforeEditChecks' hook. This prevents us from ever changing the format of the HTML (e.g. to use OOUI checkboxes). Introduce new method getCheckboxesDefinition(), which generates the checkboxes in a machine-readable format, with a new hook 'EditPageGetCheckboxesDefinition'. Rewrite getCheckboxes() in terms of that. The old hook 'EditPageBeforeEditChecks' is now deprecated. Change-Id: I3dbe973dcac6cba0c3a1ac5d983cafcfb49d833c --- RELEASE-NOTES-1.29 | 4 ++ docs/hooks.txt | 14 ++++- includes/EditPage.php | 124 ++++++++++++++++++++++++++++-------------- 3 files changed, 99 insertions(+), 43 deletions(-) diff --git a/RELEASE-NOTES-1.29 b/RELEASE-NOTES-1.29 index ab7537528e..793769ff1c 100644 --- a/RELEASE-NOTES-1.29 +++ b/RELEASE-NOTES-1.29 @@ -272,6 +272,10 @@ changes to languages because of Phabricator reports. * Article::getLastPurgeTimestamp(), WikiPage::getLastPurgeTimestamp(), and the WikiPage::PURGE_* constants are deprecated, and the functions will always return false. They were a hack for an issue that has since been fixed. +* Hook 'EditPageBeforeEditChecks' is now deprecated. Instead use the new hook + 'EditPageGetCheckboxesDefinition', or 'EditPage::showStandardInputs:options' + if you don't actually care about checkboxes and just want to add some HTML + to the page. == Compatibility == diff --git a/docs/hooks.txt b/docs/hooks.txt index 3a57563f33..a38f9bb526 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1404,10 +1404,12 @@ textarea in the edit form. &$buttons: Array of edit buttons "Save", "Preview", "Live", and "Diff" &$tabindex: HTML tabindex of the last edit check/button -'EditPageBeforeEditChecks': Allows modifying the edit checks below the textarea -in the edit form. +'EditPageBeforeEditChecks': DEPRECATED! Use 'EditPageGetCheckboxesDefinition' instead, +or 'EditPage::showStandardInputs:options' if you don't actually care about checkboxes +and just want to add some HTML to the page. +Allows modifying the edit checks below the textarea in the edit form. &$editpage: The current EditPage object -&$checks: Array of edit checks like "watch this page"/"minor edit" +&$checks: Array of the HTML for edit checks like "watch this page"/"minor edit" &$tabindex: HTML tabindex of the last edit check/button 'EditPageBeforeEditToolbar': Allows modifying the edit toolbar above the @@ -1420,6 +1422,12 @@ $title: title of page being edited &$msg: localization message name, overridable. Default is either 'copyrightwarning' or 'copyrightwarning2'. +'EditPageGetCheckboxesDefinition': Allows modifying the edit checkboxes +below the textarea in the edit form. +$editpage: The current EditPage object +&$checkboxes: Array of checkbox definitions. See EditPage::getCheckboxesDefinition() +for the format. + 'EditPageGetDiffContent': Allow modifying the wikitext that will be used in "Show changes". Note that it is preferable to implement diff handling for different data types using the ContentHandler facility. diff --git a/includes/EditPage.php b/includes/EditPage.php index ac62e3fc70..7d19e94ad7 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -4005,70 +4005,114 @@ HTML return $toolbar; } + /** + * Return an array of checkbox definitions. + * + * Array keys correspond to the `` 'name' attribute to use for each checkbox. + * + * Array values are associative arrays with the following keys: + * - 'label-message' (required): message for label text + * - 'id' (required): 'id' attribute for the `` + * - 'default' (required): default checkedness (true or false) + * - 'title-message' (optional): used to generate 'title' attribute for the `