Correct the address of the FSF in some of the GPL headers
[lhc/web/wiklou.git] / includes / specials / SpecialDisambiguations.php
1 <?php
2 /**
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 */
19
20 /**
21 * @file
22 * @ingroup SpecialPage
23 */
24 class DisambiguationsPage extends PageQueryPage {
25
26 function getName() {
27 return 'Disambiguations';
28 }
29
30 function isExpensive( ) { return true; }
31 function isSyndicated() { return false; }
32
33
34 function getPageHeader( ) {
35 return wfMsgExt( 'disambiguations-text', array( 'parse' ) );
36 }
37
38 function getSQL() {
39 global $wgContentNamespaces;
40
41 $dbr = wfGetDB( DB_SLAVE );
42
43 $dMsgText = wfMsgForContent('disambiguationspage');
44
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 # 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', 'pl_namespace' => NS_TEMPLATE,
64 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()),
65 __METHOD__ );
66
67 while ( $row = $dbr->fetchObject( $res ) ) {
68 $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title ));
69 }
70
71 $dbr->freeResult( $res );
72 }
73
74 $set = $linkBatch->constructSet( 'lb.tl', $dbr );
75 if( $set === false ) {
76 # We must always return a valid sql query, but this way DB will always quicly return an empty result
77 $set = 'FALSE';
78 wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
79 }
80
81 list( $page, $pagelinks, $templatelinks) = $dbr->tableNamesN( 'page', 'pagelinks', 'templatelinks' );
82
83 if ( $wgContentNamespaces ) {
84 $nsclause = 'IN (' . $dbr->makeList( $wgContentNamespaces ) . ')';
85 } else {
86 $nsclause = '= ' . NS_MAIN;
87 }
88
89 $sql = "SELECT 'Disambiguations' AS \"type\", pb.page_namespace AS namespace,"
90 ." pb.page_title AS title, la.pl_from AS value"
91 ." FROM {$templatelinks} AS lb, {$page} AS pb, {$pagelinks} AS la, {$page} AS pa"
92 ." WHERE $set" # disambiguation template(s)
93 .' AND pa.page_id = la.pl_from'
94 .' AND pa.page_namespace ' . $nsclause
95 .' AND pb.page_id = lb.tl_from'
96 .' AND pb.page_namespace = la.pl_namespace'
97 .' AND pb.page_title = la.pl_title'
98 .' ORDER BY lb.tl_namespace, lb.tl_title';
99
100 return $sql;
101 }
102
103 function getOrder() {
104 return '';
105 }
106
107 function formatResult( $skin, $result ) {
108 global $wgContLang;
109 $title = Title::newFromID( $result->value );
110 $dp = Title::makeTitle( $result->namespace, $result->title );
111
112 $from = $skin->link( $title );
113 $edit = $skin->link( $title, wfMsgExt( 'parentheses', array( 'escape' ), wfMsg( 'editlink' ) ) , array(), array( 'redirect' => 'no', 'action' => 'edit' ) );
114 $arr = $wgContLang->getArrow();
115 $to = $skin->link( $dp );
116
117 return "$from $edit $arr $to";
118 }
119 }
120
121 /**
122 * Constructor
123 */
124 function wfSpecialDisambiguations() {
125 list( $limit, $offset ) = wfCheckLimits();
126
127 $sd = new DisambiguationsPage();
128
129 return $sd->doQuery( $offset, $limit );
130 }