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