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