Siebrand has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/242071

Change subject: Add support for PHP CodeSniffer checks
......................................................................

Add support for PHP CodeSniffer checks

Also fix any remaining errors and warnings.

Change-Id: Ie93537f316655523db5f8b396003efdbdbfad459
---
A .gitignore
M Add_HTML_Meta_and_Title.php
A composer.json
A phpcs.xml
4 files changed, 164 insertions(+), 119 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AddHTMLMetaAndTitle 
refs/changes/71/242071/1

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..854a2d2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+*~
+*.kate-swp
+.*.swp
+node_modules/
+/composer.lock
+/vendor/
diff --git a/Add_HTML_Meta_and_Title.php b/Add_HTML_Meta_and_Title.php
index 9e1c9bc..581b586 100644
--- a/Add_HTML_Meta_and_Title.php
+++ b/Add_HTML_Meta_and_Title.php
@@ -2,49 +2,51 @@
 /*
 * Extension homepage is at  
http://www.mediawiki.org/wiki/Extension:Add_HTML_Meta_and_Title
 *
- */   
-
-/** 
- * Protect against register_globals vulnerabilities. 
- * This line must be present before any global variable is referenced. 
  */
-if (!defined('MEDIAWIKI')) {
-   echo <<<EOT
+
+/**
+ * Protect against register_globals vulnerabilities.
+ * This line must be present before any global variable is referenced.
+ */
+if ( !defined( 'MEDIAWIKI' ) ) {
+       echo <<<EOT
 To install my extension, put the following line in LocalSettings.php:
 require_once 
"\$IP/extensions/Add_HTML_Meta_and_Title/Add_HTML_Meta_and_Title.php" ); 
 EOT;
-   exit( 1 );
+       exit( 1 );
 }
 
