3 * Implements Special:PagesWithProp
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
22 * @ingroup SpecialPage
26 * Special:PagesWithProp to search the page_props table
27 * @ingroup SpecialPage
30 class SpecialPagesWithProp
extends QueryPage
{
35 private $propName = null;
40 private $existingPropNames = null;
50 private $reverse = false;
55 private $sortByValue = false;
57 function __construct( $name = 'PagesWithProp' ) {
58 parent
::__construct( $name );
61 function isCacheable() {
65 public function execute( $par ) {
67 $this->outputHeader();
68 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
70 $request = $this->getRequest();
71 $propname = $request->getVal( 'propname', $par );
72 $this->reverse
= $request->getBool( 'reverse' );
73 $this->sortByValue
= $request->getBool( 'sortbyvalue' );
75 $propnames = $this->getExistingPropNames();
77 $form = HTMLForm
::factory( 'ooui', [
81 'options' => $propnames,
82 'default' => $propname,
83 'label-message' => 'pageswithprop-prop',
87 'type' => 'namespaceselect',
88 'name' => 'namespace',
89 'label-message' => 'namespace',
96 'default' => $this->reverse
,
97 'label-message' => 'pageswithprop-reverse',
102 'name' => 'sortbyvalue',
103 'default' => $this->sortByValue
,
104 'label-message' => 'pageswithprop-sortbyvalue',
107 ], $this->getContext() );
108 $form->setMethod( 'get' );
109 $form->setSubmitCallback( [ $this, 'onSubmit' ] );
110 $form->setWrapperLegendMsg( 'pageswithprop-legend' );
111 $form->addHeaderText( $this->msg( 'pageswithprop-text' )->parseAsBlock() );
112 $form->setSubmitTextMsg( 'pageswithprop-submit' );
114 $form->prepareForm();
115 $form->displayForm( false );
116 if ( $propname !== '' && $propname !== null ) {
121 public function onSubmit( $data, $form ) {
122 $this->propName
= $data['propname'];
123 $this->ns
= $data['namespace'];
124 parent
::execute( $data['propname'] );
128 * Return an array of subpages beginning with $search that this special page will accept.
130 * @param string $search Prefix to search for
131 * @param int $limit Maximum number of results to return
132 * @param int $offset Number of pages to skip
133 * @return string[] Matching subpages
135 public function prefixSearchSubpages( $search, $limit, $offset ) {
136 $subpages = array_keys( $this->queryExistingProps( $limit, $offset ) );
137 // We've already limited and offsetted, set to N and 0 respectively.
138 return self
::prefixSearchArray( $search, count( $subpages ), $subpages, 0 );
142 * Disable RSS/Atom feeds
145 function isSyndicated() {
149 public function getQueryInfo() {
151 'tables' => [ 'page_props', 'page' ],
153 'page_id' => 'pp_page',
162 'pp_propname' => $this->propName
,
165 'page' => [ 'JOIN', 'page_id = pp_page' ]
170 if ( $this->ns
&& isset( $this->ns
) ) {
171 $query['conds']['page_namespace'] = $this->ns
;
177 function getOrderFields() {
178 $sort = [ 'page_id' ];
179 if ( $this->sortByValue
) {
180 array_unshift( $sort, 'pp_sortkey' );
188 public function sortDescending() {
189 return !$this->reverse
;
194 * @param object $result Result row
197 function formatResult( $skin, $result ) {
198 $title = Title
::newFromRow( $result );
199 $ret = $this->getLinkRenderer()->makeKnownLink( $title );
200 if ( $result->pp_value
!== '' ) {
201 // Do not show very long or binary values on the special page
202 $valueLength = strlen( $result->pp_value
);
203 $isBinary = strpos( $result->pp_value
, "\0" ) !== false;
204 $isTooLong = $valueLength > 1024;
206 if ( $isBinary ||
$isTooLong ) {
208 ->msg( $isBinary ?
'pageswithprop-prophidden-binary' : 'pageswithprop-prophidden-long' )
209 ->params( $this->getLanguage()->formatSize( $valueLength ) );
211 $propValue = Html
::element( 'span', [ 'class' => 'prop-value-hidden' ], $message->text() );
213 $propValue = Html
::element( 'span', [ 'class' => 'prop-value' ], $result->pp_value
);
216 $ret .= $this->msg( 'colon-separator' )->escaped() . $propValue;
222 public function getExistingPropNames() {
223 if ( $this->existingPropNames
=== null ) {
224 $this->existingPropNames
= $this->queryExistingProps();
226 return $this->existingPropNames
;
229 protected function queryExistingProps( $limit = null, $offset = 0 ) {
231 'DISTINCT', 'ORDER BY' => 'pp_propname'
234 $opts['LIMIT'] = $limit;
237 $opts['OFFSET'] = $offset;
240 $res = wfGetDB( DB_REPLICA
)->select(
249 foreach ( $res as $row ) {
250 $propnames[$row->pp_propname
] = $row->pp_propname
;
256 protected function getGroupName() {