X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2FCategoryPage.php;h=5fcad49ff7b019352a915c2951d1c3593c26e9bc;hb=2e8419f73832e1093856e8120dd2a8bad58a4592;hp=b12c13fe78712f3923b29315f97af6f00ae4cfaf;hpb=7ec501be6a20672f61f2f4d0e84df9bbbab4bc6d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/CategoryPage.php b/includes/CategoryPage.php index b12c13fe78..5fcad49ff7 100644 --- a/includes/CategoryPage.php +++ b/includes/CategoryPage.php @@ -1,27 +1,35 @@ getVal( 'diff' ); $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) ); - if ( isset( $diff ) && $diffOnly ) + if ( isset( $diff ) && $diffOnly ) { return parent::view(); + } - if ( !wfRunHooks( 'CategoryPageView', array( &$this ) ) ) + if ( !wfRunHooks( 'CategoryPageView', array( &$this ) ) ) { return; + } if ( NS_CATEGORY == $this->mTitle->getNamespace() ) { $this->openShowCategory(); @@ -51,15 +59,18 @@ class CategoryPage extends Article { } function closeShowCategory() { - global $wgOut, $wgRequest; + global $wgOut; $from = $until = array(); foreach ( array( 'page', 'subcat', 'file' ) as $type ) { - $from[$type] = $wgRequest->getVal( "{$type}from" ); - $until[$type] = $wgRequest->getVal( "{$type}until" ); + # 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; } - $viewer = new CategoryViewer( $this->mTitle, $from, $until, $wgRequest->getValues() ); + $viewer = new $this->mCategoryViewerClass( $this->mTitle, $from, $until, $_GET ); $wgOut->addHTML( $viewer->getHTML() ); } } @@ -83,15 +94,15 @@ class CategoryViewer { $this->limit = $wgCategoryPagingLimit; $this->cat = Category::newFromTitle( $title ); $this->query = $query; + unset( $this->query['title'] ); } /** * Format the category data list. * * @return string HTML output - * @private */ - function getHTML() { + public function getHTML() { global $wgOut, $wgCategoryMagicGallery, $wgContLang; wfProfileIn( __METHOD__ ); @@ -149,26 +160,26 @@ class CategoryViewer { /** * Add a subcategory to the internal lists, using a Category object */ - function addSubcategoryObject( $cat, $sortkey, $pageLength ) { - $title = $cat->getTitle(); - $this->addSubcategory( $title, $sortkey, $pageLength ); - } - - /** - * Add a subcategory to the internal lists, using a title object - * @deprecated kept for compatibility, please use addSubcategoryObject instead - */ - function addSubcategory( $title, $sortkey, $pageLength ) { + function addSubcategoryObject( Category $cat, $sortkey, $pageLength ) { // Subcategory; strip the 'Category' namespace from the link text. $this->children[] = $this->getSkin()->link( - $title, + $cat->getTitle(), null, array(), array(), array( 'known', 'noclasses' ) ); - $this->children_start_char[] = $this->getSubcategorySortChar( $title, $sortkey ); + $this->children_start_char[] = + $this->getSubcategorySortChar( $cat->getTitle(), $sortkey ); + } + + /** + * Add a subcategory to the internal lists, using a title object + * @deprecated kept for compatibility, please use addSubcategoryObject instead + */ + function addSubcategory( Title $title, $sortkey, $pageLength ) { + $this->addSubcategoryObject( Category::newFromTitle( $title ), $sortkey, $pageLength ); } /** @@ -243,18 +254,6 @@ class CategoryViewer { $dbr = wfGetDB( DB_SLAVE, 'category' ); - $tables = array( 'page', 'categorylinks', 'category' ); - $fields = array( 'page_title', 'page_namespace', 'page_len', - 'page_is_redirect', 'cl_sortkey', 'cat_id', 'cat_title', - 'cat_subcats', 'cat_pages', 'cat_files' ); - $conds = array( 'cl_to' => $this->title->getDBkey() ); - $opts = array( - 'USE INDEX' => array( 'categorylinks' => 'cl_sortkey' ), - 'LIMIT' => $this->limit + 1, - ); - $joins = array( 'categorylinks' => array( 'INNER JOIN', 'cl_from = page_id' ), - 'category' => array( 'LEFT JOIN', 'cat_title = page_title AND page_namespace = ' . NS_CATEGORY ) ); - $this->nextPage = array( 'page' => null, 'subcat' => null, @@ -277,12 +276,21 @@ class CategoryViewer { } $res = $dbr->select( - $tables, - array_merge( $fields, array( 'cl_sortkey_prefix' ) ), - $conds + $extraConds, + 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, __METHOD__, - $opts + array( 'ORDER BY' => $this->flip[$type] ? 'cl_sortkey DESC' : 'cl_sortkey' ), - $joins + array( + 'USE INDEX' => array( 'categorylinks' => 'cl_sortkey' ), + 'LIMIT' => $this->limit + 1, + 'ORDER BY' => $this->flip[$type] ? 'cl_sortkey DESC' : 'cl_sortkey', + ), + array( + 'categorylinks' => array( 'INNER JOIN', 'cl_from = page_id' ), + 'category' => array( 'LEFT JOIN', 'cat_title = page_title AND page_namespace = ' . NS_CATEGORY ) + ) ); $count = 0; @@ -413,10 +421,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 ''; } @@ -436,7 +444,7 @@ class CategoryViewer { * @return String * @private */ - function columnList( $articles, $articles_start_char ) { + 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 */ ); @@ -488,7 +496,7 @@ class CategoryViewer { * @return String * @private */ - function shortList( $articles, $articles_start_char ) { + static function shortList( $articles, $articles_start_char ) { $r = '

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

\n"; $r .= '