* Reorganised the includes directory, creating subdirectories db, parser and specials
[lhc/web/wiklou.git] / includes / specials / Disambiguations.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 $dbr = wfGetDB( DB_SLAVE );
26
27 $dMsgText = wfMsgForContent('disambiguationspage');
28
29 $linkBatch = new LinkBatch;
30
31 # If the text can be treated as a title, use it verbatim.
32 # Otherwise, pull the titles from the links table
33 $dp = Title::newFromText($dMsgText);
34 if( $dp ) {
35 if($dp->getNamespace() != NS_TEMPLATE) {
36 # FIXME we assume the disambiguation message is a template but
37 # the page can potentially be from another namespace :/
38 wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
39 }
40 $linkBatch->addObj( $dp );
41 } else {
42 # Get all the templates linked from the Mediawiki:Disambiguationspage
43 $disPageObj = Title::makeTitleSafe( NS_MEDIAWIKI, 'disambiguationspage' );
44 $res = $dbr->select(
45 array('pagelinks', 'page'),
46 'pl_title',
47 array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE,
48 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()),
49 __METHOD__ );
50
51 while ( $row = $dbr->fetchObject( $res ) ) {
52 $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title ));
53 }
54
55 $dbr->freeResult( $res );
56 }
57
58 $set = $linkBatch->constructSet( 'lb.tl', $dbr );
59 if( $set === false ) {
60 # We must always return a valid sql query, but this way DB will always quicly return an empty result
61 $set = 'FALSE';
62 wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
63 }
64
65 list( $page, $pagelinks, $templatelinks) = $dbr->tableNamesN( 'page', 'pagelinks', 'templatelinks' );
66
67 $sql = "SELECT 'Disambiguations' AS \"type\", pb.page_namespace AS namespace,"
68 ." pb.page_title AS title, la.pl_from AS value"
69 ." FROM {$templatelinks} AS lb, {$page} AS pb, {$pagelinks} AS la, {$page} AS pa"
70 ." WHERE $set" # disambiguation template(s)
71 .' AND pa.page_id = la.pl_from'
72 .' AND pa.page_namespace = ' . NS_MAIN # Limit to just articles in the main namespace
73 .' AND pb.page_id = lb.tl_from'
74 .' AND pb.page_namespace = la.pl_namespace'
75 .' AND pb.page_title = la.pl_title'
76 .' ORDER BY lb.tl_namespace, lb.tl_title';
77
78 return $sql;
79 }
80
81 function getOrder() {
82 return '';
83 }
84
85 function formatResult( $skin, $result ) {
86 global $wgContLang;
87 $title = Title::newFromId( $result->value );
88 $dp = Title::makeTitle( $result->namespace, $result->title );
89
90 $from = $skin->makeKnownLinkObj( $title, '' );
91 $edit = $skin->makeKnownLinkObj( $title, "(".wfMsgHtml("qbedit").")" , 'redirect=no&action=edit' );
92 $arr = $wgContLang->getArrow();
93 $to = $skin->makeKnownLinkObj( $dp, '' );
94
95 return "$from $edit $arr $to";
96 }
97 }
98
99 /**
100 * Constructor
101 */
102 function wfSpecialDisambiguations() {
103 list( $limit, $offset ) = wfCheckLimits();
104
105 $sd = new DisambiguationsPage();
106
107 return $sd->doQuery( $offset, $limit );
108 }