Merge "Show change language log on Special:PageLanguage"
[lhc/web/wiklou.git] / includes / specials / SpecialPagesWithProp.php
1 <?php
2 /**
3 * Implements Special:PagesWithProp
4 *
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.
9 *
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.
14 *
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
19 *
20 * @since 1.21
21 * @file
22 * @ingroup SpecialPage
23 * @author Brad Jorsch
24 */
25
26 /**
27 * Special:PagesWithProp to search the page_props table
28 * @ingroup SpecialPage
29 * @since 1.21
30 */
31 class SpecialPagesWithProp extends QueryPage {
32 private $propName = null;
33 private $existingPropNames = null;
34
35 function __construct( $name = 'PagesWithProp' ) {
36 parent::__construct( $name );
37 }
38
39 function isCacheable() {
40 return false;
41 }
42
43 function execute( $par ) {
44 $this->setHeaders();
45 $this->outputHeader();
46 $this->getOutput()->addModuleStyles( 'mediawiki.special.pagesWithProp' );
47
48 $request = $this->getRequest();
49 $propname = $request->getVal( 'propname', $par );
50
51 $propnames = $this->getExistingPropNames();
52
53 $form = new HTMLForm( array(
54 'propname' => array(
55 'type' => 'selectorother',
56 'name' => 'propname',
57 'options' => $propnames,
58 'default' => $propname,
59 'label-message' => 'pageswithprop-prop',
60 'required' => true,
61 ),
62 ), $this->getContext() );
63 $form->setMethod( 'get' );
64 $form->setSubmitCallback( array( $this, 'onSubmit' ) );
65 $form->setWrapperLegendMsg( 'pageswithprop-legend' );
66 $form->addHeaderText( $this->msg( 'pageswithprop-text' )->parseAsBlock() );
67 $form->setSubmitTextMsg( 'pageswithprop-submit' );
68
69 $form->prepareForm();
70 $form->displayForm( false );
71 if ( $propname !== '' && $propname !== null ) {
72 $form->trySubmit();
73 }
74 }
75
76 public function onSubmit( $data, $form ) {
77 $this->propName = $data['propname'];
78 parent::execute( $data['propname'] );
79 }
80
81 /**
82 * Return an array of subpages beginning with $search that this special page will accept.
83 *
84 * @param string $search Prefix to search for
85 * @param int $limit Maximum number of results to return
86 * @return string[] Matching subpages
87 */
88 public function prefixSearchSubpages( $search, $limit = 10 ) {
89 $subpages = array_keys( $this->getExistingPropNames() );
90 return self::prefixSearchArray( $search, $limit, $subpages );
91 }
92
93 /**
94 * Disable RSS/Atom feeds
95 * @return bool
96 */
97 function isSyndicated() {
98 return false;
99 }
100
101 function getQueryInfo() {
102 return array(
103 'tables' => array( 'page_props', 'page' ),
104 'fields' => array(
105 'page_id' => 'pp_page',
106 'page_namespace',
107 'page_title',
108 'page_len',
109 'page_is_redirect',
110 'page_latest',
111 'pp_value',
112 ),
113 'conds' => array(
114 'page_id = pp_page',
115 'pp_propname' => $this->propName,
116 ),
117 'options' => array()
118 );
119 }
120
121 function getOrderFields() {
122 return array( 'page_id' );
123 }
124
125 /**
126 * @param Skin $skin
127 * @param object $result Result row
128 * @return string
129 */
130 function formatResult( $skin, $result ) {
131 $title = Title::newFromRow( $result );
132 $ret = Linker::link( $title, null, array(), array(), array( 'known' ) );
133 if ( $result->pp_value !== '' ) {
134 // Do not show very long or binary values on the special page
135 $valueLength = strlen( $result->pp_value );
136 $isBinary = strpos( $result->pp_value, "\0" ) !== false;
137 $isTooLong = $valueLength > 1024;
138
139 if ( $isBinary || $isTooLong ) {
140 $message = $this
141 ->msg( $isBinary ? 'pageswithprop-prophidden-binary' : 'pageswithprop-prophidden-long' )
142 ->params( $this->getLanguage()->formatSize( $valueLength ) );
143
144 $propValue = Html::element( 'span', array( 'class' => 'prop-value-hidden' ), $message->text() );
145 } else {
146 $propValue = Html::element( 'span', array( 'class' => 'prop-value' ), $result->pp_value );
147 }
148
149 $ret .= $this->msg( 'colon-separator' )->escaped() . $propValue;
150 }
151
152 return $ret;
153 }
154
155 public function getExistingPropNames() {
156 if ( $this->existingPropNames === null ) {
157 $dbr = wfGetDB( DB_SLAVE );
158 $res = $dbr->select(
159 'page_props',
160 'pp_propname',
161 '',
162 __METHOD__,
163 array( 'DISTINCT', 'ORDER BY' => 'pp_propname' )
164 );
165 $propnames = array();
166 foreach ( $res as $row ) {
167 $propnames[$row->pp_propname] = $row->pp_propname;
168 }
169 $this->existingPropNames = $propnames;
170 }
171 return $this->existingPropNames;
172 }
173
174 protected function getGroupName() {
175 return 'pages';
176 }
177 }