<?php # Emoticon MediaWiki Extension # Created by Alex Wollangk (
Esta dirección electrónica esta protegida contra spambots. Es necesario activar Javascript para visualizarla
) if ( !defined( 'MEDIAWIKI' ) ) { die( 'This file is a MediaWiki extension, it is not a valid entry point' ); } global $wgHooks; global $wgExtensionCredits; $wgExtensionCredits['parserhook'][] = array( 'name' => 'Emoticons', 'status' => 'stable', 'type' => 'hook', 'author' => 'Alex Wollangk (
Esta dirección electrónica esta protegida contra spambots. Es necesario activar Javascript para visualizarla
)', 'version' => '1.0', 'update' => '2-20-2007', 'url' => 'http://www.mediawiki.org/wiki/Extension:Emoticons', 'description' => 'Enable forum-style emoticon (smiley) replacement within MediaWiki.', ); $wgHooks['ParserAfterStrip'][] = 'fnEmoticons'; // The callback function for replacing emoticons with image tags function fnEmoticons( &$parser, &$text, &$strip_state ) { global $action; // Access the global "action" variable // Only do the replacement if the action is not edit or history if( $action !== 'edit' && $action !== 'history' && $action !== 'delete' && $action !== 'watch' && strpos( $parser->mTitle->mPrefixedText, 'Special:' ) === false && $parser->mTitle->mNamespace !== 8 ) { // Get the list of emoticons from the "MediaWiki:Emoticons" article. $title = Title::makeTitle( 8, 'Emoticons' ); $emoticonListArticle = new Article( $title ); $emoticonListArticle->getContent(); // If the content successfully loaded, do the replacement if( $emoticonListArticle->mContentLoaded ) { $emoticonList = explode( "\n", $emoticonListArticle->mContent ); foreach( $emoticonList as $index => $emoticon ) { $currEmoticon = explode( "//", $emoticon, 2 ); if( count($currEmoticon) == 2 ) { // start by trimming the search value $currEmoticon[ 0 ] = trim( $currEmoticon[ 0 ] ); // if the string begins with , lop it off if( substr( $currEmoticon[ 0 ], 0, 6 ) == ' ' ) { $currEmoticon[ 0 ] = trim( substr( $currEmoticon[ 0 ], 6 ) ); } // trim the replacement value $currEmoticon[ 1 ] = trim( $currEmoticon[ 1 ] ); // and finally perform the replacement $text = str_replace( $currEmoticon[ 0 ], $currEmoticon[ 1 ], $text ); } } } } // Always a good practice to let the other hooks have their turn ... whenever it make sense. return true; }
|