Extension:SingleLinkTagCluster

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
SingleLinkTagCluster

Release status: beta

Implementation Tag
Description Extension represents a special page Special:SingleLinkTagCluster, that allows to build a tag-cluster with desired category.
Author(s) Olga Metelytsya
Last version 1.0 (13.01.2011)
MediaWiki MediaWiki 1.14.0 or higher
PHP 5.2.8
License GPL
Download SingleLinkTagCluster.php

SingleLinkTagCluster.i18n.php SingleLinkTagCluster_body.php

Check usage (experimental)

Contents

[edit] Description

This extension was created as part of a magister thesis as a means to allow the users to build a single link tag-cluster with the input-category. The single link cluster means, two elements will be connected, that have maximal similarity between each other. This extension enables a search and display of similar categories in the form of tag-cluster.

[edit] Prerequirement

For the Usage of Extension SingleLinkTagCluster the Extension WikiCategoryTagCloud is required. The Extensions Semantic MediaWiki and Semantic Forms can be helpful for the usage of SingleLinkTagCluster, because they enable more efficient category assignment as in MediaWiki. But they are not necessary for the operation of SingleLinkTagCluster.

[edit] Usage

The extension is indispensable if you need to find all similar categories to the input-category. First you go to page Special:SingleLinkTagCluster. Then you insert in the edit field desired category and click on the button “Build the cluster with this category”. After this you get the tag-cluster. Because the tag-cluster can be too long, especially by the wikis with a lot of categories, it will be divided per three categories per line, to give the users a better overview of all cluster-categories. The cluster-categories will be sorted in descending order. Each cluster-category have in brackets the number, how much the cluster-category appears together with the input-category. The cluster-categories will be also displayed in different colors, depending on on how much pages in percent the input-category appears with the cluster-category. These features make the extension more user-friendly.


[edit] Installation

1.Please cut and paste the code SingleLinkTagCluster.php, SingleLinkTagCluster.i18n.php and SingleLinkTagCluster_body.php and place it in your wiki's extensions directory in a SingleLinkTagCluster subdirectory. ($IP/extensions/SingleLinkTagCluster) 2.Changes your wiki's LocalSettings.php file to include the line: require_once("$IP/extensions/SingleLinkTagCluster/SingleLinkTagCluster.php"); Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.


[edit] SingleLinkTagCluster.php

<?php
/**
* SingleLinkTagCluster
* This MediaWiki extension represents a [[Special:SingleLinkTagCluster|special page]],
*       that allows to build the tag-cluster.
* Extension setup file.
* Requires MediaWiki 1.8 or higher and MySQL 4.1 or higher.
* Extension's home page: http://www.mediawiki.org/wiki/Extension:SingleLinkTagCluster
*
* Copyright (c) Offenburg, 2010, Olga Metelytsya  <[email protected]>
* Distributed under GNU General Public License 2.0 or later (http://www.gnu.org/copyleft/gpl.html)
*/
 
 
# Not a valid entry point, skip unless MEDIAWIKI is defined
if ( !defined('MEDIAWIKI') ) {
        echo <<<EOT
To install this extension, put the following line in LocalSettings.php:
require_once("$IP/extensions/SingleLinkTagCluster/SingleLinkTagCluster.php" );
 
EOT;
        exit( 1 );
}
 
// credits information about this extension
$wgExtensionCredits['specialpage'][] = array(
    'name' => 'SingleLinkTagCluster',
        'version' => 1.0,
        'author' => 'Olga Metelytsya <[email protected]>',
        'description' => 'Represents a [[Special:SingleLinkTagCluster|special page]], ' .
                'that allows to create a tag-cluster.',
        'url' => 'http://www.mediawiki.org/wiki/Extension:SingleLinkTagCluster'
);
 
$wgExtensionFunctions[] = 'wfSetupSingleLinkTagClusterExtension';
 
$dir = dirname(__FILE__) . '/';
 
 
// refer to the implementation file 'SingleLinkTagCluster_body.php'
$wgAutoloadClasses['SingleLinkTagCluster'] = $dir . 'SingleLinkTagCluster_body.php';
// add SingleLinkTagCluster to specialpage
$wgSpecialPages['SingleLinkTagCluster'] = 'SingleLinkTagCluster';
 
 
// function, that calls the message file out
function wfSetupSingleLinkTagClusterExtension() {
        global $IP, $wgMessageCache;
 
        if( !function_exists('efSingleLinkTagClusterMessages') ) {
 
        // refer to the message file 'SingleLinkTagCluster.i18n.php'
                require_once( 'SingleLinkTagCluster.i18n.php' );
 
 
                foreach( efSingleLinkTagClusterMessages() as $lang => $messages )
                        $wgMessageCache->addMessages( $messages, $lang );
        }
 
        $title = Title::newFromText( 'SingleLinkTagCluster' );
 
        return true;
}

[edit] SingleLinkTagCluster.i18n.php

<?php
/**
* SigleLinkTagCluster
* This MediaWiki extension represents a [[Special:SingleLinkTagCluster|special page]],
*       that allows to build a tag-cluster.
* Internationalization file, containing message strings for extension.
* Requires MediaWiki 1.8 or higher and MySQL 4.1 or higher.
* Extension's home page: http://www.mediawiki.org/wiki/Extension:SingleLinkTagCluster
*
* Distributed under GNU General Public License 2.0 or later (http://www.gnu.org/copyleft/gpl.html)
*/
 
