I try to do stuff with hooks, but there are still issues unsolved:
- Extension:AgeClassification (Seems to work)
- Extension:WimaAdvertising (Still has issues)
--WikiForMen (talk) 20:14, 1 January 2021 (UTC)
I try to do stuff with hooks, but there are still issues unsolved:
--WikiForMen (talk) 20:14, 1 January 2021 (UTC)
Are the styling issues only in certain skins? If so, you can add skin specific styles which will be easier to maintain.
it's a bit outdated but Manual:$wgResourceModuleSkinStyles explains how you can do that (feel free to update that page)
and here's an example of it in action in Minerva:
https://github.com/wikimedia/mediawiki-skins-MinervaNeue/blob/master/skin.json#L167
For Ad1 and AD2 could you use Manual:Hooks/SkinAfterPortlet to add HTML to an existing menu? I think all the Wikimedia skins should support that, and if not that's a bug.
You'd need to check $portlet parameter to check if its AD1 or AD2
Hook SkinAfterPortlet is to add additional text to the portlet, but NOT to modify the label of the portlet, I guess?
If you are modifying the label, you can only do that in MediaWiki:Sidebar, by a translateable message or by constructing a new portlet to the sidebar using Manual:SidebarBeforeOutput
A few general Q and As can be found here: User :Jdlrobson/Skins for extension developers#Q: I want to add a new "portal" menu to the sidebar.
I see. Now I can explain you, why this will not work. The labels should be translated, if you select an other language in personal settings. Depending on the purpose, the headings should be advertisement, event notice or hint. According to your suggestion, I would now have to change the entry in the navigation bar each time... I would like to avoid precisely this annoying workload.
Hook "SidebarBeforeOutput": If there are two advertising blocks, both should be called Advertisment. How should I differentiate when assigning the HTML snippet? Can this work?
This is the reason why I enter AD1 and AD2 as markers in the sidebar, I then have distinguishable markers to which I can assign an HTML snippet and in the hack of the skin I then bend the markers AD1 and AD2 to the labels, according to the variables $wgSidebarAd1Type and $wgSidebarAd2Type. And it is precisely this that cannot be implemented with all the available hooks.
Nor is it a question of creating a new "portal" SOMEWHERE. The advertising blocks must also be positioned appropriately in the sidebar in the sidebar. But this is precisely the purpose of the AD1 and AD2 markers.
That's why I decided to drill out the skins, because the task cannot be solved with the Mediawiki hooks.
And all "examples" of the hook shit going with the test/href scheme. Actually, it still needs its custom class specifications. I have to use tricks to display the advertising blocks appropriately (background colour, spacing, border if necessary).--WikiForMen (talk) 21:56, 2 January 2021 (UTC)
The documentation is so unsatisfactory that I do not understand what the difference between Manual:Hooks/SidebarBeforeOutput and Manual:Hooks/SkinBuildSidebar is supposed to be. --WikiForMen (talk) 22:26, 2 January 2021 (UTC)
> That's why I decided to drill out the skins, because the task cannot be solved with the Mediawiki hooks.
I'm not sure I completely understand the problem here, but I'm still fairly confident you can achieve what you are doing with hooks and if it's not we should update those hooks to make it possible.
> I would like to avoid precisely this annoying workload.
HTML should be cached for each time it's generated or were you talking about something other than performance here? You can use internal caching methods if what you are doing here is very intensive but it doesn't seem that way.
> The advertising blocks must also be positioned appropriately in the sidebar in the sidebar. But this is precisely the purpose of the AD1 and AD2 markers.
And that's fine. Putting AD1 and AD2 in MediaWiki:Sidebar will create 2 elements with id's #p-AD1 and #p-AD2. These will have headings translateable at `MediaWiki:aD1` and `MediaWiki:aD2`, but can also be replaced with the SidebarBeforeOutput. Using Php array methods you can retain the same positioning with a custom heading by doing something like this...
e.g.
$wgHooks['SidebarBeforeOutput'][] = function ( $skin, &$bar ) { $newbar = []; foreach( $bar as $key => $menu ) { if ( $key === 'AD1' ) { $newbar[ 'My custom label or message key' ] = $menu; } else { $newbar[$key] = $menu; } } $bar = $newbar; };
If the above doesn't help can you provide a bug report-style account of what you are trying to do here?
e.g.
// Do this...
// Run this code
// Expected result..
// Actual result..
$wgHooks['SidebarBeforeOutput'][] = function ( $skin, &$bar ) {
$newbar = [];
foreach( $bar as $key => $menu ) {
if ( $key === 'AD1' ) {
$newbar[ 'My custom label or message key' ] = $menu;
} else {
$newbar[$key] = $menu;
}
}
$bar = $newbar;
};
is not working because of a serious problem.
$wgHooks['SidebarBeforeOutput'][] = function ( $skin, &$bar ) {
$newbar = [];
foreach( $bar as $key => $menu ) {
if ( $key === 'AD1' ) {
$newbar[ 'advertising' ] = $menu; // <== first set
} else if ( $key === 'AD2' ) {
$newbar[ 'advertising' ] = $menu; // <== overriding first set
} else {
$newbar[$key] = $menu;
}
}
$bar = $newbar;
};
You see the issue? With two ad blocks one will override the other. :-(
I did another try with array_splice
:
public static function onSkinTemplateOutputPageBeforeExec(
SkinTemplate &$skin,
QuickTemplate &$tpl
) {
global $wgSidebarAd1Code, $wgSidebarAd1Style, $wgSidebarAd1Type;
global $wgSidebarAd2Code, $wgSidebarAd2Style, $wgSidebarAd2Type;
$_key1 = empty( $wgSidebarAd1Type ) ? 'advertising' : $wgSidebarAd1Type;
$_key2 = empty( $wgSidebarAd2Type ) ? 'advertising' : $wgSidebarAd2Type;
// Transfer keys 'AD1' and 'AD2' to labels
$_modified = false;
$offset = 0;
$sidebar_new = $tpl->data['sidebar'];
foreach ( $tpl->data['sidebar'] as $key => $value ) {
switch ( $key ) {
case 'AD1' :
if ( empty( $wgSidebarAd1Code ) ) {
// Deactivate marker 'AD1' if $wgSidebarAd1Code is not defined
$sidebar_new['AD1'] = false;
} else {
// Replace array with the key 'AD1' with key $wgSidebarAd1Type
array_splice( $sidebar_new, $offset, 1, [ $_key1 => $wgSidebarAd1Code ] );
}
$_modified = true;
break;
case 'AD2' :
if ( empty( $wgSidebarAd2Code ) ) {
// Deactivate marker 'AD1' if $wgSidebarAd1Code is not defined
$sidebar_new['AD2'] = false;
} else {
// Replace array with the key 'AD2' with key $wgSidebarAd2Type
array_splice( $sidebar_new, $offset, 1, [ $_key2 => $wgSidebarAd2Code ] );
}
$_modified = true;
break;
}
++$offset;
}
if ( $_modified ) {
$tpl->set( 'sidebar', $sidebar_new );
}
}
> You see the issue? With two ad blocks one will override the other. :-(
You'll need two unique message keys that translate to the heading. Use advertising-1 and advertising-2 and define those messages in i18n/en.json
Appending ?uselang=qqx to url will show you message keys for the page.
That's dirty and by doubling the same entries an increase of the overhead, but I had already thought of that... ;-)
Why is that dirty? And what overhead are you exactly referring to here? I don't see any problem with having 2 messages using the same text. I've seen this in other extensions. The context is different. See https://github.com/wikimedia/mediawiki/blob/master/languages/i18n/en.json#L148 for example.
The benefit of turning these into translatable messages is that you give the site owner control over those headings - I imagine some people may want to blank them for example and not have a heading.
Also please consider somebody reading with a screen reader. Two portals with the same heading is going to be confusing to those users, so another use case might be translating those to "advertisement 1" and "advertisement 2".
If you want to know, why I call it dirty, have a look at the css files: https://github.com/WikiMANNia/MediaWiki-Extension-WimaAdvertising/blob/master/resources/css/Vector.css It's ugly! --WikiForMen (talk) 01:58, 5 January 2021 (UTC)
Nice! Seems easier to maintain than forking the entire skin, though? :) Using LESS might make that a bit easier to maintain as you'd be able to nest all the rules.
e.g.
#p-wimaadvertising-advertising,
#p-wimaadvertising-advertising2
....
#p-wimaadvertising-hint2 {
.body {
background-color: #ffffff;
margin-left: -.7em;
margin-top: .3em;
padding: 0 0 .1em 0;
width: auto;
}
}
I'm not that IN with css and thanks for the help and suggested solutions. :-) --WikiForMen (talk) 01:20, 6 January 2021 (UTC)
It would be less "dirty" if it was considered that #2 is only used if both are advertisements or event notes ... But at least it works now. Thanks for the help. May it be helpful for someone. :-) --WikiForMen (talk) 00:13, 3 January 2021 (UTC)