2006-07-26 17:12:30 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2008-02-04 09:22:12 +00:00
|
|
|
* Special page for the CategoryTree extension, an AJAX based gadget
|
2006-07-26 17:12:30 +00:00
|
|
|
* to display the category structure of a wiki
|
|
|
|
*
|
2010-06-06 15:12:22 +00:00
|
|
|
* @file
|
|
|
|
* @ingroup 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
|
2008-03-18 17:38:32 +00:00
|
|
|
* @license GNU General Public Licence 2.0 or later
|
2006-07-26 17:12:30 +00:00
|
|
|
*/
|
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2006-07-26 17:12:30 +00:00
|
|
|
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 = '';
|
2012-11-21 08:31:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var CategoryTree
|
|
|
|
*/
|
2010-01-06 21:24:10 +00:00
|
|
|
var $tree = null;
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
function __construct() {
|
2010-08-30 17:18:13 +00:00
|
|
|
parent::__construct( 'CategoryTree', '', true );
|
2006-07-26 17:12:30 +00:00
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2012-02-09 01:23:31 +00:00
|
|
|
/**
|
|
|
|
* @param $name
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2008-06-28 20:13:20 +00:00
|
|
|
function getOption( $name ) {
|
|
|
|
global $wgCategoryTreeDefaultOptions;
|
|
|
|
|
2010-11-26 19:09:35 +00:00
|
|
|
if ( $this->tree ) {
|
|
|
|
return $this->tree->getOption( $name );
|
|
|
|
} else {
|
|
|
|
return $wgCategoryTreeDefaultOptions[$name];
|
|
|
|
}
|
2008-06-28 20:13:20 +00:00
|
|
|
}
|
|
|
|
|
2006-07-26 17:12:30 +00:00
|
|
|
/**
|
|
|
|
* Main execution function
|
2012-02-09 01:23:31 +00:00
|
|
|
* @param $par array Parameters passed to the page
|
2006-07-26 17:12:30 +00:00
|
|
|
*/
|
|
|
|
function execute( $par ) {
|
2012-02-09 01:23:31 +00:00
|
|
|
global $wgCategoryTreeDefaultOptions, $wgCategoryTreeSpecialPageOptions, $wgCategoryTreeForceHeaders;
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-07-26 17:12:30 +00:00
|
|
|
$this->setHeaders();
|
2012-02-09 01:23:31 +00:00
|
|
|
$request = $this->getRequest();
|
|
|
|
if ( $par ) {
|
|
|
|
$this->target = $par;
|
|
|
|
} else {
|
2012-08-28 22:35:39 +00:00
|
|
|
$this->target = $request->getVal( 'target', wfMessage( 'rootcategory' )->text() );
|
2012-02-09 01:23:31 +00:00
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-11 23:36:53 +00:00
|
|
|
$this->target = trim( $this->target );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
# HACK for undefined root category
|
2010-11-26 19:09:35 +00:00
|
|
|
if ( $this->target == '<rootcategory>' || $this->target == '<rootcategory>' ) {
|
|
|
|
$this->target = null;
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-06-28 20:13:20 +00:00
|
|
|
$options = array();
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-06-28 20:13:20 +00:00
|
|
|
# grab all known options from the request. Normalization is done by the CategoryTree class
|
|
|
|
foreach ( $wgCategoryTreeDefaultOptions as $option => $default ) {
|
2012-02-09 01:23:31 +00:00
|
|
|
if ( isset( $wgCategoryTreeSpecialPageOptions[$option] ) ) {
|
2008-06-30 14:09:47 +00:00
|
|
|
$default = $wgCategoryTreeSpecialPageOptions[$option];
|
2012-02-09 01:23:31 +00:00
|
|
|
}
|
2008-06-30 14:09:47 +00:00
|
|
|
|
2012-02-09 01:23:31 +00:00
|
|
|
$options[$option] = $request->getVal( $option, $default );
|
2008-06-28 20:13:20 +00:00
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-06-28 20:13:20 +00:00
|
|
|
$this->tree = new CategoryTree( $options );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2012-02-09 01:23:31 +00:00
|
|
|
$output = $this->getOutput();
|
|
|
|
$output->addWikiMsg( 'categorytree-header' );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-07-01 13:36:50 +00:00
|
|
|
$this->executeInputForm();
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2010-04-20 22:00:34 +00:00
|
|
|
if ( $this->target !== '' && $this->target !== null ) {
|
2012-02-09 01:23:31 +00:00
|
|
|
if ( !$wgCategoryTreeForceHeaders ) {
|
|
|
|
CategoryTree::setHeaders( $output );
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-24 17:12:13 +00:00
|
|
|
$title = CategoryTree::makeTitle( $this->target );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-08-11 23:36:53 +00:00
|
|
|
if ( $title && $title->getArticleID() ) {
|
2012-02-09 01:23:31 +00:00
|
|
|
$output->addHTML( Xml::openElement( 'div', array( 'class' => 'CategoryTreeParents' ) ) );
|
2012-08-28 22:35:39 +00:00
|
|
|
$output->addHTML( wfMessage( 'categorytree-parents' )->parse() );
|
|
|
|
$output->addHTML( wfMessage( 'colon-separator' )->escaped() );
|
2006-08-24 17:12:13 +00:00
|
|
|
|
2008-06-28 20:13:20 +00:00
|
|
|
$parents = $this->tree->renderParents( $title );
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-03-18 17:38:32 +00:00
|
|
|
if ( $parents == '' ) {
|
2012-08-28 22:35:39 +00:00
|
|
|
$output->addHTML( wfMessage( 'categorytree-no-parent-categories' )->parse() );
|
2008-03-18 17:38:32 +00:00
|
|
|
} else {
|
2012-02-09 01:23:31 +00:00
|
|
|
$output->addHTML( $parents );
|
2008-03-18 17:38:32 +00:00
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2012-02-09 01:23:31 +00:00
|
|
|
$output->addHTML( Xml::closeElement( 'div' ) );
|
2008-06-28 20:13:20 +00:00
|
|
|
|
2012-02-09 01:23:31 +00:00
|
|
|
$output->addHTML( Xml::openElement( 'div', array( 'class' => 'CategoryTreeResult' ) ) );
|
|
|
|
$output->addHTML( $this->tree->renderNode( $title, 1 ) );
|
|
|
|
$output->addHTML( Xml::closeElement( 'div' ) );
|
|
|
|
} else {
|
|
|
|
$output->addHTML( Xml::openElement( 'div', array( 'class' => 'CategoryTreeNotice' ) ) );
|
2012-08-28 22:35:39 +00:00
|
|
|
$output->addHTML( wfMessage( 'categorytree-not-found', $this->target )->parse() );
|
2012-02-09 01:23:31 +00:00
|
|
|
$output->addHTML( Xml::closeElement( 'div' ) );
|
2006-07-26 17:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-07-26 17:12:30 +00:00
|
|
|
/**
|
|
|
|
* Input form for entering a category
|
|
|
|
*/
|
2008-07-01 13:36:50 +00:00
|
|
|
function executeInputForm() {
|
2012-02-09 01:23:31 +00:00
|
|
|
global $wgScript;
|
2010-06-08 19:30:48 +00:00
|
|
|
$thisTitle = SpecialPage::getTitleFor( $this->getName() );
|
2012-09-25 14:11:32 +00:00
|
|
|
$namespaces = $this->getRequest()->getVal( 'namespaces', '' );
|
|
|
|
//mode may be overriden by namespaces option
|
|
|
|
$mode = ( $namespaces == '' ? $this->getOption( 'mode' ) : CT_MODE_ALL );
|
|
|
|
$modeSelector = Xml::openElement( 'select', array( 'name' => 'mode' ) );
|
|
|
|
$modeSelector .= Xml::option( wfMessage( 'categorytree-mode-categories' )->plain(), 'categories', $mode == CT_MODE_CATEGORIES );
|
|
|
|
$modeSelector .= Xml::option( wfMessage( 'categorytree-mode-pages' )->plain(), 'pages', $mode == CT_MODE_PAGES );
|
|
|
|
$modeSelector .= Xml::option( wfMessage( 'categorytree-mode-all' )->plain(), 'all', $mode == CT_MODE_ALL );
|
|
|
|
$modeSelector .= Xml::closeElement( 'select' );
|
|
|
|
$table = Xml::buildForm( array(
|
|
|
|
'categorytree-category' => Xml::input( 'target', 20, $this->target, array( 'id' => 'target' ) ) ,
|
|
|
|
'categorytree-mode-label' => $modeSelector,
|
|
|
|
'namespace' => Html::namespaceSelector(
|
|
|
|
array( 'selected' => $namespaces, 'all' => '' ),
|
|
|
|
array( 'name' => 'namespaces', 'id' => 'namespaces' )
|
|
|
|
)
|
|
|
|
), 'categorytree-go' );
|
|
|
|
$preTable = Xml::element( 'legend', null, wfMessage( 'categorytree-legend' )->plain() );
|
|
|
|
$preTable .= Html::Hidden( 'title', $thisTitle->getPrefixedDbKey() );
|
|
|
|
$fieldset = Xml::tags( 'fieldset', array(), $preTable . $table );
|
2012-02-09 01:23:31 +00:00
|
|
|
$output = $this->getOutput();
|
2012-09-25 14:11:32 +00:00
|
|
|
$output->addHTML( Xml::tags( 'form', array( 'name' => 'categorytree', 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-categorytree-form' ), $fieldset ) );
|
2006-07-26 17:12:30 +00:00
|
|
|
}
|
|
|
|
}
|