# HG changeset patch # User Dan # Date 1186409388 14400 # Node ID 80facec76d9f0c63e27e0568f9af8bfe8cc34bc2 # Parent 03c7f5ec1e4c3c7f074918a5a139a6ece1287d86 Tag cloud is now implemented diff -r 03c7f5ec1e4c -r 80facec76d9f includes/clientside/css/enano-shared.css --- a/includes/clientside/css/enano-shared.css Sun Aug 05 17:10:17 2007 -0400 +++ b/includes/clientside/css/enano-shared.css Mon Aug 06 10:09:48 2007 -0400 @@ -422,3 +422,83 @@ td.diff-context { background: #eee; font-size: smaller; } span.diffchange { color: red; font-weight: bold; } +/* Tag cloud */ +span.tc_word_normal { + font-family: Arial, helvetica, sans-serif; + font-size: 10pt; + letter-spacing: 3px; + padding: 4px 4px 4px 4px; +} +span.tc_word_small { + font-family: Arial, helvetica, sans-serif; + font-size: 8pt; +} +span.tc_word_normal a, span.tc_word_small a { + color: inherit !important; + text-decoration: none !important; +} +/* These are from http://www.lotsofcode.com/php/tutorials/tag-cloud */ +span.tc_normal_index_1 { + color: #000; + font-size: 2.4em; +} +span.tc_normal_index_2 { + color: #333; + font-size: 2.2em; +} +span.tc_normal_index_3 { + color: #666; + font-size: 2.0em; +} +span.tc_normal_index_4 { + color: #999; + font-size: 1em; +} +span.tc_normal_index_5 { + color: #aaa; + font-size: 1.6em; +} +span.tc_normal_index_6 { + color: #bbb; + font-size: 1.4em; +} +span.tc_normal_index_7 { + color: #ccc; + font-size: 1.2em; +} +span.tc_normal_index_8 { + color: #ddd; + font-size: 0.8em; +} +span.tc_small_index_1 { + color: #000; + font-size: 1.4em; +} +span.tc_small_index_2 { + color: #333; + font-size: 1.3em; +} +span.tc_small_index_3 { + color: #666; + font-size: 1.2em; +} +span.tc_small_index_4 { + color: #999; + font-size: 1em; +} +span.tc_small_index_5 { + color: #aaa; + font-size: 1.3em; +} +span.tc_small_index_6 { + color: #bbb; + font-size: 1.1em; +} +span.tc_small_index_7 { + color: #ccc; + font-size: 0.9em; +} +span.tc_small_index_8 { + color: #ddd; + font-size: 0.7em; +} diff -r 03c7f5ec1e4c -r 80facec76d9f includes/pageprocess.php --- a/includes/pageprocess.php Sun Aug 05 17:10:17 2007 -0400 +++ b/includes/pageprocess.php Mon Aug 06 10:09:48 2007 -0400 @@ -753,7 +753,7 @@ $parser->assign_bool(array( 'page_exists' => true )); - $page_title = $paths->pages[ $c_page_id ]['name']; + $page_title = htmlspecialchars($paths->pages[ $c_page_id ]['name']); } else { diff -r 03c7f5ec1e4c -r 80facec76d9f includes/tagcloud.php --- a/includes/tagcloud.php Sun Aug 05 17:10:17 2007 -0400 +++ b/includes/tagcloud.php Mon Aug 06 10:09:48 2007 -0400 @@ -51,7 +51,7 @@ function add_word($word) { - $word = strtolower($word); + $word = sanitize_tag($word); if ( isset($this->words[$word]) ) $this->words[$word] += 1; @@ -125,25 +125,33 @@ /** * Generates and returns HTML for the cloud. + * @param string Optional. The CSS class applied to all tags. Can be "normal" or "small". Defaults to "normal". + * @param string Optional. The alignment for the div. Defaults to "center". * @return string */ - function make_html() + function make_html($span_class = 'normal', $div_align = 'center') { $html = array(); $max = max($this->words); $size = $this->get_cloud_size(); + $inc = 0; if ( count($this->words) > 0 ) { foreach ( $this->words as $word => $popularity ) { + $inc++; $word = htmlspecialchars($word); $percent = ( $popularity / $max ) * 100; $index = $this->get_scale_class($percent); - $html[] = "$word"; + $newline = ( $inc == 5 ) ? "
" : ''; + ( $inc == 5 ) ? $inc = 0 : null; + $url = makeUrlNS('Special', 'TagCloud/' . htmlspecialchars($word)); + $s = ( $popularity != 1 ) ? 's' : ''; + $html[] = "$word"; // $newline"; } } - $html = implode("\n", $html); + $html = '
' . implode("\n", $html) . '
'; return $html; } diff -r 03c7f5ec1e4c -r 80facec76d9f plugins/SpecialPageFuncs.php --- a/plugins/SpecialPageFuncs.php Sun Aug 05 17:10:17 2007 -0400 +++ b/plugins/SpecialPageFuncs.php Mon Aug 06 10:09:48 2007 -0400 @@ -58,6 +58,13 @@ \'namespace\'=>\'Special\', \'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\', )); + + $paths->add_page(Array( + \'name\'=>\'Tag cloud\', + \'urlname\'=>\'TagCloud\', + \'namespace\'=>\'Special\', + \'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\', + )); '); // function names are IMPORTANT!!! The name pattern is: page__ @@ -366,4 +373,107 @@ $template->footer(); } +function page_Special_TagCloud() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + + $template->header(); + + if ( $tag = $paths->getParam(0) ) + { + $tag = sanitize_tag($tag); + $q = $db->sql_query('SELECT page_id, namespace FROM '.table_prefix.'tags WHERE tag_name=\'' . $db->escape($tag) . '\';'); + if ( !$q ) + $db->_die(); + if ( $row = $db->fetchrow() ) + { + echo '
+ '; + echo ''; + echo ''; + $i = 0; + $td_class = 'row1'; + do + { + if ( $i % 2 == 0 && $i > 1 ) + { + $td_class = ( $td_class == 'row2' ) ? 'row1' : 'row2'; + echo ''; + } + $i++; + $title = get_page_title_ns($row['page_id'], $row['namespace']); + if ( $row['namespace'] != 'Article' && isset($paths->nslist[$row['namespace']]) ) + $title = $paths->nslist[$row['namespace']] . $title; + $url = makeUrlNS($row['namespace'], $row['page_id']); + $class = ( isPage( $paths->nslist[$row['namespace']] . $row['page_id'] ) ) ? '' : ' class="wikilink-nonexistent"'; + $link = '' . htmlspecialchars($title) . ''; + echo ""; + // " workaround for jEdit highlighting bug + } + while ( $row = $db->fetchrow() ); + while ( $i % 2 > 0 ) + { + $i++; + echo ""; + } + // " workaround for jEdit highlighting bug + echo ' + + '; + echo '
Pages tagged "' . htmlspecialchars($tag) . '"
$link
« Return to tag cloud
'; + echo '
'; + } + } + else + { + $cloud = new TagCloud(); + + $q = $db->sql_query('SELECT tag_name FROM '.table_prefix.'tags;'); + if ( !$q ) + $db->_die(); + if ( $db->numrows() < 1 ) + { + echo '

No pages are tagged yet.

'; + } + else + { + echo '

Summary of page tagging

'; + while ( $row = $db->fetchrow() ) + { + $cloud->add_word($row['tag_name']); + } + echo $cloud->make_html('normal'); + echo '

Hover your mouse over a tag to see how many pages have the tag. Click on a tag to see a list of the pages that have it.

'; + } + } + + $template->footer(); +} + +// tag cloud sidebar block +function sidebar_add_tag_cloud() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + $cloud = new TagCloud(); + + $q = $db->sql_query('SELECT tag_name FROM '.table_prefix.'tags;'); + if ( !$q ) + $db->_die(); + if ( $db->numrows() < 1 ) + { + $sb_html = 'No pages are tagged yet.'; + } + else + { + while ( $row = $db->fetchrow() ) + { + $cloud->add_word($row['tag_name']); + } + $sb_html = $cloud->make_html('small', 'justify') . '
Larger version'; + } + $template->sidebar_widget('Tag cloud', "
$sb_html
"); +} + +$plugins->attachHook('compile_template', 'sidebar_add_tag_cloud();'); + ?> \ No newline at end of file