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