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' );
13 public function getDefaultOptions() {
14 $opts = parent
::getDefaultOptions();
15 $opts->add( 'target', '' );
16 $opts->add( 'showlinkedto', false );
20 public function parseParameters( $par, FormOptions
$opts ) {
21 $opts['target'] = $par;
24 public function feedSetup(){
26 $opts = parent
::feedSetup();
27 $opts['target'] = $wgRequest->getVal( 'target' );
31 public function getFeedObject( $feedFormat ){
32 $feed = new ChangesFeed( $feedFormat, false );
33 $feedObj = $feed->getFeedObject(
34 wfMsgForContent( 'recentchangeslinked-title', $this->mTargetTitle
->getPrefixedText() ),
35 wfMsgForContent( 'recentchangeslinked' )
37 return array( $feed, $feedObj );
40 public function doMainQuery( $conds, $opts ) {
41 global $wgUser, $wgOut;
43 $target = $opts['target'];
44 $showlinkedto = $opts['showlinkedto'];
45 $limit = $opts['limit'];
47 if ( $target === '' ) {
50 $title = Title
::newFromURL( $target );
51 if( !$title ||
$title->getInterwiki() != '' ){
52 $wgOut->wrapWikiMsg( '<div class="errorbox">$1</div><br clear="both" />', 'allpagesbadtitle' );
55 $this->mTargetTitle
= $title;
57 $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
60 * Ordinary links are in the pagelinks table, while transclusions are
61 * in the templatelinks table, categorizations in categorylinks and
62 * image use in imagelinks. We need to somehow combine all these.
63 * Special:Whatlinkshere does this by firing multiple queries and
64 * merging the results, but the code we inherit from our parent class
65 * expects only one result set so we use UNION instead.
68 $dbr = wfGetDB( DB_SLAVE
, 'recentchangeslinked' );
69 $id = $title->getArticleId();
70 $ns = $title->getNamespace();
71 $dbkey = $title->getDBkey();
73 $tables = array( 'recentchanges' );
74 $select = array( $dbr->tableName( 'recentchanges' ) . '.*' );
75 $join_conds = array();
77 // left join with watchlist table to highlight watched rows
78 if( $uid = $wgUser->getId() ) {
79 $tables[] = 'watchlist';
80 $select[] = 'wl_user';
81 $join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
84 // XXX: parent class does this, should we too?
85 // wfRunHooks('SpecialRecentChangesQuery', array( &$conds, &$tables, &$join_conds, $opts ) );
87 if( $ns == NS_CATEGORY
&& !$showlinkedto ) {
88 // special handling for categories
89 // XXX: should try to make this less klugy
90 $link_tables = array( 'categorylinks' );
93 // for now, always join on these tables; really should be configurable as in whatlinkshere
94 $link_tables = array( 'pagelinks', 'templatelinks' );
95 // imagelinks only contains links to pages in NS_IMAGE
96 if( $ns == NS_IMAGE ||
!$showlinkedto ) $link_tables[] = 'imagelinks';
99 if( $id == 0 && !$showlinkedto )
100 return false; // nonexistent pages can't link to any pages
102 // field name prefixes for all the various tables we might want to join with
103 $prefix = array( 'pagelinks' => 'pl', 'templatelinks' => 'tl', 'categorylinks' => 'cl', 'imagelinks' => 'il' );
105 $subsql = array(); // SELECT statements to combine with UNION
107 foreach( $link_tables as $link_table ) {
108 $pfx = $prefix[$link_table];
110 // imagelinks and categorylinks tables have no xx_namespace field, and have xx_to instead of xx_title
111 if( $link_table == 'imagelinks' ) $link_ns = NS_IMAGE
;
112 else if( $link_table == 'categorylinks' ) $link_ns = NS_CATEGORY
;
115 if( $showlinkedto ) {
116 // find changes to pages linking to this page
118 if( $ns != $link_ns ) continue; // should never happen, but check anyway
119 $subconds = array( "{$pfx}_to" => $dbkey );
121 $subconds = array( "{$pfx}_namespace" => $ns, "{$pfx}_title" => $dbkey );
123 $subjoin = "rc_cur_id = {$pfx}_from";
125 // find changes to pages linked from this page
126 $subconds = array( "{$pfx}_from" => $id );
127 if( $link_table == 'imagelinks' ||
$link_table == 'categorylinks' ) {
128 $subconds["rc_namespace"] = $link_ns;
129 $subjoin = "rc_title = {$pfx}_to";
131 $subjoin = "rc_namespace = {$pfx}_namespace AND rc_title = {$pfx}_title";
135 $subsql[] = $dbr->selectSQLText( array_merge( $tables, array( $link_table ) ), $select, $conds +
$subconds,
136 __METHOD__
, array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ),
137 $join_conds +
array( $link_table => array( 'INNER JOIN', $subjoin ) ) );
140 if( count($subsql) == 0 )
141 return false; // should never happen
142 if( count($subsql) == 1 )
145 // need to resort and relimit after union
146 $sql = "(" . implode( ") UNION (", $subsql ) . ") ORDER BY rc_timestamp DESC LIMIT {$limit}";
149 $res = $dbr->query( $sql, __METHOD__
);
151 if( $res->numRows() == 0 )
152 $this->mResultEmpty
= true;
157 function getExtraOptions( $opts ){
158 $opts->consumeValues( array( 'showlinkedto', 'target' ) );
159 $extraOpts = array();
160 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
161 $extraOpts['target'] = array( wfMsg( 'recentchangeslinked-page' ),
162 Xml
::input( 'target', 40, str_replace('_',' ',$opts['target']) ) .
163 Xml
::check( 'showlinkedto', $opts['showlinkedto'], array('id' => 'showlinkedto') ) . ' ' .
164 Xml
::label( wfMsg("recentchangeslinked-to"), 'showlinkedto' ) );
168 function setTopText( OutputPage
$out, FormOptions
$opts ) {
170 $skin = $wgUser->getSkin();
171 if( isset( $this->mTargetTitle
) && is_object( $this->mTargetTitle
) )
172 $out->setSubtitle( wfMsg( 'recentchangeslinked-backlink', $skin->link( $this->mTargetTitle
,
173 $this->mTargetTitle
->getPrefixedText(), array(), array( 'redirect' => 'no' ) ) ) );
176 function setBottomText( OutputPage
$out, FormOptions
$opts ){
177 if( isset( $this->mTargetTitle
) && is_object( $this->mTargetTitle
) ){
179 $out->setFeedAppendQuery( "target=" . urlencode( $this->mTargetTitle
->getPrefixedDBkey() ) );
181 if( isset( $this->mResultEmpty
) && $this->mResultEmpty
){
182 $out->addWikiMsg( 'recentchangeslinked-noresult' );