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