mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CategoryTree
synced 2024-09-23 18:38:14 +00:00
introducing and options
This commit is contained in:
parent
68e1989db4
commit
5edb13009e
|
@ -18,7 +18,7 @@ class CategoryTreeCategoryViewer extends CategoryViewer {
|
|||
* Add a subcategory to the internal lists
|
||||
*/
|
||||
function addSubcategory( $title, $sortkey, $pageLength ) {
|
||||
global $wgContLang, $wgOut, $wgRequest;
|
||||
global $wgContLang, $wgOut, $wgRequest, $wgCategoryTreeCategoryPageMode;
|
||||
|
||||
if ( $wgRequest->getCheck( 'notree' ) ) {
|
||||
return parent::addSubcategory( $title, $sortkey, $pageLength );
|
||||
|
@ -34,13 +34,13 @@ class CategoryTreeCategoryViewer extends CategoryViewer {
|
|||
$this->categorytree = new CategoryTree;
|
||||
}
|
||||
|
||||
$this->children[] = $this->categorytree->renderNode( $title );
|
||||
$this->children[] = $this->categorytree->renderNode( $title, $wgCategoryTreeCategoryPageMode );
|
||||
|
||||
$this->children_start_char[] = $this->getSubcategorySortChar( $title, $sortkey );
|
||||
}
|
||||
|
||||
function getSubcategorySection() {
|
||||
global $wgOut, $wgRequest, $wgCookiePrefix;
|
||||
global $wgOut, $wgRequest, $wgCookiePrefix, $wgCategoryTreeCategoryPageMode;
|
||||
|
||||
if ( $wgRequest->getCheck( 'notree' ) ) {
|
||||
return parent::getSubcategorySection();
|
||||
|
@ -102,7 +102,7 @@ class CategoryTreeCategoryViewer extends CategoryViewer {
|
|||
$ct = new CategoryTree;
|
||||
|
||||
foreach ( $this->child_titles as $title ) {
|
||||
$r .= $ct->renderNode( $title );
|
||||
$r .= $ct->renderNode( $title, $wgCategoryTreeCategoryPageMode );
|
||||
}
|
||||
}
|
||||
return $r;
|
||||
|
|
|
@ -49,6 +49,8 @@ $wgCategoryTreeUnifiedView = true;
|
|||
$wgCategoryTreeOmitNamespace = false;
|
||||
$wgCategoryTreeMaxDepth = array(CT_MODE_PAGES => 1, CT_MODE_ALL => 1, CT_MODE_CATEGORIES => 2);
|
||||
$wgCategoryTreeExtPath = '/extensions/CategoryTree';
|
||||
$wgCategoryTreeDefaultMode = CT_MODE_CATEGORIES;
|
||||
$wgCategoryTreeCategoryPageMode = CT_MODE_CATEGORIES;
|
||||
|
||||
/**
|
||||
* Register extension setup hook and credits
|
||||
|
@ -103,7 +105,7 @@ function efCategoryTree() {
|
|||
* Entry point for Ajax, registered in $wgAjaxExportList.
|
||||
* This loads CategoryTreeFunctions.php and calls CategoryTree::ajax()
|
||||
*/
|
||||
function efCategoryTreeAjaxWrapper( $category, $mode = CT_MODE_CATEGORIES ) {
|
||||
function efCategoryTreeAjaxWrapper( $category, $mode ) {
|
||||
global $wgCategoryTreeHTTPCache, $wgSquidMaxAge, $wgUseSquid;
|
||||
|
||||
$ct = new CategoryTree;
|
||||
|
@ -165,6 +167,8 @@ function efCategoryTreeAsBool( $s ) {
|
|||
* This loads CategoryTreeFunctions.php and calls CategoryTree::getTag()
|
||||
*/
|
||||
function efCategoryTreeParserHook( $cat, $argv, &$parser ) {
|
||||
global $wgCategoryTreeDefaultMode;
|
||||
|
||||
$parser->mOutput->mCategoryTreeTag = true; # flag for use by efCategoryTreeParserOutput
|
||||
|
||||
static $initialized = false;
|
||||
|
@ -181,7 +185,7 @@ function efCategoryTreeParserHook( $cat, $argv, &$parser ) {
|
|||
else if ( $mode == 'categories' ) $mode = CT_MODE_CATEGORIES;
|
||||
}
|
||||
else {
|
||||
$mode = CT_MODE_CATEGORIES;
|
||||
$mode = $wgCategoryTreeDefaultMode;
|
||||
}
|
||||
|
||||
$hideroot = isset( $argv[ 'hideroot' ] ) ? efCategoryTreeAsBool( $argv[ 'hideroot' ] ) : null;
|
||||
|
|
|
@ -114,7 +114,7 @@ class CategoryTree {
|
|||
* Custom tag implementation. This is called by efCategoryTreeParserHook, which is used to
|
||||
* load CategoryTreeFunctions.php on demand.
|
||||
*/
|
||||
function getTag( &$parser, $category, $mode, $display = 'expandroot', $style = '', $depth=1 ) {
|
||||
function getTag( &$parser, $category, $mode, $hideroot = false, $style = '', $depth=1 ) {
|
||||
global $wgCategoryTreeDisableCache, $wgCategoryTreeDynamicTag;
|
||||
static $uniq = 0;
|
||||
|
||||
|
@ -139,8 +139,8 @@ class CategoryTree {
|
|||
$html .= wfCloseElement( 'span' );
|
||||
}
|
||||
else {
|
||||
if ( $display != 'hideroot' ) $html .= CategoryTree::renderNode( $title, $mode, $depth>0, $wgCategoryTreeDynamicTag, $depth-1 );
|
||||
else if ( !$wgCategoryTreeDynamicTag ) $html .= $this->renderChildren( $title, $mode, $depth-1 );
|
||||
if ( !$hideroot ) $html .= CategoryTree::renderNode( $title, $mode, $depth>0, $wgCategoryTreeDynamicTag, $depth-1 );
|
||||
else if ( !$wgCategoryTreeDynamicTag ) $html .= $this->renderChildren( $title, $mode, $depth );
|
||||
else { //FIXME: depth would need to be propagated here. this would imact the cache key, too
|
||||
$uniq += 1;
|
||||
$load = 'ct-' . $uniq . '-' . mt_rand( 1, 100000 );
|
||||
|
@ -161,8 +161,8 @@ class CategoryTree {
|
|||
* Returns a string with an HTML representation of the children of the given category.
|
||||
* $title must be a Title object
|
||||
*/
|
||||
function renderChildren( &$title, $mode = CT_MODE_CATEGORIES, $depth=0 ) {
|
||||
global $wgCategoryTreeMaxChildren;
|
||||
function renderChildren( &$title, $mode = NULL, $depth=0 ) {
|
||||
global $wgCategoryTreeMaxChildren, $wgCategoryTreeDefaultMode;
|
||||
|
||||
$dbr =& wfGetDB( DB_SLAVE );
|
||||
|
||||
|
@ -170,6 +170,8 @@ class CategoryTree {
|
|||
$transFields = '';
|
||||
$transJoin = '';
|
||||
$transWhere = '';
|
||||
|
||||
if ( $mode === NULL ) $wgCategoryTreeDefaultMode;
|
||||
|
||||
#namespace filter. Should be configurable
|
||||
if ( $mode == CT_MODE_ALL ) $nsmatch = '';
|
||||
|
@ -268,10 +270,11 @@ class CategoryTree {
|
|||
* Returns a string with a HTML represenation of the given page.
|
||||
* $title must be a Title object
|
||||
*/
|
||||
function renderNode( &$title, $mode = CT_MODE_CATEGORIES, $children = false, $loadchildren = false, $depth = 1 ) {
|
||||
global $wgCategoryTreeOmitNamespace;
|
||||
function renderNode( &$title, $mode = NULL, $children = false, $loadchildren = false, $depth = 1 ) {
|
||||
global $wgCategoryTreeOmitNamespace, $wgCategoryTreeDefaultMode;
|
||||
static $uniq = 0;
|
||||
|
||||
if ( $mode === NULL ) $wgCategoryTreeDefaultMode;
|
||||
$load = false;
|
||||
|
||||
if ( $children && $loadchildren ) {
|
||||
|
|
36
README
36
README
|
@ -57,9 +57,10 @@ attributes, using a HTML-like syntax:
|
|||
|
||||
* onlyroot - set this to "on" show only the "root" node of the tree initially
|
||||
|
||||
* mode - can be "categories" (the default), "pages" or "all". "categories"
|
||||
only lists subcategories; "pages" lists all pages in the category
|
||||
except images; "all" shows all pages in the category.
|
||||
* mode - can be "categories", "pages" or "all". See the Modes section below.
|
||||
The default for this attribute is controlled by
|
||||
$wgCategoryTreeDefaultMode, and is initially set to CT_MODE_CATEGORIES,
|
||||
the equivalent of setting the mode attribute to "categories".
|
||||
|
||||
* style - can be used to specify any CSS styles you would like for the
|
||||
tree.
|
||||
|
@ -69,6 +70,17 @@ name of a category and then browse it's content. The CategoryTree
|
|||
extension also adds a tab for this special page to every category page.
|
||||
|
||||
|
||||
MODES
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
The category tree can be shown in different modes, determining what types of
|
||||
"leaves" the "tree" has:
|
||||
* categories (constant CT_MODE_CATEGORIES): show subcategories only
|
||||
* pages (constant CT_MODE_PAGES): show subcategories and pages, except images
|
||||
* all (constant CT_MODE_ALL): show all pages, subcategories, images, etc
|
||||
|
||||
The CT_MODE_XXX constants can be used with configuration optiosn (see below).
|
||||
|
||||
OPTIONS
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
|
@ -94,15 +106,23 @@ $wgCategoryTreeOmitNamespace - never show namespace prefix. Default is
|
|||
<manuel.schneider@wikimedia.ch>, Bug 8011
|
||||
|
||||
$wgCategoryMaxDepth - maximum value for depth argument; can be an integer,
|
||||
or an array of two integers. The first element is the
|
||||
maximum depth for the "pages" and "all" modes; the
|
||||
second is for the categories mode. Ignored if
|
||||
$wgCategoryTreeDynamicTag is true. Patch contributed by
|
||||
Steve Sanbeg.
|
||||
or an associative array, mapping CT_MODE_XXX constants
|
||||
to the maximum depth for that mode.
|
||||
Ignored if $wgCategoryTreeDynamicTag is true. Introduced
|
||||
by Steve Sanbeg.
|
||||
|
||||
$wgCategoryTreeExtPath - the (URL-) path where the extension is installed,
|
||||
relative to $wgScriptPath, with leading "/". Default is
|
||||
"/extensions/CategoryTree".
|
||||
|
||||
$wgCategoryTreeDefaultMode - the default mode to use when no mode attribute
|
||||
is specified in a <categorytree> tag. May be
|
||||
CT_MODE_CATEGORIES (the default), CT_MODE_PAGES, or
|
||||
CT_MODE_ALL.
|
||||
|
||||
$wgCategoryTreeCategoryPageMode - the mode to use when rendering trees on
|
||||
category pages. May be CT_MODE_CATEGORIES (the default),
|
||||
CT_MODE_PAGES, or CT_MODE_ALL.
|
||||
|
||||
--------------------------------------------------------------------------
|
||||
EOF
|
||||
|
|
Loading…
Reference in a new issue