4 * This is to display changes made to all articles linked in an article.
7 class SpecialRecentchangeslinked
extends SpecialRecentchanges
{
9 function __construct(){
10 SpecialPage
::SpecialPage( 'Recentchangeslinked' );
11 $this->includable( true );
14 public function getDefaultOptions() {
15 $opts = parent
::getDefaultOptions();
16 $opts->add( 'target', '' );
17 $opts->add( 'showlinkedto', false );
18 $opts->add( 'tagfilter', '' );
22 public function parseParameters( $par, FormOptions
$opts ) {
23 $opts['target'] = $par;
26 public function feedSetup() {
28 $opts = parent
::feedSetup();
29 # Feed is cached on limit,hideminor,target; other params would randomly not work
30 $opts['target'] = $wgRequest->getVal( 'target' );
34 public function getFeedObject( $feedFormat ){
35 $feed = new ChangesFeed( $feedFormat, false );
36 $feedObj = $feed->getFeedObject(
37 wfMsgForContent( 'recentchangeslinked-title', $this->mTargetTitle
->getPrefixedText() ),
38 wfMsgForContent( 'recentchangeslinked-feed' )
40 return array( $feed, $feedObj );
43 public function doMainQuery( $conds, $opts ) {
44 global $wgUser, $wgOut;
46 $target = $opts['target'];
47 $showlinkedto = $opts['showlinkedto'];
48 $limit = $opts['limit'];
50 if ( $target === '' ) {
53 $title = Title
::newFromURL( $target );
54 if( !$title ||
$title->getInterwiki() != '' ){
55 $wgOut->wrapWikiMsg( '<div class="errorbox">$1</div><br clear="both" />', 'allpagesbadtitle' );
58 $this->mTargetTitle
= $title;
60 $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
63 * Ordinary links are in the pagelinks table, while transclusions are
64 * in the templatelinks table, categorizations in categorylinks and
65 * image use in imagelinks. We need to somehow combine all these.
66 * Special:Whatlinkshere does this by firing multiple queries and
67 * merging the results, but the code we inherit from our parent class
68 * expects only one result set so we use UNION instead.
71 $dbr = wfGetDB( DB_SLAVE
, 'recentchangeslinked' );
72 $id = $title->getArticleId();
73 $ns = $title->getNamespace();
74 $dbkey = $title->getDBkey();
76 $tables = array( 'recentchanges' );
77 $select = array( $dbr->tableName( 'recentchanges' ) . '.*' );
78 $join_conds = array();
79 $query_options = array();
81 // left join with watchlist table to highlight watched rows
82 if( $uid = $wgUser->getId() ) {
83 $tables[] = 'watchlist';
84 $select[] = 'wl_user';
85 $join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
88 ChangeTags
::modifyDisplayQuery( $tables, $select, $conds, $join_conds,
89 $query_options, $opts['tagfilter'] );
91 // XXX: parent class does this, should we too?
92 // wfRunHooks('SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts ) );
94 if( $ns == NS_CATEGORY
&& !$showlinkedto ) {
95 // special handling for categories
96 // XXX: should try to make this less klugy
97 $link_tables = array( 'categorylinks' );
100 // for now, always join on these tables; really should be configurable as in whatlinkshere
101 $link_tables = array( 'pagelinks', 'templatelinks' );
102 // imagelinks only contains links to pages in NS_FILE
103 if( $ns == NS_FILE ||
!$showlinkedto ) $link_tables[] = 'imagelinks';
106 if( $id == 0 && !$showlinkedto )
107 return false; // nonexistent pages can't link to any pages
109 // field name prefixes for all the various tables we might want to join with
110 $prefix = array( 'pagelinks' => 'pl', 'templatelinks' => 'tl', 'categorylinks' => 'cl', 'imagelinks' => 'il' );
112 $subsql = array(); // SELECT statements to combine with UNION
114 foreach( $link_tables as $link_table ) {
115 $pfx = $prefix[$link_table];
117 // imagelinks and categorylinks tables have no xx_namespace field, and have xx_to instead of xx_title
118 if( $link_table == 'imagelinks' ) $link_ns = NS_FILE
;
119 else if( $link_table == 'categorylinks' ) $link_ns = NS_CATEGORY
;
122 if( $showlinkedto ) {
123 // find changes to pages linking to this page
125 if( $ns != $link_ns ) continue; // should never happen, but check anyway
126 $subconds = array( "{$pfx}_to" => $dbkey );
128 $subconds = array( "{$pfx}_namespace" => $ns, "{$pfx}_title" => $dbkey );
130 $subjoin = "rc_cur_id = {$pfx}_from";
132 // find changes to pages linked from this page
133 $subconds = array( "{$pfx}_from" => $id );
134 if( $link_table == 'imagelinks' ||
$link_table == 'categorylinks' ) {
135 $subconds["rc_namespace"] = $link_ns;
136 $subjoin = "rc_title = {$pfx}_to";
138 $subjoin = "rc_namespace = {$pfx}_namespace AND rc_title = {$pfx}_title";
142 $subsql[] = $dbr->selectSQLText(
143 array_merge( $tables, array( $link_table ) ),
147 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) +
$query_options,
148 $join_conds +
array( $link_table => array( 'INNER JOIN', $subjoin ) )
152 if( count($subsql) == 0 )
153 return false; // should never happen
154 if( count($subsql) == 1 )
157 // need to resort and relimit after union
158 $sql = $dbr->unionQueries($subsql, false).' ORDER BY rc_timestamp DESC';
159 $sql = $dbr->limitResult($sql, $limit, false);
162 $res = $dbr->query( $sql, __METHOD__
);
164 if( $res->numRows() == 0 )
165 $this->mResultEmpty
= true;
170 function getExtraOptions( $opts ){
171 $opts->consumeValues( array( 'showlinkedto', 'target' ) );
172 $extraOpts = array();
173 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
174 $extraOpts['target'] = array( wfMsgHtml( 'recentchangeslinked-page' ),
175 Xml
::input( 'target', 40, str_replace('_',' ',$opts['target']) ) .
176 Xml
::check( 'showlinkedto', $opts['showlinkedto'], array('id' => 'showlinkedto') ) . ' ' .
177 Xml
::label( wfMsg("recentchangeslinked-to"), 'showlinkedto' ) );
178 $tagFilter = ChangeTags
::buildTagFilterSelector( $opts['tagfilter'] );
180 $extraOpts['tagfilter'] = $tagFilter;
184 function setTopText( OutputPage
$out, FormOptions
$opts ) {
186 $skin = $wgUser->getSkin();
187 if( isset( $this->mTargetTitle
) && is_object( $this->mTargetTitle
) )
188 $out->setSubtitle( wfMsg( 'recentchangeslinked-backlink', $skin->link( $this->mTargetTitle
,
189 $this->mTargetTitle
->getPrefixedText(), array(), array( 'redirect' => 'no' ) ) ) );
192 function setBottomText( OutputPage
$out, FormOptions
$opts ){
193 if( isset( $this->mTargetTitle
) && is_object( $this->mTargetTitle
) ){
194 $out->setFeedAppendQuery( "target=" . urlencode( $this->mTargetTitle
->getPrefixedDBkey() ) );
196 if( isset( $this->mResultEmpty
) && $this->mResultEmpty
){
197 $out->addWikiMsg( 'recentchangeslinked-noresult' );