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
{
31 function __construct( $name = 'Disambiguations' ) {
32 parent
::__construct( $name );
35 function isExpensive() { return true; }
36 function isSyndicated() { return false; }
38 function getPageHeader() {
39 return $this->msg( 'disambiguations-text' )->parseAsBlock();
42 function getQueryInfo() {
43 $dbr = wfGetDB( DB_SLAVE
);
44 $dMsgText = $this->msg( 'disambiguationspage' )->inContentLanguage()->text();
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 # @todo 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',
64 'pl_namespace' => NS_TEMPLATE
,
65 'page_namespace' => $disPageObj->getNamespace(),
66 'page_title' => $disPageObj->getDBkey()),
69 foreach ( $res as $row ) {
70 $linkBatch->addObj( Title
::makeTitle( NS_TEMPLATE
, $row->pl_title
));
73 $set = $linkBatch->constructSet( 'tl', $dbr );
74 if( $set === false ) {
75 # We must always return a valid SQL query, but this way
76 # the DB will always quickly return an empty result
78 wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
81 // @todo FIXME: What are pagelinks and p2 doing here?
83 'tables' => array( 'templatelinks', 'p1' => 'page', 'pagelinks', 'p2' => 'page' ),
84 'fields' => array( 'p1.page_namespace AS namespace',
85 'p1.page_title AS title',
87 'conds' => array( $set,
88 'p1.page_id = tl_from',
89 'pl_namespace = p1.page_namespace',
90 'pl_title = p1.page_title',
91 'p2.page_id = pl_from',
92 'p2.page_namespace' => MWNamespace
::getContentNamespaces() )
96 function getOrderFields() {
97 return array( 'tl_namespace', 'tl_title', 'value' );
100 function sortDescending() {
105 * Fetch links and cache their existence
107 * @param $db DatabaseBase
110 function preprocessResults( $db, $res ) {
111 if ( !$res->numRows() ) {
115 $batch = new LinkBatch
;
116 foreach ( $res as $row ) {
117 $batch->add( $row->namespace, $row->title
);
124 function formatResult( $skin, $result ) {
125 $title = Title
::newFromID( $result->value
);
126 $dp = Title
::makeTitle( $result->namespace, $result->title
);
128 $from = Linker
::link( $title );
129 $edit = Linker
::link( $title, $this->msg( 'parentheses', $this->msg( 'editlink' )->text() )->escaped(),
130 array(), array( 'redirect' => 'no', 'action' => 'edit' ) );
131 $arr = $this->getLanguage()->getArrow();
132 $to = Linker
::link( $dp );
134 return "$from $edit $arr $to";