Skip to content

Commit

Permalink
PLATFORM-10084 Upgrade extension PvXCode to MW 1.43
Browse files Browse the repository at this point in the history
  • Loading branch information
adpaste committed Feb 7, 2025
1 parent dbd3f3b commit e64193b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
17 changes: 11 additions & 6 deletions PvXCode.hooks.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

use MediaWiki\MediaWikiServices;
use MediaWiki\Parser\Parser;

/**
* Curse Inc.
* PvX Code
Expand All @@ -18,9 +21,8 @@
class PvXCodeHooks {
/**
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserFirstCallInit
* @param Parser &$parser
* @param \MediaWiki\Parser\Parser &$parser
* @return true
* @throws MWException
*/
public static function onParserFirstCallInit( Parser &$parser ): bool {
// Calls PvXCode.php within the classes folder
Expand All @@ -33,10 +35,13 @@ public static function onParserFirstCallInit( Parser &$parser ): bool {
* Include the third party gwbbcode library on extension regiation.
* @return void
*/
public static function onRegistration() {
public static function onRegistration(): void {
// Retrieve config settings from localSettings.php -
// probably a better way of doing this via "use MediaWiki\MediaWikiServices;"
global $wgServer, $wgScriptPath, $wgExtensionAssetsPath;
$config = MediaWikiServices::getInstance()->getMainConfig();
$wgServer = $config->get( 'Server' );
$wgScriptPath = $config->get( 'ScriptPath' );
$wgExtensionAssetsPath = $config->get( 'ExtensionAssetsPath' );


// Local file path for includes
define( 'GWBBCODE_ROOT', __DIR__ . '/gwbbcode' );
Expand All @@ -53,6 +58,6 @@ public static function onRegistration() {
define( 'GW_WIKI_PAGE_URL', 'https://wiki.guildwars.com/wiki' );

// Load main script
require_once( GWBBCODE_ROOT . '/gwbbcode.inc.php' );
require_once GWBBCODE_ROOT . '/gwbbcode.inc.php';
}
}
9 changes: 6 additions & 3 deletions classes/PvXCode.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php

use MediaWiki\Parser\Parser;
use MediaWiki\Title\TitleValue;

/**
* Curse Inc.
* PvX Code
Expand All @@ -11,7 +15,6 @@
* @link https://gitlab.com/hydrawiki
*
*/

class PvXCode {
/**
* Parser Renderer
Expand All @@ -22,8 +25,8 @@ class PvXCode {
* @return array|string|string[]|null
*/
public static function parserRender( string $input, array $args, Parser $parser, string $frame ) {
$parser->getOutput()->addModuleStyles( 'ext.PvXCode.css' );
$parser->getOutput()->addModules( 'ext.PvXCode.js' );
$parser->getOutput()->addModuleStyles( [ 'ext.PvXCode.css' ] );
$parser->getOutput()->addModules( [ 'ext.PvXCode.js' ] );
$title = TitleValue::newFromPage( $parser->getPage() );
$text = $title->getText();

Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
},
"callback": "PvXCodeHooks::onRegistration",
"manifest_version": 1
}
}
18 changes: 6 additions & 12 deletions gwbbcode/gwbbcode.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* All images, skill names and descriptions are (C) ArenaNet.
***************************************************************************/

require_once( GWBBCODE_ROOT . '/constants.inc.php' );
require_once GWBBCODE_ROOT . '/constants.inc.php';

/***************************************************************************
* GLOBALS
Expand All @@ -39,7 +39,6 @@
}
$pvp_to_pve_skill_list = load( SKILLIDSPVP_PATH );


/***************************************************************************
* MAIN FUNCTION
***************************************************************************/
Expand Down Expand Up @@ -261,10 +260,9 @@ function skill_name_replace( $reg ) {
}

// Handle the difference between [[shock] and [shock]
if ( $noicon )
if ( $noicon ) {
// PHP note: Use of double quotes replaces variables inside with their values
// PHP note: Use of single quotes shows the variable names like JS would.
{
return "[skill noicon$attr$show]" . $name . '[/skill]';
} else {
return "[skill$attr]" . $name . '[/skill]';
Expand Down Expand Up @@ -318,7 +316,6 @@ function build_replace( $reg ) {
$secondary_display_name = 'Any';
}


// Attributes
$attributes = '';
foreach ( $attr_list_raw as $attribute_name => $attribute_value ) {
Expand All @@ -334,7 +331,6 @@ function build_replace( $reg ) {
$attributes = preg_replace( '/\s*\\+\s*/', ' + ', $attributes );
$skills = str_replace( '[skill', '[skill ' . $att, $skills );


// Build description
$desc = preg_match( '|desc=\\"([^"]+)\\"|', $att, $reg ) ? $reg[1] : '';
$desc = empty( $desc ) ? '' : ( $desc . '<br/>' );
Expand Down Expand Up @@ -579,8 +575,8 @@ function build_replace( $reg ) {
arsort( $attr_primary );
foreach ( $attr_runes as $attr => $rune ) {
if ( $rune < 3 ) {
$attr_primary[$attr] --;
$attr_runes[$attr] ++;
$attr_primary[$attr]--;
$attr_runes[$attr]++;
break;
}
}
Expand Down Expand Up @@ -1557,7 +1553,7 @@ function add_strength( $desc, &$extra_desc, $attr_list, $type ) {
if ( isset( $attr_list['Strength'] ) && $attr_list['Strength'] > 0 && strpos( $type, 'Attack' ) !== false ) {
// Strength does not stack with skills with inherent armor penetration
if ( preg_match( '@[Tt]his (attack|axe attack) has ([0-9]+)% armor penetration@', $desc, $reg ) ) {
if ( $reg[2] < $attr_list['Strength'] ) {
if ( $reg[2] < $attr_list['Strength'] ) {
$extra_desc =
'This attack skill has <b>' . $attr_list['Strength'] .
'</b>% armor penetration. Its inherent armor penetration is overwritten.';
Expand Down Expand Up @@ -1906,7 +1902,7 @@ function load( $filename ) {
if ( !file_exists( $filename ) ) {
return false;
} else {
return require( $filename );
return require $filename;
}
}

Expand Down Expand Up @@ -2336,5 +2332,3 @@ function bin_to_template( $bin ) {

return $ret;
}

?>
3 changes: 2 additions & 1 deletion specials/SpecialPvXConvert.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use MediaWiki\SpecialPage\SpecialPage;

/**
* Curse Inc.
* PvX Code
Expand Down Expand Up @@ -29,7 +31,6 @@ public function __construct() {
*
* @param $par - Not used, but expected to be there by mediawiki.
* @return void - echos to page.
* @throws MWException
*/
public function execute( $par = null ) {
$request = $this->getRequest();
Expand Down
6 changes: 3 additions & 3 deletions specials/SpecialPvXDecode.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use MediaWiki\SpecialPage\SpecialPage;

/**
* Curse Inc.
Expand All @@ -24,14 +25,13 @@ class SpecialPvXDecode extends SpecialPage {
public function __construct() {
parent::__construct( 'PvXDecode' );

require_once( GWBBCODE_ROOT . '/gwbbcode.inc.php' );
require_once GWBBCODE_ROOT . '/gwbbcode.inc.php';
}

/**
* Main Execute for the Specil Page
* @param $par - Not used, but expected to be there by mediawiki.
* @return void - echos to page.
* @throws MWException
*/
public function execute( $par = null ) {
$request = $this->getRequest();
Expand Down Expand Up @@ -84,4 +84,4 @@ protected function getGroupName(): string {
// Change to display in a different category on Special:SpecialPages.
return 'pvx';
}
}
}
3 changes: 3 additions & 0 deletions specials/SpecialPvXDownloadTemplate.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use MediaWiki\SpecialPage\SpecialPage;

/**
* Curse Inc.
* PvX Code
Expand Down

0 comments on commit e64193b

Please sign in to comment.