MediaWiki  1.30.0
SpecialRecentchangeslinked.php
Go to the documentation of this file.
1 <?php
31  protected $rclTargetTitle;
32 
33  function __construct() {
34  parent::__construct( 'Recentchangeslinked' );
35  }
36 
37  public function getDefaultOptions() {
38  $opts = parent::getDefaultOptions();
39  $opts->add( 'target', '' );
40  $opts->add( 'showlinkedto', false );
41 
42  return $opts;
43  }
44 
45  public function parseParameters( $par, FormOptions $opts ) {
46  $opts['target'] = $par;
47  }
48 
52  protected function doMainQuery( $tables, $select, $conds, $query_options,
53  $join_conds, FormOptions $opts
54  ) {
55  $target = $opts['target'];
56  $showlinkedto = $opts['showlinkedto'];
57  $limit = $opts['limit'];
58 
59  if ( $target === '' ) {
60  return false;
61  }
62  $outputPage = $this->getOutput();
63  $title = Title::newFromText( $target );
64  if ( !$title || $title->isExternal() ) {
65  $outputPage->addHTML( '<div class="errorbox">' . $this->msg( 'allpagesbadtitle' )
66  ->parse() . '</div>' );
67 
68  return false;
69  }
70 
71  $outputPage->setPageTitle( $this->msg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
72 
73  /*
74  * Ordinary links are in the pagelinks table, while transclusions are
75  * in the templatelinks table, categorizations in categorylinks and
76  * image use in imagelinks. We need to somehow combine all these.
77  * Special:Whatlinkshere does this by firing multiple queries and
78  * merging the results, but the code we inherit from our parent class
79  * expects only one result set so we use UNION instead.
80  */
81 
82  $dbr = wfGetDB( DB_REPLICA, 'recentchangeslinked' );
83  $id = $title->getArticleID();
84  $ns = $title->getNamespace();
85  $dbkey = $title->getDBkey();
86 
87  $tables[] = 'recentchanges';
88  $select = array_merge( RecentChange::selectFields(), $select );
89 
90  // left join with watchlist table to highlight watched rows
91  $uid = $this->getUser()->getId();
92  if ( $uid && $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
93  $tables[] = 'watchlist';
94  $select[] = 'wl_user';
95  $join_conds['watchlist'] = [ 'LEFT JOIN', [
96  'wl_user' => $uid,
97  'wl_title=rc_title',
98  'wl_namespace=rc_namespace'
99  ] ];
100  }
101 
102  // JOIN on page, used for 'last revision' filter highlight
103  $tables[] = 'page';
104  $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
105  $select[] = 'page_latest';
106 
107  $tagFilter = $opts['tagfilter'] ? explode( '|', $opts['tagfilter'] ) : [];
109  $tables,
110  $select,
111  $conds,
112  $join_conds,
113  $query_options,
114  $tagFilter
115  );
116 
117  if ( $dbr->unionSupportsOrderAndLimit() ) {
118  if ( count( $tagFilter ) > 1 ) {
119  // ChangeTags::modifyDisplayQuery() will have added DISTINCT.
120  // To prevent this from causing query performance problems, we need to add
121  // a GROUP BY, and add rc_id to the ORDER BY.
122  $order = [
123  'GROUP BY' => 'rc_timestamp, rc_id',
124  'ORDER BY' => 'rc_timestamp DESC, rc_id DESC'
125  ];
126  } else {
127  $order = [ 'ORDER BY' => 'rc_timestamp DESC' ];
128  }
129  } else {
130  $order = [];
131  }
132 
133  if ( !$this->runMainQueryHook( $tables, $select, $conds, $query_options, $join_conds,
134  $opts )
135  ) {
136  return false;
137  }
138 
139  if ( $ns == NS_CATEGORY && !$showlinkedto ) {
140  // special handling for categories
141  // XXX: should try to make this less kludgy
142  $link_tables = [ 'categorylinks' ];
143  $showlinkedto = true;
144  } else {
145  // for now, always join on these tables; really should be configurable as in whatlinkshere
146  $link_tables = [ 'pagelinks', 'templatelinks' ];
147  // imagelinks only contains links to pages in NS_FILE
148  if ( $ns == NS_FILE || !$showlinkedto ) {
149  $link_tables[] = 'imagelinks';
150  }
151  }
152 
153  if ( $id == 0 && !$showlinkedto ) {
154  return false; // nonexistent pages can't link to any pages
155  }
156 
157  // field name prefixes for all the various tables we might want to join with
158  $prefix = [
159  'pagelinks' => 'pl',
160  'templatelinks' => 'tl',
161  'categorylinks' => 'cl',
162  'imagelinks' => 'il'
163  ];
164 
165  $subsql = []; // SELECT statements to combine with UNION
166 
167  foreach ( $link_tables as $link_table ) {
168  $pfx = $prefix[$link_table];
169 
170  // imagelinks and categorylinks tables have no xx_namespace field,
171  // and have xx_to instead of xx_title
172  if ( $link_table == 'imagelinks' ) {
173  $link_ns = NS_FILE;
174  } elseif ( $link_table == 'categorylinks' ) {
175  $link_ns = NS_CATEGORY;
176  } else {
177  $link_ns = 0;
178  }
179 
180  if ( $showlinkedto ) {
181  // find changes to pages linking to this page
182  if ( $link_ns ) {
183  if ( $ns != $link_ns ) {
184  continue;
185  } // should never happen, but check anyway
186  $subconds = [ "{$pfx}_to" => $dbkey ];
187  } else {
188  $subconds = [ "{$pfx}_namespace" => $ns, "{$pfx}_title" => $dbkey ];
189  }
190  $subjoin = "rc_cur_id = {$pfx}_from";
191  } else {
192  // find changes to pages linked from this page
193  $subconds = [ "{$pfx}_from" => $id ];
194  if ( $link_table == 'imagelinks' || $link_table == 'categorylinks' ) {
195  $subconds["rc_namespace"] = $link_ns;
196  $subjoin = "rc_title = {$pfx}_to";
197  } else {
198  $subjoin = [ "rc_namespace = {$pfx}_namespace", "rc_title = {$pfx}_title" ];
199  }
200  }
201 
202  $query = $dbr->selectSQLText(
203  array_merge( $tables, [ $link_table ] ),
204  $select,
205  $conds + $subconds,
206  __METHOD__,
207  $order + $query_options,
208  $join_conds + [ $link_table => [ 'INNER JOIN', $subjoin ] ]
209  );
210 
211  if ( $dbr->unionSupportsOrderAndLimit() ) {
212  $query = $dbr->limitResult( $query, $limit );
213  }
214 
215  $subsql[] = $query;
216  }
217 
218  if ( count( $subsql ) == 0 ) {
219  return false; // should never happen
220  }
221  if ( count( $subsql ) == 1 && $dbr->unionSupportsOrderAndLimit() ) {
222  $sql = $subsql[0];
223  } else {
224  // need to resort and relimit after union
225  $sql = $dbr->unionQueries( $subsql, false ) . ' ORDER BY rc_timestamp DESC';
226  $sql = $dbr->limitResult( $sql, $limit, false );
227  }
228 
229  $res = $dbr->query( $sql, __METHOD__ );
230 
231  if ( $res->numRows() == 0 ) {
232  $this->mResultEmpty = true;
233  }
234 
235  return $res;
236  }
237 
238  function setTopText( FormOptions $opts ) {
239  $target = $this->getTargetTitle();
240  if ( $target ) {
241  $this->getOutput()->addBacklinkSubtitle( $target );
242  $this->getSkin()->setRelevantTitle( $target );
243  }
244  }
245 
252  function getExtraOptions( $opts ) {
253  $extraOpts = parent::getExtraOptions( $opts );
254 
255  $opts->consumeValues( [ 'showlinkedto', 'target' ] );
256 
257  $extraOpts['target'] = [ $this->msg( 'recentchangeslinked-page' )->escaped(),
258  Xml::input( 'target', 40, str_replace( '_', ' ', $opts['target'] ) ) .
259  Xml::check( 'showlinkedto', $opts['showlinkedto'], [ 'id' => 'showlinkedto' ] ) . ' ' .
260  Xml::label( $this->msg( 'recentchangeslinked-to' )->text(), 'showlinkedto' ) ];
261 
262  $this->addHelpLink( 'Help:Related changes' );
263  return $extraOpts;
264  }
265 
269  function getTargetTitle() {
270  if ( $this->rclTargetTitle === null ) {
271  $opts = $this->getOptions();
272  if ( isset( $opts['target'] ) && $opts['target'] !== '' ) {
273  $this->rclTargetTitle = Title::newFromText( $opts['target'] );
274  } else {
275  $this->rclTargetTitle = false;
276  }
277  }
278 
279  return $this->rclTargetTitle;
280  }
281 
290  public function prefixSearchSubpages( $search, $limit, $offset ) {
291  return $this->prefixSearchString( $search, $limit, $offset );
292  }
293 }
SpecialRecentChangesLinked\getExtraOptions
getExtraOptions( $opts)
Get options to be displayed in a form.
Definition: SpecialRecentchangeslinked.php:252
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:268
SpecialRecentChangesLinked\parseParameters
parseParameters( $par, FormOptions $opts)
Process $par and put options found in $opts.
Definition: SpecialRecentchangeslinked.php:45
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:746
$tables
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition: hooks.txt:988
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:675
SpecialRecentChangesLinked
This is to display changes made to all articles linked in an article.
Definition: SpecialRecentchangeslinked.php:29
Xml\label
static label( $label, $id, $attribs=[])
Convenience function to build an HTML form label.
Definition: Xml.php:358
captcha-old.count
count
Definition: captcha-old.py:249
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
SpecialRecentChangesLinked\getTargetTitle
getTargetTitle()
Definition: SpecialRecentchangeslinked.php:269
SpecialRecentChangesLinked\setTopText
setTopText(FormOptions $opts)
Send the text to be displayed above the options.
Definition: SpecialRecentchangeslinked.php:238
NS_FILE
const NS_FILE
Definition: Defines.php:71
SpecialPage\getSkin
getSkin()
Shortcut to get the skin being used for this instance.
Definition: SpecialPage.php:695
$res
$res
Definition: database.txt:21
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ChangeTags\modifyDisplayQuery
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:661
$query
null for the wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1581
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:785
SpecialPage\prefixSearchString
prefixSearchString( $search, $limit, $offset)
Perform a regular substring search for prefixSearchSubpages.
Definition: SpecialPage.php:448
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2856
Xml\check
static check( $name, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox.
Definition: Xml.php:323
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:685
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:79
SpecialRecentChangesLinked\prefixSearchSubpages
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
Definition: SpecialRecentchangeslinked.php:290
SpecialRecentChanges\runMainQueryHook
runMainQueryHook(&$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts)
Definition: SpecialRecentchanges.php:406
SpecialRecentChangesLinked\__construct
__construct()
Definition: SpecialRecentchangeslinked.php:33
SpecialRecentChangesLinked\doMainQuery
doMainQuery( $tables, $select, $conds, $query_options, $join_conds, FormOptions $opts)
@inheritDoc
Definition: SpecialRecentchangeslinked.php:52
SpecialRecentChanges
A special page that lists last changes made to the wiki.
Definition: SpecialRecentchanges.php:33
Title
Represents a title within MediaWiki.
Definition: Title.php:39
SpecialRecentChangesLinked\getDefaultOptions
getDefaultOptions()
Get a FormOptions object containing the default options.
Definition: SpecialRecentchangeslinked.php:37
RecentChange\selectFields
static selectFields()
Return the list of recentchanges fields that should be selected to create a new recentchanges object.
Definition: RecentChange.php:210
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Xml\input
static input( $name, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field.
Definition: Xml.php:274
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
SpecialRecentChangesLinked\$rclTargetTitle
bool Title $rclTargetTitle
Definition: SpecialRecentchangeslinked.php:31
ChangesListSpecialPage\getOptions
getOptions()
Get the current FormOptions for this request.
Definition: ChangesListSpecialPage.php:730