mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CategoryTree
synced 2024-12-02 20:16:17 +00:00
4bc230093f
The CategoryTree::setHeaders() method adds modules to OutputPage. It does not matter if setHeaders() gets called several times. The previous code tried to avoid to call setHeaders() several times. If wgCategoryTreeForceHeaders is set then the modules get loaded by the hooks "BeforePageDisplay" or "BeforePageDisplayMobile" on every page. In this case duplicate calls of setHeaders() are (partly) avoided by not calling setHeaders() on other hooks. This change removes this micro optimization and loads the modules unconditionally if a category tree is added on a hook. shouldForceHeaders() is now inlined. Change-Id: Ic9219575a714886b4edd446efde2a330dff4dee6
93 lines
2.3 KiB
PHP
93 lines
2.3 KiB
PHP
<?php
|
|
/**
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* @file
|
|
*/
|
|
|
|
namespace MediaWiki\Extension\CategoryTree;
|
|
|
|
use Category;
|
|
use CategoryViewer;
|
|
|
|
class CategoryTreeCategoryViewer extends CategoryViewer {
|
|
public $child_cats;
|
|
|
|
/**
|
|
* @var CategoryTree
|
|
*/
|
|
public $categorytree;
|
|
|
|
/**
|
|
* @return CategoryTree
|
|
*/
|
|
private function getCategoryTree() {
|
|
if ( !isset( $this->categorytree ) ) {
|
|
CategoryTree::setHeaders( $this->getOutput() );
|
|
|
|
$options = $this->getConfig()->get( 'CategoryTreeCategoryPageOptions' );
|
|
|
|
$mode = $this->getRequest()->getVal( 'mode' );
|
|
if ( $mode !== null ) {
|
|
$options['mode'] = CategoryTree::decodeMode( $mode );
|
|
}
|
|
|
|
$this->categorytree = new CategoryTree( $options );
|
|
}
|
|
|
|
return $this->categorytree;
|
|
}
|
|
|
|
/**
|
|
* Add a subcategory to the internal lists
|
|
* @param Category $cat
|
|
* @param string $sortkey
|
|
* @param int $pageLength
|
|
*/
|
|
public function addSubcategoryObject( Category $cat, $sortkey, $pageLength ) {
|
|
$title = $cat->getTitle();
|
|
|
|
if ( $this->getRequest()->getCheck( 'notree' ) ) {
|
|
parent::addSubcategoryObject( $cat, $sortkey, $pageLength );
|
|
return;
|
|
}
|
|
|
|
$tree = $this->getCategoryTree();
|
|
|
|
$this->children[] = $tree->renderNodeInfo( $title, $cat );
|
|
|
|
$this->children_start_char[] = $this->getSubcategorySortChar( $title, $sortkey );
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function clearCategoryState() {
|
|
$this->child_cats = [];
|
|
parent::clearCategoryState();
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function finaliseCategoryState() {
|
|
if ( $this->flip ) {
|
|
$this->child_cats = array_reverse( $this->child_cats );
|
|
}
|
|
parent::finaliseCategoryState();
|
|
}
|
|
}
|