* Set default disabled values for DjVu render options
[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 .' ORDER BY lb.tl_namespace, lb.tl_title';
83
84 return $sql;
85 }
86
87 function getOrder() {
88 return '';
89 }
90
91 function formatResult( $skin, $result ) {
92 global $wgContLang;
93 $title = Title::newFromId( $result->value );
94 $dp = Title::makeTitle( $result->namespace, $result->title );
95
96 $from = $skin->makeKnownLinkObj( $title,'');
97 $edit = $skin->makeBrokenLinkObj( $title, "(".wfMsg("qbedit").")" , 'redirect=no');
98 $arr = $wgContLang->getArrow();
99 $to = $skin->makeKnownLinkObj( $dp,'');
100
101 return "$from $edit $arr $to";
102 }
103 }
104
105 /**
106 * Constructor
107 */
108 function wfSpecialDisambiguations() {
109 list( $limit, $offset ) = wfCheckLimits();
110
111 $sd = new DisambiguationsPage();
112
113 return $sd->doQuery( $offset, $limit );
114 }
115 ?>