41 foreach ( $wgCategoryTreeDefaultOptions as $option => $default ) {
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 ) {
78 return $this->mOptions[
$name];
95 if ( $nn ===
false ||
is_null( $nn ) ) {
105 foreach ( $nn as $n ) {
118 }
elseif ( $n ==
'-' || $n ==
'_' || $n ==
'*' || $lower ==
'main' ) {
130 # get elements into canonical order
143 return $wgCategoryTreeDefaultOptions[
'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'];
189 return ( (
int)
$value > 0 );
215 return $wgCategoryTreeDefaultOptions[
'hideprefix'];
246 return $wgCategoryTreeDefaultOptions[
'hideprefix'];
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 ) {
287 $v = implode(
'|', $v );
289 $key .= $k .
':' . $v .
';';
293 $key .=
";depth=" . $depth;
303 if ( $depth !==
null ) {
305 $opt[
'depth'] = $depth;
334 $depth = 1, $allowMissing =
false
338 $category =
trim( $category );
339 if ( $category ===
'' ) {
344 if ( $wgCategoryTreeDisableCache ===
true ) {
347 $parser->getOutput()->updateCacheExpiry( $wgCategoryTreeDisableCache );
353 if ( $title ===
false || $title ===
null ) {
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' );
386 $html .= Xml::closeElement(
'div' );
411 $tables = [
'page',
'categorylinks' ];
412 $fields = [
'page_id',
'page_namespace',
'page_title',
413 'page_is_redirect',
'page_len',
'page_latest',
'cl_to',
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
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
469 $t = Title::newFromRow( $row );
474 if ( $doCount && $row->page_namespace ==
NS_CATEGORY ) {
475 $cat = Category::newFromRow( $row,
$t );
487 return $categories .
$other;
504 'page_title' =>
'cl_to',
506 [
'cl_from' => $title->getArticleID() ],
509 'LIMIT' => $wgCategoryTreeMaxChildren,
510 'ORDER BY' =>
'cl_to'
514 $special = SpecialPage::getTitleFor(
'CategoryTree' );
518 foreach (
$res as $row ) {
519 $t = Title::newFromRow( $row );
521 $label =
$t->getText();
523 $wikiLink = $special->getLocalURL(
'target=' .
$t->getPartialURL() .
524 '&' . $this->getOptionsAsUrlParameters() );
530 $s .= Xml::openElement(
'span', [
'class' =>
'CategoryTreeItem' ] );
531 $s .= Xml::element(
'a', [
'class' =>
'CategoryTreeLabel',
'href' => $wikiLink ], $label );
532 $s .= Xml::closeElement(
'span' );
547 if ( $wgCategoryTreeUseCategoryTable && $title->getNamespace() ==
NS_CATEGORY
548 && !$this->isInverse()
550 $cat = Category::newFromTitle( $title );
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.
619 $s .= Xml::openElement(
'div', [
'class' =>
'CategoryTreeSection' ] );
620 $s .= Xml::openElement(
'div', [
'class' =>
'CategoryTreeItem' ] );
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();
660 $s .= Xml::tags(
'span', $attr, $bullet ) .
' ';
665 'class' => $labelClass,
667 'title' => $title->getPrefixedText()
672 if ( $count !==
false && $this->
getOption(
'showcount' ) ) {
676 $s .= Xml::closeElement(
'div' );
677 $s .= Xml::openElement(
680 'class' =>
'CategoryTreeChildren',
681 'style' => $children > 0 ?
"display:block" :
"display:none"
687 if ( $children ==
'' ) {
688 $s .= Xml::openElement(
'i', [
'class' =>
'CategoryTreeNotice' ] );
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();
698 $s .= Xml::closeElement(
'i' );
704 $s .= Xml::closeElement(
'div' );
705 $s .= Xml::closeElement(
'div' );
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 )
777 $title =
trim( $title );
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";
790 $t = Title::newFromText( $title );
806 $depth =
intval( $depth );
811 if (
is_array( $wgCategoryTreeMaxDepth ) ) {
812 $max =
isset( $wgCategoryTreeMaxDepth[$mode] ) ? $wgCategoryTreeMaxDepth[$mode] : 1;
816 wfDebug(
'CategoryTree::capDepth: $wgCategoryTreeMaxDepth is invalid.' );
820 return min( $depth, $max );
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
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Core functions for the CategoryTree extension, an AJAX based gadget to display the category structure...
renderNodeInfo(Title $title, Category $cat=null, $children=0)
Returns a string with a HTML represenation of the given page.
getTag(Parser $parser=null, $category, $hideroot=false, array $attr=[], $depth=1, $allowMissing=false)
Custom tag implementation.
__construct(array $options)
@suppress PhanTypeInvalidDimOffset
static setHeaders(OutputPage $outputPage)
Add ResourceLoader modules to the OutputPage object.
renderChildren(Title $title, $depth=1)
Returns a string with an HTML representation of the children of the given category.
getOptionsAsUrlParameters()
static decodeBoolean( $value)
Helper function to convert a string to a boolean value.
renderParents(Title $title)
Returns a string with an HTML representation of the parents of the given category.
static decodeHidePrefix( $value)
static decodeMode( $mode)
getOptionsAsCacheKey( $depth=null)
static decodeNamespaces( $nn)
renderNode(Title $title, $children=0)
Returns a string with a HTML represenation of the given page.
static createCountString(IContextSource $context, Category $cat=null, $countMode)
Create a string which format the page, subcat and file counts of a category @suppress PhanParamReqAft...
static makeTitle( $title)
Creates a Title object from a user provided (and thus unsafe) string.
static capDepth( $mode, $depth)
Internal function to cap depth @suppress PhanPluginDuplicateConditionalNullCoalescing until PHP7 is r...
static encodeOptions(array $options, $enc)
getOptionsAsJsStructure( $depth=null)
Category objects are immutable, strictly speaking.
This class should be covered by a general architecture document which does not exist as of January 20...
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Represents a title within MediaWiki.
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
namespace and then decline to actually register it & $namespaces
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
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
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
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 "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
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
Allows to change the fields on the form that will be generated $name
Interface for objects which can provide a MediaWiki context on request.
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))