From 2fce17cedcf13644498b14ed7d6028341d8c9983 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Thu, 12 Mar 2009 13:10:59 +0000 Subject: [PATCH] (bug 17886) Export all pages by namespace. Also cleans up some hard-coded SQL in getPagesFromCategory(). Patch by davidt. --- RELEASE-NOTES | 2 ++ includes/specials/SpecialExport.php | 51 +++++++++++++++++++++++++---- languages/messages/MessagesEn.php | 2 ++ maintenance/language/messages.inc | 2 ++ 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2f1cea29fb..7f8f874df9 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -140,6 +140,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN dynamic dates. * (bug 4582) Provide preference-based autoformatting of unlinked dates with the dateformat parser function. +* (bug 17886) Special:Export now allows you to export a whole namespace (limited to 5000 pages) === Bug fixes in 1.15 === * (bug 16968) Special:Upload no longer throws useless warnings. @@ -260,6 +261,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 17900) Fixed User Groups interface log display after saving groups. * (bug 17897) Fixed string offset error in
 tags
 * (bug 17778) MediaWiki:Catseparator can now have HTML entities
+* Special:Export doesn't use raw SQL queris anymore
 
 == API changes in 1.15 ==
 * (bug 16858) Revamped list=deletedrevs to make listing deleted contributions
diff --git a/includes/specials/SpecialExport.php b/includes/specials/SpecialExport.php
index eebd93c03f..302bdfea08 100644
--- a/includes/specials/SpecialExport.php
+++ b/includes/specials/SpecialExport.php
@@ -62,6 +62,18 @@ class SpecialExport extends SpecialPage {
 				}
 			}
 		}
+		else if( $wgRequest->getCheck( 'addns' ) ) {
+			$page = $wgRequest->getText( 'pages' );
+			$nsindex = $wgRequest->getText( 'nsindex' );
+	
+			if ( $nsindex !== '' && $nsindex !== NULL && $nsindex !== false ) {
+				/**
+				 * Same implementation as above, so same @fixme
+				 */
+				$nspages = $this->getPagesFromNamespace( $nsindex );
+				if ( $nspages ) $page .= "\n" . implode( "\n", $nspages );
+			}		
+		}
 		else if( $wgRequest->wasPosted() && $par == '' ) {
 			$page = $wgRequest->getText( 'pages' );
 			$this->curonly = $wgRequest->getCheck( 'curonly' );
@@ -136,6 +148,10 @@ class SpecialExport extends SpecialPage {
 			'action' => $this->getTitle()->getLocalUrl( 'action=submit' ) ) );
 		$form .= Xml::inputLabel( wfMsg( 'export-addcattext' )	, 'catname', 'catname', 40 ) . ' ';
 		$form .= Xml::submitButton( wfMsg( 'export-addcat' ), array( 'name' => 'addcat' ) ) . '
'; + + $form .= Xml::namespaceSelector( '', null, 'nsindex', wfMsg( 'export-addnstext' ) ) . ' '; + $form .= Xml::submitButton( wfMsg( 'export-addns' ), array( 'name' => 'addns' ) ) . '
'; + $form .= Xml::element( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ), $page, false ); $form .= '
'; @@ -232,20 +248,19 @@ class SpecialExport extends SpecialPage { } } + private function getPagesFromCategory( $title ) { global $wgContLang; $name = $title->getDBkey(); $dbr = wfGetDB( DB_SLAVE ); - - list( $page, $categorylinks ) = $dbr->tableNamesN( 'page', 'categorylinks' ); - $sql = "SELECT page_namespace, page_title FROM $page " . - "JOIN $categorylinks ON cl_from = page_id " . - "WHERE cl_to = " . $dbr->addQuotes( $name ); + $res = $dbr->select( array('page', 'categorylinks' ), + array( 'page_namespace', 'page_title' ), + array('cl_from=page_id', 'cl_to' => $name ), + __METHOD__, array('LIMIT' => '5000')); $pages = array(); - $res = $dbr->query( $sql, __METHOD__ ); while ( $row = $dbr->fetchObject( $res ) ) { $n = $row->page_title; if ($row->page_namespace) { @@ -257,9 +272,31 @@ class SpecialExport extends SpecialPage { } $dbr->freeResult($res); - return $pages; + return $pages; } + private function getPagesFromNamespace( $nsindex ) { + global $wgContLang; + + $dbr = wfGetDB( DB_SLAVE ); + $res = $dbr->select( 'page', array('page_namespace', 'page_title'), + array('page_namespace' => $nsindex), + __METHOD__, array('LIMIT' => '5000') ); + + $pages = array(); + while ( $row = $dbr->fetchObject( $res ) ) { + $n = $row->page_title; + if ($row->page_namespace) { + $ns = $wgContLang->getNsText( $row->page_namespace ); + $n = $ns . ':' . $n; + } + + $pages[] = $n; + } + $dbr->freeResult($res); + + return $pages; + } /** * Expand a list of pages to include templates used in those pages. * @param $inputPages array, list of titles to look up diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 629aeb4b2d..ac63f2b4cf 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2822,6 +2822,8 @@ In the latter case you can also use a link, for example [[{{#Special:Export}}/{{ 'export-submit' => 'Export', 'export-addcattext' => 'Add pages from category:', 'export-addcat' => 'Add', +'export-addnstext' => 'Add pages from namespace:', +'export-addns' => 'Add', 'export-download' => 'Save as file', 'export-templates' => 'Include templates', 'export-pagelinks' => 'Include linked pages to a depth of:', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 1194633361..25dd4b7bb1 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1972,6 +1972,8 @@ $wgMessageStructure = array( 'export-submit', 'export-addcattext', 'export-addcat', + 'export-addnstext', + 'export-addns', 'export-download', 'export-templates', 'export-pagelinks', -- 2.20.1