94 'mediawiki.action.view.categoryPage.styles'
99 $this->cat = Category::newFromTitle( $title );
102 unset( $this->query[
'title'] );
111 $this->showGallery = $this->
getConfig()->get(
'CategoryMagicGallery' )
137 $r = $this->
msg(
'category-empty' )->parseAsBlock();
142 'class' =>
'mw-category-generated',
143 'lang' =>
$lang->getHtmlCode(),
144 'dir' =>
$lang->getDir()
146 # put a div around the headings which are in the user language
147 $r = Html::openElement(
'div',
$attribs ) . $r .
'</div>';
153 $this->articles = [];
154 $this->articles_start_char = [];
155 $this->children = [];
156 $this->children_start_char = [];
157 if ( $this->showGallery ) {
159 $mode = $this->
getRequest()->getVal(
'gallerymode',
null );
162 }
catch ( Exception
$e ) {
167 $this->gallery->setHideBadImages();
169 $this->imgsNoGallery = [];
170 $this->imgsNoGallery_start_char = [];
187 $title->isRedirect(),
188 htmlspecialchars( $title->getText() )
191 $this->children_start_char[] =
197 Hooks::run(
'CategoryViewer::generateLink', [
$type, $title,
$html, &
$link ] );
198 if (
$link ===
null ) {
199 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
200 if (
$html !==
null ) {
206 $link =
'<span class="redirect-in-category">' .
$link .
'</span>';
226 if ( $title->getPrefixedText() == $sortkey ) {
227 $word = $title->getDBkey();
232 $firstChar = $this->collation->getFirstLetter( $word );
244 function addImage(
Title $title, $sortkey, $pageLength, $isRedirect =
false ) {
246 if ( $this->showGallery ) {
247 $flip = $this->flip[
'file'];
249 $this->gallery->insert( $title );
251 $this->gallery->add( $title );
254 $this->imgsNoGallery[] = $this->
generateLink(
'image', $title, $isRedirect );
256 $this->imgsNoGallery_start_char[] =
$wgContLang->convert(
257 $this->collation->getFirstLetter( $sortkey ) );
268 function addPage( $title, $sortkey, $pageLength, $isRedirect =
false ) {
271 $this->articles[] = $this->
generateLink(
'page', $title, $isRedirect );
273 $this->articles_start_char[] =
$wgContLang->convert(
274 $this->collation->getFirstLetter( $sortkey ) );
278 if ( $this->flip[
'subcat'] ) {
279 $this->children = array_reverse( $this->children );
280 $this->children_start_char = array_reverse( $this->children_start_char );
282 if ( $this->flip[
'page'] ) {
283 $this->articles = array_reverse( $this->articles );
284 $this->articles_start_char = array_reverse( $this->articles_start_char );
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 );
306 $this->flip = [
'page' =>
false,
'subcat' =>
false,
'file' =>
false ];
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;
323 [
'page',
'categorylinks',
'category' ],
325 LinkCache::getSelectFields(),
339 array_merge( [
'cl_to' => $this->title->getDBkey() ], $extraConds ),
342 'USE INDEX' => [
'categorylinks' =>
'cl_sortkey' ],
343 'LIMIT' => $this->limit + 1,
344 'ORDER BY' => $this->flip[
$type] ?
'cl_sortkey DESC' :
'cl_sortkey',
347 'categorylinks' => [
'INNER JOIN',
'cl_from = page_id' ],
348 'category' => [
'LEFT JOIN', [
349 'cat_title = page_title',
355 Hooks::run(
'CategoryViewer::doCategoryQuery', [
$type,
$res ] );
356 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
359 foreach (
$res as $row ) {
360 $title = Title::newFromRow( $row );
361 $linkCache->addGoodLinkObjFromRow( $title, $row );
363 if ( $row->cl_collation ===
'' ) {
367 $humanSortkey = $row->cl_sortkey;
369 $humanSortkey = $title->getCategorySortkey( $row->cl_sortkey_prefix );
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;
378 if ( $count == $this->limit ) {
379 $this->prevPage[
$type] = $humanSortkey;
383 $cat = Category::newFromRow( $row, $title );
385 } elseif ( $title->getNamespace() ==
NS_FILE ) {
386 $this->
addImage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
388 $this->
addPage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect );
401 :
"<br style=\"clear:both;\"/>\n" . $r;
408 # Don't show subcategories section if there are none.
410 $rescnt = count( $this->children );
411 $dbcnt = $this->cat->getSubcatCount();
416 # Showing subcategories
417 $r .=
"<div id=\"mw-subcategories\">\n";
418 $r .=
'<h2>' . $this->
msg(
'subcategories' )->parse() .
"</h2>\n";
421 $r .= $this->
formatList( $this->children, $this->children_start_char );
433 # Don't show articles section if there are none.
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 );
447 $r =
"<div id=\"mw-pages\">\n";
448 $r .=
'<h2>' . $this->
msg(
'category_header', $ti )->parse() .
"</h2>\n";
451 $r .= $this->
formatList( $this->articles, $this->articles_start_char );
463 $rescnt = $this->showGallery ? $this->gallery->count() : count( $this->imgsNoGallery );
464 $dbcnt = $this->cat->getFileCount();
469 $r .=
"<div id=\"mw-category-media\">\n";
472 'category-media-header',
478 if ( $this->showGallery ) {
479 $r .= $this->gallery->toHTML();
481 $r .= $this->
formatList( $this->imgsNoGallery, $this->imgsNoGallery_start_char );
497 if ( isset( $this->until[
$type] ) && $this->until[
$type] !==
null ) {
502 if ( $this->nextPage[
$type] !==
null ) {
509 } elseif ( $this->nextPage[
$type] !==
null
510 || ( isset( $this->from[
$type] ) && $this->from[
$type] !==
null )
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 );
569 $ret = Html::openElement(
'div', [
'class' =>
'mw-category' ] );
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] = [];
582 foreach ( $colContents as $char =>
$articles ) {
583 # Change space to non-breaking space to keep headers aligned
584 $h3char = $char ===
' ' ?
' ' : htmlspecialchars( $char );
586 $ret .=
'<div class="mw-category-group"><h3>' . $h3char;
591 $ret .=
'</li></ul></div>';
595 $ret .= Html::closeElement(
'div' );
609 $r .=
'<ul><li>' .
$articles[0] .
'</li>';
611 for ( $index = 1; $index < $articleCount; $index++ ) {
616 $r .=
"<li>{$articles[$index]}</li>";
632 $prevLink = $this->
msg(
'prev-page' )->text();
634 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
635 if ( $first !=
'' ) {
637 $prevQuery[
"{$type}until"] = $first;
638 unset( $prevQuery[
"{$type}from"] );
647 $nextLink = $this->
msg(
'next-page' )->text();
651 $lastQuery[
"{$type}from"] =
$last;
652 unset( $lastQuery[
"{$type}until"] );
661 return $this->
msg(
'categoryviewer-pagedlinks' )->rawParams( $prevLink, $nextLink )->escaped();
676 $fragment =
'mw-pages';
679 $fragment =
'mw-subcategories';
682 $fragment =
'mw-category-media';
686 " Invalid section $section." );
689 return Title::makeTitle( $title->getNamespace(),
690 $title->getDBkey(), $fragment );
718 if (
$type ===
'article' ) {
719 $pagingType =
'page';
724 $fromOrUntil =
false;
725 if ( ( isset( $this->from[$pagingType] ) && $this->from[$pagingType] !==
null ) ||
726 ( isset( $this->until[$pagingType] ) && $this->until[$pagingType] !==
null )
731 if ( $dbcnt == $rescnt ||
732 ( ( $rescnt == $this->limit || $fromOrUntil ) && $dbcnt > $rescnt )
736 } elseif ( $rescnt < $this->limit && !$fromOrUntil ) {
742 DeferredUpdates::addCallableUpdate( [ $this->cat,
'refreshCounts' ] );
747 return $this->
msg(
"category-$type-count-limited" )->numParams( $rescnt )->parseAsBlock();
750 return $this->
msg(
"category-$type-count" )->numParams( $rescnt, $totalcnt )->parseAsBlock();
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
getCountMessage( $rescnt, $dbcnt, $type)
What to do if the category table conflicts with the number of results returned? This function says wh...
array $articles_start_char
array $children_start_char
pagingLinks( $first, $last, $type='')
Create paging links, as a helper method to getSectionPagingLinks().
getSectionPagingLinks( $type)
Get the paging links for a section (subcats/pages/files), to go at the top and bottom of the output.
Category $cat
Category object for this page.
__construct( $title, IContextSource $context, $from=[], $until=[], $query=[])
addPage( $title, $sortkey, $pageLength, $isRedirect=false)
Add a miscellaneous page.
ImageGalleryBase $gallery
addSubcategoryObject(Category $cat, $sortkey, $pageLength)
Add a subcategory to the internal lists, using a Category object.
formatList( $articles, $articles_start_char, $cutoff=6)
Format a list of articles chunked by letter, either as a bullet list or a columnar format,...
addImage(Title $title, $sortkey, $pageLength, $isRedirect=false)
Add a page in the image namespace.
static columnList( $articles, $articles_start_char)
Format a list of articles chunked by letter in a three-column list, ordered vertically.
getSubcategorySortChar( $title, $sortkey)
Get the character to be used for sorting subcategories.
getHTML()
Format the category data list.
addFragmentToTitle( $title, $section)
Takes a title, and adds the fragment identifier that corresponds to the correct segment of the catego...
array $imgsNoGallery_start_char
generateLink( $type, Title $title, $isRedirect, $html=null)
array $query
The original query array, to be used in generating paging links.
static shortList( $articles, $articles_start_char)
Format a list of articles chunked by letter in a bullet list.
Category objects are immutable, strictly speaking.
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
getRequest()
Get the WebRequest object.
getConfig()
Get the Config object.
getOutput()
Get the OutputPage object.
getLanguage()
Get the Language object.
getContext()
Get the base IContextSource object.
setContext(IContextSource $context)
Set the IContextSource object.
Marks HTML that shouldn't be escaped.
static factory( $mode=false, IContextSource $context=null)
Get a new image gallery.
Represents a title within MediaWiki.
isRedirect( $flags=0)
Is this an article that is a redirect page? Uses link cache, adding it if necessary.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function array $article
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
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
usually copyright or history_copyright This message must be in HTML not wikitext & $link
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
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
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
processing should stop and the error should be shown to the user * false
returning false will NOT prevent logging $e
Interface for objects which can provide a MediaWiki context on request.
getConfig()
Get the site configuration.
if(!isset( $args[0])) $lang