MediaWiki  1.29.2
CategoryViewer.php
Go to the documentation of this file.
1 <?php
23 
26  public $limit;
27 
29  public $from;
30 
32  public $until;
33 
35  public $articles;
36 
39 
41  public $children;
42 
45 
47  public $showGallery;
48 
51 
54 
56  public $nextPage;
57 
59  protected $prevPage;
60 
62  public $flip;
63 
65  public $title;
66 
68  public $collation;
69 
71  public $gallery;
72 
74  private $cat;
75 
77  private $query;
78 
89  $until = [], $query = []
90  ) {
91  $this->title = $title;
92  $this->setContext( $context );
93  $this->getOutput()->addModuleStyles( [
94  'mediawiki.action.view.categoryPage.styles'
95  ] );
96  $this->from = $from;
97  $this->until = $until;
98  $this->limit = $context->getConfig()->get( 'CategoryPagingLimit' );
99  $this->cat = Category::newFromTitle( $title );
100  $this->query = $query;
101  $this->collation = Collation::singleton();
102  unset( $this->query['title'] );
103  }
104 
110  public function getHTML() {
111 
112  $this->showGallery = $this->getConfig()->get( 'CategoryMagicGallery' )
113  && !$this->getOutput()->mNoGallery;
114 
115  $this->clearCategoryState();
116  $this->doCategoryQuery();
117  $this->finaliseCategoryState();
118 
119  $r = $this->getSubcategorySection() .
120  $this->getPagesSection() .
121  $this->getImageSection();
122 
123  if ( $r == '' ) {
124  // If there is no category content to display, only
125  // show the top part of the navigation links.
126  // @todo FIXME: Cannot be completely suppressed because it
127  // is unknown if 'until' or 'from' makes this
128  // give 0 results.
129  $r = $r . $this->getCategoryTop();
130  } else {
131  $r = $this->getCategoryTop() .
132  $r .
133  $this->getCategoryBottom();
134  }
135 
136  // Give a proper message if category is empty
137  if ( $r == '' ) {
138  $r = $this->msg( 'category-empty' )->parseAsBlock();
139  }
140 
141  $lang = $this->getLanguage();
142  $attribs = [
143  'class' => 'mw-category-generated',
144  'lang' => $lang->getHtmlCode(),
145  'dir' => $lang->getDir()
146  ];
147  # put a div around the headings which are in the user language
148  $r = Html::openElement( 'div', $attribs ) . $r . '</div>';
149 
150  return $r;
151  }
152 
153  function clearCategoryState() {
154  $this->articles = [];
155  $this->articles_start_char = [];
156  $this->children = [];
157  $this->children_start_char = [];
158  if ( $this->showGallery ) {
159  // Note that null for mode is taken to mean use default.
160  $mode = $this->getRequest()->getVal( 'gallerymode', null );
161  try {
162  $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
163  } catch ( Exception $e ) {
164  // User specified something invalid, fallback to default.
165  $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
166  }
167 
168  $this->gallery->setHideBadImages();
169  } else {
170  $this->imgsNoGallery = [];
171  $this->imgsNoGallery_start_char = [];
172  }
173  }
174 
181  function addSubcategoryObject( Category $cat, $sortkey, $pageLength ) {
182  // Subcategory; strip the 'Category' namespace from the link text.
183  $title = $cat->getTitle();
184 
185  $this->children[] = $this->generateLink(
186  'subcat',
187  $title,
188  $title->isRedirect(),
189  htmlspecialchars( $title->getText() )
190  );
191 
192  $this->children_start_char[] =
193  $this->getSubcategorySortChar( $cat->getTitle(), $sortkey );
194  }
195 
196  function generateLink( $type, Title $title, $isRedirect, $html = null ) {
197  $link = null;
198  Hooks::run( 'CategoryViewer::generateLink', [ $type, $title, $html, &$link ] );
199  if ( $link === null ) {
200  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
201  if ( $html !== null ) {
202  $html = new HtmlArmor( $html );
203  }
204  $link = $linkRenderer->makeLink( $title, $html );
205  }
206  if ( $isRedirect ) {
207  $link = '<span class="redirect-in-category">' . $link . '</span>';
208  }
209 
210  return $link;
211  }
212 
224  function getSubcategorySortChar( $title, $sortkey ) {
226 
227  if ( $title->getPrefixedText() == $sortkey ) {
228  $word = $title->getDBkey();
229  } else {
230  $word = $sortkey;
231  }
232 
233  $firstChar = $this->collation->getFirstLetter( $word );
234 
235  return $wgContLang->convert( $firstChar );
236  }
237 
245  function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) {
247  if ( $this->showGallery ) {
248  $flip = $this->flip['file'];
249  if ( $flip ) {
250  $this->gallery->insert( $title );
251  } else {
252  $this->gallery->add( $title );
253  }
254  } else {
255  $this->imgsNoGallery[] = $this->generateLink( 'image', $title, $isRedirect );
256 
257  $this->imgsNoGallery_start_char[] = $wgContLang->convert(
258  $this->collation->getFirstLetter( $sortkey ) );
259  }
260  }
261 
269  function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
271 
272  $this->articles[] = $this->generateLink( 'page', $title, $isRedirect );
273 
274  $this->articles_start_char[] = $wgContLang->convert(
275  $this->collation->getFirstLetter( $sortkey ) );
276  }
277 
279  if ( $this->flip['subcat'] ) {
280  $this->children = array_reverse( $this->children );
281  $this->children_start_char = array_reverse( $this->children_start_char );
282  }
283  if ( $this->flip['page'] ) {
284  $this->articles = array_reverse( $this->articles );
285  $this->articles_start_char = array_reverse( $this->articles_start_char );
286  }
287  if ( !$this->showGallery && $this->flip['file'] ) {
288  $this->imgsNoGallery = array_reverse( $this->imgsNoGallery );
289  $this->imgsNoGallery_start_char = array_reverse( $this->imgsNoGallery_start_char );
290  }
291  }
292 
293  function doCategoryQuery() {
294  $dbr = wfGetDB( DB_REPLICA, 'category' );
295 
296  $this->nextPage = [
297  'page' => null,
298  'subcat' => null,
299  'file' => null,
300  ];
301  $this->prevPage = [
302  'page' => null,
303  'subcat' => null,
304  'file' => null,
305  ];
306 
307  $this->flip = [ 'page' => false, 'subcat' => false, 'file' => false ];
308 
309  foreach ( [ 'page', 'subcat', 'file' ] as $type ) {
310  # Get the sortkeys for start/end, if applicable. Note that if
311  # the collation in the database differs from the one
312  # set in $wgCategoryCollation, pagination might go totally haywire.
313  $extraConds = [ 'cl_type' => $type ];
314  if ( isset( $this->from[$type] ) && $this->from[$type] !== null ) {
315  $extraConds[] = 'cl_sortkey >= '
316  . $dbr->addQuotes( $this->collation->getSortKey( $this->from[$type] ) );
317  } elseif ( isset( $this->until[$type] ) && $this->until[$type] !== null ) {
318  $extraConds[] = 'cl_sortkey < '
319  . $dbr->addQuotes( $this->collation->getSortKey( $this->until[$type] ) );
320  $this->flip[$type] = true;
321  }
322 
323  $res = $dbr->select(
324  [ 'page', 'categorylinks', 'category' ],
325  array_merge(
327  [
328  'page_namespace',
329  'page_title',
330  'cl_sortkey',
331  'cat_id',
332  'cat_title',
333  'cat_subcats',
334  'cat_pages',
335  'cat_files',
336  'cl_sortkey_prefix',
337  'cl_collation'
338  ]
339  ),
340  array_merge( [ 'cl_to' => $this->title->getDBkey() ], $extraConds ),
341  __METHOD__,
342  [
343  'USE INDEX' => [ 'categorylinks' => 'cl_sortkey' ],
344  'LIMIT' => $this->limit + 1,
345  'ORDER BY' => $this->flip[$type] ? 'cl_sortkey DESC' : 'cl_sortkey',
346  ],
347  [
348  'categorylinks' => [ 'INNER JOIN', 'cl_from = page_id' ],
349  'category' => [ 'LEFT JOIN', [
350  'cat_title = page_title',
351  'page_namespace' => NS_CATEGORY
352  ] ]
353  ]
354  );
355 
356  Hooks::run( 'CategoryViewer::doCategoryQuery', [ $type, $res ] );
357  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
358 
359  $count = 0;
360  foreach ( $res as $row ) {
361  $title = Title::newFromRow( $row );
362  $linkCache->addGoodLinkObjFromRow( $title, $row );
363 
364  if ( $row->cl_collation === '' ) {
365  // Hack to make sure that while updating from 1.16 schema
366  // and db is inconsistent, that the sky doesn't fall.
367  // See r83544. Could perhaps be removed in a couple decades...
368  $humanSortkey = $row->cl_sortkey;
369  } else {
370  $humanSortkey = $title->getCategorySortkey( $row->cl_sortkey_prefix );
371  }
372 
373  if ( ++$count > $this->limit ) {
374  # We've reached the one extra which shows that there
375  # are additional pages to be had. Stop here...
376  $this->nextPage[$type] = $humanSortkey;
377  break;
378  }
379  if ( $count == $this->limit ) {
380  $this->prevPage[$type] = $humanSortkey;
381  }
382 
383  if ( $title->getNamespace() == NS_CATEGORY ) {
384  $cat = Category::newFromRow( $row, $title );
385  $this->addSubcategoryObject( $cat, $humanSortkey, $row->page_len );
386  } elseif ( $title->getNamespace() == NS_FILE ) {
387  $this->addImage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
388  } else {
389  $this->addPage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
390  }
391  }
392  }
393  }
394 
398  function getCategoryTop() {
399  $r = $this->getCategoryBottom();
400  return $r === ''
401  ? $r
402  : "<br style=\"clear:both;\"/>\n" . $r;
403  }
404 
409  # Don't show subcategories section if there are none.
410  $r = '';
411  $rescnt = count( $this->children );
412  $dbcnt = $this->cat->getSubcatCount();
413  // This function should be called even if the result isn't used, it has side-effects
414  $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'subcat' );
415 
416  if ( $rescnt > 0 ) {
417  # Showing subcategories
418  $r .= "<div id=\"mw-subcategories\">\n";
419  $r .= '<h2>' . $this->msg( 'subcategories' )->parse() . "</h2>\n";
420  $r .= $countmsg;
421  $r .= $this->getSectionPagingLinks( 'subcat' );
422  $r .= $this->formatList( $this->children, $this->children_start_char );
423  $r .= $this->getSectionPagingLinks( 'subcat' );
424  $r .= "\n</div>";
425  }
426  return $r;
427  }
428 
432  function getPagesSection() {
433  $ti = wfEscapeWikiText( $this->title->getText() );
434  # Don't show articles section if there are none.
435  $r = '';
436 
437  # @todo FIXME: Here and in the other two sections: we don't need to bother
438  # with this rigmarole if the entire category contents fit on one page
439  # and have already been retrieved. We can just use $rescnt in that
440  # case and save a query and some logic.
441  $dbcnt = $this->cat->getPageCount() - $this->cat->getSubcatCount()
442  - $this->cat->getFileCount();
443  $rescnt = count( $this->articles );
444  // This function should be called even if the result isn't used, it has side-effects
445  $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'article' );
446 
447  if ( $rescnt > 0 ) {
448  $r = "<div id=\"mw-pages\">\n";
449  $r .= '<h2>' . $this->msg( 'category_header', $ti )->parse() . "</h2>\n";
450  $r .= $countmsg;
451  $r .= $this->getSectionPagingLinks( 'page' );
452  $r .= $this->formatList( $this->articles, $this->articles_start_char );
453  $r .= $this->getSectionPagingLinks( 'page' );
454  $r .= "\n</div>";
455  }
456  return $r;
457  }
458 
462  function getImageSection() {
463  $r = '';
464  $rescnt = $this->showGallery ? $this->gallery->count() : count( $this->imgsNoGallery );
465  $dbcnt = $this->cat->getFileCount();
466  // This function should be called even if the result isn't used, it has side-effects
467  $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'file' );
468 
469  if ( $rescnt > 0 ) {
470  $r .= "<div id=\"mw-category-media\">\n";
471  $r .= '<h2>' .
472  $this->msg(
473  'category-media-header',
474  wfEscapeWikiText( $this->title->getText() )
475  )->text() .
476  "</h2>\n";
477  $r .= $countmsg;
478  $r .= $this->getSectionPagingLinks( 'file' );
479  if ( $this->showGallery ) {
480  $r .= $this->gallery->toHTML();
481  } else {
482  $r .= $this->formatList( $this->imgsNoGallery, $this->imgsNoGallery_start_char );
483  }
484  $r .= $this->getSectionPagingLinks( 'file' );
485  $r .= "\n</div>";
486  }
487  return $r;
488  }
489 
497  private function getSectionPagingLinks( $type ) {
498  if ( isset( $this->until[$type] ) && $this->until[$type] !== null ) {
499  // The new value for the until parameter should be pointing to the first
500  // result displayed on the page which is the second last result retrieved
501  // from the database.The next link should have a from parameter pointing
502  // to the until parameter of the current page.
503  if ( $this->nextPage[$type] !== null ) {
504  return $this->pagingLinks( $this->prevPage[$type], $this->until[$type], $type );
505  } else {
506  // If the nextPage variable is null, it means that we have reached the first page
507  // and therefore the previous link should be disabled.
508  return $this->pagingLinks( null, $this->until[$type], $type );
509  }
510  } elseif ( $this->nextPage[$type] !== null
511  || ( isset( $this->from[$type] ) && $this->from[$type] !== null )
512  ) {
513  return $this->pagingLinks( $this->from[$type], $this->nextPage[$type], $type );
514  } else {
515  return '';
516  }
517  }
518 
522  function getCategoryBottom() {
523  return '';
524  }
525 
536  function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
537  $list = '';
538  if ( count( $articles ) > $cutoff ) {
540  } elseif ( count( $articles ) > 0 ) {
541  // for short lists of articles in categories.
543  }
544 
545  $pageLang = $this->title->getPageLanguage();
546  $attribs = [ 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
547  'class' => 'mw-content-' . $pageLang->getDir() ];
548  $list = Html::rawElement( 'div', $attribs, $list );
549 
550  return $list;
551  }
552 
568  $columns = array_combine( $articles, $articles_start_char );
569 
570  $ret = Html::openElement( 'div', [ 'class' => 'mw-category' ] );
571 
572  $colContents = [];
573 
574  # Kind of like array_flip() here, but we keep duplicates in an
575  # array instead of dropping them.
576  foreach ( $columns as $article => $char ) {
577  if ( !isset( $colContents[$char] ) ) {
578  $colContents[$char] = [];
579  }
580  $colContents[$char][] = $article;
581  }
582 
583  foreach ( $colContents as $char => $articles ) {
584  # Change space to non-breaking space to keep headers aligned
585  $h3char = $char === ' ' ? '&#160;' : htmlspecialchars( $char );
586 
587  $ret .= '<div class="mw-category-group"><h3>' . $h3char;
588  $ret .= "</h3>\n";
589 
590  $ret .= '<ul><li>';
591  $ret .= implode( "</li>\n<li>", $articles );
592  $ret .= '</li></ul></div>';
593 
594  }
595 
596  $ret .= Html::closeElement( 'div' );
597  return $ret;
598  }
599 
609  $r = '<h3>' . htmlspecialchars( $articles_start_char[0] ) . "</h3>\n";
610  $r .= '<ul><li>' . $articles[0] . '</li>';
611  $articleCount = count( $articles );
612  for ( $index = 1; $index < $articleCount; $index++ ) {
613  if ( $articles_start_char[$index] != $articles_start_char[$index - 1] ) {
614  $r .= "</ul><h3>" . htmlspecialchars( $articles_start_char[$index] ) . "</h3>\n<ul>";
615  }
616 
617  $r .= "<li>{$articles[$index]}</li>";
618  }
619  $r .= '</ul>';
620  return $r;
621  }
622 
632  private function pagingLinks( $first, $last, $type = '' ) {
633  $prevLink = $this->msg( 'prev-page' )->text();
634 
635  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
636  if ( $first != '' ) {
637  $prevQuery = $this->query;
638  $prevQuery["{$type}until"] = $first;
639  unset( $prevQuery["{$type}from"] );
640  $prevLink = $linkRenderer->makeKnownLink(
641  $this->addFragmentToTitle( $this->title, $type ),
642  $prevLink,
643  [],
644  $prevQuery
645  );
646  }
647 
648  $nextLink = $this->msg( 'next-page' )->text();
649 
650  if ( $last != '' ) {
651  $lastQuery = $this->query;
652  $lastQuery["{$type}from"] = $last;
653  unset( $lastQuery["{$type}until"] );
654  $nextLink = $linkRenderer->makeKnownLink(
655  $this->addFragmentToTitle( $this->title, $type ),
656  $nextLink,
657  [],
658  $lastQuery
659  );
660  }
661 
662  return $this->msg( 'categoryviewer-pagedlinks' )->rawParams( $prevLink, $nextLink )->escaped();
663  }
664 
674  private function addFragmentToTitle( $title, $section ) {
675  switch ( $section ) {
676  case 'page':
677  $fragment = 'mw-pages';
678  break;
679  case 'subcat':
680  $fragment = 'mw-subcategories';
681  break;
682  case 'file':
683  $fragment = 'mw-category-media';
684  break;
685  default:
686  throw new MWException( __METHOD__ .
687  " Invalid section $section." );
688  }
689 
691  $title->getDBkey(), $fragment );
692  }
693 
704  private function getCountMessage( $rescnt, $dbcnt, $type ) {
705  // There are three cases:
706  // 1) The category table figure seems sane. It might be wrong, but
707  // we can't do anything about it if we don't recalculate it on ev-
708  // ery category view.
709  // 2) The category table figure isn't sane, like it's smaller than the
710  // number of actual results, *but* the number of results is less
711  // than $this->limit and there's no offset. In this case we still
712  // know the right figure.
713  // 3) We have no idea.
714 
715  // Check if there's a "from" or "until" for anything
716 
717  // This is a little ugly, but we seem to use different names
718  // for the paging types then for the messages.
719  if ( $type === 'article' ) {
720  $pagingType = 'page';
721  } else {
722  $pagingType = $type;
723  }
724 
725  $fromOrUntil = false;
726  if ( ( isset( $this->from[$pagingType] ) && $this->from[$pagingType] !== null ) ||
727  ( isset( $this->until[$pagingType] ) && $this->until[$pagingType] !== null )
728  ) {
729  $fromOrUntil = true;
730  }
731 
732  if ( $dbcnt == $rescnt ||
733  ( ( $rescnt == $this->limit || $fromOrUntil ) && $dbcnt > $rescnt )
734  ) {
735  // Case 1: seems sane.
736  $totalcnt = $dbcnt;
737  } elseif ( $rescnt < $this->limit && !$fromOrUntil ) {
738  // Case 2: not sane, but salvageable. Use the number of results.
739  // Since there are fewer than 200, we can also take this opportunity
740  // to refresh the incorrect category table entry -- which should be
741  // quick due to the small number of entries.
742  $totalcnt = $rescnt;
743  DeferredUpdates::addCallableUpdate( [ $this->cat, 'refreshCounts' ] );
744  } else {
745  // Case 3: hopeless. Don't give a total count at all.
746  // Messages: category-subcat-count-limited, category-article-count-limited,
747  // category-file-count-limited
748  return $this->msg( "category-$type-count-limited" )->numParams( $rescnt )->parseAsBlock();
749  }
750  // Messages: category-subcat-count, category-article-count, category-file-count
751  return $this->msg( "category-$type-count" )->numParams( $rescnt, $totalcnt )->parseAsBlock();
752  }
753 }
CategoryViewer\$children
array $children
Definition: CategoryViewer.php:41
CategoryViewer\$query
array $query
The original query array, to be used in generating paging links.
Definition: CategoryViewer.php:77
Category\getTitle
getTitle()
Definition: Category.php:245
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:34
ContextSource\getConfig
getConfig()
Get the Config object.
Definition: ContextSource.php:68
CategoryViewer\shortList
static shortList( $articles, $articles_start_char)
Format a list of articles chunked by letter in a bullet list.
Definition: CategoryViewer.php:608
CategoryViewer\$gallery
ImageGalleryBase $gallery
Definition: CategoryViewer.php:71
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:41
HtmlArmor
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:28
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
query
For a write query
Definition: database.txt:26
ContextSource\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:187
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
captcha-old.count
count
Definition: captcha-old.py:225
$last
$last
Definition: profileinfo.php:415
ImageGalleryBase
Image gallery.
Definition: ImageGalleryBase.php:30
CategoryViewer\addFragmentToTitle
addFragmentToTitle( $title, $section)
Takes a title, and adds the fragment identifier that corresponds to the correct segment of the catego...
Definition: CategoryViewer.php:674
Category
Category objects are immutable, strictly speaking.
Definition: Category.php:31
CategoryViewer\columnList
static columnList( $articles, $articles_start_char)
Format a list of articles chunked by letter in a three-column list, ordered vertically.
Definition: CategoryViewer.php:567
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
CategoryViewer\getCountMessage
getCountMessage( $rescnt, $dbcnt, $type)
What to do if the category table conflicts with the number of results returned? This function says wh...
Definition: CategoryViewer.php:704
Title\getPrefixedText
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1451
NS_FILE
const NS_FILE
Definition: Defines.php:68
CategoryViewer\getImageSection
getImageSection()
Definition: CategoryViewer.php:462
CategoryViewer\getPagesSection
getPagesSection()
Definition: CategoryViewer.php:432
CategoryViewer\getSubcategorySortChar
getSubcategorySortChar( $title, $sortkey)
Get the character to be used for sorting subcategories.
Definition: CategoryViewer.php:224
$linkRenderer
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 after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition: hooks.txt:1956
CategoryViewer\$articles
string[] $articles
Definition: CategoryViewer.php:35
$res
$res
Definition: database.txt:21
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:78
$type
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2536
CategoryViewer\$imgsNoGallery_start_char
array $imgsNoGallery_start_char
Definition: CategoryViewer.php:50
CategoryViewer\clearCategoryState
clearCategoryState()
Definition: CategoryViewer.php:153
LinkCache\getSelectFields
static getSelectFields()
Fields that LinkCache needs to select.
Definition: LinkCache.php:213
Collation
Definition: Collation.php:27
CategoryViewer\__construct
__construct( $title, IContextSource $context, $from=[], $until=[], $query=[])
Definition: CategoryViewer.php:88
CategoryViewer\formatList
formatList( $articles, $articles_start_char, $cutoff=6)
Format a list of articles chunked by letter, either as a bullet list or a columnar format,...
Definition: CategoryViewer.php:536
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
CategoryViewer\finaliseCategoryState
finaliseCategoryState()
Definition: CategoryViewer.php:278
CategoryViewer\doCategoryQuery
doCategoryQuery()
Definition: CategoryViewer.php:293
ContextSource\getLanguage
getLanguage()
Get the Language object.
Definition: ContextSource.php:143
Collation\singleton
static singleton()
Definition: Collation.php:34
CategoryViewer\$cat
Category $cat
Category object for this page.
Definition: CategoryViewer.php:74
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:309
CategoryViewer\getSectionPagingLinks
getSectionPagingLinks( $type)
Get the paging links for a section (subcats/pages/files), to go at the top and bottom of the output.
Definition: CategoryViewer.php:497
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, IDatabase $dbw=null)
Add a callable update.
Definition: DeferredUpdates.php:111
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:901
$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:1956
MWException
MediaWiki exception.
Definition: MWException.php:26
CategoryViewer\$articles_start_char
array $articles_start_char
Definition: CategoryViewer.php:38
CategoryViewer\$imgsNoGallery
array $imgsNoGallery
Definition: CategoryViewer.php:53
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:924
CategoryViewer\$collation
Collation $collation
Definition: CategoryViewer.php:68
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:453
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
Title\getCategorySortkey
getCategorySortkey( $prefix='')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition: Title.php:4678
ContextSource\getOutput
getOutput()
Get the OutputPage object.
Definition: ContextSource.php:123
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:30
CategoryViewer\$flip
array $flip
Definition: CategoryViewer.php:62
$attribs
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 after processing & $attribs
Definition: hooks.txt:1956
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:514
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:76
CategoryViewer\addSubcategoryObject
addSubcategoryObject(Category $cat, $sortkey, $pageLength)
Add a subcategory to the internal lists, using a Category object.
Definition: CategoryViewer.php:181
ContextSource\setContext
setContext(IContextSource $context)
Set the IContextSource object.
Definition: ContextSource.php:58
CategoryViewer\getCategoryBottom
getCategoryBottom()
Definition: CategoryViewer.php:522
CategoryViewer\$from
array $from
Definition: CategoryViewer.php:29
Category\newFromRow
static newFromRow( $row, $title=null)
Factory function, for constructing a Category object from a result set.
Definition: Category.php:173
CategoryViewer\getHTML
getHTML()
Format the category data list.
Definition: CategoryViewer.php:110
CategoryViewer\$prevPage
array $prevPage
Definition: CategoryViewer.php:59
Category\newFromTitle
static newFromTitle( $title)
Factory function.
Definition: Category.php:140
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2122
CategoryViewer
Definition: CategoryViewer.php:24
CategoryViewer\$title
Title $title
Definition: CategoryViewer.php:65
CategoryViewer\generateLink
generateLink( $type, Title $title, $isRedirect, $html=null)
Definition: CategoryViewer.php:196
title
title
Definition: parserTests.txt:211
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1657
$ret
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 & $ret
Definition: hooks.txt:1956
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:55
Title
Represents a title within MediaWiki.
Definition: Title.php:39
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
Title\isRedirect
isRedirect( $flags=0)
Is this an article that is a redirect page? Uses link cache, adding it if necessary.
Definition: Title.php:3246
CategoryViewer\pagingLinks
pagingLinks( $first, $last, $type='')
Create paging links, as a helper method to getSectionPagingLinks().
Definition: CategoryViewer.php:632
$section
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
Definition: hooks.txt:2929
IContextSource\getConfig
getConfig()
Get the site configuration.
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
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:251
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
from
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable from
Definition: APACHE-LICENSE-2.0.txt:43
$article
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function array $article
Definition: hooks.txt:78
$link
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:2929
CategoryViewer\$limit
int $limit
Definition: CategoryViewer.php:26
CategoryViewer\$showGallery
bool $showGallery
Definition: CategoryViewer.php:47
CategoryViewer\getSubcategorySection
getSubcategorySection()
Definition: CategoryViewer.php:408
ImageGalleryBase\factory
static factory( $mode=false, IContextSource $context=null)
Get a new image gallery.
Definition: ImageGalleryBase.php:87
CategoryViewer\addPage
addPage( $title, $sortkey, $pageLength, $isRedirect=false)
Add a miscellaneous page.
Definition: CategoryViewer.php:269
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
CategoryViewer\$nextPage
array $nextPage
Definition: CategoryViewer.php:56
CategoryViewer\$children_start_char
array $children_start_char
Definition: CategoryViewer.php:44
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
CategoryViewer\getCategoryTop
getCategoryTop()
Definition: CategoryViewer.php:398
CategoryViewer\addImage
addImage(Title $title, $sortkey, $pageLength, $isRedirect=false)
Add a page in the image namespace.
Definition: CategoryViewer.php:245
Title\getText
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:883
array
the array() calling protocol came about after MediaWiki 1.4rc1.
$wgContLang
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 content language as $wgContLang
Definition: design.txt:56
CategoryViewer\$until
array $until
Definition: CategoryViewer.php:32