https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113373

Revision: 113373
Author:   jeroendedauw
Date:     2012-03-08 18:21:36 +0000 (Thu, 08 Mar 2012)
Log Message:
-----------
http://education.wmflabs.org/index.php/Thread:MW_1.18_talk:Community_portal/Articles

Modified Paths:
--------------
    trunk/extensions/EducationProgram/EducationProgram.hooks.php
    trunk/extensions/EducationProgram/actions/EPAddArticleAction.php
    trunk/extensions/EducationProgram/includes/EPArticle.php
    trunk/extensions/EducationProgram/includes/EPArticles.php
    trunk/extensions/EducationProgram/sql/EducationProgram.sql

Added Paths:
-----------
    trunk/extensions/EducationProgram/sql/AddArticleTitleField.sql

Modified: trunk/extensions/EducationProgram/EducationProgram.hooks.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.hooks.php        
2012-03-08 18:14:26 UTC (rev 113372)
+++ trunk/extensions/EducationProgram/EducationProgram.hooks.php        
2012-03-08 18:21:36 UTC (rev 113373)
@@ -37,6 +37,14 @@
                        true
                ) );
 
+               $updater->addExtensionUpdate( array(
+                       'addField',
+                       'ep_articles',
+                       'article_page_title',
+                       dirname( __FILE__ ) . '/sql/AddArticleTitleField.sql',
+                       true
+               ) );
+
                return true;
        }
 

Modified: trunk/extensions/EducationProgram/actions/EPAddArticleAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPAddArticleAction.php    
2012-03-08 18:14:26 UTC (rev 113372)
+++ trunk/extensions/EducationProgram/actions/EPAddArticleAction.php    
2012-03-08 18:21:36 UTC (rev 113373)
@@ -34,7 +34,8 @@
                $salt = 'addarticle' . $req->getInt( 'course-id' );
                $title = Title::newFromText( $req->getText( 'addarticlename' ) 
);
 
