2006-07-26 17:12:30 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Special page for the CategoryTree extension, an AJAX based gadget
|
|
|
|
* to display the category structure of a wiki
|
|
|
|
*
|
2007-01-20 15:10:35 +00:00
|
|
|
* @addtogroup Extensions
|
2007-03-13 11:39:12 +00:00
|
|
|
* @author Daniel Kinzler, brightbyte.de
|
2006-07-26 17:12:30 +00:00
|
|
|
* @copyright © 2006 Daniel Kinzler
|
|
|
|
* @licence GNU General Public Licence 2.0 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
if( !defined( 'MEDIAWIKI' ) ) {
|
|
|
|
echo( "This file is part of an extension to the MediaWiki software and cannot be used standalone.\n" );
|
|
|
|
die( 1 );
|
|
|
|
}
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
class CategoryTreePage extends SpecialPage {
|
2006-07-26 17:12:30 +00:00
|
|
|
|
|
|
|
var $target = '';
|
|
|
|
var $mode = CT_MODE_CATEGORIES;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2006-08-24 17:12:13 +00:00
|
|
|
function __construct() {
|
2006-07-29 09:18:34 +00:00
|
|
|
global $wgOut;
|
2006-07-29 17:37:08 +00:00
|
|
|
SpecialPage::SpecialPage( 'CategoryTree', '', true );
|
2006-08-24 17:12:13 +00:00
|
|
|
|
2006-07-26 17:12:30 +00:00
|
|
|
#inject messages
|
|
|
|
efInjectCategoryTreeMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main execution function
|
|
|
|
* @param $par Parameters passed to the page
|
|
|
|
*/
|
|
|
|
function execute( $par ) {
|
|
|
|
global $wgRequest, $wgOut, $wgMakeBotPrivileged, $wgUser;
|
|
|
|
|
|
|
|
$this->setHeaders();
|
|
|
|
|
|
|
|
if ( $par ) $this->target = $par;
|
|
|
|
else $this->target = $wgRequest->getVal( 'target', wfMsg( 'rootcategory') );
|
2006-08-11 23:36:53 +00:00
|
|
|
|
|
|
|
$this->target = trim( $this->target );
|
2006-07-26 17:12:30 +00:00
|
|
|
|
|
|
|
#HACK for undefined root category
|
|
|
|
if ( $this->target == '<rootcategory>' || $this->target == '<rootcategory>' ) $this->target = NULL;
|
|
|
|
|
|
|
|
$this->mode = $wgRequest->getVal( 'mode', CT_MODE_CATEGORIES );
|
|
|
|
|
|
|
|
if ( $this->mode == 'all' ) $this->mode = CT_MODE_ALL;
|
|
|
|
else if ( $this->mode == 'pages' ) $this->mode = CT_MODE_PAGES;
|
|
|
|
else if ( $this->mode == 'categories' ) $this->mode = CT_MODE_CATEGORIES;
|
|
|
|
|
|
|
|
$this->mode = (int)$this->mode;
|
|
|
|
|
|
|
|
$wgOut->addWikiText( wfMsg( 'categorytree-header' ) );
|
|
|
|
|
|
|
|
$wgOut->addHtml( $this->makeInputForm() );
|
|
|
|
|
|
|
|
if( $this->target !== '' && $this->target !== NULL ) {
|
2006-08-24 17:12:13 +00:00
|
|
|
CategoryTree::setHeaders( $wgOut );
|
2006-07-26 17:12:30 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$title = CategoryTree::makeTitle( $this->target );
|
2006-07-26 17:12:30 +00:00
|
|
|
|
2006-08-11 23:36:53 +00:00
|
|
|
if ( $title && $title->getArticleID() ) {
|
2006-07-26 17:12:30 +00:00
|
|
|
$html = '';
|
|
|
|
$html .= wfOpenElement( 'div', array( 'class' => 'CategoryTreeParents' ) );
|
2006-08-24 17:12:13 +00:00
|
|
|
$html .= wfElement( 'span',
|
|
|
|
array( 'class' => 'CategoryTreeParents' ),
|
|
|
|
wfMsg( 'categorytree-parents' ) ) . ': ';
|
|
|
|
|
|
|
|
$ct = new CategoryTree;
|
|
|
|
$parents = $ct->renderParents( $title, $this->mode );
|
2006-07-26 17:12:30 +00:00
|
|
|
|
|
|
|
if ( $parents == '' ) $html .= wfMsg( 'categorytree-nothing-found' );
|
|
|
|
else $html .= $parents;
|
|
|
|
|
|
|
|
$html .= wfCloseElement( 'div' );
|
|
|
|
|
|
|
|
$html .= wfOpenElement( 'div', array( 'class' => 'CategoryTreeResult' ) );
|
2006-08-24 17:12:13 +00:00
|
|
|
$html .= $ct->renderNode( $title, $this->mode, true, false );
|
2006-07-26 17:12:30 +00:00
|
|
|
$html .= wfCloseElement( 'div' );
|
|
|
|
$wgOut->addHtml( $html );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$wgOut->addHtml( wfOpenElement( 'div', array( 'class' => 'CategoryTreeNotice' ) ) );
|
|
|
|
$wgOut->addWikiText( wfMsg( 'categorytree-not-found' , $this->target ) );
|
|
|
|
$wgOut->addHtml( wfCloseElement( 'div' ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Input form for entering a category
|
|
|
|
*/
|
|
|
|
function makeInputForm() {
|
|
|
|
$thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
|
|
|
|
$form = '';
|
|
|
|
$form .= wfOpenElement( 'form', array( 'name' => 'categorytree', 'method' => 'get', 'action' => $thisTitle->getLocalUrl() ) );
|
|
|
|
$form .= wfElement( 'label', array( 'for' => 'target' ), wfMsg( 'categorytree-category' ) ) . ' ';
|
|
|
|
$form .= wfElement( 'input', array( 'type' => 'text', 'name' => 'target', 'id' => 'target', 'value' => $this->target ) ) . ' ';
|
|
|
|
$form .= wfOpenElement( 'select', array( 'name' => 'mode' ) );
|
|
|
|
$form .= wfElement( 'option', array( 'value' => 'categories' ) + ( $this->mode == CT_MODE_CATEGORIES ? array ( 'selected' => 'selected' ) : array() ), wfMsg( 'categorytree-mode-categories' ) );
|
|
|
|
$form .= wfElement( 'option', array( 'value' => 'pages' ) + ( $this->mode == CT_MODE_PAGES ? array ( 'selected' => 'selected' ) : array() ), wfMsg( 'categorytree-mode-pages' ) );
|
|
|
|
$form .= wfElement( 'option', array( 'value' => 'all' ) + ( $this->mode == CT_MODE_ALL ? array ( 'selected' => 'selected' ) : array() ), wfMsg( 'categorytree-mode-all' ) );
|
|
|
|
$form .= wfCloseElement( 'select' );
|
|
|
|
$form .= wfElement( 'input', array( 'type' => 'submit', 'name' => 'dotree', 'value' => wfMsg( 'categorytree-go' ) ) );
|
|
|
|
$form .= wfCloseElement( 'form' );
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
?>
|