-# Credits
 $wgExtensionCredits['parserhook'][] = array(
-       'path'                  => __FILE__,
-    'name'                     => 'Add_HTML_Meta_and_Title',
-    'author'           =>      array('Vladimir Radulovski - 
vladradulov&lt;at&gt;gmail.com',
-                                               'Jim Wilson - 
wilson.jim.r&lt;at&gt;gmail.com',
-                                               'Dennis Roczek - 
dennisroczek&lt;at&gt;gmail.com'),
-    'url'                      => 
'http://www.mediawiki.org/wiki/Extension:Add_HTML_Meta_and_Title',
-    'descriptionmsg'   => 'addhtmlmetaandtitle-desc',
-    'version'          => '0.6',
-       'license-name'  => 'MIT'
+       'path' => __FILE__,
+       'name' => 'Add_HTML_Meta_and_Title',
+       'author' => array(
+               'Vladimir Radulovski - vladradulov&lt;at&gt;gmail.com',
+               'Jim Wilson - wilson.jim.r&lt;at&gt;gmail.com',
+               'Dennis Roczek - dennisroczek&lt;at&gt;gmail.com'
+       ),
+       'url' => 
'http://www.mediawiki.org/wiki/Extension:Add_HTML_Meta_and_Title',
+       'descriptionmsg' => 'addhtmlmetaandtitle-desc',
+       'version' => '0.7',
+       'license-name' => 'MIT'
 );
 
 # Add Extension Function
-$wgExtensionFunctions[] = 'setupSEOParserHooks';
+$wgExtensionFunctions[] = 'wfSetupSEOParserHooks';
 $wgMessagesDirs['Add_HTML_Meta_and_Title'] = __DIR__ . '/i18n';
 
 /**
  * Sets up the MetaKeywordsTag Parser hook and system messages
  */
-function setupSEOParserHooks() {
-       global $wgParser, $wgMessageCache;
+function wfSetupSEOParserHooks() {
+       global $wgParser;
        # meta if empty
-       $wgParser->setHook( 'seo', 'renderSEO' );
+       $wgParser->setHook( 'seo', 'wfRenderSEO' );
 }
 
-function paramEncode( $param_text, &$parser, $frame ){
-  $expanded_param =$parser->recursiveTagParse( $param_text, $frame );
-  return base64_encode( $expanded_param );
+function wfParamEncode( $param_text, &$parser, $frame ) {
+       $expanded_param = $parser->recursiveTagParse( $param_text, $frame );
+
+       return base64_encode( $expanded_param );
 }
 
 /**
@@ -54,39 +56,49 @@
  * @param Parser $parser Reference to currently running parser (passed by 
reference).
  * @return String Always empty.
  */
-function renderSEO( $text, $params = array(), $parser, $frame ) {
-    # Short-circuit with error message if content is not specified.
-       $emt="";
-    if  ( (isset($params['title']))                                    ||
-                 (isset($params['metak']))                                     
||
-                 (isset($params['metad']))                                     
||
-                 (isset($params['metakeywords']))                              
||
-                 (isset($params['metadescription']))                   ||
-                 (isset($params['google-site-verification']))
-               )
-       {
-                   if  (isset($params['title']))           {$emt .= "<!-- 
ADDTITLE ".paramEncode($params['title'], $parser, $frame)." -->";}
-                       if  (isset($params['metak']))           {$emt .= "<!-- 
ADDMETAK ".paramEncode($params['metak'], $parser, $frame)." -->";}
-                       if  (isset($params['metakeywords']))    {$emt .= "<!-- 
ADDMETAK ".paramEncode($params['metakeywords'], $parser, $frame)." -->";}
-                       if  (isset($params['metad']))           {$emt .= "<!-- 
ADDMETAD ".paramEncode($params['metad'], $parser, $frame)." -->";}
-                       if  (isset($params['metadescription'])) {$emt .= "<!-- 
ADDMETAD ".paramEncode($params['metadescription'], $parser, $frame)." -->";}
-                       if  (isset($params['google-site-verification'])) {$emt 
.= "<!-- ADDMETAGOOGLESITEVERIFICATION 
".paramEncode($params['google-site-verification'], $parser, $frame)." -->";}
-     
-                       return $emt; //$encoded_metas_and_title;
-        
-    }
-    else
-       {return
-            '<div class="errorbox">'.
-            
wfMessage('addhtmlmetaandtitle-empty-attr')->inContentLanguage()->text().
-            '</div>';
-       }
+function wfRenderSEO( $text, $params = array(), $parser, $frame ) {
+       # Short-circuit with error message if content is not specified.
+       $emt = '';
+       if ( ( isset( $params['title'] ) ) ||
+               ( isset( $params['metak'] ) ) ||
+               ( isset( $params['metad'] ) ) ||
+               ( isset( $params['metakeywords'] ) ) ||
+               ( isset( $params['metadescription'] ) ) ||
+               ( isset( $params['google-site-verification'] ) )
+       ) {
+               if ( isset( $params['title'] ) ) {
+                       $emt .= "<!-- ADDTITLE " . wfParamEncode( 
$params['title'], $parser, $frame ) . " -->";
+               }
+               if ( isset( $params['metak'] ) ) {
+                       $emt .= "<!-- ADDMETAK " . wfParamEncode( 
$params['metak'], $parser, $frame ) . " -->";
+               }
+               if ( isset( $params['metakeywords'] ) ) {
+                       $emt .= "<!-- ADDMETAK " . wfParamEncode( 
$params['metakeywords'], $parser, $frame ) . " -->";
+               }
+               if ( isset( $params['metad'] ) ) {
+                       $emt .= "<!-- ADDMETAD " . wfParamEncode( 
$params['metad'], $parser, $frame ) . " -->";
+               }
+               if ( isset( $params['metadescription'] ) ) {
+                       $emt .= "<!-- ADDMETAD " . wfParamEncode( 
$params['metadescription'], $parser, $frame ) . " -->";
+               }
+               if ( isset( $params['google-site-verification'] ) ) {
+                       $emt .= "<!-- ADDMETAGOOGLESITEVERIFICATION " .
+                               wfParamEncode( 
$params['google-site-verification'], $parser, $frame ) . " -->";
+               }
 
+               return $emt; // $encoded_metas_and_title;
+
+       } else {
+               return
+                       '<div class="errorbox">' .
+                       wfMessage( 'addhtmlmetaandtitle-empty-attr' 
)->inContentLanguage()->text() .
+                       '</div>';
+       }
 }
 
 # Attach post-parser hook to extract metadata and alter headers
-$wgHooks['OutputPageBeforeHTML'][] = 'insertMeta';
-$wgHooks['BeforePageDisplay'][] = 'insertTitle';
+$wgHooks['OutputPageBeforeHTML'][] = 'wfInsertMeta';
+$wgHooks['BeforePageDisplay'][] = 'wfInsertTitle';
 
 /**
  * Adds the <meta> keywords to document head.
@@ -95,84 +107,91 @@
  * @param String $text Output text.
  * @return Boolean Always true to allow other extensions to continue 
processing.
  */
-function insertTitle($out){
-     # Extract meta keywords
-       if (preg_match_all(
-        '/<!-- ADDTITLE ([0-9a-zA-Z\\+\\/]+=*) -->/m', 
-        $out->mBodytext, 
-        $matches)===false
-    ) return true;
-    $data = $matches[1];
-    # Merge keyword data into OutputPage as meta tags
-    foreach ($data as $item) {
-        $content = @base64_decode($item);
-               $content = htmlspecialchars($content, ENT_QUOTES);              
-        if ($content){
-                       $new_title = $out->mHTMLtitle;
-               
-                       //Set page title
+function wfInsertTitle( $out ) {
+       # Extract meta keywords
+       if ( preg_match_all(
+                       '/<!-- ADDTITLE ([0-9a-zA-Z\\+\\/]+=*) -->/m',
+                       $out->mBodytext,
+                       $matches ) === false
+       ) return true;
+       $data = $matches[1];
+       # Merge keyword data into OutputPage as meta tags
+       foreach ( $data as $item ) {
+               MediaWiki\suppressWarnings();
+               $content = base64_decode( $item );
+               MediaWiki\restoreWarnings();
+               $content = htmlspecialchars( $content, ENT_QUOTES );
+               if ( $content ) {
+                       $new_title = $out->getHTMLTitle();
+
+                       // Set page title
                        global $wgSitename;
                        $new_title = "$content - $wgSitename";
                        $out->mHTMLtitleFromPagetitle = true;
                        $out->setHTMLTitle( $new_title );
                }
-    }
+       }
+
        return true;
 }
 
-function insertMeta($out, $text){
-    # Extract meta keywords
-    if (preg_match_all(
-        '/<!-- ADDMETAK ([0-9a-zA-Z\\+\\/]+=*) -->/m', 
-        $text, 
-        $matches)===false
-    ) return true;
-    $data = $matches[1];    
-    # Merge keyword data into OutputPage as meta tags
-    foreach ($data AS $item) {
-        $content = @base64_decode($item);
-               $content = htmlspecialchars($content, ENT_QUOTES);
-               
-        if ($content) {
+function wfInsertMeta( $out, $text ) {
+       # Extract meta keywords
+       if ( preg_match_all(
+                       '/<!-- ADDMETAK ([0-9a-zA-Z\\+\\/]+=*) -->/m',
+                       $text,
+                       $matches ) === false
+       ) return true;
+       $data = $matches[1];
+       # Merge keyword data into OutputPage as meta tags
+       foreach ( $data as $item ) {
+               MediaWiki\suppressWarnings();
+               $content = base64_decode( $item );
+               MediaWiki\restoreWarnings();
+               $content = htmlspecialchars( $content, ENT_QUOTES );
+
+               if ( $content ) {
                        $out->addMeta( 'keywords', $content );
                }
-               
-    }
+       }
 
-    # Extract meta description
-    if (preg_match_all(
-        '/<!-- ADDMETAD ([0-9a-zA-Z\\+\\/]+=*) -->/m', 
-        $text, 
-        $matches)===false
-    ) return true;
-    $data = $matches[1];
-    # Merge description data into OutputPage as meta tags
-    foreach ($data AS $item) {
-        $content = @base64_decode($item);
-               $content = htmlspecialchars($content, ENT_QUOTES);
-               
-        if ($content) {
+       # Extract meta description
+       if ( preg_match_all(
+                       '/<!-- ADDMETAD ([0-9a-zA-Z\\+\\/]+=*) -->/m',
+                       $text,
+                       $matches ) === false
+       ) return true;
+       $data = $matches[1];
+       # Merge description data into OutputPage as meta tags
+       foreach ( $data as $item ) {
+               MediaWiki\suppressWarnings();
+               $content = base64_decode( $item );
+               MediaWiki\restoreWarnings();
+               $content = htmlspecialchars( $content, ENT_QUOTES );
+
+               if ( $content ) {
                        $out->addMeta( 'description', $content );
                }
-               
-    }
-    # Extract google-site-verification
-    if (preg_match_all(
-        '/<!-- ADDMETAGOOGLESITEVERIFICATION ([0-9a-zA-Z\\+\\/]+=*) -->/m', 
-        $text, 
-        $matches)===false
-    ) return true;
-    $data = $matches[1];
-    
-    # Merge google-site-verification data into OutputPage as meta tags
-    foreach ($data AS $item) {
-        $content = @base64_decode($item);
-               $content = htmlspecialchars($content, ENT_QUOTES);
+       }
+       # Extract google-site-verification
+       if ( preg_match_all(
+                       '/<!-- ADDMETAGOOGLESITEVERIFICATION 
([0-9a-zA-Z\\+\\/]+=*) -->/m',
+                       $text,
+                       $matches ) === false
+       ) return true;
+       $data = $matches[1];
 
-        if ($content) {
-               $out->addMeta( 'google-site-verification', $content );
+       # Merge google-site-verification data into OutputPage as meta tags
+       foreach ( $data as $item ) {
+               MediaWiki\suppressWarnings();
+               $content = base64_decode( $item );
+               MediaWiki\restoreWarnings();
+               $content = htmlspecialchars( $content, ENT_QUOTES );
+
+               if ( $content ) {
+                       $out->addMeta( 'google-site-verification', $content );
                }
-    }
-    return true;
+       }
+
+       return true;
 }
-?>
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..4365e8a
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,12 @@
+{
+       "require-dev": {
+               "jakub-onderka/php-parallel-lint": "0.9",
+               "mediawiki/mediawiki-codesniffer": "0.4.0"
+       },
+       "scripts": {
+               "test": [
+                       "parallel-lint . --exclude vendor",
+                       "phpcs -p -s"
+               ]
+       }
+}
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..d81a292
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<ruleset>
+       <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
+       <file>.</file>
+       <arg name="extensions" value="php,php5,inc"/>
+       <arg name="encoding" value="utf8"/>
+       <exclude-pattern>vendor</exclude-pattern>
+</ruleset>

-- 
To view, visit https://gerrit.wikimedia.org/r/242071
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie93537f316655523db5f8b396003efdbdbfad459
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AddHTMLMetaAndTitle
Gerrit-Branch: master
Gerrit-Owner: Siebrand <siebr...@kitano.nl>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to