function generateList()
 {
     if ($this->pager->offset == -1) {
         return '';
         // list has no entries
     }
     # {{{ gallery container template
     $gallery_html = '';
     $gallery_tpl = array('__tag' => 'div', 'class' => 'cb_files_container', 0 => &$gallery_html);
     # }}}
     # create list of files (holder of prev/next AJAX links and generated image gallery)
     $filelist = array();
     # create image gallery
     $gallery = new ImageGallery();
     $gallery->setHideBadImages();
     $gallery->setPerRow(CB_Setup::$imageGalleryPerRow);
     $this->addPrevPageLink($filelist);
     foreach ($this->pager->entries as &$file) {
         $file_title = Title::makeTitle($file->page_namespace, $file->page_title);
         # show the sortkey, when it does not match title name
         $gallery->add($file_title, $this->addSortKey($file_title, $file));
     }
     if (!$gallery->isEmpty()) {
         $gallery_html = $gallery->toHTML();
         $filelist[] = CB_XML::toText($gallery_tpl);
     }
     $this->addNextPageLink($filelist);
     return $filelist;
 }
 function execute($param)
 {
     global $wgOut;
     $this->setHeaders();
     $this->ranges = CategoryBrowser::generateRanges($this->source_ranges);
     $cb = new CategoryBrowser();
     # try to create rootPager from rootcond cookie value
     if (is_string($encPolishQueue = CB_Setup::getCookie('rootcond'))) {
         $sqlCond = CB_SqlCond::newFromEncodedPolishQueue($encPolishQueue);
         $rootPager = CB_RootPager::newFromSqlCond($sqlCond);
         # add selected condition to range, if not duplicate
         CategoryBrowser::addRange($this->ranges, $rootPager->sqlCond);
     } else {
         # otherwise, try to create rootPager from the list of predefined infix queues (ranges)
         if (!is_object($rootPager = CB_RootPager::newFromCategoryRange($this->ranges))) {
             return;
         }
     }
     $rootPager->getCurrentRows();
     /* reverse polish queue encode / decode validations */
     $testCond = CB_SqlCond::newFromEncodedPolishQueue($rootPager->sqlCond->getEncodedQueue(false));
     if ($rootPager->sqlCond->getCond() != $testCond->getCond()) {
         throw new MWException('Infix queue was not re-built correctly from encoded polish queue in ' . __METHOD__);
     }
     /* infix queue encode / decode validations */
     $testCond = CB_SqlCond::newFromEncodedInfixQueue($rootPager->sqlCond->getEncodedQueue(true));
     if ($rootPager->sqlCond->getCond() != $testCond->getCond()) {
         throw new MWException('Infix queue was not re-built correctly from encoded infix queue in ' . __METHOD__);
     }
     /* end of validations */
     # {{{ top template
     $condSelector = '';
     $catlist = array();
     $js_setFilter = 'CategoryBrowser.setFilter()';
     $filterFields = array();
     if (CB_Setup::$cat_title_CI != '') {
         // case insensitive search is possible
         $filterFields[] = array('__tag' => 'span', 0 => wfMsg('cb_cat_name_filter_ci'));
         $filterFields[] = array('__tag' => 'input', 'class' => 'cb_filter_field', 'type' => 'checkbox', 'onchange' => $js_setFilter, 'id' => 'cb_cat_name_filter_ci', 'title' => wfMsg('cb_cat_name_filter_ci'), 'checked' => null);
     }
     if (CB_Setup::$allowNoParentsOnly) {
         $filterFields[] = array(array('__tag' => 'span', 'class' => 'cb_filter_field', 0 => wfMsg('cb_show_no_parents_only')), array('__tag' => 'input', 'class' => 'cb_filter_field', 'type' => 'checkbox', 'onchange' => $js_setFilter, 'onclick' => $js_setFilter, 'title' => wfMsg('cb_show_no_parents_only'), 'id' => 'cb_cat_no_parents_only'));
     }
     $top_tpl = array('__tag' => 'table', 'class' => 'cb_top_container', '__end' => "\n", array('__tag' => 'tr', '__end' => "\n", array('__tag' => 'td', 'class' => 'cb_toolbox_top', '__end' => "\n", 0 => &$condSelector)), array('__tag' => 'tr', '__end' => "\n", array('__tag' => 'td', 'class' => 'cb_toolbox_bottom', '__end' => "\n", array('__tag' => 'div', 'class' => 'cb_filter_container', wfMsg('cb_cat_name_filter'), array('__tag' => 'input', 'type' => 'text', 'onkeyup' => $js_setFilter, 'onchange' => $js_setFilter, 'id' => 'cb_cat_name_filter'), array('__tag' => 'input', 'type' => 'button', 'class' => 'cb_filter_field', 'onclick' => 'CategoryBrowser.clearNameFilter(this)', 'title' => wfMsg('cb_cat_name_filter_clear'), 'value' => '※')), array('__tag' => 'div', 'class' => 'cb_filter_container', &$filterFields))), array('__tag' => 'tr', '__end' => "\n", array('__tag' => 'td', 'class' => 'cb_toolbox', 'style' => 'display:none; ', '__end' => "\n", array('__tag' => 'div', 'id' => 'cb_editor_container', 0 => ''), array('__tag' => 'div', 'class' => 'cb_separate_container', 0 => ''))), array('__tag' => 'tr', '__end' => "\n", array('__tag' => 'td', 'class' => 'cb_toolbox', 'style' => 'display:none; ', '__end' => "\n", array('__tag' => 'div', 'class' => 'cb_copy_line_hint', 0 => wfMsg('cb_copy_line_hint')), array('__tag' => 'div', 'id' => 'cb_samples_container', 0 => ''))), array('__tag' => 'tr', '__end' => "\n", array('__tag' => 'td', '__end' => "\n", array('__tag' => 'div', 'id' => 'cb_root_container', 0 => &$catlist))));
     # }}}
     $condSelector = CategoryBrowser::generateSelector($this->ranges, $rootPager);
     $pagerView = new CB_CategoriesView($rootPager);
     $catlist = $pagerView->generateList();
     $wgOut->addHTML(CB_XML::toText($top_tpl));
 }
 /**
  * called via AJAX to get list of (subcategories,pages,files) for specitied parent category id, offset, limit
  * @param $args[0] : type of pager ('subcats','pages','files')
  * @param $args[1] : parent category name
  * @param $args[2] : offset (optional)
  * @param $args[3] : limit (optional)
  */
 static function getSubOffsetHtml()
 {
     $pager_types = array('subcats' => array('js_nav_func' => "subCatsNav", 'select_fields' => "cl_sortkey, cat_id, cat_title, cat_subcats, " . CB_AbstractPager::$cat_pages_only . ", cat_files", 'ns_cond' => "page_namespace = " . NS_CATEGORY, 'default_limit' => CB_Setup::$categoriesLimit), 'pages' => array('js_nav_func' => "pagesNav", 'select_fields' => "page_title, page_namespace, page_len, page_is_redirect", 'ns_cond' => "NOT page_namespace IN (" . NS_FILE . "," . NS_CATEGORY . ")", 'default_limit' => CB_Setup::$pagesLimit), 'files' => array('js_nav_func' => "filesNav", 'select_fields' => "page_title, page_namespace, page_len, page_is_redirect", 'ns_cond' => "page_namespace = " . NS_FILE, 'default_limit' => CB_Setup::$filesLimit), 'parents' => array('default_limit' => CB_Setup::$parentsLimit));
     $args = func_get_args();
     if (count($args) < 2) {
         return 'Too few parameters in ' . __METHOD__;
     }
     $pager_type = $args[0];
     if (!isset($pager_types[$pager_type])) {
         return 'Unknown pager type=' . CB_Setup::specialchars($pager_type) . ' in ' . __METHOD__;
     }
     $pager_setup =& $pager_types[$pager_type];
     $limit = count($args) > 3 ? abs(intval($args[3])) : $pager_setup['default_limit'];
     $offset = count($args) > 2 ? abs(intval($args[2])) : 0;
     $parentCatName = $args[1];
     $cb = new CategoryBrowser();
     if ($pager_type == 'parents') {
         $pager = new CB_ParentPager($parentCatName, $offset, $limit);
     } else {
         $pager = new CB_SubPager($parentCatName, $offset, $limit, $pager_setup['js_nav_func'], $pager_setup['select_fields'], $pager_setup['ns_cond']);
     }
     $pager->getCurrentRows();
     switch ($pager_type) {
         case 'subcats':
         case 'parents':
             $view = new CB_CategoriesView($pager);
             break;
         case 'pages':
             $view = new CB_PagesView($pager);
             break;
         case 'files':
             # respect extension & core settings
             global $wgOut, $wgCategoryMagicGallery;
             // unstub $wgOut, otherwise $wgOut->mNoGallery may be unavailable
             // strange, but calling wfDebug() instead does not unstub $wgOut successfully
             $wgOut->getHeadItems();
             if (CB_Setup::$imageGalleryPerRow < 1 || !$wgCategoryMagicGallery || $wgOut->mNoGallery) {
                 $view = new CB_PagesView($pager);
             } else {
                 $view = new CB_FilesView($pager);
             }
             break;
         default:
             return 'Unknown list type in ' . __METHOD__;
     }
     $list = $view->generateList();
     return CB_XML::toText($list);
 }