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