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