-               if ( $user->matchEditToken( $req->getText( 'token' ), $salt ) 
&& !is_null( $title ) && $title->getArticleID() !== 0 ) {
+               // TODO: some kind of warning when entering invalid title
+               if ( $user->matchEditToken( $req->getText( 'token' ), $salt ) 
&& !is_null( $title ) ) {
                        $course = EPCourses::singleton()->selectRow(
                                array( 'students', 'name' ),
                                array( 'id' => $req->getInt( 'course-id' ) )
@@ -45,6 +46,7 @@
                                        'user_id' => $user->getId(),
                                        'course_id' => $req->getInt( 
'course-id' ),
                                        'page_id' => $title->getArticleID(),
+                                       'page_title' => $title->getFullText(),
                                );
 
                                if ( !EPArticles::singleton()->has( 
$articleData ) ) {

Modified: trunk/extensions/EducationProgram/includes/EPArticle.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPArticle.php    2012-03-08 
18:14:26 UTC (rev 113372)
+++ trunk/extensions/EducationProgram/includes/EPArticle.php    2012-03-08 
18:21:36 UTC (rev 113373)
@@ -39,6 +39,15 @@
        protected $course = false;
 
        /**
+        * Cached list of user allowances to become reviewer.
+        * int userId => bool canBecomereviewer
+        *
+        * @since 0.1
+        * @var array
+        */
+       protected $canBecomeReviwer = array();
+
+       /**
         * Returns the user that is working on this article.
         *
         * @since 0.1
@@ -88,7 +97,9 @@
         */
        public function getTitle() {
                if ( $this->title === false ) {
-                       $this->title = Title::newFromID( $this->getField( 
'page_id' ) );
+                       $this->title = $this->getField( 'page_id' ) === 0 ?
+                               Title::newFromText( $this->getField( 
'page_title' ) )
+                               : Title::newFromID( $this->getField( 'page_id' 
) );
                }
 
                return $this->title;
@@ -115,8 +126,15 @@
                return $this->course === false ? $course : $this->course;
        }
 
-       protected $canBecomeReviwer = array();
-
+       /**
+        * Returns if the provided User can become a reviwers for this article.
+        *
+        * @since 0.1
+        *
+        * @param User $user
+        *
+        * @return boolean
+        */
        public function canBecomeReviewer( User $user ) {
                if ( !array_key_exists( $user->getId(), $this->canBecomeReviwer 
) ) {
                        $this->canBecomeReviwer[$user->getId()] =
@@ -129,6 +147,17 @@
                return $this->canBecomeReviwer[$user->getId()];
        }
 
+       /**
+        * Adds the users matching the provided ids as reviewers to this 
article.
+        * USers already a reviewer will be ignored. An array with actually 
added user ids
+        * is returned.
+        *
+        * @since 0.1
+        *
+        * @param array $userIds
+        *
+        * @return array
+        */
        public function addReviewers( array $userIds ) {
                $addedIds = array_diff( $userIds, $this->getField( 'reviewers' 
) );
 
@@ -139,10 +168,28 @@
                return $addedIds;
        }
 
+       /**
+        * Logs the adittion of the users matching the provided ids as 
reviewers to this article.
+        *
+        * @since 0.1
+        *
+        * @param array $userIds
+        */
        public function logReviewersAdittion( array $userIds ) {
                // TODO
        }
 
+       /**
+        * Removes the users matching the provided ids as reviewers from this 
article.
+        * Users that are not a reviwer will just be ignored. An array with 
actually removed
+        * user ids is returned.
+        *
+        * @since 0.1
+        *
+        * @param array $userIds
+        *
+        * @return array
+        */
        public function removeReviewers( array $userIds ) {
                $removedIds = array_intersect( $userIds, $this->getField( 
'reviewers' ) );
 
@@ -153,6 +200,13 @@
                return $removedIds;
        }
 
+       /**
+        * Logs the removal of the users matching the provided ids as reviewers 
for this article.
+        *
+        * @since 0.1
+        *
+        * @param array $userIds
+        */
        public function logReviewersRemoval( array $userIds ) {
                // TODO
        }

Modified: trunk/extensions/EducationProgram/includes/EPArticles.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPArticles.php   2012-03-08 
18:14:26 UTC (rev 113372)
+++ trunk/extensions/EducationProgram/includes/EPArticles.php   2012-03-08 
18:21:36 UTC (rev 113373)
@@ -56,6 +56,7 @@
                        'course_id' => 'int',
                        'user_id' => 'int',
                        'page_id' => 'int',
+                       'page_title' => 'str',
                        'reviewers' => 'array',
                );
        }

Copied: trunk/extensions/EducationProgram/sql/AddArticleTitleField.sql (from 
rev 113366, trunk/extensions/EducationProgram/sql/AddCoursesField.sql)
===================================================================
--- trunk/extensions/EducationProgram/sql/AddArticleTitleField.sql              
                (rev 0)
+++ trunk/extensions/EducationProgram/sql/AddArticleTitleField.sql      
2012-03-08 18:21:36 UTC (rev 113373)
@@ -0,0 +1,10 @@
+-- MySQL patch for the Education Program extension.
+-- Licence: GNU GPL v3+
+-- Author: Jeroen De Dauw < [email protected] >
+
+ALTER TABLE /*_*/ep_articles ADD COLUMN article_page_title varchar(255) binary 
NOT NULL;
+
+CREATE INDEX /*i*/ep_articles_page_title ON /*_*/ep_articles 
(article_page_title);
+
+DROP INDEX /*i*/ep_articles_course_page ON /*_*/ep_articles;
+CREATE UNIQUE INDEX /*i*/ep_articles_course_page ON /*_*/ep_articles 
(article_course_id, article_user_id, article_page_title);
\ No newline at end of file

Modified: trunk/extensions/EducationProgram/sql/EducationProgram.sql
===================================================================
--- trunk/extensions/EducationProgram/sql/EducationProgram.sql  2012-03-08 
18:14:26 UTC (rev 113372)
+++ trunk/extensions/EducationProgram/sql/EducationProgram.sql  2012-03-08 
18:21:36 UTC (rev 113373)
@@ -83,6 +83,7 @@
   article_user_id            INT unsigned        NOT NULL, -- Foreign key on 
user.user_id
   article_course_id          INT unsigned        NOT NULL, -- Foreign key on 
ep_courses.course_id
   article_page_id            INT unsigned        NOT NULL, -- Foreign key on 
page.page_id
+  article_page_title         varchar(255) binary NOT NULL, -- Full title of 
the page, to allow for associating non-existing pages
 
   article_reviewers          BLOB                NOT NULL -- List of reviewers 
for this article (linking user.user_id)
 ) /*$wgDBTableOptions*/;
@@ -90,7 +91,8 @@
 CREATE INDEX /*i*/ep_articles_user_id ON /*_*/ep_articles (article_user_id);
 CREATE INDEX /*i*/ep_articles_course_id ON /*_*/ep_articles 
(article_course_id);
 CREATE INDEX /*i*/ep_articles_page_id ON /*_*/ep_articles (article_page_id);
-CREATE UNIQUE INDEX /*i*/ep_articles_course_page ON /*_*/ep_articles 
(article_course_id, article_user_id, article_page_id);
+CREATE INDEX /*i*/ep_articles_page_title ON /*_*/ep_articles 
(article_page_title);
+CREATE UNIQUE INDEX /*i*/ep_articles_course_page ON /*_*/ep_articles 
(article_course_id, article_user_id, article_page_title);
 
 
 


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

Reply via email to