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
|
|
|
|
*
|
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
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
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 {
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-07-26 17:12:30 +00:00
|
|
|
var $target = '';
|
2008-06-28 20:13:20 +00:00
|
|
|
var $tree = NULL;
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-07-26 17:12:30 +00:00
|
|
|
/**
|
|
|
|
* 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 );
|
2008-02-04 10:25:48 +00:00
|
|
|
wfLoadExtensionMessages( 'CategoryTree' );
|
2006-07-26 17:12:30 +00:00
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-06-28 20:13:20 +00:00
|
|
|
function getOption( $name ) {
|
|
|
|
global $wgCategoryTreeDefaultOptions;
|
|
|
|
|
|
|
|
if ( $this->tree ) return $this->tree->getOption( $name );
|
|
|
|
else return $wgCategoryTreeDefaultOptions[$name];
|
|
|
|
}
|
|
|
|
|
2006-07-26 17:12:30 +00:00
|
|
|
/**
|
|
|
|
* Main execution function
|
|
|
|
* @param $par Parameters passed to the page
|
|
|
|
*/
|
|
|
|
function execute( $par ) {
|
2008-07-02 08:49:13 +00:00
|
|
|
global $wgRequest, $wgOut, $wgCategoryTreeDefaultOptions, $wgCategoryTreeSpecialPageOptions, $wgCategoryTreeForceHeaders;
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-07-26 17:12:30 +00:00
|
|
|
$this->setHeaders();
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2006-07-26 17:12:30 +00:00
|
|
|
if ( $par ) $this->target = $par;
|
|
|
|
else $this->target = $wgRequest->getVal( 'target', wfMsg( 'rootcategory') );
|
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
|
|
|
|
2006-07-26 17:12:30 +00:00
|
|
|
#HACK for undefined root category
|
2008-02-04 09:22:12 +00:00
|
|
|
if ( $this->target == '<rootcategory>' || $this->target == '<rootcategory>' ) $this->target = NULL;
|
|
|
|
|
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 ) {
|
2008-06-30 14:09:47 +00:00
|
|
|
if ( isset( $wgCategoryTreeSpecialPageOptions[$option] ) )
|
|
|
|
$default = $wgCategoryTreeSpecialPageOptions[$option];
|
|
|
|
|
2008-06-28 20:13:20 +00:00
|
|
|
$options[$option] = $wgRequest->getVal( $option, $default );
|
|
|
|
}
|
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
|
|
|
|
2008-07-01 13:36:50 +00:00
|
|
|
$wgOut->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
|
|
|
|
2006-07-26 17:12:30 +00:00
|
|
|
if( $this->target !== '' && $this->target !== NULL ) {
|
2008-07-02 08:49:13 +00:00
|
|
|
if ( !$wgCategoryTreeForceHeaders ) CategoryTree::setHeaders( $wgOut );
|
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() ) {
|
2008-11-06 22:20:29 +00:00
|
|
|
$wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'CategoryTreeParents' ) ) );
|
|
|
|
$wgOut->addHTML( wfMsgExt( 'categorytree-parents', 'parseinline' ) );
|
2009-01-07 22:49:54 +00:00
|
|
|
$wgOut->addHTML( wfMsg( 'colon-separator' ) );
|
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 == '' ) {
|
2008-11-06 22:20:29 +00:00
|
|
|
$wgOut->addHTML( wfMsgExt( 'categorytree-no-parent-categories', 'parseinline' ) );
|
2008-03-18 17:38:32 +00:00
|
|
|
} else {
|
2008-11-06 22:20:29 +00:00
|
|
|
$wgOut->addHTML( $parents );
|
2008-03-18 17:38:32 +00:00
|
|
|
}
|
2008-02-04 09:22:12 +00:00
|
|
|
|
2008-11-06 22:20:29 +00:00
|
|
|
$wgOut->addHTML( Xml::closeElement( 'div' ) );
|
2008-06-28 20:13:20 +00:00
|
|
|
|
2008-11-06 22:20:29 +00:00
|
|
|
$wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'CategoryTreeResult' ) ) );
|
|
|
|
$wgOut->addHTML( $this->tree->renderNode( $title, 1 ) );
|
|
|
|
$wgOut->addHTML( Xml::closeElement( 'div' ) );
|
2006-07-26 17:12:30 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-11-06 22:20:29 +00:00
|
|
|
$wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'CategoryTreeNotice' ) ) );
|
|
|
|
$wgOut->addHTML( wfMsgExt( 'categorytree-not-found', 'parseinline' , $this->target ) );
|
|
|
|
$wgOut->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
|
|
|
}
|
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() {
|
|
|
|
global $wgScript, $wgOut;
|
2006-07-26 17:12:30 +00:00
|
|
|
$thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
|
2008-06-28 20:13:20 +00:00
|
|
|
$mode = $this->getOption('mode');
|
2008-03-18 17:38:32 +00:00
|
|
|
|
2008-07-01 13:36:50 +00:00
|
|
|
$wgOut->addHTML( Xml::openElement( 'form', array( 'name' => 'categorytree', 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-categorytree-form' ) ) );
|
|
|
|
$wgOut->addHTML( Xml::openElement( 'fieldset' ) );
|
|
|
|
$wgOut->addHTML( Xml::element( 'legend', null, wfMsgNoTrans( 'categorytree-legend' ) ) );
|
|
|
|
$wgOut->addHTML( Xml::hidden( 'title', $thisTitle->getPrefixedDbKey() ) );
|
|
|
|
$wgOut->addHTML( Xml::inputLabel( wfMsgNoTrans( 'categorytree-category' ), 'target', 'target', 20, $this->target ) . ' ' );
|
|
|
|
$wgOut->addHTML( Xml::openElement( 'select', array( 'name' => 'mode' ) ) );
|
|
|
|
$wgOut->addHTML( Xml::option( wfMsgNoTrans( 'categorytree-mode-categories' ), 'categories', $mode == CT_MODE_CATEGORIES ? true : false ) );
|
|
|
|
$wgOut->addHTML( Xml::option( wfMsgNoTrans( 'categorytree-mode-pages' ), 'pages', $mode == CT_MODE_PAGES ? true : false ) );
|
|
|
|
$wgOut->addHTML( Xml::option( wfMsgNoTrans( 'categorytree-mode-all' ), 'all', $mode == CT_MODE_ALL ? true : false ) );
|
|
|
|
$wgOut->addHTML( Xml::closeElement( 'select' ) . ' ' );
|
|
|
|
$wgOut->addHTML( Xml::submitButton( wfMsgNoTrans( 'categorytree-go' ), array( 'name' => 'dotree' ) ) );
|
|
|
|
$wgOut->addHTML( Xml::closeElement( 'fieldset' ) );
|
|
|
|
$wgOut->addHTML( Xml::closeElement( 'form' ) );
|
2006-07-26 17:12:30 +00:00
|
|
|
}
|
|
|
|
}
|