From: Albert221 Date: Wed, 3 Jan 2018 14:33:58 +0000 (+0100) Subject: Add text to tab links telling if they do exist X-Git-Tag: 1.31.0-rc.0~968^2 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=a9cbe0c847f2a1a15e96768419ddbb481ce08698;p=lhc%2Fweb%2Fwiklou.git Add text to tab links telling if they do exist And changed a little bit signature of Linker::titleAttrib and Linker::tooltipAndAcceskeyAttribs. Added $options parameter to the second one and made $options parameter satisfied by passing an array with options, because there is one more now: 'nonexisting' which tells to add text about the thing that the page does not exist to its tooltip. Bug: T19099 Change-Id: Ia76dd6db363f6add5efb8955be9e23a1f8e8476f --- diff --git a/includes/Linker.php b/includes/Linker.php index c0255ac205..3b0e72d96b 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1968,8 +1968,9 @@ class Linker { * * @since 1.16.3 $msgParams added in 1.27 * @param string $name Id of the element, minus prefixes. - * @param string|null $options Null or the string 'withaccess' to add an access- - * key hint + * @param string|array|null $options Null, string or array with some of the following options: + * - 'withaccess' to add an access-key hint + * - 'nonexisting' to add an accessibility hint that page does not exist * @param array $msgParams Parameters to pass to the message * * @return string Contents of the title attribute (which you must HTML- @@ -1989,7 +1990,12 @@ class Linker { } } - if ( $options == 'withaccess' ) { + $options = (array)$options; + + if ( in_array( 'nonexisting', $options ) ) { + $tooltip = wfMessage( 'red-link-title', $tooltip ?: '' )->text(); + } + if ( in_array( 'withaccess', $options ) ) { $accesskey = self::accesskey( $name ); if ( $accesskey !== false ) { // Should be build the same as in jquery.accessKeyLabel.js @@ -2130,12 +2136,22 @@ class Linker { * @since 1.16.3. $msgParams introduced in 1.27 * @param string $name * @param array $msgParams Params for constructing the message + * @param string|array|null $options Options to be passed to titleAttrib. + * + * @see Linker::titleAttrib for what options could be passed to $options. * * @return array */ - public static function tooltipAndAccesskeyAttribs( $name, array $msgParams = [] ) { + public static function tooltipAndAccesskeyAttribs( + $name, + array $msgParams = [], + $options = null + ) { + $options = (array)$options; + $options[] = 'withaccess'; + $attribs = [ - 'title' => self::titleAttrib( $name, 'withaccess', $msgParams ), + 'title' => self::titleAttrib( $name, $options, $msgParams ), 'accesskey' => self::accesskey( $name ) ]; if ( $attribs['title'] === false ) { diff --git a/includes/skins/BaseTemplate.php b/includes/skins/BaseTemplate.php index f0b336a31a..bb1d8d0b9d 100644 --- a/includes/skins/BaseTemplate.php +++ b/includes/skins/BaseTemplate.php @@ -143,7 +143,7 @@ abstract class BaseTemplate extends QuickTemplate { if ( isset( $plink['active'] ) ) { $ptool['active'] = $plink['active']; } - foreach ( [ 'href', 'class', 'text', 'dir', 'data' ] as $k ) { + foreach ( [ 'href', 'class', 'text', 'dir', 'data', 'exists' ] as $k ) { if ( isset( $plink[$k] ) ) { $ptool['links'][0][$k] = $plink[$k]; } @@ -391,7 +391,7 @@ abstract class BaseTemplate extends QuickTemplate { if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) { $attrs = $item; foreach ( [ 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary', - 'tooltip-params' ] as $k ) { + 'tooltip-params', 'exists' ] as $k ) { unset( $attrs[$k] ); } @@ -412,13 +412,19 @@ abstract class BaseTemplate extends QuickTemplate { } if ( isset( $item['single-id'] ) ) { + $tooltipOption = isset( $item['exists'] ) && $item['exists'] === false ? 'nonexisting' : null; + if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) { - $title = Linker::titleAttrib( $item['single-id'], null, $tooltipParams ); + $title = Linker::titleAttrib( $item['single-id'], $tooltipOption, $tooltipParams ); if ( $title !== false ) { $attrs['title'] = $title; } } else { - $tip = Linker::tooltipAndAccesskeyAttribs( $item['single-id'], $tooltipParams ); + $tip = Linker::tooltipAndAccesskeyAttribs( + $item['single-id'], + $tooltipParams, + $tooltipOption + ); if ( isset( $tip['title'] ) && $tip['title'] !== false ) { $attrs['title'] = $tip['title']; } diff --git a/includes/skins/SkinTemplate.php b/includes/skins/SkinTemplate.php index badd7a2ead..8b698e8f76 100644 --- a/includes/skins/SkinTemplate.php +++ b/includes/skins/SkinTemplate.php @@ -642,6 +642,7 @@ class SkinTemplate extends Skin { 'text' => $this->username, 'href' => &$this->userpageUrlDetails['href'], 'class' => $this->userpageUrlDetails['exists'] ? false : 'new', + 'exists' => $this->userpageUrlDetails['exists'], 'active' => ( $this->userpageUrlDetails['href'] == $pageurl ), 'dir' => 'auto' ]; @@ -650,6 +651,7 @@ class SkinTemplate extends Skin { 'text' => $this->msg( 'mytalk' )->text(), 'href' => &$usertalkUrlDetails['href'], 'class' => $usertalkUrlDetails['exists'] ? false : 'new', + 'exists' => $usertalkUrlDetails['exists'], 'active' => ( $usertalkUrlDetails['href'] == $pageurl ) ]; $href = self::makeSpecialUrl( 'Preferences' ); @@ -782,8 +784,10 @@ class SkinTemplate extends Skin { if ( $selected ) { $classes[] = 'selected'; } + $exists = true; if ( $checkEdit && !$title->isKnown() ) { $classes[] = 'new'; + $exists = false; if ( $query !== '' ) { $query = 'action=edit&redlink=1&' . $query; } else { @@ -821,6 +825,7 @@ class SkinTemplate extends Skin { 'class' => implode( ' ', $classes ), 'text' => $text, 'href' => $title->getLocalURL( $query ), + 'exists' => $exists, 'primary' => true ]; if ( $linkClass !== '' ) { $result['link-class'] = $linkClass;