Add text to tab links telling if they do exist
authorAlbert221 <w.albert221@gmail.com>
Wed, 3 Jan 2018 14:33:58 +0000 (15:33 +0100)
committerMvolz <mvolz@wikimedia.org>
Mon, 8 Jan 2018 16:42:01 +0000 (16:42 +0000)
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

includes/Linker.php
includes/skins/BaseTemplate.php
includes/skins/SkinTemplate.php

index c0255ac..3b0e72d 100644 (file)
@@ -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 ) {
index f0b336a..bb1d8d0 100644 (file)
@@ -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'];
                                        }
index badd7a2..8b698e8 100644 (file)
@@ -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;