MediaWiki  REL1_20
SpecialDisambiguations.php
Go to the documentation of this file.
00001 <?php
00029 class DisambiguationsPage extends QueryPage {
00030 
00031         function __construct( $name = 'Disambiguations' ) {
00032                 parent::__construct( $name );
00033         }
00034 
00035         function isExpensive() {
00036                 return true;
00037         }
00038 
00039         function isSyndicated() {
00040                 return false;
00041         }
00042 
00043         function getPageHeader() {
00044                 return $this->msg( 'disambiguations-text' )->parseAsBlock();
00045         }
00046 
00050         function getQueryFromLinkBatch() {
00051                 $dbr = wfGetDB( DB_SLAVE );
00052                 $dMsgText = $this->msg( 'disambiguationspage' )->inContentLanguage()->text();
00053                 $linkBatch = new LinkBatch;
00054 
00055                 # If the text can be treated as a title, use it verbatim.
00056                 # Otherwise, pull the titles from the links table
00057                 $dp = Title::newFromText( $dMsgText );
00058                 if( $dp ) {
00059                         if( $dp->getNamespace() != NS_TEMPLATE ) {
00060                                 # @todo FIXME: We assume the disambiguation message is a template but
00061                                 # the page can potentially be from another namespace :/
00062                                 wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
00063                         }
00064                         $linkBatch->addObj( $dp );
00065                 } else {
00066                                 # Get all the templates linked from the Mediawiki:Disambiguationspage
00067                                 $disPageObj = Title::makeTitleSafe( NS_MEDIAWIKI, 'disambiguationspage' );
00068                                 $res = $dbr->select(
00069                                         array('pagelinks', 'page'),
00070                                         'pl_title',
00071                                         array('page_id = pl_from',
00072                                                 'pl_namespace' => NS_TEMPLATE,
00073                                                 'page_namespace' => $disPageObj->getNamespace(),
00074                                                 'page_title' => $disPageObj->getDBkey()),
00075                                         __METHOD__ );
00076 
00077                                 foreach ( $res as $row ) {
00078                                         $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title ));
00079                                 }
00080                 }
00081                 $set = $linkBatch->constructSet( 'tl', $dbr );
00082 
00083                 if( $set === false ) {
00084                         # We must always return a valid SQL query, but this way
00085                         # the DB will always quickly return an empty result
00086                         $set = 'FALSE';
00087                         wfDebug( "Mediawiki:disambiguationspage message does not link to any templates!\n" );
00088                 }
00089                 return $set;
00090         }
00091 
00092         function getQueryInfo() {
00093                 // @todo FIXME: What are pagelinks and p2 doing here?
00094                 return array (
00095                         'tables' => array(
00096                                 'templatelinks',
00097                                 'p1' => 'page',
00098                                 'pagelinks',
00099                                 'p2' => 'page'
00100                         ),
00101                         'fields' => array(
00102                                 'namespace' => 'p1.page_namespace',
00103                                 'title' => 'p1.page_title',
00104                                 'value' => 'pl_from'
00105                         ),
00106                         'conds' => array(
00107                                 $this->getQueryFromLinkBatch(),
00108                                 'p1.page_id = tl_from',
00109                                 'pl_namespace = p1.page_namespace',
00110                                 'pl_title = p1.page_title',
00111                                 'p2.page_id = pl_from',
00112                                 'p2.page_namespace' => MWNamespace::getContentNamespaces()
00113                         )
00114                 );
00115         }
00116 
00117         function getOrderFields() {
00118                 return array( 'tl_namespace', 'tl_title', 'value' );
00119         }
00120 
00121         function sortDescending() {
00122                 return false;
00123         }
00124 
00131         function preprocessResults( $db, $res ) {
00132                 if ( !$res->numRows() ) {
00133                         return;
00134                 }
00135 
00136                 $batch = new LinkBatch;
00137                 foreach ( $res as $row ) {
00138                         $batch->add( $row->namespace, $row->title );
00139                 }
00140                 $batch->execute();
00141 
00142                 $res->seek( 0 );
00143         }
00144 
00145         function formatResult( $skin, $result ) {
00146                 $title = Title::newFromID( $result->value );
00147                 $dp = Title::makeTitle( $result->namespace, $result->title );
00148 
00149                 $from = Linker::link( $title );
00150                 $edit = Linker::link(
00151                         $title,
00152                         $this->msg( 'parentheses', $this->msg( 'editlink' )->text() )->escaped(),
00153                         array(),
00154                         array( 'redirect' => 'no', 'action' => 'edit' )
00155                 );
00156                 $arr = $this->getLanguage()->getArrow();
00157                 $to = Linker::link( $dp );
00158 
00159                 return "$from $edit $arr $to";
00160         }
00161 }