jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/399774 )

Change subject: Ensure project name is set on 2nd loop when saving
......................................................................


Ensure project name is set on 2nd loop when saving

Also move top-level and other classes into a common namespace.

Bug: T182937
Change-Id: I1a5ef32df6c3164ff0f9bf8d2a0260d6d1a9c935
---
M extension.json
R src/Hooks.php
M src/NamespaceSelect.php
R src/PageAssessmentsDAO.php
M src/SpecialPage.php
M tests/phpunit/PageAssessmentsTest.php
6 files changed, 87 insertions(+), 24 deletions(-)

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



diff --git a/extension.json b/extension.json
index 7387269..cfa78a8 100644
--- a/extension.json
+++ b/extension.json
@@ -19,13 +19,13 @@
                "pageassessments": "ApiQueryPageAssessments"
        },
        "AutoloadClasses": {
-               "PageAssessmentsHooks": "PageAssessmentsHooks.php",
-               "PageAssessmentsBody": "PageAssessmentsBody.php",
                "ApiQueryPageAssessments": "api/ApiQueryPageAssessments.php",
                "ApiQueryProjectPages": "api/ApiQueryProjectPages.php",
                "ApiQueryProjects": "api/ApiQueryProjects.php",
-               "PageAssessments\\SpecialPage": "src/SpecialPage.php",
-               "PageAssessments\\NamespaceSelect": "src/NamespaceSelect.php"
+               "MediaWiki\\Extension\\PageAssessments\\Hooks": "src/Hooks.php",
+               "MediaWiki\\Extension\\PageAssessments\\NamespaceSelect": 
"src/NamespaceSelect.php",
+               "MediaWiki\\Extension\\PageAssessments\\PageAssessmentsDAO": 
"src/PageAssessmentsDAO.php",
+               "MediaWiki\\Extension\\PageAssessments\\SpecialPage": 
"src/SpecialPage.php"
        },
        "ExtensionMessagesFiles": {
                "PageAssessmentsMagic": "PageAssessments.i18n.magic.php",
@@ -33,16 +33,16 @@
        },
        "Hooks": {
                "ParserFirstCallInit": [
-                       "PageAssessmentsHooks::onParserFirstCallInit"
+                       
"MediaWiki\\Extension\\PageAssessments\\Hooks::onParserFirstCallInit"
                ],
                "LoadExtensionSchemaUpdates": [
-                       "PageAssessmentsHooks::onLoadExtensionSchemaUpdates"
+                       
"MediaWiki\\Extension\\PageAssessments\\Hooks::onLoadExtensionSchemaUpdates"
                ],
                "LinksUpdateComplete": [
-                       "PageAssessmentsHooks::onLinksUpdateComplete"
+                       
"MediaWiki\\Extension\\PageAssessments\\Hooks::onLinksUpdateComplete"
                ],
                "ArticleDeleteComplete": [
-                       "PageAssessmentsHooks::onArticleDeleteComplete"
+                       
"MediaWiki\\Extension\\PageAssessments\\Hooks::onArticleDeleteComplete"
                ]
        },
        "MessagesDirs": {
@@ -64,7 +64,7 @@
                }
        },
        "SpecialPages": {
-               "PageAssessments": "PageAssessments\\SpecialPage"
+               "PageAssessments": 
"MediaWiki\\Extension\\PageAssessments\\SpecialPage"
        },
        "config": {
                "PageAssessmentsOnTalkPages": true,
diff --git a/PageAssessmentsHooks.php b/src/Hooks.php
similarity index 84%
rename from PageAssessmentsHooks.php
rename to src/Hooks.php
index fae597b..80a17d7 100644
--- a/PageAssessmentsHooks.php
+++ b/src/Hooks.php
@@ -17,17 +17,30 @@
  *
  * Hooks for PageAssessments extension
  *
+ * @file
  * @ingroup Extensions
  */
 
-class PageAssessmentsHooks {
+namespace MediaWiki\Extension\PageAssessments;
+
+use Article;
+use Content;
+use DatabaseUpdater;
+use LinksUpdate;
+use LogEntry;
+use Parser;
+use RequestContext;
+use User;
+
+class Hooks {
 
        /**
         * Register the parser function hook
         * @param Parser &$parser
         */
-       public static function onParserFirstCallInit( &$parser ) {
-               $parser->setFunctionHook( 'assessment', 
'PageAssessmentsBody::cacheAssessment' );
+       public static function onParserFirstCallInit( Parser &$parser ) {
+               $callback = PageAssessmentsDAO::class . '::cacheAssessment';
+               $parser->setFunctionHook( 'assessment', $callback );
        }
 
        /**
@@ -57,7 +70,7 @@
                        if ( $title->isTalkPage() ) {
                                $title = $title->getSubjectPage();
                        }
-                       PageAssessmentsBody::doUpdates( $title, 
$assessmentData, $ticket );
+                       PageAssessmentsDAO::doUpdates( $title, $assessmentData, 
$ticket );
                }
        }
 
@@ -66,7 +79,7 @@
         * @param DatabaseUpdater $updater DatabaseUpdater object
         */
        public static function onLoadExtensionSchemaUpdates( DatabaseUpdater 
$updater = null ) {
-               $dbDir = __DIR__ . '/db';
+               $dbDir = __DIR__ . '/../db';
                $updater->addExtensionTable( 'page_assessments_projects',
                        "$dbDir/addProjectsTable.sql", true );
                $updater->addExtensionTable( 'page_assessments',
@@ -87,7 +100,7 @@
        public static function onArticleDeleteComplete(
                &$article, &$user, $reason, $id, $content = null, $logEntry
        ) {
-               PageAssessmentsBody::deleteRecordsForPage( $id );
+               PageAssessmentsDAO::deleteRecordsForPage( $id );
        }
 
 }
diff --git a/src/NamespaceSelect.php b/src/NamespaceSelect.php
index f07efbf..7c42807 100644
--- a/src/NamespaceSelect.php
+++ b/src/NamespaceSelect.php
@@ -1,6 +1,25 @@
 <?php
+/**
+ * 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
+ *
+ * @file
+ * @ingroup Extensions
+ */
 
-namespace PageAssessments;
+namespace MediaWiki\Extension\PageAssessments;
 
 use HTMLSelectNamespace;
 use MediaWiki\Widget\NamespaceInputWidget;
diff --git a/PageAssessmentsBody.php b/src/PageAssessmentsDAO.php
similarity index 96%
rename from PageAssessmentsBody.php
rename to src/PageAssessmentsDAO.php
index 255ad75..269a90c 100644
--- a/PageAssessmentsBody.php
+++ b/src/PageAssessmentsDAO.php
@@ -22,9 +22,15 @@
  * @ingroup Extensions
  */
 
-use MediaWiki\MediaWikiServices;
+namespace MediaWiki\Extension\PageAssessments;
 
-class PageAssessmentsBody implements IDBAccessObject {
+use DBAccessObjectUtils;
+use IDBAccessObject;
+use MediaWiki\MediaWikiServices;
+use Parser;
+use Title;
+
+class PageAssessmentsDAO implements IDBAccessObject {
 
        /** @var array Instance cache associating project IDs with project 
names */
        protected static $projectNames = [];
@@ -82,6 +88,10 @@
 
                // Add and update assessment records to the database
                foreach ( $assessmentData as $parserData ) {
+                       // Make sure the name of the project is set.
+                       if ( !isset( $parserData[0] ) || $parserData[0] == '' ) 
{
+                               continue;
+                       }
                        $projectId = $projects[$parserData[0]];
                        if ( $projectId && $pageId ) {
                                $class = $parserData[1];
diff --git a/src/SpecialPage.php b/src/SpecialPage.php
index 603bd12..bcdefe1 100644
--- a/src/SpecialPage.php
+++ b/src/SpecialPage.php
@@ -1,6 +1,25 @@
 <?php
+/**
+ * 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
+ *
+ * @file
+ * @ingroup Extensions
+ */
 
-namespace PageAssessments;
+namespace MediaWiki\Extension\PageAssessments;
 
 use Html;
 use HTMLForm;
diff --git a/tests/phpunit/PageAssessmentsTest.php 
b/tests/phpunit/PageAssessmentsTest.php
index 8576109..25030bc 100644
--- a/tests/phpunit/PageAssessmentsTest.php
+++ b/tests/phpunit/PageAssessmentsTest.php
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\Extension\PageAssessments\PageAssessmentsDAO;
+
 /**
  * Test the database access and core functionality of PageAssessmentsBody.
  *
@@ -20,7 +22,7 @@
         * Test the insertRecord() function in PageAssessmentsBody class
         */
        public function testInsert() {
-               $pageBody = new PageAssessmentsBody;
+               $pageBody = new PageAssessmentsDAO;
                $values = [
                        'pa_page_id' => '10',
                        'pa_project_id' => '3',
@@ -42,7 +44,7 @@
         */
        public function testUpdate() {
                $this->testInsert();
-               $pageBody = new PageAssessmentsBody;
+               $pageBody = new PageAssessmentsDAO;
                $values = [
                        'pa_page_id' => '10',
                        'pa_project_id' => '3',
@@ -64,7 +66,7 @@
         */
        public function testDelete() {
                $this->testInsert();
-               $pageBody = new PageAssessmentsBody;
+               $pageBody = new PageAssessmentsDAO;
                $values = [
                        'pa_page_id' => '10',
                        'pa_project_id' => '3'
@@ -79,7 +81,7 @@
         * Test the getAllProjects() function in PageAssessmentsBody class
         */
        public function testGetAllProjects() {
-               $pageBody = new PageAssessmentsBody;
+               $pageBody = new PageAssessmentsDAO;
                // Insert a record
                $this->testInsert();
                $values = [
@@ -103,7 +105,7 @@
         * Test the cleanProjectTitle() function in PageAssessmentsBody class
         */
        public function testCleanProjectTitle() {
-               $pageBody = new PageAssessmentsBody;
+               $pageBody = new PageAssessmentsDAO;
                $projectTitle = "Drinks/the '''Coffee task force'''";
                $cleanedProjectTitle = $pageBody->cleanProjectTitle( 
$projectTitle );
                $this->assertEquals( "Drinks/Coffee task force", 
$cleanedProjectTitle );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1a5ef32df6c3164ff0f9bf8d2a0260d6d1a9c935
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/PageAssessments
Gerrit-Branch: master
Gerrit-Owner: Samwilson <s...@samwilson.id.au>
Gerrit-Reviewer: Kaldari <rkald...@wikimedia.org>
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