Jump to content

Manual:LocalSettings.php snippets

From mediawiki.org

Here are some snippets you can add to LocalSettings.php to accomplish various tasks. A "snippet" is usually a short hook function, typically less than 20 lines, such that it wouldn't be worth bothering to implement it as an extension.

Snippets

[edit]

SecretSpies

[edit]

You may wish to enable some users to view deleted articles without making it evident to everyone who these users are. This would be implemented by:

$wgHooks['UserGetRights'][] = 'secretSpies';
$wgSecretSpies = array( // Users allowed to view deleted history entries and deleted revision text
	'AldrichAmes',
	'RobertHanssen'
);

// Allow secret spies to view deleted history entries and deleted revision text
function secretSpies( $user, &$aRights ) {
	global $wgSecretSpies;
	if ( in_array( $user->getName(), $wgSecretSpies ) ) {
		$aRights[] = 'deletedhistory';
		$aRights[] = 'deletedtext';
	}
	return true;
}

Twitter-optimized recent changes feed

[edit]

(See phabricator:T132840)

$wgHooks['ChangesListSpecialPageQuery'][] = 'onChangesListSpecialPageQuery';
function onChangesListSpecialPageQuery( $name, &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ) {
	global $wgTitle;
	if (
	    $wgTitle != 'Special:Badtitle/dummy title for API calls set in api.php'
	    || $name != 'Recentchanges'
	) {
		return true;
	}
	if ( !in_array( 'page', $tables ) ) {
		$tables[] = 'page';

	}
	if ( !in_array( 'page_latest', $fields ) ) {
		$fields[] = 'page_latest';
	}
	if ( !in_array( 'page_is_redirect', $fields ) ) {
		$fields[] = 'page_is_redirect';
	}
	if ( !isset( $join_conds['page'] ) ) {
		$join_conds['page'] = array( 'LEFT JOIN', 'rc_cur_id=page_id' );
	}
	if ( !isset( $conds['page_is_redirect'] ) ) {
		$conds['page_is_redirect'] = 0;
	}
	if ( !isset( $conds['rc_patrolled'] ) ) {
		$conds['rc_patrolled'] = 1;
	}
	if ( !isset( $conds['rc_new'] ) ) {
		$conds['rc_new'] = 1;
	}
	if ( !isset( $conds['rc_namespace'] ) ) {
		$conds['rc_namespace'] = 0;
	}
	return true;
}