saper has uploaded a new change for review.
https://gerrit.wikimedia.org/r/249565
Change subject: Expose links to prefernces sections
......................................................................
Expose links to prefernces sections
Convert legends of various preferences
sections to clickable links, thus
exposing element IDs for linking.
This is very helpful in pointing other
users down to the very preference they
need.
Bug: T78232
Change-Id: I3fb33070255e3697883af460f3457ad1957d61e1
---
M includes/Preferences.php
M includes/Xml.php
M includes/htmlform/HTMLForm.php
3 files changed, 21 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/65/249565/1
diff --git a/includes/Preferences.php b/includes/Preferences.php
index 0f8dcc3..1a49028 100644
--- a/includes/Preferences.php
+++ b/includes/Preferences.php
@@ -1641,7 +1641,8 @@
* @return string
*/
function getBody() {
- return $this->displaySection( $this->mFieldTree, '',
'mw-prefsection-' );
+ $subsectionHasVisibleFields = false;
+ return $this->displaySection( $this->mFieldTree, '',
'mw-prefsection-', $subsectionHasVisibleFields, true );
}
/**
diff --git a/includes/Xml.php b/includes/Xml.php
index 11f14db..e6d1b19 100644
--- a/includes/Xml.php
+++ b/includes/Xml.php
@@ -572,14 +572,25 @@
* @param string $content Pre-escaped content for the fieldset. If
false,
* only open fieldset is returned.
* @param array $attribs Any attributes to fieldset-element.
+ * @param bool $linkLegend True if the legend tag should link to the
fieldset id
*
* @return string
*/
- public static function fieldset( $legend = false, $content = false,
$attribs = array() ) {
+ public static function fieldset( $legend = false, $content = false,
$attribs = array(), $linkLegend = false ) {
$s = Xml::openElement( 'fieldset', $attribs ) . "\n";
if ( $legend ) {
- $s .= Xml::element( 'legend', null, $legend ) . "\n";
+ if ( $linkLegend && $attribs[ 'id' ] ) {
+ $legend = Xml::element( 'a',
+ array( 'href' => '#' . $attribs[ 'id'
], 'class' => 'mw-legend-link' ),
+ $legend
+ );
+ $s .= Xml::tags( 'legend', null, $legend );
+ } else {
+ $s .= Xml::element( 'legend', null, $legend );
+ }
+
+ $s .= "\n";
}
if ( $content !== false ) {
diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php
index e51620f..a963317 100644
--- a/includes/htmlform/HTMLForm.php
+++ b/includes/htmlform/HTMLForm.php
@@ -1369,13 +1369,15 @@
* @param string $fieldsetIDPrefix ID prefix for the "<fieldset>" tag of
* each subsection, ignored if empty.
* @param bool &$hasUserVisibleFields Whether the section had
user-visible fields.
+ * @param bool $linkLegend Whether section legends should be linked to
the form element IDs
*
* @return string
*/
public function displaySection( $fields,
$sectionName = '',
$fieldsetIDPrefix = '',
- &$hasUserVisibleFields = false ) {
+ &$hasUserVisibleFields = false,
+ $linkLegend = false ) {
$displayFormat = $this->getDisplayFormat();
$html = array();
@@ -1408,7 +1410,8 @@
$this->displaySection( $value,
"mw-htmlform-$key",
"$fieldsetIDPrefix$key-",
- $subsectionHasVisibleFields );
+ $subsectionHasVisibleFields,
+ $linkLegend );
$legend = null;
if ( $subsectionHasVisibleFields === true ) {
@@ -1425,7 +1428,7 @@
if ( $fieldsetIDPrefix ) {
$attributes['id'] =
Sanitizer::escapeId( "$fieldsetIDPrefix$key" );
}
- $subsectionHtml .= Xml::fieldset(
$legend, $section, $attributes ) . "\n";
+ $subsectionHtml .= Xml::fieldset(
$legend, $section, $attributes, $linkLegend ) . "\n";
} else {
// Just return the inputs, nothing
fancy.
$subsectionHtml .= $section;
--
To view, visit https://gerrit.wikimedia.org/r/249565
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3fb33070255e3697883af460f3457ad1957d61e1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: saper <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits