MediaWiki  master
SpecialListRedirects.php
Go to the documentation of this file.
1 <?php
29 
35  function __construct( $name = 'Listredirects' ) {
36  parent::__construct( $name );
37  }
38 
39  public function isExpensive() {
40  return true;
41  }
42 
43  function isSyndicated() {
44  return false;
45  }
46 
47  function sortDescending() {
48  return false;
49  }
50 
51  public function getQueryInfo() {
52  return [
53  'tables' => [ 'p1' => 'page', 'redirect', 'p2' => 'page' ],
54  'fields' => [ 'namespace' => 'p1.page_namespace',
55  'title' => 'p1.page_title',
56  'rd_namespace',
57  'rd_title',
58  'rd_fragment',
59  'rd_interwiki',
60  'redirid' => 'p2.page_id' ],
61  'conds' => [ 'p1.page_is_redirect' => 1 ],
62  'join_conds' => [ 'redirect' => [
63  'LEFT JOIN', 'rd_from=p1.page_id' ],
64  'p2' => [ 'LEFT JOIN', [
65  'p2.page_namespace=rd_namespace',
66  'p2.page_title=rd_title' ] ] ]
67  ];
68  }
69 
70  function getOrderFields() {
71  return [ 'p1.page_namespace', 'p1.page_title' ];
72  }
73 
80  function preprocessResults( $db, $res ) {
81  if ( !$res->numRows() ) {
82  return;
83  }
84 
85  $batch = new LinkBatch;
86  foreach ( $res as $row ) {
87  $batch->add( $row->namespace, $row->title );
88  $redirTarget = $this->getRedirectTarget( $row );
89  if ( $redirTarget ) {
90  $batch->addObj( $redirTarget );
91  }
92  }
93  $batch->execute();
94 
95  // Back to start for display
96  $res->seek( 0 );
97  }
98 
103  protected function getRedirectTarget( $row ) {
104  if ( isset( $row->rd_title ) ) {
105  return Title::makeTitle( $row->rd_namespace,
106  $row->rd_title, $row->rd_fragment,
107  $row->rd_interwiki
108  );
109  } else {
110  $title = Title::makeTitle( $row->namespace, $row->title );
111  $article = WikiPage::factory( $title );
112 
113  return $article->getRedirectTarget();
114  }
115  }
116 
122  function formatResult( $skin, $result ) {
123  $linkRenderer = $this->getLinkRenderer();
124  # Make a link to the redirect itself
125  $rd_title = Title::makeTitle( $result->namespace, $result->title );
126  $rd_link = $linkRenderer->makeLink(
127  $rd_title,
128  null,
129  [],
130  [ 'redirect' => 'no' ]
131  );
132 
133  # Find out where the redirect leads
134  $target = $this->getRedirectTarget( $result );
135  if ( $target ) {
136  # Make a link to the destination page
137  $lang = $this->getLanguage();
138  $arr = $lang->getArrow() . $lang->getDirMark();
139  $targetLink = $linkRenderer->makeLink( $target, $target->getFullText() );
140 
141  return "$rd_link $arr $targetLink";
142  } else {
143  return "<del>$rd_link</del>";
144  }
145  }
146 
147  public function execute( $par ) {
148  $this->addHelpLink( 'Help:Redirects' );
149  parent::execute( $par );
150  }
151 
152  protected function getGroupName() {
153  return 'pages';
154  }
155 }
SpecialListRedirects\getOrderFields
getOrderFields()
Subclasses return an array of fields to order by here.
Definition: SpecialListRedirects.php:70
SpecialListRedirects\getRedirectTarget
getRedirectTarget( $row)
Definition: SpecialListRedirects.php:103
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:35
LinkBatch\add
add( $ns, $dbkey)
Definition: LinkBatch.php:130
SpecialListRedirects\getQueryInfo
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
Definition: SpecialListRedirects.php:51
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:35
SpecialListRedirects\__construct
__construct( $name='Listredirects')
Definition: SpecialListRedirects.php:35
SpecialListRedirects\isSyndicated
isSyndicated()
Sometime we don't want to build rss / atom feeds.
Definition: SpecialListRedirects.php:43
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:749
SpecialListRedirects\isExpensive
isExpensive()
Is this query expensive (for some definition of expensive)? Then we don't let it run in miser mode.
Definition: SpecialListRedirects.php:39
$res
$res
Definition: testCompression.php:54
SpecialListRedirects\execute
execute( $par)
This is the actual workhorse.
Definition: SpecialListRedirects.php:147
QueryPage
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
Definition: QueryPage.php:36
SpecialListRedirects
Special:Listredirects - Lists all the redirects on the wiki.
Definition: SpecialListRedirects.php:34
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:828
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:141
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:24
$title
$title
Definition: testCompression.php:36
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:584
SpecialListRedirects\sortDescending
sortDescending()
Override to sort by increasing values.
Definition: SpecialListRedirects.php:47
SpecialListRedirects\formatResult
formatResult( $skin, $result)
Definition: SpecialListRedirects.php:122
SpecialListRedirects\preprocessResults
preprocessResults( $db, $res)
Cache page existence for performance.
Definition: SpecialListRedirects.php:80
SpecialListRedirects\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialListRedirects.php:152
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:904
SpecialPage\$linkRenderer
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:67