3 * Implements Special:Disambiguations
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * A special page that lists pages containing links to disambiguations pages
27 * @ingroup SpecialPage
29 class DisambiguationsPage
extends PageQueryPage
{
32 return 'Disambiguations';
35 function isExpensive( ) { return true; }
36 function isSyndicated() { return false; }
39 function getPageHeader( ) {
40 return wfMsgExt( 'disambiguations-text', array( 'parse' ) );
44 global $wgContentNamespaces;
46 $dbr = wfGetDB( DB_SLAVE
);
48 $dMsgText = wfMsgForContent('disambiguationspage');
50 $linkBatch = new LinkBatch
;
52 # If the text can be treated as a title, use it verbatim.
53 # Otherwise, pull the titles from the links table
54 $dp = Title
::newFromText($dMsgText);
56 if($dp->getNamespace() != NS_TEMPLATE
) {
57 # FIXME we assume the disambiguation message is a template but
58 # the page can potentially be from another namespace :/
59 wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
61 $linkBatch->addObj( $dp );
63 # Get all the templates linked from the Mediawiki:Disambiguationspage
64 $disPageObj = Title
::makeTitleSafe( NS_MEDIAWIKI
, 'disambiguationspage' );
66 array('pagelinks', 'page'),
68 array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE
,
69 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()),
72 foreach ( $res as $row ) {
73 $linkBatch->addObj( Title
::makeTitle( NS_TEMPLATE
, $row->pl_title
));
77 $set = $linkBatch->constructSet( 'lb.tl', $dbr );
78 if( $set === false ) {
79 # We must always return a valid sql query, but this way DB will always quicly return an empty result
81 wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
84 list( $page, $pagelinks, $templatelinks) = $dbr->tableNamesN( 'page', 'pagelinks', 'templatelinks' );
86 if ( $wgContentNamespaces ) {
87 $nsclause = 'IN (' . $dbr->makeList( $wgContentNamespaces ) . ')';
89 $nsclause = '= ' . NS_MAIN
;
92 $sql = "SELECT 'Disambiguations' AS \"type\", pb.page_namespace AS namespace,"
93 ." pb.page_title AS title, la.pl_from AS value"
94 ." FROM {$templatelinks} AS lb, {$page} AS pb, {$pagelinks} AS la, {$page} AS pa"
95 ." WHERE $set" # disambiguation template(s)
96 .' AND pa.page_id = la.pl_from'
97 .' AND pa.page_namespace ' . $nsclause
98 .' AND pb.page_id = lb.tl_from'
99 .' AND pb.page_namespace = la.pl_namespace'
100 .' AND pb.page_title = la.pl_title'
101 .' ORDER BY lb.tl_namespace, lb.tl_title';
106 function getOrder() {
110 function formatResult( $skin, $result ) {
112 $title = Title
::newFromID( $result->value
);
113 $dp = Title
::makeTitle( $result->namespace, $result->title
);
115 $from = $skin->link( $title );
116 $edit = $skin->link( $title, wfMsgExt( 'parentheses', array( 'escape' ), wfMsg( 'editlink' ) ) , array(), array( 'redirect' => 'no', 'action' => 'edit' ) );
117 $arr = $wgContLang->getArrow();
118 $to = $skin->link( $dp );
120 return "$from $edit $arr $to";
127 function wfSpecialDisambiguations() {
128 list( $limit, $offset ) = wfCheckLimits();
130 $sd = new DisambiguationsPage();
132 return $sd->doQuery( $offset, $limit );