Extension talk:Cumulus

From mediawiki.org
Latest comment: 14 years ago by Kabanoff
  • Categories are recovered by a sub-version of Extension:NiceCategoryList2 extension

No flash error[edit]

  • I followed the instructions on the page, but it doesn't seem to work for me: http://www.coreboot.org/User:Stepan -- the second cumulus tag on the page prints a message "This will be shown to users with no Flash or Javascript.", and the first one has an empty tag cloud. Any ideas?
    • It is because the SWFObject is now incompatible - if you use the swfobject.js from the wordpress package, then you should be Ok - it worked for me! Turbo Dragon 12:32, 29 September 2009 (UTC)Reply
      • No, sorry, no luck with any version of SWFObject. I don't think this is the problem. Meanwhile I can't get any output from the plugin at all anymore, but I do get this in the logs:
 [08-Apr-2010 23:27:16] PHP Warning:  Parameter 3 to CumulusWiki::hookCumulus() expected to be a reference, value given in /srv/www/vhosts/www.coreboot.org/includes/parser/Parser.php on line 3243
  • Ha, found it:
--- cumulus.php.orig    2010-04-08 23:12:49.000000000 +0200
+++ cumulus.php 2010-04-09 00:06:11.000000000 +0200
@@ -167,7 +167,7 @@
      *                 in $this->settings.
      *     $parser     Parser handle.
      */
