4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * http://www.gnu.org/copyleft/gpl.html
22 * @ingroup SpecialPage
24 class DisambiguationsPage
extends PageQueryPage
{
27 return 'Disambiguations';
30 function isExpensive( ) { return true; }
31 function isSyndicated() { return false; }
34 function getPageHeader( ) {
35 return wfMsgExt( 'disambiguations-text', array( 'parse' ) );
39 global $wgContentNamespaces;
41 $dbr = wfGetDB( DB_SLAVE
);
43 $dMsgText = wfMsgForContent('disambiguationspage');
45 $linkBatch = new LinkBatch
;
47 # If the text can be treated as a title, use it verbatim.
48 # Otherwise, pull the titles from the links table
49 $dp = Title
::newFromText($dMsgText);
51 if($dp->getNamespace() != NS_TEMPLATE
) {
52 # FIXME we assume the disambiguation message is a template but
53 # the page can potentially be from another namespace :/
54 wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
56 $linkBatch->addObj( $dp );
58 # Get all the templates linked from the Mediawiki:Disambiguationspage
59 $disPageObj = Title
::makeTitleSafe( NS_MEDIAWIKI
, 'disambiguationspage' );
61 array('pagelinks', 'page'),
63 array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE
,
64 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()),
67 while ( $row = $dbr->fetchObject( $res ) ) {
68 $linkBatch->addObj( Title
::makeTitle( NS_TEMPLATE
, $row->pl_title
));
71 $dbr->freeResult( $res );
74 $set = $linkBatch->constructSet( 'lb.tl', $dbr );
75 if( $set === false ) {
76 # We must always return a valid sql query, but this way DB will always quicly return an empty result
78 wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
81 list( $page, $pagelinks, $templatelinks) = $dbr->tableNamesN( 'page', 'pagelinks', 'templatelinks' );
83 if ( $wgContentNamespaces ) {
84 $nsclause = 'IN (' . $dbr->makeList( $wgContentNamespaces ) . ')';
86 $nsclause = '= ' . NS_MAIN
;
89 $sql = "SELECT 'Disambiguations' AS \"type\", pb.page_namespace AS namespace,"
90 ." pb.page_title AS title, la.pl_from AS value"
91 ." FROM {$templatelinks} AS lb, {$page} AS pb, {$pagelinks} AS la, {$page} AS pa"
92 ." WHERE $set" # disambiguation template(s)
93 .' AND pa.page_id = la.pl_from'
94 .' AND pa.page_namespace ' . $nsclause
95 .' AND pb.page_id = lb.tl_from'
96 .' AND pb.page_namespace = la.pl_namespace'
97 .' AND pb.page_title = la.pl_title'
98 .' ORDER BY lb.tl_namespace, lb.tl_title';
103 function getOrder() {
107 function formatResult( $skin, $result ) {
109 $title = Title
::newFromID( $result->value
);
110 $dp = Title
::makeTitle( $result->namespace, $result->title
);
112 $from = $skin->link( $title );
113 $edit = $skin->link( $title, wfMsgExt( 'parentheses', array( 'escape' ), wfMsg( 'editlink' ) ) , array(), array( 'redirect' => 'no', 'action' => 'edit' ) );
114 $arr = $wgContLang->getArrow();
115 $to = $skin->link( $dp );
117 return "$from $edit $arr $to";
124 function wfSpecialDisambiguations() {
125 list( $limit, $offset ) = wfCheckLimits();
127 $sd = new DisambiguationsPage();
129 return $sd->doQuery( $offset, $limit );