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

Revision: 111848
Author:   jeroendedauw
Date:     2012-02-18 23:54:38 +0000 (Sat, 18 Feb 2012)
Log Message:
-----------
work on article table

Modified Paths:
--------------
    trunk/extensions/EducationProgram/EducationProgram.hooks.php
    trunk/extensions/EducationProgram/EducationProgram.php
    trunk/extensions/EducationProgram/includes/EPArticleTable.php
    trunk/extensions/EducationProgram/resources/ep.articletable.js

Added Paths:
-----------
    trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php

Modified: trunk/extensions/EducationProgram/EducationProgram.hooks.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.hooks.php        
2012-02-18 22:54:47 UTC (rev 111847)
+++ trunk/extensions/EducationProgram/EducationProgram.hooks.php        
2012-02-18 23:54:38 UTC (rev 111848)
@@ -316,5 +316,20 @@
 
                return true;
        }
-       
+
+       /**
+        * Used to add new query-string actions.
+        * @see https://www.mediawiki.org/wiki/Manual:Hooks/UnknownAction
+        *
+        * @since 0.1
+        *
+        * @param string $action
+        * @param Page $page
+        *
+        * @return true
+        */
+       public static function onUnknownAction( $action, Page $page ) {
+               return true;
+       }
+
 }

Modified: trunk/extensions/EducationProgram/EducationProgram.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.php      2012-02-18 
22:54:47 UTC (rev 111847)
+++ trunk/extensions/EducationProgram/EducationProgram.php      2012-02-18 
23:54:38 UTC (rev 111848)
@@ -64,6 +64,7 @@
 $wgAutoloadClasses['EditOrgAction']                            = dirname( 
__FILE__ ) . '/actions/EditOrgAction.php';
 $wgAutoloadClasses['EPEditAction']                                     = 
dirname( __FILE__ ) . '/actions/EPEditAction.php';
 $wgAutoloadClasses['EPHistoryAction']                          = dirname( 
__FILE__ ) . '/actions/EPHistoryAction.php';
+$wgAutoloadClasses['EPRemoveArticleAction']            = dirname( __FILE__ ) . 
'/actions/EPRemoveArticleAction.php';
 $wgAutoloadClasses['EPViewAction']                                     = 
dirname( __FILE__ ) . '/actions/EPViewAction.php';
 $wgAutoloadClasses['OrgHistoryAction']                                 = 
dirname( __FILE__ ) . '/actions/OrgHistoryAction.php';
 $wgAutoloadClasses['ViewCourseAction']                                 = 
dirname( __FILE__ ) . '/actions/ViewCourseAction.php';
@@ -185,7 +186,11 @@
 $wgHooks['ArticleFromTitle'][]                                                 
= 'EPHooks::onArticleFromTitle';
 $wgHooks['CanonicalNamespaces'][]                                      = 
'EPHooks::onCanonicalNamespaces';
 $wgHooks['TitleIsAlwaysKnown'][]                                       = 
'EPHooks::onTitleIsAlwaysKnown';
+$wgHooks['UnknownAction'][]                                            = 
'EPHooks::onUnknownAction';
 
+// Actions
+$wgActions['epremarticle'] = 'EPRemoveArticleAction';
+
 // Logging
 $wgLogTypes[] = 'institution';
 $wgLogTypes[] = 'course';

Added: trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php         
                (rev 0)
+++ trunk/extensions/EducationProgram/actions/EPRemoveArticleAction.php 
2012-02-18 23:54:38 UTC (rev 111848)
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ *
+ *
+ * @since 0.1
+ *
+ * @file EPRemoveArticleAction.php
+ * @ingroup EducationProgram
+ * @ingroup Action
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class EPRemoveArticleAction extends FormlessAction {
+
+       /**
+        * (non-PHPdoc)
+        * @see Action::getName()
+        */
+       public function getName() {
+               return 'epremarticle';
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see FormlessAction::onView()
+        */
+       public function onView() {
+               $req = $this->getRequest();
+               $user = $this->getUser();
+
+               if ( $user->matchEditToken( $req->getText( 'token' ), 
'remarticle' . $req->getInt( 'article-id' ) ) ) {
+                       EPArticles::singleton()->delete( array(
+                               'id' => $req->getInt( 'article-id' ),
+                               'user_id' => $user->getId(),
+                       ) );
+               }
+
+               Action::factory( 'view', $this->page, $this->context )->show();
+               return '';
+       }
+
+
+}
\ No newline at end of file

Modified: trunk/extensions/EducationProgram/includes/EPArticleTable.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPArticleTable.php       
2012-02-18 22:54:47 UTC (rev 111847)
+++ trunk/extensions/EducationProgram/includes/EPArticleTable.php       
2012-02-18 23:54:38 UTC (rev 111848)
@@ -217,6 +217,7 @@
                                                'data-course-id' => 
$this->articleConds['course_id'],
                                                'data-user-name' => $name,
                                                'data-course-name' => 
$this->getCourseName(),
+                                               'data-token' => 
$this->getUser()->getEditToken( $this->articleConds['course_id'] . 'remstudent' 
. $userId ),
                                                'class' => 'ep-rem-student',
                                        ),
                                        wfMsg( 'ep-artciles-remstudent' )
