r71786 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71785‎ | r71786 | r71787 >
Date:09:17, 27 August 2010
Author:questpc
Status:deferred
Tags:
Comment:
ImageGallery limits proper calculation
Modified paths:
  • /trunk/extensions/CategoryBrowser/CategoryBrowser.php (modified) (history)
  • /trunk/extensions/CategoryBrowser/CategoryBrowserCtrl.php (modified) (history)
  • /trunk/extensions/CategoryBrowser/CategoryBrowserModel.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryBrowser/CategoryBrowser.php
@@ -40,7 +40,7 @@
4141 /* default minimal count of DB rows to start paging */
4242 define( 'CB_PAGING_ROWS', 20 );
4343 /* minimal count of rows in image gallery (not DB rows!) pager */
44 -define( 'CB_FILES_ROWS', 3 );
 44+define( 'CB_FILES_MAX_ROWS', 3 );
4545 /* maximal number of logical operations in SQL filter (condition) */
4646 define( 'CB_MAX_LOGICAL_OP', 5 );
4747
@@ -67,7 +67,8 @@
6868 // default limits of different pagers
6969 static $categoriesLimit = CB_PAGING_ROWS;
7070 static $pagesLimit = CB_PAGING_ROWS;
71 - static $filesLimit = CB_FILES_ROWS;
 71+ static $filesLimit = null;
 72+ static $filesMaxRows = CB_FILES_MAX_ROWS;
7273
7374 /**
7475 * Add this extension to the mediawiki's extensions list.
@@ -113,6 +114,14 @@
114115 $wgAjaxExportList[] = 'CategoryBrowser::getSubOffsetHtml';
115116 $wgAjaxExportList[] = 'CategoryBrowser::applyEncodedQueue';
116117 $wgAjaxExportList[] = 'CategoryBrowser::generateSelectedOption';
 118+
 119+ # calculate proper limit for files pager
 120+ # by default, limit for ImageGallery is maxrows * perrow :
 121+ self::$filesLimit = CB_Setup::$filesMaxRows * CB_Setup::$imageGalleryPerRow;
 122+ if ( self::$filesLimit <= 0 ) {
 123+ # ImageGallery is disabled, use pages limit instead
 124+ self::$filesLimit = CB_Setup::$pagesLimit;
 125+ }
117126 }
118127
119128 /*
@@ -127,8 +136,8 @@
128137 self::$skin = is_object( $wgUser ) ? self::$user->getSkin() : $wgSkin;
129138 self::$response = $wgRequest->response();
130139 self::$cookie_prefix = 'CategoryBrowser_' . self::$user->getId() . '_';
131 - // find out current collation of category table 'cat_title' field
132 - // this is required to switch between CI and CS search
 140+ # find out current collation of category table 'cat_title' field
 141+ # this is required to switch between CI and CS search
133142 $db = & wfGetDB( DB_SLAVE );
134143 $category_table = $db->tableName( 'category' );
135144 $db_result = $db->query( "SHOW FULL COLUMNS FROM ${category_table}" );
Index: trunk/extensions/CategoryBrowser/CategoryBrowserModel.php
@@ -107,6 +107,7 @@
108108 * otherwise throws an error
109109 * warning: will fail, when called before calling $this->getCurrentRows() !
110110 * warning: $this->limit is not set properly before calling $this->getCurrentRows() !
 111+ * todo: unused anymore; keep because might be useful in some cases
111112 */
112113 function getListType() {
113114 // it is not enough to check $this->entries[0],
Index: trunk/extensions/CategoryBrowser/CategoryBrowserCtrl.php
@@ -265,7 +265,7 @@
266266 'js_nav_func' => "filesNav",
267267 'select_fields' => "page_title, page_namespace, page_len, page_is_redirect",
268268 'ns_cond' => "page_namespace = " . NS_FILE,
269 - 'default_limit' => CB_Setup::$filesLimit * CB_Setup::$imageGalleryPerRow
 269+ 'default_limit' => CB_Setup::$filesLimit
270270 )
271271 );
272272 wfLoadExtensionMessages( 'CategoryBrowser' );
@@ -273,27 +273,28 @@
274274 if ( count( $args ) < 2 ) {
275275 return 'Too few parameters in ' . __METHOD__;
276276 }
277 - if ( !isset( $pager_types[ $args[0] ] ) ) {
278 - return 'Unknown pager type in ' . __METHOD__;
 277+ $pager_type = $args[0];
 278+ if ( !isset( $pager_types[ $pager_type ] ) ) {
 279+ return 'Unknown pager type=' . CB_Setup::specialchars( $pager_type ) . ' in ' . __METHOD__;
279280 }
280 - $pager_type = & $pager_types[ $args[0] ];
281 - $limit = ( count( $args ) > 3 ) ? abs( intval( $args[3] ) ) : $pager_type[ 'default_limit' ];
 281+ $pager_setup = & $pager_types[ $args[0] ];
 282+ $limit = ( count( $args ) > 3 ) ? abs( intval( $args[3] ) ) : $pager_setup[ 'default_limit' ];
282283 $offset = ( count( $args ) > 2 ) ? abs( intval( $args[2] ) ) : 0;
283284 $parentCatId = abs( intval( $args[1] ) );
284285 $cb = new CategoryBrowser();
285286 $pager = new CB_SubPager( $parentCatId, $offset, $limit,
286 - $pager_type[ 'js_nav_func' ],
287 - $pager_type[ 'select_fields' ],
288 - $pager_type[ 'ns_cond' ] );
 287+ $pager_setup[ 'js_nav_func' ],
 288+ $pager_setup[ 'select_fields' ],
 289+ $pager_setup[ 'ns_cond' ] );
289290 $pager->getCurrentRows();
290 - switch ( $pager->getListType() ) {
291 - case 'generateCatList' :
 291+ switch ( $pager_type ) {
 292+ case 'subcats' :
292293 $view = new CB_CategoriesView( $pager );
293294 break;
294 - case 'generatePagesList' :
 295+ case 'pages' :
295296 $view = new CB_PagesView( $pager );
296297 break;
297 - case 'generateFilesList' :
 298+ case 'files' :
298299 # respect extension & core settings
299300 global $wgOut, $wgCategoryMagicGallery;
300301 // unstub $wgOut, otherwise $wgOut->mNoGallery may be unavailable

Status & tagging log