Topic on Talk:Structured Discussions

How can I add messages or topics count on tab bar? (ex. "Discussion (43)")

7
Anvk14 (talkcontribs)

I just want to show how many messages or themes for an article when user sees the main page of article.

Thank you for great extension!

SPage (WMF) (talkcontribs)

Here's how you would show the number of topics on the [Discussion] tab in your Special:MyPage/common.js or a Gadget:

  • make Flow's "table of contents" API request for 100 topics on Discussion page (sample)
  • in a successful API response, zero in on, in jq syntax, .flow["view-topiclist"].result.topiclist.revisions and gets its length (or maybe get the length of ...topiclist.roots, Flow API results are complicated).
  • change length to "99+" if it's 100
  • append this length to the "Discussion" tab with
    $( '#ca-talk a' ).append( ' <span style="color: orange"><small>' + length + '</small></span>');
    

If you're already viewing the Discussion page there might be a way to reuse the API requests the Flow board has already made or the HTML it has already produced.

"Those who can, do, those who can't, pseudocode" 😎

Trizek (WMF) (talkcontribs)

For the moment, discussions are attached to one specific page, but could be displayed on several pages: an article about a band can be displayed the article talk page, but also on wiki projects dedicated to the music style, or the country of origin. It may be possible to display the number of discussion attached to the page, but that is not planned for the moment. Sorry, but that would be a great idea for further developments.

SPage (WMF) (talkcontribs)

Related to this cool suggestion (an excellent opportunity for common.js hack or gadget!?), a problem with Flow-enabled talk pages is if there is no discussion, the [Discussion] tab is still blue, whereas on a regular talk page, a red [Discussion] tab tells me there has never been any discussion. The latter is a huge time-saver for people like me when editing less-trafficked pages. Is there a phab ticket to restore that?

Quiddity (WMF) (talkcontribs)

@SPage (WMF): Re: your tangential question, which probably should've been in a separate topic... ;p ... That issue is not the case when a namespace is fully enabled (e.g. the talkpages of new Catalan project-space pages), but it is the case when manually converted - I've filed phab:T117828 to determine why.

This post was hidden by Tropicalkitty (history)
Anvk14 (talkcontribs)

Hi guys and @Trizek (WMF). My little hack for this :)

$wgHooks['SkinTemplateNavigation'][] = 'replaceTabs';                
function replaceTabs( $skin, &$links) {
    if($skin->getTitle()->getNamespace() == 0){                       
        // Get themes count
        $dbr = wfGetDB( DB_SLAVE );                                      
        $cnt = $dbr->selectRowCount (
            'flow_workflow',
            ['1'],
            ['workflow_namespace'=>1, 'workflow_title_text'=>$skin->getTitle()->mDbkeyform]
        );
        $cnt -= 1;
        if($cnt > 0){
            // Set class (remove red link style)
            if($links['namespaces']['talk']['class'] =='new'){
                $links['namespaces']['talk']['class'] = 'collapsible';
            }
            // Add topics count
            $links['namespaces']['talk']['text'] .= ' ('.$cnt.')';
        }
    }
    return true;
}
Reply to "How can I add messages or topics count on tab bar? (ex. "Discussion (43)")"