jenkins-bot has submitted this change and it was merged.

Change subject: Extension registration support & some cleanup
......................................................................


Extension registration support & some cleanup

* Moved hooks into their own file, inside the brand new DPLForumHooks class
* Added extension.json file for extension registration support
* Some random coding style tweaks in DPLforum_body.php
* Removed unused $skin variable from DPLForum::buildOutput()
* Bumped version number to 3.6.0

Change-Id: I3a43cac50923a9ca56672c5d8f202a4bf0b3fae7
---
A DPLForumHooks.php
M DPLforum.php
M DPLforum_body.php
A extension.json
4 files changed, 109 insertions(+), 56 deletions(-)

Approvals:
  Jack Phoenix: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/DPLForumHooks.php b/DPLForumHooks.php
new file mode 100644
index 0000000..f2939cf
--- /dev/null
+++ b/DPLForumHooks.php
@@ -0,0 +1,37 @@
+<?php
+
+class DPLForumHooks {
+       /**
+        * Register the <forum> tag with the parser.
+        *
+        * @param Parser $parser
+        * @return bool
+        */
+       public static function onParserFirstCallInit( &$parser ) {
+               $parser->setHook( 'forum', array( __CLASS__, 'parseForum' ) );
+               $parser->setFunctionHook( 'forumlink', array( new DPLForum(), 
'link' ) );
+               return true;
+       }
+
+       /**
+        * Callback for onParserFirstCallInit() above.
+        */
+       public static function parseForum( $input, $argv, $parser ) {
+               $f = new DPLForum();
+               return $f->parse( $input, $parser );
+       }
+
+       /**
+        * Register the canonical names for our namespace and its talkspace.
+        *
+        * @param array $list Array of namespace numbers with corresponding
+        *                     canonical names
+        * @return bool true
+        */
+       public static function onCanonicalNamespaces( &$list ) {
+               $list[NS_FORUM] = 'Forum';
+               $list[NS_FORUM_TALK] = 'Forum_talk';
+               return true;
+       }
+
+}
\ No newline at end of file
diff --git a/DPLforum.php b/DPLforum.php
index d1c60be..2c287ee 100644
--- a/DPLforum.php
+++ b/DPLforum.php
@@ -32,7 +32,7 @@
        'path' => __FILE__,
        'name' => 'DPLforum',
        'author' => 'Ross McClure',
-       'version' => '3.5.0',
+       'version' => '3.6.0',
        'url' => 'https://www.mediawiki.org/wiki/Extension:DPLforum',
        'descriptionmsg' => 'dplforum-desc',
 );
@@ -42,41 +42,13 @@
 define( 'NS_FORUM_TALK', 111 );
 
 // Hooked functions
-$wgHooks['ParserFirstCallInit'][] = 'wfDPLinit';
-$wgHooks['CanonicalNamespaces'][] = 'wfDPLforumCanonicalNamespaces';
+$wgHooks['ParserFirstCallInit'][] = 'DPLForumHooks::onParserFirstCallInit';
+$wgHooks['CanonicalNamespaces'][] = 'DPLForumHooks::onCanonicalNamespaces';
 
 // Set up i18n and autoload the main class
