Skip to content

Commit

Permalink
automatically set CSS content model for .less files in NS_MEDIAWIKI (#8)
Browse files Browse the repository at this point in the history
* automatically set CSS content model for .less files in NS_MEDIAWIKI
  • Loading branch information
FO-nTTaX authored Jan 29, 2024
1 parent 9107be2 commit 9ae03a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"Hooks": {
"BeforePageDisplay": "Main",
"ContentHandlerDefaultModelFor": "Main",
"LoadExtensionSchemaUpdates": "Schema",
"MakeGlobalVariablesScript": "Main",
"ResourceLoaderRegisterModules": "Main"
Expand Down
18 changes: 18 additions & 0 deletions src/Hooks/MainHookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use MediaWiki\Hook\MakeGlobalVariablesScriptHook;
use MediaWiki\MediaWikiServices;
use MediaWiki\ResourceLoader\Hook\ResourceLoaderRegisterModulesHook;
use MediaWiki\Revision\Hook\ContentHandlerDefaultModelForHook;
use MediaWiki\Revision\RevisionLookup;
use MediaWiki\Revision\SlotRecord;
use OutputPage;
Expand All @@ -17,6 +18,7 @@

class MainHookHandler implements
BeforePageDisplayHook,
ContentHandlerDefaultModelForHook,
MakeGlobalVariablesScriptHook,
ResourceLoaderRegisterModulesHook
{
Expand Down Expand Up @@ -80,6 +82,22 @@ public function onBeforePageDisplay( $out, $skin ): void {
}
}

/**
* Set the CONTENT_MODEL_CSS content handler for less files
*
* @param Title $title
* @param string &$model
* @return bool
*/
public function onContentHandlerDefaultModelFor( $title, &$model ) {
if ( $title->getNamespace() === NS_MEDIAWIKI ) {
if ( str_ends_with( $title->getText(), '.less' ) ) {
$model = CONTENT_MODEL_CSS;
return true;
}
}
}

/**
* @param array &$vars
* @param OutputPage $out
Expand Down

0 comments on commit 9ae03a8

Please sign in to comment.