summaryrefslogtreecommitdiff
path: root/includes/CategoryViewer.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/CategoryViewer.php')
-rw-r--r--includes/CategoryViewer.php119
1 files changed, 52 insertions, 67 deletions
diff --git a/includes/CategoryViewer.php b/includes/CategoryViewer.php
index 7581ae40..66079c01 100644
--- a/includes/CategoryViewer.php
+++ b/includes/CategoryViewer.php
@@ -89,6 +89,9 @@ class CategoryViewer extends ContextSource {
) {
$this->title = $title;
$this->setContext( $context );
+ $this->getOutput()->addModuleStyles( array(
+ 'mediawiki.action.view.categoryPage.styles'
+ ) );
$this->from = $from;
$this->until = $until;
$this->limit = $context->getConfig()->get( 'CategoryPagingLimit' );
@@ -104,7 +107,6 @@ class CategoryViewer extends ContextSource {
* @return string HTML output
*/
public function getHTML() {
- wfProfileIn( __METHOD__ );
$this->showGallery = $this->getConfig()->get( 'CategoryMagicGallery' )
&& !$this->getOutput()->mNoGallery;
@@ -136,11 +138,10 @@ class CategoryViewer extends ContextSource {
}
$lang = $this->getLanguage();
- $langAttribs = array( 'lang' => $lang->getCode(), 'dir' => $lang->getDir() );
+ $langAttribs = array( 'lang' => $lang->getHtmlCode(), 'dir' => $lang->getDir() );
# put a div around the headings which are in the user language
$r = Html::openElement( 'div', $langAttribs ) . $r . '</div>';
- wfProfileOut( __METHOD__ );
return $r;
}
@@ -154,7 +155,7 @@ class CategoryViewer extends ContextSource {
$mode = $this->getRequest()->getVal( 'gallerymode', null );
try {
$this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
- } catch ( MWException $e ) {
+ } catch ( Exception $e ) {
// User specified something invalid, fallback to default.
$this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
}
@@ -176,19 +177,30 @@ class CategoryViewer extends ContextSource {
// Subcategory; strip the 'Category' namespace from the link text.
$title = $cat->getTitle();
- $link = Linker::link( $title, htmlspecialchars( $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 = '<span class="redirect-in-category">' . $link . '</span>';
- }
- $this->children[] = $link;
+ $this->children[] = $this->generateLink(
+ 'subcat',
+ $title,
+ $title->isRedirect(),
+ htmlspecialchars( $title->getText() )
+ );
$this->children_start_char[] =
$this->getSubcategorySortChar( $cat->getTitle(), $sortkey );
}
+ function generateLink( $type, Title $title, $isRedirect, $html = null ) {
+ $link = null;
+ Hooks::run( 'CategoryViewer::generateLink', array( $type, $title, $html, &$link ) );
+ if ( $link === null ) {
+ $link = Linker::link( $title, $html );
+ }
+ if ( $isRedirect ) {
+ $link = '<span class="redirect-in-category">' . $link . '</span>';
+ }
+
+ return $link;
+ }
+
/**
* Get the character to be used for sorting subcategories.
* If there's a link from Category:A to Category:B, the sortkey of the resulting
@@ -231,13 +243,7 @@ class CategoryViewer extends ContextSource {
$this->gallery->add( $title );
}
} else {
- $link = Linker::link( $title );
- if ( $isRedirect ) {
- // This seems kind of pointless given 'mw-redirect' class,
- // but keeping for back-compatibility with user css.
- $link = '<span class="redirect-in-category">' . $link . '</span>';
- }
- $this->imgsNoGallery[] = $link;
+ $this->imgsNoGallery[] = $this->generateLink( 'image', $title, $isRedirect );
$this->imgsNoGallery_start_char[] = $wgContLang->convert(
$this->collation->getFirstLetter( $sortkey ) );
@@ -254,13 +260,7 @@ class CategoryViewer extends ContextSource {
function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
global $wgContLang;
- $link = Linker::link( $title );
- if ( $isRedirect ) {
- // This seems kind of pointless given 'mw-redirect' class,
- // but keeping for back-compatibility with user css.
- $link = '<span class="redirect-in-category">' . $link . '</span>';
- }
- $this->articles[] = $link;
+ $this->articles[] = $this->generateLink( 'page', $title, $isRedirect );
$this->articles_start_char[] = $wgContLang->convert(
$this->collation->getFirstLetter( $sortkey ) );
@@ -333,6 +333,8 @@ class CategoryViewer extends ContextSource {
)
);
+ Hooks::run( 'CategoryViewer::doCategoryQuery', array( $type, $res ) );
+
$count = 0;
foreach ( $res as $row ) {
$title = Title::newFromRow( $row );
@@ -390,7 +392,7 @@ class CategoryViewer extends ContextSource {
if ( $rescnt > 0 ) {
# Showing subcategories
$r .= "<div id=\"mw-subcategories\">\n";
- $r .= '<h2>' . $this->msg( 'subcategories' )->text() . "</h2>\n";
+ $r .= '<h2>' . $this->msg( 'subcategories' )->parse() . "</h2>\n";
$r .= $countmsg;
$r .= $this->getSectionPagingLinks( 'subcat' );
$r .= $this->formatList( $this->children, $this->children_start_char );
@@ -419,7 +421,7 @@ class CategoryViewer extends ContextSource {
if ( $rescnt > 0 ) {
$r = "<div id=\"mw-pages\">\n";
- $r .= '<h2>' . $this->msg( 'category_header', $ti )->text() . "</h2>\n";
+ $r .= '<h2>' . $this->msg( 'category_header', $ti )->parse() . "</h2>\n";
$r .= $countmsg;
$r .= $this->getSectionPagingLinks( 'page' );
$r .= $this->formatList( $this->articles, $this->articles_start_char );
@@ -515,7 +517,7 @@ class CategoryViewer extends ContextSource {
}
$pageLang = $this->title->getPageLanguage();
- $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
+ $attribs = array( 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
'class' => 'mw-content-' . $pageLang->getDir() );
$list = Html::rawElement( 'div', $attribs, $list );
@@ -529,8 +531,7 @@ class CategoryViewer extends ContextSource {
* TODO: Take the headers into account when creating columns, so they're
* more visually equal.
*
- * More distant TODO: Scrap this and use CSS columns, whenever IE finally
- * supports those.
+ * TODO: shortList and columnList are similar, need merging
*
* @param array $articles
* @param string[] $articles_start_char
@@ -539,50 +540,34 @@ class CategoryViewer extends ContextSource {
*/
static function columnList( $articles, $articles_start_char ) {
$columns = array_combine( $articles, $articles_start_char );
- # Split into three columns
- $columns = array_chunk( $columns, ceil( count( $columns ) / 3 ), true /* preserve keys */ );
- $ret = '<table style="width: 100%;"><tr style="vertical-align: top;">';
- $prevchar = null;
+ $ret = Html::openElement( 'div', array( 'class' => 'mw-category' ) );
- foreach ( $columns as $column ) {
- $ret .= '<td style="width: 33.3%;">';
- $colContents = array();
+ $colContents = array();
- # Kind of like array_flip() here, but we keep duplicates in an
- # array instead of dropping them.
- foreach ( $column as $article => $char ) {
- if ( !isset( $colContents[$char] ) ) {
- $colContents[$char] = array();
- }
- $colContents[$char][] = $article;
+ # Kind of like array_flip() here, but we keep duplicates in an
+ # array instead of dropping them.
+ foreach ( $columns as $article => $char ) {
+ if ( !isset( $colContents[$char] ) ) {
+ $colContents[$char] = array();
}
+ $colContents[$char][] = $article;
+ }
- $first = true;
- foreach ( $colContents as $char => $articles ) {
- # Change space to non-breaking space to keep headers aligned
- $h3char = $char === ' ' ? '&#160;' : htmlspecialchars( $char );
+ foreach ( $colContents as $char => $articles ) {
+ # Change space to non-breaking space to keep headers aligned
+ $h3char = $char === ' ' ? '&#160;' : htmlspecialchars( $char );
- $ret .= '<h3>' . $h3char;
- if ( $first && $char === $prevchar ) {
- # We're continuing a previous chunk at the top of a new
- # column, so add " cont." after the letter.
- $ret .= ' ' . wfMessage( 'listingcontinuesabbrev' )->escaped();
- }
- $ret .= "</h3>\n";
+ $ret .= '<div class="mw-category-group"><h3>' . $h3char;
+ $ret .= "</h3>\n";
- $ret .= '<ul><li>';
- $ret .= implode( "</li>\n<li>", $articles );
- $ret .= '</li></ul>';
-
- $first = false;
- $prevchar = $char;
- }
+ $ret .= '<ul><li>';
+ $ret .= implode( "</li>\n<li>", $articles );
+ $ret .= '</li></ul></div>';
- $ret .= "</td>\n";
}
- $ret .= '</tr></table>';
+ $ret .= Html::closeElement( 'div' );
return $ret;
}
@@ -618,7 +603,7 @@ class CategoryViewer extends ContextSource {
* @return string HTML
*/
private function pagingLinks( $first, $last, $type = '' ) {
- $prevLink = $this->msg( 'prevn' )->numParams( $this->limit )->escaped();
+ $prevLink = $this->msg( 'prev-page' )->text();
if ( $first != '' ) {
$prevQuery = $this->query;
@@ -632,7 +617,7 @@ class CategoryViewer extends ContextSource {
);
}
- $nextLink = $this->msg( 'nextn' )->numParams( $this->limit )->escaped();
+ $nextLink = $this->msg( 'next-page' )->text();
if ( $last != '' ) {
$lastQuery = $this->query;