r29969 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29968‎ | r29969 | r29970 >
Date:07:14, 20 January 2008
Author:brion
Status:old
Tags:
Comment:
* Add option to include templates in Special:Export.
(An option to *expand* templates might be helpful too.)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/SpecialExport.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialExport.php
@@ -50,6 +50,38 @@
5151 }
5252
5353 /**
 54+ * Expand a list of pages to include templates used in those pages.
 55+ * @input $pages string newline-separated list of page titles
 56+ * @output string newline-separated list of page titles
 57+ */
 58+function wfExportGetTemplates( $pages ) {
 59+ $pageList = array_unique( array_filter( explode( "\n", $pages ) ) );
 60+ $output = array();
 61+ $dbr = wfGetDB( DB_SLAVE );
 62+ foreach( $pageList as $page ) {
 63+ $title = Title::newFromText( $page );
 64+ $output[$title->getPrefixedText()] = true;
 65+ if( $title ) {
 66+ /// @fixme May or may not be more efficient to batch these
 67+ /// by namespace when given multiple input pages.
 68+ $result = $dbr->select(
 69+ array( 'page', 'templatelinks' ),
 70+ array( 'tl_namespace', 'tl_title' ),
 71+ array(
 72+ 'page_namespace' => $title->getNamespace(),
 73+ 'page_title' => $title->getDbKey(),
 74+ 'page_id=tl_from' ),
 75+ __METHOD__ );
 76+ foreach( $result as $row ) {
 77+ $template = Title::makeTitle( $row->tl_namespace, $row->tl_title );
 78+ $output[$template->getPrefixedText()] = true;
 79+ }
 80+ }
 81+ }
 82+ return implode( "\n", array_keys( $output ) );
 83+}
 84+
 85+/**
5486 *
5587 */
5688 function wfSpecialExport( $page = '' ) {
@@ -66,6 +98,11 @@
6799 if ( $catname !== '' && $catname !== NULL && $catname !== false ) {
68100 $t = Title::makeTitleSafe( NS_CATEGORY, $catname );
69101 if ( $t ) {
 102+ /**
 103+ * @fixme This can lead to hitting memory limit for very large
 104+ * categories. Ideally we would do the lookup synchronously
 105+ * during the export in a single query.
 106+ */
70107 $catpages = wfExportGetPagesFromCategory( $t );
71108 if ( $catpages ) $page .= "\n" . implode( "\n", $catpages );
72109 }
@@ -123,6 +160,10 @@
124161
125162 $list_authors = $wgRequest->getCheck( 'listauthors' );
126163 if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ;
 164+
 165+ if( $wgRequest->getCheck( 'templates' ) ) {
 166+ $page = wfExportGetTemplates( $page );
 167+ }
127168
128169 if ( $doexport ) {
129170 $wgOut->disable();
@@ -188,6 +229,7 @@
189230 } else {
190231 $wgOut->addHtml( wfMsgExt( 'exportnohistory', 'parse' ) );
191232 }
 233+ $form .= Xml::checkLabel( wfMsg( 'export-templates' ), 'templates', 'wpExportTemplates', false ) . '<br />';
192234 $form .= Xml::checkLabel( wfMsg( 'export-download' ), 'wpDownload', 'wpDownload', true ) . '<br />';
193235
194236 $form .= Xml::submitButton( wfMsg( 'export-submit' ) );
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2261,6 +2261,7 @@
22622262 'export-addcattext' => 'Add pages from category:',
22632263 'export-addcat' => 'Add',
22642264 'export-download' => 'Save as file',
 2265+'export-templates' => 'Include templates',
22652266
22662267 # Namespace 8 related
22672268 'allmessages' => 'System messages',
Index: trunk/phase3/RELEASE-NOTES
@@ -135,6 +135,7 @@
136136 * Support redirects in image namespace
137137 * (bug 10049) Prefix index search and namespaces in Special:Withoutinterwiki
138138 * (bug 12668) Support for custom iPhone bookmark icon via $wgAppleTouchIcon
 139+* Add option to include templates in Special:Export.
139140
140141
141142 === Bug fixes in 1.12 ===

Status & tagging log