Extension:Prefix Security/PrefixAdministration v1.1.0


 * Copy the code into a file (PrefixAdministration.php)

      " );			}

if( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
 * 1) GET REQUESTS
 * 1) GET REQUESTS

# GET REQUEST: delete prefix - question #============================================#				if( $wgRequest->getText( 'action' ) == "delete_prefixed_page" ) { $page_prefix = $wgRequest->getText( 'page_prefix' ); $wgOut->addWikiText( wfMsg( 'prefixadministration-delete-prefix-question', $page_prefix ) ); $wgOut->addHTML( "				 						  																			" ); }

# GET REQUEST: edit prefix #============================================#				if( $wgRequest->getText( 'action' ) == "edit_prefixed_page" ) { $this->edit_prefix( "", $textbox_width ); }				# GET REQUEST: delete selected users or groups - question #============================================#				if( $wgRequest->getText( 'remove_user' ) != "" || $wgRequest->getText( 'remove_group' ) != "" ) { $page_prefix = $wgRequest->getText( 'page_prefix' ); $wgOut->addHTML( "				 						  						  							" );

// users if( $operand == 0 ) { $remove_user = $wgRequest->getText( 'remove_user' ); $wgOut->addWikiText( wfMsg( 'prefixadministration-delete-users-and-groups-question', "username", $wgUser->whoIs( $remove_user ) ) ); $wgOut->addHTML( "				 									" ); }					// groups else { $remove_group = $wgRequest->getText( 'remove_group' ); $wgOut->addWikiText( wfMsg( 'prefixadministration-delete-users-and-groups-question', "group", $remove_group ) ); $wgOut->addHTML( "				 									" ); }

$wgOut->addHTML( "												<input type='submit' name='delete_items_no' value='No'>					" ); }			        			}

if ( $wgRequest->wasPosted ) {
 * 1) POST REQUESTS
 * 1) POST REQUESTS

# POST REQUEST: add prefix #============================================#				if( $wgRequest->getText( 'add_prefix' ) != "" ) { $page_prefix = $wgRequest->getText( 'new_prefix' ); if( $operand == -1 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-pageprefix-warning', $page_prefix ) ); $this->edit_prefix( $page_prefix, $textbox_width ); return; }					else if( $operand == 0 ) { $this->edit_prefix( $page_prefix, $textbox_width ); return; }					else if( $operand == 1 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-pageprefix-exist', $page_prefix ) ); return; }					else if( $operand == 2 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-pageprefix-notexist', $page_prefix ) ); return; }					else if( $operand == 3 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-user-or-group-missing', "prefix" ) ); return; }				}				# POST REQUEST: available prefixes #============================================#				if( $wgRequest->getText( 'avail_prefix' ) != "" ) { $new_prefix = strtolower( $wgRequest->getText( 'new_prefix' ) ); if( strlen( $new_prefix ) > 0 ) { $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->query( "							SELECT page_namespace, page_title 							FROM ".$this->DatabasePrefixExists."page 							WHERE page_namespace < 8						" ); $count = $dbr->numRows( $res ); if( $count > 0 ) { $exist = 0; $pages = array; while( $row = $dbr->fetchObject( $res ) ) { if( strtolower( substr( $row->page_title, 0, strlen( $new_prefix ) ) ) == $new_prefix ) { $pages[] = $row->page_title; $exist++; }							}							if( $exist > 0 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-available-prefixes', $new_prefix ) ); foreach( $pages as $page ) $wgOut->addWikiText( "* ".$page ); }							else { $wgOut->addWikiText( wfMsg( 'prefixadministration-available-prefixes-notexist', $new_prefix ) ); }						}						else { $wgOut->addWikiText( "* There are no pages defined in the database !" ); }					}					else { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-user-or-group-missing', "prefix" ) ); }				}

# POST REQUEST: all pages #============================================#				if( $wgRequest->getText( 'all_pages' ) != "" ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-all-pages' ) ); $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->query( "						SELECT page_namespace, page_title 						FROM ".$this->DatabasePrefixExists."page 						WHERE page_namespace < 8					" ); if( $dbr->numRows( $res ) > 0 ) { while( $row = $dbr->fetchObject( $res ) ) { $wgOut->addWikiText( "* ".$row->page_title ); }					}					else { $wgOut->addWikiText( "* There are no user pages found !" ); }				}

# POST REQUEST: delete prefix - yes #============================================#				if( $wgRequest->getText( 'delete_prefixed_page_yes' ) != "" ) { $page_prefix = $wgRequest->getText( 'page_prefix' ); $wgOut->addWikiText( wfMsg( 'prefixadministration-delete-prefix-deleted', $page_prefix ) ); return; }

# POST REQUEST: edit prefix #============================================#				if( $wgRequest->getText( 'edit_prefixed_page' ) != "" ) { $this->edit_prefix( "", $textbox_width ); }

