r111851 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111850‎ | r111851 | r111852 >
Date:01:36, 19 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on article table
Modified paths:
  • /trunk/extensions/EducationProgram/actions/EPAddArticleAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPArticleTable.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/actions/EPAddArticleAction.php
@@ -32,21 +32,27 @@
3333 $user = $this->getUser();
3434
3535 $salt = 'addarticle' . $req->getInt( 'course-id' );
 36+ $title = Title::newFromText( $req->getText( 'addarticlename' ) );
3637
37 - if ( $user->matchEditToken( $req->getText( 'token' ), $salt )
38 - && $user->isAllowed( 'ep-student' ) ) {
39 -
40 - $articleData = array(
41 - 'user_id' => $user->getId(),
42 - 'course_id' => $req->getInt( 'course-id' ),
43 - 'page_id' => '',
 38+ if ( $user->matchEditToken( $req->getText( 'token' ), $salt ) && !is_null( $title ) && $title->getArticleID() !== 0 ) {
 39+ $course = EPCourses::singleton()->selectRow(
 40+ array( 'students' ),
 41+ array( 'id' => $req->getInt( 'course-id' ) )
4442 );
4543
46 - if ( !EPArticles::singleton()->has( $articleData ) ) {
47 - $article = EPArticles::singleton()->newFromArray( $articleData, true );
 44+ if ( $course !== false && in_array( $user->getId(), $course->getField( 'students' ) ) ) {
 45+ $articleData = array(
 46+ 'user_id' => $user->getId(),
 47+ 'course_id' => $req->getInt( 'course-id' ),
 48+ 'page_id' => $title->getArticleID(),
 49+ );
4850
49 - if ( $article->save() ) {
50 - // TODO: log
 51+ if ( !EPArticles::singleton()->has( $articleData ) ) {
 52+ $article = EPArticles::singleton()->newFromArray( $articleData, true );
 53+
 54+ if ( $article->save() ) {
 55+ // TODO: log
 56+ }
5157 }
5258 }
5359 }
Index: trunk/extensions/EducationProgram/includes/EPArticleTable.php
@@ -99,7 +99,7 @@
100100 $user = $this->getUser();
101101
102102 $rowCount = array_reduce( $articles, function( /* integer */ $sum, EPArticle $article ) use ( $user ) {
103 - $sum += count( $article->getField( 'reviewers' ) );
 103+ $sum += max( count( $article->getField( 'reviewers' ) ), 1 );
104104
105105 if ( $article->canBecomeReviewer( $user ) ) {
106106 $sum++;
@@ -111,7 +111,7 @@
112112 $html = Html::openElement( 'tr', $this->getRowAttrs( $row ) );
113113
114114 $showArticleAdittion =
115 - $this->getUser()->getId() === $student->getField( 'user_id' )
 115+ $user->getId() === $student->getField( 'user_id' )
116116 && array_key_exists( 'course_id', $this->articleConds )
117117 && is_integer( $this->articleConds['course_id'] );
118118
@@ -174,6 +174,9 @@
175175
176176 $html .= $this->getReviewerAdittionControl( $article );
177177 }
 178+ else if ( count( $reviewers ) === 0 ) {
 179+ $html .= '<td></td>';
 180+ }
178181 }
179182
180183 if ( $showArticleAdittion ) {
@@ -377,38 +380,34 @@
378381 protected function getArticleAdittionControl( $courseId ) {
379382 $html = '';
380383
381 - if ( $this->getUser()->isAllowed( 'ep-student' )
382 - && $this->getUser()->getId() === $this->currentObject->getField( 'user_id' ) ) {
 384+ $html .= Html::openElement(
 385+ 'form',
 386+ array(
 387+ 'method' => 'post',
 388+ 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'epaddarticle' ) ),
 389+ )
 390+ );
383391
384 - $html .= Html::openElement(
385 - 'form',
386 - array(
387 - 'method' => 'post',
388 - 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'epaddarticle' ) ),
389 - )
390 - );
 392+ $html .= Xml::inputLabel(
 393+ wfMsg( 'ep-artciles-addarticle-text' ),
 394+ 'addarticlename',
 395+ 'addarticlename'
 396+ );
391397
392 - $html .= Xml::inputLabel(
393 - wfMsg( 'ep-artciles-addarticle-text' ),
394 - 'addarticlename',
395 - 'addarticlename'
396 - );
 398+ $html .= '&#160;' . Html::input(
 399+ 'addarticle',
 400+ wfMsg( 'ep-artciles-addarticle-button' ),
 401+ 'submit',
 402+ array(
 403+ 'class' => 'ep-addarticle',
 404+ )
 405+ );
397406
398 - $html .= '&#160;' . Html::input(
399 - 'addarticle',
400 - wfMsg( 'ep-artciles-addarticle-button' ),
401 - 'submit',
402 - array(
403 - 'class' => 'ep-addarticle',
404 - )
405 - );
 407+ $html .= Html::hidden( 'course-id', $courseId );
 408+ $html .= Html::hidden( 'token', $this->getUser()->getEditToken( 'addarticle' . $courseId ) );
406409
407 - $html .= Html::hidden( 'token', $this->getUser()->getEditToken( 'addarticle' . $courseId ) );
 410+ $html .= '</form>';
408411
409 - $html .= '</form>';
410 - }
411 -
412 -
413412 return '<td colspan="2">' . $html . '</td>';
414413 }
415414
@@ -487,10 +486,7 @@
488487 while( $student = $this->mResult->fetchObject() ) {
489488 $field = EPStudents::singleton()->getPrefixedField( 'user_id' );
490489 $userIds[] = $student->$field;
491 - $this->articles[$student->$field] = array( // TODO
492 - EPArticles::singleton()->newFromArray( array( 'page_id' => 1, 'user_id' => 1, 'reviewers' => array( 1, 1 ) ) ),
493 - EPArticles::singleton()->newFromArray( array( 'page_id' => 2, 'user_id' => 1, 'reviewers' => array( 1, 1 ) ) ),
494 - );
 490+ $this->articles[$student->$field] = array();
495491 }
496492
497493 $conditions = array_merge( array( 'user_id' => $userIds ), $this->articleConds );

Status & tagging log