Page MenuHomePhabricator

Remove Skin::drawCategoryBrowser and $wgUseCategoryBrowser
Closed, ResolvedPublic

Description

drawCategoryBrowser

Never extended:
https://codesearch.wmcloud.org/search/?q=function%20drawCategoryBrowser&i=nope&files=&excludeFiles=&repos=

or enabled in production:
https://codesearch.wmcloud.org/search/?q=UseCategoryBrowser&i=nope&files=&excludeFiles=&repos=

I think these belong better in an extension. If they are still used we should add a hook to enable this.

TODO

  • Support the extension
  • Create the extension
  • Document

Event Timeline

Jdlrobson renamed this task from Remove Skin::drawCategoryBrowser and to Remove Skin::drawCategoryBrowser and $wgUseCategoryBrowser.Jan 4 2022, 7:30 PM
Jdlrobson updated the task description. (Show Details)
Jdlrobson added subscribers: Mainframe98, ashley.

Seems reasonable. 👍 The only users of this obscure feature I was able to find are two old wikiHow skins ("HowTo", the pre-July/August 2013 skin, and its precedessor, "Bubbles") and the removal of the core code should not impact either of those in any way, shape or form for they essentially reimplement the core logic (albeit badly).

Change 751687 had a related patch set uploaded (by Ammarpad; author: Ammarpad):

[mediawiki/core@master] Remove experimental $wgUseCategoryBrowser and code

https://gerrit.wikimedia.org/r/751687

I took a stab at implementing this in an extension. It's trivial provided there is a hook that gets called in Skin::getCategoryLinks. I wrote a POC patch that I'll upload shortly. However, given that $wgUseCategoryBrowser is apparently experimental, I wonder if we should even bother with adding a new hook. Perhaps mailing wikitech-l can give some insight into that.

Googling, I found $wgUseCategoryBrowser used only by Miraheze in their ManageWiki extension, which allows administrators to enable it. @RhinosF1, can you share information about the usage of $wgUseCategoryBrowser on Miraheze wikis? (Assuming you have access and are allowed to share it).

Change 751759 had a related patch set uploaded (by Mainframe98; author: Mainframe98):

[mediawiki/core@master] POC: Add a hook to add extra category links

https://gerrit.wikimedia.org/r/751759

