MediaWiki  1.33.0
CategoryTree.php
Go to the documentation of this file.
1 <?php
29 class CategoryTree {
30  public $mOptions = [];
31 
36  public function __construct( array $options ) {
37  global $wgCategoryTreeDefaultOptions;
38 
39  // ensure default values and order of options.
40  // Order may become important, it may influence the cache key!
41  foreach ( $wgCategoryTreeDefaultOptions as $option => $default ) {
42  if ( isset( $options[$option] ) ) {
43  $this->mOptions[$option] = $options[$option];
44  } else {
45  $this->mOptions[$option] = $default;
46  }
47  }
48 
49  $this->mOptions['mode'] = self::decodeMode( $this->mOptions['mode'] );
50 
51  if ( $this->mOptions['mode'] == CategoryTreeMode::PARENTS ) {
52  // namespace filter makes no sense with CategoryTreeMode::PARENTS
53  $this->mOptions['namespaces'] = false;
54  }
55 
56  $this->mOptions['hideprefix'] = self::decodeHidePrefix( $this->mOptions['hideprefix'] );
57  $this->mOptions['showcount'] = self::decodeBoolean( $this->mOptions['showcount'] );
58  $this->mOptions['namespaces'] = self::decodeNamespaces( $this->mOptions['namespaces'] );
59 
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 ) {
64  $this->mOptions['mode'] = CategoryTreeMode::CATEGORIES;
65  } elseif ( !in_array( NS_FILE, $this->mOptions['namespaces'] ) ) {
66  $this->mOptions['mode'] = CategoryTreeMode::PAGES;
67  } else {
68  $this->mOptions['mode'] = CategoryTreeMode::ALL;
69  }
70  }
71  }
72 
77  public function getOption( $name ) {
78  return $this->mOptions[$name];
79  }
80 
84  private function isInverse() {
85  return $this->getOption( 'mode' ) == CategoryTreeMode::PARENTS;
86  }
87 
92  private static function decodeNamespaces( $nn ) {
93  global $wgContLang;
94 
95  if ( $nn === false || is_null( $nn ) ) {
96  return false;
97  }
98 
99  if ( !is_array( $nn ) ) {
100  $nn = preg_split( '![\s#:|]+!', $nn );
101  }
102 
103  $namespaces = [];
104 
105  foreach ( $nn as $n ) {
106  if ( is_int( $n ) ) {
107  $ns = $n;
108  } else {
109  $n = trim( $n );
110  if ( $n === '' ) {
111  continue;
112  }
113 
114  $lower = strtolower( $n );
115 
116  if ( is_numeric( $n ) ) {
117  $ns = (int)$n;
118  } elseif ( $n == '-' || $n == '_' || $n == '*' || $lower == 'main' ) {
119  $ns = NS_MAIN;
120  } else {
121  $ns = $wgContLang->getNsIndex( $n );
122  }
123  }
124 
125  if ( is_int( $ns ) ) {
126  $namespaces[] = $ns;
127  }
128  }
129 
130  # get elements into canonical order
131  sort( $namespaces );
132  return $namespaces;
133  }
134 
139  public static function decodeMode( $mode ) {
140  global $wgCategoryTreeDefaultOptions;
141 
142  if ( is_null( $mode ) ) {
143  return $wgCategoryTreeDefaultOptions['mode'];
144  }
145  if ( is_int( $mode ) ) {
146  return $mode;
147  }
148 
149  $mode = trim( strtolower( $mode ) );
150 
151  if ( is_numeric( $mode ) ) {
152  return (int)$mode;
153  }
154 
155  if ( $mode == 'all' ) {
156  $mode = CategoryTreeMode::ALL;
157  } elseif ( $mode == 'pages' ) {
158  $mode = CategoryTreeMode::PAGES;
159  } elseif ( $mode == 'categories' || $mode == 'sub' ) {
161  } elseif ( $mode == 'parents' || $mode == 'super' || $mode == 'inverse' ) {
163  } elseif ( $mode == 'default' ) {
164  $mode = $wgCategoryTreeDefaultOptions['mode'];
165  }
166 
167  return (int)$mode;
168  }
169 
176  public static function decodeBoolean( $value ) {
177  if ( is_null( $value ) ) {
178  return null;
179  }
180  if ( is_bool( $value ) ) {
181  return $value;
182  }
183  if ( is_int( $value ) ) {
184  return ( $value > 0 );
185  }
186 
187  $value = trim( strtolower( $value ) );
188  if ( is_numeric( $value ) ) {
189  return ( (int)$value > 0 );
190  }
191 
192  if ( $value == 'yes' || $value == 'y'
193  || $value == 'true' || $value == 't' || $value == 'on'
194  ) {
195  return true;
196  } elseif ( $value == 'no' || $value == 'n'
197  || $value == 'false' || $value == 'f' || $value == 'off'
198  ) {
199  return false;
200  } elseif ( $value == 'null' || $value == 'default' || $value == 'none' || $value == 'x' ) {
201  return null;
202  } else {
203  return false;
204  }
205  }
206 
211  public static function decodeHidePrefix( $value ) {
212  global $wgCategoryTreeDefaultOptions;
213 
214  if ( is_null( $value ) ) {
215  return $wgCategoryTreeDefaultOptions['hideprefix'];
216  }
217  if ( is_int( $value ) ) {
218  return $value;
219  }
220  if ( $value === true ) {
222  }
223  if ( $value === false ) {
225  }
226 
227  $value = trim( strtolower( $value ) );
228 
229  if ( $value == 'yes' || $value == 'y'
230  || $value == 'true' || $value == 't' || $value == 'on'
231  ) {
233  } elseif ( $value == 'no' || $value == 'n'
234  || $value == 'false' || $value == 'f' || $value == 'off'
235  ) {
237  } elseif ( $value == 'always' ) {
239  } elseif ( $value == 'never' ) {
241  } elseif ( $value == 'auto' ) {
243  } elseif ( $value == 'categories' || $value == 'category' || $value == 'smart' ) {
245  } else {
246  return $wgCategoryTreeDefaultOptions['hideprefix'];
247  }
248  }
249 
254  public static function setHeaders( OutputPage $outputPage ) {
255  # Add the modules
256  $outputPage->addModuleStyles( 'ext.categoryTree.styles' );
257  $outputPage->addModules( 'ext.categoryTree' );
258  }
259 
266  protected static function encodeOptions( array $options, $enc ) {
267  if ( $enc == 'mode' || $enc == '' ) {
268  $opt = $options['mode'];
269  } elseif ( $enc == 'json' ) {
271  } else {
272  throw new Exception( 'Unknown encoding for CategoryTree options: ' . $enc );
273  }
274 
275  return $opt;
276  }
277 
282  public function getOptionsAsCacheKey( $depth = null ) {
283  $key = "";
284 
285  foreach ( $this->mOptions as $k => $v ) {
286  if ( is_array( $v ) ) {
287  $v = implode( '|', $v );
288  }
289  $key .= $k . ':' . $v . ';';
290  }
291 
292  if ( !is_null( $depth ) ) {
293  $key .= ";depth=" . $depth;
294  }
295  return $key;
296  }
297 
302  public function getOptionsAsJsStructure( $depth = null ) {
303  if ( $depth !== null ) {
305  $opt['depth'] = $depth;
306  $s = self::encodeOptions( $opt, 'json' );
307  } else {
308  $s = self::encodeOptions( $this->mOptions, 'json' );
309  }
310 
311  return $s;
312  }
313 
317  private function getOptionsAsUrlParameters() {
318  return http_build_query( $this->mOptions );
319  }
320 
333  public function getTag( Parser $parser = null, $category, $hideroot = false, array $attr = [],
334  $depth = 1, $allowMissing = false
335  ) {
336  global $wgCategoryTreeDisableCache;
337 
338  $category = trim( $category );
339  if ( $category === '' ) {
340  return false;
341  }
342 
343  if ( $parser ) {
344  if ( $wgCategoryTreeDisableCache === true ) {
345  $parser->disableCache();
346  } elseif ( is_int( $wgCategoryTreeDisableCache ) ) {
347  $parser->getOutput()->updateCacheExpiry( $wgCategoryTreeDisableCache );
348  }
349  }
350 
351  $title = self::makeTitle( $category );
352 
353  if ( $title === false || $title === null ) {
354  return false;
355  }
356 
357  if ( isset( $attr['class'] ) ) {
358  $attr['class'] .= ' CategoryTreeTag';
359  } else {
360  $attr['class'] = ' CategoryTreeTag';
361  }
362 
363  $attr['data-ct-mode'] = $this->mOptions['mode'];
364  $attr['data-ct-options'] = $this->getOptionsAsJsStructure();
365 
366  $html = '';
367  $html .= Html::openElement( 'div', $attr );
368 
369  if ( !$allowMissing && !$title->getArticleID() ) {
370  $html .= Html::openElement( 'span', [ 'class' => 'CategoryTreeNotice' ] );
371  if ( $parser ) {
372  $html .= $parser->recursiveTagParse(
373  wfMessage( 'categorytree-not-found', $category )->plain() );
374  } else {
375  $html .= wfMessage( 'categorytree-not-found', $category )->parse();
376  }
377  $html .= Html::closeElement( 'span' );
378  } else {
379  if ( !$hideroot ) {
380  $html .= $this->renderNode( $title, $depth );
381  } else {
382  $html .= $this->renderChildren( $title, $depth );
383  }
384  }
385 
386  $html .= Xml::closeElement( 'div' );
387 
388  return $html;
389  }
390 
397  public function renderChildren( Title $title, $depth = 1 ) {
398  global $wgCategoryTreeMaxChildren, $wgCategoryTreeUseCategoryTable;
399 
400  if ( $title->getNamespace() != NS_CATEGORY ) {
401  // Non-categories can't have children. :)
402  return '';
403  }
404 
405  $dbr = wfGetDB( DB_REPLICA );
406 
407  $inverse = $this->isInverse();
408  $mode = $this->getOption( 'mode' );
409  $namespaces = $this->getOption( 'namespaces' );
410 
411  $tables = [ 'page', 'categorylinks' ];
412  $fields = [ 'page_id', 'page_namespace', 'page_title',
413  'page_is_redirect', 'page_len', 'page_latest', 'cl_to',
414  'cl_from' ];
415  $where = [];
416  $joins = [];
417  $options = [ 'ORDER BY' => 'cl_type, cl_sortkey', 'LIMIT' => $wgCategoryTreeMaxChildren ];
418 
419  if ( $inverse ) {
420  $joins['categorylinks'] = [ 'RIGHT JOIN', [
421  'cl_to = page_title', 'page_namespace' => NS_CATEGORY
422  ] ];
423  $where['cl_from'] = $title->getArticleID();
424  } else {
425  $joins['categorylinks'] = [ 'JOIN', 'cl_from = page_id' ];
426  $where['cl_to'] = $title->getDBkey();
427  $options['USE INDEX']['categorylinks'] = 'cl_sortkey';
428 
429  # namespace filter.
430  if ( $namespaces ) {
431  // NOTE: we assume that the $namespaces array contains only integers!
432  // decodeNamepsaces makes it so.
433  $where['page_namespace'] = $namespaces;
434  } elseif ( $mode != CategoryTreeMode::ALL ) {
435  if ( $mode == CategoryTreeMode::PAGES ) {
436  $where['cl_type'] = [ 'page', 'subcat' ];
437  } else {
438  $where['cl_type'] = 'subcat';
439  }
440  }
441  }
442 
443  # fetch member count if possible
444  $doCount = !$inverse && $wgCategoryTreeUseCategoryTable;
445 
446  if ( $doCount ) {
447  $tables = array_merge( $tables, [ 'category' ] );
448  $fields = array_merge( $fields, [
449  'cat_id', 'cat_title', 'cat_subcats', 'cat_pages', 'cat_files'
450  ] );
451  $joins['category'] = [ 'LEFT JOIN', [
452  'cat_title = page_title', 'page_namespace' => NS_CATEGORY ]
453  ];
454  }
455 
456  $res = $dbr->select( $tables, $fields, $where, __METHOD__, $options, $joins );
457 
458  # collect categories separately from other pages
459  $categories = '';
460  $other = '';
461 
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 ) {
466  $t = Title::makeTitle( NS_CATEGORY, $row->cl_to );
467  } else {
468  # TODO: translation support; ideally added to Title object
469  $t = Title::newFromRow( $row );
470  }
471 
472  $cat = null;
473 
474  if ( $doCount && $row->page_namespace == NS_CATEGORY ) {
475  $cat = Category::newFromRow( $row, $t );
476  }
477 
478  $s = $this->renderNodeInfo( $t, $cat, $depth - 1 );
479 
480  if ( $row->page_namespace == NS_CATEGORY ) {
481  $categories .= $s;
482  } else {
483  $other .= $s;
484  }
485  }
486 
487  return $categories . $other;
488  }
489 
495  public function renderParents( Title $title ) {
496  global $wgCategoryTreeMaxChildren;
497 
498  $dbr = wfGetDB( DB_REPLICA );
499 
500  $res = $dbr->select(
501  'categorylinks',
502  [
503  'page_namespace' => NS_CATEGORY,
504  'page_title' => 'cl_to',
505  ],
506  [ 'cl_from' => $title->getArticleID() ],
507  __METHOD__,
508  [
509  'LIMIT' => $wgCategoryTreeMaxChildren,
510  'ORDER BY' => 'cl_to'
511  ]
512  );
513 
514  $special = SpecialPage::getTitleFor( 'CategoryTree' );
515 
516  $s = '';
517 
518  foreach ( $res as $row ) {
519  $t = Title::newFromRow( $row );
520 
521  $label = $t->getText();
522 
523  $wikiLink = $special->getLocalURL( 'target=' . $t->getPartialURL() .
524  '&' . $this->getOptionsAsUrlParameters() );
525 
526  if ( $s !== '' ) {
527  $s .= wfMessage( 'pipe-separator' )->escaped();
528  }
529 
530  $s .= Xml::openElement( 'span', [ 'class' => 'CategoryTreeItem' ] );
531  $s .= Xml::element( 'a', [ 'class' => 'CategoryTreeLabel', 'href' => $wikiLink ], $label );
532  $s .= Xml::closeElement( 'span' );
533  }
534 
535  return $s;
536  }
537 
544  public function renderNode( Title $title, $children = 0 ) {
545  global $wgCategoryTreeUseCategoryTable;
546 
547  if ( $wgCategoryTreeUseCategoryTable && $title->getNamespace() == NS_CATEGORY
548  && !$this->isInverse()
549  ) {
550  $cat = Category::newFromTitle( $title );
551  } else {
552  $cat = null;
553  }
554 
555  return $this->renderNodeInfo( $title, $cat, $children );
556  }
557 
566  public function renderNodeInfo( Title $title, Category $cat = null, $children = 0 ) {
567  $mode = $this->getOption( 'mode' );
568 
569  $ns = $title->getNamespace();
570  $key = $title->getDBkey();
571 
572  $hideprefix = $this->getOption( 'hideprefix' );
573 
574  if ( $hideprefix == CategoryTreeHidePrefix::ALWAYS ) {
575  $hideprefix = true;
576  } elseif ( $hideprefix == CategoryTreeHidePrefix::AUTO ) {
577  $hideprefix = ( $mode == CategoryTreeMode::CATEGORIES );
578  } elseif ( $hideprefix == CategoryTreeHidePrefix::CATEGORIES ) {
579  $hideprefix = ( $ns == NS_CATEGORY );
580  } else {
581  $hideprefix = true;
582  }
583 
584  // when showing only categories, omit namespace in label unless we explicitely defined the
585  // configuration setting
586  // patch contributed by Manuel Schneider <manuel.schneider@wikimedia.ch>, Bug 8011
587  if ( $hideprefix ) {
588  $label = $title->getText();
589  } else {
590  $label = $title->getPrefixedText();
591  }
592 
593  $labelClass = 'CategoryTreeLabel ' . ' CategoryTreeLabelNs' . $ns;
594 
595  if ( !$title->getArticleID() ) {
596  $labelClass .= ' new';
597  $wikiLink = $title->getLocalURL( 'action=edit&redlink=1' );
598  } else {
599  $wikiLink = $title->getLocalURL();
600  }
601 
602  if ( $ns == NS_CATEGORY ) {
603  $labelClass .= ' CategoryTreeLabelCategory';
604  } else {
605  $labelClass .= ' CategoryTreeLabelPage';
606  }
607 
608  if ( ( $ns % 2 ) > 0 ) {
609  $labelClass .= ' CategoryTreeLabelTalk';
610  }
611 
612  $count = false;
613  $s = '';
614 
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.
618 
619  $s .= Xml::openElement( 'div', [ 'class' => 'CategoryTreeSection' ] );
620  $s .= Xml::openElement( 'div', [ 'class' => 'CategoryTreeItem' ] );
621 
622  $attr = [ 'class' => 'CategoryTreeBullet' ];
623 
624  if ( $ns == NS_CATEGORY ) {
625  if ( $cat ) {
626  if ( $mode == CategoryTreeMode::CATEGORIES ) {
627  $count = intval( $cat->getSubcatCount() );
628  } elseif ( $mode == CategoryTreeMode::PAGES ) {
629  $count = intval( $cat->getPageCount() ) - intval( $cat->getFileCount() );
630  } else {
631  $count = intval( $cat->getPageCount() );
632  }
633  }
634  if ( $count === 0 ) {
635  $bullet = wfMessage( 'categorytree-empty-bullet' )->escaped() . ' ';
636  $attr['class'] = 'CategoryTreeEmptyBullet';
637  } else {
638  $linkattr = [];
639 
640  $linkattr[ 'class' ] = "CategoryTreeToggle";
641  $linkattr['data-ct-title'] = $key;
642 
643  if ( $children == 0 ) {
644  // Use ->plain() to ensure identical result as JS,
645  // which does:
646  // $link.text( mw.msg( 'categorytree-expand-bullet' ) );
647  $txt = wfMessage( 'categorytree-expand-bullet' )->plain();
648  $linkattr[ 'data-ct-state' ] = 'collapsed';
649  } else {
650  $txt = wfMessage( 'categorytree-collapse-bullet' )->plain();
651  $linkattr[ 'data-ct-loaded' ] = true;
652  $linkattr[ 'data-ct-state' ] = 'expanded';
653  }
654 
655  $bullet = Html::element( 'span', $linkattr, $txt ) . ' ';
656  }
657  } else {
658  $bullet = wfMessage( 'categorytree-page-bullet' )->escaped();
659  }
660  $s .= Xml::tags( 'span', $attr, $bullet ) . ' ';
661 
662  $s .= Xml::element(
663  'a',
664  [
665  'class' => $labelClass,
666  'href' => $wikiLink,
667  'title' => $title->getPrefixedText()
668  ],
669  $label
670  );
671 
672  if ( $count !== false && $this->getOption( 'showcount' ) ) {
673  $s .= self::createCountString( RequestContext::getMain(), $cat, $count );
674  }
675 
676  $s .= Xml::closeElement( 'div' );
677  $s .= Xml::openElement(
678  'div',
679  [
680  'class' => 'CategoryTreeChildren',
681  'style' => $children > 0 ? "display:block" : "display:none"
682  ]
683  );
684 
685  if ( $ns == NS_CATEGORY && $children > 0 ) {
686  $children = $this->renderChildren( $title, $children );
687  if ( $children == '' ) {
688  $s .= Xml::openElement( 'i', [ 'class' => 'CategoryTreeNotice' ] );
689  if ( $mode == CategoryTreeMode::CATEGORIES ) {
690  $s .= wfMessage( 'categorytree-no-subcategories' )->escaped();
691  } elseif ( $mode == CategoryTreeMode::PAGES ) {
692  $s .= wfMessage( 'categorytree-no-pages' )->escaped();
693  } elseif ( $mode == CategoryTreeMode::PARENTS ) {
694  $s .= wfMessage( 'categorytree-no-parent-categories' )->escaped();
695  } else {
696  $s .= wfMessage( 'categorytree-nothing-found' )->escaped();
697  }
698  $s .= Xml::closeElement( 'i' );
699  } else {
700  $s .= $children;
701  }
702  }
703 
704  $s .= Xml::closeElement( 'div' );
705  $s .= Xml::closeElement( 'div' );
706 
707  return $s;
708  }
709 
718  public static function createCountString( IContextSource $context, Category $cat = null,
719  $countMode
720  ) {
721  global $wgContLang;
722 
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;
730 
731  $attr = [
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()
736  ];
737 
738  $s = $wgContLang->getDirMark() . ' ';
739 
740  # Create a list of category members with only non-zero member counts
741  $memberNums = [];
742  if ( $subcatCount ) {
743  $memberNums[] = $context->msg( 'categorytree-num-categories' )
744  ->numParams( $subcatCount )->text();
745  }
746  if ( $pages ) {
747  $memberNums[] = $context->msg( 'categorytree-num-pages' )->numParams( $pages )->text();
748  }
749  if ( $fileCount ) {
750  $memberNums[] = $context->msg( 'categorytree-num-files' )
751  ->numParams( $fileCount )->text();
752  }
753  $memberNumsShort = $memberNums
754  ? $context->getLanguage()->commaList( $memberNums )
755  : $context->msg( 'categorytree-num-empty' )->text();
756 
757  # Only $5 is actually used in the default message.
758  # Other arguments can be used in a customized message.
759  $s .= Xml::tags(
760  'span',
761  $attr,
762  $context->msg( 'categorytree-member-num' )
763  // Do not use numParams on params 1-4, as they are only used for customisation.
764  ->params( $subcatCount, $pages, $fileCount, $allCount, $memberNumsShort )
765  ->escaped()
766  );
767 
768  return $s;
769  }
770 
776  public static function makeTitle( $title ) {
777  $title = trim( $title );
778 
779  if ( strval( $title ) === '' ) {
780  return null;
781  }
782 
783  # The title must be in the category namespace
784  # Ignore a leading Category: if there is one
786  if ( !$t || $t->getNamespace() != NS_CATEGORY || $t->getInterwiki() != '' ) {
787  // If we were given something like "Wikipedia:Foo" or "Template:",
788  // try it again but forced.
789  $title = "Category:$title";
791  }
792  return $t;
793  }
794 
802  public static function capDepth( $mode, $depth ) {
803  global $wgCategoryTreeMaxDepth;
804 
805  if ( is_numeric( $depth ) ) {
806  $depth = intval( $depth );
807  } else {
808  return 1;
809  }
810 
811  if ( is_array( $wgCategoryTreeMaxDepth ) ) {
812  $max = isset( $wgCategoryTreeMaxDepth[$mode] ) ? $wgCategoryTreeMaxDepth[$mode] : 1;
813  } elseif ( is_numeric( $wgCategoryTreeMaxDepth ) ) {
814  $max = $wgCategoryTreeMaxDepth;
815  } else {
816  wfDebug( 'CategoryTree::capDepth: $wgCategoryTreeMaxDepth is invalid.' );
817  $max = 1;
818  }
819 
820  return min( $depth, $max );
821  }
822 }
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:306
CategoryTree\getOption
getOption( $name)
Definition: CategoryTree.php:77
CategoryTree\isInverse
isInverse()
Definition: CategoryTree.php:84
$context
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
Definition: hooks.txt:2636
CategoryTree\capDepth
static capDepth( $mode, $depth)
Internal function to cap depth @suppress PhanPluginDuplicateConditionalNullCoalescing until PHP7 is r...
Definition: CategoryTree.php:802
CategoryTree\renderParents
renderParents(Title $title)
Returns a string with an HTML representation of the parents of the given category.
Definition: CategoryTree.php:495
CategoryTree\decodeMode
static decodeMode( $mode)
Definition: CategoryTree.php:139
$opt
$opt
Definition: postprocess-phan.php:115
captcha-old.count
count
Definition: captcha-old.py:249
Category
Category objects are immutable, strictly speaking.
Definition: Category.php:31
$namespaces
namespace and then decline to actually register it & $namespaces
Definition: hooks.txt:925
$tables
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
Definition: hooks.txt:979
NS_FILE
const NS_FILE
Definition: Defines.php:70
CategoryTree
Core functions for the CategoryTree extension, an AJAX based gadget to display the category structure...
Definition: CategoryTree.php:29
$s
$s
Definition: mergeMessageFileList.php:186
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:82
$res
$res
Definition: database.txt:21
CategoryTree\decodeHidePrefix
static decodeHidePrefix( $value)
Definition: CategoryTree.php:211
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:108
CategoryTree\renderNodeInfo
renderNodeInfo(Title $title, Category $cat=null, $children=0)
Returns a string with a HTML represenation of the given page.
Definition: CategoryTree.php:566
php
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
Definition: injection.txt:35
CategoryTreeHidePrefix\NEVER
const NEVER
Definition: CategoryTreeHidePrefix.php:31
CategoryTree\createCountString
static createCountString(IContextSource $context, Category $cat=null, $countMode)
Create a string which format the page, subcat and file counts of a category @suppress PhanParamReqAft...
Definition: CategoryTree.php:718
CategoryTreeMode\PAGES
const PAGES
Definition: CategoryTreeMode.php:32
$dbr
$dbr
Definition: testCompression.php:50
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
FormatJson\encode
static encode( $value, $pretty=false, $escaping=0)
Returns the JSON representation of a value.
Definition: FormatJson.php:115
$html
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
Definition: hooks.txt:1985
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:506
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2636
CategoryTreeHidePrefix\ALWAYS
const ALWAYS
Definition: CategoryTreeHidePrefix.php:33
Xml\element
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:41
$parser
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
Definition: hooks.txt:1802
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:78
array
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))
CategoryTree\getTag
getTag(Parser $parser=null, $category, $hideroot=false, array $attr=[], $depth=1, $allowMissing=false)
Custom tag implementation.
Definition: CategoryTree.php:333
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:949
Category\newFromRow
static newFromRow( $row, $title=null)
Factory function, for constructing a Category object from a result set.
Definition: Category.php:179
Category\newFromTitle
static newFromTitle( $title)
Factory function.
Definition: Category.php:146
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
$value
$value
Definition: styleTest.css.php:49
Xml\tags
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:130
CategoryTree\renderChildren
renderChildren(Title $title, $depth=1)
Returns a string with an HTML representation of the children of the given category.
Definition: CategoryTree.php:397
CategoryTreeMode\PARENTS
const PARENTS
Definition: CategoryTreeMode.php:36
CategoryTree\$mOptions
$mOptions
Definition: CategoryTree.php:30
CategoryTreeMode\ALL
const ALL
Definition: CategoryTreeMode.php:34
CategoryTree\decodeBoolean
static decodeBoolean( $value)
Helper function to convert a string to a boolean value.
Definition: CategoryTree.php:176
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:430
plain
either a plain
Definition: hooks.txt:2046
CategoryTree\__construct
__construct(array $options)
@suppress PhanTypeInvalidDimOffset
Definition: CategoryTree.php:36
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:53
CategoryTree\getOptionsAsUrlParameters
getOptionsAsUrlParameters()
Definition: CategoryTree.php:317
CategoryTree\encodeOptions
static encodeOptions(array $options, $enc)
Definition: CategoryTree.php:266
Title
Represents a title within MediaWiki.
Definition: Title.php:40
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:117
CategoryTree\getOptionsAsCacheKey
getOptionsAsCacheKey( $depth=null)
Definition: CategoryTree.php:282
$options
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
Definition: hooks.txt:1985
CategoryTreeHidePrefix\AUTO
const AUTO
Definition: CategoryTreeHidePrefix.php:37
as
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
Definition: distributors.txt:9
CategoryTree\renderNode
renderNode(Title $title, $children=0)
Returns a string with a HTML represenation of the given page.
Definition: CategoryTree.php:544
CategoryTree\makeTitle
static makeTitle( $title)
Creates a Title object from a user provided (and thus unsafe) string.
Definition: CategoryTree.php:776
$t
$t
Definition: testCompression.php:69
CategoryTree\getOptionsAsJsStructure
getOptionsAsJsStructure( $depth=null)
Definition: CategoryTree.php:302
wfMessage
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 "&lt
CategoryTreeMode\CATEGORIES
const CATEGORIES
Definition: CategoryTreeMode.php:30
CategoryTreeHidePrefix\CATEGORIES
const CATEGORIES
Definition: CategoryTreeHidePrefix.php:35
$wgContLang
$wgContLang
Definition: Setup.php:790
CategoryTree\decodeNamespaces
static decodeNamespaces( $nn)
Definition: CategoryTree.php:92
CategoryTree\setHeaders
static setHeaders(OutputPage $outputPage)
Add ResourceLoader modules to the OutputPage object.
Definition: CategoryTree.php:254