Add a way for packagers to override some installation details
[lhc/web/wiklou.git] / includes / specials / SpecialDisambiguations.php
1 <?php
2 /**
3 * Implements Special:Disambiguations
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * A special page that lists pages containing links to disambiguations pages
26 *
27 * @ingroup SpecialPage
28 */
29 class DisambiguationsPage extends QueryPage {
30
31 function __construct( $name = 'Disambiguations' ) {
32 parent::__construct( $name );
33 }
34
35 function isExpensive() { return true; }
36 function isSyndicated() { return false; }
37
38 function getPageHeader() {
39 return $this->msg( 'disambiguations-text' )->parseAsBlock();
40 }
41
42 function getQueryInfo() {
43 $dbr = wfGetDB( DB_SLAVE );
44 $dMsgText = $this->msg( 'disambiguationspage' )->inContentLanguage()->text();
45 $linkBatch = new LinkBatch;
46
47 # If the text can be treated as a title, use it verbatim.
48 # Otherwise, pull the titles from the links table
49 $dp = Title::newFromText($dMsgText);
50 if( $dp ) {
51 if( $dp->getNamespace() != NS_TEMPLATE ) {
52 # @todo FIXME: We assume the disambiguation message is a template but
53 # the page can potentially be from another namespace :/
54 wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
55 }
56 $linkBatch->addObj( $dp );
57 } else {
58 # Get all the templates linked from the Mediawiki:Disambiguationspage
59 $disPageObj = Title::makeTitleSafe( NS_MEDIAWIKI, 'disambiguationspage' );
60 $res = $dbr->select(
61 array('pagelinks', 'page'),
62 'pl_title',
63 array('page_id = pl_from',
64 'pl_namespace' => NS_TEMPLATE,
65 'page_namespace' => $disPageObj->getNamespace(),
66 'page_title' => $disPageObj->getDBkey()),
67 __METHOD__ );
68
69 foreach ( $res as $row ) {
70 $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title ));
71 }
72 }
73 $set = $linkBatch->constructSet( 'tl', $dbr );
74 if( $set === false ) {
75 # We must always return a valid SQL query, but this way
76 # the DB will always quickly return an empty result
77 $set = 'FALSE';
78 wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
79 }
80
81 // @todo FIXME: What are pagelinks and p2 doing here?
82 return array (
83 'tables' => array( 'templatelinks', 'p1' => 'page', 'pagelinks', 'p2' => 'page' ),
84 'fields' => array( 'p1.page_namespace AS namespace',
85 'p1.page_title AS title',
86 'pl_from AS value' ),
87 'conds' => array( $set,
88 'p1.page_id = tl_from',
89 'pl_namespace = p1.page_namespace',
90 'pl_title = p1.page_title',
91 'p2.page_id = pl_from',
92 'p2.page_namespace' => MWNamespace::getContentNamespaces() )
93 );
94 }
95
96 function getOrderFields() {
97 return array( 'tl_namespace', 'tl_title', 'value' );
98 }
99
100 function sortDescending() {
101 return false;
102 }
103
104 /**
105 * Fetch links and cache their existence
106 *
107 * @param $db DatabaseBase
108 * @param $res
109 */
110 function preprocessResults( $db, $res ) {
111 if ( !$res->numRows() ) {
112 return;
113 }
114
115 $batch = new LinkBatch;
116 foreach ( $res as $row ) {
117 $batch->add( $row->namespace, $row->title );
118 }
119 $batch->execute();
120
121 $res->seek( 0 );
122 }
123
124 function formatResult( $skin, $result ) {
125 $title = Title::newFromID( $result->value );
126 $dp = Title::makeTitle( $result->namespace, $result->title );
127
128 $from = Linker::link( $title );
129 $edit = Linker::link( $title, $this->msg( 'parentheses', $this->msg( 'editlink' )->text() )->escaped(),
130 array(), array( 'redirect' => 'no', 'action' => 'edit' ) );
131 $arr = $this->getLanguage()->getArrow();
132 $to = Linker::link( $dp );
133
134 return "$from $edit $arr $to";
135 }
136 }