Fixed some @params documentation (includes/[specialpage|specials])
[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
34 function __construct( $name = 'PagesWithProp' ) {
35 parent::__construct( $name );
36 }
37
38 function isCacheable() {
39 return false;
40 }
41
42 function execute( $par ) {
43 $this->setHeaders();
44 $this->outputHeader();
45 $this->getOutput()->addModuleStyles( 'mediawiki.special.pagesWithProp' );
46
47 $request = $this->getRequest();
48 $propname = $request->getVal( 'propname', $par );
49
50 $dbr = wfGetDB( DB_SLAVE );
51 $res = $dbr->select(
52 'page_props',
53 'pp_propname',
54 '',
55 __METHOD__,
56 array( 'DISTINCT', 'ORDER BY' => 'pp_propname' )
57 );
58 $propnames = array();
59 foreach ( $res as $row ) {
60 $propnames[$row->pp_propname] = $row->pp_propname;
61 }
62
63 $form = new HTMLForm( array(
64 'propname' => array(
65 'type' => 'selectorother',
66 'name' => 'propname',
67 'options' => $propnames,
68 'default' => $propname,
69 'label-message' => 'pageswithprop-prop',
70 'required' => true,
71 ),
72 ), $this->getContext() );
73 $form->setMethod( 'get' );
74 $form->setSubmitCallback( array( $this, 'onSubmit' ) );
75 $form->setWrapperLegendMsg( 'pageswithprop-legend' );
76 $form->addHeaderText( $this->msg( 'pageswithprop-text' )->parseAsBlock() );
77 $form->setSubmitTextMsg( 'pageswithprop-submit' );
78
79 $form->prepareForm();
80 $form->displayForm( false );
81 if ( $propname !== '' && $propname !== null ) {
82 $form->trySubmit();
83 }
84 }
85
86 public function onSubmit( $data, $form ) {
87 $this->propName = $data['propname'];
88 parent::execute( $data['propname'] );
89 }
90
91 /**
92 * Disable RSS/Atom feeds
93 * @return bool
94 */
95 function isSyndicated() {
96 return false;
97 }
98
99 function getQueryInfo() {
100 return array(
101 'tables' => array( 'page_props', 'page' ),
102 'fields' => array(
103 'page_id' => 'pp_page',
104 'page_namespace',
105 'page_title',
106 'page_len',
107 'page_is_redirect',
108 'page_latest',
109 'pp_value',
110 ),
111 'conds' => array(
112 'page_id = pp_page',
113 'pp_propname' => $this->propName,
114 ),
115 'options' => array()
116 );
117 }
118
119 function getOrderFields() {
120 return array( 'page_id' );
121 }
122
123 /**
124 * @param Skin $skin
125 * @param object $result Result row
126 * @return string
127 */
128 function formatResult( $skin, $result ) {
129 $title = Title::newFromRow( $result );
130 $ret = Linker::link( $title, null, array(), array(), array( 'known' ) );
131 if ( $result->pp_value !== '' ) {
132 // Do not show very long or binary values on the special page
133 $valueLength = strlen( $result->pp_value );
134 $isBinary = strpos( $result->pp_value, "\0" ) !== false;
135 $isTooLong = $valueLength > 1024;
136
137 if ( $isBinary || $isTooLong ) {
138 $message = $this
139 ->msg( $isBinary ? 'pageswithprop-prophidden-binary' : 'pageswithprop-prophidden-long' )
140 ->params( $this->getLanguage()->formatSize( $valueLength ) );
141
142 $propValue = Html::element( 'span', array( 'class' => 'prop-value-hidden' ), $message->text() );
143 } else {
144 $propValue = Html::element( 'span', array( 'class' => 'prop-value' ), $result->pp_value );
145 }
146
147 $ret .= $this->msg( 'colon-separator' )->escaped() . $propValue;
148 }
149
150 return $ret;
151 }
152
153 protected function getGroupName() {
154 return 'pages';
155 }
156 }