Adding Google code to MediaWiki MobileFrontend skin

The following is a super-hacky method of adding Google Adsense banner ads above and below your content as well as add Google Analytics code when a user is on mobile and uses the MobileFrontend skin of your MediaWiki site.

top banner ad bottom banner ad

For MediaWiki version 1.26.0 and MobileFront version 1.0.0, the skin templates for the MobileFrontend extension can be found in public_html/extensions/MobileFrontend/includes/skins. The default skin that the extension uses is called SkinMinerva.php.

First, take your Google Analytics and Adsense code and convert all the single quotes to double quotes.

In SkinMinerva.php, find the getHeaderHtml() function, and replace the following code:

protected function getHeaderHtml() {
  $title = $this->getOutput()->getPageTitle();
  if ( $title ) {
    return Html::rawElement( 'h1', array( 'id' => 'section_0' ), $title );
  }
  return '';
}

to the following:

protected function getHeaderHtml() {
  $title = $this->getOutput()->getPageTitle();
  if ( $title ) {
    $result = 'INSERT AD CODE';
    $result .= Html::rawElement( 'h1', array( 'id' => 'section_0' ),
    $this->getOutput()->getPageTitle() );
    return $result;
  }
  return '';
}

Further down in the file, look for the function prepareMobileFooterLinks(). Replace the following code:

// Generate the licensing text displayed in the footer of each page.
// See Skin::getCopyright for desktop equivalent.
$license = self::getLicense( 'footer' );
if ( isset( $license['link'] ) && $license['link'] ) {
  $licenseText = $this->msg( 'mobile-frontend-copyright' )->rawParams( $license['link'] )->text();
} else {
  $licenseText = '';
}

with the following code template:

// Generate the licensing text displayed in the footer of each page.
// See Skin::getCopyright for desktop equivalent.
$licenseText = 'INSERT AD AND ANALYTICS CODE';

$license = self::getLicense( 'footer' );
if ( isset( $license['link'] ) && $license['link'] ) {
  $licenseText .= $this->msg( 'mobile-frontend-copyright' )->rawParams( $license['link'] )->text();
} else {
  $licenseText .= '';
}

Hope this helps!