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