Merge "Whitelist the <wbr> element."
[mediawiki.git] / includes / specials / SpecialDisambiguations.php
blobceecd15b9782ffbee40fd006045439d058b0ef4b
1 <?php
2 /**
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
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * A special page that lists pages containing links to disambiguations pages
27 * @ingroup SpecialPage
29 class DisambiguationsPage extends QueryPage {
30 function __construct( $name = 'Disambiguations' ) {
31 parent::__construct( $name );
34 function isExpensive() {
35 return true;
38 function isSyndicated() {
39 return false;
42 function getPageHeader() {
43 return $this->msg( 'disambiguations-text' )->parseAsBlock();
46 /**
47 * @return string|bool False on failure
49 function getQueryFromLinkBatch() {
50 $dbr = wfGetDB( DB_SLAVE );
51 $dMsgText = $this->msg( 'disambiguationspage' )->inContentLanguage()->text();
52 $linkBatch = new LinkBatch;
54 # If the text can be treated as a title, use it verbatim.
55 # Otherwise, pull the titles from the links table
56 $dp = Title::newFromText( $dMsgText );
57 if ( $dp ) {
58 if ( $dp->getNamespace() != NS_TEMPLATE ) {
59 # @todo FIXME: We assume the disambiguation message is a template but
60 # the page can potentially be from another namespace :/
61 wfDebug( "Mediawiki:disambiguationspage message does not refer to a template!\n" );
63 $linkBatch->addObj( $dp );
64 } else {
65 # Get all the templates linked from the Mediawiki:Disambiguationspage
66 $disPageObj = Title::makeTitleSafe( NS_MEDIAWIKI, 'disambiguationspage' );
67 $res = $dbr->select(
68 array( 'pagelinks', 'page' ),
69 'pl_title',
70 array(
71 'page_id = pl_from',
72 'pl_namespace' => NS_TEMPLATE,
73 'page_namespace' => $disPageObj->getNamespace(),
74 'page_title' => $disPageObj->getDBkey()
76 __METHOD__
79 foreach ( $res as $row ) {
80 $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title ) );
83 $set = $linkBatch->constructSet( 'tl', $dbr );
85 if ( $set === false ) {
86 # We must always return a valid SQL query, but this way
87 # the DB will always quickly return an empty result
88 $set = 'FALSE';
89 wfDebug( "Mediawiki:disambiguationspage message does not link to any templates!\n" );
92 return $set;
95 function getQueryInfo() {
96 // @todo FIXME: What are pagelinks and p2 doing here?
97 return array(
98 'tables' => array(
99 'templatelinks',
100 'p1' => 'page',
101 'pagelinks',
102 'p2' => 'page'
104 'fields' => array(
105 'namespace' => 'p1.page_namespace',
106 'title' => 'p1.page_title',
107 'value' => 'pl_from'
109 'conds' => array(
110 $this->getQueryFromLinkBatch(),
111 'p1.page_id = tl_from',
112 'pl_namespace = p1.page_namespace',
113 'pl_title = p1.page_title',
114 'p2.page_id = pl_from',
115 'p2.page_namespace' => MWNamespace::getContentNamespaces()
120 function getOrderFields() {
121 return array( 'tl_namespace', 'tl_title', 'value' );
124 function sortDescending() {
125 return false;
129 * Fetch links and cache their existence
131 * @param DatabaseBase $db
132 * @param ResultWrapper $res
134 function preprocessResults( $db, $res ) {
135 if ( !$res->numRows() ) {
136 return;
139 $batch = new LinkBatch;
140 foreach ( $res as $row ) {
141 $batch->add( $row->namespace, $row->title );
143 $batch->execute();
145 $res->seek( 0 );
149 * @param Skin $skin
150 * @param object $result Result row
151 * @return string
153 function formatResult( $skin, $result ) {
154 $title = Title::newFromID( $result->value );
155 $dp = Title::makeTitle( $result->namespace, $result->title );
157 $from = Linker::link( $title );
158 $edit = Linker::link(
159 $title,
160 $this->msg( 'parentheses', $this->msg( 'editlink' )->text() )->escaped(),
161 array(),
162 array( 'redirect' => 'no', 'action' => 'edit' )
164 $arr = $this->getLanguage()->getArrow();
165 $to = Linker::link( $dp );
167 return "$from $edit $arr $to";
170 protected function getGroupName() {
171 return 'pages';