Extension:AltTag

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
AltTag

Release status: experimental

Implementation Extended syntax, Tag
Description Convert alternate tags with their attributes to tags that used by MediaWiki
Author(s) Ahmad Alshaikh (أحمد ش الشيخtalk)
Last version 0.2
MediaWiki Tested on MW 1.16
PHP PHP4+
License GPLv3
Download See Below
Hooks used
ParserBeforeStrip
Check usage and version matrix; stats

The AltTag extension makes it possible to create user-defined XML-style tags in any language aliasing other tags. For example this arabic tag <مرجع اسم="test"> will alias <ref name="test">.

Why is it needed?
Use of LTR tags in RTL text wrecks havoc. It's very hard to place, and even harder to verify and fix.

For example, look at this:

<ref name=الاسم group=الفئة> هنا محتوى <big> كبير <code>  محتوى شيفرة</code> كبير </big> </ref>

This code is 100% correct, but writing RTL with LTR makes it messy. With this extension you can do that like this:

<مرجع اسم=الاسم فئة=الفئة> هنا محتوى <كبير> كبير <شيفرة> محتوى شيفرة </شيفرة> كبير </كبير> </مرجع>

This is the main advantage, but there are other benefits as well.

Contents

Features[edit]

  1. This extension processes all tags and their attributes. It will also support the tags the content of which do not change, such as pre and nowiki.
  2. Processing of all of these tags and their attributes is done before the parse stage. This minimizes mistakes and risk.
  3. It's possible to combine aliased and non-aliased tags, e.g. open tag with alias and close with unaliased name, and vice versa, or open with one alias and close with another.
  4. It's possible to define several aliases for the same tag.

Usage[edit]

After installing the extension, the alternate tag and alternate attributes are used the same way the original tag and attribute would be used.

Notes[edit]

  1. AltTag will work with any language, not just with RTL languages.
  2. It's possible to alternate tag to close real tag, and vice versa - except nowikis tags.
  3. AltTag does not add any new tags, it just allows new aliases for existing tags.

Download Instructions[edit]

Please cut and paste the code found below and place it in $IP/extensions/AltTag/AltTag.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Installation[edit]

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/AltTag/AltTag.php");

Configuration[edit]

To use AltTag you should define some information. You will find it in AltTag.php file under this line // ----- User Variables ---------.

Note: next examples is in Arabic.

Alternate Tags[edit]

You will find it under this line // ----- Tags --------------- , It's an Array Its key is the Alternate Tag and the value is the real tag.
Example :

$AT_a_Tag = array (
        'كبير'      => 'big' ,
        'صغير'      => 'small' ,
        'مرجع'      => 'ref',
        'سطر'        => 'br'
        );

Note: You can use mere than one alternate for one tag.

Nowikis Tags[edit]

It's any tag you want to keep alternates into it without any change, such as nowiki and pre or any tag you want.

You will find this under // ----- NoWikis ------------. It's an Array and its key is the Alternate Tag and the value is the real tag.

Example :

$AT_a_NoWikis = array (
        'لاويكي'     => 'nowiki',
        'مهيأ'      => 'pre' ,
        'شيفرة'     => 'code' ,
        'كود'       => 'code' ,
        'مصدر'      => 'source'
        );

Note : You can use more than one alternate for one real tag.

Alternates Attributes[edit]

You will find this under // ----- Attributes --------. It's an Array and its key is the Alternate attribute and the value is the real attribute.

Example :

$AT_a_Attr = array (
        'اسم'   => 'name',
        'فئة'   => 'group'
        );

Note: You can use mere than one alternate for one attribute.

Extra Letters[edit]

If you using any non-English letters like Arabic, Chinese, Russian etc, you must insert it here. You will find it under // ----- Extra Letters ------
.Example :

$AT_s_ExtraChar = 'ذضصثقفغعهخحجدشسيبلاتنمكطئءؤرىةوزظإأآ' ;

Warning : should not put anything other than Letters - no dots, no spaces, no signs, or anything else.

Code[edit]

<?php
if ( ! defined( 'MEDIAWIKI' ) )
        die();
/**
 * AltTag Extension
 * A parser extension that replace alternative XML Tag to english Tags.
 * The Purpose of use is using alternatives for any XML(HTML) Tags with Its Attributes in WikiMarkup, Using any name and any language.
 *      That makes work very easy for RTL language.becouae working with RTL text with LTR Tags very hard thing.
 *              Look at the Docs to know more!.
 *
 * Author :
 *              Ahmad Alshaikh (أحمد ش الشيخ)
 *              ar.wikipedia.org/wiki/مستخدم:أحمد ش الشيخ
 * Thanks to OsaOsa5 for his help in translating AltTag page in MediaWiki
 *
 * Link : http://www.mediawiki.org/wiki/Extension:AltTag
 */
///////////////////////////////////////////////////////////
// Note : Alt Tag can close the Real tag and the opissite is allowed too.
///////////////////////////////////////////////////////////
// ----- Variables ------------------
        // ----- User Variables ---------
        ##################################################################################################
        ##### Below Variables Must Contain ONLY A-Z a-z 0-9 _  and any letter of any language.
        ##### DO NOT add any spaces or dots or any thing else .
        ##### Make sure that Arrays Keys and values Like This 'Something' NOT ' Something' or 'Some Thing' 
        ##################################################################################################
                // ----- Tags ---------------
                        // This array should contain the alternatives of Tags names.
                        /*      The array must be like this:
                                $AT_a_Tag = array (
                                        'AltOfTag'   => 'Tag',
                                        'AltOfTag2' => 'Tag2'
                                        );
                        */
                        $AT_a_Tag = array (
                                'AltOfTag'   => 'Tag',
                                'AltOfTag2' => 'Tag2'
                                );
                        //Note: multi Alts for one Tag is allowed.
                // ----- Attributes ---------
                        // This array should contain the alternatives of attributes names.
                        /*      The array must be like this:
                                $AT_a_Attr = array (
                                        'AltOfAttr'   => 'Attr',
                                        'AltOfAttr2' => 'Attr2'
                                        );
                        */
                        $AT_a_Attr = array (
                                'AltOfAttr'   => 'Attr',
                                'AltOfAttr2' => 'Attr2'
                                );
                        //Note: multi Alts for one Attr is allowed.
                // ----- NoWikis ------------
                        // This array should contain the alternatives of Tags that its contains should be untouched.
                        /*      The array must be like this:
                                $AT_a_NoWikis = array (
                                        'AltTag'   => 'RealTag' ,
                                        'AltTag'   => 'RealTag' 
                                        );
                                Note : You can add tow Alternatives for one Tag Like This :
                                        'Alt 1'   => 'RealTag' ,
                                        'Alt 2'   => 'RealTag' 
                        */
                        $AT_a_NoWikis = array (
                                'AltTag'   => 'RealTag' ,
                                'AltTag2'   => 'RealTag2' ,
                                'AltTag3'   => 'RealTag3' 
                                );
                        //Note: multi Alts for one Attr is allowed.
                // ----- Extra Characters ---
                        // This string will contain the Letters that is not (a-z A-Z 0-9 _ ), If you use non english letters insert it here.
                        /*      example (Arabic Letters);
                                $AT_s_ExtraChar = 'ذضصثقفغعهخحجدشسيبلاتنمكطئءؤرىةوزظإأآ';
                        */
                        $AT_s_ExtraChar = '' ;
        // ----- Ext Variables ----------
                $AT_s_SqReplac          = '' ;
                $AT_s_DqReplac          = '' ;
                $AT_b_ArrayFixed = false ; // If this var = true , FixArrays function will not work . Fixing process must be done one time.
//array ( 'nowiki' , 'pre' , 'code' , 'source' ) ; //add real nowikis to jump over them.
// ----- Registration Info ----------
        $wgExtensionCredits['parserhook'][] = array(
        'path'                  => __FILE__,
        'name'                  => "AltTag",
        'description'   => "This extension parsing custom alternatives Of XML(HTML) Tags in any language",
        'version'               => '0.2',
        'author'                => "Ahmad Alshaikh - أحمد الشيخ",
        'url'                   => "http://www.mediawiki.org/wiki/Extension:AltTag",
                );
// ----- Registration Hook ----------
        $wgHooks['ParserBeforeStrip'][] = 'AltTag_Process';
// This hook will call 'AltTag_Process' before making any parsing.
 
 
/* ===== Information ================
        # Variable
                1) All global variables in this extension starting with  $AT_
                2) Every variable in this extension starting with its (Type code) :
                        String  : s_ like  $s_RegEx
                        Array   : a_ like  $a_matches
                        Boolean : b_ Like  $b_NowikiOpen
        # Functions
                1) There is just tow functions for external call. (AltTag_ExternalProcess and AltTag_Process)
                2) Every Other function Started with tow underscore _ .
        # Sections
                I split this sctipt to sections according to its work.
                // ---- Section Name ---------------------
        # Known Bugs :
                1) Fixed in 0.2 : It does not jump over the real Nowikis Tags Like : Nowiki and pre
        2) Fixed in 0.2 : It does not match Alternative Tag in the array with Alternative tag in the wikitext in case they are not in the same character case.
*/
 
/** AltTag_Process
 * Process wikitext to replace AltTags with default wikimarkup Tags(Included its attributes).
 *      This function called from parser.php !!
 * This functions must be the first called 'ParserBeforeStrip'. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 * @param $s_text Wikitext that you want to process the AltTags in it.
 * @return boolean true
*/
function AltTag_Process( &$parser , &$s_text , &$stripState ) {
        global $AT_s_ExtraChar ,        $AT_a_NoWikis   , $s_SqReplac , $s_DqReplac ;
 
        __AltTag_FixArrays() ;
 
 
        // -- RegEx for whole tag.
        $s_AllowedRegEx = '[A-Za-z0-9_' . $AT_s_ExtraChar . ']' ; // It's important to match letters,Numbers only.
        /* Used RegEx pattern is   </?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)/?>    by haacked.com */
        $s_allTagPttrn = '#</?' . $s_AllowedRegEx . '+((\s+' . $s_AllowedRegEx . '+(\s*=\s*(?:".*?"|' . "'" . '.*?' . "'" . '|[^' . "'" . '">\s]+))?)+\s*|\s*)/?\>#' ;
        // -- Get all tags in one array.
        $a_allTagsMatches = array();
        if ( !preg_match_all ( $s_allTagPttrn , $s_text , $a_allTagsMatches , PREG_PATTERN_ORDER ) ) {
                return true;
        }
        /* 
        Now, $a_allTagsMatches array is like this:
        array(
                [0] => array included every tag.(from < to >)
                And the others is not important.
                )
        */
        // -- Processing -------------------------
        $a_fixedTags = array(); // look at docs (How to work) to know about it. or look at (Return Fixed Tags) section below
        $s_tmp_TagReplc = __AltTag_GetReplac( $s_text ); // Get temp replacement of Tags places. look at (Return Fixed Tags) section below
        // ------ Nowikis valiables --------------
        $b_NoWikiOpen = false; // If ($b_NoWikiOpen === true) Tags will be untouched (the same).
        #$b_SkipOneTag = false; // If ($b_SkipOneTag === true) Script will ignore one Tag.
        $s_OpenedNoWiki = '' ;  // This variable will containe Opened nowiki Tag name (why? because nowiki must end with same tsg that open it).
 
        // ------ Processing In Loop -------------
        foreach ( $a_allTagsMatches[0] as $s_tag ) {
                // Now, $s_tag is full Tag (e.q <TagName Att1="Value1" Att2=Value2> or </TagName> or <TagName attr=value />)
 
 
                // -------- Processing Nowikis  ------
                //      If the name of tag Is one of nowikis ((( or any of its replacements , $b_NoWikiOpen Will be true.
                //      then If $b_NoWikiOpen==true , Fixed tag will be the same;  untell The END of same first Opened nowiki Tag 
                //            (ForExample : <AltNoWiki>SomeThing <AltNowiki2>SomeThing</AltNowiki2></AltNoWiki>)
                //             Will jump over (SomeThing <AltNowiki2>SomeThing</AltNowiki2>) not Only (SomeThing <AltNowiki2>SomeThing)
                /*
                        Alt Tag will Process every OPEN Nowikis Tags And first close of it only not every Nowikis Tag.
                        Note : Nowikis Tags are every tag its contains wikitext will ignored. Like ( nowiki , pre , source and what you want)
                */
                // ---- Get name of Tag. -------------
                preg_match( '~<\s*?/?(.+?)[\s/>]~' , $s_tag , $a_TagName ); // Get Name of Tag in $a_TagName at $a_TagName[1]
                $a_TagName[ 1 ] = strtolower ( $a_TagName[ 1 ] );
                // $a_TagName[1] is the name of wikitext tag.
 
                // ======= Make AltTag Jump over Real nowiki tags !! ( version 0.2 ) ===============
                // Capital An small letters problem !!
 
                // =================================================================================
                If  (   isset ( $AT_a_NoWikis[ $a_TagName[ 1 ] ] ) ) {  // Check if this Tag name is an alternative in AT_a_NoWikis array 
                        // Is this closing tag? </Tag> AND NowikiTag is open (No processing for colosing tags out of Nowiki tag)
                        If ( preg_match('~<\s*?/.+~' , $s_tag ) ) {
                                If ( ( $a_TagName[1] == $s_OpenedNoWiki ) && ( $b_NoWikiOpen ) ) {
                                        // Check if This Closing AltTag for Nowiki Tag that in the start
                                        $s_OpenedNoWiki = '';
                                        $b_NoWikiOpen = false;
                                        $s_tag = '</' . $AT_a_NoWikis[$a_TagName[1]] . '>' ;
                                }
                        } else { // Not closing Tag.
                                If ( !$b_NoWikiOpen ) {  // Check if this tag in other Nowiki Tag.
                                        // This (If) for nowiki Alt Tags In other Nowiki.. The code must be sure that this nowiki alt tag is not in nowiki
                                        $s_OpenedNoWiki = $a_TagName[1];
                                        $b_NoWikiOpen = true;
                                        $s_tag = '<' . $AT_a_NoWikis[$a_TagName[1]] . '>'; //Fix Nowiki Alt Tag
                                }
                        }
                }
 
                // ---------------- Replace Tags With tag replacement ------------
                If ( $b_NoWikiOpen ) { // If Nowiki Tag is Open, The resault is untouched Tag
                        $a_fixedTags[] = $s_tag; // Add same Tag to FixedTags array without any change.
                } else {
                        // =========== Fix some problems =============================
                        // ------------------ quote after \ --------------------------
                        /* When PHP do preg_replace for something there are quote sighns in it, It usualy insert / before it
                                , That make next RegEx don't work 
                                This is also for security resons. Any ' or " to close '$2' is not allowed.
                                */
                                        $s_SqReplac =  __AltTag_GetReplac ( $s_tag ); // $s_SqReplac is the replacement of any single quote.
                                        $s_DqReplac =  __AltTag_GetReplac ( $s_tag . $s_SqReplac );// $s_DqReplac is the replacement of any double quote.insert $s_SqReplac to the text so as not be $s_DqReplac and  $s_SqReplac the same.
                                        $s_tag = str_replace ( '"' , $s_DqReplac , $s_tag ); // Replace every " to  $s_DqReplac
                                        $s_tag = str_replace ( "'" , $s_SqReplac , $s_tag ); // Replace every ' to  $s_SqReplac
                        // ----------- Real work ----------------------
                        $a_fixedTags[] = preg_replace( '#(<\/?)([^\s/]*?)([\s/].*?>|>)#e' , "'$1'.__AltTag_ProcessTag('$2').__AltTag_ProcessAttr('$3')" , $s_tag , 1);
                        /* above line does:
                                1) extract the Tag Name as $2 and do 'AltTag_ProcessTag' for it.
                                2) extract the part after tag name as $3 in $s_tag and do AltTag_ProcessAttr.
                                e.g if we have tag like this (< tagname attr1='value1' attr2=value \>)
                                        $1 will be (< )
                                        $2 will be (tagname)
                                        $3 will be ( attr1='value1' attr2=value \>)
                        */
                }
        }
        // ----- Replacing Tags ---------------------------
        $s_text = preg_replace( $s_allTagPttrn , $s_tmp_TagReplc , $s_text  ); //replace all Tags with $s_tmp_TagReplc
        // ----- Return Fixed Tags ------------------------
        /*      after above foreatch the wikitext that was like 
                        dfsafsaf <Alttag1>  <Tag2 Altattr=value > df </tag2> dff </Alttag1>
                now it look like
                        dfsafsaf $s_tmp_TagReplc  $s_tmp_TagReplc df $s_tmp_TagReplc dff $s_tmp_TagReplc
                i.e every tag was converted to $s_tmp_TagReplc value.
 
                And the $a_fixedTags now it is like this :
                        $a_fixedTags = array (
                                '<tag1>',                       // the real tag of AltTag1
                                '<Tag2 attr=value >',           // attr is the real attr for alttag.
                                '</tag2>',
                                '</tag1>'                                       // the real tag of AltTag1
                        )
 
                Below foreach loop will replace every $s_tmp_TagReplc by Its Tag from $a_fixedTags. one time every time.
        */
        foreach ( $a_fixedTags as $s_Fixedtag ) {
                $s_text = preg_replace( '/' . preg_quote( $s_tmp_TagReplc ) . '/' , $s_Fixedtag , $s_text , 1 );
        }
 
 
        return true;
}
 
/** __AltTag_ProcessTag
 * Get real Tag name of $TagName from $AT_a_Attr.
 *      This function called from AltTag_Process !!
 * @param $s_TagName the alternative tag to get real tag name of it.
 * @return string real tag name 
 *              if $s_TagName is not exists in $s_TagName , this function will return same $s_TagName.
*/
function __AltTag_ProcessTag( $s_TagName ) {
        $s_TagName = strtolower ( $s_TagName ) ;
        global $AT_a_Tag;
        if ( isset ( $AT_a_Tag[$s_TagName] ) ) {  //Is there any real tag name of $TagName.
                return $AT_a_Tag[$s_TagName];
        }
        return $s_TagName;
}
 
/** __AltTag_ProcessAttr
 * Process all attribute name in $s_AttrPart
 *      This function called from AltTag_Process !!
 * @param s_AttrPart Every thing after tag namr to >.
 * @return string processed AttrPart
*/
function __AltTag_ProcessAttr( $s_AttrPart ) {
        /* $s_AttrPart is all chrs after tag name
                When Tag is :   <tagname attr=val />    or      </tagname>
                AttrPart is :   ( attr=val />)                  or (>)
 
                $s_AttrPart come replaced " and ' to its replacements (take a look to (quote after \) section)
                i.e When tag is : <tagname attr="val" attr='val' />
                        AttrPart is : attr=($s_DqReplac)val($s_DqReplac) attr=($s_SqReplac)val($s_SqReplac)  // for sure without ().
        */
        global $s_SqReplac , $s_DqReplac;
        /* --- Get " and ' Back (Look at above lines)  */ 
        $s_AttrPart = str_replace( $s_DqReplac , '"' , $s_AttrPart );
        $s_AttrPart = str_replace( $s_SqReplac , "'" , $s_AttrPart );
        // --- Split Attr part --------------------------
        // Used RegEx pattern is  (\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?   ;Get Att and Value by:VonC (member in stackoverflow)
        $a_matches = array();
        if ( !preg_match_all( "~(\S+)=[\"']?((?:.(?![\"']?\s+(?:\S+)=|[>\"']))+.)[\"']?~" , $s_AttrPart , $a_matches ) ) {
                return $s_AttrPart;
        }
        /*  $a_matches is
                        3 Items Array : 
                                First one is an array for full attr=Value
                                Seconde one is an array for attr
                                Third one is an array for value without quotation
        */
        // ----- quote after \ --------------------------
                /* When PHP do preg_replace for something there are quote sighns in it, It usualy insert / before it
                        , That make next RegEx don't work 
                        This is also for security resons. Any ' or " to close '$2' is not allowed.
                */
                $s_AttrPart = str_replace( '"' , $s_DqReplac , $s_AttrPart );
                $s_AttrPart = str_replace( "'" , $s_SqReplac , $s_AttrPart );
        // --- Replace AltAttr with RealAttr -------------
        /* Now, Next lines going to process every attr alone
                According to previos RegEx, Attr name Included in $a_matches[1] !! 
                So, next for loop will get name of every attr and change the RegEx pattern.
        */
        $s_AttrPrsPttrn = ''; //This is the RegEx pattern that I will put attr to it.
        for ( $o = 0 ; $o < count ( $a_matches[0] ) ; $o++ ) { 
                // origrn pattern =   (\s*?)([^\s]+?)(\s*?=\s*?)(\"[^\"]*?\"|\'[^\']*?\'|.*?)(\s|/|>)      when ([^\s]+?) is the attribute name.
                $s_AttrPrsPttrn = "~(\s*?)(" . $a_matches[1][$o] . ")(\s*?=\s*?)(" . '"' . "[^" . '"' . "]*?" . '"' . "|'[^']*?'|.*?)(\s|/|>)~e";
                // --- Convert every ' and " to its replacement because there is no ' and " in $s_AttrPart ,now.
                $s_AttrPrsPttrn = str_replace( '"' , $s_DqReplac , $s_AttrPrsPttrn );
                $s_AttrPrsPttrn = str_replace( "'" , $s_SqReplac , $s_AttrPrsPttrn );
                // ---- Process the Attr -----------
                $s_AttrPart = preg_replace( $s_AttrPrsPttrn , "'$1'.__AltTag_GetRealAttr('$2').'$3$4$5'" , $s_AttrPart , 1 ); // does not support unclosed quot!!
        }
        /* --- Get " and ' Back (Look at problems)  */ 
                $s_AttrPart = str_replace( $s_DqReplac , '"' , $s_AttrPart );
                $s_AttrPart = str_replace( $s_SqReplac , "'" , $s_AttrPart );
        //---------------------
        return $s_AttrPart;
}
 
/** __AltTag_GetRealAttr
 * Get real attribute name of $s_AltAttr from $AT_a_Attr.
 *      This function called from AltTag_ProcessAttr !!
 * @param $s_AltAttr the alternative attribute you want to get real attribute of it.
 * @return string real attribute name 
 *              if $s_AltAttr is not exists in $AT_a_Attr , this function will return same $s_AltAttr.
*/
function __AltTag_GetRealAttr( $s_AltAttr ) {
        $s_AltAttr = strtolower ( $s_AltAttr ) ;
        global $AT_a_Attr;
        if ( isset( $AT_a_Attr[$s_AltAttr] ) ) { //Is there any real attribute name of $s_AltAttr.
                return $AT_a_Attr[$s_AltAttr];
        }
        else
        {
                return $s_AltAttr;
        }
}
 
/** __AltTag_GetReplac
 * Get random 8 Letters are not exist in some text.
 * The return value is used to replace some part of text temporarily and replace it after that.
 *      This function called from AltTag_Process !!
 * @param $s_text Text you want to get random 8 letter don't exist in it.
 * @return string random 8 letters
*/
function __AltTag_GetReplac( $s_text ) {
        $s_return =' ';
        while ( stripos ( $s_text , $s_return ) ): // check if random 8 letters exist in $s_text
                $s_return='';
                for ( $t = 1 ; $t <= 8 ; $t++ ) {
                        $s_return .= chr ( rand ( 65 , 90 ) ); // from 65 to 90 because it English letters range of ASCI
                }
        endwhile;
        return $s_return;
}
/** __AltTag_FixArrays 
        created in version 0.2
        This function will :
                Make all keys in the arrays in small letters
                Add real tags to the array to protect it from replacing (It will replace it self), including nowikis tags.
                Strip any dots or any thing else in ExtraChar
*/
function __AltTag_FixArrays() {
        // ----------
        global $AT_b_Fixed ;
        If ( $AT_b_Fixed == true ) {
                return 1 ;
        }
        $AT_b_Fixed = true ;
        // --------
        global $AT_s_ExtraChar ,        $AT_a_NoWikis   , $s_SqReplac , $s_DqReplac , $AT_a_Attr , $AT_a_Tag ;
        // -- Fix Capital letters in the alternatives -- Bug 2
        $AT_a_NoWikis = __AltTag_KeysToLower( $AT_a_NoWikis ) ;
        $AT_a_Attr = __AltTag_KeysToLower( $AT_a_Attr ) ;
        $AT_a_Tag = __AltTag_KeysToLower( $AT_a_Tag ) ;
        // -- Fix Real Nowiki !!
        // Add real nowikis into the array will make AltTag jumps over it. Bug 1
        $a_RealNowikis = array ( 'nowiki' , 'pre' , 'source' , 'code' );
        $a_RealNowikis = array_combine ( $a_RealNowikis , $a_RealNowikis ) ;
        $AT_a_NoWikis = array_merge ( $AT_a_NoWikis ,  $a_RealNowikis ); // origin array must be first becouse we want to replace values in it.
        // Strip any dots or spaces and anything like that in $AT_s_ExtraChar
        $AT_s_ExtraChar = preg_replace ( '~[0-9a-zA-Z\~/\\\*\-\s\+\^\(\)\[\]\{\}\'`!@#$%&_=";:/\?.>,<]~' , '' , $AT_s_ExtraChar );
}
/** __AltTag_KeysToLower 
        created in version 0.2
        This function will make all keys of this array is small letters
*/
function __AltTag_KeysToLower($a_Array ) {
        $a_keys = array_keys ( $a_Array );
        $a_values = array_values ( $a_Array );
        for ( $o = 0 ; $o < count( $a_keys ) ; $o++ ) {
                $a_keys[ $o ] =  strtolower ( $a_keys[ $o ] ) ;
        }
        $a_Array = array_combine ( $a_keys , $a_values ) ;
        return $a_Array ;
}
 
