MediaWiki  1.23.2
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 
49  public function doMainQuery( $conds, $opts ) {
50  $target = $opts['target'];
51  $showlinkedto = $opts['showlinkedto'];
52  $limit = $opts['limit'];
53 
54  if ( $target === '' ) {
55  return false;
56  }
57  $outputPage = $this->getOutput();
58  $title = Title::newFromURL( $target );
59  if ( !$title || $title->isExternal() ) {
60  $outputPage->addHtml( '<div class="errorbox">' . $this->msg( 'allpagesbadtitle' )
61  ->parse() . '</div>' );
62 
63  return false;
64  }
65 
66  $outputPage->setPageTitle( $this->msg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
67 
68  /*
69  * Ordinary links are in the pagelinks table, while transclusions are
70  * in the templatelinks table, categorizations in categorylinks and
71  * image use in imagelinks. We need to somehow combine all these.
72  * Special:Whatlinkshere does this by firing multiple queries and
73  * merging the results, but the code we inherit from our parent class
74  * expects only one result set so we use UNION instead.
75  */
76 
77  $dbr = wfGetDB( DB_SLAVE, 'recentchangeslinked' );
78  $id = $title->getArticleID();
79  $ns = $title->getNamespace();
80  $dbkey = $title->getDBkey();
81 
82  $tables = array( 'recentchanges' );
83  $select = RecentChange::selectFields();
84  $join_conds = array();
85  $query_options = array();
86 
87  // left join with watchlist table to highlight watched rows
88  $uid = $this->getUser()->getId();
89  if ( $uid && $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
90  $tables[] = 'watchlist';
91  $select[] = 'wl_user';
92  $join_conds['watchlist'] = array( 'LEFT JOIN', array(
93  'wl_user' => $uid,
94  'wl_title=rc_title',
95  'wl_namespace=rc_namespace'
96  ) );
97  }
98  if ( $this->getUser()->isAllowed( 'rollback' ) ) {
99  $tables[] = 'page';
100  $join_conds['page'] = array( 'LEFT JOIN', 'rc_cur_id=page_id' );
101  $select[] = 'page_latest';
102  }
104  $tables,
105  $select,
106  $conds,
107  $join_conds,
108  $query_options,
109  $opts['tagfilter']
110  );
111 
112  if ( !wfRunHooks( 'SpecialRecentChangesQuery',
113  array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$select ),
114  '1.23' )
115  ) {
116  return false;
117  }
118 
119  if ( $ns == NS_CATEGORY && !$showlinkedto ) {
120  // special handling for categories
121  // XXX: should try to make this less kludgy
122  $link_tables = array( 'categorylinks' );
123  $showlinkedto = true;
124  } else {
125  // for now, always join on these tables; really should be configurable as in whatlinkshere
126  $link_tables = array( 'pagelinks', 'templatelinks' );
127  // imagelinks only contains links to pages in NS_FILE
128  if ( $ns == NS_FILE || !$showlinkedto ) {
129  $link_tables[] = 'imagelinks';
130  }
131  }
132 
133  if ( $id == 0 && !$showlinkedto ) {
134  return false; // nonexistent pages can't link to any pages
135  }
136 
137  // field name prefixes for all the various tables we might want to join with
138  $prefix = array(
139  'pagelinks' => 'pl',
140  'templatelinks' => 'tl',
141  'categorylinks' => 'cl',
142  'imagelinks' => 'il'
143  );
144 
145  $subsql = array(); // SELECT statements to combine with UNION
146 
147  foreach ( $link_tables as $link_table ) {
148  $pfx = $prefix[$link_table];
149 
150  // imagelinks and categorylinks tables have no xx_namespace field,
151  // and have xx_to instead of xx_title
152  if ( $link_table == 'imagelinks' ) {
153  $link_ns = NS_FILE;
154  } elseif ( $link_table == 'categorylinks' ) {
155  $link_ns = NS_CATEGORY;
156  } else {
157  $link_ns = 0;
158  }
159 
160  if ( $showlinkedto ) {
161  // find changes to pages linking to this page
162  if ( $link_ns ) {
163  if ( $ns != $link_ns ) {
164  continue;
165  } // should never happen, but check anyway
166  $subconds = array( "{$pfx}_to" => $dbkey );
167  } else {
168  $subconds = array( "{$pfx}_namespace" => $ns, "{$pfx}_title" => $dbkey );
169  }
170  $subjoin = "rc_cur_id = {$pfx}_from";
171  } else {
172  // find changes to pages linked from this page
173  $subconds = array( "{$pfx}_from" => $id );
174  if ( $link_table == 'imagelinks' || $link_table == 'categorylinks' ) {
175  $subconds["rc_namespace"] = $link_ns;
176  $subjoin = "rc_title = {$pfx}_to";
177  } else {
178  $subjoin = array( "rc_namespace = {$pfx}_namespace", "rc_title = {$pfx}_title" );
179  }
180  }
181 
182  if ( $dbr->unionSupportsOrderAndLimit() ) {
183  $order = array( 'ORDER BY' => 'rc_timestamp DESC' );
184  } else {
185  $order = array();
186  }
187 
188  $query = $dbr->selectSQLText(
189  array_merge( $tables, array( $link_table ) ),
190  $select,
191  $conds + $subconds,
192  __METHOD__,
193  $order + $query_options,
194  $join_conds + array( $link_table => array( 'INNER JOIN', $subjoin ) )
195  );
196 
197  if ( $dbr->unionSupportsOrderAndLimit() ) {
198  $query = $dbr->limitResult( $query, $limit );
199  }
200 
201  $subsql[] = $query;
202  }
203 
204  if ( count( $subsql ) == 0 ) {
205  return false; // should never happen
206  }
207  if ( count( $subsql ) == 1 && $dbr->unionSupportsOrderAndLimit() ) {
208  $sql = $subsql[0];
209  } else {
210  // need to resort and relimit after union
211  $sql = $dbr->unionQueries( $subsql, false ) . ' ORDER BY rc_timestamp DESC';
212  $sql = $dbr->limitResult( $sql, $limit, false );
213  }
214 
215  $res = $dbr->query( $sql, __METHOD__ );
216 
217  if ( $res->numRows() == 0 ) {
218  $this->mResultEmpty = true;
219  }
220 
221  return $res;
222  }
223 
224  function setTopText( FormOptions $opts ) {
225  $target = $this->getTargetTitle();
226  if ( $target ) {
227  $this->getOutput()->addBacklinkSubtitle( $target );
228  }
229  }
230 
237  function getExtraOptions( $opts ) {
238  $extraOpts = parent::getExtraOptions( $opts );
239 
240  $opts->consumeValues( array( 'showlinkedto', 'target' ) );
241 
242  $extraOpts['target'] = array( $this->msg( 'recentchangeslinked-page' )->escaped(),
243  Xml::input( 'target', 40, str_replace( '_', ' ', $opts['target'] ) ) .
244  Xml::check( 'showlinkedto', $opts['showlinkedto'], array( 'id' => 'showlinkedto' ) ) . ' ' .
245  Xml::label( $this->msg( 'recentchangeslinked-to' )->text(), 'showlinkedto' ) );
246 
247  return $extraOpts;
248  }
249 
253  function getTargetTitle() {
254  if ( $this->rclTargetTitle === null ) {
255  $opts = $this->getOptions();
256  if ( isset( $opts['target'] ) && $opts['target'] !== '' ) {
257  $this->rclTargetTitle = Title::newFromText( $opts['target'] );
258  } else {
259  $this->rclTargetTitle = false;
260  }
261  }
262 
263  return $this->rclTargetTitle;
264  }
265 }
SpecialRecentChangesLinked\getExtraOptions
getExtraOptions( $opts)
Get options to be displayed in a form.
Definition: SpecialRecentchangeslinked.php:236
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:189
SpecialRecentChangesLinked\parseParameters
parseParameters( $par, FormOptions $opts)
Process $par and put options found in $opts.
Definition: SpecialRecentchangeslinked.php:44
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
$tables
namespace and then decline to actually register it RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:815
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:535
SpecialRecentChangesLinked
This is to display changes made to all articles linked in an article.
Definition: SpecialRecentchangeslinked.php:29
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
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:252
SpecialRecentChangesLinked\setTopText
setTopText(FormOptions $opts)
Send the text to be displayed above the options.
Definition: SpecialRecentchangeslinked.php:223
NS_FILE
const NS_FILE
Definition: Defines.php:85
$limit
if( $sleep) $limit
Definition: importImages.php:99
$dbr
$dbr
Definition: testCompression.php:48
ChangeTags\modifyDisplayQuery
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag=false)
Applies all tags-related changes to a query.
Definition: ChangeTags.php:202
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4001
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:545
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:93
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:609
Xml\check
static check( $name, $checked=false, $attribs=array())
Convenience function to build an HTML checkbox.
Definition: Xml.php:339
SpecialRecentChangesLinked\__construct
__construct()
Definition: SpecialRecentchangeslinked.php:32
Title\newFromURL
static newFromURL( $url)
THIS IS NOT THE FUNCTION YOU WANT.
Definition: Title.php:241
SpecialRecentChanges
A special page that lists last changes made to the wiki.
Definition: SpecialRecentchanges.php:29
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
Title
Represents a title within MediaWiki.
Definition: Title.php:35
SpecialRecentChangesLinked\getDefaultOptions
getDefaultOptions()
Get a FormOptions object containing the default options.
Definition: SpecialRecentchangeslinked.php:36
RecentChange\selectFields
static selectFields()
Return the list of recentchanges fields that should be selected to create a new recentchanges object.
Definition: RecentChange.php:151
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
SpecialRecentChangesLinked\doMainQuery
doMainQuery( $conds, $opts)
Process the query.
Definition: SpecialRecentchangeslinked.php:48
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
Xml\input
static input( $name, $size=false, $value=false, $attribs=array())
Convenience function to build an HTML text input field.
Definition: Xml.php:294
Xml\label
static label( $label, $id, $attribs=array())
Convenience function to build an HTML form label.
Definition: Xml.php:374
SpecialRecentChangesLinked\$rclTargetTitle
bool Title $rclTargetTitle
Definition: SpecialRecentchangeslinked.php:30
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105
$res
$res
Definition: database.txt:21
ChangesListSpecialPage\getOptions
getOptions()
Get the current FormOptions for this request.
Definition: ChangesListSpecialPage.php:89