PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/mediawiki-integration/source/php/mediawiki/includes/SpecialExport.php

https://code.google.com/
PHP | 131 lines | 79 code | 11 blank | 41 comment | 19 complexity | be1ef24326db193b53db6e24b151dd9d MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0
  1. <?php
  2. # Copyright (C) 2003 Brion Vibber <brion@pobox.com>
  3. # http://www.mediawiki.org/
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program; if not, write to the Free Software Foundation, Inc.,
  17. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. # http://www.gnu.org/copyleft/gpl.html
  19. /**
  20. *
  21. * @package MediaWiki
  22. * @subpackage SpecialPage
  23. */
  24. /**
  25. *
  26. */
  27. function wfSpecialExport( $page = '' ) {
  28. global $wgOut, $wgRequest, $wgExportAllowListContributors;
  29. global $wgExportAllowHistory, $wgExportMaxHistory;
  30. $curonly = true;
  31. if( $wgRequest->wasPosted() ) {
  32. $page = $wgRequest->getText( 'pages' );
  33. $curonly = $wgRequest->getCheck( 'curonly' );
  34. $rawOffset = $wgRequest->getVal( 'offset' );
  35. if( $rawOffset ) {
  36. $offset = wfTimestamp( TS_MW, $rawOffset );
  37. } else {
  38. $offset = null;
  39. }
  40. $limit = $wgRequest->getInt( 'limit' );
  41. $dir = $wgRequest->getVal( 'dir' );
  42. $history = array(
  43. 'dir' => 'asc',
  44. 'offset' => false,
  45. 'limit' => $wgExportMaxHistory,
  46. );
  47. $historyCheck = $wgRequest->getCheck( 'history' );
  48. if ( $curonly ) {
  49. $history = WikiExporter::CURRENT;
  50. } elseif ( !$historyCheck ) {
  51. if ( $limit > 0 && $limit < $wgExportMaxHistory ) {
  52. $history['limit'] = $limit;
  53. }
  54. if ( !is_null( $offset ) ) {
  55. $history['offset'] = $offset;
  56. }
  57. if ( strtolower( $dir ) == 'desc' ) {
  58. $history['dir'] = 'desc';
  59. }
  60. }
  61. } else {
  62. // Default to current-only for GET requests
  63. $page = $wgRequest->getText( 'pages', $page );
  64. $historyCheck = $wgRequest->getCheck( 'history' );
  65. if( $historyCheck ) {
  66. $history = WikiExporter::FULL;
  67. } else {
  68. $history = WikiExporter::CURRENT;
  69. }
  70. }
  71. if( !$wgExportAllowHistory ) {
  72. // Override
  73. $history = WikiExporter::CURRENT;
  74. }
  75. $list_authors = $wgRequest->getCheck( 'listauthors' );
  76. if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ;
  77. if( $page != '' ) {
  78. $wgOut->disable();
  79. // Cancel output buffering and gzipping if set
  80. // This should provide safer streaming for pages with history
  81. wfResetOutputBuffers();
  82. header( "Content-type: application/xml; charset=utf-8" );
  83. $pages = explode( "\n", $page );
  84. $db =& wfGetDB( DB_SLAVE );
  85. $exporter = new WikiExporter( $db, $history );
  86. $exporter->list_authors = $list_authors ;
  87. $exporter->openStream();
  88. foreach( $pages as $page ) {
  89. /*
  90. if( $wgExportMaxHistory && !$curonly ) {
  91. $title = Title::newFromText( $page );
  92. if( $title ) {
  93. $count = Revision::countByTitle( $db, $title );
  94. if( $count > $wgExportMaxHistory ) {
  95. wfDebug( __FUNCTION__ .
  96. ": Skipped $page, $count revisions too big\n" );
  97. continue;
  98. }
  99. }
  100. }*/
  101. $exporter->pageByName( $page );
  102. }
  103. $exporter->closeStream();
  104. return;
  105. }
  106. $wgOut->addWikiText( wfMsg( "exporttext" ) );
  107. $titleObj = SpecialPage::getTitleFor( "Export" );
  108. $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalUrl() ) );
  109. $form .= wfOpenElement( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ) ) . '</textarea><br />';
  110. if( $wgExportAllowHistory ) {
  111. $form .= wfCheck( 'curonly', true, array( 'value' => 'true', 'id' => 'curonly' ) );
  112. $form .= wfLabel( wfMsg( 'exportcuronly' ), 'curonly' ) . '<br />';
  113. } else {
  114. $wgOut->addWikiText( wfMsg( 'exportnohistory' ) );
  115. }
  116. $form .= wfHidden( 'action', 'submit' );
  117. $form .= wfSubmitButton( wfMsg( 'export-submit' ) ) . '</form>';
  118. $wgOut->addHtml( $form );
  119. }
  120. ?>