<?php
/*
CategorySelector provides a convenient way to select a category.
Copyright (C) 2006, Daniel Kinzler, brightbyte.de
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
if ( defined( 'WS_TOC' ) ) {
$info['ignore'] = true;
return;
}
define("WS_WEB",true);
require_once( "common/WebInit.php" );
require_once( "WikiAccess.php" );
#require_once( "WikiSelector.php" );
#require_once( "WikiSenseLocalizer.php" );
function printCategoryLink( $cat ) {
global $target, $wiki;
$u= $target;
if (strpos($u,'%t')!== false) $u= str_replace('%t', urlencode($cat), $u);
else $u.= urlencode($cat);
$u= str_replace('&','&',$u);
$s= escapeHtml( $wiki->asTitle($cat) );
print "<a href='$u'>$s</a>";
}
function printCategoryLinks( $cats ) {
if (!$cats) {
print "<i>(nothing found)</i>";
return;
}
$first= true;
foreach ($cats as $c) {
if ($first) $first= false;
else print ', ';
printCategoryLink( $c );
}
}
$wiki= $wgRequest->getVal('wiki');
$cat= $wgRequest->getVal('cat');
$target= $wgRequest->getVal('target');
if (!$target && $wiki) $target= '?wiki='.urlencode($wiki).'&cat=%t';
if ($wiki && $cat) $wiki=& WikiAccess::newInstance($wiki);
if ($wiki && $cat) {
$parents= $wiki->getCategories($cat,NS_CATEGORY);
$children= $wiki->getCategoryContents($cat,NS_CATEGORY);
?>
<div class='catsel'>
<div class='catselParents'>
<? printCategoryLinks($parents); ?>
</div>
<div class='catselCurrent'>
<? print escapeHtml( $wiki->asTitle($cat) ); ?>
</div>
<div class='catselChildren'>
<? printCategoryLinks($children); ?>
</div>
</div>
<?
}
else {
?>
<div class='error'>
Missing parameters!
</div>
<?
}
?>CategorySelector.php
application/x-php, 2481 bytes (load raw)

