root > misc > CategoryTreeExtenstion > CategoryTreePage.php

CategoryTreePage.php

application/x-php, 4212 bytes (load raw)
<?php
/**
 * Special page for the  CategoryTree extension, an AJAX based gadget
 * to display the category structure of a wiki
 *
 * @package MediaWiki
 * @subpackage Extensions
 * @author Daniel Kinzler <duesentrieb@brightbyte.de>
 * @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 );
}

require_once( 'SpecialPage.php' );
require_once( 'CategoryTreeFunctions.php' );

class CategoryTree extends SpecialPage {
       
        var $target = '';
        var $mode = CT_MODE_CATEGORIES;
       
        /**
         * Constructor
         */

        function CategoryTree() {
                SpecialPage::SpecialPage( 'CategoryTree', 'categorytree' );
                        
                #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') );
                                
                #HACK for undefined root category
                if ( $this->target == '<rootcategory>' || $this->target == '&lt;rootcategory&gt;' ) $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 ) {
                        efCategoryTreeHeader();
                       
                        $title = efCategoryTreeMakeTitle( $this->target );
                       
                        if ( $title->getArticleID() ) {
                                $html = '';
                                $html .= wfOpenElement( 'div', array( 'class' => 'CategoryTreeParents' ) );
                                $html .= wfElement( 'span', array( 'class' => 'CategoryTreeParents' ), wfMsg( 'categorytree-parents' ) ) . ': ';
                               
                                $parents = efCategoryTreeRenderParents( $title, $this->mode );
                               
                                if ( $parents == '' ) $html .= wfMsg( 'categorytree-nothing-found' );
                                else $html .= $parents;
                               
                                $html .= wfCloseElement( 'div' );
                               
                                $html .= wfOpenElement( 'div', array( 'class' => 'CategoryTreeResult' ) );
                                $html .= efCategoryTreeRenderNode( $title, $this->mode, true );
                                $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;
        }
}

?>