MediaWiki
REL1_22
|
00001 <?php 00031 class SpecialPagesWithProp extends QueryPage { 00032 private $propName = null; 00033 00034 function __construct( $name = 'PagesWithProp' ) { 00035 parent::__construct( $name ); 00036 } 00037 00038 function isCacheable() { 00039 return false; 00040 } 00041 00042 function execute( $par ) { 00043 $this->setHeaders(); 00044 $this->outputHeader(); 00045 $this->getOutput()->addModuleStyles( 'mediawiki.special.pagesWithProp' ); 00046 00047 $request = $this->getRequest(); 00048 $propname = $request->getVal( 'propname', $par ); 00049 00050 $dbr = wfGetDB( DB_SLAVE ); 00051 $res = $dbr->select( 00052 'page_props', 00053 'pp_propname', 00054 '', 00055 __METHOD__, 00056 array( 'DISTINCT', 'ORDER BY' => 'pp_propname' ) 00057 ); 00058 $propnames = array(); 00059 foreach ( $res as $row ) { 00060 $propnames[$row->pp_propname] = $row->pp_propname; 00061 } 00062 00063 $form = new HTMLForm( array( 00064 'propname' => array( 00065 'type' => 'selectorother', 00066 'name' => 'propname', 00067 'options' => $propnames, 00068 'default' => $propname, 00069 'label-message' => 'pageswithprop-prop', 00070 'required' => true, 00071 ), 00072 ), $this->getContext() ); 00073 $form->setMethod( 'get' ); 00074 $form->setSubmitCallback( array( $this, 'onSubmit' ) ); 00075 $form->setWrapperLegendMsg( 'pageswithprop-legend' ); 00076 $form->addHeaderText( $this->msg( 'pageswithprop-text' )->parseAsBlock() ); 00077 $form->setSubmitTextMsg( 'pageswithprop-submit' ); 00078 00079 $form->prepareForm(); 00080 $form->displayForm( false ); 00081 if ( $propname !== '' && $propname !== null ) { 00082 $form->trySubmit(); 00083 } 00084 } 00085 00086 public function onSubmit( $data, $form ) { 00087 $this->propName = $data['propname']; 00088 parent::execute( $data['propname'] ); 00089 } 00090 00095 function isSyndicated() { 00096 return false; 00097 } 00098 00099 function getQueryInfo() { 00100 return array( 00101 'tables' => array( 'page_props', 'page' ), 00102 'fields' => array( 00103 'page_id' => 'pp_page', 00104 'page_namespace', 00105 'page_title', 00106 'page_len', 00107 'page_is_redirect', 00108 'page_latest', 00109 'pp_value', 00110 ), 00111 'conds' => array( 00112 'page_id = pp_page', 00113 'pp_propname' => $this->propName, 00114 ), 00115 'options' => array() 00116 ); 00117 } 00118 00119 function getOrderFields() { 00120 return array( 'page_id' ); 00121 } 00122 00128 function formatResult( $skin, $result ) { 00129 $title = Title::newFromRow( $result ); 00130 $ret = Linker::link( $title, null, array(), array(), array( 'known' ) ); 00131 if ( $result->pp_value !== '' ) { 00132 // Do not show very long or binary values on the special page 00133 $valueLength = strlen( $result->pp_value ); 00134 $isBinary = strpos( $result->pp_value, "\0" ) !== false; 00135 $isTooLong = $valueLength > 1024; 00136 00137 if ( $isBinary || $isTooLong ) { 00138 $message = $this 00139 ->msg( $isBinary ? 'pageswithprop-prophidden-binary' : 'pageswithprop-prophidden-long' ) 00140 ->params( $this->getLanguage()->formatSize( $valueLength ) ); 00141 00142 $propValue = Html::element( 'span', array( 'class' => 'prop-value-hidden' ), $message->text() ); 00143 } else { 00144 $propValue = Html::element( 'span', array( 'class' => 'prop-value' ), $result->pp_value ); 00145 } 00146 00147 $ret .= $this->msg( 'colon-separator' )->escaped() . $propValue; 00148 } 00149 00150 return $ret; 00151 } 00152 00153 protected function getGroupName() { 00154 return 'pages'; 00155 } 00156 }