-    public function hookCumulus($category, $argv, &$parser) {
+    public function hookCumulus( $category, $argv, $parser, $frame ) {
         // Get any user-specified parameters, and save them in $this->settings.
         $this->settings = array_merge($this->settings, $argv);

This fixes Cumulus for my MediaWiki version (1.15.3 by now). It does not fix the issue of several <cumulus> instances on the same page causing a a "No Flash" error, but that's not critical since I only used it for testing...

base[edit]

You must replace Category:Base_Category by the top category of the tree

My version for no sub-category[edit]

Hi - I had trouble with this in my wiki which has few categories. The main problem seemed to be that only sub-categories were being added, and that I don't have a main "root" category...

So I used the tagcloud extension code to make the extension show all of the categories. Also in the code are some filename fixes as the original assumed that /extension was a link to the extensions folder - this should probably use system-wide mw constants though... Turbo Dragon 13:47, 29 September 2009 (UTC)Reply

<?php



if (!defined('MEDIAWIKI')) die();

$wgExtensionFunctions[] = 'wfCumulusWiki';
$wgExtensionCredits['parserhook'][] = array(
  'name' =>        'CumulusWiki',
  'author' =>      'Luc',
  'url' =>         'http://www.mediawiki.org/w/index.php?title=Extension:Cumulus',
  'description' => 'WP-Cumulus Port to mediawiki',
);


/*
 * Sets a parser hook for <cumulus></cumulus>.
 */
function wfCumulusWiki() {
    new CumulusWiki();
}


/*
 * Simple class to hold category's title, links list,
 * and categories list., taken from NiceCategoryList extension
 */
class CumulusWiki_Links {

    private $title;
    private $articles = array();
    private $categories = array();
    private $subcats = array();

    public function __construct($title) {
        $this->title = $title;
    }


    public function addCategory($title, $links) {
        $this->subcats[] = $title;
        if ($links)
                $this->categories[] = $links;
    }


    public function addArticle($title) {
        $this->articles[] = $title;
    }


    /*
     * Get the title of this category.
     */
    public function getTitle() {
        return $this->title;
    }


    /*
     * Get the titles of the sub-categories of this category.
     */
    public function getCatTitles() {
        return $this->subcats;
    }


    /*
     * Get the titles of the articles in this category.
     */
    public function getArtTitles() {
        return $this->articles;
    }


    /*
     * Get the link records of the sub-categories of this category,
     * if we have them.
     * Returns an array of CumulusWiki_Links objects.
     */
    public function getCategories() {
        return $this->categories;
    }


    /*
     * Return true iff we have link records for the sub-categories
     * of this category.
     */
    public function hasCatLinks() {
        return count($this->categories) > 0;
    }


    /*
     * Title comparison function
     */
    private function titleCmp($a, $b) {
        return $a->getText() > $b->getText();
    }

    /*
     * CumulusWiki_Links comparison function
     */
    private function categoryCmp($a, $b) {
        return self::titleCmp($a->title, $b->title);
    }

    /*
     * Sort links and categories alphabetically.
     */
    public function sort() {
        usort($this->articles, array(&$this, "titleCmp"));
        usort($this->categories, array(&$this, "categoryCmp"));
    }

}


class CumulusWiki {

    ////////////////////////////////////////////////////////////////////////
    // Configuration
    ////////////////////////////////////////////////////////////////////////

    /*
     * Default settings for the category list.
     */
    private $settings = array(
        'maxdepth'  => 32,           // Sanity stop level.
        'style'     => 12,     // No du style WP-Cumulus
        'showcats'  => 1,            // Non-0 to display sub-cat links in a category.
        'showarts'  => 1,            // Non-0 to display article links in a category.
        'headings'  => 'head',       // Show category headings as headings.
        'headstart' => 1,            // Heading level to start at.
        'sort'      => 0,            // Non-0 to sort the list alphabetically;
                'color'         =>'0x242424',
                'hicolor'       =>'0x996600'


    );


    ////////////////////////////////////////////////////////////////////////
    // Constructor
    ////////////////////////////////////////////////////////////////////////

    /*
     * Setup Nice Category List extension.
     * Sets a parser hook for <ncl></ncl>.
     */
    public function __construct() {
            global $wgParser;
            $wgParser->setHook('cumulus', array(&$this, 'hookCumulus'));
    }


    ////////////////////////////////////////////////////////////////////////
    // Hook
    ////////////////////////////////////////////////////////////////////////

    /*
     * The hook function.  Handles <ncl></ncl>.
     *     $category   The tag's text content
     *                 this is the name of the category we want to index.
     *     $argv       List of tag parameters; these can be any of the settings
     *                 in $this->settings.
     *     $parser     Parser handle.
     */
    public function hookCumulus($category, $argv, &$parser) {
        // Get any user-specified parameters, and save them in $this->settings.
        foreach ($argv as $key => $value)
            $this->settings[$key] = $value;

        $MIN_SIZE = 77;
        $INCREASE_FACTOR = 100;

        global $wgScript;
        $dbr = &wfGetDB(DB_SLAVE);
        extract($dbr->tableNames('categorylinks'));

        $cloud_style = @$params['style'];
        $cloud_classes = preg_split( '/\s+/', @$params['class'] );
        array_unshift( $cloud_classes, "tagcloud" );
        $link_style = $params['linkstyle'];
        $link_classes = preg_split( '/\s+/', @$params['linkclass'] );
        $min_count_input = getBoxExtensionOption($input, "min_count");
        $min_size_input = getBoxExtensionOption($input, "min_size");
        $increase_factor_input = getBoxExtensionOption($input, "increase_factor");
        if ($min_size_input != null) {
                $MIN_SIZE = $min_size_input;
        }
        if ($increase_factor_input != null) {
                $INCREASE_FACTOR = $increase_factor_input;
        }
        if ($min_count_input == null) {
                $min_count_input = 0;
        }

        $excluded_input = getBoxExtensionOption($input, "exclude");

        $exclude_condition = "";
        if (strlen($excluded_input) > 0) {
                $excluded_categories = explode(",", $excluded_input);
                if (count($excluded_categories) > 0) {
                        $exclude_condition = " WHERE cl_to NOT IN (";
                        for ($i = 0; $i < count($excluded_categories); $i++) {
                                $exclude_condition = $exclude_condition . "'" . trim($excluded_categories[$i]) . "'";
                                if ($i < count($excluded_categories) - 1) {
                                        $exclude_condition = $exclude_condition . ",";
                                }
                        }
                        $exclude_condition = $exclude_condition . ")";
                }
        }

        // Get the database handle, and get all the category links for
        // this category.
        $dbr =& wfGetDB(DB_SLAVE);

        $sql = "SELECT cl_to as title, COUNT(*) as count FROM $categorylinks  " . $exclude_condition . " GROUP BY cl_to HAVING count >= $min_count_input ORDER BY cl_to ASC";

        $res = $dbr->query($sql);
        $count = $dbr->numRows($res);

        $tagList = "";

        $min = 1000000;
        $max = -1;


        // find biggest and smallest categories
        for ($i = 0; $i < $count; $i++) {
                $obj = $dbr->fetchObject($res);
                $tags[$i][0] = $obj->title;
                $tags[$i][1] = $obj->count;
                if ($obj->count < $min) {
                        $min = $obj->count;
                }
                if ($obj->count > $max) {
                        $max = $obj->count;
                }
        }

        // Now - go through the categories and put them into the list

        for ($i = 0; $i < $count; $i++) {
                $textSize = $MIN_SIZE + ($INCREASE_FACTOR * ($tags[$i][1])) / ($max);
                $title = Title::makeTitle( NS_CATEGORY, $tags[$i][0] );

                //if( $style != '' && $style{-1} != ';' ) $style .= ';';
                //$style .= "font-size: {$textSize}%;";
                $style = $textSize/10;

                //$output .=  "<a href='" . $title->getLocalURL() . "' style='".$style."' color='".$this->settings['color']."' hicolor='".$this->settings['hicolor']."'>" . $title->getText() . "</a>";
                $output .=  "<a href='" . $title->getLocalURL() . "' style='".$style."' color='".$this->settings['color']."' hicolor='".$this->settings['hicolor']."'>" . $title->getText() . "</a>";

                //$currentRow = "<a class=\"" . implode( ' ', $link_classes ) . "\" style=\"{$style}\" href=\"" . $title->getLocalURL() . "\">" . $title->getText() . "</a>&nbsp; ";
        }

        $output="
        <script type=\"text/javascript\" src=\"/mediawiki/extensions/cumulus/swfobject.js\"></script>




        <div id=\"flashcontent\"></div>

        <script type=\"text/javascript\">
                var so = new SWFObject(\"/mediawiki/extensions/cumulus/tagcloud.swf\", \"tagcloud\", \"250\", \"250\", \"7\", \"#ffffff\");
                // uncomment next line to enable transparency
                so.addParam(\"wmode\", \"transparent\");
                so.addVariable(\"tcolor\", \"0x333333\");
                so.addVariable(\"mode\", \"tags\");
                so.addVariable(\"distr\", \"true\");
                so.addVariable(\"tspeed\", \"100\");
                so.addVariable(\"tagcloud\", \"<tags>$output</tags>\");
                so.write(\"flashcontent\");
        </script>



";


        $localParser = new Parser();

        return $output;
    }


    ////////////////////////////////////////////////////////////////////////
    // Database Access
    ////////////////////////////////////////////////////////////////////////

    /*
     * Get all of the direct and indirect members of a given category: ie.
     * all of the articles and categories which belong to that category
     * and its children.
     *     $dbr        The database handle
     *     $catTitle   The Title object for the category to search
     *     $depth      Our current recursion depth: starts at 0
     *     $processed  List of categories that have been searched to date
     *                 (to prevent looping)
     *
     * Returns null if this category has already been searched; otherwise,
     * a CumulusWiki_Links object for the given category, containing all
     * the sub-categories and member articles.
     */
    private function searchCategory($dbr, $catTitle, $depth, $processed = array()) {
        // Avoid endless recursion by making sure we haven't been here before.
        if (in_array($catTitle->getText(), $processed))
            return null;
        $processed[] = $catTitle->getText();

        // Get all of the category links for this category.
        $links = $this->getCategoryLinks($dbr, $catTitle);

        // Build a list of items which belong to this category.
        $cl = new CumulusWiki_Links($catTitle);
        foreach ($links as $l) {
                // Make a Title for this item.
            $title = Title::makeTitle($l->page_namespace, $l->page_title);

            if ($title->getNamespace() == NS_CATEGORY) {
                // This item is itself a category: recurse to find all its
                // links, unless we've hit maxdepth.
                $subLinks = null;
                if ($depth + 1 < $this->settings['maxdepth'])
                    $subLinks = $this->searchCategory($dbr, $title,
                                                      $depth + 1, $processed);

                // Record the subcategory name, and its links if we got any.
                $cl->addCategory($title, $subLinks);
            } else {
                // This is a regular page; just add it to the list.
                $cl->addArticle($title);
            }
        }

        // Sort the item lists, if requested.  (Thanks, Jej.)
        //if ($this->settings['sort'])
          //  $cl->sort();

        return $cl;
    }


    /*
     * Get all of the direct members of a given category.
     *     $dbr        The database handle
     *     $title      The Title object for the category to search
     *
     * Returns an array of objects, each representing one member of the named
     * caregory.  Each object contains the following fields from the database:
     *      page_title
     *      page_namespace
     *      cl_sortkey
     */
    private function getCategoryLinks($dbr, $title) {
            // Query the database.
        $res = $dbr->select(
            array('page', 'categorylinks'),
            array('page_title', 'page_namespace', 'cl_sortkey'),
            array('cl_from = page_id', 'cl_to' => $title->getDBKey()),
            '',
            array('ORDER BY' => 'cl_sortkey')
        );
        if ($res === false)
                return array();

        // Convert the results list into an array.
        $list = array();
        while ($x = $dbr->fetchObject($res))
                $list[] = $x;

        // Free the results.
        $dbr->freeResult($res);

        return $list;
    }


    ////////////////////////////////////////////////////////////////////////
    // Output
    ////////////////////////////////////////////////////////////////////////

    /*
     * Generate output for the list.
     */
    function outputCategory($category, $level = 0) {
        global $wgContLang;

        $output = '';

        // The second level and onwards has a heading.
        // The heading gets smaller as the level grows.
        if ($level > 0) {
            $title = $category->getTitle();
            $ptitle = $title->getPrefixedText();
            $title = $wgContLang->convert($title->getText());
            $link = "[[:" . $ptitle . "|'''" . $title . "''']]";


               $output .=  "<a href='http://".$_SERVER['SERVER_NAME']."/index.php?title=Category:$title' style='".$this->settings['style']."' color='".$this->settings['color']."' hicolor='".$this->settings['hicolor']."'>$title</a>";

        }




        // Recurse into each subcategory.
        $subCategories = $category->getCategories();
        foreach ($subCategories as $cat)
                        {
                        $cttemp=$this->outputCategory($cat, $level + 1);
            $output .= $this->outputCategory($cat, $level + 1);

                        }


        return $output;
    }

}

Extension don't work properly[edit]

It does not work properly for me, I have the same message: "This will be shown to users with no Flash or Javascript." (see pic.). I have read a manual, used various combinations of installation and the distribution kit, but it has not helped me.

Extension don't work properly

My version of system:

  • MediaWiki: 1.15.0
  • PHP: 5.2.8 (apache2handler)
  • MySQL: 5.1.30-community-log

Your extension is very useful, I'd like to use it in my wiki. Thanks. Kabanoff 13:34, 10 December 2009 (UTC)Reply

version of swfobjet[edit]

API of swfobject changed with versions 2.0 and upper. You MUST use version 1.5 max to make this extension work, which can be found here [1]

JP Ayanidès, 11:15, 12 March 2010 (UTC)

still does not work.

It depends on your relative path[edit]

On Ubuntu (10.04 server), I got the same problem. If you have the Alias /mediawiki /var/lib/mediawiki active in your /etc/mediawiki/apache.conf, you could change some lines in the cumulus.php, so that the extensions can be found. See the fragment in the example on this discussion page (section: #My version for no sub-category). Check the paths for swfobject.js and tagcloud.swf in this sample and compare it with yours:

        $output="
        <script type=\"text/javascript\" src=\"/mediawiki/extensions/cumulus/swfobject.js\"></script>
 
        <div id=\"flashcontent\"></div>
 
        <script type=\"text/javascript\">
                var so = new SWFObject(\"/mediawiki/extensions/cumulus/tagcloud.swf\", \"tagcloud\", \"250\", \"250\", \"7\", \"#ffffff\");
                // uncomment next line to enable transparency
                so.addParam(\"wmode\", \"transparent\");
                so.addVariable(\"tcolor\", \"0x333333\");
                so.addVariable(\"mode\", \"tags\");
                so.addVariable(\"distr\", \"true\");
                so.addVariable(\"tspeed\", \"100\");
                so.addVariable(\"tagcloud\", \"<tags>$output</tags>\");
                so.write(\"flashcontent\");
        </script>



I hope it helps...