2004-08-22 09:42:12 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2012-05-21 19:56:04 +00:00
|
|
|
* Special handling for category description pages.
|
2010-08-14 17:42:40 +00:00
|
|
|
* Modelled after ImagePage.php.
|
2004-09-02 23:28:24 +00:00
|
|
|
*
|
2012-05-21 19:56:04 +00:00
|
|
|
* 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
|
|
|
|
|
*
|
2010-08-14 17:42:40 +00:00
|
|
|
* @file
|
2004-09-03 23:00:01 +00:00
|
|
|
*/
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2010-08-14 17:42:40 +00:00
|
|
|
* Special handling for category description pages, showing pages,
|
|
|
|
|
* subcategories and file that belong to the category
|
2019-06-29 14:11:57 +00:00
|
|
|
*
|
2020-03-26 00:43:50 +00:00
|
|
|
* @method WikiCategoryPage getPage() Set by overwritten newPage() in this class
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-08-22 09:42:12 +00:00
|
|
|
class CategoryPage extends Article {
|
2010-08-13 22:07:48 +00:00
|
|
|
# Subclasses can change this to override the viewer class.
|
2018-01-13 00:02:09 +00:00
|
|
|
protected $mCategoryViewerClass = CategoryViewer::class;
|
2010-08-13 22:07:48 +00:00
|
|
|
|
2011-10-14 21:18:38 +00:00
|
|
|
/**
|
2014-04-10 18:50:10 +00:00
|
|
|
* @param Title $title
|
2011-10-14 21:18:38 +00:00
|
|
|
* @return WikiCategoryPage
|
|
|
|
|
*/
|
2011-06-29 22:09:51 +00:00
|
|
|
protected function newPage( Title $title ) {
|
|
|
|
|
// Overload mPage with a category-specific page
|
|
|
|
|
return new WikiCategoryPage( $title );
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-17 16:28:19 +00:00
|
|
|
public function view() {
|
2011-10-09 16:00:50 +00:00
|
|
|
$request = $this->getContext()->getRequest();
|
|
|
|
|
$diff = $request->getVal( 'diff' );
|
|
|
|
|
$diffOnly = $request->getBool( 'diffonly',
|
|
|
|
|
$this->getContext()->getUser()->getOption( 'diffonly' ) );
|
2007-01-17 05:01:54 +00:00
|
|
|
|
2013-01-01 21:13:30 +00:00
|
|
|
if ( $diff !== null && $diffOnly ) {
|
2011-10-15 17:46:37 +00:00
|
|
|
parent::view();
|
|
|
|
|
return;
|
2010-11-30 19:06:28 +00:00
|
|
|
}
|
2007-01-17 05:01:54 +00:00
|
|
|
|
2016-12-25 23:55:27 +00:00
|
|
|
// Avoid PHP 7.1 warning of passing $this by reference
|
|
|
|
|
$categoryPage = $this;
|
|
|
|
|
|
|
|
|
|
if ( !Hooks::run( 'CategoryPageView', [ &$categoryPage ] ) ) {
|
2009-01-24 17:42:12 +00:00
|
|
|
return;
|
2010-11-30 19:06:28 +00:00
|
|
|
}
|
2005-04-25 11:09:21 +00:00
|
|
|
|
2011-10-15 17:46:37 +00:00
|
|
|
$title = $this->getTitle();
|
2016-05-19 12:48:26 +00:00
|
|
|
if ( $title->inNamespace( NS_CATEGORY ) ) {
|
2004-08-22 09:42:12 +00:00
|
|
|
$this->openShowCategory();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-25 20:52:30 +00:00
|
|
|
parent::view();
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2016-05-19 12:48:26 +00:00
|
|
|
if ( $title->inNamespace( NS_CATEGORY ) ) {
|
2004-08-22 09:42:12 +00:00
|
|
|
$this->closeShowCategory();
|
|
|
|
|
}
|
2016-08-23 04:10:13 +00:00
|
|
|
|
|
|
|
|
# Use adaptive TTLs for CDN so delayed/failed purges are noticed less often
|
|
|
|
|
$outputPage = $this->getContext()->getOutput();
|
2020-03-26 00:43:50 +00:00
|
|
|
$outputPage->adaptCdnTTL(
|
|
|
|
|
$this->getPage()->getTouched(),
|
|
|
|
|
IExpiringStore::TTL_MINUTE
|
|
|
|
|
);
|
2004-08-22 09:42:12 +00:00
|
|
|
}
|
2010-02-14 22:07:30 +00:00
|
|
|
|
2020-05-17 16:28:19 +00:00
|
|
|
public function openShowCategory() {
|
2004-08-22 09:42:12 +00:00
|
|
|
# For overloading
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2020-05-17 16:28:19 +00:00
|
|
|
public function closeShowCategory() {
|
2011-03-09 01:13:17 +00:00
|
|
|
// Use these as defaults for back compat --catrope
|
2011-10-09 16:00:50 +00:00
|
|
|
$request = $this->getContext()->getRequest();
|
|
|
|
|
$oldFrom = $request->getVal( 'from' );
|
|
|
|
|
$oldUntil = $request->getVal( 'until' );
|
2011-10-09 03:50:03 +00:00
|
|
|
|
2011-10-09 16:00:50 +00:00
|
|
|
$reqArray = $request->getValues();
|
2011-10-14 21:18:38 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$from = $until = [];
|
|
|
|
|
foreach ( [ 'page', 'subcat', 'file' ] as $type ) {
|
2011-10-09 16:00:50 +00:00
|
|
|
$from[$type] = $request->getVal( "{$type}from", $oldFrom );
|
|
|
|
|
$until[$type] = $request->getVal( "{$type}until", $oldUntil );
|
2011-10-09 03:50:03 +00:00
|
|
|
|
|
|
|
|
// Do not want old-style from/until propagating in nav links.
|
|
|
|
|
if ( !isset( $reqArray["{$type}from"] ) && isset( $reqArray["from"] ) ) {
|
|
|
|
|
$reqArray["{$type}from"] = $reqArray["from"];
|
|
|
|
|
}
|
|
|
|
|
if ( !isset( $reqArray["{$type}to"] ) && isset( $reqArray["to"] ) ) {
|
|
|
|
|
$reqArray["{$type}to"] = $reqArray["to"];
|
|
|
|
|
}
|
2010-07-26 21:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-09 03:50:03 +00:00
|
|
|
unset( $reqArray["from"] );
|
|
|
|
|
unset( $reqArray["to"] );
|
|
|
|
|
|
2013-08-24 15:06:25 +00:00
|
|
|
$viewer = new $this->mCategoryViewerClass(
|
|
|
|
|
$this->getContext()->getTitle(),
|
|
|
|
|
$this->getContext(),
|
|
|
|
|
$from,
|
|
|
|
|
$until,
|
|
|
|
|
$reqArray
|
|
|
|
|
);
|
2015-03-04 23:25:56 +00:00
|
|
|
$out = $this->getContext()->getOutput();
|
|
|
|
|
$out->addHTML( $viewer->getHTML() );
|
2015-05-02 11:37:19 +00:00
|
|
|
$this->addHelpLink( 'Help:Categories' );
|
2004-08-22 09:42:12 +00:00
|
|
|
}
|
2017-07-30 20:28:19 +00:00
|
|
|
|
2020-05-17 16:28:19 +00:00
|
|
|
/**
|
|
|
|
|
* @deprecated since 1.35
|
|
|
|
|
*/
|
|
|
|
|
public function getCategoryViewerClass() {
|
|
|
|
|
wfDeprecated( __METHOD__, '1.35' );
|
2017-07-30 20:28:19 +00:00
|
|
|
return $this->mCategoryViewerClass;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-17 16:28:19 +00:00
|
|
|
/**
|
|
|
|
|
* @deprecated since 1.35
|
|
|
|
|
*/
|
|
|
|
|
public function setCategoryViewerClass( $class ) {
|
|
|
|
|
wfDeprecated( __METHOD__, '1.35' );
|
2017-07-30 20:28:19 +00:00
|
|
|
$this->mCategoryViewerClass = $class;
|
|
|
|
|
}
|
2006-08-24 17:03:39 +00:00
|
|
|
}
|