One more tweak: double global declaration of $wgOut
[lhc/web/wiklou.git] / includes / specials / SpecialRecentchangeslinked.php
1 <?php
2
3 /**
4 * This is to display changes made to all articles linked in an article.
5 * @ingroup SpecialPage
6 */
7 class SpecialRecentchangeslinked extends SpecialRecentchanges {
8
9 function __construct(){
10 SpecialPage::SpecialPage( 'Recentchangeslinked' );
11 }
12
13 public function getDefaultOptions() {
14 $opts = parent::getDefaultOptions();
15 $opts->add( 'target', '' );
16 $opts->add( 'showlinkedto', false );
17 return $opts;
18 }
19
20 public function parseParameters( $par, FormOptions $opts ) {
21 $opts['target'] = $par;
22 }
23
24 public function feedSetup(){
25 global $wgRequest;
26 $opts = parent::feedSetup();
27 $opts['target'] = $wgRequest->getVal( 'target' );
28 return $opts;
29 }
30
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' )
36 );
37 return array( $feed, $feedObj );
38 }
39
40 public function doMainQuery( $conds, $opts ) {
41 global $wgUser, $wgOut;
42
43 $target = $opts['target'];
44 $showlinkedto = $opts['showlinkedto'];
45 $limit = $opts['limit'];
46
47 if ( $target === '' ) {
48 return false;
49 }
50 $title = Title::newFromURL( $target );
51 if( !$title || $title->getInterwiki() != '' ){
52 $wgOut->wrapWikiMsg( '<div class="errorbox">$1</div><br clear="both" />', 'allpagesbadtitle' );
53 return false;
54 }
55 $this->mTargetTitle = $title;
56
57 $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
58
59 $dbr = wfGetDB( DB_SLAVE, 'recentchangeslinked' );
60 $id = $title->getArticleId();
61
62 $tables = array( 'recentchanges' );
63 $select = array( $dbr->tableName( 'recentchanges' ) . '.*' );
64 $join_conds = array();
65
66 if( $title->getNamespace() == NS_CATEGORY ) {
67 $tables[] = 'categorylinks';
68 $conds['cl_to'] = $title->getDBkey();
69 $join_conds['categorylinks'] = array( 'LEFT JOIN', 'cl_from=rc_cur_id' );
70 } else {
71 if( $showlinkedto ) {
72 if( $title->getNamespace() == NS_TEMPLATE ){
73 $tables[] = 'templatelinks';
74 $conds['tl_namespace'] = $title->getNamespace();
75 $conds['tl_title'] = $title->getDBkey();
76 $join_conds['templatelinks'] = array( 'LEFT JOIN', 'tl_from=rc_cur_id' );
77 } else {
78 $tables[] = 'pagelinks';
79 $conds['pl_namespace'] = $title->getNamespace();
80 $conds['pl_title'] = $title->getDBkey();
81 $join_conds['pagelinks'] = array( 'LEFT JOIN', 'pl_from=rc_cur_id' );
82 }
83 } else {
84 $tables[] = 'pagelinks';
85 $conds['pl_from'] = $id;
86 $join_conds['pagelinks'] = array( 'LEFT JOIN', 'pl_namespace = rc_namespace AND pl_title = rc_title' );
87 }
88 }
89
90 if( $uid = $wgUser->getId() ) {
91 $tables[] = 'watchlist';
92 $join_conds['watchlist'] = array( 'LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace" );
93 $select[] = 'wl_user';
94 }
95
96 $res = $dbr->select( $tables, $select, $conds, __METHOD__,
97 array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ), $join_conds );
98
99 if( $dbr->numRows( $res ) == 0 )
100 $this->mResultEmpty = true;
101
102 return $res;
103 }
104
105 function getExtraOptions( $opts ){
106 $opts->consumeValues( array( 'showlinkedto', 'target' ) );
107 $extraOpts = array();
108 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
109 $extraOpts['target'] = array( wfMsg( 'recentchangeslinked-page' ),
110 Xml::input( 'target', 40, str_replace('_',' ',$opts['target']) ) .
111 Xml::check( 'showlinkedto', $opts['showlinkedto'], array('id' => 'showlinkedto') ) . ' ' .
112 Xml::label( wfMsg("recentchangeslinked-to"), 'showlinkedto' ) );
113 $extraOpts['submit'] = Xml::submitbutton( wfMsg('allpagessubmit') );
114 return $extraOpts;
115 }
116
117 function setTopText( &$out, $opts ){}
118
119 function setBottomText( &$out, $opts ){
120 if( isset( $this->mTargetTitle ) && is_object( $this->mTargetTitle ) ){
121 global $wgUser;
122 $out->setFeedAppendQuery( "target=" . urlencode( $this->mTargetTitle->getPrefixedDBkey() ) );
123 $out->addHTML("&lt; ".$wgUser->getSkin()->makeLinkObj( $this->mTargetTitle, "", "redirect=no" )."<hr />\n");
124 }
125 if( isset( $this->mResultEmpty ) && $this->mResultEmpty ){
126 $out->addWikiMsg( 'recentchangeslinked-noresult' );
127 }
128 }
129 }