10 class DisambiguationsPage
extends PageQueryPage
{
13 return 'Disambiguations';
16 function isExpensive( ) { return true; }
17 function isSyndicated() { return false; }
20 function getPageHeader( ) {
21 return wfMsgExt( 'disambiguations-text', array( 'parse' ) );
25 global $wgContentNamespaces;
27 $dbr = wfGetDB( DB_SLAVE
);
29 $dMsgText = wfMsgForContent('disambiguationspage');
31 $linkBatch = new LinkBatch
;
33 # If the text can be treated as a title, use it verbatim.
34 # Otherwise, pull the titles from the links table
35 $dp = Title
::newFromText($dMsgText);
37 if($dp->getNamespace() != NS_TEMPLATE
) {
38 # FIXME we assume the disambiguation message is a template but
39 # the page can potentially be from another namespace :/
40 wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
42 $linkBatch->addObj( $dp );
44 # Get all the templates linked from the Mediawiki:Disambiguationspage
45 $disPageObj = Title
::makeTitleSafe( NS_MEDIAWIKI
, 'disambiguationspage' );
47 array('pagelinks', 'page'),
49 array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE
,
50 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()),
53 while ( $row = $dbr->fetchObject( $res ) ) {
54 $linkBatch->addObj( Title
::makeTitle( NS_TEMPLATE
, $row->pl_title
));
57 $dbr->freeResult( $res );
60 $set = $linkBatch->constructSet( 'lb.tl', $dbr );
61 if( $set === false ) {
62 # We must always return a valid sql query, but this way DB will always quicly return an empty result
64 wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
67 list( $page, $pagelinks, $templatelinks) = $dbr->tableNamesN( 'page', 'pagelinks', 'templatelinks' );
69 if ( $wgContentNamespaces ) {
70 $nsclause = 'IN (' . $dbr->makeList( $wgContentNamespaces ) . ')';
72 $nsclause = '= ' . NS_MAIN
;
75 $sql = "SELECT 'Disambiguations' AS \"type\", pb.page_namespace AS namespace,"
76 ." pb.page_title AS title, la.pl_from AS value"
77 ." FROM {$templatelinks} AS lb, {$page} AS pb, {$pagelinks} AS la, {$page} AS pa"
78 ." WHERE $set" # disambiguation template(s)
79 .' AND pa.page_id = la.pl_from'
80 .' AND pa.page_namespace ' . $nsclause
81 .' AND pb.page_id = lb.tl_from'
82 .' AND pb.page_namespace = la.pl_namespace'
83 .' AND pb.page_title = la.pl_title'
84 .' ORDER BY lb.tl_namespace, lb.tl_title';
93 function formatResult( $skin, $result ) {
95 $title = Title
::newFromID( $result->value
);
96 $dp = Title
::makeTitle( $result->namespace, $result->title
);
98 $from = $skin->link( $title );
99 $edit = $skin->link( $title, wfMsgExt( 'parentheses', array( 'escape' ), wfMsg( 'editlink' ) ) , array(), array( 'redirect' => 'no', 'action' => 'edit' ) );
100 $arr = $wgContLang->getArrow();
101 $to = $skin->link( $dp );
103 return "$from $edit $arr $to";
110 function wfSpecialDisambiguations() {
111 list( $limit, $offset ) = wfCheckLimits();
113 $sd = new DisambiguationsPage();
115 return $sd->doQuery( $offset, $limit );