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
|
|
|
*/
|
2010-08-21 19:54:25 +00:00
|
|
|
class SpecialRecentchangeslinked extends SpecialRecentChanges {
|
2010-02-10 04:13:43 +00:00
|
|
|
var $rclTargetTitle;
|
2004-09-02 23:28:24 +00:00
|
|
|
|
2008-06-26 19:12:52 +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 );
|
2009-01-28 19:08:18 +00:00
|
|
|
$opts->add( 'tagfilter', '' );
|
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
|
|
|
|
2009-01-17 18:44:28 +00:00
|
|
|
public function feedSetup() {
|
2008-06-26 19:12:52 +00:00
|
|
|
global $wgRequest;
|
|
|
|
|
$opts = parent::feedSetup();
|
|
|
|
|
$opts['target'] = $wgRequest->getVal( 'target' );
|
|
|
|
|
return $opts;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2008-06-26 19:12:52 +00:00
|
|
|
|
|
|
|
|
public function getFeedObject( $feedFormat ){
|
2008-06-17 08:24:00 +00:00
|
|
|
$feed = new ChangesFeed( $feedFormat, false );
|
2008-06-26 19:12:52 +00:00
|
|
|
$feedObj = $feed->getFeedObject(
|
2010-02-10 04:13:43 +00:00
|
|
|
wfMsgForContent( 'recentchangeslinked-title', $this->getTargetTitle()->getPrefixedText() ),
|
2011-02-17 19:26:38 +00:00
|
|
|
wfMsgForContent( 'recentchangeslinked-feed' ),
|
|
|
|
|
$this->getTitle()->getFullUrl()
|
2008-06-26 19:12:52 +00:00
|
|
|
);
|
|
|
|
|
return array( $feed, $feedObj );
|
2008-05-16 21:34:46 +00:00
|
|
|
}
|
2006-08-04 20:18:43 +00:00
|
|
|
|
2008-06-26 19:12:52 +00:00
|
|
|
public function doMainQuery( $conds, $opts ) {
|
|
|
|
|
global $wgUser, $wgOut;
|
|
|
|
|
|
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
|
|
|
}
|
2008-06-27 11:43:39 +00:00
|
|
|
$title = Title::newFromURL( $target );
|
|
|
|
|
if( !$title || $title->getInterwiki() != '' ){
|
2010-05-28 21:22:45 +00:00
|
|
|
$wgOut->wrapWikiMsg( "<div class=\"errorbox\">\n$1\n</div><br style=\"clear: both\" />", 'allpagesbadtitle' );
|
2008-06-26 19:12:52 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-27 11:43:39 +00:00
|
|
|
$wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
|
|
|
|
|
|
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' );
|
|
|
|
|
$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
|
|
|
|
|
|
|
|
$tables = array( 'recentchanges' );
|
|
|
|
|
$select = array( $dbr->tableName( 'recentchanges' ) . '.*' );
|
|
|
|
|
$join_conds = array();
|
2009-03-31 13:01:05 +00:00
|
|
|
$query_options = array();
|
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
|
2010-11-01 00:07:17 +00:00
|
|
|
$uid = $wgUser->getId();
|
|
|
|
|
if( $uid ) {
|
2008-07-22 22:37:55 +00:00
|
|
|
$tables[] = 'watchlist';
|
|
|
|
|
$select[] = 'wl_user';
|
|
|
|
|
$join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
|
|
|
|
|
}
|
2009-08-08 20:47:11 +00:00
|
|
|
if ( $wgUser->isAllowed( 'rollback' ) ) {
|
|
|
|
|
$tables[] = 'page';
|
|
|
|
|
$join_conds['page'] = array('LEFT JOIN', 'rc_cur_id=page_id');
|
|
|
|
|
$select[] = 'page_latest';
|
|
|
|
|
}
|
2010-07-23 22:37:52 +00:00
|
|
|
if ( !$this->including() ) { // bug 23293
|
|
|
|
|
ChangeTags::modifyDisplayQuery( $tables, $select, $conds, $join_conds,
|
|
|
|
|
$query_options, $opts['tagfilter'] );
|
|
|
|
|
}
|
2009-01-28 19:08:18 +00:00
|
|
|
|
2010-08-30 19:07:09 +00:00
|
|
|
if ( !wfRunHooks( 'SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$select ) ) )
|
2010-08-06 13:07:46 +00:00
|
|
|
return false;
|
2008-07-22 22:37:55 +00:00
|
|
|
|
|
|
|
|
if( $ns == NS_CATEGORY && !$showlinkedto ) {
|
|
|
|
|
// special handling for categories
|
|
|
|
|
// XXX: should try to make this less klugy
|
|
|
|
|
$link_tables = array( 'categorylinks' );
|
|
|
|
|
$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
|
|
|
|
|
$link_tables = array( 'pagelinks', 'templatelinks' );
|
2008-12-01 17:14:30 +00:00
|
|
|
// imagelinks only contains links to pages in NS_FILE
|
|
|
|
|
if( $ns == NS_FILE || !$showlinkedto ) $link_tables[] = 'imagelinks';
|
2008-07-22 22:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
2008-09-14 04:28:16 +00:00
|
|
|
if( $id == 0 && !$showlinkedto )
|
|
|
|
|
return false; // nonexistent pages can't link to any pages
|
|
|
|
|
|
2008-07-22 22:37:55 +00:00
|
|
|
// field name prefixes for all the various tables we might want to join with
|
|
|
|
|
$prefix = array( 'pagelinks' => 'pl', 'templatelinks' => 'tl', 'categorylinks' => 'cl', 'imagelinks' => 'il' );
|
|
|
|
|
|
|
|
|
|
$subsql = array(); // SELECT statements to combine with UNION
|
|
|
|
|
|
|
|
|
|
foreach( $link_tables as $link_table ) {
|
|
|
|
|
$pfx = $prefix[$link_table];
|
|
|
|
|
|
|
|
|
|
// imagelinks and categorylinks tables have no xx_namespace field, and have xx_to instead of xx_title
|
2008-12-01 17:14:30 +00:00
|
|
|
if( $link_table == 'imagelinks' ) $link_ns = NS_FILE;
|
2008-07-22 22:37:55 +00:00
|
|
|
else if( $link_table == 'categorylinks' ) $link_ns = NS_CATEGORY;
|
|
|
|
|
else $link_ns = 0;
|
|
|
|
|
|
2008-06-26 19:12:52 +00:00
|
|
|
if( $showlinkedto ) {
|
2008-07-22 22:37:55 +00:00
|
|
|
// find changes to pages linking to this page
|
|
|
|
|
if( $link_ns ) {
|
|
|
|
|
if( $ns != $link_ns ) continue; // should never happen, but check anyway
|
|
|
|
|
$subconds = array( "{$pfx}_to" => $dbkey );
|
2008-06-26 19:12:52 +00:00
|
|
|
} else {
|
2008-07-22 22:37:55 +00:00
|
|
|
$subconds = array( "{$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
|
|
|
|
|
$subconds = array( "{$pfx}_from" => $id );
|
|
|
|
|
if( $link_table == 'imagelinks' || $link_table == 'categorylinks' ) {
|
|
|
|
|
$subconds["rc_namespace"] = $link_ns;
|
|
|
|
|
$subjoin = "rc_title = {$pfx}_to";
|
|
|
|
|
} else {
|
|
|
|
|
$subjoin = "rc_namespace = {$pfx}_namespace AND rc_title = {$pfx}_title";
|
|
|
|
|
}
|
2008-05-16 21:34:46 +00:00
|
|
|
}
|
2008-07-22 22:37:55 +00:00
|
|
|
|
2009-10-17 12:23:23 +00:00
|
|
|
if( $dbr->unionSupportsOrderAndLimit())
|
|
|
|
|
$order = array( 'ORDER BY' => 'rc_timestamp DESC' );
|
|
|
|
|
else
|
|
|
|
|
$order = array();
|
|
|
|
|
|
2011-03-18 20:37:11 +00:00
|
|
|
|
|
|
|
|
$query = $dbr->selectSQLText(
|
|
|
|
|
array_merge( $tables, array( $link_table ) ),
|
|
|
|
|
$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,
|
2009-01-17 18:44:28 +00:00
|
|
|
$join_conds + array( $link_table => array( 'INNER JOIN', $subjoin ) )
|
|
|
|
|
);
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-10-17 12:23:23 +00:00
|
|
|
if( $dbr->unionSupportsOrderAndLimit())
|
|
|
|
|
$query = $dbr->limitResult( $query, $limit );
|
|
|
|
|
|
|
|
|
|
$subsql[] = $query;
|
2008-05-16 21:34:46 +00:00
|
|
|
}
|
2008-06-17 08:24:00 +00:00
|
|
|
|
2008-07-22 22:37:55 +00:00
|
|
|
if( count($subsql) == 0 )
|
|
|
|
|
return false; // should never happen
|
2009-10-17 12:23:23 +00:00
|
|
|
if( count($subsql) == 1 && $dbr->unionSupportsOrderAndLimit() )
|
2008-07-22 22:37:55 +00:00
|
|
|
$sql = $subsql[0];
|
|
|
|
|
else {
|
|
|
|
|
// need to resort and relimit after union
|
2009-05-19 16:58:56 +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
|
|
|
|
2008-07-26 08:42:29 +00:00
|
|
|
if( $res->numRows() == 0 )
|
2008-06-26 19:12:52 +00:00
|
|
|
$this->mResultEmpty = true;
|
|
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2008-06-26 19:12:52 +00:00
|
|
|
function getExtraOptions( $opts ){
|
2009-07-27 10:45:18 +00:00
|
|
|
$opts->consumeValues( array( 'showlinkedto', 'target', 'tagfilter' ) );
|
2008-06-26 19:12:52 +00:00
|
|
|
$extraOpts = array();
|
|
|
|
|
$extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
|
2009-05-22 09:35:48 +00:00
|
|
|
$extraOpts['target'] = array( wfMsgHtml( 'recentchangeslinked-page' ),
|
2008-12-31 21:12:01 +00:00
|
|
|
Xml::input( 'target', 40, str_replace('_',' ',$opts['target']) ) .
|
2008-06-26 19:12:52 +00:00
|
|
|
Xml::check( 'showlinkedto', $opts['showlinkedto'], array('id' => 'showlinkedto') ) . ' ' .
|
|
|
|
|
Xml::label( wfMsg("recentchangeslinked-to"), 'showlinkedto' ) );
|
2009-01-30 23:24:29 +00:00
|
|
|
$tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] );
|
|
|
|
|
if ($tagFilter)
|
|
|
|
|
$extraOpts['tagfilter'] = $tagFilter;
|
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
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $this->rclTargetTitle;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-06 17:35:19 +00:00
|
|
|
function setTopText( OutputPage $out, FormOptions $opts ) {
|
|
|
|
|
global $wgUser;
|
2008-08-06 12:49:16 +00:00
|
|
|
$skin = $wgUser->getSkin();
|
2010-02-10 04:13:43 +00:00
|
|
|
$target = $this->getTargetTitle();
|
|
|
|
|
if( $target )
|
|
|
|
|
$out->setSubtitle( wfMsg( 'recentchangeslinked-backlink', $skin->link( $target,
|
|
|
|
|
$target->getPrefixedText(), array(), array( 'redirect' => 'no' ) ) ) );
|
2008-08-06 12:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-10 04:13:43 +00:00
|
|
|
public function getFeedQuery() {
|
|
|
|
|
$target = $this->getTargetTitle();
|
|
|
|
|
if( $target ) {
|
|
|
|
|
return "target=" . urlencode( $target->getPrefixedDBkey() );
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
2008-06-26 19:12:52 +00:00
|
|
|
}
|
2010-02-10 04:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setBottomText( OutputPage $out, FormOptions $opts ) {
|
2008-06-26 19:12:52 +00:00
|
|
|
if( isset( $this->mResultEmpty ) && $this->mResultEmpty ){
|
2011-03-18 20:37:11 +00:00
|
|
|
$out->addWikiMsg( 'recentchangeslinked-noresult' );
|
2007-03-05 18:44:42 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
}
|