Extension talk:Link Attributes

Latest comment: 1 year ago by UlyssesZhan in topic Cannot have formatting in link text

It seems that there is a problem with the source code

Line

# $attribsText = Html::expandAttributes( array( 'class' => 'external '.$linktype ) );

should not start from sharp sign # — Preceding unsigned comment added by 208.247.73.130 (talkcontribs)

Invalid signature

edit

After taking the above advice (uncommenting the # line in linkattr_ExternalLink), then I reversed the change I made to the 'includes/Linker.php' page. It then gave an error that there was an invalid signature in linkattr_ExternalLink. To fix it, I removed $this, and changed &$linktype to $linktype. That fixed the errors for me.

Is patch necessary?

edit

Hi, I would like this extension very much, but I hate it when you have to do a patch in a file that requires extra administration for new installations of a wiki or upgrades.

Is the patch really necessary?

Hi 84.105.220.61,
I hadn't any time to look at the new registration system of MW1.25, but it is on my agenda.
I can verify that it works without any problems for MW1.24.X as you also can see at Wikiapiary.
If you have a MW1.25 installation and if it doesn't work out of the box, simply ping me (best is with logs or error messages) and I will have a look why it doesn't work and how to fix it.
Regards,
Dennisroczek (talk) 12:55, 30 July 2015 (UTC)Reply

Notice after purge

edit

Hello all,

there is a little issue after use of purge --all maintaining on server. Mediawiki 1.26 printed fllowing:

Notice: Undefined index: rel in /var/www/html/mediawiki/test/extensions/Link_Attributes/Link_Attributes.php on line 60

Notice: Undefined index: class in /var/www/html/mediawiki/test/extensions/Link_Attributes/Link_Attributes.php on line 58

For patching i must change the linkattr_ModifyLink to

 elseif (substr($r, 0, 1) == '.'){
			   if(isset($attribs['class'])){
				   $attribs['class'] .= ' ' . substr($r, 1);
			   }else{
				   $attribs['class'] = ' ' . substr($r, 1);
			   }
		   } else {
			   if(isset($attribs['rel'])){
				  $attribs['rel'] .= ' ' . $r;
			   }else
			   {
				    $attribs['rel'] = ' ' . $r;
			   }
		   }

Can you check the patch and add it to source?

Best Regards

--Sundance Raphael (talk) 12:13, 12 April 2016 (UTC)Reply

edit

wfLoadExtension( 'Link Attributes' ); --> wfLoadExtension( 'Link_Attributes' );

missing _ underscore character in installation notes

— Preceding unsigned comment added by 2601:586:581:4c80:7c36:d570:40c5:9063 (talkcontribs) 06:51, 16 November 2020‎

Thanks, I've updated the page. —Sam Wilson 01:49, 16 November 2020 (UTC)Reply

Possible to add more attributes? (feature request)

edit

Hi there, thank you for your effort with the extension! In order to integrate bootstrap functionality I would love to see the option to add more attributes.

  • data-toggle
  • role
  • aria-expanded
  • aria-controls

Maybe it is possible to use your syntax with additional special characters?

Thank you very much in advance!

Add: actually I looked into the code and it wasn't too difficult to do myself. Maybe you want to integrate it into yours. The special characters were chosen at absolute random. Works like a charm with bootstrap framework!

  • data-toggle = '+'
  • role = '%'
  • aria-expanded = '#'
  • aria-controls = '$'
if ( ( substr( $r, 0, 2 ) == '-~' || substr( $r, 0, 2 ) == '~-' ) && isset( $attribs[ 'rev' ] ) ) {
					$attribs[ 'rev' ] = str_ireplace( substr( $r, 2 ), '', $attribs[ 'rev' ] );
				} elseif ( ( substr( $r, 0, 2 ) == '-.' || substr( $r, 0, 2 ) == '.-' ) && isset( $attribs[ 'class' ] ) ) {
					$attribs[ 'class' ] = str_ireplace( substr( $r, 2 ), '', $attribs[ 'class' ] );
				} elseif ( ( substr( $r, 0, 2 ) == '-+' || substr( $r, 0, 2 ) == '+-' ) && isset( $attribs[ 'data-toggle' ] ) ) {
					$attribs[ 'data-toggle' ] = str_ireplace( substr( $r, 2 ), '', $attribs[ 'data-toggle' ] );
				} elseif ( ( substr( $r, 0, 2 ) == '-%' || substr( $r, 0, 2 ) == '%-' ) && isset( $attribs[ 'role' ] ) ) {
					$attribs[ 'role' ] = str_ireplace( substr( $r, 2 ), '', $attribs[ 'role' ] );
				} elseif ( ( substr( $r, 0, 2 ) == '-#' || substr( $r, 0, 2 ) == '#-' ) && isset( $attribs[ 'aria-expanded' ] ) ) {
					$attribs[ 'aria-expanded' ] = str_ireplace( substr( $r, 2 ), '', $attribs[ 'aria-expanded' ] );
				} elseif ( ( substr( $r, 0, 2 ) == '-$' || substr( $r, 0, 2 ) == '$-' ) && isset( $attribs[ 'aria-controls' ] ) ) {
					$attribs[ 'aria-controls' ] = str_ireplace( substr( $r, 2 ), '', $attribs[ 'aria-controls' ] );
				} elseif ( ( substr( $r, 0, 1 ) == '-' ) && isset( $attribs[ 'rel' ] ) ) {
					$attribs[ 'rel' ] = str_ireplace( substr( $r, 1 ), '', $attribs[ 'rel' ] );
				} elseif ( substr( $r, 0, 1 ) == '~' ) {
					$attribs[ 'rev' ] .= ' ' . substr( $r, 1 );
				} elseif ( substr( $r, 0, 1 ) == '.' ) {
					$attribs[ 'class' ] .= ' ' . substr( $r, 1 );
				} elseif ( substr( $r, 0, 1 ) == '+' ) {
					$attribs[ 'data-toggle' ] .= ' ' . substr( $r, 1 );
				} elseif ( substr( $r, 0, 1 ) == '%' ) {
					$attribs[ 'role' ] .= ' ' . substr( $r, 1 );
				} elseif ( substr( $r, 0, 1 ) == '#' ) {
					$attribs[ 'aria-expanded' ] .= ' ' . substr( $r, 1 );
				} elseif ( substr( $r, 0, 1 ) == '$' ) {
					$attribs[ 'aria-controls' ] .= ' ' . substr( $r, 1 );
				} else {
					$attribs[ 'rel' ] .= ' ' . $r;
				}
			}

			if ( isset( $attribs[ 'rel' ] ) ) {
				$attribs[ 'rel' ] = trim( preg_replace( '/\s+/', ' ', $attribs[ 'rel' ] ) );
			}
			if ( isset( $attribs[ 'rev' ] ) ) {
				$attribs[ 'rev' ] = trim( preg_replace( '/\s+/', ' ', $attribs[ 'rev' ] ) );
			}
			if ( isset( $attribs[ 'class' ] ) ) {
				$attribs[ 'class' ] = trim( preg_replace( '/\s+/', ' ', $attribs[ 'class' ] ) );
			}
			if ( isset( $attribs[ 'data-toggle' ] ) ) {
				$attribs[ 'data-toggle' ] = trim( preg_replace( '/\s+/', ' ', $attribs[ 'data-toggle' ] ) );
			}
			if ( isset( $attribs[ 'role' ] ) ) {
				$attribs[ 'role' ] = trim( preg_replace( '/\s+/', ' ', $attribs[ 'role' ] ) );
			}
			if ( isset( $attribs[ 'aria-expanded' ] ) ) {
				$attribs[ 'aria-expanded' ] = trim( preg_replace( '/\s+/', ' ', $attribs[ 'aria-expanded' ] ) );
			}
			if ( isset( $attribs[ 'aria-controls' ] ) ) {
				$attribs[ 'aria-controls' ] = trim( preg_replace( '/\s+/', ' ', $attribs[ 'aria-controls' ] ) );
			}

Chaeidras (talk) 22:32, 22 March 2022 (UTC)Reply

edit

When this extension is loaded, [some_external_link <s>Test</s>] will be rendered as if [some_external_link <nowiki><s>Test</s></nowiki>]. Is this a bug? UlyssesZhan (talk) 19:10, 17 October 2023 (UTC)Reply

Return to "Link Attributes" page.