00001 <?php 00010 class DisambiguationsPage extends PageQueryPage { 00011 00012 function getName() { 00013 return 'Disambiguations'; 00014 } 00015 00016 function isExpensive( ) { return true; } 00017 function isSyndicated() { return false; } 00018 00019 00020 function getPageHeader( ) { 00021 return wfMsgExt( 'disambiguations-text', array( 'parse' ) ); 00022 } 00023 00024 function getSQL() { 00025 $dbr = wfGetDB( DB_SLAVE ); 00026 00027 $dMsgText = wfMsgForContent('disambiguationspage'); 00028 00029 $linkBatch = new LinkBatch; 00030 00031 # If the text can be treated as a title, use it verbatim. 00032 # Otherwise, pull the titles from the links table 00033 $dp = Title::newFromText($dMsgText); 00034 if( $dp ) { 00035 if($dp->getNamespace() != NS_TEMPLATE) { 00036 # FIXME we assume the disambiguation message is a template but 00037 # the page can potentially be from another namespace :/ 00038 wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n"); 00039 } 00040 $linkBatch->addObj( $dp ); 00041 } else { 00042 # Get all the templates linked from the Mediawiki:Disambiguationspage 00043 $disPageObj = Title::makeTitleSafe( NS_MEDIAWIKI, 'disambiguationspage' ); 00044 $res = $dbr->select( 00045 array('pagelinks', 'page'), 00046 'pl_title', 00047 array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE, 00048 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()), 00049 __METHOD__ ); 00050 00051 while ( $row = $dbr->fetchObject( $res ) ) { 00052 $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title )); 00053 } 00054 00055 $dbr->freeResult( $res ); 00056 } 00057 00058 $set = $linkBatch->constructSet( 'lb.tl', $dbr ); 00059 if( $set === false ) { 00060 # We must always return a valid sql query, but this way DB will always quicly return an empty result 00061 $set = 'FALSE'; 00062 wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n"); 00063 } 00064 00065 list( $page, $pagelinks, $templatelinks) = $dbr->tableNamesN( 'page', 'pagelinks', 'templatelinks' ); 00066 00067 $sql = "SELECT 'Disambiguations' AS \"type\", pb.page_namespace AS namespace," 00068 ." pb.page_title AS title, la.pl_from AS value" 00069 ." FROM {$templatelinks} AS lb, {$page} AS pb, {$pagelinks} AS la, {$page} AS pa" 00070 ." WHERE $set" # disambiguation template(s) 00071 .' AND pa.page_id = la.pl_from' 00072 .' AND pa.page_namespace = ' . NS_MAIN # Limit to just articles in the main namespace 00073 .' AND pb.page_id = lb.tl_from' 00074 .' AND pb.page_namespace = la.pl_namespace' 00075 .' AND pb.page_title = la.pl_title' 00076 .' ORDER BY lb.tl_namespace, lb.tl_title'; 00077 00078 return $sql; 00079 } 00080 00081 function getOrder() { 00082 return ''; 00083 } 00084 00085 function formatResult( $skin, $result ) { 00086 global $wgContLang; 00087 $title = Title::newFromID( $result->value ); 00088 $dp = Title::makeTitle( $result->namespace, $result->title ); 00089 00090 $from = $skin->link( $title ); 00091 $edit = $skin->link( $title, "(".wfMsgHtml("qbedit").")", array(), array( 'redirect' => 'no', 'action' => 'edit' ) ); 00092 $arr = $wgContLang->getArrow(); 00093 $to = $skin->link( $dp ); 00094 00095 return "$from $edit $arr $to"; 00096 } 00097 } 00098 00102 function wfSpecialDisambiguations() { 00103 list( $limit, $offset ) = wfCheckLimits(); 00104 00105 $sd = new DisambiguationsPage(); 00106 00107 return $sd->doQuery( $offset, $limit ); 00108 }