2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2010-06-21 12:59:04 +00:00
|
|
|
/**
|
2010-08-15 07:16:58 +00:00
|
|
|
* Implements Special:Recentchangeslinked
|
2010-06-21 12:59: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.,
|
2010-06-21 13:16:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-06-21 12:59:04 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-15 07:16:58 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup SpecialPage
|
2010-06-21 12:59:04 +00:00
|
|
|
*/
|
2008-06-26 19:12:52 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2004-09-03 15:23:37 +00:00
|
|
|
* This is to display changes made to all articles linked in an article.
|
2010-08-15 07:16:58 +00:00
|
|
|
*
|
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
|
|
|
* @ingroup SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2013-12-18 16:02:33 +00:00
|
|
|
class SpecialRecentChangesLinked extends SpecialRecentChanges {
|
2014-03-12 11:50:43 +00:00
|
|
|
/** @var bool|Title */
|
|
|
|
|
protected $rclTargetTitle;
|
2004-09-02 23:28:24 +00:00
|
|
|
|
2013-01-26 18:15:35 +00:00
|
|
|
function __construct() {
|
2010-07-17 19:04:07 +00:00
|
|
|
parent::__construct( 'Recentchangeslinked' );
|
2004-03-11 09:06:13 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-06-26 19:12:52 +00:00
|
|
|
public function getDefaultOptions() {
|
|
|
|
|
$opts = parent::getDefaultOptions();
|
|
|
|
|
$opts->add( 'target', '' );
|
|
|
|
|
$opts->add( 'showlinkedto', false );
|
2014-03-22 22:51:18 +00:00
|
|
|
|
2008-06-26 19:12:52 +00:00
|
|
|
return $opts;
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2008-06-26 19:12:52 +00:00
|
|
|
public function parseParameters( $par, FormOptions $opts ) {
|
|
|
|
|
$opts['target'] = $par;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2008-06-26 19:12:52 +00:00
|
|
|
|
|
|
|
|
public function doMainQuery( $conds, $opts ) {
|
2008-06-27 11:43:39 +00:00
|
|
|
$target = $opts['target'];
|
2008-06-26 19:12:52 +00:00
|
|
|
$showlinkedto = $opts['showlinkedto'];
|
|
|
|
|
$limit = $opts['limit'];
|
|
|
|
|
|
|
|
|
|
if ( $target === '' ) {
|
|
|
|
|
return false;
|
2008-04-13 15:27:26 +00:00
|
|
|
}
|
2012-01-22 00:58:47 +00:00
|
|
|
$outputPage = $this->getOutput();
|
2015-12-11 21:50:55 +00:00
|
|
|
$title = Title::newFromText( $target );
|
2014-01-02 10:59:10 +00:00
|
|
|
if ( !$title || $title->isExternal() ) {
|
2014-03-12 11:50:43 +00:00
|
|
|
$outputPage->addHtml( '<div class="errorbox">' . $this->msg( 'allpagesbadtitle' )
|
|
|
|
|
->parse() . '</div>' );
|
2014-03-22 22:51:18 +00:00
|
|
|
|
2008-06-26 19:12:52 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-22 00:58:47 +00:00
|
|
|
$outputPage->setPageTitle( $this->msg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
|
2008-06-27 11:43:39 +00:00
|
|
|
|
2008-07-22 22:37:55 +00:00
|
|
|
/*
|
|
|
|
|
* Ordinary links are in the pagelinks table, while transclusions are
|
|
|
|
|
* in the templatelinks table, categorizations in categorylinks and
|
|
|
|
|
* image use in imagelinks. We need to somehow combine all these.
|
|
|
|
|
* Special:Whatlinkshere does this by firing multiple queries and
|
|
|
|
|
* merging the results, but the code we inherit from our parent class
|
|
|
|
|
* expects only one result set so we use UNION instead.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-06-26 19:12:52 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE, 'recentchangeslinked' );
|
2012-03-11 18:54:55 +00:00
|
|
|
$id = $title->getArticleID();
|
2008-07-22 22:37:55 +00:00
|
|
|
$ns = $title->getNamespace();
|
|
|
|
|
$dbkey = $title->getDBkey();
|
2008-06-26 19:12:52 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$tables = [ 'recentchanges' ];
|
2012-11-08 18:25:59 +00:00
|
|
|
$select = RecentChange::selectFields();
|
2016-02-17 09:09:32 +00:00
|
|
|
$join_conds = [];
|
|
|
|
|
$query_options = [];
|
2008-06-26 19:12:52 +00:00
|
|
|
|
2008-07-22 22:37:55 +00:00
|
|
|
// left join with watchlist table to highlight watched rows
|
2011-07-17 09:25:50 +00:00
|
|
|
$uid = $this->getUser()->getId();
|
2013-06-13 18:02:55 +00:00
|
|
|
if ( $uid && $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
|
2008-07-22 22:37:55 +00:00
|
|
|
$tables[] = 'watchlist';
|
|
|
|
|
$select[] = 'wl_user';
|
2016-02-17 09:09:32 +00:00
|
|
|
$join_conds['watchlist'] = [ 'LEFT JOIN', [
|
2013-01-19 11:20:37 +00:00
|
|
|
'wl_user' => $uid,
|
|
|
|
|
'wl_title=rc_title',
|
|
|
|
|
'wl_namespace=rc_namespace'
|
2016-02-17 09:09:32 +00:00
|
|
|
] ];
|
2008-07-22 22:37:55 +00:00
|
|
|
}
|
2011-07-17 09:25:50 +00:00
|
|
|
if ( $this->getUser()->isAllowed( 'rollback' ) ) {
|
2009-08-08 20:47:11 +00:00
|
|
|
$tables[] = 'page';
|
2016-02-17 09:09:32 +00:00
|
|
|
$join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
|
2009-08-08 20:47:11 +00:00
|
|
|
$select[] = 'page_latest';
|
|
|
|
|
}
|
2012-08-04 20:20:00 +00:00
|
|
|
ChangeTags::modifyDisplayQuery(
|
|
|
|
|
$tables,
|
|
|
|
|
$select,
|
|
|
|
|
$conds,
|
|
|
|
|
$join_conds,
|
|
|
|
|
$query_options,
|
|
|
|
|
$opts['tagfilter']
|
|
|
|
|
);
|
2009-01-28 19:08:18 +00:00
|
|
|
|
2014-08-01 15:13:18 +00:00
|
|
|
if ( !$this->runMainQueryHook( $tables, $select, $conds, $query_options, $join_conds,
|
|
|
|
|
$opts )
|
2014-03-12 11:50:43 +00:00
|
|
|
) {
|
2010-08-06 13:07:46 +00:00
|
|
|
return false;
|
2012-01-22 00:58:47 +00:00
|
|
|
}
|
2008-07-22 22:37:55 +00:00
|
|
|
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $ns == NS_CATEGORY && !$showlinkedto ) {
|
2008-07-22 22:37:55 +00:00
|
|
|
// special handling for categories
|
2013-03-13 07:42:41 +00:00
|
|
|
// XXX: should try to make this less kludgy
|
2016-02-17 09:09:32 +00:00
|
|
|
$link_tables = [ 'categorylinks' ];
|
2008-07-22 22:37:55 +00:00
|
|
|
$showlinkedto = true;
|
2008-06-26 19:12:52 +00:00
|
|
|
} else {
|
2008-07-22 22:37:55 +00:00
|
|
|
// for now, always join on these tables; really should be configurable as in whatlinkshere
|
2016-02-17 09:09:32 +00:00
|
|
|
$link_tables = [ 'pagelinks', 'templatelinks' ];
|
2008-12-01 17:14:30 +00:00
|
|
|
// imagelinks only contains links to pages in NS_FILE
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $ns == NS_FILE || !$showlinkedto ) {
|
2012-01-22 00:58:47 +00:00
|
|
|
$link_tables[] = 'imagelinks';
|
|
|
|
|
}
|
2008-07-22 22:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $id == 0 && !$showlinkedto ) {
|
2008-09-14 04:28:16 +00:00
|
|
|
return false; // nonexistent pages can't link to any pages
|
2012-01-22 00:58:47 +00:00
|
|
|
}
|
2008-09-14 04:28:16 +00:00
|
|
|
|
2008-07-22 22:37:55 +00:00
|
|
|
// field name prefixes for all the various tables we might want to join with
|
2016-02-17 09:09:32 +00:00
|
|
|
$prefix = [
|
2014-03-12 11:50:43 +00:00
|
|
|
'pagelinks' => 'pl',
|
|
|
|
|
'templatelinks' => 'tl',
|
|
|
|
|
'categorylinks' => 'cl',
|
|
|
|
|
'imagelinks' => 'il'
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2008-07-22 22:37:55 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$subsql = []; // SELECT statements to combine with UNION
|
2008-07-22 22:37:55 +00:00
|
|
|
|
2013-04-19 20:55:47 +00:00
|
|
|
foreach ( $link_tables as $link_table ) {
|
2008-07-22 22:37:55 +00:00
|
|
|
$pfx = $prefix[$link_table];
|
|
|
|
|
|
2014-03-12 11:50:43 +00:00
|
|
|
// imagelinks and categorylinks tables have no xx_namespace field,
|
|
|
|
|
// and have xx_to instead of xx_title
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $link_table == 'imagelinks' ) {
|
2012-01-22 00:58:47 +00:00
|
|
|
$link_ns = NS_FILE;
|
2013-04-19 20:55:47 +00:00
|
|
|
} elseif ( $link_table == 'categorylinks' ) {
|
2012-01-22 00:58:47 +00:00
|
|
|
$link_ns = NS_CATEGORY;
|
|
|
|
|
} else {
|
|
|
|
|
$link_ns = 0;
|
|
|
|
|
}
|
2008-07-22 22:37:55 +00:00
|
|
|
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $showlinkedto ) {
|
2008-07-22 22:37:55 +00:00
|
|
|
// find changes to pages linking to this page
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $link_ns ) {
|
|
|
|
|
if ( $ns != $link_ns ) {
|
2012-01-22 00:58:47 +00:00
|
|
|
continue;
|
|
|
|
|
} // should never happen, but check anyway
|
2016-02-17 09:09:32 +00:00
|
|
|
$subconds = [ "{$pfx}_to" => $dbkey ];
|
2008-06-26 19:12:52 +00:00
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$subconds = [ "{$pfx}_namespace" => $ns, "{$pfx}_title" => $dbkey ];
|
2008-06-26 19:12:52 +00:00
|
|
|
}
|
2008-07-22 22:37:55 +00:00
|
|
|
$subjoin = "rc_cur_id = {$pfx}_from";
|
2008-06-26 19:12:52 +00:00
|
|
|
} else {
|
2008-07-22 22:37:55 +00:00
|
|
|
// find changes to pages linked from this page
|
2016-02-17 09:09:32 +00:00
|
|
|
$subconds = [ "{$pfx}_from" => $id ];
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $link_table == 'imagelinks' || $link_table == 'categorylinks' ) {
|
2008-07-22 22:37:55 +00:00
|
|
|
$subconds["rc_namespace"] = $link_ns;
|
|
|
|
|
$subjoin = "rc_title = {$pfx}_to";
|
|
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$subjoin = [ "rc_namespace = {$pfx}_namespace", "rc_title = {$pfx}_title" ];
|
2008-07-22 22:37:55 +00:00
|
|
|
}
|
2008-05-16 21:34:46 +00:00
|
|
|
}
|
2008-07-22 22:37:55 +00:00
|
|
|
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $dbr->unionSupportsOrderAndLimit() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$order = [ 'ORDER BY' => 'rc_timestamp DESC' ];
|
2012-01-22 00:58:47 +00:00
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$order = [];
|
2012-01-22 00:58:47 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
|
|
|
|
$query = $dbr->selectSQLText(
|
2016-02-17 09:09:32 +00:00
|
|
|
array_merge( $tables, [ $link_table ] ),
|
2011-03-18 20:37:11 +00:00
|
|
|
$select,
|
2009-01-17 18:44:28 +00:00
|
|
|
$conds + $subconds,
|
2011-03-18 20:37:11 +00:00
|
|
|
__METHOD__,
|
2009-10-17 12:23:23 +00:00
|
|
|
$order + $query_options,
|
2016-02-17 09:09:32 +00:00
|
|
|
$join_conds + [ $link_table => [ 'INNER JOIN', $subjoin ] ]
|
2009-01-17 18:44:28 +00:00
|
|
|
);
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $dbr->unionSupportsOrderAndLimit() ) {
|
2009-10-17 12:23:23 +00:00
|
|
|
$query = $dbr->limitResult( $query, $limit );
|
2013-04-19 20:55:47 +00:00
|
|
|
}
|
2009-10-17 12:23:23 +00:00
|
|
|
|
|
|
|
|
$subsql[] = $query;
|
2008-05-16 21:34:46 +00:00
|
|
|
}
|
2008-06-17 08:24:00 +00:00
|
|
|
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( count( $subsql ) == 0 ) {
|
2008-07-22 22:37:55 +00:00
|
|
|
return false; // should never happen
|
2012-01-22 00:58:47 +00:00
|
|
|
}
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( count( $subsql ) == 1 && $dbr->unionSupportsOrderAndLimit() ) {
|
2008-07-22 22:37:55 +00:00
|
|
|
$sql = $subsql[0];
|
2012-01-22 00:58:47 +00:00
|
|
|
} else {
|
2008-07-22 22:37:55 +00:00
|
|
|
// need to resort and relimit after union
|
2013-01-28 21:11:10 +00:00
|
|
|
$sql = $dbr->unionQueries( $subsql, false ) . ' ORDER BY rc_timestamp DESC';
|
|
|
|
|
$sql = $dbr->limitResult( $sql, $limit, false );
|
2008-06-26 19:12:52 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2008-07-22 22:37:55 +00:00
|
|
|
$res = $dbr->query( $sql, __METHOD__ );
|
2008-06-26 19:12:52 +00:00
|
|
|
|
2013-04-19 20:55:47 +00:00
|
|
|
if ( $res->numRows() == 0 ) {
|
2008-06-26 19:12:52 +00:00
|
|
|
$this->mResultEmpty = true;
|
2012-01-22 00:58:47 +00:00
|
|
|
}
|
2008-06-26 19:12:52 +00:00
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2013-12-22 02:17:34 +00:00
|
|
|
function setTopText( FormOptions $opts ) {
|
|
|
|
|
$target = $this->getTargetTitle();
|
|
|
|
|
if ( $target ) {
|
|
|
|
|
$this->getOutput()->addBacklinkSubtitle( $target );
|
2014-08-03 19:29:54 +00:00
|
|
|
$this->getSkin()->setRelevantTitle( $target );
|
2013-12-22 02:17:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-22 00:58:47 +00:00
|
|
|
/**
|
2013-05-20 12:00:52 +00:00
|
|
|
* Get options to be displayed in a form
|
|
|
|
|
*
|
|
|
|
|
* @param FormOptions $opts
|
2012-01-22 00:58:47 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
2013-01-26 18:15:35 +00:00
|
|
|
function getExtraOptions( $opts ) {
|
2013-05-20 12:00:52 +00:00
|
|
|
$extraOpts = parent::getExtraOptions( $opts );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$opts->consumeValues( [ 'showlinkedto', 'target' ] );
|
2013-05-20 12:00:52 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$extraOpts['target'] = [ $this->msg( 'recentchangeslinked-page' )->escaped(),
|
2013-01-26 18:15:35 +00:00
|
|
|
Xml::input( 'target', 40, str_replace( '_', ' ', $opts['target'] ) ) .
|
2016-02-17 09:09:32 +00:00
|
|
|
Xml::check( 'showlinkedto', $opts['showlinkedto'], [ 'id' => 'showlinkedto' ] ) . ' ' .
|
|
|
|
|
Xml::label( $this->msg( 'recentchangeslinked-to' )->text(), 'showlinkedto' ) ];
|
2013-05-20 12:00:52 +00:00
|
|
|
|
2015-03-04 23:58:14 +00:00
|
|
|
$this->addHelpLink( 'Help:Related changes' );
|
2008-06-26 19:12:52 +00:00
|
|
|
return $extraOpts;
|
2008-05-16 21:34:46 +00:00
|
|
|
}
|
2008-08-06 12:49:16 +00:00
|
|
|
|
2011-05-26 19:21:50 +00:00
|
|
|
/**
|
|
|
|
|
* @return Title
|
|
|
|
|
*/
|
2010-02-10 04:13:43 +00:00
|
|
|
function getTargetTitle() {
|
|
|
|
|
if ( $this->rclTargetTitle === null ) {
|
|
|
|
|
$opts = $this->getOptions();
|
|
|
|
|
if ( isset( $opts['target'] ) && $opts['target'] !== '' ) {
|
|
|
|
|
$this->rclTargetTitle = Title::newFromText( $opts['target'] );
|
|
|
|
|
} else {
|
|
|
|
|
$this->rclTargetTitle = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-22 22:51:18 +00:00
|
|
|
|
2010-02-10 04:13:43 +00:00
|
|
|
return $this->rclTargetTitle;
|
|
|
|
|
}
|
2015-12-06 15:06:01 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return an array of subpages beginning with $search that this special page will accept.
|
|
|
|
|
*
|
|
|
|
|
* @param string $search Prefix to search for
|
|
|
|
|
* @param int $limit Maximum number of results to return (usually 10)
|
|
|
|
|
* @param int $offset Number of results to skip (usually 0)
|
|
|
|
|
* @return string[] Matching subpages
|
|
|
|
|
*/
|
|
|
|
|
public function prefixSearchSubpages( $search, $limit, $offset ) {
|
2016-01-26 21:18:27 +00:00
|
|
|
return $this->prefixSearchString( $search, $limit, $offset );
|
2015-12-06 15:06:01 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|