Standardised file description headers; first path
[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 PageQueryPage {
30
31 function getName() {
32 return 'Disambiguations';
33 }
34
35 function isExpensive( ) { return true; }
36 function isSyndicated() { return false; }
37
38
39 function getPageHeader( ) {
40 return wfMsgExt( 'disambiguations-text', array( 'parse' ) );
41 }
42
43 function getSQL() {
44 global $wgContentNamespaces;
45
46 $dbr = wfGetDB( DB_SLAVE );
47
48 $dMsgText = wfMsgForContent('disambiguationspage');
49
50 $linkBatch = new LinkBatch;
51
52 # If the text can be treated as a title, use it verbatim.
53 # Otherwise, pull the titles from the links table
54 $dp = Title::newFromText($dMsgText);
55 if( $dp ) {
56 if($dp->getNamespace() != NS_TEMPLATE) {
57 # FIXME we assume the disambiguation message is a template but
58 # the page can potentially be from another namespace :/
59 wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
60 }
61 $linkBatch->addObj( $dp );
62 } else {
63 # Get all the templates linked from the Mediawiki:Disambiguationspage
64 $disPageObj = Title::makeTitleSafe( NS_MEDIAWIKI, 'disambiguationspage' );
65 $res = $dbr->select(
66 array('pagelinks', 'page'),
67 'pl_title',
68 array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE,
69 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()),
70 __METHOD__ );
71
72 while ( $row = $dbr->fetchObject( $res ) ) {
73 $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title ));
74 }
75 }
76
77 $set = $linkBatch->constructSet( 'lb.tl', $dbr );
78 if( $set === false ) {
79 # We must always return a valid sql query, but this way DB will always quicly return an empty result
80 $set = 'FALSE';
81 wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
82 }
83
84 list( $page, $pagelinks, $templatelinks) = $dbr->tableNamesN( 'page', 'pagelinks', 'templatelinks' );
85
86 if ( $wgContentNamespaces ) {
87 $nsclause = 'IN (' . $dbr->makeList( $wgContentNamespaces ) . ')';
88 } else {
89 $nsclause = '= ' . NS_MAIN;
90 }
91
92 $sql = "SELECT 'Disambiguations' AS \"type\", pb.page_namespace AS namespace,"
93 ." pb.page_title AS title, la.pl_from AS value"
94 ." FROM {$templatelinks} AS lb, {$page} AS pb, {$pagelinks} AS la, {$page} AS pa"
95 ." WHERE $set" # disambiguation template(s)
96 .' AND pa.page_id = la.pl_from'
97 .' AND pa.page_namespace ' . $nsclause
98 .' AND pb.page_id = lb.tl_from'
99 .' AND pb.page_namespace = la.pl_namespace'
100 .' AND pb.page_title = la.pl_title'
101 .' ORDER BY lb.tl_namespace, lb.tl_title';
102
103 return $sql;
104 }
105
106 function getOrder() {
107 return '';
108 }
109
110 function formatResult( $skin, $result ) {
111 global $wgContLang;
112 $title = Title::newFromID( $result->value );
113 $dp = Title::makeTitle( $result->namespace, $result->title );
114
115 $from = $skin->link( $title );
116 $edit = $skin->link( $title, wfMsgExt( 'parentheses', array( 'escape' ), wfMsg( 'editlink' ) ) , array(), array( 'redirect' => 'no', 'action' => 'edit' ) );
117 $arr = $wgContLang->getArrow();
118 $to = $skin->link( $dp );
119
120 return "$from $edit $arr $to";
121 }
122 }
123
124 /**
125 * Constructor
126 */
127 function wfSpecialDisambiguations() {
128 list( $limit, $offset ) = wfCheckLimits();
129
130 $sd = new DisambiguationsPage();
131
132 return $sd->doQuery( $offset, $limit );
133 }