MediaWiki r13289 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r13288‎ | r13289 (on ViewVC)‎ | r13290 >
Date:08:50, 23 March 2006
Author:magnus_manske
Status:old
Tags:
Comment:
Special:Export contributor list back in (default:off)
Set $wgExportAllowListContributors=true to turn it on
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/Export.php
===================================================================
--- trunk/phase3/includes/Export.php	(revision 13288)
+++ trunk/phase3/includes/Export.php	(revision 13289)
@@ -40,6 +40,10 @@
  * @subpackage SpecialPage
  */
 class WikiExporter {
+	
+	var $list_authors = false ; # Return distinct author list (when not returning full history)
+	var $author_list = "" ;
+	
 	/**
 	 * If using MW_EXPORT_STREAM to stream a large amount of data,
 	 * provide a database connection which is not managed by
@@ -133,6 +137,30 @@
 
 	// -------------------- private implementation below --------------------
 
+	# Generates the distinct list of authors of an article
+	# Not called by default (depends on $this->list_authors)
+	# Can be set by Special:Export when not exporting whole history
+	function do_list_authors ( $page , $revision , $cond ) {
+		$fname = "do_list_authors" ;
+		wfProfileIn( $fname );
+		$this->author_list = "<contributors>";
+		$sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision} WHERE page_id=rev_page AND " . $cond ;
+		$result = $this->db->query( $sql, $fname );
+		$resultset = $this->db->resultObject( $result );
+		while( $row = $resultset->fetchObject() ) {
+			$this->author_list .= "<contributor>" . 
+				"<username>" . 
+				htmlentities( $row->rev_user_text )  . 
+				"</username>" . 
+				"<id>" . 
+				$row->rev_user .
+				"</id>" . 
+				"</contributor>";
+		}
+		wfProfileOut( $fname );
+		$this->author_list .= "</contributors>";
+	}
+
 	function dumpFrom( $cond = '' ) {
 		$fname = 'WikiExporter::dumpFrom';
 		wfProfileIn( $fname );
@@ -140,10 +168,13 @@
 		$page     = $this->db->tableName( 'page' );
 		$revision = $this->db->tableName( 'revision' );
 		$text     = $this->db->tableName( 'text' );
-
+		
 		if( $this->history == MW_EXPORT_FULL ) {
 			$join = 'page_id=rev_page';
 		} elseif( $this->history == MW_EXPORT_CURRENT ) {
+			if ( $this->list_authors && $cond != '' )  { // List authors, if so desired
+				$this->do_list_authors ( $page , $revision , $cond );
+			}
 			$join = 'page_id=rev_page AND page_latest=rev_id';
 		} else {
 			wfProfileOut( $fname );
@@ -179,6 +210,10 @@
 		$result = $this->db->query( $sql, $fname );
 		$wrapper = $this->db->resultObject( $result );
 		$this->outputStream( $wrapper );
+		
+		if ( $this->list_authors ) {
+			$this->outputStream( $wrapper );
+		}
 
 		if( $this->buffer == MW_EXPORT_STREAM ) {
 			$this->db->bufferResults( $prev );
@@ -218,7 +253,7 @@
 			$this->sink->writeRevision( $row, $output );
 		}
 		if( isset( $last ) ) {
-			$output = $this->writer->closePage();
+			$output = $this->author_list . $this->writer->closePage();
 			$this->sink->writeClosePage( $output );
 		}
 		$resultset->free();
Index: trunk/phase3/includes/SpecialExport.php
===================================================================
--- trunk/phase3/includes/SpecialExport.php	(revision 13288)
+++ trunk/phase3/includes/SpecialExport.php	(revision 13289)
@@ -30,7 +30,7 @@
  *
  */
 function wfSpecialExport( $page = '' ) {
-	global $wgOut, $wgRequest;
+	global $wgOut, $wgRequest, $wgExportAllowListContributors;
 	global $wgExportAllowHistory;
 
 	if( $wgRequest->getVal( 'action' ) == 'submit') {
@@ -44,6 +44,9 @@
 		# Pre-check the 'current version only' box in the UI
 		$curonly = true;
 	}
+	
+	$list_authors = $wgRequest->getCheck( 'listauthors' );
+	if ( !$curonly || !$wgExportAllowListContributors ) $list_authors = false ;
 
 	if( $page != '' ) {
 		$wgOut->disable();
@@ -53,6 +56,7 @@
 		$db =& wfGetDB( DB_SLAVE );
 		$history = $curonly ? MW_EXPORT_CURRENT : MW_EXPORT_FULL;
 		$exporter = new WikiExporter( $db, $history );
+		$exporter->list_authors = $list_authors ;
 		$exporter->openStream();
 		$exporter->pagesByName( $pages );
 		$exporter->closeStream();
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 13288)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 13289)
@@ -1390,6 +1390,7 @@
  * disabled on Wikimedia's sites.
  */
 $wgExportAllowHistory = true;
+$wgExportAllowListContributors = false ;
 
 
 /** Text matching this regular expression will be recognised as spam
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 13288)
+++ trunk/phase3/RELEASE-NOTES	(revision 13289)
@@ -379,6 +379,7 @@
 * JavaScript filter for Special:Allmessages
 * (bug 3047) Don't mention talk pages on Special:Movepage when there isn't one
 * Show links to user page, talk page and contributions page on Special:Newpages
+* Special:Export can now export a list of all contributors to an article (off by default)
 
 Misc.:
 * PHP 4.1 compatibility fix: don't use new_link parameter to mysql_connect

Status & tagging log

  • 01:58, 13 October 2010 ^demon (Talk | contribs) changed the status of r13289 [removed: new added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox