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  'value' => 'p1.page_title',
57  'rd_namespace',
58  'rd_title',
59  'rd_fragment',
60  'rd_interwiki',
61  'redirid' => 'p2.page_id' ],
62  'conds' => [ 'p1.page_is_redirect' => 1 ],
63  'join_conds' => [ 'redirect' => [
64  'LEFT JOIN', 'rd_from=p1.page_id' ],
65  'p2' => [ 'LEFT JOIN', [
66  'p2.page_namespace=rd_namespace',
67  'p2.page_title=rd_title' ] ] ]
68  ];
69  }
70 
71  function getOrderFields() {
72  return [ 'p1.page_namespace', 'p1.page_title' ];
73  }
74 
81  function preprocessResults( $db, $res ) {
82  if ( !$res->numRows() ) {
83  return;
84  }
85 
86  $batch = new LinkBatch;
87  foreach ( $res as $row ) {
88  $batch->add( $row->namespace, $row->title );
89  $redirTarget = $this->getRedirectTarget( $row );
90  if ( $redirTarget ) {
91  $batch->addObj( $redirTarget );
92  }
93  }
94  $batch->execute();
95 
96  // Back to start for display
97  $res->seek( 0 );
98  }
99 
104  protected function getRedirectTarget( $row ) {
105  if ( isset( $row->rd_title ) ) {
106  return Title::makeTitle( $row->rd_namespace,
107  $row->rd_title, $row->rd_fragment,
108  $row->rd_interwiki
109  );
110  } else {
111  $title = Title::makeTitle( $row->namespace, $row->title );
112  $article = WikiPage::factory( $title );
113 
114  return $article->getRedirectTarget();
115  }
116  }
117 
123  function formatResult( $skin, $result ) {
124  $linkRenderer = $this->getLinkRenderer();
125  # Make a link to the redirect itself
126  $rd_title = Title::makeTitle( $result->namespace, $result->title );
127  $rd_link = $linkRenderer->makeLink(
128  $rd_title,
129  null,
130  [],
131  [ 'redirect' => 'no' ]
132  );
133 
134  # Find out where the redirect leads
135  $target = $this->getRedirectTarget( $result );
136  if ( $target ) {
137  # Make a link to the destination page
138  $lang = $this->getLanguage();
139  $arr = $lang->getArrow() . $lang->getDirMark();
140  $targetLink = $linkRenderer->makeLink( $target, $target->getFullText() );
141 
142  return "$rd_link $arr $targetLink";
143  } else {
144  return "<del>$rd_link</del>";
145  }
146  }
147 
148  public function execute( $par ) {
149  $this->addHelpLink( 'Help:Redirects' );
150  parent::execute( $par );
151  }
152 
153  protected function getGroupName() {
154  return 'pages';
155  }
156 }
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:142
add( $ns, $dbkey)
Definition: LinkBatch.php:83
__construct( $name='Listredirects')
if(!isset( $args[0])) $lang
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
preprocessResults( $db, $res)
Cache page existence for performance.
This is a class for doing query pages; since they&#39;re almost all the same, we factor out some of the f...
Definition: QueryPage.php:36
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
formatResult( $skin, $result)
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:586
Special:Listredirects - Lists all the redirects on the wiki.
getLanguage()
Shortcut to get user&#39;s language.
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:67