2004-08-22 09:42:12 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Special handling for category description pages
|
|
|
|
|
* Modelled after ImagePage.php
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
*/
|
2004-12-03 10:57:19 +00:00
|
|
|
|
|
|
|
|
if( !defined( 'MEDIAWIKI' ) )
|
|
|
|
|
die();
|
2004-08-22 09:42:12 +00:00
|
|
|
|
2005-05-13 22:05:54 +00:00
|
|
|
global $wgCategoryMagicGallery;
|
2005-01-27 19:51:47 +00:00
|
|
|
if( $wgCategoryMagicGallery )
|
|
|
|
|
/** */
|
2004-09-30 21:36:12 +00:00
|
|
|
require_once('ImageGallery.php');
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-08-22 09:42:12 +00:00
|
|
|
class CategoryPage extends Article {
|
|
|
|
|
|
|
|
|
|
function view() {
|
2005-04-25 11:09:21 +00:00
|
|
|
if(!wfRunHooks('CategoryPageView', array(&$this))) return;
|
|
|
|
|
|
2004-08-22 09:42:12 +00:00
|
|
|
if ( NS_CATEGORY == $this->mTitle->getNamespace() ) {
|
|
|
|
|
$this->openShowCategory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Article::view();
|
|
|
|
|
|
|
|
|
|
# If the article we've just shown is in the "Image" namespace,
|
|
|
|
|
# follow it with the history list and link list for the image
|
|
|
|
|
# it describes.
|
|
|
|
|
|
|
|
|
|
if ( NS_CATEGORY == $this->mTitle->getNamespace() ) {
|
|
|
|
|
$this->closeShowCategory();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
function openShowCategory() {
|
2004-08-22 09:42:12 +00:00
|
|
|
# For overloading
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-18 23:41:46 +00:00
|
|
|
# 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.
|
2004-08-22 09:42:12 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
function closeShowCategory() {
|
2004-12-21 03:26:43 +00:00
|
|
|
global $wgOut, $wgRequest;
|
|
|
|
|
$pageConditions = array();
|
|
|
|
|
$from = $wgRequest->getVal( 'from' );
|
|
|
|
|
$until = $wgRequest->getVal( 'until' );
|
|
|
|
|
$wgOut->addHTML( $this->doCategoryMagic( $from, $until ) );
|
2004-08-22 09:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
2004-12-21 03:26:43 +00:00
|
|
|
/**
|
|
|
|
|
* 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 = '' ) {
|
2004-11-18 23:41:46 +00:00
|
|
|
global $wgContLang,$wgUser, $wgCategoryMagicGallery;
|
2004-12-21 03:26:43 +00:00
|
|
|
$fname = 'CategoryPage::doCategoryMagic';
|
|
|
|
|
wfProfileIn( $fname );
|
2004-08-22 09:42:12 +00:00
|
|
|
|
2004-12-21 03:26:43 +00:00
|
|
|
$articles = array();
|
2004-11-18 23:41:46 +00:00
|
|
|
$articles_start_char = array();
|
2004-12-21 03:26:43 +00:00
|
|
|
$children = array();
|
2004-11-18 23:41:46 +00:00
|
|
|
$children_start_char = array();
|
2004-12-21 03:26:43 +00:00
|
|
|
$data = array();
|
|
|
|
|
if( $wgCategoryMagicGallery ) {
|
2004-09-30 21:36:12 +00:00
|
|
|
$ig = new ImageGallery();
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-18 23:41:46 +00:00
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
2004-12-21 03:26:43 +00:00
|
|
|
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' ),
|
2005-06-01 10:29:34 +00:00
|
|
|
array( 'page_title', 'page_namespace', 'page_len', 'cl_sortkey' ),
|
2004-12-21 03:26:43 +00:00
|
|
|
array( $pageCondition,
|
|
|
|
|
'cl_from = page_id',
|
2005-03-14 07:42:38 +00:00
|
|
|
'cl_to' => $this->mTitle->getDBKey()),
|
|
|
|
|
#'page_is_redirect' => 0),
|
2004-12-21 03:26:43 +00:00
|
|
|
#+ $pageCondition,
|
|
|
|
|
$fname,
|
|
|
|
|
array( 'ORDER BY' => $flip ? 'cl_sortkey DESC' : 'cl_sortkey',
|
|
|
|
|
'LIMIT' => $limit + 1 ) );
|
|
|
|
|
|
|
|
|
|
$sk =& $wgUser->getSkin();
|
|
|
|
|
$r = "<br style=\"clear:both;\"/>\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.
|
2005-06-29 01:14:04 +00:00
|
|
|
array_push( $children, $sk->makeKnownLinkObj( $title, $wgContLang->convertHtml( $title->getText() ) ) );
|
2004-12-21 03:26:43 +00:00
|
|
|
|
2004-11-18 23:41:46 +00:00
|
|
|
// 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...
|
2005-04-28 03:33:54 +00:00
|
|
|
$sortkey='';
|
2004-12-21 03:26:43 +00:00
|
|
|
if( $title->getPrefixedText() == $x->cl_sortkey ) {
|
2005-04-28 03:33:54 +00:00
|
|
|
$sortkey=$wgContLang->firstChar( $x->page_title );
|
2004-12-21 03:26:43 +00:00
|
|
|
} else {
|
2005-04-28 03:33:54 +00:00
|
|
|
$sortkey=$wgContLang->firstChar( $x->cl_sortkey );
|
2004-12-21 03:26:43 +00:00
|
|
|
}
|
2005-04-28 03:33:54 +00:00
|
|
|
array_push( $children_start_char, $wgContLang->convert( $sortkey ) ) ;
|
2004-12-21 03:26:43 +00:00
|
|
|
} elseif( $wgCategoryMagicGallery && $title->getNamespace() == NS_IMAGE ) {
|
|
|
|
|
// Show thumbnails of categorized images, in a separate chunk
|
|
|
|
|
if( $flip ) {
|
|
|
|
|
$ig->insert( Image::newFromTitle( $title ) );
|
2004-11-18 23:41:46 +00:00
|
|
|
} else {
|
2004-12-21 03:26:43 +00:00
|
|
|
$ig->add( Image::newFromTitle( $title ) );
|
2004-11-18 23:41:46 +00:00
|
|
|
}
|
2004-09-30 21:36:12 +00:00
|
|
|
} else {
|
2004-12-21 03:26:43 +00:00
|
|
|
// Page in this category
|
2005-06-28 04:51:15 +00:00
|
|
|
array_push( $articles, $sk->makeSizeLinkObj( $x->page_len, $title, $wgContLang->convert( $title->getPrefixedText() ) ) ) ;
|
2005-07-14 05:45:51 +00:00
|
|
|
array_push( $articles_start_char, $wgContLang->convert( $wgContLang->firstChar( $x->cl_sortkey ) ) );
|
2004-11-18 23:41:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
2004-12-21 03:26:43 +00:00
|
|
|
$dbr->freeResult( $res );
|
2004-11-18 23:41:46 +00:00
|
|
|
|
2004-12-21 03:26:43 +00:00
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-18 23:41:46 +00:00
|
|
|
# Don't show subcategories section if there are none.
|
2004-12-21 03:26:43 +00:00
|
|
|
if( count( $children ) > 0 ) {
|
2004-11-18 23:41:46 +00:00
|
|
|
# Showing subcategories
|
|
|
|
|
$r .= '<h2>' . wfMsg( 'subcategories' ) . "</h2>\n";
|
2004-12-21 03:26:43 +00:00
|
|
|
$r .= $this->formatCount( $children, 'subcategorycount' );
|
|
|
|
|
$r .= $this->formatList( $children, $children_start_char );
|
|
|
|
|
}
|
2004-11-18 23:41:46 +00:00
|
|
|
|
2004-12-21 03:26:43 +00:00
|
|
|
# Showing articles in this category
|
|
|
|
|
$ti = htmlspecialchars( $this->mTitle->getText() );
|
2004-11-18 23:41:46 +00:00
|
|
|
$r .= '<h2>' . wfMsg( 'category_header', $ti ) . "</h2>\n";
|
2004-12-21 03:26:43 +00:00
|
|
|
$r .= $this->formatCount( $articles, 'categoryarticlecount' );
|
|
|
|
|
$r .= $this->formatList( $articles, $articles_start_char );
|
2004-11-18 23:41:46 +00:00
|
|
|
|
2004-12-21 03:26:43 +00:00
|
|
|
if( $wgCategoryMagicGallery && ! $ig->isEmpty() ) {
|
|
|
|
|
$r.= $ig->toHTML();
|
2004-11-18 23:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
2004-12-21 03:26:43 +00:00
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
return $r;
|
|
|
|
|
}
|
2004-11-18 23:41:46 +00:00
|
|
|
|
2004-12-21 03:26:43 +00:00
|
|
|
/**
|
|
|
|
|
* @param array $articles
|
|
|
|
|
* @param string $message
|
|
|
|
|
* @return string
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function formatCount( $articles, $message ) {
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
$numart = count( $articles );
|
|
|
|
|
if( $numart == 1 ) {
|
|
|
|
|
# Slightly different message to avoid silly plural
|
|
|
|
|
$message .= '1';
|
|
|
|
|
}
|
|
|
|
|
return wfMsg( $message, $wgContLang->formatNum( $numart ) );
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Format a list of articles chunked by letter, either as a
|
|
|
|
|
* bullet list or a columnar format, depending on the length.
|
|
|
|
|
*
|
|
|
|
|
* @param array $articles
|
|
|
|
|
* @param array $articles_start_char
|
|
|
|
|
* @param int $cutoff
|
|
|
|
|
* @return string
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
|
|
|
|
|
if ( count ( $articles ) > $cutoff ) {
|
|
|
|
|
return $this->columnList( $articles, $articles_start_char );
|
|
|
|
|
} elseif ( count($articles) > 0) {
|
|
|
|
|
// for short lists of articles in categories.
|
|
|
|
|
return $this->shortList( $articles, $articles_start_char );
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Format a list of articles chunked by letter in a three-column
|
|
|
|
|
* list, ordered vertically.
|
|
|
|
|
*
|
|
|
|
|
* @param array $articles
|
|
|
|
|
* @param array $articles_start_char
|
|
|
|
|
* @return string
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function columnList( $articles, $articles_start_char ) {
|
|
|
|
|
// divide list into three equal chunks
|
|
|
|
|
$chunk = (int) (count ( $articles ) / 3);
|
|
|
|
|
|
|
|
|
|
// get and display header
|
|
|
|
|
$r = '<table width="100%"><tr valign="top">';
|
|
|
|
|
|
2004-12-31 15:01:20 +00:00
|
|
|
$prev_start_char = 'none';
|
2004-12-21 03:26:43 +00:00
|
|
|
|
|
|
|
|
// loop through the chunks
|
|
|
|
|
for($startChunk = 0, $endChunk = $chunk, $chunkIndex = 0;
|
|
|
|
|
$chunkIndex < 3;
|
|
|
|
|
$chunkIndex++, $startChunk = $endChunk, $endChunk += $chunk + 1)
|
|
|
|
|
{
|
2005-02-03 08:44:59 +00:00
|
|
|
$r .= "<td>\n";
|
|
|
|
|
$atColumnTop = true;
|
2004-11-18 18:57:51 +00:00
|
|
|
|
2004-12-21 03:26:43 +00:00
|
|
|
// output all articles in category
|
|
|
|
|
for ($index = $startChunk ;
|
|
|
|
|
$index < $endChunk && $index < count($articles);
|
|
|
|
|
$index++ )
|
2004-11-18 23:41:46 +00:00
|
|
|
{
|
2004-12-31 15:01:20 +00:00
|
|
|
// check for change of starting letter or begining of chunk
|
2004-12-21 03:26:43 +00:00
|
|
|
if ( ($index == $startChunk) ||
|
|
|
|
|
($articles_start_char[$index] != $articles_start_char[$index - 1]) )
|
2004-11-18 23:41:46 +00:00
|
|
|
|
|
|
|
|
{
|
2005-02-03 08:44:59 +00:00
|
|
|
if( $atColumnTop ) {
|
|
|
|
|
$atColumnTop = false;
|
|
|
|
|
} else {
|
|
|
|
|
$r .= "</ul>\n";
|
|
|
|
|
}
|
2004-12-21 03:26:43 +00:00
|
|
|
$cont_msg = "";
|
2004-12-31 15:01:20 +00:00
|
|
|
if ( $articles_start_char[$index] == $prev_start_char )
|
2004-12-21 03:26:43 +00:00
|
|
|
$cont_msg = wfMsg('listingcontinuesabbrev');
|
2005-02-03 08:44:59 +00:00
|
|
|
$r .= "<h3>{$articles_start_char[$index]}$cont_msg</h3>\n<ul>";
|
2004-12-21 03:26:43 +00:00
|
|
|
$prev_start_char = $articles_start_char[$index];
|
2004-11-18 23:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
2004-12-21 03:26:43 +00:00
|
|
|
$r .= "<li>{$articles[$index]}</li>";
|
2004-11-18 23:41:46 +00:00
|
|
|
}
|
2005-02-03 08:44:59 +00:00
|
|
|
if( !$atColumnTop ) {
|
|
|
|
|
$r .= "</ul>\n";
|
|
|
|
|
}
|
|
|
|
|
$r .= "</td>\n";
|
2004-11-18 23:41:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2004-12-21 03:26:43 +00:00
|
|
|
$r .= '</tr></table>';
|
|
|
|
|
return $r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Format a list of articles chunked by letter in a bullet list.
|
|
|
|
|
* @param array $articles
|
|
|
|
|
* @param array $articles_start_char
|
|
|
|
|
* @return string
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function shortList( $articles, $articles_start_char ) {
|
|
|
|
|
$r = '<h3>'.$articles_start_char[0]."</h3>\n";
|
|
|
|
|
$r .= '<ul><li>'.$articles[0].'</li>';
|
|
|
|
|
for ($index = 1; $index < count($articles); $index++ )
|
|
|
|
|
{
|
|
|
|
|
if ($articles_start_char[$index] != $articles_start_char[$index - 1])
|
|
|
|
|
{
|
|
|
|
|
$r .= "</ul><h3>{$articles_start_char[$index]}</h3>\n<ul>";
|
|
|
|
|
}
|
2004-09-30 21:36:12 +00:00
|
|
|
|
2004-12-21 03:26:43 +00:00
|
|
|
$r .= "<li>{$articles[$index]}</li>";
|
2004-09-30 21:36:12 +00:00
|
|
|
}
|
2004-12-21 03:26:43 +00:00
|
|
|
$r .= '</ul>';
|
|
|
|
|
return $r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Title $title
|
|
|
|
|
* @param string $first
|
|
|
|
|
* @param string $last
|
|
|
|
|
* @param int $limit
|
|
|
|
|
* @param array $query - additional query options to pass
|
|
|
|
|
* @return string
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function pagingLinks( $title, $first, $last, $limit, $query = array() ) {
|
|
|
|
|
global $wgUser, $wgLang;
|
|
|
|
|
$sk =& $wgUser->getSkin();
|
|
|
|
|
$limitText = $wgLang->formatNum( $limit );
|
|
|
|
|
|
|
|
|
|
$prevLink = htmlspecialchars( wfMsg( 'prevn', $limitText ) );
|
|
|
|
|
if( $first != '' ) {
|
|
|
|
|
$prevLink = $sk->makeLinkObj( $title, $prevLink,
|
|
|
|
|
wfArrayToCGI( $query + array( 'until' => $first ) ) );
|
|
|
|
|
}
|
|
|
|
|
$nextLink = htmlspecialchars( wfMsg( 'nextn', $limitText ) );
|
|
|
|
|
if( $last != '' ) {
|
|
|
|
|
$nextLink = $sk->makeLinkObj( $title, $nextLink,
|
|
|
|
|
wfArrayToCGI( $query + array( 'from' => $last ) ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "($prevLink) ($nextLink)";
|
2004-11-18 23:41:46 +00:00
|
|
|
}
|
2004-08-22 09:42:12 +00:00
|
|
|
}
|
2004-12-21 03:26:43 +00:00
|
|
|
|
|
|
|
|
|
2004-08-22 09:42:12 +00:00
|
|
|
?>
|