function efSingleLinkTagClusterMessages() {
        $messages = array();
 
        // English messages
        $messages['en'] = array(
                'singlelinktagcluster' => 'SingleLinkTagCluster',
                'singlelinktagcluster_include' => 'Please enter one category.',
                'singlelinktagcluster_comment' => 'This specialpage allows you to build the SingleLink tag-cluster with the category.',
                'singlelink_comment' => 'The SingleLink Cluster means, two elements will be connected, that have max. similarity between eachother.',
                'singlelinktagcluster_result' => 'This is a SingleLink tag-cluster to the category',
                'with' => 'With ',
                'singlelinktagcluster_colour1' => ' Teal ',
                'singlelinktagcluster_colour2' => ' Pink ',
                'singlelinktagcluster_colour3' => ' Lila ',
                'singlelinktagcluster_colour4' => ' Blau ',
                'singlelinktagcluster_colour5' => ' Green ',
                'green' => 'you see the categories, that appear with a input-category on 1% and less then 1% of pages. ',
        'teal' => 'you see the categories, that appear with a input-category on more then 1% and up to 25% of pages. ',
                'pink' => 'you see the categories, that appear with a input-category on the more then 25% and up to 50% of pages. ',
                'lila' => 'you see the categories, that appear with a input-category on the more then 50% to 75% of pages. ',
                'blau' => 'you see the categories, that appear with a input-category on the more then 75% to 100% of pages. ',
        'klammer' => 'In brackets ( ) you see the proper number of matches. ',
        'singlelinktagcluster_no_params' => 'Please, select at least one category.',
        'singlelinktagcluster_no_result' => 'This category does not exist.',
                'singlelinktagcluster_build' => 'Build the cluster with this category.',
                'tagcloud' => 'TagCloud ' ,
                'tagcloud_comment' => 'Hier you can see the existing categories. ',
                'singlelinktagcluster_no_cat' => 'No cluster can be generated with the inserted category, because no other category comes together with the inserted category . ',
        );
 
        // German messages
        $messages['de'] = array(
                'singlelinktagcluster' => 'SingleLinkTagCluster',
                'singlelinktagcluster_include' => 'Geben Sie bitte eine Kategorie ein.',
                'singlelinktagcluster_comment' => 'Diese Spezialseite bildet ein Single Link Tag-Cluster mit der eingegebenen Kategorie.',
                'singlelink_comment' => 'Beim Single Link Cluster geht es darum, dass die Elemente mit minimaler Distanz, d.h. mit maximaler Aehnlichkeit vereinigt werden. ',
                'singlelinktagcluster_result' => 'Das ist ein SingleLink Cluster zu der Kategorie ',
                'with' => 'Mit',
                'singlelinktagcluster_colour1' => ' Teal ',
                'singlelinktagcluster_colour2' => ' Pink ',
                'singlelinktagcluster_colour3' => ' Lila ',
                'singlelinktagcluster_colour4' => ' Blau ',
                'singlelinktagcluster_colour5' => ' Gruen ',
                'green' => 'sind die Kategorien markiert, die zusammen mit der eingegebenen Kategorie auf 1% und weniger als 1% der Seiten vorkommen. ',
                'teal' => 'sind die Kategorien markiert, die zusammen mit der eingegebenen Kategorie auf mehr als 1% bis 25% der Seiten vorkommen. ',
                'pink' => 'sind die Kategorien markiert, die zusammen mit der eingegebenen Kategorie auf mehr als 25% bis 50% der Seiten vorkommen. ',
                'lila' => 'sind die Kategorien markiert, die zusammen mit der eingegebenen Kategorie auf mehr als 50% bis 75% der Seiten vorkommen. ',
                'blau' => 'sind die Kategorien markiert, die zusammen mit der eingegebenen Kategorie auf mehr als 75% bis 100% der Seiten vorkommen. ',
        'klammer' => 'In Klammern ( ) ist die genaue Anzahl des Vorkommens angegeben. ',
                'singlelinktagcluster_no_params' => 'Bitte eine Kategorie angeben.',
                'singlelinktagcluster_no_result' => 'Die eingegebene Kategorie existiert nicht.',
                'singlelinktagcluster_build' => 'Cluster mit diesem Tag bilden',
                'tagcloud' => 'TagCloud ' ,
                'tagcloud_comment' => 'Hier koennen Sie die vorhandenen Kategorien anschauen. ',
                'singlelinktagcluster_no_cat' => 'Der Cluster zur der angegebenen Kategorie kann nicht erzeugt werden, da keine Kategorien mit der angegebenen Kategorie zusammen vorkommen.',
 
        );
    return $messages;
}

[edit] SingleLinkTagCluster_body.php

<?php
/**
* SingleLinkTagCluster
* version 1.0
* This MediaWiki extension represents a [[Special:SingleLinkTagCluster|special page]],
*       that allows to build tag-cluster.
* Extension setup file.
* Requires MediaWiki 1.8 or higher and MySQL 4.1 or higher.
* Extension's home page: http://www.mediawiki.org/wiki/Extension:SingleLinkTagCluster
*
* Copyright (c) Offenburg, 2010, Olga Metelytsya  <[email protected]>
* Distributed under GNU General Public License 2.0 or later (http://www.gnu.org/copyleft/gpl.html)
*/
 
// the class SingleLinkTagCluster inherits
// from the standard MediaWiki class SpecialPage
class SingleLinkTagCluster extends SpecialPage
{
    // Number of input categories,
    // to that the tag-cluster must be created.
    var $inCategoriesNumber = 1;
 
    // array, to that the input category will be added.
    var $inCategories = array();
 
    /** Method of passing parameters. Change it to 'get', if you need that method. */
    var $paramsPassMethod = 'post';
 
    // function that calls the SpecialPage SingleLinkTagCluster
    function SingleLinkTagCluster() {
        global $wgRequest;
        SpecialPage::SpecialPage( 'SingleLinkTagCluster' );
    }
 
