X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FCategoryPage.php;h=2d09936f639695fa161618189f74d1722d04198c;hb=97bfb998ee07677a208b0578a7cc67d6e2936849;hp=491c8343f6f97eef12278566b8115e85dc14c26b;hpb=2691d45e5dcc02ab597e87301cee546e0cb74598;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/CategoryPage.php b/includes/CategoryPage.php index 491c8343f6..2d09936f63 100644 --- a/includes/CategoryPage.php +++ b/includes/CategoryPage.php @@ -5,8 +5,13 @@ * * @package MediaWiki */ + +if( !defined( 'MEDIAWIKI' ) ) + die(); -if ( $wgCategoryMagicGallery ) +global $wgCategoryMagicGallery; +if( $wgCategoryMagicGallery ) + /** */ require_once('ImageGallery.php'); /** @@ -15,6 +20,8 @@ if ( $wgCategoryMagicGallery ) class CategoryPage extends Article { function view() { + if(!wfRunHooks('CategoryPageView', array(&$this))) return; + if ( NS_CATEGORY == $this->mTitle->getNamespace() ) { $this->openShowCategory(); } @@ -34,279 +41,292 @@ class CategoryPage extends Article { # For overloading } - # generate a list of subcategories and pages for a category - # depending on wfMsg("usenewcategorypage") it either calls the new - # or the old code. The new code will not work properly for some - # languages due to sorting issues, so they might want to turn it - # off. + # generate a list of subcategories and pages for a category + # depending on wfMsg("usenewcategorypage") it either calls the new + # or the old code. The new code will not work properly for some + # languages due to sorting issues, so they might want to turn it + # off. function closeShowCategory() { - global $wgOut; - $msg = wfMsg('usenewcategorypage'); - if ( '0' == @$msg[0] ) - { - $wgOut->addHTML( $this->oldCategoryMagic() ); - } else { - $wgOut->addHTML( $this->newCategoryMagic() ); - } - } - - # This method generates the list of subcategories and pages for a category - function oldCategoryMagic () { - global $wgContLang, $wgUser ; - $fname = 'CategoryPage::oldCategoryMagic'; - - - $sk =& $wgUser->getSkin() ; - - $articles = array() ; - $children = array() ; - $r = ''; - $id = $this->mTitle->getArticleID() ; - - # FIXME: add limits - $dbr =& wfGetDB( DB_SLAVE ); - $cur = $dbr->tableName( 'cur' ); - $categorylinks = $dbr->tableName( 'categorylinks' ); - - $t = $dbr->strencode( $this->mTitle->getDBKey() ); - $sql = "SELECT DISTINCT cur_title,cur_namespace FROM $cur,$categorylinks " . - "WHERE cl_to='$t' AND cl_from=cur_id AND cur_is_redirect=0 ORDER BY cl_sortkey" ; - $res = $dbr->query( $sql, $fname ) ; - # For all pages that link to this category - while ( $x = $dbr->fetchObject ( $res ) ) - { - $t = $wgContLang->getNsText ( $x->cur_namespace ) ; - if ( $t != '' ) $t .= ':' ; - $t .= $x->cur_title ; - - if ( $x->cur_namespace == NS_CATEGORY ) { - array_push ( $children , $sk->makeLink ( $t ) ) ; # Subcategory - } else { - array_push ( $articles , $sk->makeLink ( $t ) ) ; # Page in this category - } - } - $dbr->freeResult ( $res ) ; - - # Showing subcategories - if ( count ( $children ) > 0 ) { - $r .= '

'.wfMsg('subcategories')."

\n" ; - $r .= implode ( ', ' , $children ) ; - } - - # Showing pages in this category - if ( count ( $articles ) > 0 ) { - $ti = $this->mTitle->getText() ; - $h = wfMsg( 'category_header', $ti ); - $r .= "

$h

\n" ; - $r .= implode ( ', ' , $articles ) ; - } - - return $r ; + global $wgOut, $wgRequest; + $pageConditions = array(); + $from = $wgRequest->getVal( 'from' ); + $until = $wgRequest->getVal( 'until' ); + $wgOut->addHTML( $this->doCategoryMagic( $from, $until ) ); } - function newCategoryMagic () { - global $wgContLang,$wgUser, $wgCategoryMagicGallery; - - $sk =& $wgUser->getSkin(); - - $r = "
\n"; - - $articles = array() ; - $articles_start_char = array(); - $children = array() ; - $children_start_char = array(); - $data = array () ; - $id = $this->mTitle->getArticleID() ; - - if ( $wgCategoryMagicGallery ) { + /** + * Format the category data list. + * + * @param string $from -- return only sort keys from this item on + * @param string $until -- don't return keys after this point. + * @return string HTML output + * @access private + */ + function doCategoryMagic( $from = '', $until = '' ) { + global $wgContLang,$wgUser, $wgCategoryMagicGallery; + $fname = 'CategoryPage::doCategoryMagic'; + wfProfileIn( $fname ); + + $articles = array(); + $articles_start_char = array(); + $children = array(); + $children_start_char = array(); + $data = array(); + if( $wgCategoryMagicGallery ) { $ig = new ImageGallery(); } - # FIXME: add limits - $dbr =& wfGetDB( DB_SLAVE ); - $cur = $dbr->tableName( 'cur' ); - $categorylinks = $dbr->tableName( 'categorylinks' ); - - $t = $dbr->strencode( $this->mTitle->getDBKey() ); - $sql = "SELECT DISTINCT cur_title,cur_namespace,cl_sortkey FROM " . - "$cur,$categorylinks WHERE cl_to='$t' AND cl_from=cur_id AND cur_is_redirect=0 ORDER BY cl_sortkey" ; - $res = $dbr->query ( $sql ) ; - while ( $x = $dbr->fetchObject ( $res ) ) - { - $t = $ns = $wgContLang->getNsText ( $x->cur_namespace ) ; - if ( $t != '' ) $t .= ':' ; - $t .= $x->cur_title ; - $ctitle = str_replace( '_',' ',$x->cur_title ); - - if ( $x->cur_namespace == NS_CATEGORY ) { - array_push ( $children, $sk->makeKnownLink ( $t, $ctitle ) ) ; # Subcategory - - // If there's a link from Category:A to Category:B, the sortkey of the resulting - // 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... - if ( ($ns.':'.$ctitle) == $x->cl_sortkey ) { - array_push ( $children_start_char, $wgContLang->firstChar( $x->cur_title ) ); - } else { - array_push ( $children_start_char, $wgContLang->firstChar( $x->cl_sortkey ) ) ; - } - } elseif ( $wgCategoryMagicGallery && $x->cur_namespace == NS_IMAGE ) { - $ig->add( new Image( $x->cur_title ) ); + $dbr =& wfGetDB( DB_SLAVE ); + if( $from != '' ) { + $pageCondition = 'cl_sortkey >= ' . $dbr->addQuotes( $from ); + $flip = false; + } elseif( $until != '' ) { + $pageCondition = 'cl_sortkey < ' . $dbr->addQuotes( $until ); + $flip = true; + } else { + $pageCondition = '1'; + $flip = false; + } + $limit = 200; + $res = $dbr->select( + array( 'page', 'categorylinks' ), + array( 'page_title', 'page_namespace', 'cl_sortkey' ), + array( $pageCondition, + 'cl_from = page_id', + 'cl_to' => $this->mTitle->getDBKey()), + #'page_is_redirect' => 0), + #+ $pageCondition, + $fname, + array( 'ORDER BY' => $flip ? 'cl_sortkey DESC' : 'cl_sortkey', + 'LIMIT' => $limit + 1 ) ); + + $sk =& $wgUser->getSkin(); + $r = "
\n"; + $count = 0; + $nextPage = null; + while( $x = $dbr->fetchObject ( $res ) ) { + if( ++$count > $limit ) { + // We've reached the one extra which shows that there are + // additional pages to be had. Stop here... + $nextPage = $x->cl_sortkey; + break; + } + + $title = Title::makeTitle( $x->page_namespace, $x->page_title ); + + if( $title->getNamespace() == NS_CATEGORY ) { + // Subcategory; strip the 'Category' namespace from the link text. + array_push( $children, $sk->makeKnownLinkObj( $title, $wgContLang->convert( $title->getText() ) ) ); + + // If there's a link from Category:A to Category:B, the sortkey of the resulting + // 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... + $sortkey=''; + if( $title->getPrefixedText() == $x->cl_sortkey ) { + $sortkey=$wgContLang->firstChar( $x->page_title ); + } else { + $sortkey=$wgContLang->firstChar( $x->cl_sortkey ); + } + array_push( $children_start_char, $wgContLang->convert( $sortkey ) ) ; + } elseif( $wgCategoryMagicGallery && $title->getNamespace() == NS_IMAGE ) { + // Show thumbnails of categorized images, in a separate chunk + if( $flip ) { + $ig->insert( Image::newFromTitle( $title ) ); + } else { + $ig->add( Image::newFromTitle( $title ) ); + } } else { - array_push ( $articles , $sk->makeKnownLink ( $t ) ) ; # Page in this category - array_push ( $articles_start_char, $wgContLang->firstChar( $x->cl_sortkey ) ) ; - } - } - $dbr->freeResult ( $res ) ; - - $ti = $this->mTitle->getText() ; - - # Don't show subcategories section if there are none. - if ( count ( $children ) > 0 ) - { - # Showing subcategories - $r .= '

' . wfMsg( 'subcategories' ) . "

\n"; - - $numchild = count( $children ); - if($numchild == 1) { - $r .= wfMsg( 'subcategorycount1', $wgContLang->formatNum( 1 ) ); - } else { - $r .= wfMsg( 'subcategorycount' , $wgContLang->formatNum( $numchild ) ); - } - unset($numchild); - - if ( count ( $children ) > 6 ) { - - // divide list into three equal chunks - $chunk = (int) (count ( $children ) / 3); - - // get and display header - $r .= ''; - - $startChunk = 0; - $endChunk = $chunk; - - // loop through the chunks - for($startChunk = 0, $endChunk = $chunk, $chunkIndex = 0; - $chunkIndex < 3; - $chunkIndex++, $startChunk = $endChunk, $endChunk += $chunk + 1) - { - - $r .= ''; - - - } - $r .= '
    '; - // output all subcategories to category - for ($index = $startChunk ; - $index < $endChunk && $index < count($children); - $index++ ) - { - // check for change of starting letter or begging of chunk - if ( ($index == $startChunk) - || ($children_start_char[$index] != $children_start_char[$index - 1]) ) - { - $r .= "

{$children_start_char[$index]}

\n
    "; - } - - $r .= "
  • {$children[$index]}
  • "; - } - $r .= '
'; - } else { - // for short lists of subcategories to category. - - $r .= "

{$children_start_char[0]}

\n"; - $r .= '

{$children_start_char[$index]}

\n'; - } - } # END of if ( count($children) > 0 ) - - $r .= '

' . wfMsg( 'category_header', $ti ) . "

\n"; - - $numart = count( $articles ); - if($numart == 1) { - $r .= wfMsg( 'categoryarticlecount1', $wgContLang->formatNum( 1 ) ); - } else { - $r .= wfMsg( 'categoryarticlecount' , $wgContLang->formatNum( $numart ) ); - } - unset($numart); - - # Showing articles in this category - if ( count ( $articles ) > 6) { - $ti = $this->mTitle->getText() ; - - // divide list into three equal chunks - $chunk = (int) (count ( $articles ) / 3); - - // get and display header - $r .= ''; - - $prev_start_char = ""; - - // loop through the chunks - for($startChunk = 0, $endChunk = $chunk, $chunkIndex = 0; - $chunkIndex < 3; - $chunkIndex++, $startChunk = $endChunk, $endChunk += $chunk + 1) - { - - $r .= ''; + # Showing articles in this category + $ti = htmlspecialchars( $this->mTitle->getText() ); + $r .= '

' . wfMsg( 'category_header', $ti ) . "

\n"; + $r .= $this->formatCount( $articles, 'categoryarticlecount' ); + $r .= $this->formatList( $articles, $articles_start_char ); + if( $wgCategoryMagicGallery && ! $ig->isEmpty() ) { + $r.= $ig->toHTML(); + } - } - $r .= '
    '; - - // output all articles in category - for ($index = $startChunk ; - $index < $endChunk && $index < count($articles); - $index++ ) - { - // check for change of starting letter or begging of chunk - if ( ($index == $startChunk) || - ($articles_start_char[$index] != $articles_start_char[$index - 1]) ) + // Page in this category + array_push( $articles, $sk->makeKnownLinkObj( $title, $wgContLang->convert( $title->getText() ) ) ) ; + array_push( $articles_start_char, $wgContLang->convert( $wgContLang->firstChar( $x->cl_sortkey ) ) ); + } + } + $dbr->freeResult( $res ); - { - $cont_msg = ""; - if($articles_start_char[$index] == $prev_start_char) - $cont_msg = wfMsg('listingcontinuesabbrev'); - $r .= "

{$articles_start_char[$index]}$cont_msg

\n
    "; - $prev_start_char = $articles_start_char[$index]; - } + if( $flip ) { + $children = array_reverse( $children ); + $children_start_char = array_reverse( $children_start_char ); + $articles = array_reverse( $articles ); + $articles_start_char = array_reverse( $articles_start_char ); + } + + if( $until != '' ) { + $r .= $this->pagingLinks( $this->mTitle, $nextPage, $until, $limit ); + } elseif( $nextPage != '' || $from != '' ) { + $r .= $this->pagingLinks( $this->mTitle, $from, $nextPage, $limit ); + } + + # Don't show subcategories section if there are none. + if( count( $children ) > 0 ) { + # Showing subcategories + $r .= '

    ' . wfMsg( 'subcategories' ) . "

    \n"; + $r .= $this->formatCount( $children, 'subcategorycount' ); + $r .= $this->formatList( $children, $children_start_char ); + } - $r .= "
  • {$articles[$index]}
  • "; - } - $r .= '
'; - } elseif ( count($articles) > 0) { - // for short lists of articles in categories. - $ti = $this->mTitle->getText() ; + wfProfileOut( $fname ); + return $r; + } - $r .= '

'.$articles_start_char[0]."

\n"; - $r .= '

{$articles_start_char[$index]}

\n