What is the mechanism used to control how Drupal pages are rendered?
Aaron is right that you'd likely want to handle much of this at the theme layer. You'd want to familiarize yourself with how drupal handles templates.

As for the actual creation of a page in code, this page does a pretty good outline of a method. I've not done this myself, but it reads correctly.

You'll first want to understand how to build a module. The basics are, you need a mymodule folder, and a mymodule.module file and mymodule.info file. Anywhere you see a resource that says to use hook_some_function, you're going to replace hook with mymodule.

The nuts and bolts of the page above outline:

-- Implementing of hook_menu (in this instance, the module's name is starting_drupal_dev)

/**
* Implements hook_menu().
*/
function starting_drupal_dev_menu() {
  $items['starting_drupal_dev/custom'] = array(
    'title' =&gt; 'Custom page',
    'page callback' =&gt; 'starting_drupal_dev_custom',
    'access arguments' =&gt; array('access content'),
  );

  return $items;
}


-- Using the custom function starting_drupal_dev_custom to define how the page renders

/**
* Custom callback function.
*/
function starting_drupal_dev_custom() {
  $content['raw_markup'] = array(
    '#type' =&gt; 'markup',
    '#markup' =&gt; '&lt;p&gt;Hello world&lt;/p&gt;',
  );

  return $content;
}


You could then assign your various database queries to variables in order to render them within #markup.

Again, I've not used this particular method myself, but it seems to me that you could at least use this as a starting point for what you're trying to do. Not sure whether or not you could combine this method with theme templates for layout or not. Maybe somebody else could chime in with regard to that.

As for your final question, NEVER (usually) HACK CORE. Handle everything in modules and themes.