Open main menu

Extension:ProxyPage

MediaWiki extensions manual
OOjs UI icon advanced.svg
ProxyPage
Release status: stable
Implementation User interface
Author(s) (Cchanteptalk)
MediaWiki 1.13.x - 1.16.0
License No license specified
Download No link
Example http://www.nozicaa.com/fr/page.content/Contact
Translate the ProxyPage extension if it is available at translatewiki.net
Check usage and version matrix.

Contents

What can this extension do?Edit

Displays content from specified HTTP, without redirect.

UsageEdit

Just add following code as standalone proxy page text:

<!-- ProxyURL: http://my.target.url/page -->

… or …

<!-- ProxyURL: Another wiki page title -->

InstallationEdit

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/ProxyPage/ProxyPage.setup.php");

CodeEdit

Put following code as $IP/extensions/ProxyPage/ProxyPage.setup.php.

<?php
if( !defined( 'MEDIAWIKI' ) ) {
    echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
    die( 1 );
}

$wgExtensionCredits['interface'][] = array( 
    'name' => 'ProxyPage', 
    'author' => 'Cedric Chantepie', 
    'description' => 'Page that display content from proxified HTTP url',
);

$wgHooks['OutputPageBeforeHTML'][] = 'displayHttpContent';

/**
 * Add head element for ProxyPage integration
 */
function displayHttpContent(&$out, &$text) {
  global $wgArticle, $wgTitle;
  $content = NULL;
  $pos = FALSE;

  if (!isset($wgTitle) || !$wgTitle->exists() ||
      !isset($wgArticle) || 
      ($content = $wgArticle->getContent()) == NULL ||
      ($pos = strpos($content, "<!-- ProxyURL:")) === FALSE) {

    return true;
  }

  // ---

  $href = NULL;
  $pos += 14;
  $end = strpos($content, '-->', $pos);

  if ($end == 0) {
    return true;
  }

  $href = trim( substr($content, $pos, $end-$pos) );

  if (strpos($href, 'http://') === FALSE) {
    $t = Title::newFromText($href);
    $href = $t->escapeFullURL();

    if (strpos($href, '?') === FALSE) {
      $href .= "?proxy=" . urlencode( $wgTitle->getFullText() );
    } else {
      $href .= "&proxy=" . urlencode( $wgTitle->getFullText() );
    }
  }

  $out->disable();

  echo file_get_contents($href);

  return true;
}
?>