Jeroen De Dauw has submitted this change and it was merged.

Change subject: Introduced top level factory class for the extension
......................................................................


Introduced top level factory class for the extension

This is an initial step in cleaning up the dependency management of this 
extension
- still a long way to go...

Change-Id: I2dcaada461a7d50c3713ba91a9deddce4c409650
---
M EducationProgram.php
A includes/Extension.php
M includes/actions/AddArticleAction.php
M includes/actions/AddReviewerAction.php
M includes/actions/RemoveArticleAction.php
M includes/actions/RemoveReviewerAction.php
M includes/pagers/ArticlePager.php
M includes/pagers/ArticleTable.php
M includes/rows/Course.php
M includes/specials/SpecialEducationProgram.php
D includes/tables/Articles.php
11 files changed, 114 insertions(+), 83 deletions(-)

Approvals:
  Jeroen De Dauw: Verified; Looks good to me, approved



diff --git a/EducationProgram.php b/EducationProgram.php
index 768ced6..c1f1414 100644
--- a/EducationProgram.php
+++ b/EducationProgram.php
@@ -136,7 +136,6 @@
 $wgAutoloadClasses['EducationProgram\VerySpecialPage']                         
        = $dir . '/includes/specials/VerySpecialPage.php';
 
 // includes/tables (deriving from ORMTable)
-$wgAutoloadClasses['EducationProgram\Articles']                                
        = $dir . '/includes/tables/Articles.php';
 $wgAutoloadClasses['EducationProgram\CAs']                                     
                = $dir . '/includes/tables/CAs.php';
 $wgAutoloadClasses['EducationProgram\Courses']                                 
                = $dir . '/includes/tables/Courses.php';
 $wgAutoloadClasses['EducationProgram\Events']                                  
        = $dir . '/includes/tables/Events.php';
@@ -150,6 +149,7 @@
 // includes
 $wgAutoloadClasses['EducationProgram\DiffTable']                               
        = $dir . '/includes/DiffTable.php';
 $wgAutoloadClasses['EducationProgram\DYKBox']                                  
        = $dir . '/includes/DYKBox.php';
+$wgAutoloadClasses['EducationProgram\Extension']                               
        = $dir . '/includes/Extension.php';
 $wgAutoloadClasses['EducationProgram\FailForm']                                
        = $dir . '/includes/FailForm.php';
 $wgAutoloadClasses['EducationProgram\HTMLCombobox']                            
= $dir . '/includes/HTMLCombobox.php';
 $wgAutoloadClasses['EducationProgram\HTMLDateField']                           
= $dir . '/includes/HTMLDateField.php';
diff --git a/includes/Extension.php b/includes/Extension.php
new file mode 100644
index 0000000..68ba4e7
--- /dev/null
+++ b/includes/Extension.php
@@ -0,0 +1,101 @@
+<?php
+
+namespace EducationProgram;
+
+use ORMTable;
+
+/**
+ * Main extension class, acts as dependency injection container look-alike.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 0.3
+ *
+ * @file
+ * @ingroup EducationProgram
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class Extension {
+
+       /**
+        * @since 0.3
+        *
+        * @var Settings
+        */
+       protected $settings;
+
+       /**
+        * Constructor
+        *
+        * @since 0.3
+        *
+        * @param Settings $settings
+        */
+       public function __construct( Settings $settings ) {
+               $this->settings = $settings;
+       }
+
+       /**
+        * Returns a new article ORMTable.
+        *
+        * @since 0.3
+        *
+        * @return ORMTable
+        */
+       public function newArticleTable() {
+               return new ORMTable(
+                       'ep_articles',
+                       array(
+                               'id' => 'id',
+
+                               'course_id' => 'int',
+                               'user_id' => 'int',
+                               'page_id' => 'int',
+                               'page_title' => 'str',
+                               'reviewers' => 'array',
+                       ),
+                       array(
+                               'reviewers' => array(),
+                       ),
+                       'EducationProgram\Article',
+                       'article_'
+               );
+       }
+
+       /**
+        * Global instance access.
+        *
+        * This is evil and should not be used except in intermediate steps 
during
+        * refactoring aimed at killing dependency pulling code.
+        *
+        * @since 0.3
+        * @deprecated since 0.3
+        *
+        * @return Extension
+        */
+       public static function globalInstance() {
+               static $instance = null;
+
+               if ( $instance === null ) {
+                       $instance = new static( Settings::newFromGlobals( 
$GLOBALS ) );
+               }
+
+               return $instance;
+       }
+
+}
diff --git a/includes/actions/AddArticleAction.php 
b/includes/actions/AddArticleAction.php
index f38cf36..f197a8b 100644
--- a/includes/actions/AddArticleAction.php
+++ b/includes/actions/AddArticleAction.php
@@ -49,11 +49,13 @@
                                        'page_title' => $title->getFullText(),
                                );
 
-                               if ( !Articles::singleton()->has( $articleData 
) ) {
+                               $articlesTable = 
Extension::globalInstance()->newArticleTable();
+
+                               if ( !$articlesTable->has( $articleData ) ) {
                                        /**
                                         * @var Article $article
                                         */
-                                       $article = 
Articles::singleton()->newRow( $articleData, true );
+                                       $article = $articlesTable->newRow( 
$articleData, true );
 
                                        if ( $article->save() ) {
                                                $article->logAdittion( 
$this->getUser() );
diff --git a/includes/actions/AddReviewerAction.php 
b/includes/actions/AddReviewerAction.php
index 98ab502..069efcb 100644
--- a/includes/actions/AddReviewerAction.php
+++ b/includes/actions/AddReviewerAction.php
@@ -34,7 +34,7 @@
 
                if ( $user->matchEditToken( $req->getText( 'token' ), $salt ) ) 
{
 
-                       $article = Articles::singleton()->selectRow(
+                       $article = 
Extension::globalInstance()->newArticleTable()->selectRow(
                                null,
                                array( 'id' => $req->getInt( 'article-id' ) )
                        );
diff --git a/includes/actions/RemoveArticleAction.php 
b/includes/actions/RemoveArticleAction.php
index d0811eb..954dbf9 100644
--- a/includes/actions/RemoveArticleAction.php
+++ b/includes/actions/RemoveArticleAction.php
@@ -33,7 +33,7 @@
                        /**
                         * @var EPArticle $article
                         */
-                       $article = Articles::singleton()->selectRow(
+                       $article = 
Extension::globalInstance()->newArticleTable()->selectRow(
                                null,
                                array(
                                        'id' => $req->getInt( 'article-id' ),
diff --git a/includes/actions/RemoveReviewerAction.php 
b/includes/actions/RemoveReviewerAction.php
index 5134f71..2e84325 100644
--- a/includes/actions/RemoveReviewerAction.php
+++ b/includes/actions/RemoveReviewerAction.php
@@ -38,7 +38,7 @@
                        /**
                         * @var Article $article
                         */
-                       $article = Articles::singleton()->selectRow(
+                       $article = 
Extension::globalInstance()->newArticleTable()->selectRow(
                                null,
                                array( 'id' => $req->getInt( 'article-id' ) )
                        );
diff --git a/includes/pagers/ArticlePager.php b/includes/pagers/ArticlePager.php
index bbee5bf..a842ae7 100644
--- a/includes/pagers/ArticlePager.php
+++ b/includes/pagers/ArticlePager.php
@@ -35,8 +35,8 @@
        public function __construct( IContextSource $context, array $conds = 
array() ) {
                $this->mDefaultDirection = true;
 
-               // when MW 1.19 becomes min, we want to pass an IContextSource 
$context here.
-               parent::__construct( $context, $conds, Articles::singleton() );
+               // TODO: inject table!
+               parent::__construct( $context, $conds, 
Extension::globalInstance()->newArticleTable() );
        }
 
        /**
diff --git a/includes/pagers/ArticleTable.php b/includes/pagers/ArticleTable.php
index a833e21..117380b 100644
--- a/includes/pagers/ArticleTable.php
+++ b/includes/pagers/ArticleTable.php
@@ -537,7 +537,7 @@
 
                $conditions = array_merge( array( 'user_id' => $userIds ), 
$this->articleConds );
 
-               $articles = Articles::singleton()->select( null, $conditions );
+               $articles = 
Extension::globalInstance()->newArticleTable()->select( null, $conditions );
 
                /**
                 * @var EPArticle $article
diff --git a/includes/rows/Course.php b/includes/rows/Course.php
index 8890e22..3ea0a96 100644
--- a/includes/rows/Course.php
+++ b/includes/rows/Course.php
@@ -636,7 +636,7 @@
                                // Get rid of the articles asscoaite 
associations with the student.
                                // No revisioning is implemented here, so this 
cannot be undone.
                                // Might want to add revisioning or just add a 
'deleted' flag at some point.
-                               Articles::singleton()->delete( array(
+                               
Extension::globalInstance()->newArticleTable()->delete( array(
                                        'course_id' => $this->getId(),
                                        'user_id' => $removedUsers,
                                ) );
diff --git a/includes/specials/SpecialEducationProgram.php 
b/includes/specials/SpecialEducationProgram.php
index 9c89b32..2a16bb6 100644
--- a/includes/specials/SpecialEducationProgram.php
+++ b/includes/specials/SpecialEducationProgram.php
@@ -276,7 +276,7 @@
                                $courseIds[] = $course->getId();
                        }
 
-                       $pageIds = Articles::singleton()->selectFields( 
'page_id', array( 'course_id' => $courseIds ), array( 'DISTINCT' ) );
+                       $pageIds = 
Extension::globalInstance()->newArticleTable()->selectFields( 'page_id', array( 
'course_id' => $courseIds ), array( 'DISTINCT' ) );
                        $pageIds = array_unique( $pageIds );
 
                        $students = array_unique( $students );
diff --git a/includes/tables/Articles.php b/includes/tables/Articles.php
deleted file mode 100644
index d639a4a..0000000
--- a/includes/tables/Articles.php
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-
-namespace EducationProgram;
-
-/**
- * Class representing the ep_articles table.
- *
- * @since 0.1
- *
- * @ingroup EducationProgram
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- */
-class Articles extends \ORMTable {
-
-       /**
-        * @see ORMTable::getName()
-        * @since 0.1
-        * @return string
-        */
-       public function getName() {
-               return 'ep_articles';
-       }
-
-       /**
-        * @see ORMTable::getFieldPrefix()
-        * @since 0.1
-        * @return string
-        */
-       public function getFieldPrefix() {
-               return 'article_';
-       }
-
-       /**
-        * @see ORMTable::getRowClass()
-        * @since 0.1
-        * @return string
-        */
-       public function getRowClass() {
-               return 'EducationProgram\EPArticle';
-       }
-
-       /**
-        * @see ORMTable::getFields()
-        * @since 0.1
-        * @return array
-        */
-       public function getFields() {
-               return array(
-                       'id' => 'id',
-
-                       'course_id' => 'int',
-                       'user_id' => 'int',
-                       'page_id' => 'int',
-                       'page_title' => 'str',
-                       'reviewers' => 'array',
-               );
-       }
-
-       /**
-        * @see ORMTable::getDefaults()
-        * @since 0.1
-        * @return array
-        */
-       public function getDefaults() {
-               return array(
-                       'reviewers' => array(),
-               );
-       }
-
-}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2dcaada461a7d50c3713ba91a9deddce4c409650
Gerrit-PatchSet: 10
Gerrit-Project: mediawiki/extensions/EducationProgram
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Ragesoss <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to