~ubuntu-branches/ubuntu/saucy/mediawiki-extensions/saucy

« back to all changes in this revision

Viewing changes to include/CategoryTreePage.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2010-05-04 15:13:35 UTC
  • mfrom: (0.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100504151335-54qeucg3ec108q28
Tags: 2.2
* Added Replaces:/Conflicts: to allow a proper upgrade.
Closes: #580066
* Fixed package descriptions.
Closes: #579667
* Patched mediawiki-extensions-fckeditor to make it work with
  php 5.3. The fix may not be perfect but at least it work.
  Not closing the bug (#579822) for now..

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * Special page for the  CategoryTree extension, an AJAX based gadget
4
 
 * to display the category structure of a wiki
5
 
 *
6
 
 * @addtogroup Extensions
7
 
 * @author Daniel Kinzler, brightbyte.de
8
 
 * @copyright © 2006 Daniel Kinzler
9
 
 * @license GNU General Public Licence 2.0 or later
10
 
 */
11
 
 
12
 
if( !defined( 'MEDIAWIKI' ) ) {
13
 
        echo( "This file is part of an extension to the MediaWiki software and cannot be used standalone.\n" );
14
 
        die( 1 );
15
 
}
16
 
 
17
 
class CategoryTreePage extends SpecialPage {
18
 
 
19
 
        var $target = '';
20
 
        var $tree = NULL;
21
 
 
22
 
        /**
23
 
         * Constructor
24
 
         */
25
 
        function __construct() {
26
 
                global $wgOut;
27
 
                SpecialPage::SpecialPage( 'CategoryTree', '', true );
28
 
                wfLoadExtensionMessages( 'CategoryTree' );
29
 
        }
30
 
 
31
 
        function getOption( $name ) {
32
 
                global $wgCategoryTreeDefaultOptions;
33
 
 
34
 
                if ( $this->tree ) return $this->tree->getOption( $name );
35
 
                else return $wgCategoryTreeDefaultOptions[$name];
36
 
        }
37
 
 
38
 
        /**
39
 
         * Main execution function
40
 
         * @param $par Parameters passed to the page
41
 
         */
42
 
        function execute( $par ) {
43
 
                global $wgRequest, $wgOut, $wgCategoryTreeDefaultOptions, $wgCategoryTreeSpecialPageOptions, $wgCategoryTreeForceHeaders;
44
 
 
45
 
                $this->setHeaders();
46
 
 
47
 
                if ( $par ) $this->target = $par;
48
 
                else $this->target = $wgRequest->getVal( 'target', wfMsg( 'rootcategory') );
49
 
 
50
 
                $this->target = trim( $this->target );
51
 
 
52
 
                #HACK for undefined root category
53
 
                if ( $this->target == '<rootcategory>' || $this->target == '&lt;rootcategory&gt;' ) $this->target = NULL;
54
 
 
55
 
                $options = array();
56
 
 
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];
61
 
 
62
 
                        $options[$option] = $wgRequest->getVal( $option, $default );
63
 
                }
64
 
 
65
 
                $this->tree = new CategoryTree( $options );
66
 
 
67
 
                $wgOut->addWikiMsg( 'categorytree-header' );
68
 
 
69
 
                $this->executeInputForm();
70
 
 
71
 
                if( $this->target !== '' && $this->target !== NULL ) {
72
 
                        if ( !$wgCategoryTreeForceHeaders ) CategoryTree::setHeaders( $wgOut );
73
 
 
74
 
                        $title = CategoryTree::makeTitle( $this->target );
75
 
 
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' ) );
80
 
 
81
 
                                $parents = $this->tree->renderParents( $title );
82
 
 
83
 
                                if ( $parents == '' ) {
84
 
                                        $wgOut->addHTML( wfMsgExt( 'categorytree-no-parent-categories', 'parseinline' ) );
85
 
                                } else {
86
 
                                        $wgOut->addHTML( $parents );
87
 
                                }
88
 
 
89
 
                                $wgOut->addHTML( Xml::closeElement( 'div' ) );
90
 
 
91
 
                                $wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'CategoryTreeResult' ) ) );
92
 
                                $wgOut->addHTML( $this->tree->renderNode( $title, 1 ) );
93
 
                                $wgOut->addHTML( Xml::closeElement( 'div' ) );
94
 
                        }
95
 
                        else {
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' ) );
99
 
                        }
100
 
                }
101
 
 
102
 
        }
103
 
 
104
 
        /**
105
 
         * Input form for entering a category
106
 
         */
107
 
        function executeInputForm() {
108
 
                global $wgScript, $wgOut;
109
 
                $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
110
 
                $mode = $this->getOption('mode');
111
 
 
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' ) );
125
 
        }
126
 
}