Custom loading MediaWiki skinScripts - mediawiki

I'm about to set up some custom JS and CSS using something like this in LocalSettings.php, from here: https://www.mediawiki.org/wiki/Snippets/Load_an_additional_JavaScript_or_stylesheet_file_on_all_pages#Code
$wgResourceModules['zzz.customizations'] = array(
'styles' => "skin.css", // Stylesheet to be loaded in all skins
// Custom styles to apply only to Vector skin. Remove if you don't use it
'skinStyles' => array(
'vector' => 'skin-vector.css',
),
// End custom styles for vector
'scripts' => "skin.js", // Script file to be loaded in all skins
'localBasePath' => "$IP/customizations/",
'remoteBasePath' => "$wgScriptPath/customizations/"
);
function efCustomBeforePageDisplay( &$out, &$skin ) {
$out->addModules( array( 'zzz.customizations' ) );
}
This code shows a custom CSS that's loaded only for the vector skin, and another that's always loaded. I want to do the same with with the JavaScript, that is, load a JS file that's only for the vector skin as well as one that is always loaded.
I see from that documentation (https://www.mediawiki.org/wiki/Manual:$wgResourceModules) that skinScripts is supported, but I don't know how it would fit into the above code. Could anyone show me how to modify the above code to make that happen? Thanks.

The documentation you linked says:
skinScripts
Scripts to include in specific skin contexts.
Array keyed by skin name containing file path string or array of file path strings.
That isn't much different from the skinStyles entry, so I'd assume that something like this would work:
$wgResourceModules['zzz.customizations'] = array(
'styles' => "skin.css", // Stylesheet to be loaded in all skins
// Custom styles to apply only to Vector skin. Remove if you don't use it
'skinStyles' => array(
'vector' => 'skin-vector.css',
),
// End custom styles for vector
'scripts' => "skin.js", // Script file to be loaded in all skins
'skinScripts' => array(
'vector' => 'skin-vector.js',
),
'localBasePath' => "$IP/customizations/",
'remoteBasePath' => "$wgScriptPath/customizations/"
);
function efCustomBeforePageDisplay( &$out, &$skin ) {
$out->addModules( array( 'zzz.customizations' ) );
}
Where vector is the name of the skin, and skin-vector.js is the JavaScript file that only goes with that skin.

Related

Error No font or default font set in mpdf 6.1

I'm using codeigneiter in my system and mpdf 6.1 to generate pdf. When i'm adding new font in ttfont, then i get eror "No font or default font set!", code in my html to print:
$mpdf = new mPDF('utf-8','A4','');
$mpdf->fontDir = './third_party/mPDF/ttfont/'; /* location to save new font */
$mpdf->fontdata['ampleSoft'] = array(
'R' => "ampleSoft-bold.ttf",
'B' => "AmpleSoft-Medium.ttf",
);
$mpdf->SetFont('ampleSoft');
And in file config_fonts i'm adding new code:
'ampleSoft' => array(
'R' => 'AmpleSoft-Medium.ttf',
'B' => 'ampleSoft-bold.ttf'
)
What's wrong with that?
fontDir variable is not available in mPDF 6.x. Define the path in _MPDF_TTFONTPATH constant. You may need to duplicate used font files from the distribution to your custom directory.
https://mpdf.github.io/fonts-languages/fonts-in-mpdf-6-x.html

Wordpress: programmatically create sub menu for frontend

I'd like to write a wordpress-plugin, where you can add a page.
If you submit the page it should also create a submenu under the menu "Teams".
Until now I can create a page through my code, but not the submenu.
I tried different functions I found on google, but nothing will work.
Does anyone know a function or a script that will help?
Yes sure, use the following as a sample to get you going. The clause to check if you are in the right menu may need altering or deleting if you don't have multiple menu objects defined.
menu_item_parent is vital and that is the parent item uid. find that by viewing your front end source code. You should find that each menu item inserted via WP menu creating functions inserts the unique items id.
// add a sub menu dynamically via code!
function aj_add_menu_item( $items, $args ) {
// check we are in the right menu
if( $args -> theme_location =="primary" ) {
$new_links = array();
// Create a nav_menu_item object
$newItem = array(
'title' => "Offers",
'menu_item_parent' => 71,
'ID' => 'loginout',
'db_id' => '12312332', // something random
'url' => "offers",
'classes' => array( 'menu-item' )
);
$items[] = (object) $newItem; // add to end of existing object.
menu_item_parent value will ensure it goes in right place
return $items;
}else{
return $items;
}
}
add_filter( 'wp_nav_menu_objects', 'aj_add_menu_item', 10, 2 );

cmb2 tinymce menu bar not showing

I'm using CMB2 to allow for front end submissions using a custom post type. The code works well but the problem is that it doesn't support menu bar. There's the textarea, submit button and the title but menu bar is not showing. What could be the problem?
Below is my code:
$cmb->add_field( array(
'name' => __( 'New Post Content', 'wds-post-submit' ),
'id' => 'submitted_post_content',
'type' => 'wysiwyg',
'options' => array(
'wpautop' => true, // use wpautop?
'media_buttons' => true, // show insert/upload button(s)
'textarea_name' => $editor_id, // set the textarea name to something different, square brackets [] can be used here
'textarea_rows' => get_option('default_post_edit_rows', 10), // rows="..."
'tabindex' => true,
'editor_css' => '', // intended for extra styles for both visual and HTML editors buttons, needs to include the `<style>` tags, can use "scoped".
'editor_class' => '', // add extra class(es) to the editor textarea
'teeny' => false, // output the minimal editor config used in Press This
'dfw' => false, // replace the default fullscreen with DFW (needs specific css)
'tinymce' => array(
'menubar' => true;
), // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
),
) );
A little late, but: change
'menubar' => true;
to
'menubar' => true,

How to remove or change powered by text in elgg?

I am using elgg 2.0(alpha). Now i want to remove powered by text (in footer) and write my site name.
Default text is Powered by Elgg and link to http://elgg.org.
How can i change/remove this?
You can use the elgg basic function for that.
First register the method in init.
function theme_init() {
elgg_register_event_handler('pagesetup', 'system', 'theme_pagesetup', 1000);
}
And then
function theme_pagesetup() {
elgg_register_menu_item('footer', ElggMenuItem::factory(array(
'name' => 'powered',
'text' => 'My site', `keep empty if you dont want`
'href' => 'http://website.com',
'section' => 'meta',
'priority' => 1,
)));
}
Using this you can easily remove/change footer text.

How to add a link in MediaWiki VisualEditor Toolbar?

I`m trying to insert a custom link to a special page in VisualEditor toolbar. See the image below.
See Image
I googled a lot but without success. Someone please give a path...
My answer is based on the following resources:
MediaWiki core JS doc (ooui-js)
VisualEditor JS doc (+ reading code of both repositories used for VE, mediawiki/extension/VisualEditor and VisualEditor)
Also, I'm pretty sure, that there is no documented way of adding a tool to the toolbar in VE, as far as I know. Although it's possible to add a tool to a group, which is already added, mostly used for the "Insert" tool group, like in Syntaxhighlight_GeSHi). There is, probably, a much easier or "better" way of doing this :)
First, VisualEditor provides a way to load additional modules (called plugins) when the main part of VE loads (mostly, when you click the "Edit" button). The modules needs to be registered via the global variable $wgVisualEditorPluginModules (or the equivalent in extension.json, if you're using the new extension registration). In your extension registration file, you should initialize a module (with your required script files to add the tool) and add it as a VE plugin.
Example PHP (old extension registration via PHP files):
// other setup...
$wgResourceModules['ext.extName.visualeditor'] = array(
'localBasePath' => __DIR__,
'remoteExtPath' => 'extName'
'dependencies' => array(
'ext.visualEditor.mwcore',
),
'scripts' => array(
'javascripts/ve.ui.ExtNameTool.js',
),
'messages' => array(
'extname-ve-toolname',
),
);
$wgVisualEditorPluginModules[] = 'ext.extName.visualeditor';
// other setup...
extension.json (new JSON-based extension registration):
// other setup...
"ResourceModules": {
"ext.geshi.visualEditor": {
"scripts": [
"javascripts/ve.ui.ExtNameTool.js"
],
"dependencies": [
"ext.visualEditor.mwcore"
],
"messages": [
"extname-ve-toolname"
]
}
},
"VisualEditorPluginModules": [
"ext.extName.visualeditor"
],
// other setup...
Now, if VE starts, it will load your module, named ext.extName.visualeditor in this example, with the script ve.ui.ExtNameTool.js. In this script, you can now do, what ever you want. As an example, this is a way to add a new module to the end of the toolgroup list in the toolbar:
Example of ve.ui.ExtNameTool.js:
( function () {
// create a new class, which will inherit ve.ui.Tool,
// which represents one tool
ve.ui.extNameTool = function extNameTool( toolGroup, config ) {
// parent constructor
ve.ui.extNameTool.super.apply( this, arguments );
// the tool should be enabled by default, enable it
this.setDisabled( false );
}
// inherit ve.ui.Tool
OO.inheritClass( ve.ui.extNameTool, ve.ui.Tool );
// every tool needs at least a name, or an icon
// (with the static property icon)
ve.ui.extNameTool.static.name = 'extname';
// don't add the tool to a named group automatically
ve.ui.extNameTool.static.autoAddToGroup = false;
// prevent this tool to be added to a catch-all group (*),
although this tool isn't added to a group
ve.ui.extNameTool.static.autoAddToCatchall = false;
// the title of the group (it's a message key,
// which should be added to the extensions i18n
// en.json file to be translateable)
// can be a string, too
ve.ui.extNameTool.static.title =
OO.ui.deferMsg( 'extname-ve-toolname' );
// onSelect is the handler for a click on the tool
ve.ui.extNameTool.prototype.onSelect = function () {
// show an alert box only, but you can do anything
alert( 'Hello' );
this.setActive( false );
}
// needs to be overwritten, but does nothing so far
ve.ui.extNameTool.prototype.onUpdateState = function () {
ve.ui.extNameTool.super.prototype.onUpdateState.apply( this, arguments );
}
// the tool needs to be registered to the toolFactory
// of the toolbar to be reachable with the given name
ve.ui.toolFactory.register( ve.ui.extNameTool );
// add this tool to the toolbar
ve.init.mw.Target.static.toolbarGroups.push( {
// this will create a new toolgroup with the tools
// named in this include directive. The naem is the name given
// in the static property of the tool
include: [ 'extname' ]
} );
} )();
After installing the extension in your LocalSettings.php and starting VE, you should see a new tool in the toolbar with the given name. Clicking it will show an alert box with content "Hello". Like written in the inline comments: In the click handler (onSelect) you can do whatever you want, e.g. open a link in a new tab, e.g. to a Special page. To get the link to a special page I would suggest to use mw.Title to get a localized namespace. For example:
var relativeUrl = mw.Title.newFromText( 'RecentChanges', -1 ).getUrl();
The first parameter of mw.Title.newFromText() is the name of the page, the second parameter is the ID of the namespace (-1 is the default for special pages and should always work).
I hope that helps!
I am not sure I understand your question entirely. It is as simple as selecting some text, clicking the chain icon, then clicking the External Link tab and pasting your link there.