Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( !defined( 'MEDIAWIKI' ) ) {
- die( 'This file is a MediaWiki extension, it is not a valid entry point' );
- }
- $wgExtensionCredits['parserhook'][] = array(
- 'path' => __FILE__,
- 'name' => 'GuildWikiSkills',
- 'version' => '0.0a',
- 'author' => '[[User:Dr ishmael|Tony Tauer]]',
- 'description' => 'Performs dynamic formatting of skill descriptions.',
- );
- $dir = dirname( __FILE__ ) . '/';
- $wgExtensionFunctions[] = 'wfSkillFunctions';
- $wgHooks['LanguageGetMagic'][] = 'wfSkillFunctionsLanguageGetMagic';
- /*
- $wgSkillFunctionsLinks : A hash of article names to link to and the keywords
- to trigger the links
- The order here (target article => keyword regex) is counterintuitive, but it's
- better to have the target article as the hash key since keys have to be unique
- and we only want 1 entry per target (so we don't end up with repeated links)
- The hash values are regex fragments that will be inserted into the following:
- /(?<= |-)('.$needle.')(?!\]|\|)/i
- That means that $needle must be preceded by either a space or a hyphen, and
- cannot be followed by a pipe or a closing bracket, and that the search is
- case-insensitive. Once a $needle is found and linked, it will then be
- wrapped between an opening bracket and a pipe, preventing it from matching
- any other patterns.
- The overall order of entries is very sensitive, since a lot of entries are
- substrings of other entries. Attack, Damage, and Skill are the most obvious,
- but you should always be aware of this when adding or modifying entries.
- */
- $wgSkillFunctionsLinks = array(
- # conditions
- 'Bleeding' => 'bleed',
- 'Blind' => 'blind',
- 'Burning' => 'burn|on fire',
- 'Cracked Armor' => 'cracked armor',
- 'Crippled' => 'cripple',
- 'Dazed' => 'daze',
- 'Deep Wound' => 'deep wound',
- 'Disease' => 'disease',
- 'Poison' => 'poison',
- 'Weakness' => 'weak',
- 'Condition' => 'condition',
- # skill types (not all appear in descriptions, but listing all for completeness)
- 'Chant' => 'chant', # no conflict with 'enchant' since $needle must be preceded by a space
- 'Echo (skill type)' => '(?<=This )echo',
- 'Elite skill' => 'elite(| skill)',
- 'Flash Enchantment' => 'flash enchantment',
- 'Enchantment' => 'enchant',
- 'Form' => 'form',
- 'Hex' => 'hex(?!er)', # avoid Hexer's Vigor (references itself)
- 'Preparation' => 'preparation',
- 'Shout' => 'shout',
- 'Signet' => 'signet',
- 'Weapon Spell' => 'weapon spell',
- 'Spell' => 'spell',
- 'Stance' => '(?<!Berserker |Defensive |Disciplined |Tiger |Wary )stance',
- 'Trap' => 'trap',
- 'Ritual' => '(binding |nature |)ritual',
- 'Ward Spell' => 'ward',
- 'Well Spell' => 'well',
- # attack skill types
- 'Dual attack' => 'dual attack',
- 'Lead attack' => 'lead attack',
- 'Off-hand attack' => 'off-hand attack',
- 'Dagger Attack' => 'dagger attack',
- 'Axe Attack' => 'axe attack',
- 'Hammer Attack' => 'hammer attack',
- 'Sword Attack' => 'sword attack',
- 'Bow Attack' => 'bow attack',
- 'Spear Attack' => 'spear attack',
- 'Scythe Attack' => 'scythe attack',
- 'Attack (skill type)' => 'attack skill',
- 'Skill' => 'skill',
- # non-skill attacks
- 'Physical attack' => 'physical attack',
- 'Ranged attack' => 'ranged attack',
- 'Attack' => '(?<!Penetrating |Sundering )attack',
- # attributes - only a few are mentioned in current descriptions; listing
- # them all for completeness
- 'Primary attribute' => 'primary attribute',
- 'Attribute' => 'attribute',
- 'Critical Strikes' => 'critical strikes',
- 'Dagger Mastery' => 'dagger mastery',
- 'Deadly Arts' => 'deadly arts',
- 'Shadow Arts' => 'shadow arts',
- 'Earth Prayers' => 'earth prayers',
- 'Mysticism' => 'mysticism',
- 'Scythe Mastery' => 'scythe mastery',
- 'Wind Prayers' => 'wind prayers',
- 'Air Magic' => 'air magic',
- 'Earth Magic' => 'earth magic|earth(?= or water)',
- 'Energy Storage' => 'energy storage',
- 'Fire Magic' => 'fire magic',
- 'Water Magic' => 'water magic|water(?= hex)',
- 'Domination Magic' => 'domination magic',
- 'Fast Casting' => 'fast casting',
- 'Illusion Magic' => 'illusion magic|illusion(?= hex| attribute)',
- 'Inspiration Magic' => 'inspiration magic',
- 'Divine Favor' => 'divine favor',
- 'Healing Prayers' => 'healing prayer|healing(?= or protection)',
- 'Protection Prayers' => 'protection prayers',
- 'Smiting Prayers' => 'smiting prayers',
- 'Blood Magic' => 'blood magic',
- 'Curses' => 'curses',
- 'Death Magic' => 'death magic',
- 'Soul Reaping' => 'soul reaping',
- 'Command' => 'command',
- 'Leadership' => 'leadership',
- 'Motivation' => 'motivation',
- 'Spear Mastery' => 'spear mastery',
- 'Beast Mastery' => 'beast mastery',
- 'Expertise' => 'expertise',
- 'Marksmanship' => 'marksmanship',
- 'Wilderness Survival' => 'wilderness survival',
- 'Channeling Magic' => 'channeling magic',
- 'Communing' => 'communing',
- 'Restoration Magic' => 'restoration magic',
- 'Spawning Power' => 'spawning power',
- 'Axe Mastery' => 'axe mastery',
- 'Hammer Mastery' => 'hammer mastery',
- 'Strength' => 'strength',
- 'Swordsmanship' => 'swordsmanship',
- 'Tactics' => 'tactics',
- # weapons - all '[weapon] attack' and '[weapon] mastery' entries must precede these
- 'Axe' => '(?<!Furious |Whirling )axe',
- 'Bow' => 'bow',
- 'Daggers' => 'daggers',
- 'Hammer' => '(?<!Devastating )hammer(?! Bash)',
- 'Scythe' => 'scythe',
- 'Shield' => 'shield',
- 'Spear' => 'spear',
- 'Sword' => 'sword',
- 'Arrow' => '(?<!Poison |Shock )arrow',
- # professions - not all 10 are mentioned in current descriptions; listing
- # them all for completeness
- 'Assassin' => 'assassin',
- 'Dervish' => 'dervish',
- 'Elementalist' => 'elementalist',
- 'Mesmer' => 'mesmer',
- 'Monk' => 'monk',
- 'Necromancer' => 'necromancer',
- 'Paragon' => 'paragon',
- 'Ranger' => 'ranger',
- 'Ritualist' => 'ritualist',
- 'Warrior' => 'warrior',
- # skill cost terms
- 'Adrenaline' => 'adrenal',
- 'Activation time' => 'activat', # activate/activating
- 'Energy#Energy regeneration/degeneration' => 'energy (r|d)egeneration',
- 'Energy' => 'energy',
- 'Exhaustion' => 'exhaust', # exhaustion/exhausted
- 'Health#Health regeneration/degeneration' => 'health (r|d)egeneration',
- 'Health' => 'health',
- 'Heal' => 'heal(?!th)',
- 'Recharge' => 'recharg', # recharge/recharging
- 'Sacrifice' => 'sacrifice',
- 'Upkeep' => 'maintain',
- # skill effect terms
- 'Touch' => 'touch',
- 'Disable' => 'disable',
- 'Interrupt' => '(?<!easily )interrupt|disrupting|uninterruptible',
- 'Easily interrupted' => 'easily interrupted',
- 'Life stealing' => 'life steal|steal(?=.*health)', # 'steal' is also used in a couple Energy stealing skills
- 'Block' => '(un|)block',
- 'Miss' => 'miss',
- 'Fail' => 'fail(?! to hit)',
- 'Knockdown' => 'knock(ed|s|)( |-|)down', # knocked/knocks/knock, joined by ' ' or '-' or nothing
- 'Resurrect (action)' => 'resurrect|(returned|back) to life',
- 'Range' => 'range|adjacent|near|in the area|earshot',
- 'Armor penetration' => 'armor penetration',
- 'Armor (rating)' => 'armor',
- 'Critical hit' => 'critical( attack| hit)',
- 'Cast' => 'cast',
- 'Corpse exploitation' => 'exploit',
- 'Create' => 'animate|create|summon',
- 'Shadow step' => 'shadow step',
- 'Teleport' => 'teleport',
- 'Death penalty' => 'death penalty',
- 'Morale boost' => 'morale boost',
- 'Melee' => 'melee',
- 'Action' => 'action',
- 'Double strike' => 'double strike',
- 'Projectile' => 'projectile',
- 'Bundle' => '(bundle |)item',
- # damage
- 'Physical damage' => 'physical damage',
- 'Blunt damage' => 'blunt damage',
- 'Piercing damage' => 'piercing damage',
- 'Slashing damage' => 'slashing damage',
- 'Elemental damage' => 'elemental damage|elemental(?= and| or)',
- 'Cold damage' => 'cold damage|cold(?= weapon)',
- 'Earth damage' => 'earth damage|earth(?= weapon)',
- 'Fire damage' => 'fire damage|fire(?= weapon)',
- 'Lightning damage' => 'lightning damage|lightning(?= weapon)',
- 'Holy damage' => 'holy damage',
- 'Shadow damage' => 'shadow damage',
- 'Damage reduction' => 'damage reduction',
- 'Damage' => 'damage',
- # targets
- 'Corpse' => 'corpse',
- 'Fleshy creature' => 'fleshy',
- 'Summoned creature' => 'summoned creature',
- 'Spirit' => '(?<!Watchful |Spiteful )spirit',
- 'Bone Fiend' => 'bone fiend',
- 'Bone Horror' => 'bone horror',
- 'Bone Minion' => 'bone minion',
- 'Flesh Golem' => 'flesh golem',
- 'Shambling Horror' => 'shambling horror',
- 'Jagged Horror' => 'jagged horror',
- 'Vampiric Horror' => 'vampiric horror',
- 'Minion' => 'undead (|allied)(allies|ally|minion|servant)|animated undead|minion|servant',
- 'Ally' => 'all(y|ies)',
- 'Party' => 'party',
- 'Animal companion' => 'animal(| companion)|pet',
- 'Foe' => 'foe',
- # misc for PvE skills
- 'Sunspear rank' => 'sunspear rank',
- 'Raven Blessing skills quick reference' => 'raven attacks',
- 'Ursan Blessing skills quick reference' => 'bear attacks',
- 'Volfen Blessing skills quick reference' => 'wolf attacks',
- 'Experience' => 'experience',
- 'Ice Imp' => 'ice imp',
- 'Mursaat Elementalist' => 'mursaat',
- 'Naga Shaman' => 'naga shaman',
- 'Ruby Djinn' => 'ruby djinn',
- 'Boss' => 'boss',
- 'Destroyer' => 'destroyer',
- 'Drunk' => 'drunk',
- 'Hidden object' => 'hidden object',
- 'Compass' => 'compass',
- 'Charr' => 'charr',
- 'Iron Palm' => 'iron palm',
- 'Fox Fangs' => 'fox fangs',
- 'Nine Tail Strike' => 'nine tail strike',
- );
- function wfSkillFunctions ( ) {
- global $wgParser, $wgExtSkillFunctions;
- $wgExtSkillFunctions = new ExtSkillFunctions ( );
- $wgParser->setFunctionHook('descparse', array(&$wgExtSkillFunctions,'parseDescription' ));
- }
- function wfSkillFunctionsLanguageGetMagic( &$magicWords, $langCode = "en" ) {
- switch ( $langCode ) {
- default:
- $magicWords['descparse'] = array ( 0, 'descparse' );
- }
- return true;
- }
- class ExtSkillFunctions {
- /**
- * {{#descparse:raw_description|str1_min|str1_max|str2_min|str2_max|str3_min|str3_max}}
- * Note: If any of the parameters are an empty string, they are ignored.
- */
- function parseDescription ( &$parser, $raw = '', $min1 = -1, $max1 = -1,
- $min2 = -1, $max2 = -1, $min3 = -1, $max3 = -1
- ) {
- global $wgSkillFunctionsLinks;
- # Read additional link keywords from MediaWiki: pages
- # These should all be of the 'target' => 'needle' format
- $source = wfMsgForContent('Skill-description-links');
- if( $source && !wfEmptyMsg('Skill-description-links', $source) ) {
- $lines = explode("\n", $source);
- $lines = ExtSkillFunctions::stripLines($lines);
- foreach($lines as $line) {
- if(preg_match('/^\'.*?\' => \'.*?\'$/', $line)) {
- $wgSkillFunctionsLinks[] = $line;
- }
- }
- }
- if ( $raw === '' ) {
- # if input is empty, return empty
- return '';
- }
- $rval = $raw;
- # Set up $parms as an array of arrays
- # $parms[1][0] = $min1, $parms[3][1] = $max3, etc.
- $parms = array('', array($min1, $max1), array($min2, $max2), array($min3, $max3));
- # Evaluate parms and perform %str#% substitution
- foreach (array(1, 2, 3) as $i) {
- $min = ($parms[$i][0] === '') ? -1 : $parms[$i][0];
- $max = ($parms[$i][1] === '') ? -1 : $parms[$i][1];
- # If only the max is set, this is an error
- if ($min === -1 && $max !== -1) {
- return '<strong class="error">' . "Error: str${i}_max given without str${i}_min" . '</strong>';
- }
- # If only the min is set, then substitute %str#% with min (no formatting)
- elseif ($min !== -1 && $max === -1) {
- $rval = str_replace("%str$i%",$min,$rval);
- }
- # If both min and max are set and are different, calculate range and substitute (with formatting)
- elseif ($min !== -1 && $max !== -1 && $min !== $max) {
- $v12 = round($min + ($max - $min)*12/15);
- $rval = str_replace("%str$i%","'''${min}...${v12}...${max}'''",$rval);
- }
- # If both min and max are set and are the same, substitue (with formatting)
- elseif ($min !== -1 && $max !== -1 && $min === $max) {
- $rval = str_replace("%str$i%","'''$min'''",$rval);
- }
- # Else if neither min nor max is set, and $raw contains %str#%, return error
- elseif ( strpos($rval,"%str$i%") ) {
- return '<strong class="error">' . "Error: description contains %str$i% but str${i}_min/max are not set" . '</strong>';
- }
- }
- # Collapse doubled %%
- $rval = str_replace('%%','%',$rval);
- # Translate <c=@SkillDull>...</c> into ''...''
- $rval = str_replace('<c=@SkillDull>',"''",$rval);
- $rval = str_replace('</c>',"''",$rval);
- # Plurals
- $rval = str_replace('[s]','s',$rval); # simple
- $rval = preg_replace('/\w+\[pl:"(\w+)\"\]/','$1',$rval); # complex
- # Prepend a space so the backreferences can match at the beginning of the string
- $rval = ' ' . $rval;
- # Links
- foreach ($wgSkillFunctionsLinks as $target => $needle) {
- $rval = preg_replace('/(?<= |-)('.$needle.')(?!\]|\|)/i','[['.$target.'|$1]]',$rval,1);
- }
- # Remove the prepended space
- $rval = substr($rval,1);
- # Wrap with span to set CSS class
- $rval = '<span class="skill_description">' . $rval . '</span>';
- return $rval;
- }
- /**
- * Strip comments and whitespace, then remove blanks
- * @private
- * @static
- */
- static function stripLines( $lines ) {
- return array_filter(
- array_map( 'trim',
- preg_replace( '/#.*$/', '',
- $lines ) ) );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement