0081331ae798d52b62a6eccea16410cefb31a318
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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
));
72 $set = $linkBatch->constructSet( 'lb.tl', $dbr );
73 if( $set === false ) {
74 # We must always return a valid sql query, but this way DB will always quicly return an empty result
76 wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
79 list( $page, $pagelinks, $templatelinks) = $dbr->tableNamesN( 'page', 'pagelinks', 'templatelinks' );
81 if ( $wgContentNamespaces ) {
82 $nsclause = 'IN (' . $dbr->makeList( $wgContentNamespaces ) . ')';
84 $nsclause = '= ' . NS_MAIN
;
87 $sql = "SELECT 'Disambiguations' AS \"type\", pb.page_namespace AS namespace,"
88 ." pb.page_title AS title, la.pl_from AS value"
89 ." FROM {$templatelinks} AS lb, {$page} AS pb, {$pagelinks} AS la, {$page} AS pa"
90 ." WHERE $set" # disambiguation template(s)
91 .' AND pa.page_id = la.pl_from'
92 .' AND pa.page_namespace ' . $nsclause
93 .' AND pb.page_id = lb.tl_from'
94 .' AND pb.page_namespace = la.pl_namespace'
95 .' AND pb.page_title = la.pl_title'
96 .' ORDER BY lb.tl_namespace, lb.tl_title';
101 function getOrder() {
105 function formatResult( $skin, $result ) {
107 $title = Title
::newFromID( $result->value
);
108 $dp = Title
::makeTitle( $result->namespace, $result->title
);
110 $from = $skin->link( $title );
111 $edit = $skin->link( $title, wfMsgExt( 'parentheses', array( 'escape' ), wfMsg( 'editlink' ) ) , array(), array( 'redirect' => 'no', 'action' => 'edit' ) );
112 $arr = $wgContLang->getArrow();
113 $to = $skin->link( $dp );
115 return "$from $edit $arr $to";
122 function wfSpecialDisambiguations() {
123 list( $limit, $offset ) = wfCheckLimits();
125 $sd = new DisambiguationsPage();
127 return $sd->doQuery( $offset, $limit );