MediaWiki  REL1_28
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 ) {
201  }
202  if ( $isRedirect ) {
203  $link = '<span class="redirect-in-category">' . $link . '</span>';
204  }
205 
206  return $link;
207  }
208 
220  function getSubcategorySortChar( $title, $sortkey ) {
222 
223  if ( $title->getPrefixedText() == $sortkey ) {
224  $word = $title->getDBkey();
225  } else {
226  $word = $sortkey;
227  }
228 
229  $firstChar = $this->collation->getFirstLetter( $word );
230 
231  return $wgContLang->convert( $firstChar );
232  }
233 
241  function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) {
243  if ( $this->showGallery ) {
244  $flip = $this->flip['file'];
245  if ( $flip ) {
246  $this->gallery->insert( $title );
247  } else {
248  $this->gallery->add( $title );
249  }
250  } else {
251  $this->imgsNoGallery[] = $this->generateLink( 'image', $title, $isRedirect );
252 
253  $this->imgsNoGallery_start_char[] = $wgContLang->convert(
254  $this->collation->getFirstLetter( $sortkey ) );
255  }
256  }
257 
265  function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
267 
268  $this->articles[] = $this->generateLink( 'page', $title, $isRedirect );
269 
270  $this->articles_start_char[] = $wgContLang->convert(
271  $this->collation->getFirstLetter( $sortkey ) );
272  }
273 
275  if ( $this->flip['subcat'] ) {
276  $this->children = array_reverse( $this->children );
277  $this->children_start_char = array_reverse( $this->children_start_char );
278  }
279  if ( $this->flip['page'] ) {
280  $this->articles = array_reverse( $this->articles );
281  $this->articles_start_char = array_reverse( $this->articles_start_char );
282  }
283  if ( !$this->showGallery && $this->flip['file'] ) {
284  $this->imgsNoGallery = array_reverse( $this->imgsNoGallery );
285  $this->imgsNoGallery_start_char = array_reverse( $this->imgsNoGallery_start_char );
286  }
287  }
288 
289  function doCategoryQuery() {
290  $dbr = wfGetDB( DB_REPLICA, 'category' );
291 
292  $this->nextPage = [
293  'page' => null,
294  'subcat' => null,
295  'file' => null,
296  ];
297  $this->prevPage = [
298  'page' => null,
299  'subcat' => null,
300  'file' => null,
301  ];
302 
303  $this->flip = [ 'page' => false, 'subcat' => false, 'file' => false ];
304 
305  foreach ( [ 'page', 'subcat', 'file' ] as $type ) {
306  # Get the sortkeys for start/end, if applicable. Note that if
307  # the collation in the database differs from the one
308  # set in $wgCategoryCollation, pagination might go totally haywire.
309  $extraConds = [ 'cl_type' => $type ];
310  if ( isset( $this->from[$type] ) && $this->from[$type] !== null ) {
311  $extraConds[] = 'cl_sortkey >= '
312  . $dbr->addQuotes( $this->collation->getSortKey( $this->from[$type] ) );
313  } elseif ( isset( $this->until[$type] ) && $this->until[$type] !== null ) {
314  $extraConds[] = 'cl_sortkey < '
315  . $dbr->addQuotes( $this->collation->getSortKey( $this->until[$type] ) );
316  $this->flip[$type] = true;
317  }
318 
319  $res = $dbr->select(
320  [ 'page', 'categorylinks', 'category' ],
321  array_merge(
323  [
324  'page_namespace',
325  'page_title',
326  'cl_sortkey',
327  'cat_id',
328  'cat_title',
329  'cat_subcats',
330  'cat_pages',
331  'cat_files',
332  'cl_sortkey_prefix',
333  'cl_collation'
334  ]
335  ),
336  array_merge( [ 'cl_to' => $this->title->getDBkey() ], $extraConds ),
337  __METHOD__,
338  [
339  'USE INDEX' => [ 'categorylinks' => 'cl_sortkey' ],
340  'LIMIT' => $this->limit + 1,
341  'ORDER BY' => $this->flip[$type] ? 'cl_sortkey DESC' : 'cl_sortkey',
342  ],
343  [
344  'categorylinks' => [ 'INNER JOIN', 'cl_from = page_id' ],
345  'category' => [ 'LEFT JOIN', [
346  'cat_title = page_title',
347  'page_namespace' => NS_CATEGORY
348  ] ]
349  ]
350  );
351 
352  Hooks::run( 'CategoryViewer::doCategoryQuery', [ $type, $res ] );
353  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
354 
355  $count = 0;
356  foreach ( $res as $row ) {
357  $title = Title::newFromRow( $row );
358  $linkCache->addGoodLinkObjFromRow( $title, $row );
359 
360  if ( $row->cl_collation === '' ) {
361  // Hack to make sure that while updating from 1.16 schema
362  // and db is inconsistent, that the sky doesn't fall.
363  // See r83544. Could perhaps be removed in a couple decades...
364  $humanSortkey = $row->cl_sortkey;
365  } else {
366  $humanSortkey = $title->getCategorySortkey( $row->cl_sortkey_prefix );
367  }
368 
369  if ( ++$count > $this->limit ) {
370  # We've reached the one extra which shows that there
371  # are additional pages to be had. Stop here...
372  $this->nextPage[$type] = $humanSortkey;
373  break;
374  }
375  if ( $count == $this->limit ) {
376  $this->prevPage[$type] = $humanSortkey;
377  }
378 
379  if ( $title->getNamespace() == NS_CATEGORY ) {
380  $cat = Category::newFromRow( $row, $title );
381  $this->addSubcategoryObject( $cat, $humanSortkey, $row->page_len );
382  } elseif ( $title->getNamespace() == NS_FILE ) {
383  $this->addImage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
384  } else {
385  $this->addPage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
386  }
387  }
388  }
389  }
390 
394  function getCategoryTop() {
395  $r = $this->getCategoryBottom();
396  return $r === ''
397  ? $r
398  : "<br style=\"clear:both;\"/>\n" . $r;
399  }
400 
405  # Don't show subcategories section if there are none.
406  $r = '';
407  $rescnt = count( $this->children );
408  $dbcnt = $this->cat->getSubcatCount();
409  // This function should be called even if the result isn't used, it has side-effects
410  $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'subcat' );
411 
412  if ( $rescnt > 0 ) {
413  # Showing subcategories
414  $r .= "<div id=\"mw-subcategories\">\n";
415  $r .= '<h2>' . $this->msg( 'subcategories' )->parse() . "</h2>\n";
416  $r .= $countmsg;
417  $r .= $this->getSectionPagingLinks( 'subcat' );
418  $r .= $this->formatList( $this->children, $this->children_start_char );
419  $r .= $this->getSectionPagingLinks( 'subcat' );
420  $r .= "\n</div>";
421  }
422  return $r;
423  }
424 
428  function getPagesSection() {
429  $ti = wfEscapeWikiText( $this->title->getText() );
430  # Don't show articles section if there are none.
431  $r = '';
432 
433  # @todo FIXME: Here and in the other two sections: we don't need to bother
434  # with this rigmarole if the entire category contents fit on one page
435  # and have already been retrieved. We can just use $rescnt in that
436  # case and save a query and some logic.
437  $dbcnt = $this->cat->getPageCount() - $this->cat->getSubcatCount()
438  - $this->cat->getFileCount();
439  $rescnt = count( $this->articles );
440  // This function should be called even if the result isn't used, it has side-effects
441  $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'article' );
442 
443  if ( $rescnt > 0 ) {
444  $r = "<div id=\"mw-pages\">\n";
445  $r .= '<h2>' . $this->msg( 'category_header', $ti )->parse() . "</h2>\n";
446  $r .= $countmsg;
447  $r .= $this->getSectionPagingLinks( 'page' );
448  $r .= $this->formatList( $this->articles, $this->articles_start_char );
449  $r .= $this->getSectionPagingLinks( 'page' );
450  $r .= "\n</div>";
451  }
452  return $r;
453  }
454 
458  function getImageSection() {
459  $r = '';
460  $rescnt = $this->showGallery ? $this->gallery->count() : count( $this->imgsNoGallery );
461  $dbcnt = $this->cat->getFileCount();
462  // This function should be called even if the result isn't used, it has side-effects
463  $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'file' );
464 
465  if ( $rescnt > 0 ) {
466  $r .= "<div id=\"mw-category-media\">\n";
467  $r .= '<h2>' .
468  $this->msg(
469  'category-media-header',
470  wfEscapeWikiText( $this->title->getText() )
471  )->text() .
472  "</h2>\n";
473  $r .= $countmsg;
474  $r .= $this->getSectionPagingLinks( 'file' );
475  if ( $this->showGallery ) {
476  $r .= $this->gallery->toHTML();
477  } else {
478  $r .= $this->formatList( $this->imgsNoGallery, $this->imgsNoGallery_start_char );
479  }
480  $r .= $this->getSectionPagingLinks( 'file' );
481  $r .= "\n</div>";
482  }
483  return $r;
484  }
485 
493  private function getSectionPagingLinks( $type ) {
494  if ( isset( $this->until[$type] ) && $this->until[$type] !== null ) {
495  // The new value for the until parameter should be pointing to the first
496  // result displayed on the page which is the second last result retrieved
497  // from the database.The next link should have a from parameter pointing
498  // to the until parameter of the current page.
499  if ( $this->nextPage[$type] !== null ) {
500  return $this->pagingLinks( $this->prevPage[$type], $this->until[$type], $type );
501  } else {
502  // If the nextPage variable is null, it means that we have reached the first page
503  // and therefore the previous link should be disabled.
504  return $this->pagingLinks( null, $this->until[$type], $type );
505  }
506  } elseif ( $this->nextPage[$type] !== null
507  || ( isset( $this->from[$type] ) && $this->from[$type] !== null )
508  ) {
509  return $this->pagingLinks( $this->from[$type], $this->nextPage[$type], $type );
510  } else {
511  return '';
512  }
513  }
514 
518  function getCategoryBottom() {
519  return '';
520  }
521 
532  function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
533  $list = '';
534  if ( count( $articles ) > $cutoff ) {
536  } elseif ( count( $articles ) > 0 ) {
537  // for short lists of articles in categories.
539  }
540 
541  $pageLang = $this->title->getPageLanguage();
542  $attribs = [ 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
543  'class' => 'mw-content-' . $pageLang->getDir() ];
544  $list = Html::rawElement( 'div', $attribs, $list );
545 
546  return $list;
547  }
548 
564  $columns = array_combine( $articles, $articles_start_char );
565 
566  $ret = Html::openElement( 'div', [ 'class' => 'mw-category' ] );
567 
568  $colContents = [];
569 
570  # Kind of like array_flip() here, but we keep duplicates in an
571  # array instead of dropping them.
572  foreach ( $columns as $article => $char ) {
573  if ( !isset( $colContents[$char] ) ) {
574  $colContents[$char] = [];
575  }
576  $colContents[$char][] = $article;
577  }
578 
579  foreach ( $colContents as $char => $articles ) {
580  # Change space to non-breaking space to keep headers aligned
581  $h3char = $char === ' ' ? '&#160;' : htmlspecialchars( $char );
582 
583  $ret .= '<div class="mw-category-group"><h3>' . $h3char;
584  $ret .= "</h3>\n";
585 
586  $ret .= '<ul><li>';
587  $ret .= implode( "</li>\n<li>", $articles );
588  $ret .= '</li></ul></div>';
589 
590  }
591 
592  $ret .= Html::closeElement( 'div' );
593  return $ret;
594  }
595 
605  $r = '<h3>' . htmlspecialchars( $articles_start_char[0] ) . "</h3>\n";
606  $r .= '<ul><li>' . $articles[0] . '</li>';
607  $articleCount = count( $articles );
608  for ( $index = 1; $index < $articleCount; $index++ ) {
609  if ( $articles_start_char[$index] != $articles_start_char[$index - 1] ) {
610  $r .= "</ul><h3>" . htmlspecialchars( $articles_start_char[$index] ) . "</h3>\n<ul>";
611  }
612 
613  $r .= "<li>{$articles[$index]}</li>";
614  }
615  $r .= '</ul>';
616  return $r;
617  }
618 
628  private function pagingLinks( $first, $last, $type = '' ) {
629  $prevLink = $this->msg( 'prev-page' )->text();
630 
631  if ( $first != '' ) {
632  $prevQuery = $this->query;
633  $prevQuery["{$type}until"] = $first;
634  unset( $prevQuery["{$type}from"] );
635  $prevLink = Linker::linkKnown(
636  $this->addFragmentToTitle( $this->title, $type ),
637  $prevLink,
638  [],
639  $prevQuery
640  );
641  }
642 
643  $nextLink = $this->msg( 'next-page' )->text();
644 
645  if ( $last != '' ) {
646  $lastQuery = $this->query;
647  $lastQuery["{$type}from"] = $last;
648  unset( $lastQuery["{$type}until"] );
649  $nextLink = Linker::linkKnown(
650  $this->addFragmentToTitle( $this->title, $type ),
651  $nextLink,
652  [],
653  $lastQuery
654  );
655  }
656 
657  return $this->msg( 'categoryviewer-pagedlinks' )->rawParams( $prevLink, $nextLink )->escaped();
658  }
659 
669  private function addFragmentToTitle( $title, $section ) {
670  switch ( $section ) {
671  case 'page':
672  $fragment = 'mw-pages';
673  break;
674  case 'subcat':
675  $fragment = 'mw-subcategories';
676  break;
677  case 'file':
678  $fragment = 'mw-category-media';
679  break;
680  default:
681  throw new MWException( __METHOD__ .
682  " Invalid section $section." );
683  }
684 
686  $title->getDBkey(), $fragment );
687  }
688 
699  private function getCountMessage( $rescnt, $dbcnt, $type ) {
700  // There are three cases:
701  // 1) The category table figure seems sane. It might be wrong, but
702  // we can't do anything about it if we don't recalculate it on ev-
703  // ery category view.
704  // 2) The category table figure isn't sane, like it's smaller than the
705  // number of actual results, *but* the number of results is less
706  // than $this->limit and there's no offset. In this case we still
707  // know the right figure.
708  // 3) We have no idea.
709 
710  // Check if there's a "from" or "until" for anything
711 
712  // This is a little ugly, but we seem to use different names
713  // for the paging types then for the messages.
714  if ( $type === 'article' ) {
715  $pagingType = 'page';
716  } else {
717  $pagingType = $type;
718  }
719 
720  $fromOrUntil = false;
721  if ( ( isset( $this->from[$pagingType] ) && $this->from[$pagingType] !== null ) ||
722  ( isset( $this->until[$pagingType] ) && $this->until[$pagingType] !== null )
723  ) {
724  $fromOrUntil = true;
725  }
726 
727  if ( $dbcnt == $rescnt ||
728  ( ( $rescnt == $this->limit || $fromOrUntil ) && $dbcnt > $rescnt )
729  ) {
730  // Case 1: seems sane.
731  $totalcnt = $dbcnt;
732  } elseif ( $rescnt < $this->limit && !$fromOrUntil ) {
733  // Case 2: not sane, but salvageable. Use the number of results.
734  // Since there are fewer than 200, we can also take this opportunity
735  // to refresh the incorrect category table entry -- which should be
736  // quick due to the small number of entries.
737  $totalcnt = $rescnt;
738  $category = $this->cat;
739  DeferredUpdates::addCallableUpdate( function () use ( $category ) {
740  $category->refreshCounts();
741  } );
742  } else {
743  // Case 3: hopeless. Don't give a total count at all.
744  // Messages: category-subcat-count-limited, category-article-count-limited,
745  // category-file-count-limited
746  return $this->msg( "category-$type-count-limited" )->numParams( $rescnt )->parseAsBlock();
747  }
748  // Messages: category-subcat-count, category-article-count, category-file-count
749  return $this->msg( "category-$type-count" )->numParams( $rescnt, $totalcnt )->parseAsBlock();
750  }
751 }
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:33
ContextSource\getConfig
getConfig()
Get the Config object.
Definition: ContextSource.php:67
CategoryViewer\shortList
static shortList( $articles, $articles_start_char)
Format a list of articles chunked by letter in a bullet list.
Definition: CategoryViewer.php:604
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:40
query
For a write query
Definition: database.txt:26
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:3
$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:1939
ContextSource\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:186
array
the array() calling protocol came about after MediaWiki 1.4rc1.
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
$last
$last
Definition: profileinfo.php:415
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:669
Category
Category objects are immutable, strictly speaking.
Definition: Category.php:31
$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:1939
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:563
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:699
Title\getPrefixedText
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1455
NS_FILE
const NS_FILE
Definition: Defines.php:62
CategoryViewer\getImageSection
getImageSection()
Definition: CategoryViewer.php:458
CategoryViewer\getPagesSection
getPagesSection()
Definition: CategoryViewer.php:428
CategoryViewer\getSubcategorySortChar
getSubcategorySortChar( $title, $sortkey)
Get the character to be used for sorting subcategories.
Definition: CategoryViewer.php:220
Linker\linkKnown
static linkKnown( $target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:255
CategoryViewer\$articles
string[] $articles
Definition: CategoryViewer.php:35
$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
$res
$res
Definition: database.txt:21
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:77
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:210
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:532
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:274
CategoryViewer\doCategoryQuery
doCategoryQuery()
Definition: CategoryViewer.php:289
$dbr
$dbr
Definition: testCompression.php:50
ContextSource\getLanguage
getLanguage()
Get the Language object.
Definition: ContextSource.php:142
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:305
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:493
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, IDatabase $dbw=null)
Add a callable update.
Definition: DeferredUpdates.php:105
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:898
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:921
CategoryViewer\$collation
Collation $collation
Definition: CategoryViewer.php:68
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:450
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3073
Title\getCategorySortkey
getCategorySortkey( $prefix='')
Returns the raw sort key to be used for categories, with the specified prefix.
Definition: Title.php:4654
$count
$count
Definition: importImages.php:141
ContextSource\getOutput
getOutput()
Get the OutputPage object.
Definition: ContextSource.php:122
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:29
CategoryViewer\$flip
array $flip
Definition: CategoryViewer.php:62
title
title
Definition: parserTests.txt:211
$link
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:2892
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:511
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:22
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:70
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:57
CategoryViewer\getCategoryBottom
getCategoryBottom()
Definition: CategoryViewer.php:518
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
$type
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' 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 one of or reset 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:2259
CategoryViewer\$prevPage
array $prevPage
Definition: CategoryViewer.php:59
Category\newFromTitle
static newFromTitle( $title)
Factory function.
Definition: Category.php:140
$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:1939
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
Linker\link
static link( $target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:203
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1667
CategoryViewer\$gallery
ImageGallery $gallery
Definition: CategoryViewer.php:71
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:36
$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:2892
Title\isRedirect
isRedirect( $flags=0)
Is this an article that is a redirect page? Uses link cache, adding it if necessary.
Definition: Title.php:3235
CategoryViewer\pagingLinks
pagingLinks( $first, $last, $type='')
Create paging links, as a helper method to getSectionPagingLinks().
Definition: CategoryViewer.php:628
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:247
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
CategoryViewer\$limit
int $limit
Definition: CategoryViewer.php:26
CategoryViewer\$showGallery
bool $showGallery
Definition: CategoryViewer.php:47
CategoryViewer\getSubcategorySection
getSubcategorySection()
Definition: CategoryViewer.php:404
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:265
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:394
ImageGallery
Backwards compatibility.
Definition: TraditionalImageGallery.php:359
CategoryViewer\addImage
addImage(Title $title, $sortkey, $pageLength, $isRedirect=false)
Add a page in the image namespace.
Definition: CategoryViewer.php:241
Title\getText
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:880
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2105
$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