| Index: trunk/extensions/Survey/Survey.i18n.php |
| — | — | @@ -24,6 +24,7 @@ |
| 25 | 25 | 'right-surveysubmit' => 'Participate in surveys', |
| 26 | 26 | |
| 27 | 27 | 'special-surveys' => 'Surveys admin', |
| | 28 | + 'special-survey' => 'Survey admin', |
| 28 | 29 | 'special-surveystats' => 'Survey statistics', |
| 29 | 30 | |
| 30 | 31 | '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 @@ |
| 60 | 60 | $wgAutoloadClasses['SurveyQuestion'] = dirname( __FILE__ ) . '/includes/SurveyQuestion.php'; |
| 61 | 61 | $wgAutoloadClasses['SurveySubmission'] = dirname( __FILE__ ) . '/includes/SurveySubmission.php'; |
| 62 | 62 | |
| | 63 | +$wgAutoloadClasses['SpecialSurvey'] = dirname( __FILE__ ) . '/specials/SpecialSurvey.php'; |
| | 64 | +$wgAutoloadClasses['SpecialSurveyPage'] = dirname( __FILE__ ) . '/specials/SpecialSurveyPage.php'; |
| 63 | 65 | $wgAutoloadClasses['SpecialSurveys'] = dirname( __FILE__ ) . '/specials/SpecialSurveys.php'; |
| 64 | 66 | $wgAutoloadClasses['SpecialSurveyStats'] = dirname( __FILE__ ) . '/specials/SpecialSurveyStats.php'; |
| | 67 | +$wgAutoloadClasses['SpecialTakeSurvey'] = dirname( __FILE__ ) . '/specials/SpecialTakeSurvey.php'; |
| 65 | 68 | |
| | 69 | +$wgSpecialPages['Survey'] = 'SpecialSurvey'; |
| 66 | 70 | $wgSpecialPages['Surveys'] = 'SpecialSurveys'; |
| 67 | 71 | $wgSpecialPages['SurveyStats'] = 'SpecialSurveyStats'; |
| | 72 | +$wgSpecialPages['TakeSurvey'] = 'SpecialTakeSurvey'; |
| 68 | 73 | |
| | 74 | +$wgSpecialPageGroups['Survey'] = 'other'; |
| 69 | 75 | $wgSpecialPageGroups['Surveys'] = 'other'; |
| 70 | 76 | $wgSpecialPageGroups['SurveyStats'] = 'other'; |
| | 77 | +$wgSpecialPageGroups['TakeSurvey'] = 'other'; |
| 71 | 78 | |
| 72 | 79 | $wgAPIModules['addsurvey'] = 'ApiAddSurvey'; |
| 73 | 80 | $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 |
| 1 | 73 | + native |
| Index: trunk/extensions/Survey/specials/SpecialSurveyStats.php |
| — | — | @@ -11,7 +11,7 @@ |
| 12 | 12 | * @licence GNU GPL v3 or later |
| 13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | 14 | */ |
| 15 | | -class SpecialSurveyStats extends SpecialPage { |
| | 15 | +class SpecialSurveyStats extends SpecialSurveyPage { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * Constructor. |
| — | — | @@ -23,27 +23,6 @@ |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
| 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 | | - /** |
| 48 | 27 | * Main method. |
| 49 | 28 | * |
| 50 | 29 | * @since 0.1 |
| — | — | @@ -51,17 +30,8 @@ |
| 52 | 31 | * @param string $arg |
| 53 | 32 | */ |
| 54 | 33 | public function execute( $subPage ) { |
| 55 | | - global $wgOut, $wgUser; |
| | 34 | + parent::execute( $subPage ); |
| 56 | 35 | |
| 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 | | - |
| 66 | 36 | } |
| 67 | 37 | |
| 68 | 38 | } |
| 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 |
| 1 | 39 | + native |
| Index: trunk/extensions/Survey/specials/SpecialSurveys.php |
| — | — | @@ -11,7 +11,7 @@ |
| 12 | 12 | * @licence GNU GPL v3 or later |
| 13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | 14 | */ |
| 15 | | -class SpecialSurveys extends SpecialPage { |
| | 15 | +class SpecialSurveys extends SpecialSurveyPage { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * Constructor. |
| — | — | @@ -23,45 +23,153 @@ |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | | - * @see SpecialPage::getDescription |
| | 27 | + * Main method. |
| 28 | 28 | * |
| 29 | 29 | * @since 0.1 |
| | 30 | + * |
| | 31 | + * @param string $arg |
| 30 | 32 | */ |
| 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 | + } |
| 33 | 46 | } |
| 34 | 47 | |
| 35 | 48 | /** |
| 36 | | - * Sets headers - this should be called from the execute() method of all derived classes! |
| | 49 | + * Displays surveys. |
| 37 | 50 | * |
| 38 | 51 | * @since 0.1 |
| 39 | 52 | */ |
| 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 | + } |
| 46 | 71 | |
| 47 | 72 | /** |
| 48 | | - * Main method. |
| | 73 | + * Displays a small form to add a new campaign. |
| 49 | 74 | * |
| 50 | 75 | * @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( ' ' . Html::input( 'newsurvey' ) . ' ' ); |
| | 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. |
| 51 | 112 | * |
| 52 | | - * @param string $arg |
| | 113 | + * @since 0.1 |
| | 114 | + * |
| | 115 | + * @param ResultWrapper $surveys |
| 53 | 116 | */ |
| 54 | | - public function execute( $subPage ) { |
| 55 | | - global $wgOut, $wgUser; |
| | 117 | + protected function displaySurveysTable( ResultWrapper $surveys ) { |
| | 118 | + $out = $this->getOutput(); |
| 56 | 119 | |
| 57 | | - $this->setHeaders(); |
| 58 | | - $this->outputHeader(); |
| | 120 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'surveys-special-existing' ) ) ); |
| 59 | 121 | |
| 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 | + ); |
| 64 | 171 | } |
| 65 | 172 | |
| 66 | | - } |
| | 173 | + $out->addHTML( '</table>' ); |
| | 174 | + } |
| 67 | 175 | |
| 68 | 176 | } |
| 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 |
| 1 | 39 | + native |
| Index: trunk/extensions/Survey/includes/Survey.class.php |
| — | — | @@ -243,8 +243,6 @@ |
| 244 | 244 | * @return boolean Success indicator |
| 245 | 245 | */ |
| 246 | 246 | public function removeFromDB() { |
| 247 | | - $sucecss = parent::removeFromDB(); |
| 248 | | - |
| 249 | 247 | $dbr= wfgetDB( DB_SLAVE ); |
| 250 | 248 | |
| 251 | 249 | $submissionsForSurvey = $dbr->select( |
| — | — | @@ -257,10 +255,7 @@ |
| 258 | 256 | |
| 259 | 257 | $dbw->begin(); |
| 260 | 258 | |
| 261 | | - $sucecss = $dbw->delete( |
| 262 | | - 'surveys', |
| 263 | | - array( 'survey_id' => $this->id ) |
| 264 | | - ); |
| | 259 | + $sucecss = parent::removeFromDB(); |
| 265 | 260 | |
| 266 | 261 | $sucecss = $dbw->delete( |
| 267 | 262 | 'survey_questions', |
| — | — | @@ -289,4 +284,4 @@ |
| 290 | 285 | return $sucecss; |
| 291 | 286 | } |
| 292 | 287 | |
| 293 | | -} |
| \ No newline at end of file |
| | 288 | +} |
| Index: trunk/extensions/Survey/Survey.alias.php |
| — | — | @@ -17,5 +17,6 @@ |
| 18 | 18 | /** English (English) */ |
| 19 | 19 | $specialPageAliases['en'] = array( |
| 20 | 20 | 'Surveys' => array( 'Surveys' ), |
| | 21 | + 'Survey' => array( 'Survey' ), |
| 21 | 22 | 'SurveyStats' => array( 'SurveyStats', 'SurveyStatistics' ), |
| 22 | 23 | ); |