Go to the documentation of this file.
36 global $wgCategoryTreeDefaultOptions;
40 foreach ( $wgCategoryTreeDefaultOptions
as $option => $default ) {
42 $this->mOptions[$option] =
$options[$option];
44 $this->mOptions[$option] = $default;
52 $this->mOptions[
'namespaces'] =
false;
59 if ( $this->mOptions[
'namespaces'] ) {
60 # automatically adjust mode to match namespace filter
61 if (
count( $this->mOptions[
'namespaces'] ) === 1
62 && $this->mOptions[
'namespaces'][0] ==
NS_CATEGORY ) {
64 } elseif ( !in_array(
NS_FILE, $this->mOptions[
'namespaces'] ) ) {
77 return $this->mOptions[
$name];
94 if ( $nn ===
false || is_null( $nn ) ) {
98 if ( !is_array( $nn ) ) {
99 $nn = preg_split(
'![\s#:|]+!', $nn );
104 foreach ( $nn
as $n ) {
105 if ( is_int( $n ) ) {
113 $lower = strtolower( $n );
115 if ( is_numeric( $n ) ) {
117 } elseif ( $n ==
'-' || $n ==
'_' || $n ==
'*' || $lower ==
'main' ) {
124 if ( is_int( $ns ) ) {
129 sort(
$namespaces ); #
get elements into canonical order
138 global $wgCategoryTreeDefaultOptions;
140 if ( is_null( $mode ) ) {
141 return $wgCategoryTreeDefaultOptions[
'mode'];
143 if ( is_int( $mode ) ) {
147 $mode = trim( strtolower( $mode ) );
149 if ( is_numeric( $mode ) ) {
153 if ( $mode ==
'all' ) {
155 } elseif ( $mode ==
'pages' ) {
157 } elseif ( $mode ==
'categories' || $mode ==
'sub' ) {
159 } elseif ( $mode ==
'parents' || $mode ==
'super' || $mode ==
'inverse' ) {
161 } elseif ( $mode ==
'default' ) {
162 $mode = $wgCategoryTreeDefaultOptions[
'mode'];
175 if ( is_null(
$value ) ) {
178 if ( is_bool(
$value ) ) {
186 if ( is_numeric(
$value ) ) {
187 return ( (
int)
$value > 0 );
210 global $wgCategoryTreeDefaultOptions;
212 if ( is_null(
$value ) ) {
213 return $wgCategoryTreeDefaultOptions[
'hideprefix'];
235 } elseif (
$value ==
'always' ) {
237 } elseif (
$value ==
'never' ) {
239 } elseif (
$value ==
'auto' ) {
244 return $wgCategoryTreeDefaultOptions[
'hideprefix'];
254 $outputPage->addModuleStyles(
'ext.categoryTree.css' );
255 $outputPage->addModules(
'ext.categoryTree' );
265 if ( $enc ==
'mode' || $enc ==
'' ) {
267 } elseif ( $enc ==
'json' ) {
270 throw new Exception(
'Unknown encoding for CategoryTree options: ' . $enc );
283 foreach ( $this->mOptions
as $k => $v ) {
284 if ( is_array( $v ) ) {
285 $v = implode(
'|', $v );
287 $key .= $k .
':' . $v .
';';
290 if ( !is_null( $depth ) ) {
291 $key .=
";depth=" . $depth;
301 if ( $depth !==
null ) {
303 $opt[
'depth'] = $depth;
316 return http_build_query( $this->mOptions );
330 public function getTag(
$parser, $category, $hideroot =
false, $attr = [], $depth = 1,
331 $allowMissing =
false
333 global $wgCategoryTreeDisableCache;
335 $category = trim( $category );
336 if ( $category ===
'' ) {
341 if ( $wgCategoryTreeDisableCache ===
true ) {
343 } elseif ( is_int( $wgCategoryTreeDisableCache ) ) {
344 $parser->getOutput()->updateCacheExpiry( $wgCategoryTreeDisableCache );
354 if ( isset( $attr[
'class'] ) ) {
355 $attr[
'class'] .=
' CategoryTreeTag';
357 $attr[
'class'] =
' CategoryTreeTag';
360 $attr[
'data-ct-mode'] = $this->mOptions[
'mode'];
366 if ( !$allowMissing && !
$title->getArticleID() ) {
372 $html .=
wfMessage(
'categorytree-not-found', $category )->parse();
395 global $wgCategoryTreeMaxChildren, $wgCategoryTreeUseCategoryTable;
408 $tables = [
'page',
'categorylinks' ];
409 $fields = [
'page_id',
'page_namespace',
'page_title',
410 'page_is_redirect',
'page_len',
'page_latest',
'cl_to',
414 $options = [
'ORDER BY' =>
'cl_type, cl_sortkey',
'LIMIT' => $wgCategoryTreeMaxChildren ];
417 $joins[
'categorylinks'] = [
'RIGHT JOIN', [
418 'cl_to = page_title',
'page_namespace' =>
NS_CATEGORY
420 $where[
'cl_from'] =
$title->getArticleID();
422 $joins[
'categorylinks'] = [
'JOIN',
'cl_from = page_id' ];
423 $where[
'cl_to'] =
$title->getDBkey();
424 $options[
'USE INDEX'][
'categorylinks'] =
'cl_sortkey';
433 $where[
'cl_type'] = [
'page',
'subcat' ];
435 $where[
'cl_type'] =
'subcat';
440 # fetch member count if possible
441 $doCount = !$inverse && $wgCategoryTreeUseCategoryTable;
445 $fields = array_merge( $fields, [
446 'cat_id',
'cat_title',
'cat_subcats',
'cat_pages',
'cat_files'
448 $joins[
'category'] = [
'LEFT JOIN', [
449 'cat_title = page_title',
'page_namespace' =>
NS_CATEGORY ]
455 # collect categories separately from other pages
459 foreach (
$res as $row ) {
460 # NOTE: in inverse mode, the page record may be null, because we use a right join.
461 # happens for categories with no category page (red cat links)
462 if ( $inverse && $row->page_title ===
null ) {
465 # TODO: translation support; ideally added to Title object
471 if ( $doCount && $row->page_namespace ==
NS_CATEGORY ) {
484 return $categories . $other;
493 global $wgCategoryTreeMaxChildren;
501 'page_title' =>
'cl_to',
503 [
'cl_from' =>
$title->getArticleID() ],
506 'LIMIT' => $wgCategoryTreeMaxChildren,
507 'ORDER BY' =>
'cl_to'
515 foreach (
$res as $row ) {
518 $label =
$t->getText();
520 $wikiLink = $special->getLocalURL(
'target=' .
$t->getPartialURL() .
528 $s .=
Xml::element(
'a', [
'class' =>
'CategoryTreeLabel',
'href' => $wikiLink ], $label );
542 global $wgCategoryTreeUseCategoryTable;
566 $ns =
$title->getNamespace();
567 $key =
$title->getDBkey();
569 $hideprefix = $this->
getOption(
'hideprefix' );
585 $label =
$title->getText();
587 $label =
$title->getPrefixedText();
590 $labelClass =
'CategoryTreeLabel ' .
' CategoryTreeLabelNs' . $ns;
592 if ( !
$title->getArticleID() ) {
593 $labelClass .=
' new';
594 $wikiLink =
$title->getLocalURL(
'action=edit&redlink=1' );
596 $wikiLink =
$title->getLocalURL();
600 $labelClass .=
' CategoryTreeLabelCategory';
602 $labelClass .=
' CategoryTreeLabelPage';
605 if ( ( $ns % 2 ) > 0 ) {
606 $labelClass .=
' CategoryTreeLabelTalk';
612 # NOTE: things in CategoryTree.js rely on the exact order of tags!
613 # Specifically, the CategoryTreeChildren div must be the first
614 # sibling with nodeName = DIV of the grandparent of the expland link.
619 $attr = [
'class' =>
'CategoryTreeBullet' ];
624 $count = intval( $cat->getSubcatCount() );
626 $count = intval( $cat->getPageCount() ) - intval( $cat->getFileCount() );
628 $count = intval( $cat->getPageCount() );
631 if ( $count === 0 ) {
632 $bullet =
wfMessage(
'categorytree-empty-bullet' )->escaped() .
' ';
633 $attr[
'class'] =
'CategoryTreeEmptyBullet';
637 $linkattr[
'class' ] =
"CategoryTreeToggle";
638 $linkattr[
'data-ct-title'] = $key;
641 if ( $children == 0 ) {
645 $txt = htmlspecialchars(
wfMessage(
'categorytree-expand-bullet' )->
plain() );
646 $linkattr[
'data-ct-state' ] =
'collapsed';
648 $txt = htmlspecialchars(
wfMessage(
'categorytree-collapse-bullet' )->
plain() );
649 $linkattr[
'data-ct-loaded' ] =
true;
650 $linkattr[
'data-ct-state' ] =
'expanded';
656 $bullet =
wfMessage(
'categorytree-page-bullet' )->escaped();
663 'class' => $labelClass,
665 'title' =>
$title->getPrefixedText()
670 if ( $count !==
false && $this->
getOption(
'showcount' ) ) {
678 'class' =>
'CategoryTreeChildren',
679 'style' => $children > 0 ?
"display:block" :
"display:none"
685 if ( $children ==
'' ) {
688 $s .=
wfMessage(
'categorytree-no-subcategories' )->escaped();
690 $s .=
wfMessage(
'categorytree-no-pages' )->escaped();
692 $s .=
wfMessage(
'categorytree-no-parent-categories' )->escaped();
694 $s .=
wfMessage(
'categorytree-nothing-found' )->escaped();
718 # Get counts, with conversion to integer so === works
719 # Note: $allCount is the total number of cat members,
720 # not the count of how many members are normal pages.
721 $allCount = $cat ? intval( $cat->getPageCount() ) : 0;
722 $subcatCount = $cat ? intval( $cat->getSubcatCount() ) : 0;
723 $fileCount = $cat ? intval( $cat->getFileCount() ) : 0;
724 $pages = $allCount - $subcatCount - $fileCount;
727 'title' =>
$context->msg(
'categorytree-member-counts' )
728 ->numParams( $subcatCount, $pages, $fileCount, $allCount, $countMode )->text(),
729 'dir' =>
$context->getLanguage()->getDir() # numbers
and commas
get messed
up in a mixed dir env
734 # Create a list of category members with only non-zero member counts
736 if ( $subcatCount ) {
737 $memberNums[] =
$context->msg(
'categorytree-num-categories' )
738 ->numParams( $subcatCount )->text();
741 $memberNums[] =
$context->msg(
'categorytree-num-pages' )->numParams( $pages )->text();
744 $memberNums[] =
$context->msg(
'categorytree-num-files' )
745 ->numParams( $fileCount )->text();
747 $memberNumsShort = $memberNums
748 ?
$context->getLanguage()->commaList( $memberNums )
749 :
$context->msg(
'categorytree-num-empty' )->text();
751 # Only $5 is actually used in the default message.
752 # Other arguments can be used in a customized message.
756 $context->msg(
'categorytree-member-num' )
758 ->params( $subcatCount, $pages, $fileCount, $allCount, $memberNumsShort )
773 if ( strval(
$title ) ===
'' ) {
777 # The title must be in the category namespace
778 # Ignore a leading Category: if there is one
783 $title =
"Category:$title";
796 global $wgCategoryTreeMaxDepth;
798 if ( is_numeric( $depth ) ) {
799 $depth = intval( $depth );
804 if ( is_array( $wgCategoryTreeMaxDepth ) ) {
805 $max = isset( $wgCategoryTreeMaxDepth[$mode] ) ? $wgCategoryTreeMaxDepth[$mode] : 1;
806 } elseif ( is_numeric( $wgCategoryTreeMaxDepth ) ) {
807 $max = $wgCategoryTreeMaxDepth;
809 wfDebug(
'CategoryTree::capDepth: $wgCategoryTreeMaxDepth is invalid.' );
813 return min( $depth, $max );
getTag( $parser, $category, $hideroot=false, $attr=[], $depth=1, $allowMissing=false)
Custom tag implementation.
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.
static decodeMode( $mode)
renderChildren( $title, $depth=1)
Returns a string with an HTML representation of the children of the given category.
renderNodeInfo( $title, $cat, $children=0)
Returns a string with a HTML represenation of the given page.
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,...
</source > ! result< div class="mw-highlight mw-content-ltr" dir="ltr">< pre >< span ></span >< span class="kd"> var</span >< span class="nx"> a</span >< span class="p"></span ></pre ></div > ! end ! test Multiline< source/> in lists !input *< source > a b</source > *foo< source > a b</source > ! html< ul >< li >< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul >< ul >< li > foo< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul > ! html tidy< ul >< li >< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul >< ul >< li > foo< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul > ! end ! test Custom attributes !input< source lang="javascript" id="foo" class="bar" dir="rtl" style="font-size: larger;"> var a
static decodeHidePrefix( $value)
static openElement( $element, $attribs=null)
This opens an XML element.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set up
static setHeaders( $outputPage)
Add ResourceLoader modules to the OutputPage object.
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 closeElement( $element)
Returns "</$element>".
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.
null for the wiki Added in
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.
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.
static decodeBoolean( $value)
Helper function to convert a string to a boolean value.
static getMain()
Get the RequestContext object associated with the main request.
renderParents( $title)
Returns a string with an HTML representation of the parents of the given category.
Interface for objects which can provide a MediaWiki context on request.
getOptionsAsUrlParameters()
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
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
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
static encodeOptions( $options, $enc)
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 "<
renderNode( $title, $children=0)
Returns a string with a HTML represenation of the given page.
static decodeNamespaces( $nn)
static createCountString(IContextSource $context, $cat, $countMode)
Create a string which format the page, subcat and file counts of a category.