3
* Special page for the CategoryTree extension, an AJAX based gadget
4
* to display the category structure of a wiki
6
* @addtogroup Extensions
7
* @author Daniel Kinzler, brightbyte.de
8
* @copyright © 2006 Daniel Kinzler
9
* @license GNU General Public Licence 2.0 or later
12
if( !defined( 'MEDIAWIKI' ) ) {
13
echo( "This file is part of an extension to the MediaWiki software and cannot be used standalone.\n" );
17
class CategoryTreePage extends SpecialPage {
25
function __construct() {
27
SpecialPage::SpecialPage( 'CategoryTree', '', true );
28
wfLoadExtensionMessages( 'CategoryTree' );
31
function getOption( $name ) {
32
global $wgCategoryTreeDefaultOptions;
34
if ( $this->tree ) return $this->tree->getOption( $name );
35
else return $wgCategoryTreeDefaultOptions[$name];
39
* Main execution function
40
* @param $par Parameters passed to the page
42
function execute( $par ) {
43
global $wgRequest, $wgOut, $wgCategoryTreeDefaultOptions, $wgCategoryTreeSpecialPageOptions, $wgCategoryTreeForceHeaders;
47
if ( $par ) $this->target = $par;
48
else $this->target = $wgRequest->getVal( 'target', wfMsg( 'rootcategory') );
50
$this->target = trim( $this->target );
52
#HACK for undefined root category
53
if ( $this->target == '<rootcategory>' || $this->target == '<rootcategory>' ) $this->target = NULL;
57
# grab all known options from the request. Normalization is done by the CategoryTree class
58
foreach ( $wgCategoryTreeDefaultOptions as $option => $default ) {
59
if ( isset( $wgCategoryTreeSpecialPageOptions[$option] ) )
60
$default = $wgCategoryTreeSpecialPageOptions[$option];
62
$options[$option] = $wgRequest->getVal( $option, $default );
65
$this->tree = new CategoryTree( $options );
67
$wgOut->addWikiMsg( 'categorytree-header' );
69
$this->executeInputForm();
71
if( $this->target !== '' && $this->target !== NULL ) {
72
if ( !$wgCategoryTreeForceHeaders ) CategoryTree::setHeaders( $wgOut );
74
$title = CategoryTree::makeTitle( $this->target );
76
if ( $title && $title->getArticleID() ) {
77
$wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'CategoryTreeParents' ) ) );
78
$wgOut->addHTML( wfMsgExt( 'categorytree-parents', 'parseinline' ) );
79
$wgOut->addHTML( wfMsg( 'colon-separator' ) );
81
$parents = $this->tree->renderParents( $title );
83
if ( $parents == '' ) {
84
$wgOut->addHTML( wfMsgExt( 'categorytree-no-parent-categories', 'parseinline' ) );
86
$wgOut->addHTML( $parents );
89
$wgOut->addHTML( Xml::closeElement( 'div' ) );
91
$wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'CategoryTreeResult' ) ) );
92
$wgOut->addHTML( $this->tree->renderNode( $title, 1 ) );
93
$wgOut->addHTML( Xml::closeElement( 'div' ) );
96
$wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'CategoryTreeNotice' ) ) );
97
$wgOut->addHTML( wfMsgExt( 'categorytree-not-found', 'parseinline' , $this->target ) );
98
$wgOut->addHTML( Xml::closeElement( 'div' ) );
105
* Input form for entering a category
107
function executeInputForm() {
108
global $wgScript, $wgOut;
109
$thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
110
$mode = $this->getOption('mode');
112
$wgOut->addHTML( Xml::openElement( 'form', array( 'name' => 'categorytree', 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-categorytree-form' ) ) );
113
$wgOut->addHTML( Xml::openElement( 'fieldset' ) );
114
$wgOut->addHTML( Xml::element( 'legend', null, wfMsgNoTrans( 'categorytree-legend' ) ) );
115
$wgOut->addHTML( Xml::hidden( 'title', $thisTitle->getPrefixedDbKey() ) );
116
$wgOut->addHTML( Xml::inputLabel( wfMsgNoTrans( 'categorytree-category' ), 'target', 'target', 20, $this->target ) . ' ' );
117
$wgOut->addHTML( Xml::openElement( 'select', array( 'name' => 'mode' ) ) );
118
$wgOut->addHTML( Xml::option( wfMsgNoTrans( 'categorytree-mode-categories' ), 'categories', $mode == CT_MODE_CATEGORIES ? true : false ) );
119
$wgOut->addHTML( Xml::option( wfMsgNoTrans( 'categorytree-mode-pages' ), 'pages', $mode == CT_MODE_PAGES ? true : false ) );
120
$wgOut->addHTML( Xml::option( wfMsgNoTrans( 'categorytree-mode-all' ), 'all', $mode == CT_MODE_ALL ? true : false ) );
121
$wgOut->addHTML( Xml::closeElement( 'select' ) . ' ' );
122
$wgOut->addHTML( Xml::submitButton( wfMsgNoTrans( 'categorytree-go' ), array( 'name' => 'dotree' ) ) );
123
$wgOut->addHTML( Xml::closeElement( 'fieldset' ) );
124
$wgOut->addHTML( Xml::closeElement( 'form' ) );