/** Change Log ------------------------------------------------------
        Version 0.2 (Experimental)
                1)Fixed some bugs (Look at Known Bugs Above)
                2)Added two functions (__AltTag_KeysToLower , __AltTag_FixArrays)
                3)All Checking processing will be done in small letters.
        Version 0.1 (Experimental)
                First Version.
--------------------------------------------------------------------- */

How it works[edit]

AltTag converts the alternate tags to real ones , and then transport the product to MediaWiki; this extension process the wikiText before converting it to HTML. So, if MediaWiki brings the revised version from the displayed version (or the other way around), this extension will not operate.

For developers[edit]

It's not a good explanation, but it's enough to understand how it works.

This extension work as this following steps:

1) Get all of the tags to $a_allTagsMatches specifically $a_allTagsMatches[0].
2) Processing the tags in the array (so far did not edit wikitext) this way:
1) Check if the tag is one if Nowikis Tags. If it was one of them $b_NoWikiOpen will be true
2) If $b_NoWikiOpen is true any tag will be added to $a_fixedTags without any change untill Nowiki closing tag.
The tag will splitted to two parts, first part will be sent to __AltTag_ProcessTag() and anything after the tag name will be sent to __AltTag_ProcessAttr() then add the resault into $a_fixedTags.
3) Replacing process: Now all tags in Wikitest will be replaced by random replacement does not exist in wikitest.
4) Returning process: Now the random will be replacement with fixed tag from $a_fixedTags, one time every time. This will return the tags to its correct places.
Why this all Replacing and Returning? Because this extension using RegEx pattern gets any tag, and it need to replace one time every time. Without using this replacements thing RegEx will working with first Tag every time.
Language: English  • العربية