SpecialDisambiguations.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * @file
  4. * @ingroup SpecialPage
  5. */
  6. /**
  7. * @ingroup SpecialPage
  8. */
  9. class DisambiguationsPage extends PageQueryPage {
  10. function getName() {
  11. return 'Disambiguations';
  12. }
  13. function isExpensive( ) { return true; }
  14. function isSyndicated() { return false; }
  15. function getPageHeader( ) {
  16. return wfMsgExt( 'disambiguations-text', array( 'parse' ) );
  17. }
  18. function getSQL() {
  19. $dbr = wfGetDB( DB_SLAVE );
  20. $dMsgText = wfMsgForContent('disambiguationspage');
  21. $linkBatch = new LinkBatch;
  22. # If the text can be treated as a title, use it verbatim.
  23. # Otherwise, pull the titles from the links table
  24. $dp = Title::newFromText($dMsgText);
  25. if( $dp ) {
  26. if($dp->getNamespace() != NS_TEMPLATE) {
  27. # FIXME we assume the disambiguation message is a template but
  28. # the page can potentially be from another namespace :/
  29. wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
  30. }
  31. $linkBatch->addObj( $dp );
  32. } else {
  33. # Get all the templates linked from the Mediawiki:Disambiguationspage
  34. $disPageObj = Title::makeTitleSafe( NS_MEDIAWIKI, 'disambiguationspage' );
  35. $res = $dbr->select(
  36. array('pagelinks', 'page'),
  37. 'pl_title',
  38. array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE,
  39. 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()),
  40. __METHOD__ );
  41. while ( $row = $dbr->fetchObject( $res ) ) {
  42. $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title ));
  43. }
  44. $dbr->freeResult( $res );
  45. }
  46. $set = $linkBatch->constructSet( 'lb.tl', $dbr );
  47. if( $set === false ) {
  48. # We must always return a valid sql query, but this way DB will always quicly return an empty result
  49. $set = 'FALSE';
  50. wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
  51. }
  52. list( $page, $pagelinks, $templatelinks) = $dbr->tableNamesN( 'page', 'pagelinks', 'templatelinks' );
  53. $sql = "SELECT 'Disambiguations' AS \"type\", pb.page_namespace AS namespace,"
  54. ." pb.page_title AS title, la.pl_from AS value"
  55. ." FROM {$templatelinks} AS lb, {$page} AS pb, {$pagelinks} AS la, {$page} AS pa"
  56. ." WHERE $set" # disambiguation template(s)
  57. .' AND pa.page_id = la.pl_from'
  58. .' AND pa.page_namespace = ' . NS_MAIN # Limit to just articles in the main namespace
  59. .' AND pb.page_id = lb.tl_from'
  60. .' AND pb.page_namespace = la.pl_namespace'
  61. .' AND pb.page_title = la.pl_title'
  62. .' ORDER BY lb.tl_namespace, lb.tl_title';
  63. return $sql;
  64. }
  65. function getOrder() {
  66. return '';
  67. }
  68. function formatResult( $skin, $result ) {
  69. global $wgContLang;
  70. $title = Title::newFromID( $result->value );
  71. $dp = Title::makeTitle( $result->namespace, $result->title );
  72. $from = $skin->link( $title );
  73. $edit = $skin->link( $title, "(".wfMsgHtml("qbedit").")", array(), array( 'redirect' => 'no', 'action' => 'edit' ) );
  74. $arr = $wgContLang->getArrow();
  75. $to = $skin->link( $dp );
  76. return "$from $edit $arr $to";
  77. }
  78. }
  79. /**
  80. * Constructor
  81. */
  82. function wfSpecialDisambiguations() {
  83. list( $limit, $offset ) = wfCheckLimits();
  84. $sd = new DisambiguationsPage();
  85. return $sd->doQuery( $offset, $limit );
  86. }