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
{
31 private $propName = null;
32 private $existingPropNames = null;
34 function __construct( $name = 'PagesWithProp' ) {
35 parent
::__construct( $name );
38 function isCacheable() {
42 public function execute( $par ) {
44 $this->outputHeader();
45 $this->getOutput()->addModuleStyles( 'mediawiki.special.pagesWithProp' );
47 $request = $this->getRequest();
48 $propname = $request->getVal( 'propname', $par );
50 $propnames = $this->getExistingPropNames();
52 $form = HTMLForm
::factory( 'ooui', [
56 'options' => $propnames,
57 'default' => $propname,
58 'label-message' => 'pageswithprop-prop',
61 ], $this->getContext() );
62 $form->setMethod( 'get' );
63 $form->setSubmitCallback( [ $this, 'onSubmit' ] );
64 $form->setWrapperLegendMsg( 'pageswithprop-legend' );
65 $form->addHeaderText( $this->msg( 'pageswithprop-text' )->parseAsBlock() );
66 $form->setSubmitTextMsg( 'pageswithprop-submit' );
69 $form->displayForm( false );
70 if ( $propname !== '' && $propname !== null ) {
75 public function onSubmit( $data, $form ) {
76 $this->propName
= $data['propname'];
77 parent
::execute( $data['propname'] );
81 * Return an array of subpages beginning with $search that this special page will accept.
83 * @param string $search Prefix to search for
84 * @param int $limit Maximum number of results to return
85 * @param int $offset Number of pages to skip
86 * @return string[] Matching subpages
88 public function prefixSearchSubpages( $search, $limit, $offset ) {
89 $subpages = array_keys( $this->queryExistingProps( $limit, $offset ) );
90 // We've already limited and offsetted, set to N and 0 respectively.
91 return self
::prefixSearchArray( $search, count( $subpages ), $subpages, 0 );
95 * Disable RSS/Atom feeds
98 function isSyndicated() {
102 public function getQueryInfo() {
104 'tables' => [ 'page_props', 'page' ],
106 'page_id' => 'pp_page',
115 'pp_propname' => $this->propName
,
118 'page' => [ 'INNER JOIN', 'page_id = pp_page' ]
124 function getOrderFields() {
125 return [ 'page_id' ];
130 * @param object $result Result row
133 function formatResult( $skin, $result ) {
134 $title = Title
::newFromRow( $result );
135 $ret = $this->getLinkRenderer()->makeKnownLink( $title );
136 if ( $result->pp_value
!== '' ) {
137 // Do not show very long or binary values on the special page
138 $valueLength = strlen( $result->pp_value
);
139 $isBinary = strpos( $result->pp_value
, "\0" ) !== false;
140 $isTooLong = $valueLength > 1024;
142 if ( $isBinary ||
$isTooLong ) {
144 ->msg( $isBinary ?
'pageswithprop-prophidden-binary' : 'pageswithprop-prophidden-long' )
145 ->params( $this->getLanguage()->formatSize( $valueLength ) );
147 $propValue = Html
::element( 'span', [ 'class' => 'prop-value-hidden' ], $message->text() );
149 $propValue = Html
::element( 'span', [ 'class' => 'prop-value' ], $result->pp_value
);
152 $ret .= $this->msg( 'colon-separator' )->escaped() . $propValue;
158 public function getExistingPropNames() {
159 if ( $this->existingPropNames
=== null ) {
160 $this->existingPropNames
= $this->queryExistingProps();
162 return $this->existingPropNames
;
165 protected function queryExistingProps( $limit = null, $offset = 0 ) {
167 'DISTINCT', 'ORDER BY' => 'pp_propname'
170 $opts['LIMIT'] = $limit;
173 $opts['OFFSET'] = $offset;
176 $res = wfGetDB( DB_REPLICA
)->select(
185 foreach ( $res as $row ) {
186 $propnames[$row->pp_propname
] = $row->pp_propname
;
192 protected function getGroupName() {