Extension talk:Uniwiki Authors/vpovilaitis

 __FILE__,	'name'           => 'Authors',	'author'         => array( 'Merrick Schaefer', 'Mark Johnston', 'Evan Wheeler', 'Adam Mckaig (at UNICEF)', 'Vitas Povilaitis' ),	'url'            => 'https://www.mediawiki.org/wiki/Extension:Uniwiki_Authors',	'descriptionmsg' => 'authors-desc', );

$wgExtensionMessagesFiles['Authors'] = dirname( __FILE__ ). '/Authors.i18n.php';

/* HOOKS  */ $wgHooks['OutputPageBeforeHTML'][] = "UW_Authors_List";

function UW_Authors_List ( &$out, &$text ) { global $wgTitle, $wgRequest, $wgShowAuthorsNamespaces, $wgShowAuthors, $wgShowAuthorsPercent, $wgShowAuthorsAddBytes;

/* do nothing if the option is disabled * (but why would the extension be enabled?) */ if ( !$wgShowAuthors ) return true;

// only build authors on namespaces in $wgShowAuthorsNamespaces if ( !in_array ( $wgTitle->getNamespace, $wgShowAuthorsNamespaces ) ) return true;

/* get the contribs from the database (don't use the default	 * MediaWiki one since it ignores the current user) */ $article = new Article ( $wgTitle ); $contribs = array; $usrs = array; $lens = 0; $db = wfGetDB ( DB_MASTER ); $rev_table = $db->tableName ( "revision" ); $user_table = $db->tableName ( "user" );

$sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp, MAX(rev_len) as rev_len		FROM $rev_table LEFT JOIN $user_table ON rev_user = user_id		WHERE rev_page = {$article->getID}		ORDER BY timestamp DESC"; /*GROUP BY rev_user, rev_user_text, user_real_name*/

$results = $db->query ( $sql, __METHOD__ ); while ( $line = $db->fetchObject ( $results ) ) { if ( $lens == 0 ) { if ( !in_array( $line->rev_user, $usrs ) ) { $usrs[] = $line->rev_user; $contribs[] = array(			$line->rev_user,			$line->rev_user_text,			$line->user_real_name		); };	  }	   else if ((($line->rev_len * 100)/ $lens - 100 > $wgShowAuthorsPercent) || (($line->rev_len - $lens) > $wgShowAuthorsAddBytes)) { if ( !in_array( $line->rev_user, $usrs ) ) { $usrs[] = $line->rev_user; $contribs[] = array(			$line->rev_user,			$line->rev_user_text,			$line->user_real_name		); };	  };	   $lens = $line->rev_len; }

$db->freeResult ( $results );

// return if there are no authors if ( sizeof ( $results ) <= 0 ) return true;

// now build a sensible authors display in HTML

$authors = "\n ". " " . wfMsg( 'authors_authors' ). " " .		""; $anons = 0; foreach ( $contribs as $author ) { $id      = $author[0]; $username = $author[1]; $realname = $author[2]; $authorLinker = new Linker; if ( $id != "0" ) { // user with an id // FIME: broken. Incompatible with 1.14. Method creditLink was renamed and changed. $author_link = $authorLinker->userLink( $id, $username ); $authors .= "$author_link - $realname"; } else { // anonymous $anons++; }	}	// add the anonymous entries if ( $anons > 0 ) $authors .= "". wfMsg( 'authors_anonymous' ). ""; $authors .= " ";

$text .= $authors; return true; }