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' )
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();
80 // left join with watchlist table to highlight watched rows
81 if( $uid = $wgUser->getId() ) {
82 $tables[] = 'watchlist';
83 $select[] = 'wl_user';
84 $join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
87 ChangeTags
::modifyDisplayQuery( $tables, $select, $conds, $join_conds, $opts['tagfilter'] );
89 // XXX: parent class does this, should we too?
90 // wfRunHooks('SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts ) );
92 if( $ns == NS_CATEGORY
&& !$showlinkedto ) {
93 // special handling for categories
94 // XXX: should try to make this less klugy
95 $link_tables = array( 'categorylinks' );
98 // for now, always join on these tables; really should be configurable as in whatlinkshere
99 $link_tables = array( 'pagelinks', 'templatelinks' );
100 // imagelinks only contains links to pages in NS_FILE
101 if( $ns == NS_FILE ||
!$showlinkedto ) $link_tables[] = 'imagelinks';
104 if( $id == 0 && !$showlinkedto )
105 return false; // nonexistent pages can't link to any pages
107 // field name prefixes for all the various tables we might want to join with
108 $prefix = array( 'pagelinks' => 'pl', 'templatelinks' => 'tl', 'categorylinks' => 'cl', 'imagelinks' => 'il' );
110 $subsql = array(); // SELECT statements to combine with UNION
112 foreach( $link_tables as $link_table ) {
113 $pfx = $prefix[$link_table];
115 // imagelinks and categorylinks tables have no xx_namespace field, and have xx_to instead of xx_title
116 if( $link_table == 'imagelinks' ) $link_ns = NS_FILE
;
117 else if( $link_table == 'categorylinks' ) $link_ns = NS_CATEGORY
;
120 if( $showlinkedto ) {
121 // find changes to pages linking to this page
123 if( $ns != $link_ns ) continue; // should never happen, but check anyway
124 $subconds = array( "{$pfx}_to" => $dbkey );
126 $subconds = array( "{$pfx}_namespace" => $ns, "{$pfx}_title" => $dbkey );
128 $subjoin = "rc_cur_id = {$pfx}_from";
130 // find changes to pages linked from this page
131 $subconds = array( "{$pfx}_from" => $id );
132 if( $link_table == 'imagelinks' ||
$link_table == 'categorylinks' ) {
133 $subconds["rc_namespace"] = $link_ns;
134 $subjoin = "rc_title = {$pfx}_to";
136 $subjoin = "rc_namespace = {$pfx}_namespace AND rc_title = {$pfx}_title";
140 $subsql[] = $dbr->selectSQLText(
141 array_merge( $tables, array( $link_table ) ),
145 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ),
146 $join_conds +
array( $link_table => array( 'INNER JOIN', $subjoin ) )
150 if( count($subsql) == 0 )
151 return false; // should never happen
152 if( count($subsql) == 1 )
155 // need to resort and relimit after union
156 $sql = "(" . implode( ") UNION (", $subsql ) . ") ORDER BY rc_timestamp DESC LIMIT {$limit}";
159 $res = $dbr->query( $sql, __METHOD__
);
161 if( $res->numRows() == 0 )
162 $this->mResultEmpty
= true;
167 function getExtraOptions( $opts ){
168 $opts->consumeValues( array( 'showlinkedto', 'target' ) );
169 $extraOpts = array();
170 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
171 $extraOpts['target'] = array( wfMsg( 'recentchangeslinked-page' ),
172 Xml
::input( 'target', 40, str_replace('_',' ',$opts['target']) ) .
173 Xml
::check( 'showlinkedto', $opts['showlinkedto'], array('id' => 'showlinkedto') ) . ' ' .
174 Xml
::label( wfMsg("recentchangeslinked-to"), 'showlinkedto' ) );
175 $extraOpts['tagfilter'] = ChangeTags
::buildTagFilterSelector( $opts['tagfilter'] );
179 function setTopText( OutputPage
$out, FormOptions
$opts ) {
181 $skin = $wgUser->getSkin();
182 if( isset( $this->mTargetTitle
) && is_object( $this->mTargetTitle
) )
183 $out->setSubtitle( wfMsg( 'recentchangeslinked-backlink', $skin->link( $this->mTargetTitle
,
184 $this->mTargetTitle
->getPrefixedText(), array(), array( 'redirect' => 'no' ) ) ) );
187 function setBottomText( OutputPage
$out, FormOptions
$opts ){
188 if( isset( $this->mTargetTitle
) && is_object( $this->mTargetTitle
) ){
190 $out->setFeedAppendQuery( "target=" . urlencode( $this->mTargetTitle
->getPrefixedDBkey() ) );
192 if( isset( $this->mResultEmpty
) && $this->mResultEmpty
){
193 $out->addWikiMsg( 'recentchangeslinked-noresult' );