Regarding making it possible for this feature to be inside an extension, I was thinking that we could make categories a type of portlet/navigation menu (I've been planning to write out some similar tasks for the footer). That way it would be able to use SkinAfterPortlet and SkinTemplateNavigation::Universal hooks instead of introducing a new hook.

e.g.

diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php
index c24fac5ca0..d6b7e34748 100644
--- a/includes/skins/Skin.php
+++ b/includes/skins/Skin.php
@@ -2217,6 +2217,7 @@ abstract class Skin extends ContextSource {
         */
        final public function makeLink( $key, $item, $linkOptions = [] ) {
                $options = $linkOptions + $this->defaultLinkOptions;
+               if ( $item['html'] ?? null ) return $item['html']; // already converted to link. We'll use these for special portlets which don't allow full customization of link.
                $text = $item['text'] ?? $this->msg( $item['msg'] ?? $key )->text();
 
                $html = htmlspecialchars( $text );
diff --git a/includes/skins/SkinTemplate.php b/includes/skins/SkinTemplate.php
index d05473ac82..fe413a6b71 100644
--- a/includes/skins/SkinTemplate.php
+++ b/includes/skins/SkinTemplate.php
@@ -1192,6 +1192,18 @@ class SkinTemplate extends Skin {
                $action = $this->getAction();
                $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
 
+               $categories = []; // here for now, but would be in a function called getCategoryNavigationData(). We'd also update Skin::getCategories to use this data for backwards compatibility
+               foreach ( $this->getOutput()->getCategoryLinks() as $group => $links ) {
+                       $allLinks = [];
+                       $groupName = 'category-' . $group;
+                       foreach ( $links as $i => $link ) {
+                               $allLinks[$groupName . '-' . $i] = [
+                                       'html' => $link,
+                               ];
+                       }
+                       $categories[$groupName] = $allLinks;
+               }
+
                $content_navigation = [
                        // Modern keys: Please ensure these get unset inside Skin::prepareQuickTemplate
                        'user-interface-preferences' => [],
@@ -1206,6 +1218,9 @@ class SkinTemplate extends Skin {
                        'actions' => [],
                        'variants' => []
                ];
+               foreach ( $categories as $group => $definition ) {
+                       $content_navigation[$group] = $definition;
+               }
 
                $userCanRead = $this->getAuthority()->probablyCan( 'read', $title );

Change 751759 abandoned by Mainframe98:

[mediawiki/core@master] POC: Add a hook to add extra category links

Reason:

In T298553#7598960, a better solution than just exposing HTML is proposed. This is a POC.

https://gerrit.wikimedia.org/r/751759

I took a stab at implementing this in an extension. It's trivial provided there is a hook that gets called in Skin::getCategoryLinks. I wrote a POC patch that I'll upload shortly. However, given that $wgUseCategoryBrowser is apparently experimental, I wonder if we should even bother with adding a new hook. Perhaps mailing wikitech-l can give some insight into that.

Googling, I found $wgUseCategoryBrowser used only by Miraheze in their ManageWiki extension, which allows administrators to enable it. @RhinosF1, can you share information about the usage of $wgUseCategoryBrowser on Miraheze wikis? (Assuming you have access and are allowed to share it).

Didn't see the ping but just caught Jon's email. We'll have a look later at stats and reach out to those affected.

Community was notified about the removal of $wgUseCategoryBrowser with the following email.

I guess T35614 can be closed once the parameter was removed.

Regarding making it possible for this feature to be inside an extension, I was thinking that we could make categories a type of portlet/navigation menu (I've been planning to write out some similar tasks for the footer). That way it would be able to use SkinAfterPortlet and SkinTemplateNavigation::Universal hooks instead of introducing a new hook.

Love it! It's what I've been doing with MediaWiki-skins-Mirage already, which is why the category browser doesn't work with Mirage. (That was fun trying to figure out why it didn't work)

@Mainframe98 if you care to try it out there's a WIP patch I've just published which captures the general direction we're working towards - https://gerrit.wikimedia.org/r/c/mediawiki/core/+/726995

In this patch, the template data data-portlets entry contains hidden, normal categories as well as footer links giving more control to category and footer rendering and making them more extensible. Would be interested in you trying it out?

Community was notified about the removal of $wgUseCategoryBrowser with the following email.

Thanks a bunch. Let us know if there's any interest in an extension that retains this functionality!

Community was notified about the removal of $wgUseCategoryBrowser with the following email.

Thanks a bunch. Let us know if there's any interest in an extension that retains this functionality!

You are welcome. Admittedly this parameter was not really on my radar thus I have never used it. From wikis I attend to there was never really a request for this feature if I recall correctly.

For the historical perspective I wrote that feature in June 2004: https://www.mediawiki.org/wiki/Special:Code/MediaWiki/3888 , the intent was to ease browsing through parent categories similar to how it was done on Dmoz back in the days. So potentially when browsing MediaWiki article you would see an entry such as:

ContentsArticlesMain topic classificationsEducationEducation MaterialsReference WorksEncyclopediasOnline EncyclopediasWikipediaHistory of Wikipedia

English Wikipedia apparently has a root category ( https://en.wikipedia.org/wiki/Category:Contents ) which is rather convenient but the real example above shows that is it not really practical when a wiki has a lot of categories.

On smaller wikis it was quite helpful when there is just a few categories, that made it easier to navigate / browse without having having to rely on hand crafted navigation box.

Anyway I am happy to get it dropped since I don' t think anyone is actively using it.

@Mainframe98 if you care to try it out there's a WIP patch I've just published which captures the general direction we're working towards - https://gerrit.wikimedia.org/r/c/mediawiki/core/+/726995

In this patch, the template data data-portlets entry contains hidden, normal categories as well as footer links giving more control to category and footer rendering and making them more extensible. Would be interested in you trying it out?

Thanks. I'm having issues actually making a working prototype with it - though I definitely prefer the approach that patch takes. Depending on how much usage the category browser sees (as in, if anyone is interested in having it in an extension), we can create the extension when that patch is merged instead.

Seems reasonable. 👍 The only users of this obscure feature I was able to find are two old wikiHow skins ("HowTo", the pre-July/August 2013 skin, and its precedessor, "Bubbles") and the removal of the core code should not impact either of those in any way, shape or form for they essentially reimplement the core logic (albeit badly).

Hi,

I guess I'm also one of the obscure users of categories. I find it pretty useful and would be greatful if similar functionality could be implemented as an extension.

The way I use it is to list wiki pages related to a specific subject. Here is an example: https://wiki.tnonline.net/w/Category:Btrfs

Thanks.

This comment was removed by Forza1000.

@Forza1000 thanks for letting me know. I'll make sure we have some kind of solution for the 1.38 release T298801.

@Forza1000 thanks for letting me know. I'll make sure we have some kind of solution for the 1.38 release T298801.

This sounds great and it is much appreciated. I'd be happy to try something out/beta test.

Change 751687 merged by jenkins-bot:

[mediawiki/core@master] Remove experimental $wgUseCategoryBrowser and code

https://gerrit.wikimedia.org/r/751687

Change 753485 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/core@master] Reference CategoryExplorer extension in release notes

https://gerrit.wikimedia.org/r/753485

Change 753485 merged by jenkins-bot:

[mediawiki/core@master] Reference CategoryExplorer extension in release notes

https://gerrit.wikimedia.org/r/753485

Jdlrobson claimed this task.

All done. Thanks to everyone who provided feedback.
TLDR: If you want to continue to use this feature or develop this feature, there is now a dedicated extension at https://www.mediawiki.org/wiki/Extension:CategoryExplorer