r107939 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107938‎ | r107939 | r107940 >
Date:21:08, 3 January 2012
Author:greg
Status:resolved (Comments)
Tags:
Comment:
Allow new checkbox on Special::Export to export all pages. See bug 10574.
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialExport.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -2271,6 +2271,7 @@
22722272 'export' => array(
22732273 'export',
22742274 'exporttext',
 2275+ 'exportall',
22752276 'exportcuronly',
22762277 'exportnohistory',
22772278 'exportlistauthors',
Index: trunk/phase3/includes/DefaultSettings.php
@@ -4773,6 +4773,11 @@
47744774 */
47754775 $wgExportFromNamespaces = false;
47764776
 4777+/**
 4778+* Whether to allow exporting the entire wiki into a single file
 4779+*/
 4780+$wgExportAllowAll = false;
 4781+
47774782 /** @} */ # end of import/export }
47784783
47794784 /*************************************************************************//**
Index: trunk/phase3/includes/specials/SpecialExport.php
@@ -40,6 +40,7 @@
4141 public function execute( $par ) {
4242 global $wgSitename, $wgExportAllowListContributors, $wgExportFromNamespaces;
4343 global $wgExportAllowHistory, $wgExportMaxHistory, $wgExportMaxLinkDepth;
 44+ global $wgExportAllowAll;
4445
4546 $this->setHeaders();
4647 $this->outputHeader();
@@ -88,6 +89,10 @@
8990 }
9091 }
9192 }
 93+ elseif( $request->getCheck( 'exportall' ) && $wgExportAllowAll ) {
 94+ $this->doExport = true;
 95+ $exportall = true;
 96+ }
9297 elseif( $request->wasPosted() && $par == '' ) {
9398 $page = $request->getText( 'pages' );
9499 $this->curonly = $request->getCheck( 'curonly' );
@@ -165,7 +170,7 @@
166171 $request->response()->header( "Content-disposition: attachment;filename={$filename}" );
167172 }
168173
169 - $this->doExport( $page, $history, $list_authors );
 174+ $this->doExport( $page, $history, $list_authors, $exportall );
170175
171176 return;
172177 }
@@ -183,6 +188,15 @@
184189 $form .= Xml::submitButton( wfMsg( 'export-addns' ), array( 'name' => 'addns' ) ) . '<br />';
185190 }
186191
 192+ if ( $wgExportAllowAll ) {
 193+ $form .= Xml::checkLabel(
 194+ wfMsg( 'exportall' ),
 195+ 'exportall',
 196+ 'exportall',
 197+ $request->wasPosted() ? $request->getCheck( 'exportall' ) : false
 198+ ) . '<br />';
 199+ }
 200+
187201 $form .= Xml::element( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ), $page, false );
188202 $form .= '<br />';
189203
@@ -245,50 +259,58 @@
246260 * @param $history Mixed: one of the WikiExporter history export constants
247261 * @param $list_authors Boolean: Whether to add distinct author list (when
248262 * not returning full history)
 263+ * @param $exportall Boolean: Whether to export everything
249264 */
250 - private function doExport( $page, $history, $list_authors ) {
251 - $pageSet = array(); // Inverted index of all pages to look up
 265+ private function doExport( $page, $history, $list_authors, $exportall ) {
252266
253 - // Split up and normalize input
254 - foreach( explode( "\n", $page ) as $pageName ) {
255 - $pageName = trim( $pageName );
256 - $title = Title::newFromText( $pageName );
257 - if( $title && $title->getInterwiki() == '' && $title->getText() !== '' ) {
258 - // Only record each page once!
259 - $pageSet[$title->getPrefixedText()] = true;
 267+ // If we are grabbing everything, enable full history and ignore the rest
 268+ if ($exportall) {
 269+ $history = WikiExporter::FULL;
 270+ } else {
 271+
 272+ $pageSet = array(); // Inverted index of all pages to look up
 273+
 274+ // Split up and normalize input
 275+ foreach( explode( "\n", $page ) as $pageName ) {
 276+ $pageName = trim( $pageName );
 277+ $title = Title::newFromText( $pageName );
 278+ if( $title && $title->getInterwiki() == '' && $title->getText() !== '' ) {
 279+ // Only record each page once!
 280+ $pageSet[$title->getPrefixedText()] = true;
 281+ }
260282 }
261 - }
262283
263 - // Set of original pages to pass on to further manipulation...
264 - $inputPages = array_keys( $pageSet );
 284+ // Set of original pages to pass on to further manipulation...
 285+ $inputPages = array_keys( $pageSet );
265286
266 - // Look up any linked pages if asked...
267 - if( $this->templates ) {
268 - $pageSet = $this->getTemplates( $inputPages, $pageSet );
269 - }
270 - $linkDepth = $this->pageLinkDepth;
271 - if( $linkDepth ) {
272 - $pageSet = $this->getPageLinks( $inputPages, $pageSet, $linkDepth );
273 - }
 287+ // Look up any linked pages if asked...
 288+ if( $this->templates ) {
 289+ $pageSet = $this->getTemplates( $inputPages, $pageSet );
 290+ }
 291+ $linkDepth = $this->pageLinkDepth;
 292+ if( $linkDepth ) {
 293+ $pageSet = $this->getPageLinks( $inputPages, $pageSet, $linkDepth );
 294+ }
274295
275 - /*
276 - // Enable this when we can do something useful exporting/importing image information. :)
277 - if( $this->images ) ) {
278 - $pageSet = $this->getImages( $inputPages, $pageSet );
279 - }
280 - */
 296+ /*
 297+ // Enable this when we can do something useful exporting/importing image information. :)
 298+ if( $this->images ) ) {
 299+ $pageSet = $this->getImages( $inputPages, $pageSet );
 300+ }
 301+ */
281302
282 - $pages = array_keys( $pageSet );
 303+ $pages = array_keys( $pageSet );
283304
284 - // Normalize titles to the same format and remove dupes, see bug 17374
285 - foreach( $pages as $k => $v ) {
286 - $pages[$k] = str_replace( " ", "_", $v );
 305+ // Normalize titles to the same format and remove dupes, see bug 17374
 306+ foreach( $pages as $k => $v ) {
 307+ $pages[$k] = str_replace( " ", "_", $v );
 308+ }
 309+
 310+ $pages = array_unique( $pages );
287311 }
288312
289 - $pages = array_unique( $pages );
290 -
291313 /* Ok, let's get to it... */
292 - if( $history == WikiExporter::CURRENT ) {
 314+ if( $history == WikiExporter::CURRENT && ! $exportall ) {
293315 $lb = false;
294316 $db = wfGetDB( DB_SLAVE );
295317 $buffer = WikiExporter::BUFFER;
@@ -308,7 +330,10 @@
309331 $exporter->list_authors = $list_authors;
310332 $exporter->openStream();
311333
312 - foreach( $pages as $page ) {
 334+ if ( $exportall ) {
 335+ $exporter->allPages();
 336+ } else {
 337+ foreach( $pages as $page ) {
313338 /*
314339 if( $wgExportMaxHistory && !$this->curonly ) {
315340 $title = Title::newFromText( $page );
@@ -322,15 +347,16 @@
323348 }
324349 }*/
325350 #Bug 8824: Only export pages the user can read
326 - $title = Title::newFromText( $page );
327 - if( is_null( $title ) ) {
328 - continue; #TODO: perhaps output an <error> tag or something.
 351+ $title = Title::newFromText( $page );
 352+ if( is_null( $title ) ) {
 353+ continue; #TODO: perhaps output an <error> tag or something.
 354+ }
 355+ if( !$title->userCan( 'read', $this->getUser() ) ) {
 356+ continue; #TODO: perhaps output an <error> tag or something.
 357+ }
 358+
 359+ $exporter->pageByTitle( $title );
329360 }
330 - if( !$title->userCan( 'read', $this->getUser() ) ) {
331 - continue; #TODO: perhaps output an <error> tag or something.
332 - }
333 -
334 - $exporter->pageByTitle( $title );
335361 }
336362
337363 $exporter->closeStream();
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -3310,6 +3310,7 @@
33113311 To export pages, enter the titles in the text box below, one title per line, and select whether you want the current revision as well as all old revisions, with the page history lines, or the current revision with the info about the last edit.
33123312
33133313 In the latter case you can also use a link, for example [[{{#Special:Export}}/{{MediaWiki:Mainpage}}]] for the page "[[{{MediaWiki:Mainpage}}]]".',
 3314+'exportall' => 'Export all pages',
33143315 'exportcuronly' => 'Include only the current revision, not the full history',
33153316 'exportnohistory' => "----
33163317 '''Note:''' Exporting the full history of pages through this form has been disabled due to performance reasons.",

Follow-up revisions

RevisionCommit summaryAuthorDate
r108901Fix for r107939: PHP Notice: Undefined variable: exportall in includes/speci...ialex14:18, 14 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   07:39, 4 January 2012

Some whitespace issues and please add message documentation.

#Comment by Turnstep (talk | contribs)   21:10, 4 January 2012

Happy to oblige, but can you elaborate on what whitespace issues you see and where I would add documentation?

#Comment by Nikerabbit (talk | contribs)   21:18, 4 January 2012
if ($exportall) {
should be
if ( $exportall ) {

Docs to MessagesQqq.php. Localisation#Message_documentation should help and if not I will explain.

#Comment by Turnstep (talk | contribs)   17:11, 5 January 2012

Thanks, applied in r108151

Status & tagging log