From 31587c50fe43f18e6379bf2d1b0376be0715fb4a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 28 Aug 2017 19:47:01 +0200 Subject: [PATCH] EditPage: Deprecate getCheckboxes() and getCheckboxesOOUI() Follow-up to 478caa076f75fde935c66eb9334410d868c30818, which asked for someone else to disentangle that. After this patch, we're left with separate blocks of code that can just be deleted when we remove the EditPageBeforeEditChecks hook or the getCheckboxes() function. Change-Id: I88d2dda3a6e030f73e209e0d389d4c0aa6c45139 --- RELEASE-NOTES-1.30 | 2 ++ includes/EditPage.php | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/RELEASE-NOTES-1.30 b/RELEASE-NOTES-1.30 index 10759995fc..166895b664 100644 --- a/RELEASE-NOTES-1.30 +++ b/RELEASE-NOTES-1.30 @@ -185,6 +185,8 @@ changes to languages because of Phabricator reports. * EditPage::isOouiEnabled() is deprecated and will always return true. * EditPage::getSummaryInput() and ::getSummaryInputOOUI() are deprecated. Please use ::getSummaryInputWidget() instead. +* EditPage::getCheckboxes() and ::getCheckboxesOOUI() are deprecated. Please + use ::getCheckboxesWidget() instead. * Parser::getRandomString() (deprecated in 1.26) was removed. * Parser::uniqPrefix() (deprecated in 1.26) was removed. * Parser::extractTagsAndParams() now only accepts three arguments. The fourth, diff --git a/includes/EditPage.php b/includes/EditPage.php index 48e694c5c7..82bc3de41f 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -3594,7 +3594,7 @@ class EditPage { $wgOut->addHTML( $this->getSummaryPreview( false, $this->summary ) ); } - $checkboxes = $this->getCheckboxesOOUI( + $checkboxes = $this->getCheckboxesWidget( $tabindex, [ 'minor' => $this->minoredit, 'watch' => $this->watchthis ] ); @@ -4178,6 +4178,7 @@ class EditPage { * Returns an array of html code of the following checkboxes old style: * minor and watch * + * @deprecated since 1.30 Use getCheckboxesWidget() or getCheckboxesDefinition() instead * @param int &$tabindex Current tabindex * @param array $checked See getCheckboxesDefinition() * @return array @@ -4233,21 +4234,34 @@ class EditPage { } /** - * Returns an array of html code of the following checkboxes: - * minor and watch + * Returns an array of checkboxes for the edit form, including 'minor' and 'watch' checkboxes and + * any other added by extensions. * + * @deprecated since 1.30 Use getCheckboxesWidget() or getCheckboxesDefinition() instead * @param int &$tabindex Current tabindex * @param array $checked Array of checkbox => bool, where bool indicates the checked * status of the checkbox * - * @return array + * @return array Associative array of string keys to OOUI\FieldLayout instances */ public function getCheckboxesOOUI( &$tabindex, $checked ) { + return $this->getCheckboxesWidget( $tabindex, $checked ); + } + + /** + * Returns an array of checkboxes for the edit form, including 'minor' and 'watch' checkboxes and + * any other added by extensions. + * + * @param int &$tabindex Current tabindex + * @param array $checked Array of checkbox => bool, where bool indicates the checked + * status of the checkbox + * + * @return array Associative array of string keys to OOUI\FieldLayout instances + */ + public function getCheckboxesWidget( &$tabindex, $checked ) { $checkboxes = []; $checkboxesDef = $this->getCheckboxesDefinition( $checked ); - $origTabindex = $tabindex; - foreach ( $checkboxesDef as $name => $options ) { $legacyName = isset( $options['legacy-name'] ) ? $options['legacy-name'] : $name; @@ -4286,7 +4300,19 @@ class EditPage { // Backwards-compatibility hack to run the EditPageBeforeEditChecks hook. It's important, // people have used it for the weirdest things completely unrelated to checkboxes... // And if we're gonna run it, might as well allow its legacy checkboxes to be shown. - $legacyCheckboxes = $this->getCheckboxes( $origTabindex, $checked ); + $legacyCheckboxes = []; + if ( !$this->isNew ) { + $legacyCheckboxes['minor'] = ''; + } + $legacyCheckboxes['watch'] = ''; + // Copy new-style checkboxes into an old-style structure + foreach ( $checkboxes as $name => $oouiLayout ) { + $legacyCheckboxes[$name] = (string)$oouiLayout; + } + // Avoid PHP 7.1 warning of passing $this by reference + $ep = $this; + Hooks::run( 'EditPageBeforeEditChecks', [ &$ep, &$legacyCheckboxes, &$tabindex ], '1.29' ); + // Copy back any additional old-style checkboxes into the new-style structure foreach ( $legacyCheckboxes as $name => $html ) { if ( $html && !isset( $checkboxes[$name] ) ) { $checkboxes[$name] = new OOUI\Widget( [ 'content' => new OOUI\HtmlSnippet( $html ) ] ); -- 2.20.1