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