* (bug 23017) Special:Disambiguations now list pages in content namespaces rather...
[lhc/web/wiklou.git] / includes / specials / SpecialDisambiguations.php
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
5 */
6
7 /**
8 * @ingroup SpecialPage
9 */
10 class DisambiguationsPage extends PageQueryPage {
11
12 function getName() {
13 return 'Disambiguations';
14 }
15
16 function isExpensive( ) { return true; }
17 function isSyndicated() { return false; }
18
19
20 function getPageHeader( ) {
21 return wfMsgExt( 'disambiguations-text', array( 'parse' ) );
22 }
23
24 function getSQL() {
25 global $wgContentNamespaces;
26
27 $dbr = wfGetDB( DB_SLAVE );
28
29 $dMsgText = wfMsgForContent('disambiguationspage');
30
31 $linkBatch = new LinkBatch;
32
33 # If the text can be treated as a title, use it verbatim.
34 # Otherwise, pull the titles from the links table
35 $dp = Title::newFromText($dMsgText);
36 if( $dp ) {
37 if($dp->getNamespace() != NS_TEMPLATE) {
38 # FIXME we assume the disambiguation message is a template but
39 # the page can potentially be from another namespace :/
40 wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
41 }
42 $linkBatch->addObj( $dp );
43 } else {
44 # Get all the templates linked from the Mediawiki:Disambiguationspage
45 $disPageObj = Title::makeTitleSafe( NS_MEDIAWIKI, 'disambiguationspage' );
46 $res = $dbr->select(
47 array('pagelinks', 'page'),
48 'pl_title',
49 array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE,
50 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()),
51 __METHOD__ );
52
53 while ( $row = $dbr->fetchObject( $res ) ) {
54 $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title ));
55 }
56
57 $dbr->freeResult( $res );
58 }
59
60 $set = $linkBatch->constructSet( 'lb.tl', $dbr );
61 if( $set === false ) {
62 # We must always return a valid sql query, but this way DB will always quicly return an empty result
63 $set = 'FALSE';
64 wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
65 }
66
67 list( $page, $pagelinks, $templatelinks) = $dbr->tableNamesN( 'page', 'pagelinks', 'templatelinks' );
68
69 if ( $wgContentNamespaces ) {
70 $nsclause = 'IN (' . $dbr->makeList( $wgContentNamespaces ) . ')';
71 } else {
72 $nsclause = '= ' . NS_MAIN;
73 }
74
75 $sql = "SELECT 'Disambiguations' AS \"type\", pb.page_namespace AS namespace,"
76 ." pb.page_title AS title, la.pl_from AS value"
77 ." FROM {$templatelinks} AS lb, {$page} AS pb, {$pagelinks} AS la, {$page} AS pa"
78 ." WHERE $set" # disambiguation template(s)
79 .' AND pa.page_id = la.pl_from'
80 .' AND pa.page_namespace ' . $nsclause
81 .' AND pb.page_id = lb.tl_from'
82 .' AND pb.page_namespace = la.pl_namespace'
83 .' AND pb.page_title = la.pl_title'
84 .' ORDER BY lb.tl_namespace, lb.tl_title';
85
86 return $sql;
87 }
88
89 function getOrder() {
90 return '';
91 }
92
93 function formatResult( $skin, $result ) {
94 global $wgContLang;
95 $title = Title::newFromID( $result->value );
96 $dp = Title::makeTitle( $result->namespace, $result->title );
97
98 $from = $skin->link( $title );
99 $edit = $skin->link( $title, wfMsgExt( 'parentheses', array( 'escape' ), wfMsg( 'editlink' ) ) , array(), array( 'redirect' => 'no', 'action' => 'edit' ) );
100 $arr = $wgContLang->getArrow();
101 $to = $skin->link( $dp );
102
103 return "$from $edit $arr $to";
104 }
105 }
106
107 /**
108 * Constructor
109 */
110 function wfSpecialDisambiguations() {
111 list( $limit, $offset ) = wfCheckLimits();
112
113 $sd = new DisambiguationsPage();
114
115 return $sd->doQuery( $offset, $limit );
116 }