# POST REQUEST: add user #============================================#				if( $wgRequest->getText( 'add_user' ) != "" ) { $user_name = $wgRequest->getText( 'add_user_or_group_name' ); $page_prefix = strlen( $wgRequest->getText( 'page_prefix' ) ) > 0 ? $wgRequest->getText( 'page_prefix' ) : "other pages"; if( $operand == 0 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-user-or-group-successful', "user name", $user_name, $page_prefix ) ); return; }					else if( $operand == 1 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-user-or-group-successful', "user name", $user_name, $page_prefix ) ); return; }					else if( $operand == 2 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-user-or-group-exist', "user name", $user_name, $page_prefix ) ); return; }					else if( $operand == 3 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-user-or-group-not-exist', "user name", $user_name ) ); return; }					else if( $operand == 4 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-user-or-group-missing', "user" ) ); return; }				}

# POST REQUEST: add group #============================================#				if( $wgRequest->getText( 'add_group' ) != "" ) { $page_prefix = strlen( $wgRequest->getText( 'page_prefix' ) ) > 0 ? $wgRequest->getText( 'page_prefix' ) : "other pages"; if( $operand == 0 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-user-or-group-successful', "group", $group_name, $page_prefix ) ); return; }					else if( $operand == 1 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-user-or-group-exist', "group", $group_name, $page_prefix ) ); return; }					else if( $operand == 2 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-user-or-group-not-exist', "group", $group_name ) ); return; }					else if( $operand == 3 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-user-or-group-missing', "group" ) ); return; }				}

# POST REQUEST: find user or group #============================================#				if( $wgRequest->getText( 'find_user_or_group' ) != "" ) { $to_find = $wgRequest->getText( 'add_user_or_group_name' ); if( strlen($to_find) > 0 ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-edit-find-user-or-group-list' ) ); # users #=========================				 	  	$dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->query( "SELECT user_name FROM ".$this->DatabasePrefixExists."user" ); $finded_array = array; $num = 0; while( $row = $dbr->fetchObject( $res ) ) { $finded = $row->user_name; if( $to_find == substr( $finded, 0, strlen( $to_find ) ) ) { $finded_array[] = $finded; $num++; }						}						$wgOut->addWikiText( " Users: " ); if( $num > 0 ) { foreach( $finded_array as $finded ) { $wgOut->addWikiText( "*".$finded ); }						}						else { $wgOut->addWikiText( "* No user matches search criteria." ); }						# groups #=========================					   $res = $dbr->query( "							SELECT DISTINCT ug_group 							FROM ".$this->DatabasePrefixExists."user_groups						" ); $finded_array = array; $num = 0; while( $row = $dbr->fetchObject( $res ) ) { $finded = $row->ug_group; if( $to_find == substr( $finded, 0, strlen( $to_find ) ) ) { $finded_array[] = $finded; $num++; }						}						$wgOut->addWikiText( " Groups: " ); if( $num > 0 ) { foreach( $finded_array as $finded ) { $wgOut->addWikiText( "*".$finded ); }						}						else { $wgOut->addWikiText( "* No group matches search criteria." ); return; }					}					else { $wgOut->addWikiText( wfMsg( 'prefixadministration-add-user-or-group-missing', "user or group" ) ); return; }				}

# POST REQUEST: save settings #============================================#				if( $wgRequest->getText( 'save_settings' ) != "" ) { $wgOut->addWikiText( wfMsg( 'prefixadministration-save-settings-success' ) ); return; }			}		}

/**		 * Function: edit_prefix * - Creates edit area upon edit button click * 		 * @param $page_prefix: String prefix name * @param $textbox_width: String size of textbox */		function edit_prefix( $page_prefix = "", $textbox_width = "size='20'" ) { global $wgTitle; global $wgOut; global $wgRequest; global $wgGroupPermissions;

global $wgArticlePath; $server_param = strstr( $wgArticlePath, "?" ) ? "&" : "?";

$action = $wgTitle->escapeLocalURL; if( $page_prefix == "" ) $page_prefix = $wgRequest->getText( 'page_prefix' ); if( $page_prefix != "" ) { $wgOut->addHTML( "					 Settings for Page Prefix \"".$page_prefix."\" 			" ); }		/**		 * Function: canAdministrate * - Retrieves username listed in $wgGroupPermissions['logged']['prefixAdministration'] array * - If this array does not exist then only Sysops can Administrate */		function canAdministrate { global $wgUser; global $wgOut; global $wgGroupPermissions;

if( isset( $wgGroupPermissions['logged']['prefixAdministration'] ) ) { $username = $wgUser->whoIs( $wgUser->getId ); if( in_array( $username, $wgGroupPermissions['logged']['prefixAdministration'] ) ) return true; else if( !$wgUser->isAllowed("userrights") ) return false; }		 	else { if( !$wgUser->isAllowed("userrights") ) { return false; }			}			return true; }

/**		 * Function: DatabasePrefixExists * - Returns the database table prefix if exist, else returns "" */		function DatabasePrefixExists { global $wgGroupPermissions; if( isset( $wgGroupPermissions['logged']['databasePrefix'] ) ) return $wgGroupPermissions['logged']['databasePrefix']; return ""; }	} }

else { echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" ); die( -1 ); }

?>