http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99759
Revision: 99759
Author: reedy
Date: 2011-10-14 08:01:47 +0000 (Fri, 14 Oct 2011)
Log Message:
-----------
Documentation
Did some conditional refactoring
Remove some unused variables
Modified Paths:
--------------
trunk/extensions/MobileFrontend/DeviceDetection.php
trunk/extensions/MobileFrontend/MobileFrontend.php
trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php
Modified: trunk/extensions/MobileFrontend/DeviceDetection.php
===================================================================
--- trunk/extensions/MobileFrontend/DeviceDetection.php 2011-10-14 08:00:27 UTC
(rev 99758)
+++ trunk/extensions/MobileFrontend/DeviceDetection.php 2011-10-14 08:01:47 UTC
(rev 99759)
@@ -249,11 +249,18 @@
return $formats;
}
+ /**
+ * @param $formatName
+ * @return array
+ */
public function format( $formatName ) {
$format = $this->availableFormats();
return ( isset( $format[$formatName] ) ) ? $format[$formatName]
: array();
}
+ /**
+ * @return string
+ */
public function testFormatName() {
$testResults = '';
Modified: trunk/extensions/MobileFrontend/MobileFrontend.php
===================================================================
--- trunk/extensions/MobileFrontend/MobileFrontend.php 2011-10-14 08:00:27 UTC
(rev 99758)
+++ trunk/extensions/MobileFrontend/MobileFrontend.php 2011-10-14 08:01:47 UTC
(rev 99759)
@@ -72,12 +72,15 @@
* Make the classes stripped from page content configurable. Each item will
* be stripped from the page. See $itemsToRemove for more info
*/
-$wgMFRemovableClasses = array(
-);
+$wgMFRemovableClasses = array();
# Unit tests
$wgHooks['UnitTestsList'][] = 'efExtMobileFrontendUnitTests';
+/**
+ * @param $files array
+ * @return bool
+ */
function efExtMobileFrontendUnitTests( &$files ) {
$files[] = dirname( __FILE__ ) . '/tests/MobileFrontendTest.php';
return true;
@@ -89,8 +92,7 @@
/**
* @var DOMDocument
*/
- private $doc;
- private $mainPage;
+ private $doc, $mainPage;
public static $messages = array();
@@ -200,6 +202,13 @@
'.nomobile',
);
+ /**
+ * @param $request WebRequest
+ * @param $title Title
+ * @param $output OutputPage
+ * @return bool
+ * @throws HttpError
+ */
public function testCanonicalRedirect( $request, $title, $output ) {
global $wgUsePathInfo, $wgMobileDomain;
$xDevice = isset( $_SERVER['HTTP_X_DEVICE'] ) ?
$_SERVER['HTTP_X_DEVICE'] : '';
@@ -251,6 +260,11 @@
}
}
+ /**
+ * @param $obj Article
+ * @param $tpl
+ * @return bool
+ */
public function addMobileFooter( &$obj, &$tpl ) {
global $wgRequest;
wfProfileIn( __METHOD__ );
@@ -269,7 +283,12 @@
wfProfileOut( __METHOD__ );
return true;
}
-
+
+ /**
+ * @param $url string
+ * @param $field string
+ * @return string
+ */
private function removeQueryStringParameter( $url, $field ) {
$url = preg_replace( '/(.*)(\?|&)' . $field .
'=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&' );
$url = substr( $url, 0, -1 );
@@ -344,6 +363,7 @@
$key = wfMemcKey( 'mobile', 'ua', $uAmd5 );
+ $props = null;
try {
$props = $wgMemc->get( $key );
if ( ! $props ) {
@@ -465,28 +485,22 @@
exit();
}
- if ( $mobileAction == 'disable_mobile_site' ) {
- if ( $this->contentFormat == 'XHTML' ) {
- echo $this->renderDisableMobileSiteXHTML();
- wfProfileOut( __METHOD__ );
- exit();
- }
+ if ( $mobileAction == 'disable_mobile_site' &&
$this->contentFormat == 'XHTML' ) {
+ echo $this->renderDisableMobileSiteXHTML();
+ wfProfileOut( __METHOD__ );
+ exit();
}
- if ( $mobileAction == 'opt_in_mobile_site' ) {
- if ( $this->contentFormat == 'XHTML' ) {
- echo $this->renderOptInMobileSiteXHTML();
- wfProfileOut( __METHOD__ );
- exit();
- }
+ if ( $mobileAction == 'opt_in_mobile_site' &&
$this->contentFormat == 'XHTML' ) {
+ echo $this->renderOptInMobileSiteXHTML();
+ wfProfileOut( __METHOD__ );
+ exit();
}
- if ( $mobileAction == 'opt_out_mobile_site' ) {
- if ( $this->contentFormat == 'XHTML' ) {
- echo $this->renderOptOutMobileSiteXHTML();
- wfProfileOut( __METHOD__ );
- exit();
- }
+ if ( $mobileAction == 'opt_out_mobile_site' &&
$this->contentFormat == 'XHTML' ) {
+ echo $this->renderOptOutMobileSiteXHTML();
+ wfProfileOut( __METHOD__ );
+ exit();
}
if ( $mobileAction == 'opt_in_cookie' ) {
@@ -502,7 +516,7 @@
// WURFL documentation:
http://wurfl.sourceforge.net/help_doc.php
// Determine the kind of markup
- if ( is_array( $props ) && $props['preferred_markup'] ) {
+ if ( is_array( $props ) && isset( $props['preferred_markup'] )
&& $props['preferred_markup'] ) {
// wfDebug( __METHOD__ . ": preferred markup for this
device: " . $props['preferred_markup'] );
// xhtml/html: html_web_3_2, html_web_4_0
// xthml basic/xhtmlmp (wap 2.0): html_wi_w3_xhtmlbasic
html_wi_oma_xhtmlmp_1_0
@@ -538,6 +552,9 @@
return true;
}
+ /**
+ * @param $value string
+ */
private function setOptInOutCookie( $value ) {
global $wgCookieDomain, $wgRequest;
wfProfileIn( __METHOD__ );
@@ -548,6 +565,9 @@
wfProfileOut( __METHOD__ );
}
+ /**
+ * @return string
+ */
private function getBaseDomain() {
wfProfileIn( __METHOD__ );
// Validates value as IP address
@@ -557,12 +577,15 @@
// Although some browsers will accept cookies without
the initial ., ยป RFC 2109 requires it to be included.
wfProfileOut( __METHOD__ );
return '.' . $domainParts[1] . '.' . $domainParts[0];
- } else {
- wfProfileOut( __METHOD__ );
- return $_SERVER['HTTP_HOST'];
}
+ wfProfileOut( __METHOD__ );
+ return $_SERVER['HTTP_HOST'];
}
+ /**
+ * @param $url string
+ * @return string
+ */
private function getRelativeURL( $url ) {
wfProfileIn( __METHOD__ );
$parsedUrl = parse_url( $url );
@@ -572,10 +595,9 @@
$baseUrl = $parsedUrl['scheme'] . '://' .
$parsedUrl['host'];
$baseUrl = str_replace( $baseUrl, '', $url );
return $baseUrl;
- } else {
- wfProfileOut( __METHOD__ );
- return $url;
}
+ wfProfileOut( __METHOD__ );
+ return $url;
}
private function disableCaching() {
@@ -600,6 +622,9 @@
wfProfileOut( __METHOD__ );
}
+ /**
+ * @return string
+ */
private function renderLeaveFeedbackXHTML() {
global $wgRequest, $wgUser;
wfProfileIn( __METHOD__ );
@@ -628,6 +653,9 @@
return '';
}
+ /**
+ * @return string
+ */
private function renderOptInMobileSiteXHTML() {
wfProfileIn( __METHOD__ );
if ( $this->contentFormat == 'XHTML' ) {
@@ -649,6 +677,9 @@
return '';
}
+ /**
+ * @return string
+ */
private function renderOptOutMobileSiteXHTML() {
wfProfileIn( __METHOD__ );
if ( $this->contentFormat == 'XHTML' ) {
@@ -670,6 +701,9 @@
return '';
}
+ /**
+ * @return string
+ */
private function renderDisableMobileSiteXHTML() {
wfProfileIn( __METHOD__ );
if ( $this->contentFormat == 'XHTML' ) {
@@ -692,6 +726,10 @@
return '';
}
+ /**
+ * @param $matches array
+ * @return string
+ */
private function headingTransformCallbackWML( $matches ) {
wfProfileIn( __METHOD__ );
static $headings = 0;
@@ -705,6 +743,10 @@
return $base;
}
+ /**
+ * @param $matches array
+ * @return string
+ */
private function headingTransformCallbackXHTML( $matches ) {
wfProfileIn( __METHOD__ );
if ( isset( $matches[0] ) ) {
@@ -720,13 +762,13 @@
++$headings;
// Back to top link
$base = Html::openElement( 'div',
- array(
'id' => 'anchor_' . intval( $headings - 1 ),
-
'class' => 'section_anchors', )
+ array( 'id' => 'anchor_' .
intval( $headings - 1 ),
+ 'class' =>
'section_anchors', )
) .
Html::rawElement( 'a',
array( 'href' => '#section_' .
intval( $headings - 1 ),
'class' =>
'back_to_top' ),
- '↑' .
$backToTop ) .
+ '↑' .
$backToTop ) .
Html::closeElement( 'div' );
// generate the HTML we are going to inject
$buttons = Html::element( 'button',
@@ -789,8 +831,11 @@
return $s;
}
+ /**
+ * @param $s string
+ * @return string
+ */
private function createWMLCard( $s ) {
- global $wgRequest;
wfProfileIn( __METHOD__ );
$segments = explode( $this->WMLSectionSeperator, $s );
$card = '';
@@ -833,6 +878,9 @@
return $card;
}
+ /**
+ * @return array
+ */
private function parseItemsToRemove() {
global $wgMFRemovableClasses;
wfProfileIn( __METHOD__ );
@@ -851,6 +899,9 @@
return $itemToRemoveRecords;
}
+ /**
+ * @param $html string
+ */
public function DOMParseMainPage( $html ) {
wfProfileIn( __METHOD__ );
$html = mb_convert_encoding( $html, 'HTML-ENTITIES', "UTF-8" );
@@ -907,8 +958,12 @@
return $contentHtml;
}
+ /**
+ * @param $html string
+ * @return string
+ */
public function DOMParse( $html ) {
- global $wgSitename, $wgScript;
+ global $wgScript;
wfProfileIn( __METHOD__ );
$html = mb_convert_encoding( $html, 'HTML-ENTITIES', "UTF-8" );
libxml_use_internal_errors( true );
@@ -958,7 +1013,7 @@
foreach ( $itemToRemoveRecords['ID'] as $itemToRemove ) {
$itemToRemoveNode = $this->doc->getElementById(
$itemToRemove );
if ( $itemToRemoveNode ) {
- $removedItemToRemove =
$itemToRemoveNode->parentNode->removeChild( $itemToRemoveNode );
+ $itemToRemoveNode->parentNode->removeChild(
$itemToRemoveNode );
}
}
@@ -968,7 +1023,7 @@
$elements = $xpath->query( '//*[@class="' .
$classToRemove . '"]' );
foreach ( $elements as $element ) {
- $removedElement =
$element->parentNode->removeChild( $element );
+ $element->parentNode->removeChild( $element );
}
}
@@ -1008,9 +1063,6 @@
$contentHtml = $this->DOMParseMainPage( $contentHtml );
}
- $title = htmlspecialchars( self::$title->getText() );
- $htmlTitle = htmlspecialchars( self::$htmlTitle );
-
if ( strlen( $contentHtml ) > 4000 && $this->contentFormat ==
'XHTML'
&& self::$device['supports_javascript'] === true
&& empty( self::$search ) && !self::$isMainPage ) {
Modified: trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php
===================================================================
--- trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php
2011-10-14 08:00:27 UTC (rev 99758)
+++ trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php
2011-10-14 08:01:47 UTC (rev 99759)
@@ -1,10 +1,11 @@
<?php
class ExtMobileFrontendTest extends MediaWikiTestCase {
-
/**
* PHP 5.3.2 introduces the ReflectionMethod::setAccessible() method to
allow the invocation of
* protected and private methods directly through the Reflection API
+ *
+ * @param $name string
*/
protected static function getMethod( $name ) {
$class = new ReflectionClass( 'ExtMobileFrontend' );
@@ -15,32 +16,34 @@
protected function setUp() {
parent::setUp();
- $this->wgExtMobileFrontend = new ExtMobileFrontend();
+ global $wgExtMobileFrontend;
+ $wgExtMobileFrontend = new ExtMobileFrontend();
}
protected function tearDown() {
- unset( $this->wgExtMobileFrontend );
+ global $wgExtMobileFrontend;
+ unset( $wgExtMobileFrontend );
parent::tearDown();
}
public function testGetBaseDomain() {
+ global $wgExtMobileFrontend;
$getBaseDomain = self::getMethod( 'getBaseDomain' );
- $wgExtMobileFrontend = new ExtMobileFrontend();
$_SERVER['HTTP_HOST'] = 'en.wikipedia.org';
$this->assertEquals( '.wikipedia.org',
$getBaseDomain->invokeArgs( $wgExtMobileFrontend, array() ) );
}
public function testGetRelativeURL() {
+ global $wgExtMobileFrontend;
$getRelativeURL = self::getMethod( 'getRelativeURL' );
- $wgExtMobileFrontend = new ExtMobileFrontend();
$url = 'http://en.wikipedia.org/wiki/Positional_astronomy';
$this->assertEquals( '/wiki/Positional_astronomy',
$getRelativeURL->invokeArgs( $wgExtMobileFrontend, array( $url ) ) );
}
public function testDisableCaching() {
- global $wgRequest;
+ global $wgRequest, $wgExtMobileFrontend;
$disableCaching = self::getMethod( 'disableCaching' );
- $wgExtMobileFrontend = new ExtMobileFrontend();
+
$_SERVER['HTTP_VIA'] = '.wikimedia.org:3128';
$disableCaching->invokeArgs( $wgExtMobileFrontend, array() );
$this->assertEquals( 'no-cache, must-revalidate',
$wgRequest->response()->getheader( 'Cache-Control' ) );
@@ -49,9 +52,8 @@
}
public function testSendXDeviceVaryHeader() {
- global $wgRequest;
+ global $wgRequest, $wgExtMobileFrontend;
$sendXDeviceVaryHeader = self::getMethod(
'sendXDeviceVaryHeader' );
- $wgExtMobileFrontend = new ExtMobileFrontend();
$_SERVER['HTTP_X_DEVICE'] = 'device';
$sendXDeviceVaryHeader->invokeArgs( $wgExtMobileFrontend,
array() );
$this->assertEquals( $_SERVER['HTTP_X_DEVICE'],
$wgRequest->response()->getheader( 'X-Device' ) );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs