2003-12-21 12:01:29 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2011-08-07 14:29:28 +00:00
|
|
|
* Page history
|
2011-08-06 19:41:49 +00:00
|
|
|
*
|
2012-06-05 22:58:54 +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
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
2013-03-05 15:39:35 +00:00
|
|
|
* @ingroup Actions
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
|
|
|
|
|
2016-11-30 01:07:37 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2017-02-19 05:03:13 +00:00
|
|
|
use Wikimedia\Rdbms\FakeResultWrapper;
|
2020-01-10 00:00:51 +00:00
|
|
|
use Wikimedia\Rdbms\IResultWrapper;
|
2016-11-30 01:07:37 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2013-02-03 18:47:42 +00:00
|
|
|
* This class handles printing the history page for an article. In order to
|
2005-06-29 03:37:57 +00:00
|
|
|
* be efficient, it uses timestamps rather than offsets for paging, to avoid
|
|
|
|
|
* costly LIMIT,offset queries.
|
2011-08-07 14:29:28 +00:00
|
|
|
*
|
|
|
|
|
* Construct it by passing in an Article, and call $h->history() to print the
|
|
|
|
|
* history.
|
|
|
|
|
*
|
2013-03-05 15:39:35 +00:00
|
|
|
* @ingroup Actions
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2011-10-23 09:21:02 +00:00
|
|
|
class HistoryAction extends FormlessAction {
|
2006-06-06 12:28:44 +00:00
|
|
|
const DIR_PREV = 0;
|
|
|
|
|
const DIR_NEXT = 1;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2013-11-14 12:08:14 +00:00
|
|
|
/** @var array Array of message keys and strings */
|
|
|
|
|
public $message;
|
|
|
|
|
|
2011-10-23 09:21:02 +00:00
|
|
|
public function getName() {
|
|
|
|
|
return 'history';
|
|
|
|
|
}
|
2005-06-29 03:37:57 +00:00
|
|
|
|
2011-10-23 09:21:02 +00:00
|
|
|
public function requiresWrite() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function requiresUnblock() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getPageTitle() {
|
|
|
|
|
return $this->msg( 'history-title', $this->getTitle()->getPrefixedText() )->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getDescription() {
|
|
|
|
|
// Creation of a subtitle link pointing to [[Special:Log]]
|
2014-03-25 16:01:51 +00:00
|
|
|
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
|
|
|
|
|
$subtitle = $linkRenderer->makeKnownLink(
|
2011-10-23 09:21:02 +00:00
|
|
|
SpecialPage::getTitleFor( 'Log' ),
|
2016-11-30 01:07:37 +00:00
|
|
|
$this->msg( 'viewpagelogs' )->text(),
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
|
|
|
|
[ 'page' => $this->getTitle()->getPrefixedText() ]
|
2011-10-23 09:21:02 +00:00
|
|
|
);
|
2014-03-25 16:01:51 +00:00
|
|
|
|
|
|
|
|
$links = [];
|
|
|
|
|
// Allow extensions to add more links
|
|
|
|
|
Hooks::run( 'HistoryPageToolLinks', [ $this->getContext(), $linkRenderer, &$links ] );
|
|
|
|
|
if ( $links ) {
|
|
|
|
|
$subtitle .= ''
|
|
|
|
|
. $this->msg( 'word-separator' )->escaped()
|
|
|
|
|
. $this->msg( 'parentheses' )
|
|
|
|
|
->rawParams( $this->getLanguage()->pipeList( $links ) )
|
|
|
|
|
->escaped();
|
|
|
|
|
}
|
2019-03-28 20:14:49 +00:00
|
|
|
return Html::rawElement( 'div', [ 'class' => 'mw-history-subtitle' ], $subtitle );
|
2011-08-07 14:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
2008-03-09 02:27:03 +00:00
|
|
|
/**
|
|
|
|
|
* As we use the same small set of messages in various methods and that
|
|
|
|
|
* they are called often, we call them once and save them in $this->message
|
|
|
|
|
*/
|
2010-11-15 20:13:58 +00:00
|
|
|
private function preCacheMessages() {
|
2008-03-09 02:27:03 +00:00
|
|
|
// Precache various messages
|
2010-11-15 19:51:47 +00:00
|
|
|
if ( !isset( $this->message ) ) {
|
2019-09-01 14:00:35 +00:00
|
|
|
$this->message = [];
|
2016-02-17 09:09:32 +00:00
|
|
|
$msgs = [ 'cur', 'last', 'pipe-separator' ];
|
2010-11-15 19:51:47 +00:00
|
|
|
foreach ( $msgs as $msg ) {
|
2011-10-23 09:21:02 +00:00
|
|
|
$this->message[$msg] = $this->msg( $msg )->escaped();
|
2008-03-09 02:27:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-12-21 12:01:29 +00:00
|
|
|
}
|
2004-08-28 18:54:23 +00:00
|
|
|
|
2019-03-26 22:52:13 +00:00
|
|
|
/**
|
|
|
|
|
* @param WebRequest $request
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function getTimestampFromRequest( WebRequest $request ) {
|
|
|
|
|
// Backwards compatibility checks for URIs with only year and/or month.
|
|
|
|
|
$year = $request->getInt( 'year' );
|
|
|
|
|
$month = $request->getInt( 'month' );
|
|
|
|
|
$day = null;
|
|
|
|
|
if ( $year !== 0 || $month !== 0 ) {
|
|
|
|
|
if ( $year === 0 ) {
|
|
|
|
|
$year = MWTimestamp::getLocalInstance()->format( 'Y' );
|
|
|
|
|
}
|
|
|
|
|
if ( $month < 1 || $month > 12 ) {
|
|
|
|
|
// month is invalid so treat as December (all months)
|
|
|
|
|
$month = 12;
|
|
|
|
|
}
|
|
|
|
|
// month is valid so check day
|
|
|
|
|
$day = cal_days_in_month( CAL_GREGORIAN, $month, $year );
|
|
|
|
|
|
|
|
|
|
// Left pad the months and days
|
|
|
|
|
$month = str_pad( $month, 2, "0", STR_PAD_LEFT );
|
|
|
|
|
$day = str_pad( $day, 2, "0", STR_PAD_LEFT );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$before = $request->getVal( 'date-range-to' );
|
|
|
|
|
if ( $before ) {
|
|
|
|
|
$parts = explode( '-', $before );
|
|
|
|
|
$year = $parts[0];
|
|
|
|
|
// check date input is valid
|
|
|
|
|
if ( count( $parts ) === 3 ) {
|
|
|
|
|
$month = $parts[1];
|
|
|
|
|
$day = $parts[2];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $year && $month && $day ? $year . '-' . $month . '-' . $day : '';
|
|
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2005-06-29 03:37:57 +00:00
|
|
|
/**
|
|
|
|
|
* Print the history page for an article.
|
2019-06-18 19:10:39 +00:00
|
|
|
* @return string|null
|
2005-06-29 03:37:57 +00:00
|
|
|
*/
|
2011-10-23 09:21:02 +00:00
|
|
|
function onView() {
|
2011-09-29 21:20:51 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
|
$request = $this->getRequest();
|
2003-12-21 12:01:29 +00:00
|
|
|
|
2019-05-09 00:21:36 +00:00
|
|
|
// Allow client-side HTTP caching of the history page.
|
|
|
|
|
// But, always ignore this cache if the (logged-in) user has this page on their watchlist
|
|
|
|
|
// and has one or more unseen revisions. Otherwise, we might be showing stale update markers.
|
|
|
|
|
// The Last-Modified for the history page does not change when user's markers are cleared,
|
|
|
|
|
// so going from "some unseen" to "all seen" would not clear the cache.
|
|
|
|
|
// But, when all of the revisions are marked as seen, then only way for new unseen revision
|
|
|
|
|
// markers to appear, is for the page to be edited, which updates page_touched/Last-Modified.
|
|
|
|
|
if (
|
|
|
|
|
!$this->hasUnseenRevisionMarkers() &&
|
2020-03-26 00:43:50 +00:00
|
|
|
$out->checkLastModified( $this->getWikiPage()->getTouched() )
|
2019-05-09 00:21:36 +00:00
|
|
|
) {
|
2019-06-18 19:10:39 +00:00
|
|
|
return null; // Client cache fresh and headers sent, nothing more to do.
|
2011-09-24 01:17:04 +00:00
|
|
|
}
|
2005-06-29 03:37:57 +00:00
|
|
|
|
2011-10-23 09:21:02 +00:00
|
|
|
$this->preCacheMessages();
|
2014-07-30 17:56:25 +00:00
|
|
|
$config = $this->context->getConfig();
|
2011-10-23 09:21:02 +00:00
|
|
|
|
2011-09-24 01:17:04 +00:00
|
|
|
# Fill in the file cache if not set already
|
2016-09-14 20:36:34 +00:00
|
|
|
if ( HTMLFileCache::useFileCache( $this->getContext() ) ) {
|
2014-09-15 22:47:30 +00:00
|
|
|
$cache = new HTMLFileCache( $this->getTitle(), 'history' );
|
2011-09-29 08:18:20 +00:00
|
|
|
if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
ob_start( [ &$cache, 'saveToFileCache' ] );
|
2011-09-24 01:17:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-15 20:13:58 +00:00
|
|
|
// Setup page variables.
|
2011-09-29 21:20:51 +00:00
|
|
|
$out->setFeedAppendQuery( 'action=history' );
|
2013-08-09 22:25:20 +00:00
|
|
|
$out->addModules( 'mediawiki.action.history' );
|
2016-07-07 05:22:14 +00:00
|
|
|
$out->addModuleStyles( [
|
2019-01-09 00:30:18 +00:00
|
|
|
'mediawiki.interface.helpers.styles',
|
2016-07-07 05:22:14 +00:00
|
|
|
'mediawiki.action.history.styles',
|
|
|
|
|
'mediawiki.special.changeslist',
|
|
|
|
|
] );
|
2014-07-30 17:56:25 +00:00
|
|
|
if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
|
|
|
|
|
$out = $this->getOutput();
|
2016-02-17 09:09:32 +00:00
|
|
|
$out->addModuleStyles( [
|
2014-07-30 17:56:25 +00:00
|
|
|
'mediawiki.ui.input',
|
|
|
|
|
'mediawiki.ui.checkbox',
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2014-07-30 17:56:25 +00:00
|
|
|
}
|
2006-05-28 03:47:28 +00:00
|
|
|
|
2010-11-15 20:13:58 +00:00
|
|
|
// Handle atom/RSS feeds.
|
2019-04-13 22:43:14 +00:00
|
|
|
$feedType = $request->getRawVal( 'feed' );
|
|
|
|
|
if ( $feedType !== null ) {
|
2012-02-09 18:01:54 +00:00
|
|
|
$this->feed( $feedType );
|
2019-06-18 19:10:39 +00:00
|
|
|
return null;
|
2006-05-28 03:47:28 +00:00
|
|
|
}
|
2003-12-21 12:01:29 +00:00
|
|
|
|
2019-05-17 05:16:16 +00:00
|
|
|
$this->addHelpLink(
|
|
|
|
|
'https://meta.wikimedia.org/wiki/Special:MyLanguage/Help:Page_history',
|
|
|
|
|
true
|
|
|
|
|
);
|
2016-01-27 12:10:23 +00:00
|
|
|
|
2010-11-15 20:13:58 +00:00
|
|
|
// Fail nicely if article doesn't exist.
|
2020-03-26 00:43:50 +00:00
|
|
|
if ( !$this->getWikiPage()->exists() ) {
|
2016-09-23 20:07:31 +00:00
|
|
|
global $wgSend404Code;
|
|
|
|
|
if ( $wgSend404Code ) {
|
|
|
|
|
$out->setStatusCode( 404 );
|
|
|
|
|
}
|
2011-09-29 21:20:51 +00:00
|
|
|
$out->addWikiMsg( 'nohistory' );
|
2017-02-22 17:55:56 +00:00
|
|
|
|
|
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
|
|
|
|
|
2009-09-16 17:17:16 +00:00
|
|
|
# show deletion/move log if there is an entry
|
2009-09-18 11:51:00 +00:00
|
|
|
LogEventsList::showLogExtract(
|
2011-09-29 21:20:51 +00:00
|
|
|
$out,
|
2017-09-03 17:03:28 +00:00
|
|
|
[ 'delete', 'move', 'protect' ],
|
2011-09-29 21:20:51 +00:00
|
|
|
$this->getTitle(),
|
2009-09-18 11:51:00 +00:00
|
|
|
'',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'lim' => 10,
|
2017-02-22 17:55:56 +00:00
|
|
|
'conds' => [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ],
|
2009-09-16 17:17:16 +00:00
|
|
|
'showIfEmpty' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
'msgKey' => [ 'moveddeleted-notice' ]
|
|
|
|
|
]
|
2009-09-16 17:17:16 +00:00
|
|
|
);
|
2013-11-14 11:18:26 +00:00
|
|
|
|
2019-06-18 19:10:39 +00:00
|
|
|
return null;
|
2003-12-21 12:01:29 +00:00
|
|
|
}
|
2004-08-28 18:54:23 +00:00
|
|
|
|
2019-03-26 22:52:13 +00:00
|
|
|
$ts = $this->getTimestampFromRequest( $request );
|
2013-03-07 16:50:43 +00:00
|
|
|
$tagFilter = $request->getVal( 'tagfilter' );
|
2010-11-15 20:13:58 +00:00
|
|
|
|
2009-10-26 18:45:27 +00:00
|
|
|
/**
|
|
|
|
|
* Option to show only revisions that have been (partially) hidden via RevisionDelete
|
|
|
|
|
*/
|
2011-09-29 21:20:51 +00:00
|
|
|
if ( $request->getBool( 'deleted' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$conds = [ 'rev_deleted != 0' ];
|
2010-02-09 01:17:01 +00:00
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$conds = [];
|
2009-10-26 18:45:27 +00:00
|
|
|
}
|
2019-03-26 22:52:13 +00:00
|
|
|
|
|
|
|
|
// Add the general form.
|
|
|
|
|
$fields = [
|
|
|
|
|
[
|
|
|
|
|
'name' => 'title',
|
|
|
|
|
'type' => 'hidden',
|
|
|
|
|
'default' => $this->getTitle()->getPrefixedDBkey(),
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'name' => 'action',
|
|
|
|
|
'type' => 'hidden',
|
|
|
|
|
'default' => 'history',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'type' => 'date',
|
|
|
|
|
'default' => $ts,
|
|
|
|
|
'label' => $this->msg( 'date-range-to' )->text(),
|
|
|
|
|
'name' => 'date-range-to',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'label-raw' => $this->msg( 'tag-filter' )->parse(),
|
|
|
|
|
'type' => 'tagfilter',
|
|
|
|
|
'id' => 'tagfilter',
|
|
|
|
|
'name' => 'tagfilter',
|
|
|
|
|
'value' => $tagFilter,
|
|
|
|
|
]
|
|
|
|
|
];
|
2019-08-16 18:13:56 +00:00
|
|
|
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
|
|
|
|
|
if ( $permissionManager->userHasRight( $this->getUser(), 'deletedhistory' ) ) {
|
2019-03-26 22:52:13 +00:00
|
|
|
$fields[] = [
|
|
|
|
|
'type' => 'check',
|
|
|
|
|
'label' => $this->msg( 'history-show-deleted' )->text(),
|
|
|
|
|
'default' => $request->getBool( 'deleted' ),
|
|
|
|
|
'name' => 'deleted',
|
|
|
|
|
];
|
2012-10-13 14:05:00 +00:00
|
|
|
}
|
2008-08-21 00:45:13 +00:00
|
|
|
|
2019-03-26 22:52:13 +00:00
|
|
|
$out->enableOOUI();
|
|
|
|
|
$htmlForm = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
|
|
|
|
|
$htmlForm
|
|
|
|
|
->setMethod( 'get' )
|
2019-03-29 12:26:30 +00:00
|
|
|
->setAction( wfScript() )
|
2019-04-15 23:53:55 +00:00
|
|
|
->setCollapsibleOptions( true )
|
2019-03-26 22:52:13 +00:00
|
|
|
->setId( 'mw-history-searchform' )
|
|
|
|
|
->setSubmitText( $this->msg( 'historyaction-submit' )->text() )
|
2019-03-27 22:52:29 +00:00
|
|
|
->setWrapperAttributes( [ 'id' => 'mw-history-search' ] )
|
2019-03-26 22:52:13 +00:00
|
|
|
->setWrapperLegend( $this->msg( 'history-fieldset-title' )->text() );
|
|
|
|
|
$htmlForm->loadData();
|
|
|
|
|
|
|
|
|
|
$out->addHTML( $htmlForm->getHTML( false ) );
|
2007-12-04 11:12:10 +00:00
|
|
|
|
2020-03-27 13:28:27 +00:00
|
|
|
$article = $this->getArticle(); // must be a variable for hook reference
|
2020-03-26 00:43:50 +00:00
|
|
|
Hooks::run(
|
|
|
|
|
'PageHistoryBeforeList',
|
|
|
|
|
[
|
2020-03-27 13:28:27 +00:00
|
|
|
&$article,
|
2020-03-26 00:43:50 +00:00
|
|
|
$this->getContext()
|
|
|
|
|
]
|
|
|
|
|
);
|
2005-06-29 00:23:42 +00:00
|
|
|
|
2010-11-15 20:13:58 +00:00
|
|
|
// Create and output the list.
|
2019-03-26 22:52:13 +00:00
|
|
|
$dateComponents = explode( '-', $ts );
|
|
|
|
|
if ( count( $dateComponents ) > 1 ) {
|
|
|
|
|
$y = $dateComponents[0];
|
|
|
|
|
$m = $dateComponents[1];
|
|
|
|
|
$d = $dateComponents[2];
|
|
|
|
|
} else {
|
|
|
|
|
$y = '';
|
|
|
|
|
$m = '';
|
|
|
|
|
$d = '';
|
|
|
|
|
}
|
|
|
|
|
$pager = new HistoryPager( $this, $y, $m, $tagFilter, $conds, $d );
|
2011-09-29 21:20:51 +00:00
|
|
|
$out->addHTML(
|
2008-04-14 07:45:50 +00:00
|
|
|
$pager->getNavigationBar() .
|
2006-11-19 17:16:34 +00:00
|
|
|
$pager->getBody() .
|
2006-07-07 17:11:47 +00:00
|
|
|
$pager->getNavigationBar()
|
2008-11-08 19:41:38 +00:00
|
|
|
);
|
2011-09-29 21:20:51 +00:00
|
|
|
$out->preventClickjacking( $pager->getPreventClickjacking() );
|
2019-06-18 19:10:39 +00:00
|
|
|
|
|
|
|
|
return null;
|
2003-12-21 12:01:29 +00:00
|
|
|
}
|
2008-08-21 00:45:13 +00:00
|
|
|
|
2019-05-09 00:21:36 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool Page is watched by and has unseen revision for the user
|
|
|
|
|
*/
|
|
|
|
|
private function hasUnseenRevisionMarkers() {
|
|
|
|
|
return (
|
|
|
|
|
$this->getContext()->getConfig()->get( 'ShowUpdatedMarker' ) &&
|
|
|
|
|
$this->getTitle()->getNotificationTimestamp( $this->getUser() )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-17 05:09:36 +00:00
|
|
|
/**
|
|
|
|
|
* Fetch an array of revisions, specified by a given limit, offset and
|
|
|
|
|
* direction. This is now only used by the feeds. It was previously
|
|
|
|
|
* used by the main UI but that's now handled by the pager.
|
2010-01-17 16:34:22 +00:00
|
|
|
*
|
2014-04-10 18:50:10 +00:00
|
|
|
* @param int $limit The limit number of revisions to get
|
|
|
|
|
* @param int $offset
|
2014-07-17 08:10:50 +00:00
|
|
|
* @param int $direction Either self::DIR_PREV or self::DIR_NEXT
|
2019-07-04 19:56:31 +00:00
|
|
|
* @return IResultWrapper
|
2009-08-17 05:09:36 +00:00
|
|
|
*/
|
2010-01-17 16:34:22 +00:00
|
|
|
function fetchRevisions( $limit, $offset, $direction ) {
|
2012-06-09 21:30:46 +00:00
|
|
|
// Fail if article doesn't exist.
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( !$this->getTitle()->exists() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return new FakeResultWrapper( [] );
|
2012-06-09 21:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-05 19:55:19 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2009-08-17 05:09:36 +00:00
|
|
|
|
2014-07-17 08:10:50 +00:00
|
|
|
if ( $direction === self::DIR_PREV ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
list( $dirs, $oper ) = [ "ASC", ">=" ];
|
2014-07-17 08:10:50 +00:00
|
|
|
} else { /* $direction === self::DIR_NEXT */
|
2016-02-17 09:09:32 +00:00
|
|
|
list( $dirs, $oper ) = [ "DESC", "<=" ];
|
2010-11-15 19:51:47 +00:00
|
|
|
}
|
2009-08-17 05:09:36 +00:00
|
|
|
|
2010-11-15 19:51:47 +00:00
|
|
|
if ( $offset ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
|
2010-11-15 19:51:47 +00:00
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$offsets = [];
|
2010-11-15 19:51:47 +00:00
|
|
|
}
|
2009-08-17 05:09:36 +00:00
|
|
|
|
2020-03-26 00:43:50 +00:00
|
|
|
$page_id = $this->getWikiPage()->getId();
|
2009-08-17 05:09:36 +00:00
|
|
|
|
2020-02-18 19:53:12 +00:00
|
|
|
$revQuery = MediaWikiServices::getInstance()->getRevisionStore()->getQueryInfo();
|
2017-10-06 17:03:55 +00:00
|
|
|
return $dbr->select(
|
|
|
|
|
$revQuery['tables'],
|
|
|
|
|
$revQuery['fields'],
|
2016-02-17 09:09:32 +00:00
|
|
|
array_merge( [ 'rev_page' => $page_id ], $offsets ),
|
2009-08-17 05:09:36 +00:00
|
|
|
__METHOD__,
|
2017-10-06 17:03:55 +00:00
|
|
|
[
|
|
|
|
|
'ORDER BY' => "rev_timestamp $dirs",
|
|
|
|
|
'USE INDEX' => [ 'revision' => 'page_timestamp' ],
|
|
|
|
|
'LIMIT' => $limit
|
|
|
|
|
],
|
|
|
|
|
$revQuery['joins']
|
2009-08-17 05:09:36 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Output a subscription feed listing recent edits to this page.
|
2010-01-17 16:34:22 +00:00
|
|
|
*
|
2014-07-24 17:42:45 +00:00
|
|
|
* @param string $type Feed type
|
2009-08-17 05:09:36 +00:00
|
|
|
*/
|
|
|
|
|
function feed( $type ) {
|
2010-11-15 19:51:47 +00:00
|
|
|
if ( !FeedUtils::checkFeedOutput( $type ) ) {
|
2009-08-17 05:09:36 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2011-09-29 21:20:51 +00:00
|
|
|
$request = $this->getRequest();
|
2009-08-17 05:09:36 +00:00
|
|
|
|
2014-08-13 02:45:55 +00:00
|
|
|
$feedClasses = $this->context->getConfig()->get( 'FeedClasses' );
|
2013-12-30 17:32:53 +00:00
|
|
|
/** @var RSSFeed|AtomFeed $feed */
|
2014-08-13 02:45:55 +00:00
|
|
|
$feed = new $feedClasses[$type](
|
2011-09-29 21:20:51 +00:00
|
|
|
$this->getTitle()->getPrefixedText() . ' - ' .
|
2012-08-19 06:58:23 +00:00
|
|
|
$this->msg( 'history-feed-title' )->inContentLanguage()->text(),
|
|
|
|
|
$this->msg( 'history-feed-description' )->inContentLanguage()->text(),
|
2013-03-27 13:36:05 +00:00
|
|
|
$this->getTitle()->getFullURL( 'action=history' )
|
2009-09-18 11:51:00 +00:00
|
|
|
);
|
2009-08-17 05:09:36 +00:00
|
|
|
|
|
|
|
|
// Get a limit on number of feed entries. Provide a sane default
|
|
|
|
|
// of 10 if none is defined (but limit to $wgFeedLimit max)
|
2011-09-29 21:20:51 +00:00
|
|
|
$limit = $request->getInt( 'limit', 10 );
|
2014-08-13 02:45:55 +00:00
|
|
|
$limit = min(
|
|
|
|
|
max( $limit, 1 ),
|
|
|
|
|
$this->context->getConfig()->get( 'FeedLimit' )
|
|
|
|
|
);
|
2013-07-07 18:39:53 +00:00
|
|
|
|
2014-07-17 08:10:50 +00:00
|
|
|
$items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT );
|
2009-08-17 05:09:36 +00:00
|
|
|
|
2010-11-15 20:13:58 +00:00
|
|
|
// Generate feed elements enclosed between header and footer.
|
2009-08-17 05:09:36 +00:00
|
|
|
$feed->outHeader();
|
2011-10-23 09:21:02 +00:00
|
|
|
if ( $items->numRows() ) {
|
2010-11-15 19:51:47 +00:00
|
|
|
foreach ( $items as $row ) {
|
2009-08-17 05:09:36 +00:00
|
|
|
$feed->outItem( $this->feedItem( $row ) );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$feed->outItem( $this->feedEmpty() );
|
|
|
|
|
}
|
|
|
|
|
$feed->outFooter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function feedEmpty() {
|
|
|
|
|
return new FeedItem(
|
2012-08-19 06:58:23 +00:00
|
|
|
$this->msg( 'nohistory' )->inContentLanguage()->text(),
|
|
|
|
|
$this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
|
2013-03-27 13:36:05 +00:00
|
|
|
$this->getTitle()->getFullURL(),
|
2009-08-17 05:09:36 +00:00
|
|
|
wfTimestamp( TS_MW ),
|
2009-09-14 16:38:35 +00:00
|
|
|
'',
|
2013-03-27 13:36:05 +00:00
|
|
|
$this->getTitle()->getTalkPage()->getFullURL()
|
2009-09-14 16:38:35 +00:00
|
|
|
);
|
2009-08-17 05:09:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generate a FeedItem object from a given revision table row
|
|
|
|
|
* Borrows Recent Changes' feed generation functions for formatting;
|
|
|
|
|
* includes a diff to the previous revision (if any).
|
|
|
|
|
*
|
2014-07-24 17:42:45 +00:00
|
|
|
* @param stdClass|array $row Database row
|
2009-08-17 05:09:36 +00:00
|
|
|
* @return FeedItem
|
|
|
|
|
*/
|
|
|
|
|
function feedItem( $row ) {
|
2019-08-27 02:45:33 +00:00
|
|
|
$revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
|
|
|
|
|
$rev = $revisionStore->newRevisionFromRow( $row, 0, $this->getTitle() );
|
|
|
|
|
$prevRev = $revisionStore->getPreviousRevision( $rev );
|
|
|
|
|
$revComment = $rev->getComment() === null ? null : $rev->getComment()->text;
|
2009-09-14 16:38:35 +00:00
|
|
|
$text = FeedUtils::formatDiffRow(
|
2011-09-29 21:20:51 +00:00
|
|
|
$this->getTitle(),
|
2019-08-27 02:45:33 +00:00
|
|
|
$prevRev ? $prevRev->getId() : false,
|
2009-09-14 16:38:35 +00:00
|
|
|
$rev->getId(),
|
|
|
|
|
$rev->getTimestamp(),
|
2019-08-27 02:45:33 +00:00
|
|
|
$revComment
|
2009-09-14 16:38:35 +00:00
|
|
|
);
|
2019-08-27 02:45:33 +00:00
|
|
|
$revUserText = $rev->getUser() ? $rev->getUser()->getName() : '';
|
|
|
|
|
if ( $revComment == '' ) {
|
2018-07-29 12:24:54 +00:00
|
|
|
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
|
2012-08-19 06:58:23 +00:00
|
|
|
$title = $this->msg( 'history-feed-item-nocomment',
|
2019-08-27 02:45:33 +00:00
|
|
|
$revUserText,
|
2018-07-29 12:24:54 +00:00
|
|
|
$contLang->timeanddate( $rev->getTimestamp() ),
|
|
|
|
|
$contLang->date( $rev->getTimestamp() ),
|
|
|
|
|
$contLang->time( $rev->getTimestamp() )
|
|
|
|
|
)->inContentLanguage()->text();
|
2009-08-17 05:09:36 +00:00
|
|
|
} else {
|
2019-08-27 02:45:33 +00:00
|
|
|
$title = $revUserText .
|
2013-11-14 11:18:26 +00:00
|
|
|
$this->msg( 'colon-separator' )->inContentLanguage()->text() .
|
2019-08-27 02:45:33 +00:00
|
|
|
FeedItem::stripComment( $revComment );
|
2009-08-17 05:09:36 +00:00
|
|
|
}
|
2013-11-14 11:18:26 +00:00
|
|
|
|
2009-08-17 05:09:36 +00:00
|
|
|
return new FeedItem(
|
|
|
|
|
$title,
|
|
|
|
|
$text,
|
2013-03-27 13:36:05 +00:00
|
|
|
$this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
|
2009-08-17 05:09:36 +00:00
|
|
|
$rev->getTimestamp(),
|
2019-08-27 02:45:33 +00:00
|
|
|
$revUserText,
|
2013-03-27 13:36:05 +00:00
|
|
|
$this->getTitle()->getTalkPage()->getFullURL()
|
2009-09-14 16:38:35 +00:00
|
|
|
);
|
2009-08-17 05:09:36 +00:00
|
|
|
}
|
|
|
|
|
}
|