-$dir = dirname( __FILE__ ) . '/';
 $wgMessagesDirs['DPLforum'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['DPLforum'] = $dir . 'DPLforum.i18n.php';
-$wgExtensionMessagesFiles['DPLforumMagic'] = $dir . 'DPLforum.i18n.magic.php';
-$wgExtensionMessagesFiles['DPLforumNamespaces'] = $dir . 
'DPLforum.namespaces.php';
-$wgAutoloadClasses['DPLForum'] = $dir . 'DPLforum_body.php';
-
-/**
- * @param Parser $parser
- * @return bool
- */
-function wfDPLinit( &$parser ) {
-       $parser->setHook( 'forum', 'parseForum' );
-       $parser->setFunctionHook( 'forumlink', array( new DPLForum(), 'link' ) 
);
-       return true;
-}
-
-function parseForum( $input, $argv, $parser ) {
-       $f = new DPLForum();
-       return $f->parse( $input, $parser );
-}
-
-/**
- * Register the canonical names for our namespace and its talkspace.
- *
- * @param array $list array of namespace numbers with corresponding
- *                     canonical names
- * @return bool true
- */
-function wfDPLforumCanonicalNamespaces( &$list ) {
-       $list[NS_FORUM] = 'Forum';
-       $list[NS_FORUM_TALK] = 'Forum_talk';
-       return true;
-}
+$wgExtensionMessagesFiles['DPLforum'] = __DIR__ . '/DPLforum.i18n.php';
+$wgExtensionMessagesFiles['DPLforumMagic'] = __DIR__ . 
'/DPLforum.i18n.magic.php';
+$wgExtensionMessagesFiles['DPLforumNamespaces'] = __DIR__ . 
'/DPLforum.namespaces.php';
+$wgAutoloadClasses['DPLForum'] = __DIR__ . '/DPLforum_body.php';
+$wgAutoloadClasses['DPLForumHooks'] = __DIR__ . '/DPLForumHooks.php';
diff --git a/DPLforum_body.php b/DPLforum_body.php
index e620fc6..78a9ef6 100644
--- a/DPLforum_body.php
+++ b/DPLforum_body.php
@@ -153,7 +153,7 @@
                if ( preg_match( "/\\d+(\\D+)(\\d+)/", $cond, $m ) ) {
                        $m[1] = strtr( $m[1], array( ( '&l' . 't;' ) => '<', ( 
'&g' . 't;' ) => '>' ) );
                        $m[2] = intval( $m[2] ) - 1;
-                       switch( $m[1] ) {
+                       switch ( $m[1] ) {
                                case '<':
                                        return ( $page >= $m[2] );
                                case '>':
@@ -218,7 +218,7 @@
                $this->bAddCreationDate = ( $this->get( 'addcreationdate' ) == 
'true' );
                $this->sCreationDateFormat = $this->get( 'creationdateformat', 
false );
 
-               switch( $this->get( 'historylink' ) ) {
+               switch ( $this->get( 'historylink' ) ) {
                        case 'embed':
                        case 'true':
                                $this->bEmbedHistory = true;
@@ -227,11 +227,11 @@
                                $this->bLinkHistory = true;
                }
                $sOrder = 'rev_timestamp';
-               switch( $this->get( 'ordermethod' ) ) {
+               switch ( $this->get( 'ordermethod' ) ) {
                        case 'categoryadd':
                        case 'created':
                                $sOrder = 'first_time';
-                       break;
+                               break;
                        case 'pageid':
                                $sOrder = 'page_id';
                }
@@ -261,19 +261,19 @@
                $sStartItem = $sEndItem = '';
                $bCountMode = false;
                $arg = $this->get( 'mode' );
-               switch( $arg ) {
+               switch ( $arg ) {
                        case 'none':
                                $sEndItem = '<br />';
-                       break;
+                               break;
                        case 'count':
                                $bCountMode = true;
-                       break;
+                               break;
                        case 'list':
                        case 'ordered':
                        case 'unordered':
                                $sStartItem = '<li>';
                                $sEndItem = '</li>';
-                       break;
+                               break;
                        case 'table':
                        default:
                                $this->bTableMode = true;
@@ -344,14 +344,16 @@
                        . " ON o.rev_id =( SELECT MIN(q.rev_id) FROM $sRevTable"
                        . " AS q WHERE q.rev_page = page_id )";
                } else {
-                       if ( $sOrder == 'first_time' )
+                       if ( $sOrder == 'first_time' ) {
                                $sOrder = 'page_id';
+                       }
                        $sSqlSelectFrom .= $arg;
                }
 
                $sSqlWhere = ' WHERE 1=1';
-               if ( $iNamespace >= 0 )
+               if ( $iNamespace >= 0 ) {
                        $sSqlWhere = ' WHERE page_namespace=' . $iNamespace;
+               }
 
                if ( $sPrefix !== '' ) {
                        // Escape SQL special characters
@@ -360,28 +362,28 @@
                        $sSqlWhere .= " AND page_title LIKE BINARY '" . 
$sPrefix . "%'";
                }
 
-               switch( $this->get( 'redirects' ) ) {
+               switch ( $this->get( 'redirects' ) ) {
                        case 'only':
                                $sSqlWhere .= ' AND page_is_redirect = 1';
                        case 'include':
-                       break;
+                               break;
                        case 'exclude':
                        default:
                                $sSqlWhere .= ' AND page_is_redirect = 0';
-                       break;
+                               break;
                }
 
                $n = 1;
                for ( $i = 0; $i < $cats; $i++ ) {
                        $sSqlSelectFrom .= " INNER JOIN $categorylinks AS" .
-                       " c{$n} ON page_id = c{$n}.cl_from AND c{$n}.cl_to=" .
-                       $dbr->addQuotes( $aCategories[$i]->getDBkey() );
+                               " c{$n} ON page_id = c{$n}.cl_from AND 
c{$n}.cl_to=" .
+                               $dbr->addQuotes( $aCategories[$i]->getDBkey() );
                        $n++;
                }
                for ( $i = 0; $i < $nocats; $i++ ) {
                        $sSqlSelectFrom .= " LEFT OUTER JOIN $categorylinks AS" 
.
-                       " c{$n} ON page_id = c{$n}.cl_from AND c{$n}.cl_to=" .
-                       $dbr->addQuotes( $aExcludeCategories[$i]->getDBkey() );
+                               " c{$n} ON page_id = c{$n}.cl_from AND 
c{$n}.cl_to=" .
+                               $dbr->addQuotes( 
$aExcludeCategories[$i]->getDBkey() );
                        $sSqlWhere .= " AND c{$n}.cl_to IS NULL";
                        $n++;
                }
@@ -415,13 +417,13 @@
                        }
                } elseif ( is_null( $title ) ) {
                        foreach ( $res as $row ) {
-                               if( isset( $row->first_time ) ) {
+                               if ( isset( $row->first_time ) ) {
                                        $first_time = $row->first_time;
                                } else {
                                        $first_time = '';
                                }
 
-                               if( isset( $row->first_user ) ) {
+                               if ( isset( $row->first_user ) ) {
                                        $first_user = $row->first_user;
                                } else {
                                        $first_user = '';
@@ -460,7 +462,6 @@
         * @return string
         */
        function buildOutput( $page, $title, $time, $user = '', $author = '', 
$made = '' ) {
-               $skin = RequestContext::getMain()->getSkin();
                $tableMode =& $this->bTableMode;
                $output = '';
 
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..6c7c76b
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,43 @@
+{
+       "name": "DPLforum",
+       "version": "3.6.0",
+       "author": "Ross McClure",
+       "license-name": "GPL-2.0+",
+       "url": "https://www.mediawiki.org/wiki/Extension:DPLforum";,
+       "descriptionmsg": "dplforum-desc",
+       "type": "parserhook",
+       "MessagesDirs": {
+               "DPLforum": [
+                       "i18n"
+               ]
+       },
+       "namespaces": [
+               {
+                       "id": 110,
+                       "constant": "NS_FORUM",
+                       "name": "Forum"
+               },
+               {
+                       "id": 111,
+                       "constant": "NS_FORUM_TALK",
+                       "name": "Forum_talk"
+               }
+       ],
+       "ExtensionMessagesFiles": {
+               "DPLforumMagic": "DPLforum.i18n.magic.php",
+               "DPLforumNamespaces": "DPLforum.namespaces.php"
+       },
+       "AutoloadClasses": {
+               "DPLForum": "DPLforum_body.php",
+               "DPLForumHooks": "DPLForumHooks.php"
+       },
+       "Hooks": {
+               "ParserFirstCallInit": [
+                       "DPLForumHooks::onParserFirstCallInit"
+               ],
+               "CanonicalNamespaces": [
+                       "DPLForumHooks::onCanonicalNamespaces"
+               ]
+       },
+       "manifest_version": 1
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3a43cac50923a9ca56672c5d8f202a4bf0b3fae7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DPLforum
Gerrit-Branch: master
Gerrit-Owner: Jack Phoenix <j...@countervandalism.net>
Gerrit-Reviewer: Jack Phoenix <j...@countervandalism.net>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to