r95393 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:< r95392‎ | r95393 | r95394 >
Date:11:23, 24 August 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on special pages
Modified paths:
  • /trunk/extensions/Survey/Survey.alias.php (modified) (history)
  • /trunk/extensions/Survey/Survey.i18n.php (modified) (history)
  • /trunk/extensions/Survey/Survey.php (modified) (history)
  • /trunk/extensions/Survey/includes/Survey.class.php (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialSurvey.php (added) (history)
  • /trunk/extensions/Survey/specials/SpecialSurveyPage.php (added) (history)
  • /trunk/extensions/Survey/specials/SpecialSurveyStats.php (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialSurveys.php (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialTakeSurvey.php (added) (history)

Diff [purge]

Index: trunk/extensions/Survey/Survey.i18n.php
——@@ -24,6 +24,7 @@
2525 'right-surveysubmit' => 'Participate in surveys',
2626
2727 'special-surveys' => 'Surveys admin',
 28+ 'special-survey' => 'Survey admin',
2829 'special-surveystats' => 'Survey statistics',
2930
3031 'survey-err-id-xor-name' => 'You need to provide either the id or the name of the survey to submit',
Index: trunk/extensions/Survey/Survey.php
——@@ -59,14 +59,21 @@
6060 $wgAutoloadClasses['SurveyQuestion'] = dirname( __FILE__ ) . '/includes/SurveyQuestion.php';
6161 $wgAutoloadClasses['SurveySubmission'] = dirname( __FILE__ ) . '/includes/SurveySubmission.php';
6262
 63+$wgAutoloadClasses['SpecialSurvey'] = dirname( __FILE__ ) . '/specials/SpecialSurvey.php';
 64+$wgAutoloadClasses['SpecialSurveyPage'] = dirname( __FILE__ ) . '/specials/SpecialSurveyPage.php';
6365 $wgAutoloadClasses['SpecialSurveys'] = dirname( __FILE__ ) . '/specials/SpecialSurveys.php';
6466 $wgAutoloadClasses['SpecialSurveyStats'] = dirname( __FILE__ ) . '/specials/SpecialSurveyStats.php';
 67+$wgAutoloadClasses['SpecialTakeSurvey'] = dirname( __FILE__ ) . '/specials/SpecialTakeSurvey.php';
6568
 69+$wgSpecialPages['Survey'] = 'SpecialSurvey';
6670 $wgSpecialPages['Surveys'] = 'SpecialSurveys';
6771 $wgSpecialPages['SurveyStats'] = 'SpecialSurveyStats';
 72+$wgSpecialPages['TakeSurvey'] = 'SpecialTakeSurvey';
6873
 74+$wgSpecialPageGroups['Survey'] = 'other';
6975 $wgSpecialPageGroups['Surveys'] = 'other';
7076 $wgSpecialPageGroups['SurveyStats'] = 'other';
 77+$wgSpecialPageGroups['TakeSurvey'] = 'other';
7178
7279 $wgAPIModules['addsurvey'] = 'ApiAddSurvey';
7380 $wgAPIModules['deletesurvey'] = 'ApiDeleteSurvey';
Index: trunk/extensions/Survey/specials/SpecialSurveyPage.php
——@@ -0,0 +1,71 @@
 2+<?php
 3+
 4+/**
 5+ * Base special page for special pages in the Survey extension,
 6+ * taking care of some common stuff and providing compatibility helpers.
 7+ *
 8+ * @since 0.1
 9+ *
 10+ * @file SpecialSurveyPage.php
 11+ * @ingroup Survey
 12+ *
 13+ * @licence GNU GPL v3 or later
 14+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 15+ */
 16+abstract class SpecialSurveyPage extends SpecialPage {
 17+
 18+ /**
 19+ * @see SpecialPage::getDescription
 20+ *
 21+ * @since 0.1
 22+ */
 23+ public function getDescription() {
 24+ return wfMsg( 'special-' . strtolower( $this->getName() ) );
 25+ }
 26+
 27+ /**
 28+ * Sets headers - this should be called from the execute() method of all derived classes!
 29+ *
 30+ * @since 0.1
 31+ */
 32+ public function setHeaders() {
 33+ $out = $this->getOutput();
 34+ $out->setArticleRelated( false );
 35+ $out->setRobotPolicy( 'noindex,nofollow' );
 36+ $out->setPageTitle( $this->getDescription() );
 37+ }
 38+
 39+ /**
 40+ * Main method.
 41+ *
 42+ * @since 0.1
 43+ *
 44+ * @param string $arg
 45+ */
 46+ public function execute( $subPage ) {
 47+ global $wgUser;
 48+
 49+ $this->setHeaders();
 50+ $this->outputHeader();
 51+
 52+ // If the user is authorized, display the page, if not, show an error.
 53+ if ( !$this->userCanExecute( $wgUser ) ) {
 54+ $this->displayRestrictionError();
 55+ return;
 56+ }
 57+ }
 58+
 59+ /**
 60+ * Get the OutputPage being used for this instance.
 61+ * This overrides the getOutput method of Specialpage added in MediaWiki 1.18,
 62+ * and returns $wgOut for older versions.
 63+ *
 64+ * @since 0.1
 65+ *
 66+ * @return OutputPage
 67+ */
 68+ public function getOutput() {
 69+ return version_compare( $GLOBALS['wgVersion'], '1.18', '>=' ) ? parent::getOutput() : $GLOBALS['wgOut'];
 70+ }
 71+
 72+}
Property changes on: trunk/extensions/Survey/specials/SpecialSurveyPage.php
___________________________________________________________________
Added: svn:eol-style
173 + native
Index: trunk/extensions/Survey/specials/SpecialSurveyStats.php
——@@ -11,7 +11,7 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class SpecialSurveyStats extends SpecialPage {
 15+class SpecialSurveyStats extends SpecialSurveyPage {
1616
1717 /**
1818 * Constructor.
——@@ -23,27 +23,6 @@
2424 }
2525
2626 /**
27 - * @see SpecialPage::getDescription
28 - *
29 - * @since 0.1
30 - */
31 - public function getDescription() {
32 - return wfMsg( 'special-' . strtolower( $this->getName() ) );
33 - }
34 -
35 - /**
36 - * Sets headers - this should be called from the execute() method of all derived classes!
37 - *
38 - * @since 0.1
39 - */
40 - public function setHeaders() {
41 - global $wgOut;
42 - $wgOut->setArticleRelated( false );
43 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
44 - $wgOut->setPageTitle( $this->getDescription() );
45 - }
46 -
47 - /**
4827 * Main method.
4928 *
5029 * @since 0.1
——@@ -51,17 +30,8 @@
5231 * @param string $arg
5332 */
5433 public function execute( $subPage ) {
55 - global $wgOut, $wgUser;
 34+ parent::execute( $subPage );
5635
57 - $this->setHeaders();
58 - $this->outputHeader();
59 -
60 - // If the user is authorized, display the page, if not, show an error.
61 - if ( !$this->userCanExecute( $wgUser ) ) {
62 - $this->displayRestrictionError();
63 - return;
64 - }
65 -
6636 }
6737
6838 }
Index: trunk/extensions/Survey/specials/SpecialSurvey.php
——@@ -0,0 +1,37 @@
 2+<?php
 3+
 4+/**
 5+ * Administration interface for a survey.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file SpecialSurvey.php
 10+ * @ingroup Survey
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class SpecialSurvey extends SpecialSurveyPage {
 16+
 17+ /**
 18+ * Constructor.
 19+ *
 20+ * @since 0.1
 21+ */
 22+ public function __construct() {
 23+ parent::__construct( 'Survey', 'surveyadmin' );
 24+ }
 25+
 26+ /**
 27+ * Main method.
 28+ *
 29+ * @since 0.1
 30+ *
 31+ * @param string $arg
 32+ */
 33+ public function execute( $subPage ) {
 34+ parent::execute( $subPage );
 35+
 36+ }
 37+
 38+}
Property changes on: trunk/extensions/Survey/specials/SpecialSurvey.php
___________________________________________________________________
Added: svn:eol-style
139 + native
Index: trunk/extensions/Survey/specials/SpecialSurveys.php
——@@ -11,7 +11,7 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class SpecialSurveys extends SpecialPage {
 15+class SpecialSurveys extends SpecialSurveyPage {
1616
1717 /**
1818 * Constructor.
——@@ -23,45 +23,153 @@
2424 }
2525
2626 /**
27 - * @see SpecialPage::getDescription
 27+ * Main method.
2828 *
2929 * @since 0.1
 30+ *
 31+ * @param string $arg
3032 */
31 - public function getDescription() {
32 - return wfMsg( 'special-' . strtolower( $this->getName() ) );
 33+ public function execute( $subPage ) {
 34+ parent::execute( $subPage );
 35+
 36+ global $wgRequest;
 37+
 38+ if ( $wgRequest->wasPosted()
 39+ && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) )
 40+ && $wgRequest->getCheck( 'newsurvey' ) ) {
 41+ $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Survey', $wgRequest->getVal( 'newsurvey' ) )->getLocalURL() );
 42+ }
 43+ else {
 44+ $this->displaySurveys();
 45+ }
3346 }
3447
3548 /**
36 - * Sets headers - this should be called from the execute() method of all derived classes!
 49+ * Displays surveys.
3750 *
3851 * @since 0.1
3952 */
40 - public function setHeaders() {
41 - global $wgOut;
42 - $wgOut->setArticleRelated( false );
43 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
44 - $wgOut->setPageTitle( $this->getDescription() );
45 - }
 53+ protected function displaySurveys() {
 54+ $this->displayAddNewControl();
 55+
 56+ $dbr = wfGetDB( DB_SLAVE );
 57+
 58+ $surveys = $dbr->select(
 59+ 'surveys',
 60+ array(
 61+ 'survey_id',
 62+ 'survey_name',
 63+ 'survey_enabled',
 64+ )
 65+ );
 66+
 67+ if ( $surveys->numRows() > 0 ) {
 68+ $this->displaySurveysTable( $surveys );
 69+ }
 70+ }
4671
4772 /**
48 - * Main method.
 73+ * Displays a small form to add a new campaign.
4974 *
5075 * @since 0.1
 76+ */
 77+ protected function displayAddNewControl() {
 78+ $out = $this->getOutput();
 79+
 80+ $out->addHTML( Html::openElement(
 81+ 'form',
 82+ array(
 83+ 'method' => 'post',
 84+ 'action' => $this->getTitle()->getLocalURL(),
 85+ )
 86+ ) );
 87+
 88+ $out->addHTML( '<fieldset>' );
 89+
 90+ $out->addHTML( '<legend>' . htmlspecialchars( wfMsg( 'surveys-special-addnew' ) ) . '</legend>' );
 91+
 92+ $out->addHTML( Html::element( 'p', array(), wfMsg( 'surveys-special-namedoc' ) ) );
 93+
 94+ $out->addHTML( Html::element( 'label', array( 'for' => 'newcampaign' ), wfMsg( 'surveys-special-newname' ) ) );
 95+
 96+ $out->addHTML( '&#160;' . Html::input( 'newsurvey' ) . '&#160;' );
 97+
 98+ $out->addHTML( Html::input(
 99+ 'addnewsurvey',
 100+ wfMsg( 'surveys-special-add' ),
 101+ 'submit'
 102+ ) );
 103+
 104+ global $wgUser;
 105+ $out->addHTML( Html::hidden( 'wpEditToken', $wgUser->editToken() ) );
 106+
 107+ $out->addHTML( '</fieldset></form>' );
 108+ }
 109+
 110+ /**
 111+ * Displays a list of all survets.
51112 *
52 - * @param string $arg
 113+ * @since 0.1
 114+ *
 115+ * @param ResultWrapper $surveys
53116 */
54 - public function execute( $subPage ) {
55 - global $wgOut, $wgUser;
 117+ protected function displaySurveysTable( ResultWrapper $surveys ) {
 118+ $out = $this->getOutput();
56119
57 - $this->setHeaders();
58 - $this->outputHeader();
 120+ $out->addHTML( Html::element( 'h2', array(), wfMsg( 'surveys-special-existing' ) ) );
59121
60 - // If the user is authorized, display the page, if not, show an error.
61 - if ( !$this->userCanExecute( $wgUser ) ) {
62 - $this->displayRestrictionError();
63 - return;
 122+ $out->addHTML( Xml::openElement(
 123+ 'table',
 124+ array( 'class' => 'wikitable', 'style' => 'width:400px' )
 125+ ) );
 126+
 127+ $out->addHTML(
 128+ '<tr>' .
 129+ Html::element( 'th', array(), wfMsg( 'surveys-special-name' ) ) .
 130+ Html::element( 'th', array(), wfMsg( 'surveys-special-status' ) ) .
 131+ Html::element( 'th', array(), wfMsg( 'surveys-special-edit' ) ) .
 132+ Html::element( 'th', array(), wfMsg( 'surveys-special-delete' ) ) .
 133+ '</tr>'
 134+ );
 135+
 136+ foreach ( $surveys as $survey ) {
 137+ $out->addHTML(
 138+ '<tr>' .
 139+ '<td>' .
 140+ Html::element(
 141+ 'a',
 142+ array(
 143+ 'href' => SpecialPage::getTitleFor( 'TakeSurvey', $survey->survey_name )->getLocalURL()
 144+ ),
 145+ $survey->survey_name
 146+ ) .
 147+ '</td>' .
 148+ Html::element( 'td', array(), wfMsg( 'surveys-special-' . ( $survey->survey_enabled ? 'enabled' : 'disabled' ) ) ) .
 149+ '<td>' .
 150+ Html::element(
 151+ 'a',
 152+ array(
 153+ 'href' => SpecialPage::getTitleFor( 'Survey', $survey->survey_name )->getLocalURL()
 154+ ),
 155+ wfMsg( 'surveys-special-edit' )
 156+ ) .
 157+ '</td>' .
 158+ '<td>' .
 159+ Html::element(
 160+ 'a',
 161+ array(
 162+ 'href' => '#',
 163+ 'class' => 'survey-delete',
 164+ 'data-survey-id' => $survey->survey_id
 165+ ),
 166+ wfMsg( 'surveys-special-delete' )
 167+ ) .
 168+ '</td>' .
 169+ '</tr>'
 170+ );
64171 }
65172
66 - }
 173+ $out->addHTML( '</table>' );
 174+ }
67175
68176 }
Index: trunk/extensions/Survey/specials/SpecialTakeSurvey.php
——@@ -0,0 +1,37 @@
 2+<?php
 3+
 4+/**
 5+ * Page on which a survey is displayed.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file SpecialTakeSurvey.php
 10+ * @ingroup Survey
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class SpecialTakeSurvey extends SpecialSurveyPage {
 16+
 17+ /**
 18+ * Constructor.
 19+ *
 20+ * @since 0.1
 21+ */
 22+ public function __construct() {
 23+ parent::__construct( 'TakeSurvey', 'surveysubmit' );
 24+ }
 25+
 26+ /**
 27+ * Main method.
 28+ *
 29+ * @since 0.1
 30+ *
 31+ * @param string $arg
 32+ */
 33+ public function execute( $subPage ) {
 34+ parent::execute( $subPage );
 35+
 36+ }
 37+
 38+}
Property changes on: trunk/extensions/Survey/specials/SpecialTakeSurvey.php
___________________________________________________________________
Added: svn:eol-style
139 + native
Index: trunk/extensions/Survey/includes/Survey.class.php
——@@ -243,8 +243,6 @@
244244 * @return boolean Success indicator
245245 */
246246 public function removeFromDB() {
247 - $sucecss = parent::removeFromDB();
248 -
249247 $dbr= wfgetDB( DB_SLAVE );
250248
251249 $submissionsForSurvey = $dbr->select(
——@@ -257,10 +255,7 @@
258256
259257 $dbw->begin();
260258
261 - $sucecss = $dbw->delete(
262 - 'surveys',
263 - array( 'survey_id' => $this->id )
264 - );
 259+ $sucecss = parent::removeFromDB();
265260
266261 $sucecss = $dbw->delete(
267262 'survey_questions',
——@@ -289,4 +284,4 @@
290285 return $sucecss;
291286 }
292287
293 -}
\ No newline at end of file
 288+}
Index: trunk/extensions/Survey/Survey.alias.php
——@@ -17,5 +17,6 @@
1818 /** English (English) */
1919 $specialPageAliases['en'] = array(
2020 'Surveys' => array( 'Surveys' ),
 21+ 'Survey' => array( 'Survey' ),
2122 'SurveyStats' => array( 'SurveyStats', 'SurveyStatistics' ),
2223 );

Follow-up revisions

RevisionCommit summaryAuthorDate
r95394fu r95393; added missing alias and messagesjeroendedauw11:28, 24 August 2011

Status & tagging log