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