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;
45 private $reverse = false;
50 private $sortByValue = false;
52 function __construct( $name = 'PagesWithProp' ) {
53 parent
::__construct( $name );
56 function isCacheable() {
60 public function execute( $par ) {
62 $this->outputHeader();
63 $this->getOutput()->addModuleStyles( 'mediawiki.special' );
65 $request = $this->getRequest();
66 $propname = $request->getVal( 'propname', $par );
67 $this->reverse
= $request->getBool( 'reverse' );
68 $this->sortByValue
= $request->getBool( 'sortbyvalue' );
70 $propnames = $this->getExistingPropNames();
72 $form = HTMLForm
::factory( 'ooui', [
76 'options' => $propnames,
77 'default' => $propname,
78 'label-message' => 'pageswithprop-prop',
84 'default' => $this->reverse
,
85 'label-message' => 'pageswithprop-reverse',
90 'name' => 'sortbyvalue',
91 'default' => $this->sortByValue
,
92 'label-message' => 'pageswithprop-sortbyvalue',
95 ], $this->getContext() );
96 $form->setMethod( 'get' );
97 $form->setSubmitCallback( [ $this, 'onSubmit' ] );
98 $form->setWrapperLegendMsg( 'pageswithprop-legend' );
99 $form->addHeaderText( $this->msg( 'pageswithprop-text' )->parseAsBlock() );
100 $form->setSubmitTextMsg( 'pageswithprop-submit' );
102 $form->prepareForm();
103 $form->displayForm( false );
104 if ( $propname !== '' && $propname !== null ) {
109 public function onSubmit( $data, $form ) {
110 $this->propName
= $data['propname'];
111 parent
::execute( $data['propname'] );
115 * Return an array of subpages beginning with $search that this special page will accept.
117 * @param string $search Prefix to search for
118 * @param int $limit Maximum number of results to return
119 * @param int $offset Number of pages to skip
120 * @return string[] Matching subpages
122 public function prefixSearchSubpages( $search, $limit, $offset ) {
123 $subpages = array_keys( $this->queryExistingProps( $limit, $offset ) );
124 // We've already limited and offsetted, set to N and 0 respectively.
125 return self
::prefixSearchArray( $search, count( $subpages ), $subpages, 0 );
129 * Disable RSS/Atom feeds
132 function isSyndicated() {
136 public function getQueryInfo() {
138 'tables' => [ 'page_props', 'page' ],
140 'page_id' => 'pp_page',
149 'pp_propname' => $this->propName
,
152 'page' => [ 'JOIN', 'page_id = pp_page' ]
158 function getOrderFields() {
159 $sort = [ 'page_id' ];
160 if ( $this->sortByValue
) {
161 array_unshift( $sort, 'pp_sortkey' );
169 public function sortDescending() {
170 return !$this->reverse
;
175 * @param object $result Result row
178 function formatResult( $skin, $result ) {
179 $title = Title
::newFromRow( $result );
180 $ret = $this->getLinkRenderer()->makeKnownLink( $title );
181 if ( $result->pp_value
!== '' ) {
182 // Do not show very long or binary values on the special page
183 $valueLength = strlen( $result->pp_value
);
184 $isBinary = strpos( $result->pp_value
, "\0" ) !== false;
185 $isTooLong = $valueLength > 1024;
187 if ( $isBinary ||
$isTooLong ) {
189 ->msg( $isBinary ?
'pageswithprop-prophidden-binary' : 'pageswithprop-prophidden-long' )
190 ->params( $this->getLanguage()->formatSize( $valueLength ) );
192 $propValue = Html
::element( 'span', [ 'class' => 'prop-value-hidden' ], $message->text() );
194 $propValue = Html
::element( 'span', [ 'class' => 'prop-value' ], $result->pp_value
);
197 $ret .= $this->msg( 'colon-separator' )->escaped() . $propValue;
203 public function getExistingPropNames() {
204 if ( $this->existingPropNames
=== null ) {
205 $this->existingPropNames
= $this->queryExistingProps();
207 return $this->existingPropNames
;
210 protected function queryExistingProps( $limit = null, $offset = 0 ) {
212 'DISTINCT', 'ORDER BY' => 'pp_propname'
215 $opts['LIMIT'] = $limit;
218 $opts['OFFSET'] = $offset;
221 $res = wfGetDB( DB_REPLICA
)->select(
230 foreach ( $res as $row ) {
231 $propnames[$row->pp_propname
] = $row->pp_propname
;
237 protected function getGroupName() {