X-Git-Url: https://git.cyclocoop.org/%242?a=blobdiff_plain;f=includes%2FCategoryPage.php;h=3568d89bd28e6ae0a8a41e0d10b675e147b425d0;hb=2b302cfccd0cd4191f1f48b0540f623c06621b32;hp=682dda3360019d854fb90894854729e30ae53877;hpb=73208791845927d192c919686412f7a61a08dead;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/CategoryPage.php b/includes/CategoryPage.php index 682dda3360..3568d89bd2 100644 --- a/includes/CategoryPage.php +++ b/includes/CategoryPage.php @@ -44,14 +44,23 @@ class CategoryPage extends Article { /** * Don't return a 404 for categories in use. + * In use defined as: either the actual page exists + * or the category currently has members. */ function hasViewableContent() { if ( parent::hasViewableContent() ) { return true; } else { $cat = Category::newFromTitle( $this->mTitle ); - return $cat->getId() != 0; + // If any of these are not 0, then has members + if ( $cat->getPageCount() + || $cat->getSubcatCount() + || $cat->getFileCount() + ) { + return true; + } } + return false; } function openShowCategory() { @@ -59,31 +68,66 @@ class CategoryPage extends Article { } function closeShowCategory() { - global $wgOut; + global $wgOut, $wgRequest; + // Use these as defaults for back compat --catrope + $oldFrom = $wgRequest->getVal( 'from' ); + $oldUntil = $wgRequest->getVal( 'until' ); + $from = $until = array(); foreach ( array( 'page', 'subcat', 'file' ) as $type ) { - # Use $_GET instead of $wgRequest, because the latter helpfully - # normalizes Unicode, which removes nulls. TODO: do something - # smarter than passing nulls in URLs. :/ - $from[$type] = isset( $_GET["{$type}from"] ) ? $_GET["{$type}from"] : null; - $until[$type] = isset( $_GET["{$type}until"] ) ? $_GET["{$type}until"] : null; + $from[$type] = $wgRequest->getVal( "{$type}from", $oldFrom ); + $until[$type] = $wgRequest->getVal( "{$type}until", $oldUntil ); } - $viewer = new $this->mCategoryViewerClass( $this->mTitle, $from, $until, $_GET ); + $viewer = new $this->mCategoryViewerClass( $this->mTitle, $from, $until, $wgRequest->getValues() ); $wgOut->addHTML( $viewer->getHTML() ); } } class CategoryViewer { - var $title, $limit, $from, $until, + var $limit, $from, $until, $articles, $articles_start_char, $children, $children_start_char, - $showGallery, $gallery, - $skin; - # Category object for this page + $showGallery, $imgsNoGalley, + $imgsNoGallery_start_char, + $skin, $imgsNoGallery; + + /** + * @var + */ + var $nextPage; + + /** + * @var Array + */ + var $flip; + + /** + * @var Title + */ + var $title; + + /** + * @var Collation + */ + var $collation; + + /** + * @var ImageGallery + */ + var $gallery; + + /** + * Category object for this page + * @var Category + */ private $cat; - # The original query array, to be used in generating paging links. + + /** + * The original query array, to be used in generating paging links. + * @var array + */ private $query; function __construct( $title, $from = '', $until = '', $query = array() ) { @@ -94,6 +138,7 @@ class CategoryViewer { $this->limit = $wgCategoryPagingLimit; $this->cat = Category::newFromTitle( $title ); $this->query = $query; + $this->collation = Collation::singleton(); unset( $this->query['title'] ); } @@ -101,9 +146,8 @@ class CategoryViewer { * Format the category data list. * * @return string HTML output - * @private */ - function getHTML() { + public function getHTML() { global $wgOut, $wgCategoryMagicGallery, $wgContLang; wfProfileIn( __METHOD__ ); @@ -147,9 +191,15 @@ class CategoryViewer { if ( $this->showGallery ) { $this->gallery = new ImageGallery(); $this->gallery->setHideBadImages(); + } else { + $this->imgsNoGallery = array(); + $this->imgsNoGallery_start_char = array(); } } + /** + * @return Skin + */ function getSkin() { if ( !$this->skin ) { global $wgUser; @@ -163,13 +213,16 @@ class CategoryViewer { */ function addSubcategoryObject( Category $cat, $sortkey, $pageLength ) { // Subcategory; strip the 'Category' namespace from the link text. - $this->children[] = $this->getSkin()->link( - $cat->getTitle(), - null, - array(), - array(), - array( 'known', 'noclasses' ) - ); + $title = $cat->getTitle(); + + $link = $this->getSkin()->link( $title, $title->getText() ); + if ( $title->isRedirect() ) { + // This didn't used to add redirect-in-category, but might + // as well be consistent with the rest of the sections + // on a category page. + $link = '' . $link . ''; + } + $this->children[] = $link; $this->children_start_char[] = $this->getSubcategorySortChar( $cat->getTitle(), $sortkey ); @@ -189,6 +242,9 @@ class CategoryViewer { * entry in the categorylinks table is Category:A, not A, which it SHOULD be. * Workaround: If sortkey == "Category:".$title, than use $title for sorting, * else use sortkey... + * + * @param Title $title + * @param string $sortkey The human-readable sortkey (before transforming to icu or whatever). */ function getSubcategorySortChar( $title, $sortkey ) { global $wgContLang; @@ -199,7 +255,7 @@ class CategoryViewer { $word = $sortkey; } - $firstChar = $wgContLang->firstLetterForLists( $word ); + $firstChar = $this->collation->getFirstLetter( $word ); return $wgContLang->convert( $firstChar ); } @@ -208,6 +264,7 @@ class CategoryViewer { * Add a page in the image namespace */ function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) { + global $wgContLang; if ( $this->showGallery ) { $flip = $this->flip['file']; if ( $flip ) { @@ -216,7 +273,16 @@ class CategoryViewer { $this->gallery->add( $title ); } } else { - $this->addPage( $title, $sortkey, $pageLength, $isRedirect ); + $link = $this->getSkin()->link( $title ); + if ( $isRedirect ) { + // This seems kind of pointless given 'mw-redirect' class, + // but keeping for back-compatibility with user css. + $link = '' . $link . ''; + } + $this->imgsNoGallery[] = $link; + + $this->imgsNoGallery_start_char[] = $wgContLang->convert( + $this->collation->getFirstLetter( $sortkey ) ); } } @@ -225,18 +291,17 @@ class CategoryViewer { */ function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) { global $wgContLang; - $this->articles[] = $isRedirect - ? '' . - $this->getSkin()->link( - $title, - null, - array(), - array(), - array( 'known', 'noclasses' ) - ) . '' - : $this->getSkin()->link( $title ); - - $this->articles_start_char[] = $wgContLang->convert( $wgContLang->firstLetterForLists( $sortkey ) ); + + $link = $this->getSkin()->link( $title ); + if ( $isRedirect ) { + // This seems kind of pointless given 'mw-redirect' class, + // but keeping for back-compatiability with user css. + $link = '' . $link . ''; + } + $this->articles[] = $link; + + $this->articles_start_char[] = $wgContLang->convert( + $this->collation->getFirstLetter( $sortkey ) ); } function finaliseCategoryState() { @@ -248,11 +313,13 @@ class CategoryViewer { $this->articles = array_reverse( $this->articles ); $this->articles_start_char = array_reverse( $this->articles_start_char ); } + if ( !$this->showGallery && $this->flip['file'] ) { + $this->imgsNoGallery = array_reverse( $this->imgsNoGallery ); + $this->imgsNoGallery_start_char = array_reverse( $this->imgsNoGallery_start_char ); + } } function doCategoryQuery() { - global $wgContLang; - $dbr = wfGetDB( DB_SLAVE, 'category' ); $this->nextPage = array( @@ -265,14 +332,14 @@ class CategoryViewer { foreach ( array( 'page', 'subcat', 'file' ) as $type ) { # Get the sortkeys for start/end, if applicable. Note that if # the collation in the database differs from the one - # $wgContLang is using, pagination might go totally haywire. + # set in $wgCategoryCollation, pagination might go totally haywire. $extraConds = array( 'cl_type' => $type ); if ( $this->from[$type] !== null ) { $extraConds[] = 'cl_sortkey >= ' - . $dbr->addQuotes( $wgContLang->convertToSortkey( $this->from[$type] ) ); + . $dbr->addQuotes( $this->collation->getSortKey( $this->from[$type] ) ); } elseif ( $this->until[$type] !== null ) { $extraConds[] = 'cl_sortkey < ' - . $dbr->addQuotes( $wgContLang->convertToSortkey( $this->until[$type] ) ); + . $dbr->addQuotes( $this->collation->getSortKey( $this->until[$type] ) ); $this->flip[$type] = true; } @@ -280,8 +347,9 @@ class CategoryViewer { array( 'page', 'categorylinks', 'category' ), array( 'page_id', 'page_title', 'page_namespace', 'page_len', 'page_is_redirect', 'cl_sortkey', 'cat_id', 'cat_title', - 'cat_subcats', 'cat_pages', 'cat_files', 'cl_sortkey_prefix' ), - array( 'cl_to' => $this->title->getDBkey() ) + $extraConds, + 'cat_subcats', 'cat_pages', 'cat_files', + 'cl_sortkey_prefix', 'cl_collation' ), + array_merge( array( 'cl_to' => $this->title->getDBkey() ), $extraConds ), __METHOD__, array( 'USE INDEX' => array( 'categorylinks' => 'cl_sortkey' ), @@ -297,22 +365,29 @@ class CategoryViewer { $count = 0; foreach ( $res as $row ) { $title = Title::newFromRow( $row ); - $rawSortkey = $title->getCategorySortkey( $row->cl_sortkey_prefix ); + if ( $row->cl_collation === '' ) { + // Hack to make sure that while updating from 1.16 schema + // and db is inconsistent, that the sky doesn't fall. + // See r83544. Could perhaps be removed in a couple decades... + $humanSortkey = $row->cl_sortkey; + } else { + $humanSortkey = $title->getCategorySortkey( $row->cl_sortkey_prefix ); + } if ( ++$count > $this->limit ) { # We've reached the one extra which shows that there # are additional pages to be had. Stop here... - $this->nextPage[$type] = $rawSortkey; + $this->nextPage[$type] = $humanSortkey; break; } if ( $title->getNamespace() == NS_CATEGORY ) { $cat = Category::newFromRow( $row, $title ); - $this->addSubcategoryObject( $cat, $rawSortkey, $row->page_len ); - } elseif ( $this->showGallery && $title->getNamespace() == NS_FILE ) { - $this->addImage( $title, $rawSortkey, $row->page_len, $row->page_is_redirect ); + $this->addSubcategoryObject( $cat, $humanSortkey, $row->page_len ); + } elseif ( $title->getNamespace() == NS_FILE ) { + $this->addImage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect ); } else { - $this->addPage( $title, $rawSortkey, $row->page_len, $row->page_is_redirect ); + $this->addPage( $title, $humanSortkey, $row->page_len, $row->page_is_redirect ); } } } @@ -373,16 +448,20 @@ class CategoryViewer { function getImageSection() { $r = ''; - if ( $this->showGallery && ! $this->gallery->isEmpty() ) { + $rescnt = $this->showGallery ? $this->gallery->count() : count( $this->imgsNoGallery ); + if ( $rescnt > 0 ) { $dbcnt = $this->cat->getFileCount(); - $rescnt = $this->gallery->count(); $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'file' ); $r .= "
\n"; $r .= '

' . wfMsg( 'category-media-header', htmlspecialchars( $this->title->getText() ) ) . "

\n"; $r .= $countmsg; $r .= $this->getSectionPagingLinks( 'file' ); - $r .= $this->gallery->toHTML(); + if ( $this->showGallery ) { + $r .= $this->gallery->toHTML(); + } else { + $r .= $this->formatList( $this->imgsNoGallery, $this->imgsNoGallery_start_char ); + } $r .= $this->getSectionPagingLinks( 'file' ); $r .= "\n
"; } @@ -422,10 +501,10 @@ class CategoryViewer { */ function formatList( $articles, $articles_start_char, $cutoff = 6 ) { if ( count ( $articles ) > $cutoff ) { - return $this->columnList( $articles, $articles_start_char ); + return self::columnList( $articles, $articles_start_char ); } elseif ( count( $articles ) > 0 ) { // for short lists of articles in categories. - return $this->shortList( $articles, $articles_start_char ); + return self::shortList( $articles, $articles_start_char ); } return ''; } @@ -500,10 +579,8 @@ class CategoryViewer { static function shortList( $articles, $articles_start_char ) { $r = '

' . htmlspecialchars( $articles_start_char[0] ) . "

\n"; $r .= '

" . htmlspecialchars( $articles_start_char[$index] ) . "

\n