SpecialPrefixindex.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /**
  3. * implements Special:Prefixindex
  4. * @ingroup SpecialPage
  5. */
  6. class SpecialPrefixindex extends SpecialAllpages {
  7. // Inherit $maxPerPage
  8. function __construct(){
  9. parent::__construct( 'Prefixindex' );
  10. }
  11. /**
  12. * Entry point : initialise variables and call subfunctions.
  13. * @param $par String: becomes "FOO" when called like Special:Prefixindex/FOO (default null)
  14. */
  15. function execute( $par ) {
  16. global $wgRequest, $wgOut, $wgContLang;
  17. $this->setHeaders();
  18. $this->outputHeader();
  19. # GET values
  20. $from = $wgRequest->getVal( 'from' );
  21. $prefix = $wgRequest->getVal( 'prefix', '' );
  22. $namespace = $wgRequest->getInt( 'namespace' );
  23. $namespaces = $wgContLang->getNamespaces();
  24. $wgOut->setPagetitle( ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
  25. ? wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
  26. : wfMsg( 'prefixindex' )
  27. );
  28. if( isset( $par ) ){
  29. $this->showPrefixChunk( $namespace, $par, $from );
  30. } elseif( isset( $prefix ) ){
  31. $this->showPrefixChunk( $namespace, $prefix, $from );
  32. } elseif( isset( $from ) ){
  33. $this->showPrefixChunk( $namespace, $from, $from );
  34. } else {
  35. $wgOut->addHTML( $this->namespacePrefixForm( $namespace, null ) );
  36. }
  37. }
  38. /**
  39. * HTML for the top form
  40. * @param integer $namespace A namespace constant (default NS_MAIN).
  41. * @param string $from dbKey we are starting listing at.
  42. */
  43. function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) {
  44. global $wgScript;
  45. $t = $this->getTitle();
  46. $out = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
  47. $out .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
  48. $out .= Xml::hidden( 'title', $t->getPrefixedText() );
  49. $out .= Xml::openElement( 'fieldset' );
  50. $out .= Xml::element( 'legend', null, wfMsg( 'allpages' ) );
  51. $out .= Xml::openElement( 'table', array( 'id' => 'nsselect', 'class' => 'allpages' ) );
  52. $out .= "<tr>
  53. <td class='mw-label'>" .
  54. Xml::label( wfMsg( 'allpagesprefix' ), 'nsfrom' ) .
  55. "</td>
  56. <td class='mw-input'>" .
  57. Xml::input( 'from', 30, str_replace('_',' ',$from), array( 'id' => 'nsfrom' ) ) .
  58. "</td>
  59. </tr>
  60. <tr>
  61. <td class='mw-label'>" .
  62. Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
  63. "</td>
  64. <td class='mw-input'>" .
  65. Xml::namespaceSelector( $namespace, null ) . ' ' .
  66. Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
  67. "</td>
  68. </tr>";
  69. $out .= Xml::closeElement( 'table' );
  70. $out .= Xml::closeElement( 'fieldset' );
  71. $out .= Xml::closeElement( 'form' );
  72. $out .= Xml::closeElement( 'div' );
  73. return $out;
  74. }
  75. /**
  76. * @param integer $namespace (Default NS_MAIN)
  77. * @param string $from list all pages from this name (default FALSE)
  78. */
  79. function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) {
  80. global $wgOut, $wgUser, $wgContLang, $wgLang;
  81. $sk = $wgUser->getSkin();
  82. if (!isset($from)) $from = $prefix;
  83. $fromList = $this->getNamespaceKeyAndText($namespace, $from);
  84. $prefixList = $this->getNamespaceKeyAndText($namespace, $prefix);
  85. $namespaces = $wgContLang->getNamespaces();
  86. if ( !$prefixList || !$fromList ) {
  87. $out = wfMsgWikiHtml( 'allpagesbadtitle' );
  88. } elseif ( !in_array( $namespace, array_keys( $namespaces ) ) ) {
  89. // Show errormessage and reset to NS_MAIN
  90. $out = wfMsgExt( 'allpages-bad-ns', array( 'parseinline' ), $namespace );
  91. $namespace = NS_MAIN;
  92. } else {
  93. list( $namespace, $prefixKey, $prefix ) = $prefixList;
  94. list( /* $fromNs */, $fromKey, $from ) = $fromList;
  95. ### FIXME: should complain if $fromNs != $namespace
  96. $dbr = wfGetDB( DB_SLAVE );
  97. $res = $dbr->select( 'page',
  98. array( 'page_namespace', 'page_title', 'page_is_redirect' ),
  99. array(
  100. 'page_namespace' => $namespace,
  101. 'page_title LIKE \'' . $dbr->escapeLike( $prefixKey ) .'%\'',
  102. 'page_title >= ' . $dbr->addQuotes( $fromKey ),
  103. ),
  104. __METHOD__,
  105. array(
  106. 'ORDER BY' => 'page_title',
  107. 'LIMIT' => $this->maxPerPage + 1,
  108. 'USE INDEX' => 'name_title',
  109. )
  110. );
  111. ### FIXME: side link to previous
  112. $n = 0;
  113. if( $res->numRows() > 0 ) {
  114. $out = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-list-table' ) );
  115. while( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
  116. $t = Title::makeTitle( $s->page_namespace, $s->page_title );
  117. if( $t ) {
  118. $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
  119. $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
  120. ($s->page_is_redirect ? '</div>' : '' );
  121. } else {
  122. $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
  123. }
  124. if( $n % 3 == 0 ) {
  125. $out .= '<tr>';
  126. }
  127. $out .= "<td>$link</td>";
  128. $n++;
  129. if( $n % 3 == 0 ) {
  130. $out .= '</tr>';
  131. }
  132. }
  133. if( ($n % 3) != 0 ) {
  134. $out .= '</tr>';
  135. }
  136. $out .= Xml::closeElement( 'table' );
  137. } else {
  138. $out = '';
  139. }
  140. }
  141. if ( $this->including() ) {
  142. $out2 = '';
  143. } else {
  144. $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
  145. $self = $this->getTitle();
  146. $out2 = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) ) .
  147. '<tr>
  148. <td>' .
  149. $nsForm .
  150. '</td>
  151. <td id="mw-prefixindex-nav-form">' .
  152. $sk->makeKnownLinkObj( $self, wfMsg ( 'allpages' ) );
  153. if( isset( $res ) && $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
  154. $namespaceparam = $namespace ? "&namespace=$namespace" : "";
  155. $out2 = $wgLang->pipeList( array(
  156. $out2,
  157. $sk->makeKnownLinkObj(
  158. $self,
  159. wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title ) ) ),
  160. "from=" . wfUrlEncode( $s->page_title ) .
  161. "&prefix=" . wfUrlEncode( $prefix ) . $namespaceparam )
  162. ) );
  163. }
  164. $out2 .= "</td></tr>" .
  165. Xml::closeElement( 'table' );
  166. }
  167. $wgOut->addHTML( $out2 . $out );
  168. }
  169. }