Extension talk:EnableAbbrTags

Latest comment: 15 years ago by Jeffmcneill in topic Why is ABBR prohibited anyway?

Why is ABBR prohibited anyway?

edit

Does anyone know what the issue is with just allowing abbr tags?

  • Only a subset of HTML is allowed in MediaWiki. If more is needed there are extensions and settings to enable full HTML (but with security issues) or parsers/custom tags must be used (like this one). --Jeffmcneill 08:51, 17 July 2009 (UTC)Reply

More attributes allowed

edit

I've updated this extension to allow style, lang, etc. attributes, and simplified the code a bit.

<?php
/**
 * EnableAbbrTags.php
 * This extension enables <abbr></abbr> tags.
 * 
 * CHANGELOG:  
 * v.0.2 added return codes to run under 1.11
 * v.0.3 include all attributes: 'id', 'class', 'lang', 'dir', 'title', 'style'.
 * 
 * AUTHORS: 
 * Written by Jeff McNeill http://jeffmcneill.com/ building on the work of 
 * AllowAnchorTags http://www.mediawiki.org/wiki/Extension:AllowAnchorTags
 * Modified 2009-07-17 by Sam Wilson http://samwilson.id.au/ to include other 
 * attributes.
 *  
 * To activate the functionality of this extension include the following in 
 * LocalSettings.php file:
 * 
 *     require_once('extensions/EnableAbbrTags.php');
 *      
 */
 
#Defines the main function to be executed for this extension.
$wgExtensionFunctions[] = 'EnableAbbrTag';
 
# Sets the hook to be executed once the parser has stripped HTML tags.
$wgHooks['ParserAfterStrip'][] = 'EnableAbbrTag';
 
# This function initiates the hook for the parser to convert <xabbr></xabbr>
# tags to <abbr></abbr> tags.
function EnableAbbrTag() {
    // Declaring the global parser..
    global $wgParser;
 
    // Setting the hook to parse <xabbr></xabbr> tags from the parser output..
    $wgParser->setHook( 'xabbr', 'startEnableAbbr' );
    return(true);
}
 
# This function extracts the parameters from the <xabbr></xabbr> tags and
# the text between the <xabbr> and </xabbr> tags and formats them as "<abbr></abbr>"
# tags and writes them in the document.

function startEnableAbbr( $input, $argv ) {

    // See http://www.w3.org/TR/html401/struct/text.html#edef-ABBR
    $allowedAttributes = array('id', 'class', 'lang', 'dir', 'title', 'style');

    // Build the {attribute='value' ...} string:
    $attrs = "";
    foreach ($allowedAttributes as $attr) {
        if(isset($argv[$attr])) {
            $attrs .= " $attr=\"".$argv[$attr]."\"";
        } else {
            $attrs .= '';
        }
    }
    
    return "<abbr$attrs>$input</abbr>";
     
}

abbr in Templates

edit

This extension (as the version above) don't work with abbr used in templates.

For example a template {{Abbr|One|Two}} witch contain

<xabbr title="{{{1}}}">{{{2}}}</xabbr>

will outpout

<abbr title="{{{1}}}">{{{2}}}</abbr>

and not (as espected)

<abbr title="One">Two</abbr>

I've tried to change hook name to proceed the substitution after parsing template parameters but it as no effect. Someone can fix that ? ⇨ Dr Brains ∞ Doléances ∞ 02:29, 24 November 2010 (UTC)

OK, I've found a far better method :
In /includes/Sanitizer.php, class Sanitizer, function removeHTMLtags(), just add 'abbr' to $htmlpairs Array :
 			$htmlpairs = array_merge( $extratags, array( # Tags that must be closed

-                               'b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1',

+                               'abbr', 'b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1',

				'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's',
				'strike', 'strong', 'tt', 'var', 'div', 'center',
				'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre',
				'ruby', 'rt' , 'rb' , 'rp', 'p', 'span', 'u'
			) );

⇨ Dr Brains ∞ Doléances ∞ 02:50, 24 November 2010 (UTC)

Return to "EnableAbbrTags" page.