    // the main function that will be called when a special page is accessed
    function execute( $par ) {
        global $wgRequest, $wgOut, $wgVersion;
 
        // if the MediaWiki version is smaller as 1.8, the error message appears "Error:.."
                if( version_compare( $wgVersion, '1.8', '<' ) === true ) {
                        $wgOut->showErrorPage( "Error: Upgrade required", "The News Channel 
                            extension " .
                        "can't work on MediaWiki version older than 1.8. Please, upgrade." );
                        return;
                }
 
        // if the valid request is entered, apply the function showResults()
                if( !is_null( $wgRequest->getVal( 'wpSubmitSearchParams' ) ) ||
                        stripos( $wgRequest->getRequestURL(), 'wpInCategory' ) !== false) {
                                for( $i = 1; $i <= $this->inCategoriesNumber; $i++ )
                                        $this->inCategories[$i] = $wgRequest->getVal( 'wpInCategory' . $i );
                                $this->showResults(); // apply function showResults()
                // otherwise apply the function showForm()
                } else {
                        $this->showForm();
        }
    }
 
 
    // this function builds the tag-cluster and shows the result
    function showResults() {
 
 
        global $wgRequest, $wgOut, $wgDBtype, $wgDBprefix;
 
        wfProfileIn( 'SingleLinkTagCluster::showResults' );
 
 
        // create the database object, that grants the reading access
        // to the database
        $dbr =& wfGetDB( DB_SLAVE );
 
        // check the required database version
        // if it is smaller as 4.1, error message appears 'Error:..'
                if( $wgDBtype != 'mysql' ||
                        version_compare( $dbr->getServerVersion(), '4.1', '<' ) === true ) {
                                $wgOut->showErrorPage( 'Error: Upgrade Required', 'The SingleLinkTagCluster ' .
                                        'extension requires MySQL database engine 4.1 or higher. Please, upgrade.' );
                        return;
                }
 
        // initialising the input category as string
        $inCategoriesStr = '';
        $inCategoriesCount = 0;
        for( $i = 1; $i <= $this->inCategoriesNumber; $i++ ) {
                    // if the input category is valid
                    if( $this->inCategories[$i] != null && $this->inCategories[$i] != '' ) {
                            // add this category to string and replace ' ' with '_',
                            $inCategoriesStr .=
                                $dbr->addQuotes(
                                     str_replace( ' ', '_', ucfirst( $this->inCategories[$i] ) ) ) . ',';
                            // count the entered categories
                            $inCategoriesCount++;
                     }
        }
 
 
        if( strlen( $inCategoriesStr ) > 0 )
            $inCategoriesStr = substr( $inCategoriesStr, 0, -1 );
 
 
        // if no input category exists
        if( $inCategoriesCount == 0) {
            // message appears 'Please, select at least one category.',
            $wgOut->addHTML( '<h3>' . wfMsg( 'singlelinktagcluster_no_params' ) .
                                '</h3><br /><hr /><br />' );
            // apply the function 'showForm()'
            $this->showForm();
            return;
        }
 
        else
            $exSqlQueryStr = '';
 
        // initialising the database tables 'categorylinks' and 'page'
        $catlinksTableName = $dbr->tableName( 'categorylinks' );
        $pageTableName = $dbr->tableName( 'page' );
 
 
        // search for the input category in the database table 'category'
        $catTableName = $dbr->tableName( 'category' );
        // select the input categoty from database
        $sqlInputStr =
            "SELECT {$catTableName}.cat_title AS resstr " .
            "FROM {$catTableName} " .
            "WHERE cat_title IN({$inCategoriesStr})";
 
        $res2 = $dbr->query( $sqlInputStr, 'SingleLinkTagCluster::showResults', false );
 
        // if the input category is not found in datebase
        if( $dbr->numRows($res2) == 0 ) {
             // message appears "This category doesn't exist"
             $wgOut->addHTML( '<h3>' . wfMsg( 'singlelinktagcluster_no_result' ) .
                                '</h3><br /><hr /><br />');
             $this->showForm();
             return;
        }
 
        $b = $dbr->numRows($res2);
 
                // if the input category is found in database table 'category'
        // the request will be sent to the database server
        $mysqlres2 = mysql_query($sqlInputStr);
 
        // add the request (input category) to an associative array
        $resArr = array();
        $resArr = mysql_fetch_array($mysqlres2, MYSQL_ASSOC);
        // print_r($resArr); // Output: Array([resstr]=>Input_Category)
 
        // add the input category to string $dRow1, replacing '_' with ' '
        $dRow = "";
        $dRow1 = "";
        $replacement1 = array();
        while( $row = $dbr->fetchObject( $res2 ) ) {
 
           $dRow = $row->resstr;
 
           $replacement1 = array('_' => ' ');
           $dRow1 = strtr($dRow, $replacement1);
           // echo $dRow1; // Output: 'Input Category'
        }
 
                // show some information from the message file
                // "With Blue colour are the categories highlighted, that appear ...."
        //      $msgColour1 = wfMsg( 'singlelinktagcluster_colour1' );
        $msgColour1 = wfMsgHtml( 'singlelinktagcluster_colour1' );
        $msgColour2 = wfMsgHtml( 'singlelinktagcluster_colour2' );
        $msgColour3 = wfMsgHtml( 'singlelinktagcluster_colour3' );
        $msgColour4 = wfMsgHtml( 'singlelinktagcluster_colour4' );
        $msgColour5 = wfMsgHtml( 'singlelinktagcluster_colour5' );
        $msgWith = wfMsgHtml( 'with' );
        $msgGreen = wfMsgHtml( 'green' );
        $msgTeal = wfMsgHtml( 'teal' );
        $msgPink = wfMsgHtml( 'pink' );
        $msgLila = wfMsgHtml( 'lila' );
        $msgBlau = wfMsgHtml( 'blau' );
        $msgKlammer = wfMsgHtml( 'klammer' );
        $wgOut->addHTML( "{$msgWith}<font color=#000080>{$msgColour4}</font>{$msgBlau}<br>" );
        $wgOut->addHTML( "{$msgWith}<font color=#8B008B>{$msgColour3}</font>{$msgLila}<br>" );
        $wgOut->addHTML( "{$msgWith}<font color=#CD1076>{$msgColour2}</font>{$msgPink}<br>" );
        $wgOut->addHTML( "{$msgWith}<font color=#008080>{$msgColour1}</font>{$msgTeal}<br>" );
        $wgOut->addHTML( "{$msgWith}<font color=#008000>{$msgColour5}</font>{$msgGreen}<br>" );
        $wgOut->addHTML( "{$msgKlammer}<br><br><br>" );
        $msgResultComment = wfMsgHtml( 'singlelinktagcluster_result' );
 
        // show the message, that appears to created tag-cluster
        // 'This is the SingleLink tag-cluster to the category 'Input Category' '
        $wgOut->addHTML( "<h5>{$msgResultComment} <a href=\".../../Kategorie:$dRow\"><font color=#000080>$dRow1</font></a></h5><hr />" );
 
        // Building of tag-cluster.
        // if the valid input category was entered
                if( $inCategoriesCount > 0 ) {
                        // select all categories from database table 'category' and sort
                        $sqlQueryStr =
                "SELECT{$catTableName}.cat_title AS ct " .
                                "FROM {$catTableName} " .
                                "ORDER BY {$catTableName}.cat_title";
 
                        // select all pagetitel and all categories, belonging to this pages
                        $sqlQueryStr1 =
                           "SELECT {$pageTableName}.page_title AS ns, " .
                               "{$catlinksTableName}.cl_to AS ct " .
                                "FROM {$pageTableName}, " .
                                    "{$catlinksTableName} " .
                                "WHERE {$pageTableName}.page_id = {$catlinksTableName}.cl_from " .
                                "ORDER BY {$pageTableName}.page_title";
                }
                else {
                        $sqlQueryStr =
                                "SELECT {$pageTableName}.page_namespace AS ns, " .
                               "{$pageTableName}.page_title AS title " .
                                "FROM {$pageTableName}, " .
                                        "(SELECT cl_from " .
                                        "FROM {$catlinksTableName} " .
                                        "WHERE cl_to IN({$inCategoriesStr}) " .
                                        "GROUP BY cl_from) AS matches " .
                                "WHERE {$pageTableName}.page_id NOT IN(matches.cl_from) " .
                                        "AND {$pageTableName}.page_namespace <> 8 " .
                                "ORDER BY {$pageTableName}.page_title";
                }
 
        // add all categories to an associative array $allCategories
        $mysql = mysql_query($sqlQueryStr);
        $allCategories = array();
        while($allCategories[] = mysql_fetch_array($mysql, MYSQL_ASSOC));
 
                $cat = array();
        $categoryArray=array();
 
        foreach ($allCategories as $key => $val){
           // echo $key; print_r($val); echo "<br>";
           // Output:
           // 0 Array([ct]=>Cat1)
           // 1 Array([ct]=>Cat2)
           $cat = $val;
           $categoryArray[] = $cat['ct'];
 
        }
        // print_r($categoryArray); echo "<br>";
        // Output:
        // Array([0]=>Cat1 [1]=>Cat2 [2]=>Cat3 [3]=>Cat4....)
 
        // add all pagetitles with their categories to an associative array
        $allPageTitel = array();
        $mysql1 = mysql_query($sqlQueryStr1);
        while($allPageTitel[] = mysql_fetch_array($mysql1, MYSQL_ASSOC));
        // print_r($allPageTitel);  echo "<br>";
        // Output:
        // Array([0]=>Array([ns]=>Pagetitel1 [ct]=>Cat1)
        //      ([1]=>Array[ns]=>Pagetitel1  [ct]=>Cat2)
        //      ([2]=>Array[ns]=>Pagetitel2  [ct]=>Cat3)
 
 
                // add all pagetitles to array $pageTitelArray
        $pageTitelArray = array();
        foreach($allPageTitel as $k => $tval){
          // echo $k; echo " "; print_r($tval); echo "<br>";
          // Output:
          // [0] => Array([ns]=>Pagetitel1 [ct]=>Cat1)
          // [1] => Array([ns]=>Pagetitel1 [ct]=>Cat2)
          // [2] => Array([ns]=>Pagetitel1 [ct]=>Cat3)
          if(!$tval['ns'] == ''){
            $pageTitelArray[] = $tval['ns'];
          }
        }
 
            // remove all double pagetitles from array $pageTitelArray
        $pageTitelArray1 = array();
        $pageTitelArray1 = array_unique($pageTitelArray);
        // print_r($pageTitelArray1);
        // Output: Array([0]=>Pagetitel1 [8]=>Pagetitel2 [13]=>Pagetitel3...)
 
        // enumerate all pagetitles
        $countTitle = count($pageTitelArray1);
 
        // create an array, consinting of categories as keys,
        // and an array from all belonging to this categories pagetitles as values
        $catAndPagetitel1 = array();
        $Category = '';
        $titel = '';
 
        for ($i=0; $i < count($categoryArray); $i++){
            $catAndPagetitel= array();
            $titelArray = array();
            foreach($allPageTitel as $key => $val){
              // if category form array $categoryArray equal the category form $allPageTitel Array
              if ($categoryArray[$i] == $val['ct']){
                // add this category to string
                $Category = $categoryArray[$i];
                // add the pagetitle, that belongs to this category, to string
                $titel = $val['ns'];
                // add this pagetitle to array;
                $titelArray[] = $titel;
              }
            }
            // add the category and all pagetitles, belonging to this category, to array
            $catAndPagetitel[$Category] = $titelArray;
            // print_r($catAndPagetitel); echo "<br>";
            // Output:
            // Array([Cat1] => Array([0] => Pagetitel1))
            // Array([Cat1] => Array())
            // Array([Cat2] => Array([0]=>Pagetitel1 [2]=>Pagetitel2 [3]=>Pagetitel3..))
 
                        // remove the key of Array $catAndPagetitel, if the value is empty
            $emptyArray = array();
            foreach($catAndPagetitel as $k => $values){
              if($values == $emptyArray){
                $null = $catAndPagetitel[0];
                $catAndPagetitel = array();
              }
            }
            $catAndPagetitel1[] = $catAndPagetitel;
        }
 
                // remove all empty arrays from $catAndPagetitel1
        $catAndPagetitel2 = array();
        $emptyArray1 = array();
        foreach($catAndPagetitel1 as $key => $val){
          // echo $key; echo " "; print_r($val); echo "<br>";
          // Output:
          // 0 Array([Cat1]=> Array([0] => Pagetitel1))
          // 1 Array()
          // 2 Array([Cat2]=> Array([0] => Pagetitel1 [1]=>Pagetitel2 [2]=>Pagetitel3..)) )
 
          if(!$val  == $emptyArray1){
            $catAndPagetitel2[] = $val;
          }
        }
        // foreach($catAndPagetitel2 as $key => $newval){
        // echo $key; echo " "; print_r($newval); echo "<br>";
        // Output: (without empty arrays)
        // 0 Array([Cat1]=> Array([0] => Pagetitel1))
        // 1 Array([Cat2]=> Array([0] => Pagetitel1 [1]=>Pagetitel2 [2]=>Pagetitel3..))
        // }
 
 
                // build the category similarity matrix
                $simMatrix = array();
        $catCountArray = array();
        $a = array();
        $b = array();
        $matches = array();
 
        for($i = 0; $i < count($catAndPagetitel2); $i++){
          for ($j = 0; $j < count($catAndPagetitel2); $j++){
            if (!($i == $j)){
              $a = $catAndPagetitel2[$i];
              // print_r($a); echo "<br>";
              // Output:
              // Array([Cat1] => Array([0]=>Pagetitel1 [1]=>Pagetitel2..))
              $b = $catAndPagetitel2[$j];
              // print_r($b); echo "<br>";
              // Output:
              // Array([Cat2] => Array([0]=>Pagetitel1 [1]=>Pagetitel3..))
              foreach($a as $k1 => $values1){
                foreach($b as $k2 => $v2){
                  if ( !($k1 == $k2)){
                    // array_intersect => return the values (Pagetitles) form the Array $a,
                    // that also appear in Array $b
                    $matches = array_intersect($values1, $v2);
                    // print_r($matches); echo "<br>";
                        // Output:
                        // Array([0]=>Pagetitel1)
                    $anzahl = count($matches);
                    $catCountArray[$k2] =  $anzahl; // Output: Array([Cat2]=> 1 )
                  }
                }
              }
              $simMatrix[$k1] = $catCountArray;
              // Output: Array([Cat1] => Array([Cat2] => 1 ))
              // it means, that Cat1 appears together with Cat2 one time
            }
          }
        }
        // the similarity matrix ($simMatrix) looks so:
        // foreach($simMatrix as $key => $vall){
           // echo $key; echo " "; print_r($vall); echo "<br>"; echo "<br>";
           // Output:
           // Cat1 Array([Cat1=>0 [Cat2]=>1 [Cat3]=>0 [Cat4]=>5...)
           // it means, that category1 appears with category2 one time and with
           // category4 - five times.
        // }
 
 
        // delete the key-value pair ([Cat1]=>0) of array $vall,
        // if their key (Cat1) coinsids with the key (Cat1) of array $simMatrix
        $simMatrix1=array();
        foreach($simMatrix as $key => $vall){
          foreach($vall as $k => $values){
            if ($key == $k){
              unset($vall[$k]);
            }
          }
          $simMatrix1[$key] = $vall;
        }
 
            // return cluster-categories,
        // that appear together with the input category
        // the result array will be sorted in descending order
        $resultKeysArray = array();
        foreach($simMatrix1 as $key => $val){
           // echo $key; echo " "; print_r($val); echo "<br><br>";
           // Output:
           // Cat1 Array([Cat2]=>1 [Cat3]=>0 [Cat4]=>5...)
           $key1 = "'$key'";
           if ($key1 == $inCategoriesStr){ // if $key1 (Cat1) equal the input category
             arsort($val); // sort the values of $val;
             foreach($val as $ke => $va){
                if ($va > 0){ // return categories, their value greater than 0
                  $resultKeysArray[$ke] = $va;
                }
             }
           }
        }
 
            // print_r($resultKeysArray); echo "<br>";
        // Output: result cluster-categories
        // Array([Cat6] => 9 [Cat3] => 5 [Cat2] => 4 [Cat7] => 3 [Cat4] => 2 [Cat1] = 1)
 
        // split the $resultKeysArray into 3 chunks
                $resultKeys1 = array();
        $resultKeys1 = array_chunk($resultKeysArray,3, TRUE);
        // print_r($resultKeys1); echo "<br>";
        // Output:
        // Array([0]=>Array([Cat6]=>9 [Cat3]=>5 [Cat2]=>4)
        //       [1]=>Array([Cat7]=>3 [Cat4]=>2 [Cat1]=>1)
 
 
                // in this part of programm will be
                // the html output (clutser-categories) prepared and displayed
        $sqlQueryStr2 = "";
        $sqlArr = array();
        $sqlArr1 = array();
 
        $val1 = array();
 
        $keysArray = array();
        $val4 = array();
 
 
        foreach($resultKeys1 as $key => $val){
          // print_r($val); echo "<br>";
          // Output:
          // Array([Cat6]=>9 [Cat3]=>5 [Cat2]=>4)
          // Array([Cat7]=>3 [Cat4]=>2 [Cat1]=>1)
 
          $keysArray = array_keys($val); // return keys from array $val
          // print_r($keysArray); echo "<br>";
          // Output:
          // Array([0]=>Cat6 [1]=>Cat3 [2]=>Cat2)
          // Array([0]=>Cat7 [1]=>Cat4 [2]=>Cat1)
 
          // replace the underlines with whitespaces ('Category_1' with 'Category 1')
          $resultKeys2 = array();
          $replacement = array();
          $replaceStr = "";
          for($i=0; $i < count($keysArray); $i++){
             $replacement = array('_' => ' ');
             $replaceStr = strtr($keysArray[$i], $replacement);
             $resultKeys2[] = "'$replaceStr'";
             //$resultKeys2[$i] = "$replaceStr'";
          }
          // print_r($resultKeys2); echo "<br>";
          // Output: without underlines (Category 1)
          // Array([0]=>Cat6 [1]=>Cat3 [2]=>Cat2)
          // Array([0]=>Cat7 [1]=>Cat4 [2]=>Cat1)
 
          // select the cluster-categories from database
          for($i=0; $i < count($resultKeys2); $i++){
            // if the $resultKeys2 Array contains one category
            if(count($resultKeys2) == 1){
               $sqlQueryStr2 =
               "SELECT $resultKeys2[0] AS cattit " .
               "FROM {$catTableName}";
            }
            // if the $resultKeys2 Array contains two categories
            if(count($resultKeys2) == 2){
               $sqlQueryStr2 =
               "SELECT $resultKeys2[0] AS cattit, $resultKeys2[1] AS catit " .
               "FROM {$catTableName}";
            }
            // if the $resultKeys2 Array contains three categories
            if(count($resultKeys2) == 3){
               $sqlQueryStr2 =
               "SELECT $resultKeys2[0] AS cattit, $resultKeys2[1] AS catit, $resultKeys2[2] AS catt " .
               "FROM {$catTableName}";
            }
          }
          $res = $dbr->query( $sqlQueryStr2, 'SingleLinkTagCluster::showResults', false );
 
          // add the clutser-categories, selected from database, to string
                  $aRow='';
                  $bRow='';
                  $cRow='';
 
                  $catView = new CategoryViewer( Title::makeTitle( '-1', wfMsg( 'singlelinktagcluster' ) ) ); // Titel des Seite: TagClustering
 
                  while( $row = $dbr->fetchObject( $res ) ) {
            $aRow = $row->cattit;
            $bRow = $row->catit;
            $cRow = $row->catt;
          }
          // echo $aRow; echo " "; echo $bRow; echo " "; echo $cRow; echo "<br>";
          // Output: cluster-categories as string, splited per 3 categories
          // Cat6 Cat3 Cat2
          // Cat7 Cat4 Cat1
 
                  // print_r($val); echo "<br>";
          // Output:
          // Array([Cat6]=>9 [Cat3]=>5 [Cat2]=>4)
          // Array([Cat7]=>3 [Cat4]=>2 [Cat1]=>1)
 
          // add keys (cluster-categories) from array $val to array $resultKeys
          $resultKeys = array();
          $resultKeys = array_keys($val);
 
          // add values (number, how much the input category apears with the cluster-categories)
          // from array $val to array $resultValues
          $resultValues = array();
          $resultValues = array_values($val);
 
 
          // Html Output of cluster-categories
 
          // if the array $resultValues consists of one category
          if(count($resultValues) == 1){
            // calculate the percent, on how many pages the input categoty appears with
            // the cluster-categoty together.
            $prozentZahl = ($resultValues[0] * 100) / $countTitle;
 
                        // depending on the number of percents, the cluster-categories will be highlighted
                        // with different colour
            if($prozentZahl <= 1){
              $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#008000>$aRow </font></a><font color=#008000>($resultValues[0])</font><br>" );
            }
            if(($prozentZahl > 1) && ($prozentZahl <=25)){
              $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#008080>$aRow </font></a><font color=#008080>($resultValues[0])</font><br>" );
            }
            if(($prozentZahl > 25) && ($prozentZahl <= 50)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#CD1076>$aRow </font></a><font color=#CD1076>($resultValues[0])</font><br>" );
            }
            if(($prozentZahl > 50) && ($prozentZahl <= 75)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0])</font><br>" );
            }
            if(($prozentZahl > 75) && ($prozentZahl <= 100)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0])</font><br>" );
            }
          }
 
                  // if the array $resultValues consists of two categories
          if(count($resultValues) == 2){
            $prozentZahl = ($resultValues[0] * 100) / $countTitle;
            $prozentZahl2 = ($resultValues[1] * 100) / $countTitle;
            if(($prozentZahl <= 1) && ($prozentZahl2 <= 1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#008000>$aRow </font></a><font color=#008000>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008000> $bRow </font></a><font color=#008000>($resultValues[1])</font><br>" );
            }
            if(($prozentZahl > 1 && $prozentZahl <=25) && ($prozentZahl2 <= 1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#008080>$aRow </font></a><font color=#008080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008000> $bRow </font></a><font color=#008000>($resultValues[1])</font><br>" );
            }
            if(($prozentZahl > 1 && $prozentZahl <=25) && ($prozentZahl2 > 1 && $prozentZahl2 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#008080>$aRow </font></a><font color=#008080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008080> $bRow </font></a><font color=#008080>($resultValues[1])</font><br>" );
            }
            if(($prozentZahl > 25 && $prozentZahl <=50) && ($prozentZahl2 <= 1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#CD1076>$aRow </font></a><font color=#CD1076>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008000> $bRow </font></a><font color=#008000>($resultValues[1])</font><br>" );
            }
            if(($prozentZahl > 25 && $prozentZahl <=50) && ($prozentZahl2 > 1 && $prozentZahl2 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#CD1076>$aRow </font></a><font color=#CD1076>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008080> $bRow </font></a><font color=#008080>($resultValues[1])</font><br>" );
            }
            if(($prozentZahl > 25 && $prozentZahl <=50) && ($prozentZahl2 > 25 && $prozentZahl2 <=50)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#CD1076>$aRow </font></a><font color=#CD1076>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#CD1076> $bRow </font></a><font color=#CD1076>($resultValues[1])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 <= 1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008000> $bRow </font></a><font color=#008000>($resultValues[1])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 > 1 && $prozentZahl2 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008080> $bRow </font></a><font color=#008080>($resultValues[1])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 > 25 && $prozentZahl2 <=50)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#CD1076> $bRow </font></a><font color=#CD1076>($resultValues[1])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 > 50 && $prozentZahl2 <=75)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#8B008B> $bRow </font></a><font color=#8B008B>($resultValues[1])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 <= 1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008000> $bRow </font></a><font color=#008000>($resultValues[1])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 1 && $prozentZahl2 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008080> $bRow </font></a><font color=#008080>($resultValues[1])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 25 && $prozentZahl2 <=75)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#CD1076> $bRow </font></a><font color=#CD1076>($resultValues[1])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 75 && $prozentZahl2 <=100)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#000080> $bRow </font></a><font color=#000080>($resultValues[1])</font><br>" );
            }
          }
 
          // if the array $resultValues consists of three categories
          if(count($resultValues) == 3){
            $prozentZahl = ($resultValues[0] * 100) / $countTitle;
            $prozentZahl2 = ($resultValues[1] * 100) / $countTitle;
            $prozentZahl3 = ($resultValues[2] * 100) / $countTitle;
         //   echo "$prozentZahl, $prozentZahl2, $prozentZahl3<br>";
 
            if(($prozentZahl <= 1) && ($prozentZahl2 <= 1) && ($prozentZahl3 <= 1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#008000>$aRow </font></a><font color=#008000>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008000> $bRow </font></a><font color=#008000>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 1 && $prozentZahl <=25) && ($prozentZahl2 <= 1) && ($prozentZahl3 <= 1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#008080>$aRow </font></a><font color=#008080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008000> $bRow </font></a><font color=#008000>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 1 && $prozentZahl <=25) && ($prozentZahl2 > 1 && $prozentZahl2 <=25) && ($prozentZahl3 <= 1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#008080>$aRow </font></a><font color=#008080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008080> $bRow </font></a><font color=#008080>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 1 && $prozentZahl <=25) && ($prozentZahl2 > 1 && $prozentZahl2 <=25) && ($prozentZahl3 > 1 && $prozentZahl3 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#008080>$aRow </font></a><font color=#008080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008080> $bRow </font></a><font color=#008080>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008080> $cRow </font></a><font color=#008080>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 25 && $prozentZahl <=50) && ($prozentZahl2 <= 1)  && ($prozentZahl3 <= 1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#CD1076>$aRow </font></a><font color=#CD1076>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008000> $bRow </font></a><font color=#008000>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 25 && $prozentZahl <=50) && ($prozentZahl2 > 1 && $prozentZahl2 <=25)  && ($prozentZahl3 <= 1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#CD1076>$aRow </font></a><font color=#CD1076>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008080> $bRow </font></a><font color=#008080>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 25 && $prozentZahl <=50) && ($prozentZahl2 > 1 && $prozentZahl2 <=25)  && ($prozentZahl3 > 1 && $prozentZahl3 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#CD1076>$aRow </font></a><font color=#CD1076>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008080> $bRow </font></a><font color=#008080>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008080> $cRow </font></a><font color=#008080>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 25 && $prozentZahl <=50) && ($prozentZahl2 > 25 && $prozentZahl2 <=50)  && ($prozentZahl3 <= 1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#CD1076>$aRow </font></a><font color=#CD1076>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#CD1076> $bRow </font></a><font color=#CD1076>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 25 && $prozentZahl <=50) && ($prozentZahl2 > 25 && $prozentZahl2 <=50)  && ($prozentZahl3 > 1 && $prozentZahl3 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#CD1076>$aRow </font></a><font color=#CD1076>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#CD1076> $bRow </font></a><font color=#CD1076>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008080> $cRow </font></a><font color=#008080>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 25 && $prozentZahl <=50) && ($prozentZahl2 > 25 && $prozentZahl2 <=50)  && ($prozentZahl3 > 25 && $prozentZahl3 <=50)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#CD1076>$aRow </font></a><font color=#CD1076>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#CD1076> $bRow </font></a><font color=#CD1076>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#CD1076> $cRow </font></a><font color=#CD1076>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 <=1) && ($prozentZahl3 <=1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008000> $bRow </font></a><font color=#008000>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 > 1 && $prozentZahl2 <=25)  && ($prozentZahl3 <=1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008080> $bRow </font></a><font color=#008080>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 > 1 && $prozentZahl2 <=25)  && ($prozentZahl3 > 1 && $prozentZahl3 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008080> $bRow </font></a><font color=#008080>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008080> $cRow </font></a><font color=#008080>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 > 25 && $prozentZahl2 <=50)  && ($prozentZahl3 <=1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#CD1076> $bRow </font></a><font color=#CD1076>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 > 25 && $prozentZahl2 <=50)  && ($prozentZahl3 > 1 && $prozentZahl3 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#CD1076> $bRow </font></a><font color=#CD1076>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008080> $cRow </font></a><font color=#008080>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 > 25 && $prozentZahl2 <=50)  && ($prozentZahl3 > 25 && $prozentZahl3 <=50)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#CD1076> $bRow </font></a><font color=#CD1076>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#CD1076> $cRow </font></a><font color=#CD1076>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 > 50 && $prozentZahl2 <=75)  && ($prozentZahl3 <=1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#8B008B> $bRow </font></a><font color=#8B008B>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 > 50 && $prozentZahl2 <=75)  && ($prozentZahl3 > 1 && $prozentZahl3 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#8B008B> $bRow </font></a><font color=#8B008B>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008080> $cRow </font></a><font color=#008080>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 > 50 && $prozentZahl2 <=75)  && ($prozentZahl3 > 25 && $prozentZahl3 <=50)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#8B008B> $bRow </font></a><font color=#8B008B>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#CD1076> $cRow </font></a><font color=#CD1076>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 50 && $prozentZahl <=75) && ($prozentZahl2 > 50 && $prozentZahl2 <=75)  && ($prozentZahl3 > 50 && $prozentZahl3 <=75)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#8B008B>$aRow </font></a><font color=#8B008B>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#8B008B> $bRow </font></a><font color=#8B008B>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#8B008B> $cRow </font></a><font color=#8B008B>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 <=1)  && ($prozentZahl3 <=1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008000> $bRow </font></a><font color=#008000>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 1 && $prozentZahl2 <=25)  && ($prozentZahl3 <=1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008080> $bRow </font></a><font color=#008080>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 1 && $prozentZahl2 <=25)  && ($prozentZahl3 > 1 && $prozentZahl3 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#008080> $bRow </font></a><font color=#008080>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008080> $cRow </font></a><font color=#008080>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 25 && $prozentZahl2 <=50)  && ($prozentZahl3 <=1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#CD1076> $bRow </font></a><font color=#CD1076>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 25 && $prozentZahl2 <=50)  && ($prozentZahl3 > 1 && $prozentZahl3 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#CD1076> $bRow </font></a><font color=#CD1076>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008080> $cRow </font></a><font color=#008080>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 25 && $prozentZahl2 <=50)  && ($prozentZahl3 > 25 && $prozentZahl3 <=50)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#CD1076> $bRow </font></a><font color=#CD1076>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#CD1076> $cRow </font></a><font color=#CD1076>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 50 && $prozentZahl2 <=75)  && ($prozentZahl3 <=1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#8B008B> $bRow </font></a><font color=#8B008B>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 50 && $prozentZahl2 <=75)  && ($prozentZahl3 > 1 && $prozentZahl3 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#8B008B> $bRow </font></a><font color=#8B008B>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008080> $cRow </font></a><font color=#008080>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 50 && $prozentZahl2 <=75)  && ($prozentZahl3 > 25 && $prozentZahl3 <=50)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#8B008B> $bRow </font></a><font color=#8B008B>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#CD1076> $cRow </font></a><font color=#CD1076>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 50 && $prozentZahl2 <=75)  && ($prozentZahl3 > 50 && $prozentZahl3 <=75)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#8B008B> $bRow </font></a><font color=#8B008B>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#8B008B> $cRow </font></a><font color=#8B008B>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 75 && $prozentZahl2 <=100) && ($prozentZahl3 <=1)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#000080> $bRow </font></a><font color=#000080>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008000> $cRow </font></a><font color=#008000>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 75 && $prozentZahl2 <=100) && ($prozentZahl3 > 1 && $prozentZahl3 <=25)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#000080> $bRow </font></a><font color=#000080>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#008080> $cRow </font></a><font color=#008080>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 75 && $prozentZahl2 <=100) && ($prozentZahl3 > 25 && $prozentZahl3 <=50)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#000080> $bRow </font></a><font color=#000080>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#CD1076> $cRow </font></a><font color=#CD1076>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 75 && $prozentZahl2 <=100) && ($prozentZahl3 > 50 && $prozentZahl3 <=75)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#000080> $bRow </font></a><font color=#000080>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#8B008B> $cRow </font></a><font color=#8B008B>($resultValues[2])</font><br>" );
            }
            if(($prozentZahl > 75 && $prozentZahl <=100) && ($prozentZahl2 > 75 && $prozentZahl2 <=100)  && ($prozentZahl3 > 75 && $prozentZahl3 <=100)){
               $wgOut->addHTML( "<a href=\".../../Kategorie:$resultKeys[0]\"><font color=#000080>$aRow </font></a><font color=#000080>($resultValues[0]),</font><a href=\".../../Kategorie:$resultKeys[1]\"><font color=#000080> $bRow </font></a><font color=#000080>($resultValues[1]), </font><a href=\".../../Kategorie:$resultKeys[2]\"><font color=#000080> $cRow </font></a><font color=#000080>($resultValues[2])</font><br>" );
            }
          }
 
        }
        $wgOut->addHTML( "<br><br><hr /><br>" );
        // if the input category doesn't appear with any other categoty
        // message apears: 'No cluster can be generated with the inserted category..'
        if( $dbr->numRows($res) == 0 ) {
                        $wgOut->addHTML( '<h3>' . wfMsg( 'singlelinktagcluster_no_cat' ) .
                                '</h3><br /><hr /><br />' );
                        // apply function showForm()
                        $this->showForm();
                        return;
        }
        $dbr->freeResult( $res );
        $this->showForm();
 
        wfProfileOut( 'SingleLinkTagCluster::showResults' );
    }
 
 
        // this function shows the Html page, that appears after loading the spezialpage 'SingleLinkTagCluster'
        // this page contains following information:
        // 1. description, what this spezialpage does.
        // 2. description, what is the SingeLink Cluster.
        // 3. input field, where the user can enter the categoty, to that the tag-cluster
        //    must be created.
        // 4. tag-cloud, that is used, to take an overview of existing categories
 
    function showForm() {
 
        global $wgOut, $wgUser, $wgRequest;
        global $wgScriptPath, $wgUseAjax, $wgJsMimeType;
 
        // show the Spezialpagetitle 'SingleLinkTagCluster'
        $wgOut->setPagetitle( wfMsg( 'singlelinktagcluster' ) );
        $titleObj = Title::makeTitle( NS_SPECIAL, 'SingleLinkTagCluster' );
        $action = $titleObj->escapeLocalURL( '' );
        $token = htmlspecialchars( $wgUser->editToken() );
 
        $msgComment = wfMsgHtml( 'singlelinktagcluster_comment' );
        $msgInCategories = wfMsgHtml( 'singlelinktagcluster_include' );
        $msgSingleLink = wfMsgHtml( 'singlelink_comment' );
        $msgTagCloud = wfMsgHtml( 'tagcloud' );
        $msgTagCloudComment = wfMsgHtml( 'tagcloud_comment' );
        $msgSubmitButton = wfMsgHtml( 'singlelinktagcluster_submit_button' );
        $msgClusterButton = wfMsgHtml ( 'singlelinktagcluster_build' );
 
        // show the message 'This specialpage allows you to build
        // the SingleLink tag-cluster with the category'
        $wgOut->addWikiText( "$msgComment" );
 
        // show the message 'The SingleLink Cluster means...'
        $wgOut->addWikiText( "$msgSingleLink" );
 
        // show the edit fiel and message 'Please enter one category'
        $wgOut->addHTML(" <br><br>
   <form id=\"SingleLinkTagCluster\" method=\"{$this->paramsPassMethod}\" action=\"{$action}\">   
   <table border=\"0\">
        {$dropdownLists}
        <tr>
           <td colspan=\"2\" align=\"left\">{$msgInCategories}</td>
        </tr>");
        for( $i = substr_count( $dropdownLists, '<select' ) + 1;
            $i <= $this->inCategoriesNumber; $i++ ) {
                    $categoryTitle = count( $this->inCategories ) - 1 >= $i ?
                                $this->inCategories[$i] : '';
                    $wgOut->addHTML("
        <tr>
            <td colspan=\"2\">
                    <input tabindex=\"{$i}\" type=\"text\" size=\"40\" name=\"wpInCategory{$i}\" " .
                                        "value=\"{$categoryTitle}\" />
            </td>
        </tr>");
        }
 
        $j = $this->inCategoriesNumber + 1;
 
        // show the submit button 'Build the cluster with this category'
        $wgOut->addHTML("
        <tr>
                <td colspan=\"2\" style=\"padding-top: 1em\" align=\"left\">
                        <input tabindex=\"{$j}\" type=\"submit\" name=\"wpSubmitSearchParams\" " .
                                "value=\"{$msgClusterButton}\" />
                </td>
        </tr>
    </table>
    <br />
    <br />
    <br />
    </form>\n");
 
    // show the tag-cloud
    $wgOut->addHTML( "<h3>{$msgTagCloud}</h3>{$msgTagCloudComment}<hr />" );
    $wgOut->addWikiText("<tagcloud>min_count=1\n min_size=77\n increase_factor=160</tagcloud>");
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox