Jump to content
  • 0

Counts of Categories associated with a page


s_pokras

Question

I'm wondering if it might be possible to add a feature to the display of each category at the bottom of each page. I'd like to display how many pages are currently in each category that is assigned to each page.

Categories:   Philadelphia (4) | Housing (7)

With this display, users will know something about the categories assigned to a page without having to click on each of them.

Stan

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

If you mean the list of categories that MediaWiki automatically makes - its possible, but would requires php programming.

 

Try adding the following to LocalSettings.php:

 

$wgHooks['OutputPageMakeCategoryLinks'][] = function( $outputPage, $categories, &$links ) { 
                global $wgContLang;

                $linkRenderer = MediaWiki\MediaWikiServices::getInstance()->getLinkRenderer();
                foreach ( $categories as $category => $type ) {
                        // array keys will cast numeric category names to ints, so cast back to string                      
                        $category = (string)$category;
                        $origcategory = $category;
                        $title = Title::makeTitleSafe( NS_CATEGORY, $category );
                        if ( !$title ) {
                                continue;  
                        }            
                        $wgContLang->findVariantLink( $category, $title, true );
                        if ( $category != $origcategory && array_key_exists( $category, $categories ) ) {                   
                                continue;
                        }           
                        $text = $wgContLang->convertHtml( $title->getText() );
                        $text .= ' ' . wfMessage( 'parentheses' )
                                ->numParams( Category::newFromTitle( $title )->getPageCount() )
                                ->escaped();
                        // This is not settable by hook. Which seems stupid. T180423
                        //$this->mCategories[$type][] = $title->getText();
                        $links[$type][] = $linkRenderer->makeLink( $title, new HtmlArmor( $text ) );
                }
                return false;
        };

 

Link to comment
Share on other sites

  • 0

I want to thank SamanthaNguyen for your reply. It's good to know how to get a response like you suggest, but it's not what I'm seeking.

I must thank Bawolff for the work you did in creating the code that did exactly what I was looking for! It's a thing of beauty. Here's a link to a page that demonstrates the results of applying the code you created.

http://wikidelphia.org/wiki/Philadelphia_Senate_on_Aging

The display of numbers next to each category will make it much easier for anyone using Wikidelphia to understand the relationships among the various pages. Seeing at a glance which categories represent numerous page links and which have few will allow people to more easily see distinctions among listed pages while searching for similarities.

Wikidelphia is being designed around the needs of community people for better connections: pathways for collaboration. The category system we're using is an experiment designed to offer multiple opportunities to find a page or a list of pages that meet the needs of people looking to enhance the self-sufficiency of a neighborhood. The neighborhood could be the whole Philadelphia region, or a two-block square array of homes.

Having the ability to see counts of pages associated with each category will help users and designers to more effectively choose which categories to use and which to merge. This will soon become a really handy feature for managing the Wikidelphia content.

My thanks to both of you!

Stan

Link to comment
Share on other sites

  • 0

Dear Bawolff,

You have to take some credit. You recognized the problem and knew where to find the solution... And it's working well. Of course, now that this is working, I'll try my luck to see if this solution can be refined. Here's the next level of request:

Some of our categories have both pages and subcategories. One example is Is-Church(14 C, 31 P)

But when we look at a page with the category Is-Church, we now see the sum of the pages + subcategories like this: Is-Church (45)

Do you think it's possible to make this additional level of refinement?

This idea will become even more handy as we begin to encourage people to create their own personal categories. With that feature, users will be able to create their own personal category structure. I'm hoping that this will encourage the creation and growth of useful coalitions where people can share what they know about the landscape of any community, social or political environment. It's this kind of personalization of the information that will make Wikidelphia useful in a different way than Google. People will be able to define and display the relationships among the pages on Wikidelphia.

On 11/18/2017 at 10:51 PM, bawolff said:

Your welcome, but just to ensure that I don't take credit where its not due, most of that is copied and pasted from includes/OutputPage.php with just two lines changed.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.