Go to the documentation of this file.
37 global $wgCategoryTreeDefaultOptions;
41 foreach ( $wgCategoryTreeDefaultOptions
as $option => $default ) {
43 $this->mOptions[$option] =
$options[$option];
45 $this->mOptions[$option] = $default;
53 $this->mOptions[
'namespaces'] =
false;
60 if ( $this->mOptions[
'namespaces'] ) {
61 # automatically adjust mode to match namespace filter
62 if (
count( $this->mOptions[
'namespaces'] ) === 1
63 && $this->mOptions[
'namespaces'][0] ==
NS_CATEGORY ) {
65 } elseif ( !in_array(
NS_FILE, $this->mOptions[
'namespaces'] ) ) {
78 return $this->mOptions[
$name];
95 if ( $nn ===
false || is_null( $nn ) ) {
99 if ( !is_array( $nn ) ) {
100 $nn = preg_split(
'![\s#:|]+!', $nn );
105 foreach ( $nn
as $n ) {
106 if ( is_int( $n ) ) {
114 $lower = strtolower( $n );
116 if ( is_numeric( $n ) ) {
118 } elseif ( $n ==
'-' || $n ==
'_' || $n ==
'*' || $lower ==
'main' ) {
125 if ( is_int( $ns ) ) {
130 # get elements into canonical order
140 global $wgCategoryTreeDefaultOptions;
142 if ( is_null( $mode ) ) {
143 return $wgCategoryTreeDefaultOptions[
'mode'];
145 if ( is_int( $mode ) ) {
149 $mode = trim( strtolower( $mode ) );
151 if ( is_numeric( $mode ) ) {
155 if ( $mode ==
'all' ) {
157 } elseif ( $mode ==
'pages' ) {
159 } elseif ( $mode ==
'categories' || $mode ==
'sub' ) {
161 } elseif ( $mode ==
'parents' || $mode ==
'super' || $mode ==
'inverse' ) {
163 } elseif ( $mode ==
'default' ) {
164 $mode = $wgCategoryTreeDefaultOptions[
'mode'];
177 if ( is_null(
$value ) ) {
180 if ( is_bool(
$value ) ) {
188 if ( is_numeric(
$value ) ) {
189 return ( (
int)
$value > 0 );
212 global $wgCategoryTreeDefaultOptions;
214 if ( is_null(
$value ) ) {
215 return $wgCategoryTreeDefaultOptions[
'hideprefix'];
237 } elseif (
$value ==
'always' ) {
239 } elseif (
$value ==
'never' ) {
241 } elseif (
$value ==
'auto' ) {
246 return $wgCategoryTreeDefaultOptions[
'hideprefix'];
254 public static function setHeaders( OutputPage $outputPage ) {
256 $outputPage->addModuleStyles(
'ext.categoryTree.styles' );
257 $outputPage->addModules(
'ext.categoryTree' );
267 if ( $enc ==
'mode' || $enc ==
'' ) {
269 } elseif ( $enc ==
'json' ) {
272 throw new Exception(
'Unknown encoding for CategoryTree options: ' . $enc );
285 foreach ( $this->mOptions
as $k => $v ) {
286 if ( is_array( $v ) ) {
287 $v = implode(
'|', $v );
289 $key .= $k .
':' . $v .
';';
292 if ( !is_null( $depth ) ) {
293 $key .=
";depth=" . $depth;
303 if ( $depth !==
null ) {
305 $opt[
'depth'] = $depth;
318 return http_build_query( $this->mOptions );
334 $depth = 1, $allowMissing =
false
336 global $wgCategoryTreeDisableCache;
338 $category = trim( $category );
339 if ( $category ===
'' ) {
344 if ( $wgCategoryTreeDisableCache ===
true ) {
346 } elseif ( is_int( $wgCategoryTreeDisableCache ) ) {
347 $parser->getOutput()->updateCacheExpiry( $wgCategoryTreeDisableCache );
357 if ( isset( $attr[
'class'] ) ) {
358 $attr[
'class'] .=
' CategoryTreeTag';
360 $attr[
'class'] =
' CategoryTreeTag';
363 $attr[
'data-ct-mode'] = $this->mOptions[
'mode'];
367 $html .= Html::openElement(
'div', $attr );
369 if ( !$allowMissing && !
$title->getArticleID() ) {
370 $html .= Html::openElement(
'span', [
'class' =>
'CategoryTreeNotice' ] );
375 $html .=
wfMessage(
'categorytree-not-found', $category )->parse();
377 $html .= Html::closeElement(
'span' );
398 global $wgCategoryTreeMaxChildren, $wgCategoryTreeUseCategoryTable;
411 $tables = [
'page',
'categorylinks' ];
412 $fields = [
'page_id',
'page_namespace',
'page_title',
413 'page_is_redirect',
'page_len',
'page_latest',
'cl_to',
417 $options = [
'ORDER BY' =>
'cl_type, cl_sortkey',
'LIMIT' => $wgCategoryTreeMaxChildren ];
420 $joins[
'categorylinks'] = [
'RIGHT JOIN', [
421 'cl_to = page_title',
'page_namespace' =>
NS_CATEGORY
423 $where[
'cl_from'] =
$title->getArticleID();
425 $joins[
'categorylinks'] = [
'JOIN',
'cl_from = page_id' ];
426 $where[
'cl_to'] =
$title->getDBkey();
427 $options[
'USE INDEX'][
'categorylinks'] =
'cl_sortkey';
436 $where[
'cl_type'] = [
'page',
'subcat' ];
438 $where[
'cl_type'] =
'subcat';
443 # fetch member count if possible
444 $doCount = !$inverse && $wgCategoryTreeUseCategoryTable;
448 $fields = array_merge( $fields, [
449 'cat_id',
'cat_title',
'cat_subcats',
'cat_pages',
'cat_files'
451 $joins[
'category'] = [
'LEFT JOIN', [
452 'cat_title = page_title',
'page_namespace' =>
NS_CATEGORY ]
458 # collect categories separately from other pages
462 foreach (
$res as $row ) {
463 # NOTE: in inverse mode, the page record may be null, because we use a right join.
464 # happens for categories with no category page (red cat links)
465 if ( $inverse && $row->page_title ===
null ) {
468 # TODO: translation support; ideally added to Title object
474 if ( $doCount && $row->page_namespace ==
NS_CATEGORY ) {
487 return $categories . $other;
496 global $wgCategoryTreeMaxChildren;
504 'page_title' =>
'cl_to',
506 [
'cl_from' =>
$title->getArticleID() ],
509 'LIMIT' => $wgCategoryTreeMaxChildren,
510 'ORDER BY' =>
'cl_to'
518 foreach (
$res as $row ) {
521 $label =
$t->getText();
523 $wikiLink = $special->getLocalURL(
'target=' .
$t->getPartialURL() .
531 $s .=
Xml::element(
'a', [
'class' =>
'CategoryTreeLabel',
'href' => $wikiLink ], $label );
545 global $wgCategoryTreeUseCategoryTable;
569 $ns =
$title->getNamespace();
570 $key =
$title->getDBkey();
572 $hideprefix = $this->
getOption(
'hideprefix' );
588 $label =
$title->getText();
590 $label =
$title->getPrefixedText();
593 $labelClass =
'CategoryTreeLabel ' .
' CategoryTreeLabelNs' . $ns;
595 if ( !
$title->getArticleID() ) {
596 $labelClass .=
' new';
597 $wikiLink =
$title->getLocalURL(
'action=edit&redlink=1' );
599 $wikiLink =
$title->getLocalURL();
603 $labelClass .=
' CategoryTreeLabelCategory';
605 $labelClass .=
' CategoryTreeLabelPage';
608 if ( ( $ns % 2 ) > 0 ) {
609 $labelClass .=
' CategoryTreeLabelTalk';
615 # NOTE: things in CategoryTree.js rely on the exact order of tags!
616 # Specifically, the CategoryTreeChildren div must be the first
617 # sibling with nodeName = DIV of the grandparent of the expland link.
622 $attr = [
'class' =>
'CategoryTreeBullet' ];
627 $count = intval( $cat->getSubcatCount() );
629 $count = intval( $cat->getPageCount() ) - intval( $cat->getFileCount() );
631 $count = intval( $cat->getPageCount() );
634 if ( $count === 0 ) {
635 $bullet =
wfMessage(
'categorytree-empty-bullet' )->escaped() .
' ';
636 $attr[
'class'] =
'CategoryTreeEmptyBullet';
640 $linkattr[
'class' ] =
"CategoryTreeToggle";
641 $linkattr[
'data-ct-title'] = $key;
643 if ( $children == 0 ) {
647 $txt =
wfMessage(
'categorytree-expand-bullet' )->plain();
648 $linkattr[
'data-ct-state' ] =
'collapsed';
650 $txt =
wfMessage(
'categorytree-collapse-bullet' )->plain();
651 $linkattr[
'data-ct-loaded' ] =
true;
652 $linkattr[
'data-ct-state' ] =
'expanded';
655 $bullet = Html::element(
'span', $linkattr, $txt ) .
' ';
658 $bullet =
wfMessage(
'categorytree-page-bullet' )->escaped();
665 'class' => $labelClass,
667 'title' =>
$title->getPrefixedText()
672 if ( $count !==
false && $this->
getOption(
'showcount' ) ) {
680 'class' =>
'CategoryTreeChildren',
681 'style' => $children > 0 ?
"display:block" :
"display:none"
687 if ( $children ==
'' ) {
690 $s .=
wfMessage(
'categorytree-no-subcategories' )->escaped();
692 $s .=
wfMessage(
'categorytree-no-pages' )->escaped();
694 $s .=
wfMessage(
'categorytree-no-parent-categories' )->escaped();
696 $s .=
wfMessage(
'categorytree-nothing-found' )->escaped();
723 # Get counts, with conversion to integer so === works
724 # Note: $allCount is the total number of cat members,
725 # not the count of how many members are normal pages.
726 $allCount = $cat ? intval( $cat->getPageCount() ) : 0;
727 $subcatCount = $cat ? intval( $cat->getSubcatCount() ) : 0;
728 $fileCount = $cat ? intval( $cat->getFileCount() ) : 0;
729 $pages = $allCount - $subcatCount - $fileCount;
732 'title' =>
$context->msg(
'categorytree-member-counts' )
733 ->numParams( $subcatCount, $pages, $fileCount, $allCount, $countMode )->text(),
734 # numbers and commas get messed up in a mixed dir env
735 'dir' =>
$context->getLanguage()->getDir()
740 # Create a list of category members with only non-zero member counts
742 if ( $subcatCount ) {
743 $memberNums[] =
$context->msg(
'categorytree-num-categories' )
744 ->numParams( $subcatCount )->text();
747 $memberNums[] =
$context->msg(
'categorytree-num-pages' )->numParams( $pages )->text();
750 $memberNums[] =
$context->msg(
'categorytree-num-files' )
751 ->numParams( $fileCount )->text();
753 $memberNumsShort = $memberNums
754 ?
$context->getLanguage()->commaList( $memberNums )
755 :
$context->msg(
'categorytree-num-empty' )->text();
757 # Only $5 is actually used in the default message.
758 # Other arguments can be used in a customized message.
762 $context->msg(
'categorytree-member-num' )
764 ->params( $subcatCount, $pages, $fileCount, $allCount, $memberNumsShort )
779 if ( strval(
$title ) ===
'' ) {
783 # The title must be in the category namespace
784 # Ignore a leading Category: if there is one
789 $title =
"Category:$title";
803 global $wgCategoryTreeMaxDepth;
805 if ( is_numeric( $depth ) ) {
806 $depth = intval( $depth );
811 if ( is_array( $wgCategoryTreeMaxDepth ) ) {
812 $max = isset( $wgCategoryTreeMaxDepth[$mode] ) ? $wgCategoryTreeMaxDepth[$mode] : 1;
813 } elseif ( is_numeric( $wgCategoryTreeMaxDepth ) ) {
814 $max = $wgCategoryTreeMaxDepth;
816 wfDebug(
'CategoryTree::capDepth: $wgCategoryTreeMaxDepth is invalid.' );
820 return min( $depth, $max );
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
static capDepth( $mode, $depth)
Internal function to cap depth @suppress PhanPluginDuplicateConditionalNullCoalescing until PHP7 is r...
renderParents(Title $title)
Returns a string with an HTML representation of the parents of the given category.
static decodeMode( $mode)
Category objects are immutable, strictly speaking.
namespace and then decline to actually register it & $namespaces
this hook is for auditing only RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Core functions for the CategoryTree extension, an AJAX based gadget to display the category structure...
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
static decodeHidePrefix( $value)
static openElement( $element, $attribs=null)
This opens an XML element.
renderNodeInfo(Title $title, Category $cat=null, $children=0)
Returns a string with a HTML represenation of the given page.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
static createCountString(IContextSource $context, Category $cat=null, $countMode)
Create a string which format the page, subcat and file counts of a category @suppress PhanParamReqAft...
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
namespace and then decline to actually register it file or subcat img or subcat $title
static newFromRow( $row)
Make a Title object from a DB row.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
getTag(Parser $parser=null, $category, $hideroot=false, array $attr=[], $depth=1, $allowMissing=false)
Custom tag implementation.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
static newFromRow( $row, $title=null)
Factory function, for constructing a Category object from a result set.
static newFromTitle( $title)
Factory function.
Allows to change the fields on the form that will be generated $name
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
renderChildren(Title $title, $depth=1)
Returns a string with an HTML representation of the children of the given category.
static decodeBoolean( $value)
Helper function to convert a string to a boolean value.
static getMain()
Get the RequestContext object associated with the main request.
__construct(array $options)
@suppress PhanTypeInvalidDimOffset
Interface for objects which can provide a MediaWiki context on request.
getOptionsAsUrlParameters()
static encodeOptions(array $options, $enc)
Represents a title within MediaWiki.
static closeElement( $element)
Shortcut to close an XML element.
getOptionsAsCacheKey( $depth=null)
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
renderNode(Title $title, $children=0)
Returns a string with a HTML represenation of the given page.
static makeTitle( $title)
Creates a Title object from a user provided (and thus unsafe) string.
getOptionsAsJsStructure( $depth=null)
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<
static decodeNamespaces( $nn)
static setHeaders(OutputPage $outputPage)
Add ResourceLoader modules to the OutputPage object.