@@ -262,7 +263,7 @@
         * @param integer $rowSpan
         *
         * @return string
-        */-
+        */
        protected function getArticleCell( EPArticle $article, $rowSpan ) {
                $html = Linker::link(
                        $article->getTitle(),
@@ -273,6 +274,7 @@
                        'href' => '#',
                        'data-article-id' => $article->getId(),
                        'data-article-name' => 
$article->getTitle()->getFullText(),
+                       'data-token' => $this->getUser()->getEditToken( 
'remarticle' . $article->getId() ),
                        'class' => 'ep-rem-article',
                );
 
@@ -329,6 +331,7 @@
                                                'data-student-name' => 
$article->getUser()->getName(),
                                                'data-reviewer-name' => 
$user->getName(),
                                                'data-reviewer-id' => 
$user->getId(),
+                                               'data-token' => 
$this->getUser()->getEditToken( $userId . 'remreviewer' . $article->getId() ),
                                                'class' => 'ep-rem-reviewer',
                                        ),
                                        wfMsg( 'ep-artciles-remreviewer' )
@@ -346,6 +349,7 @@
                                        'data-article-id' => $article->getId(),
                                        'data-article-name' => 
$article->getField( 'name' ),
                                        'data-student-name' => 
$article->getUser()->getName(),
+                                       'data-token' => 
$this->getUser()->getEditToken( $userId . 'remreviewer' . $article->getId() ),
                                ),
                                wfMsg( 'ep-artciles-remreviewer-self' )
                        );
@@ -421,6 +425,7 @@
                                'data-article-id' => $article->getId(),
                                'data-article-name' => 
$article->getTitle()->getFullText(),
                                'data-user-name' => 
$article->getUser()->getName(),
+                               'data-token' => $this->getUser()->getEditToken( 
'addreviewer' . $article->getId() ),
                        ),
                        wfMsg( 'ep-artciles-becomereviewer' )
                );

Modified: trunk/extensions/EducationProgram/resources/ep.articletable.js
===================================================================
--- trunk/extensions/EducationProgram/resources/ep.articletable.js      
2012-02-18 22:54:47 UTC (rev 111847)
+++ trunk/extensions/EducationProgram/resources/ep.articletable.js      
2012-02-18 23:54:38 UTC (rev 111848)
@@ -29,6 +29,12 @@
 
                $form.append( $( '<input>' ).attr( {
                        'type': 'hidden',
+                       'name': 'token',
+                       'value': $this.attr( 'data-token' )
+               } ) );
+
+               $form.append( $( '<input>' ).attr( {
+                       'type': 'hidden',
                        'name': 'article-id',
                        'value': $this.attr( 'data-article-id' )
                } ) );
@@ -78,6 +84,12 @@
 
                $form.append( $( '<input>' ).attr( {
                        'type': 'hidden',
+                       'name': 'token',
+                       'value': $this.attr( 'data-token' )
+               } ) );
+
+               $form.append( $( '<input>' ).attr( {
+                       'type': 'hidden',
                        'name': 'user-id',
                        'value': $this.attr( 'data-user-id' )
                } ) );
@@ -133,6 +145,12 @@
 
                $form.append( $( '<input>' ).attr( {
                        'type': 'hidden',
+                       'name': 'token',
+                       'value': $this.attr( 'data-token' )
+               } ) );
+
+               $form.append( $( '<input>' ).attr( {
+                       'type': 'hidden',
                        'name': 'article-id',
                        'value': $this.attr( 'data-article-id' )
                } ) );
@@ -186,6 +204,12 @@
 
                $form.append( $( '<input>' ).attr( {
                        'type': 'hidden',
+                       'name': 'token',
+                       'value': $this.attr( 'data-token' )
+               } ) );
+
+               $form.append( $( '<input>' ).attr( {
+                       'type': 'hidden',
                        'name': 'article-id',
                        'value': $this.attr( 'data-article-id' )
                } ) );


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

Reply via email to