MediaWiki  1.30.0
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  $this->showGallery = $this->getConfig()->get( 'CategoryMagicGallery' )
112  && !$this->getOutput()->mNoGallery;
113 
114  $this->clearCategoryState();
115  $this->doCategoryQuery();
116  $this->finaliseCategoryState();
117 
118  $r = $this->getSubcategorySection() .
119  $this->getPagesSection() .
120  $this->getImageSection();
121 
122  if ( $r == '' ) {
123  // If there is no category content to display, only
124  // show the top part of the navigation links.
125  // @todo FIXME: Cannot be completely suppressed because it
126  // is unknown if 'until' or 'from' makes this
127  // give 0 results.
128  $r = $r . $this->getCategoryTop();
129  } else {
130  $r = $this->getCategoryTop() .
131  $r .
132  $this->getCategoryBottom();
133  }
134 
135  // Give a proper message if category is empty
136  if ( $r == '' ) {
137  $r = $this->msg( 'category-empty' )->parseAsBlock();
138  }
139 
140  $lang = $this->getLanguage();
141  $attribs = [
142  'class' => 'mw-category-generated',
143  'lang' => $lang->getHtmlCode(),
144  'dir' => $lang->getDir()
145  ];
146  # put a div around the headings which are in the user language
147  $r = Html::openElement( 'div', $attribs ) . $r . '</div>';
148 
149  return $r;
150  }
151 
152  function clearCategoryState() {
153  $this->articles = [];
154  $this->articles_start_char = [];
155  $this->children = [];
156  $this->children_start_char = [];
157  if ( $this->showGallery ) {
158  // Note that null for mode is taken to mean use default.
159  $mode = $this->getRequest()->getVal( 'gallerymode', null );
160  try {
161  $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
162  } catch ( Exception $e ) {
163  // User specified something invalid, fallback to default.
164  $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
165  }
166 
167  $this->gallery->setHideBadImages();
168  } else {
169  $this->imgsNoGallery = [];
170  $this->imgsNoGallery_start_char = [];
171  }
172  }
173 
180  function addSubcategoryObject( Category $cat, $sortkey, $pageLength ) {
181  // Subcategory; strip the 'Category' namespace from the link text.
182  $title = $cat->getTitle();
183 
184  $this->children[] = $this->generateLink(
185  'subcat',
186  $title,
187  $title->isRedirect(),
188  htmlspecialchars( $title->getText() )
189  );
190 
191  $this->children_start_char[] =
192  $this->getSubcategorySortChar( $cat->getTitle(), $sortkey );
193  }
194 
195  function generateLink( $type, Title $title, $isRedirect, $html = null ) {
196  $link = null;
197  Hooks::run( 'CategoryViewer::generateLink', [ $type, $title, $html, &$link ] );
198  if ( $link === null ) {
199  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
200  if ( $html !== null ) {
201  $html = new HtmlArmor( $html );
202  }
203  $link = $linkRenderer->makeLink( $title, $html );
204  }
205  if ( $isRedirect ) {
206  $link = '<span class="redirect-in-category">' . $link . '</span>';
207  }
208 
209  return $link;
210  }
211 
223  function getSubcategorySortChar( $title, $sortkey ) {
225 
226  if ( $title->getPrefixedText() == $sortkey ) {
227  $word = $title->getDBkey();
228  } else {
229  $word = $sortkey;
230  }
231 
232  $firstChar = $this->collation->getFirstLetter( $word );
233 
234  return $wgContLang->convert( $firstChar );
235  }
236 
244  function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) {
246  if ( $this->showGallery ) {
247  $flip = $this->flip['file'];
248  if ( $flip ) {
249  $this->gallery->insert( $title );
250  } else {
251  $this->gallery->add( $title );
252  }
253  } else {
254  $this->imgsNoGallery[] = $this->generateLink( 'image', $title, $isRedirect );
255 
256  $this->imgsNoGallery_start_char[] = $wgContLang->convert(
257  $this->collation->getFirstLetter( $sortkey ) );
258  }
259  }
260 
268  function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
270 
271  $this->articles[] = $this->generateLink( 'page', $title, $isRedirect );
272 
273  $this->articles_start_char[] = $wgContLang->convert(
274  $this->collation->getFirstLetter( $sortkey ) );
275  }
276 
278  if ( $this->flip['subcat'] ) {
279  $this->children = array_reverse( $this->children );
280  $this->children_start_char = array_reverse( $this->children_start_char );
281  }
282  if ( $this->flip['page'] ) {
283  $this->articles = array_reverse( $this->articles );
284  $this->articles_start_char = array_reverse( $this->articles_start_char );
285  }
286  if ( !$this->showGallery && $this->flip['file'] ) {
287  $this->imgsNoGallery = array_reverse( $this->imgsNoGallery );
288  $this->imgsNoGallery_start_char = array_reverse( $this->imgsNoGallery_start_char );
289  }
290  }
291 
292  function doCategoryQuery() {
293  $dbr = wfGetDB( DB_REPLICA, 'category' );
294 
295  $this->nextPage = [
296  'page' => null,
297  'subcat' => null,
298  'file' => null,
299  ];
300  $this->prevPage = [
301  'page' => null,
302  'subcat' => null,
303  'file' => null,
304  ];
305 
306  $this->flip = [ 'page' => false, 'subcat' => false, 'file' => false ];
307 
308  foreach ( [ 'page', 'subcat', 'file' ] as $type ) {
309  # Get the sortkeys for start/end, if applicable. Note that if
310  # the collation in the database differs from the one
311  # set in $wgCategoryCollation, pagination might go totally haywire.
312  $extraConds = [ 'cl_type' => $type ];
313  if ( isset( $this->from[$type] ) && $this->from[$type] !== null ) {
314  $extraConds[] = 'cl_sortkey >= '
315  . $dbr->addQuotes( $this->collation->getSortKey( $this->from[$type] ) );
316  } elseif ( isset( $this->until[$type] ) && $this->until[$type] !== null ) {
317  $extraConds[] = 'cl_sortkey < '
318  . $dbr->addQuotes( $this->collation->getSortKey( $this->until[$type] ) );
319  $this->flip[$type] = true;
320  }
321 
322  $res = $dbr->select(
323  [ 'page', 'categorylinks', 'category' ],
324  array_merge(
326  [
327  'page_namespace',
328  'page_title',
329  'cl_sortkey',
330  'cat_id',
331  'cat_title',
332  'cat_subcats',
333  'cat_pages',
334  'cat_files',
335  'cl_sortkey_prefix',
336  'cl_collation'
337  ]
338  ),
339  array_merge( [ 'cl_to' => $this->title->getDBkey() ], $extraConds ),
340  __METHOD__,
341  [
342  'USE INDEX' => [ 'categorylinks' => 'cl_sortkey' ],
343  'LIMIT' => $this->limit + 1,
344  'ORDER BY' => $this->flip[$type] ? 'cl_sortkey DESC' : 'cl_sortkey',
345  ],
346  [
347  'categorylinks' => [ 'INNER JOIN', 'cl_from = page_id' ],
348  'category' => [ 'LEFT JOIN', [
349  'cat_title = page_title',
350  'page_namespace' => NS_CATEGORY
351  ] ]
352  ]
353  );
354 
355  Hooks::run( 'CategoryViewer::doCategoryQuery', [ $type, $res ] );
356  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
357 
358  $count = 0;
359  foreach ( $res as $row ) {
360  $title = Title::newFromRow( $row );
361  $linkCache->addGoodLinkObjFromRow( $title, $row );
362 
363  if ( $row->cl_collation === '' ) {
364  // Hack to make sure that while updating from 1.16 schema
365  // and db is inconsistent, that the sky doesn't fall.
366  // See r83544. Could perhaps be removed in a couple decades...
367  $humanSortkey = $row->cl_sortkey;
368  } else {
369  $humanSortkey = $title->getCategorySortkey( $row->cl_sortkey_prefix );
370  }
371 
372  if ( ++$count > $this->limit ) {
373  # We've reached the one extra which shows that there
374  # are additional pages to be had. Stop here...
375  $this->nextPage[$type] = $humanSortkey;
376  break;
377  }
378  if ( $count == $this->limit ) {
379  $this->prevPage[$type] = $humanSortkey;
380  }
381 
382  if ( $title->getNamespace() == NS_CATEGORY ) {
383  $cat = Category::newFromRow( $row, $title );
384  $this->addSubcategoryObject( $cat, $humanSortkey, $row->page_len );
385  } elseif ( $title->getNamespace() == NS_FILE ) {
386  $this->addImage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
387  } else {
388  $this->addPage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
389  }
390  }
391  }
392  }
393 
397  function getCategoryTop() {
398  $r = $this->getCategoryBottom();
399  return $r === ''
400  ? $r
401  : "<br style=\"clear:both;\"/>\n" . $r;
402  }
403 
408  # Don't show subcategories section if there are none.
409  $r = '';
410  $rescnt = count( $this->children );
411  $dbcnt = $this->cat->getSubcatCount();
412  // This function should be called even if the result isn't used, it has side-effects
413  $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'subcat' );
414 
415  if ( $rescnt > 0 ) {
416  # Showing subcategories
417  $r .= "<div id=\"mw-subcategories\">\n";
418  $r .= '<h2>' . $this->msg( 'subcategories' )->parse() . "</h2>\n";
419  $r .= $countmsg;
420  $r .= $this->getSectionPagingLinks( 'subcat' );
421  $r .= $this->formatList( $this->children, $this->children_start_char );
422  $r .= $this->getSectionPagingLinks( 'subcat' );
423  $r .= "\n</div>";
424  }
425  return $r;
426  }
427 
431  function getPagesSection() {
432  $ti = wfEscapeWikiText( $this->title->getText() );
433  # Don't show articles section if there are none.
434  $r = '';
435 
436  # @todo FIXME: Here and in the other two sections: we don't need to bother
437  # with this rigmarole if the entire category contents fit on one page
438  # and have already been retrieved. We can just use $rescnt in that
439  # case and save a query and some logic.
440  $dbcnt = $this->cat->getPageCount() - $this->cat->getSubcatCount()
441  - $this->cat->getFileCount();
442  $rescnt = count( $this->articles );
443  // This function should be called even if the result isn't used, it has side-effects
444  $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'article' );
445 
446  if ( $rescnt > 0 ) {
447  $r = "<div id=\"mw-pages\">\n";
448  $r .= '<h2>' . $this->msg( 'category_header', $ti )->parse() . "</h2>\n";
449  $r .= $countmsg;
450  $r .= $this->getSectionPagingLinks( 'page' );
451  $r .= $this->formatList( $this->articles, $this->articles_start_char );
452  $r .= $this->getSectionPagingLinks( 'page' );
453  $r .= "\n</div>";
454  }
455  return $r;
456  }
457 
461  function getImageSection() {
462  $r = '';
463  $rescnt = $this->showGallery ? $this->gallery->count() : count( $this->imgsNoGallery );
464  $dbcnt = $this->cat->getFileCount();
465  // This function should be called even if the result isn't used, it has side-effects
466  $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'file' );
467 
468  if ( $rescnt > 0 ) {
469  $r .= "<div id=\"mw-category-media\">\n";
470  $r .= '<h2>' .
471  $this->msg(
472  'category-media-header',
473  wfEscapeWikiText( $this->title->getText() )
474  )->text() .
475  "</h2>\n";
476  $r .= $countmsg;
477  $r .= $this->getSectionPagingLinks( 'file' );
478  if ( $this->showGallery ) {
479  $r .= $this->gallery->toHTML();
480  } else {
481  $r .= $this->formatList( $this->imgsNoGallery, $this->imgsNoGallery_start_char );
482  }
483  $r .= $this->getSectionPagingLinks( 'file' );
484  $r .= "\n</div>";
485  }
486  return $r;
487  }
488 
496  private function getSectionPagingLinks( $type ) {
497  if ( isset( $this->until[$type] ) && $this->until[$type] !== null ) {
498  // The new value for the until parameter should be pointing to the first
499  // result displayed on the page which is the second last result retrieved
500  // from the database.The next link should have a from parameter pointing
501  // to the until parameter of the current page.
502  if ( $this->nextPage[$type] !== null ) {
503  return $this->pagingLinks( $this->prevPage[$type], $this->until[$type], $type );
504  } else {
505  // If the nextPage variable is null, it means that we have reached the first page
506  // and therefore the previous link should be disabled.
507  return $this->pagingLinks( null, $this->until[$type], $type );
508  }
509  } elseif ( $this->nextPage[$type] !== null
510  || ( isset( $this->from[$type] ) && $this->from[$type] !== null )
511  ) {
512  return $this->pagingLinks( $this->from[$type], $this->nextPage[$type], $type );
513  } else {
514  return '';
515  }
516  }
517 
521  function getCategoryBottom() {
522  return '';
523  }
524 
535  function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
536  $list = '';
537  if ( count( $articles ) > $cutoff ) {
539  } elseif ( count( $articles ) > 0 ) {
540  // for short lists of articles in categories.
542  }
543 
544  $pageLang = $this->title->getPageLanguage();
545  $attribs = [ 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
546  'class' => 'mw-content-' . $pageLang->getDir() ];
547  $list = Html::rawElement( 'div', $attribs, $list );
548 
549  return $list;
550  }
551 
567  $columns = array_combine( $articles, $articles_start_char );
568 
569  $ret = Html::openElement( 'div', [ 'class' => 'mw-category' ] );
570 
571  $colContents = [];
572 
573  # Kind of like array_flip() here, but we keep duplicates in an
574  # array instead of dropping them.
575  foreach ( $columns as $article => $char ) {
576  if ( !isset( $colContents[$char] ) ) {
577  $colContents[$char] = [];
578  }
579  $colContents[$char][] = $article;
580  }
581 
582  foreach ( $colContents as $char => $articles ) {
583  # Change space to non-breaking space to keep headers aligned
584  $h3char = $char === ' ' ? '&#160;' : htmlspecialchars( $char );
585 
586  $ret .= '<div class="mw-category-group"><h3>' . $h3char;
587  $ret .= "</h3>\n";
588 
589  $ret .= '<ul><li>';
590  $ret .= implode( "</li>\n<li>", $articles );
591  $ret .= '</li></ul></div>';
592 
593  }
594 
595  $ret .= Html::closeElement( 'div' );
596  return $ret;
597  }
598 
608  $r = '<h3>' . htmlspecialchars( $articles_start_char[0] ) . "</h3>\n";
609  $r .= '<ul><li>' . $articles[0] . '</li>';
610  $articleCount = count( $articles );
611  for ( $index = 1; $index < $articleCount; $index++ ) {
612  if ( $articles_start_char[$index] != $articles_start_char[$index - 1] ) {
613  $r .= "</ul><h3>" . htmlspecialchars( $articles_start_char[$index] ) . "</h3>\n<ul>";
614  }
615 
616  $r .= "<li>{$articles[$index]}</li>";
617  }
618  $r .= '</ul>';
619  return $r;
620  }
621 
631  private function pagingLinks( $first, $last, $type = '' ) {
632  $prevLink = $this->msg( 'prev-page' )->text();
633 
634  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
635  if ( $first != '' ) {
636  $prevQuery = $this->query;
637  $prevQuery["{$type}until"] = $first;
638  unset( $prevQuery["{$type}from"] );
639  $prevLink = $linkRenderer->makeKnownLink(
640  $this->addFragmentToTitle( $this->title, $type ),
641  $prevLink,
642  [],
643  $prevQuery
644  );
645  }
646 
647  $nextLink = $this->msg( 'next-page' )->text();
648 
649  if ( $last != '' ) {
650  $lastQuery = $this->query;
651  $lastQuery["{$type}from"] = $last;
652  unset( $lastQuery["{$type}until"] );
653  $nextLink = $linkRenderer->makeKnownLink(
654  $this->addFragmentToTitle( $this->title, $type ),
655  $nextLink,
656  [],
657  $lastQuery
658  );
659  }
660 
661  return $this->msg( 'categoryviewer-pagedlinks' )->rawParams( $prevLink, $nextLink )->escaped();
662  }
663 
673  private function addFragmentToTitle( $title, $section ) {
674  switch ( $section ) {
675  case 'page':
676  $fragment = 'mw-pages';
677  break;
678  case 'subcat':
679  $fragment = 'mw-subcategories';
680  break;
681  case 'file':
682  $fragment = 'mw-category-media';
683  break;
684  default:
685  throw new MWException( __METHOD__ .
686  " Invalid section $section." );
687  }
688 
690  $title->getDBkey(), $fragment );
691  }
692 
703  private function getCountMessage( $rescnt, $dbcnt, $type ) {
704  // There are three cases:
705  // 1) The category table figure seems sane. It might be wrong, but
706  // we can't do anything about it if we don't recalculate it on ev-
707  // ery category view.
708  // 2) The category table figure isn't sane, like it's smaller than the
709  // number of actual results, *but* the number of results is less
710  // than $this->limit and there's no offset. In this case we still
711  // know the right figure.
712  // 3) We have no idea.
713 
714  // Check if there's a "from" or "until" for anything
715 
716  // This is a little ugly, but we seem to use different names
717  // for the paging types then for the messages.
718  if ( $type === 'article' ) {
719  $pagingType = 'page';
720  } else {
721  $pagingType = $type;
722  }
723 
724  $fromOrUntil = false;
725  if ( ( isset( $this->from[$pagingType] ) && $this->from[$pagingType] !== null ) ||
726  ( isset( $this->until[$pagingType] ) && $this->until[$pagingType] !== null )
727  ) {
728  $fromOrUntil = true;
729  }
730 
731  if ( $dbcnt == $rescnt ||
732  ( ( $rescnt == $this->limit || $fromOrUntil ) && $dbcnt > $rescnt )
733  ) {
734  // Case 1: seems sane.
735  $totalcnt = $dbcnt;
736  } elseif ( $rescnt < $this->limit && !$fromOrUntil ) {
737  // Case 2: not sane, but salvageable. Use the number of results.
738  // Since there are fewer than 200, we can also take this opportunity
739  // to refresh the incorrect category table entry -- which should be
740  // quick due to the small number of entries.
741  $totalcnt = $rescnt;
742  DeferredUpdates::addCallableUpdate( [ $this->cat, 'refreshCounts' ] );
743  } else {
744  // Case 3: hopeless. Don't give a total count at all.
745  // Messages: category-subcat-count-limited, category-article-count-limited,
746  // category-file-count-limited
747  return $this->msg( "category-$type-count-limited" )->numParams( $rescnt )->parseAsBlock();
748  }
749  // Messages: category-subcat-count, category-article-count, category-file-count
750  return $this->msg( "category-$type-count" )->numParams( $rescnt, $totalcnt )->parseAsBlock();
751  }
752 }
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:251
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:607
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:187
query
For a write query
Definition: database.txt:26
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
captcha-old.count
count
Definition: captcha-old.py:249
$last
$last
Definition: profileinfo.php:415
ImageGalleryBase
Image gallery.
Definition: ImageGalleryBase.php:30
ContextSource\msg
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:189
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:673
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:566
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:703
Title\getPrefixedText
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1550
NS_FILE
const NS_FILE
Definition: Defines.php:71
CategoryViewer\getImageSection
getImageSection()
Definition: CategoryViewer.php:461
CategoryViewer\getPagesSection
getPagesSection()
Definition: CategoryViewer.php:431
CategoryViewer\getSubcategorySortChar
getSubcategorySortChar( $title, $sortkey)
Get the character to be used for sorting subcategories.
Definition: CategoryViewer.php:223
$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:1965
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
CategoryViewer\$imgsNoGallery_start_char
array $imgsNoGallery_start_char
Definition: CategoryViewer.php:50
CategoryViewer\clearCategoryState
clearCategoryState()
Definition: CategoryViewer.php:152
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:535
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:277
CategoryViewer\doCategoryQuery
doCategoryQuery()
Definition: CategoryViewer.php:292
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
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2696
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:496
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:955
$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:1965
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:978
CategoryViewer\$collation
Collation $collation
Definition: CategoryViewer.php:68
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:459
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2856
Title\getCategorySortkey
getCategorySortkey( $prefix='')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition: Title.php:4805
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
$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:77
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:1965
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:529
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:79
CategoryViewer\addSubcategoryObject
addSubcategoryObject(Category $cat, $sortkey, $pageLength)
Add a subcategory to the internal lists, using a Category object.
Definition: CategoryViewer.php:180
ContextSource\setContext
setContext(IContextSource $context)
Set the IContextSource object.
Definition: ContextSource.php:58
CategoryViewer\getCategoryBottom
getCategoryBottom()
Definition: CategoryViewer.php:521
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:179
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:146
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2141
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:195
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1703
$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:1965
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:3357
CategoryViewer\pagingLinks
pagingLinks( $first, $last, $type='')
Create paging links, as a helper method to getSectionPagingLinks().
Definition: CategoryViewer.php:631
$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:2981
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
$link
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:2981
CategoryViewer\$limit
int $limit
Definition: CategoryViewer.php:26
CategoryViewer\$showGallery
bool $showGallery
Definition: CategoryViewer.php:47
CategoryViewer\getSubcategorySection
getSubcategorySection()
Definition: CategoryViewer.php:407
ImageGalleryBase\factory
static factory( $mode=false, IContextSource $context=null)
Get a new image gallery.
Definition: ImageGalleryBase.php:92
CategoryViewer\addPage
addPage( $title, $sortkey, $pageLength, $isRedirect=false)
Add a miscellaneous page.
Definition: CategoryViewer.php:268
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:203
CategoryViewer\getCategoryTop
getCategoryTop()
Definition: CategoryViewer.php:397
CategoryViewer\addImage
addImage(Title $title, $sortkey, $pageLength, $isRedirect=false)
Add a page in the image namespace.
Definition: CategoryViewer.php:244
Title\getText
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:937
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
$type
$type
Definition: testCompression.php:48
CategoryViewer\$until
array $until
Definition: CategoryViewer.php:32