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 ) ) {
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 );
350 if ( $title ===
false || $title ===
null ) {
354 if ( isset( $attr[
'class'] ) ) {
355 $attr[
'class'] .=
' CategoryTreeTag';
357 $attr[
'class'] =
' CategoryTreeTag';
360 $attr[
'data-ct-mode'] = $this->mOptions[
'mode'];
364 $html .= Html::openElement(
'div', $attr );
366 if ( !$allowMissing && !$title->getArticleID() ) {
367 $html .= Html::openElement(
'span', [
'class' =>
'CategoryTreeNotice' ] );
372 $html .=
wfMessage(
'categorytree-not-found', $category )->parse();
374 $html .= Html::closeElement(
'span' );
383 $html .= Xml::closeElement(
'div' );
396 global $wgCategoryTreeMaxChildren, $wgCategoryTreeUseCategoryTable;
409 $tables = [
'page',
'categorylinks' ];
410 $fields = [
'page_id',
'page_namespace',
'page_title',
411 'page_is_redirect',
'page_len',
'page_latest',
'cl_to',
415 $options = [
'ORDER BY' =>
'cl_type, cl_sortkey',
'LIMIT' => $wgCategoryTreeMaxChildren ];
418 $joins[
'categorylinks'] = [
'RIGHT JOIN', [
419 'cl_to = page_title',
'page_namespace' =>
NS_CATEGORY
421 $where[
'cl_from'] = $title->getArticleID();
423 $joins[
'categorylinks'] = [
'JOIN',
'cl_from = page_id' ];
424 $where[
'cl_to'] = $title->getDBkey();
425 $options[
'USE INDEX'][
'categorylinks'] =
'cl_sortkey';
434 $where[
'cl_type'] = [
'page',
'subcat' ];
436 $where[
'cl_type'] =
'subcat';
441 # fetch member count if possible
442 $doCount = !$inverse && $wgCategoryTreeUseCategoryTable;
446 $fields = array_merge( $fields, [
447 'cat_id',
'cat_title',
'cat_subcats',
'cat_pages',
'cat_files'
449 $joins[
'category'] = [
'LEFT JOIN', [
450 'cat_title = page_title',
'page_namespace' =>
NS_CATEGORY ]
456 # collect categories separately from other pages
460 foreach (
$res as $row ) {
461 # NOTE: in inverse mode, the page record may be null, because we use a right join.
462 # happens for categories with no category page (red cat links)
463 if ( $inverse && $row->page_title ===
null ) {
466 # TODO: translation support; ideally added to Title object
467 $t = Title::newFromRow( $row );
472 if ( $doCount && $row->page_namespace ==
NS_CATEGORY ) {
473 $cat = Category::newFromRow( $row,
$t );
486 return $categories . $other;
495 global $wgCategoryTreeMaxChildren;
503 'page_title' =>
'cl_to',
505 [
'cl_from' => $title->getArticleID() ],
508 'LIMIT' => $wgCategoryTreeMaxChildren,
509 'ORDER BY' =>
'cl_to'
513 $special = SpecialPage::getTitleFor(
'CategoryTree' );
517 foreach (
$res as $row ) {
518 $t = Title::newFromRow( $row );
520 $label =
$t->getText();
522 $wikiLink = $special->getLocalURL(
'target=' .
$t->getPartialURL() .
523 '&' . $this->getOptionsAsUrlParameters() );
529 $s .= Xml::openElement(
'span', [
'class' =>
'CategoryTreeItem' ] );
530 $s .= Xml::element(
'a', [
'class' =>
'CategoryTreeLabel',
'href' => $wikiLink ], $label );
531 $s .= Xml::closeElement(
'span' );
546 global $wgCategoryTreeUseCategoryTable;
548 if ( $wgCategoryTreeUseCategoryTable && $title->getNamespace() ==
NS_CATEGORY
549 && !$this->isInverse()
551 $cat = Category::newFromTitle( $title );
570 $ns = $title->getNamespace();
571 $key = $title->getDBkey();
573 $hideprefix = $this->
getOption(
'hideprefix' );
589 $label = $title->getText();
591 $label = $title->getPrefixedText();
594 $labelClass =
'CategoryTreeLabel ' .
' CategoryTreeLabelNs' . $ns;
596 if ( !$title->getArticleID() ) {
597 $labelClass .=
' new';
598 $wikiLink = $title->getLocalURL(
'action=edit&redlink=1' );
600 $wikiLink = $title->getLocalURL();
604 $labelClass .=
' CategoryTreeLabelCategory';
606 $labelClass .=
' CategoryTreeLabelPage';
609 if ( ( $ns % 2 ) > 0 ) {
610 $labelClass .=
' CategoryTreeLabelTalk';
616 # NOTE: things in CategoryTree.js rely on the exact order of tags!
617 # Specifically, the CategoryTreeChildren div must be the first
618 # sibling with nodeName = DIV of the grandparent of the expland link.
620 $s .= Xml::openElement(
'div', [
'class' =>
'CategoryTreeSection' ] );
621 $s .= Xml::openElement(
'div', [
'class' =>
'CategoryTreeItem' ] );
623 $attr = [
'class' =>
'CategoryTreeBullet' ];
628 $count = intval( $cat->getSubcatCount() );
630 $count = intval( $cat->getPageCount() ) - intval( $cat->getFileCount() );
632 $count = intval( $cat->getPageCount() );
635 if ( $count === 0 ) {
636 $bullet =
wfMessage(
'categorytree-empty-bullet' )->escaped() .
' ';
637 $attr[
'class'] =
'CategoryTreeEmptyBullet';
641 $linkattr[
'class' ] =
"CategoryTreeToggle";
642 $linkattr[
'data-ct-title'] = $key;
645 if ( $children == 0 ) {
649 $txt = htmlspecialchars(
wfMessage(
'categorytree-expand-bullet' )->
plain() );
650 $linkattr[
'data-ct-state' ] =
'collapsed';
652 $txt = htmlspecialchars(
wfMessage(
'categorytree-collapse-bullet' )->
plain() );
653 $linkattr[
'data-ct-loaded' ] =
true;
654 $linkattr[
'data-ct-state' ] =
'expanded';
657 $bullet = Xml::openElement( $tag, $linkattr ) . $txt . Xml::closeElement( $tag ) .
' ';
660 $bullet =
wfMessage(
'categorytree-page-bullet' )->escaped();
662 $s .= Xml::tags(
'span', $attr, $bullet ) .
' ';
667 'class' => $labelClass,
669 'title' => $title->getPrefixedText()
674 if ( $count !==
false && $this->
getOption(
'showcount' ) ) {
678 $s .= Xml::closeElement(
'div' );
680 $s .= Xml::openElement(
683 'class' =>
'CategoryTreeChildren',
684 'style' => $children > 0 ?
"display:block" :
"display:none"
690 if ( $children ==
'' ) {
691 $s .= Xml::openElement(
'i', [
'class' =>
'CategoryTreeNotice' ] );
693 $s .=
wfMessage(
'categorytree-no-subcategories' )->escaped();
695 $s .=
wfMessage(
'categorytree-no-pages' )->escaped();
697 $s .=
wfMessage(
'categorytree-no-parent-categories' )->escaped();
699 $s .=
wfMessage(
'categorytree-nothing-found' )->escaped();
701 $s .= Xml::closeElement(
'i' );
707 $s .= Xml::closeElement(
'div' );
708 $s .= Xml::closeElement(
'div' );
725 # Get counts, with conversion to integer so === works
726 # Note: $allCount is the total number of cat members,
727 # not the count of how many members are normal pages.
728 $allCount = $cat ? intval( $cat->getPageCount() ) : 0;
729 $subcatCount = $cat ? intval( $cat->getSubcatCount() ) : 0;
730 $fileCount = $cat ? intval( $cat->getFileCount() ) : 0;
731 $pages = $allCount - $subcatCount - $fileCount;
734 'title' =>
$context->msg(
'categorytree-member-counts' )
735 ->numParams( $subcatCount, $pages, $fileCount, $allCount, $countMode )->text(),
736 'dir' =>
$context->getLanguage()->getDir() # numbers and commas
get messed up in a mixed dir env
741 # Create a list of category members with only non-zero member counts
743 if ( $subcatCount ) {
744 $memberNums[] =
$context->msg(
'categorytree-num-categories' )
745 ->numParams( $subcatCount )->text();
748 $memberNums[] =
$context->msg(
'categorytree-num-pages' )->numParams( $pages )->text();
751 $memberNums[] =
$context->msg(
'categorytree-num-files' )
752 ->numParams( $fileCount )->text();
754 $memberNumsShort = $memberNums
755 ?
$context->getLanguage()->commaList( $memberNums )
756 :
$context->msg(
'categorytree-num-empty' )->text();
758 # Only $5 is actually used in the default message.
759 # Other arguments can be used in a customized message.
763 $context->msg(
'categorytree-member-num' )
765 ->params( $subcatCount, $pages, $fileCount, $allCount, $memberNumsShort )
778 $title = trim( $title );
780 if ( strval( $title ) ===
'' ) {
784 # The title must be in the category namespace
785 # Ignore a leading Category: if there is one
790 $title =
"Category:$title";
791 $t = Title::newFromText( $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 );
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...
static encodeOptions( $options, $enc)
renderParents( $title)
Returns a string with an HTML representation of the parents of the given category.
renderNodeInfo( $title, $cat, $children=0)
Returns a string with a HTML represenation of the given page.
renderNode( $title, $children=0)
Returns a string with a HTML represenation of the given page.
getOptionsAsUrlParameters()
static decodeBoolean( $value)
Helper function to convert a string to a boolean value.
static decodeHidePrefix( $value)
static decodeMode( $mode)
getTag( $parser, $category, $hideroot=false, $attr=[], $depth=1, $allowMissing=false)
Custom tag implementation.
renderChildren( $title, $depth=1)
Returns a string with an HTML representation of the children of the given category.
getOptionsAsCacheKey( $depth=null)
static decodeNamespaces( $nn)
static makeTitle( $title)
Creates a Title object from a user provided (and thus unsafe) string.
static capDepth( $mode, $depth)
Internal function to cap depth.
getOptionsAsJsStructure( $depth=null)
static setHeaders( $outputPage)
Add ResourceLoader modules to the OutputPage object.
static createCountString(IContextSource $context, $cat, $countMode)
Create a string which format the page, subcat and file counts of a category.
static getMain()
Get the RequestContext object associated with the main request.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any order
do that in ParserLimitReportFormat instead $parser
this hook is for auditing only RecentChangesLinked and Watchlist 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
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
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 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.