mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CategoryTree
synced 2024-11-30 11:06:55 +00:00
Replace CategoryTreeCategoryViewer with hooks of CategoryViewer
Change-Id: I34a47c4f2f4b08cd3ed8ce5c4a585cc42d44372d
This commit is contained in:
parent
cca06d7656
commit
6e911fba75
|
@ -100,13 +100,14 @@
|
||||||
},
|
},
|
||||||
"Hooks": {
|
"Hooks": {
|
||||||
"MediaWikiServices": "config",
|
"MediaWikiServices": "config",
|
||||||
"ArticleFromTitle": "default",
|
|
||||||
"SpecialTrackingCategories::preprocess": "default",
|
"SpecialTrackingCategories::preprocess": "default",
|
||||||
"SpecialTrackingCategories::generateCatLink": "default",
|
"SpecialTrackingCategories::generateCatLink": "default",
|
||||||
"SkinAfterPortlet": "default",
|
"SkinAfterPortlet": "default",
|
||||||
"SkinBuildSidebar": "default",
|
"SkinBuildSidebar": "default",
|
||||||
"ParserFirstCallInit": "default",
|
"ParserFirstCallInit": "default",
|
||||||
"OutputPageMakeCategoryLinks": "default"
|
"OutputPageMakeCategoryLinks": "default",
|
||||||
|
"CategoryViewer::doCategoryQuery": "default",
|
||||||
|
"CategoryViewer::generateLink": "default"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"CategoryTreeMaxChildren": {
|
"CategoryTreeMaxChildren": {
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace MediaWiki\Extension\CategoryTree;
|
||||||
use Category;
|
use Category;
|
||||||
use MediaWiki\Linker\LinkTarget;
|
use MediaWiki\Linker\LinkTarget;
|
||||||
use Wikimedia\Rdbms\ILoadBalancer;
|
use Wikimedia\Rdbms\ILoadBalancer;
|
||||||
|
use Wikimedia\Rdbms\IResultWrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches Category::class objects
|
* Caches Category::class objects
|
||||||
|
@ -91,6 +92,13 @@ class CategoryCache {
|
||||||
->caller( __METHOD__ )
|
->caller( __METHOD__ )
|
||||||
->fetchResultSet();
|
->fetchResultSet();
|
||||||
|
|
||||||
|
$this->fillFromQuery( $rows );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IResultWrapper $rows
|
||||||
|
*/
|
||||||
|
public function fillFromQuery( IResultWrapper $rows ) {
|
||||||
foreach ( $rows as $row ) {
|
foreach ( $rows as $row ) {
|
||||||
$this->cache[$row->cat_title] = Category::newFromRow( $row );
|
$this->cache[$row->cat_title] = Category::newFromRow( $row );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
<?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 CategoryPage;
|
|
||||||
|
|
||||||
class CategoryTreeCategoryPage extends CategoryPage {
|
|
||||||
/** @var string */
|
|
||||||
public $mCategoryViewerClass = CategoryTreeCategoryViewer::class;
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
<?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 {
|
|
||||||
/** @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()->getRawVal( '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 );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -24,24 +24,25 @@
|
||||||
|
|
||||||
namespace MediaWiki\Extension\CategoryTree;
|
namespace MediaWiki\Extension\CategoryTree;
|
||||||
|
|
||||||
use Article;
|
|
||||||
use Config;
|
use Config;
|
||||||
use Html;
|
use Html;
|
||||||
use IContextSource;
|
use MediaWiki\Hook\CategoryViewer__doCategoryQueryHook;
|
||||||
|
use MediaWiki\Hook\CategoryViewer__generateLinkHook;
|
||||||
use MediaWiki\Hook\OutputPageMakeCategoryLinksHook;
|
use MediaWiki\Hook\OutputPageMakeCategoryLinksHook;
|
||||||
use MediaWiki\Hook\ParserFirstCallInitHook;
|
use MediaWiki\Hook\ParserFirstCallInitHook;
|
||||||
use MediaWiki\Hook\SkinBuildSidebarHook;
|
use MediaWiki\Hook\SkinBuildSidebarHook;
|
||||||
use MediaWiki\Hook\SpecialTrackingCategories__generateCatLinkHook;
|
use MediaWiki\Hook\SpecialTrackingCategories__generateCatLinkHook;
|
||||||
use MediaWiki\Hook\SpecialTrackingCategories__preprocessHook;
|
use MediaWiki\Hook\SpecialTrackingCategories__preprocessHook;
|
||||||
use MediaWiki\Linker\LinkTarget;
|
use MediaWiki\Linker\LinkTarget;
|
||||||
use MediaWiki\Page\Hook\ArticleFromTitleHook;
|
|
||||||
use OutputPage;
|
use OutputPage;
|
||||||
use Parser;
|
use Parser;
|
||||||
use PPFrame;
|
use PPFrame;
|
||||||
|
use RequestContext;
|
||||||
use Sanitizer;
|
use Sanitizer;
|
||||||
use Skin;
|
use Skin;
|
||||||
use SpecialPage;
|
use SpecialPage;
|
||||||
use Title;
|
use Title;
|
||||||
|
use Wikimedia\Rdbms\IResultWrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hooks for the CategoryTree extension, an AJAX based gadget
|
* Hooks for the CategoryTree extension, an AJAX based gadget
|
||||||
|
@ -50,12 +51,13 @@ use Title;
|
||||||
* @phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
|
* @phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
|
||||||
*/
|
*/
|
||||||
class Hooks implements
|
class Hooks implements
|
||||||
ArticleFromTitleHook,
|
|
||||||
SpecialTrackingCategories__preprocessHook,
|
SpecialTrackingCategories__preprocessHook,
|
||||||
SpecialTrackingCategories__generateCatLinkHook,
|
SpecialTrackingCategories__generateCatLinkHook,
|
||||||
SkinBuildSidebarHook,
|
SkinBuildSidebarHook,
|
||||||
ParserFirstCallInitHook,
|
ParserFirstCallInitHook,
|
||||||
OutputPageMakeCategoryLinksHook
|
OutputPageMakeCategoryLinksHook,
|
||||||
|
CategoryViewer__doCategoryQueryHook,
|
||||||
|
CategoryViewer__generateLinkHook
|
||||||
{
|
{
|
||||||
|
|
||||||
/** @var CategoryCache */
|
/** @var CategoryCache */
|
||||||
|
@ -208,20 +210,6 @@ class Hooks implements
|
||||||
return $ct->getTag( $parser, $cat, $hideroot, $attr, $depth, $allowMissing );
|
return $ct->getTag( $parser, $cat, $hideroot, $attr, $depth, $allowMissing );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* ArticleFromTitle hook, override category page handling
|
|
||||||
*
|
|
||||||
* @param Title $title
|
|
||||||
* @param Article|null &$article Article (object) that will be returned
|
|
||||||
* @param IContextSource $context
|
|
||||||
* @return bool|void True or no return value to continue or false to abort
|
|
||||||
*/
|
|
||||||
public function onArticleFromTitle( $title, &$article, $context ) {
|
|
||||||
if ( $title->inNamespace( NS_CATEGORY ) ) {
|
|
||||||
$article = new CategoryTreeCategoryPage( $title );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OutputPageMakeCategoryLinks hook, override category links
|
* OutputPageMakeCategoryLinks hook, override category links
|
||||||
* @param OutputPage $out
|
* @param OutputPage $out
|
||||||
|
@ -293,4 +281,45 @@ class Hooks implements
|
||||||
|
|
||||||
$html .= CategoryTree::createCountString( $specialPage->getContext(), $cat, 0 );
|
$html .= CategoryTree::createCountString( $specialPage->getContext(), $cat, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $type
|
||||||
|
* @param IResultWrapper $res
|
||||||
|
*/
|
||||||
|
public function onCategoryViewer__doCategoryQuery( $type, $res ) {
|
||||||
|
if ( $type === 'subcat' && $res ) {
|
||||||
|
$this->categoryCache->fillFromQuery( $res );
|
||||||
|
CategoryTree::setHeaders( RequestContext::getMain()->getOutput() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $type
|
||||||
|
* @param Title $title
|
||||||
|
* @param string $html
|
||||||
|
* @param string &$link
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function onCategoryViewer__generateLink( $type, $title, $html, &$link ) {
|
||||||
|
if ( $type !== 'subcat' || $link !== null ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request = RequestContext::getMain()->getRequest();
|
||||||
|
if ( $request->getCheck( 'notree' ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$options = $this->config->get( 'CategoryTreeCategoryPageOptions' );
|
||||||
|
$mode = $request->getRawVal( 'mode' );
|
||||||
|
if ( $mode !== null ) {
|
||||||
|
$options['mode'] = $mode;
|
||||||
|
}
|
||||||
|
$tree = new CategoryTree( $options );
|
||||||
|
|
||||||
|
$cat = $this->categoryCache->getCategory( $title );
|
||||||
|
|
||||||
|
$link = $tree->renderNodeInfo( $title, $cat );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue