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 // field name prefixes for all the various tables we might want to join with
100 $prefix = array( 'pagelinks' => 'pl', 'templatelinks' => 'tl', 'categorylinks' => 'cl', 'imagelinks' => 'il' );
102 $subsql = array(); // SELECT statements to combine with UNION
104 foreach( $link_tables as $link_table ) {
105 $pfx = $prefix[$link_table];
107 // imagelinks and categorylinks tables have no xx_namespace field, and have xx_to instead of xx_title
108 if( $link_table == 'imagelinks' ) $link_ns = NS_IMAGE
;
109 else if( $link_table == 'categorylinks' ) $link_ns = NS_CATEGORY
;
112 if( $showlinkedto ) {
113 // find changes to pages linking to this page
115 if( $ns != $link_ns ) continue; // should never happen, but check anyway
116 $subconds = array( "{$pfx}_to" => $dbkey );
118 $subconds = array( "{$pfx}_namespace" => $ns, "{$pfx}_title" => $dbkey );
120 $subjoin = "rc_cur_id = {$pfx}_from";
122 // find changes to pages linked from this page
123 $subconds = array( "{$pfx}_from" => $id );
124 if( $link_table == 'imagelinks' ||
$link_table == 'categorylinks' ) {
125 $subconds["rc_namespace"] = $link_ns;
126 $subjoin = "rc_title = {$pfx}_to";
128 $subjoin = "rc_namespace = {$pfx}_namespace AND rc_title = {$pfx}_title";
132 $subsql[] = $dbr->selectSQLText( array_merge( $tables, array( $link_table ) ), $select, $conds +
$subconds,
133 __METHOD__
, array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ),
134 $join_conds +
array( $link_table => array( 'INNER JOIN', $subjoin ) ) );
137 if( count($subsql) == 0 )
138 return false; // should never happen
139 if( count($subsql) == 1 )
142 // need to resort and relimit after union
143 $sql = "(" . implode( ") UNION (", $subsql ) . ") ORDER BY rc_timestamp DESC LIMIT {$limit}";
146 $res = $dbr->query( $sql, __METHOD__
);
148 if( $res->numRows() == 0 )
149 $this->mResultEmpty
= true;
154 function getExtraOptions( $opts ){
155 $opts->consumeValues( array( 'showlinkedto', 'target' ) );
156 $extraOpts = array();
157 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
158 $extraOpts['target'] = array( wfMsg( 'recentchangeslinked-page' ),
159 Xml
::input( 'target', 40, str_replace('_',' ',$opts['target']) ) .
160 Xml
::check( 'showlinkedto', $opts['showlinkedto'], array('id' => 'showlinkedto') ) . ' ' .
161 Xml
::label( wfMsg("recentchangeslinked-to"), 'showlinkedto' ) );
162 $extraOpts['submit'] = Xml
::submitbutton( wfMsg('allpagessubmit') );
166 function setTopText( &$out, $opts ) {
167 global $wgOut, $wgUser;
168 $skin = $wgUser->getSkin();
169 $wgOut->setSubtitle( wfMsg( 'recentchangeslinked-backlink', $skin->link( $this->mTargetTitle
, $this->mTargetTitle
->getPrefixedText(), array(), array( 'redirect' => 'no' ) ) ) );
172 function setBottomText( &$out, $opts ){
173 if( isset( $this->mTargetTitle
) && is_object( $this->mTargetTitle
) ){
175 $out->setFeedAppendQuery( "target=" . urlencode( $this->mTargetTitle
->getPrefixedDBkey() ) );
177 if( isset( $this->mResultEmpty
) && $this->mResultEmpty
){
178 $out->addWikiMsg( 'recentchangeslinked-noresult' );