Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit e0d8f1288bec46d6bfd1468b0fa040f8eb363790
Author: Tobias Oetterer <[email protected]>
Date:   Sat Jul 13 08:33:57 2024 +0200

    finished overhaul

    * switched to suggested mw hook handling system
    * moved skin and module handling in new class BootstrapComponentsService
    * moved to MediaWikiServices for three "main classes"
    * ParserOutputHelper still crude construct. stays in for now

commit 39d171692b8d7e7517e3a2ddad252d026a276e78
Author: Tobias Oetterer <[email protected]>
Date:   Tue Jul 9 18:09:51 2024 +0200

    starting refactoring

    * moved extension classes to proper MediaWiki namespace schema
    * started switching to ServiceWiring
    * started moving hook registration to mw default using extension.json
     * abandoning registration via onExtensionFunction
     * new HooksHandler class taking over (and incorporating
       DefaultHooksHandler)
     * obsoleting class HookRegisty
    * augmenting method signatures with type declarations
  • Loading branch information
oetterer committed Jul 13, 2024
1 parent 9ec2e30 commit f32bcf6
Show file tree
Hide file tree
Showing 81 changed files with 1,573 additions and 2,039 deletions.
5 changes: 4 additions & 1 deletion BootstrapComponents.magic.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
* @author Tobias Oetterer
*/

use MediaWiki\MediaWikiServices;

$magicWords = [];

$componentLibrary = \BootstrapComponents\ApplicationFactory::getInstance()->getComponentLibrary();
/** @var \MediaWiki\Extension\BootstrapComponents\ComponentLibrary $componentLibrary */
$componentLibrary = MediaWikiServices::getInstance()->getService( 'BootstrapComponents.ComponentLibrary' );

// English
$magicWords['en'] = $componentLibrary->compileMagicWordsArray();
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
},
"require": {
"php": ">=7.4",
"composer/installers": "^2|^1.0.1",
"mediawiki/mw-extension-registry-helper": "^1.0",
"mediawiki/bootstrap": "^5.0|^4.0"
"composer/installers": "^2",
"mediawiki/bootstrap": "^5.0"
},
"require-dev": {
"mediawiki/mediawiki-codesniffer": "43.0.0",
Expand Down
18 changes: 18 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@

Released on _not yet_

Changes:
* dropping support of mediawiki < 1.39
* removed auto-loading of Extension:Bootstrap.
* add translations via translatewiki
*
Fixes:
* fixed php 8 deprecation notice indicating missing logic encapsulation
in class AbstractComponent

Refactoring:
* modified extension namespace to be compatible with mediawiki
extension namespace schema


### BootstrapComponents 5.1.2

Released on 12-May-2024

Changes:
* add css classes to restore the usual infobox layout
* add more style control to card component
Expand Down
42 changes: 31 additions & 11 deletions extension.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,60 @@
{
"name": "BootstrapComponents",
"version": "5.1.2-dev",
"version": "5.2.0-dev",
"author": [ "Tobias Oetterer" ],
"url": "https://www.mediawiki.org/wiki/Extension:BootstrapComponents",
"descriptionmsg": "bootstrap-components-desc",
"license-name": "GPL-3.0-or-later",
"type": "parserhook",
"requires": {
"MediaWiki": ">= 1.35.0"
"MediaWiki": ">= 1.39.0"
},
"ConfigRegistry": {
"BootstrapComponents": "GlobalVarConfig::newInstance"
},
"AutoloadNamespaces": {
"BootstrapComponents\\": "src/"
"MediaWiki\\Extension\\BootstrapComponents\\": "src/"
},
"TestAutoloadNamespaces": {
"BootstrapComponents\\Tests\\": "tests/phpunit/"
"MediaWiki\\Extension\\BootstrapComponents\\Tests\\": "tests/phpunit/"
},
"ServiceWiringFiles": [
"src/ServiceWiring.php"
],
"@note": "the extension's main hooks are registered in BootstrapComponents\\HookRegistry",
"HookHandlers": {
"BootStrapHooks": {
"class": "BootstrapComponents\\Hooks\\DefaultHooksHandler"
"class": "MediaWiki\\Extension\\BootstrapComponents\\HooksHandler",
"services": [
"BootstrapComponentsService",
"BootstrapComponents.ComponentLibrary",
"BootstrapComponents.NestingController"
]
}
},
"Hooks": {
"SetupAfterCache": {
"GalleryGetModes": {
"handler": "BootStrapHooks"
},
"ImageBeforeProduceHTML": {
"handler": "BootStrapHooks"
},
"InternalParseBeforeLinks": {
"handler": "BootStrapHooks"
},
"OutputPageParserOutput": {
"handler": "BootStrapHooks"
},
"ParserAfterParse": {
"handler": "BootStrapHooks"
},
"ScribuntoExternalLibraries": "BootstrapComponents\\Hooks\\DefaultHooksHandler::onScribuntoExternalLibraries"
"ParserFirstCallInit": {
"handler": "BootStrapHooks"
},
"SetupAfterCache": {
"handler": "BootStrapHooks"
},
"ScribuntoExternalLibraries": "MediaWiki\\Extension\\BootstrapComponents\\HooksHandler::onScribuntoExternalLibraries"
},
"config": {
"BootstrapComponentsDisableSourceLinkOnImageModal": {
Expand All @@ -55,10 +78,7 @@
"public": true
}
},
"callback": "BootstrapComponents\\BootstrapComponents::init",
"ExtensionFunctions": [
"BootstrapComponents\\BootstrapComponents::onExtensionFunction"
],
"callback": "MediaWiki\\Extension\\BootstrapComponents\\BootstrapComponents::init",
"MessagesDirs": {
"BootstrapComponents": [
"i18n"
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
verbose="true">
<listeners>
<listener file="tests/phpunit/ExecutionTimeTestListener.php"
class="BootstrapComponents\Tests\ExecutionTimeTestListener">
class="Mediawiki\Extension\BootstrapComponents\Tests\ExecutionTimeTestListener">
<arguments>
<boolean>true</boolean>
<integer>10</integer>
Expand Down
7 changes: 3 additions & 4 deletions src/AbstractComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @author Tobias Oetterer
*/

namespace BootstrapComponents;
namespace MediaWiki\Extension\BootstrapComponents;

use \MWException;

Expand Down Expand Up @@ -283,7 +283,7 @@ protected function prepareInput( $parserRequest, $fullParse = false ) {
$parserRequest->getFrame()
);
}
if ( $input && preg_match( '/\n\n/', $input ) || preg_match( '/<p/', $input ) ) {
if ( $input && (preg_match( '/\n\n/', $input ) || preg_match( '/<p/', $input )) ) {
// if there are paragraph marker we prefix input with a new line so the parser recognizes two paragraphs.
$input = "\n" . $input . "\n";
}
Expand Down Expand Up @@ -316,10 +316,9 @@ protected function processCss( $class, $style ) {
*/
private function augmentParserOutput() {
$this->getParserOutputHelper()->addTrackingCategory();
$this->getParserOutputHelper()->loadBootstrapModules();
$modules = $this->getComponentLibrary()->getModulesFor(
$this->getComponentName(),
$this->getParserOutputHelper()->getNameOfActiveSkin()
'vector'
);
$this->getParserOutputHelper()->addModules( $modules );
}
Expand Down
53 changes: 19 additions & 34 deletions src/ApplicationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @author Tobias Oetterer
*/

namespace BootstrapComponents;
namespace MediaWiki\Extension\BootstrapComponents;

use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
Expand Down Expand Up @@ -88,27 +88,7 @@ public static function getInstance() {
public function __construct() {
$this->applicationStore = [];
$this->applicationClassRegister = $this->getApplicationClassRegister();
$this->getLogger()->info( 'ApplicationFactory was build!' );
}

/**
* @param null|bool|array $componentWhiteList
*
* @throws MWException cascading {@see \BootstrapComponents\ApplicationFactory::getApplication}
*
* @return ComponentLibrary
*/
public function getComponentLibrary( $componentWhiteList = null ) {
return $this->getApplication( 'ComponentLibrary', $componentWhiteList );
}

/**
* @throws MWException cascading {@see \BootstrapComponents\ApplicationFactory::getApplication}
*
* @return NestingController
*/
public function getNestingController() {
return $this->getApplication( 'NestingController' );
$this->getLogger()->debug( 'ApplicationFactory was build!' );
}

/**
Expand All @@ -119,7 +99,7 @@ public function getNestingController() {
*
* @return AttributeManager
*/
public function getNewAttributeManager( $validAttributes, $aliases ) {
public function getNewAttributeManager( array $validAttributes, array $aliases ): AttributeManager {
return new AttributeManager( $validAttributes, $aliases );
}

Expand All @@ -133,7 +113,9 @@ public function getNewAttributeManager( $validAttributes, $aliases ) {
*
* @return ModalBuilder
*/
public function getNewModalBuilder( $id, $trigger, $content, $parserOutputHelper ) {
public function getNewModalBuilder(
string $id, string $trigger, string $content, ParserOutputHelper $parserOutputHelper
): ModalBuilder {
return new ModalBuilder( $id, $trigger, $content, $parserOutputHelper );
}

Expand All @@ -148,7 +130,9 @@ public function getNewModalBuilder( $id, $trigger, $content, $parserOutputHelper
*
* @return ParserRequest
*/
public function getNewParserRequest( $argumentsPassedByParser, $isParserFunction, $componentName = 'unknown' ) {
public function getNewParserRequest(
array $argumentsPassedByParser, bool $isParserFunction, string $componentName = 'unknown'
): ParserRequest {
return new ParserRequest( $argumentsPassedByParser, $isParserFunction, $componentName );
}

Expand Down Expand Up @@ -178,7 +162,7 @@ public function getParserOutputHelper( $parser = null ) {
*
* @return bool
*/
public function registerApplication( $name, $class ) {
public function registerApplication( string $name, string $class ): bool {
$application = trim( $name );
$applicationClass = trim( $class );
if ( $application != '' && class_exists( $applicationClass ) ) {
Expand All @@ -199,7 +183,7 @@ public function registerApplication( $name, $class ) {
*
* @return bool
*/
public function resetLookup( $application = null ) {
public function resetLookup( ?string $application = null ): bool {
if ( is_null( $application ) ) {
$this->applicationStore = [];
return true;
Expand All @@ -218,9 +202,9 @@ public function resetLookup( $application = null ) {
*
* @throws MWException when no class is registered for the requested application or the creation of the object fails.
*
* @return mixed|object
* @return object
*/
protected function getApplication( $name ) {
protected function getApplication( $name ): object {
if ( isset( $this->applicationStore[$name] ) ) {
return $this->applicationStore[$name];
}
Expand All @@ -233,9 +217,11 @@ protected function getApplication( $name ) {
try {
$objectReflection = new ReflectionClass( $this->applicationClassRegister[$name] );
} catch ( \ReflectionException $e ) {
throw new MWException( 'Error while trying to build application "' . $name . '" with class ' . $this->applicationClassRegister[$name] );
throw new MWException(
'Error while trying to build application "' . $name . '" with class ' . $this->applicationClassRegister[$name]
);
}
$this->getLogger()->info( 'ApplicationFactory successfully build application ' . $name );
$this->getLogger()->debug( 'ApplicationFactory successfully build application ' . $name );
return $this->applicationStore[$name] = $objectReflection->newInstanceArgs( $args );
}

Expand All @@ -244,9 +230,8 @@ protected function getApplication( $name ) {
*/
protected function getApplicationClassRegister() {
return [
'ComponentLibrary' => 'BootstrapComponents\\ComponentLibrary',
'NestingController' => 'BootstrapComponents\\NestingController',
'ParserOutputHelper' => 'BootstrapComponents\\ParserOutputHelper',
'NestingController' => 'MediaWiki\\Extension\\BootstrapComponents\\NestingController',
'ParserOutputHelper' => 'MediaWiki\\Extension\\BootstrapComponents\\ParserOutputHelper',
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/AttributeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @author Tobias Oetterer
*/

namespace BootstrapComponents;
namespace MediaWiki\Extension\BootstrapComponents;

/**
* Class AttributeManager
Expand Down
Loading

0 comments on commit f32bcf6

Please sign in to comment.