3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 namespace MediaWiki\Specials
;
23 use MediaWiki\Html\Html
;
24 use MediaWiki\HTMLForm\HTMLForm
;
25 use MediaWiki\SpecialPage\QueryPage
;
26 use MediaWiki\Title\Title
;
29 use Wikimedia\Rdbms\IConnectionProvider
;
32 * Special:PagesWithProp to search the page_props table
34 * @ingroup SpecialPage
37 class SpecialPagesWithProp
extends QueryPage
{
42 private $propName = null;
47 private $existingPropNames = null;
57 private $reverse = false;
62 private $sortByValue = false;
64 public function __construct( IConnectionProvider
$dbProvider ) {
65 parent
::__construct( 'PagesWithProp' );
66 $this->setDatabaseProvider( $dbProvider );
69 public function isCacheable() {
73 public function execute( $par ) {
75 $this->outputHeader();
76 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
78 $request = $this->getRequest();
79 $propname = $request->getVal( 'propname', $par );
80 $this->ns
= $request->getIntOrNull( 'namespace' );
81 $this->reverse
= $request->getBool( 'reverse' );
82 $this->sortByValue
= $request->getBool( 'sortbyvalue' );
84 $propnames = $this->getExistingPropNames();
90 'options' => $propnames,
91 'default' => $propname,
92 'label-message' => 'pageswithprop-prop',
96 'type' => 'namespaceselect',
97 'name' => 'namespace',
98 'label-message' => 'namespace',
100 'default' => $this->ns
,
105 'default' => $this->reverse
,
106 'label-message' => 'pageswithprop-reverse',
111 'name' => 'sortbyvalue',
112 'default' => $this->sortByValue
,
113 'label-message' => 'pageswithprop-sortbyvalue',
118 $form = HTMLForm
::factory( 'ooui', $fields, $this->getContext() )
120 ->setTitle( $this->getPageTitle() ) // Remove subpage
121 ->setSubmitCallback( [ $this, 'onSubmit' ] )
122 ->setWrapperLegendMsg( 'pageswithprop-legend' )
123 ->addHeaderHtml( $this->msg( 'pageswithprop-text' )->parseAsBlock() )
124 ->setSubmitTextMsg( 'pageswithprop-submit' )
126 $form->displayForm( false );
127 if ( $propname !== '' && $propname !== null ) {
132 public function onSubmit( $data, $form ) {
133 $this->propName
= $data['propname'];
134 parent
::execute( $data['propname'] );
138 * Return an array of subpages beginning with $search that this special page will accept.
140 * @param string $search Prefix to search for
141 * @param int $limit Maximum number of results to return
142 * @param int $offset Number of pages to skip
143 * @return string[] Matching subpages
145 public function prefixSearchSubpages( $search, $limit, $offset ) {
146 $subpages = array_keys( $this->queryExistingProps( $limit, $offset ) );
147 // We've already limited and offsetted, set to N and 0 respectively.
148 return self
::prefixSearchArray( $search, count( $subpages ), $subpages, 0 );
152 * Disable RSS/Atom feeds
155 public function isSyndicated() {
162 protected function linkParameters() {
164 'reverse' => $this->reverse
,
165 'sortbyvalue' => $this->sortByValue
,
167 if ( $this->ns
!== null ) {
168 $params['namespace'] = $this->ns
;
173 public function getQueryInfo() {
175 'tables' => [ 'page_props', 'page' ],
177 'page_id' => 'pp_page',
186 'pp_propname' => $this->propName
,
189 'page' => [ 'JOIN', 'page_id = pp_page' ]
194 if ( $this->ns
!== null ) {
195 $query['conds']['page_namespace'] = $this->ns
;
201 protected function getOrderFields() {
202 $sort = [ 'page_id' ];
203 if ( $this->sortByValue
) {
204 array_unshift( $sort, 'pp_sortkey' );
212 public function sortDescending() {
213 return !$this->reverse
;
218 * @param stdClass $result Result row
221 public function formatResult( $skin, $result ) {
222 $title = Title
::newFromRow( $result );
223 $ret = $this->getLinkRenderer()->makeKnownLink( $title );
224 if ( $result->pp_value
!== '' ) {
225 // Do not show very long or binary values on the special page
226 $valueLength = strlen( $result->pp_value
);
227 $isBinary = str_contains( $result->pp_value
, "\0" );
228 $isTooLong = $valueLength > 1024;
230 if ( $isBinary ||
$isTooLong ) {
232 ->msg( $isBinary ?
'pageswithprop-prophidden-binary' : 'pageswithprop-prophidden-long' )
233 ->sizeParams( $valueLength );
235 $propValue = Html
::element( 'span', [ 'class' => 'prop-value-hidden' ], $message->text() );
237 $propValue = Html
::element( 'span', [ 'class' => 'prop-value' ], $result->pp_value
);
240 $ret .= $this->msg( 'colon-separator' )->escaped() . $propValue;
246 public function getExistingPropNames() {
247 if ( $this->existingPropNames
=== null ) {
248 $this->existingPropNames
= $this->queryExistingProps();
250 return $this->existingPropNames
;
253 protected function queryExistingProps( $limit = null, $offset = 0 ) {
254 $queryBuilder = $this->getDatabaseProvider()
255 ->getReplicaDatabase()
256 ->newSelectQueryBuilder()
257 ->select( 'pp_propname' )
259 ->from( 'page_props' )
260 ->orderBy( 'pp_propname' );
263 $queryBuilder->limit( $limit );
266 $queryBuilder->offset( $offset );
268 $res = $queryBuilder->caller( __METHOD__
)->fetchResultSet();
271 foreach ( $res as $row ) {
272 $propnames[$row->pp_propname
] = $row->pp_propname
;
278 protected function getGroupName() {
284 * Retain the old class name for backwards compatibility.
285 * @deprecated since 1.41
287 class_alias( SpecialPagesWithProp
::class, 'SpecialPagesWithProp' );