Index: trunk/extensions/Survey/Survey.php |
— | — | @@ -90,6 +90,7 @@ |
91 | 91 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'SurveyHooks::onSchemaUpdate'; |
92 | 92 | $wgHooks['UnitTestsList'][] = 'SurveyHooks::registerUnitTests'; |
93 | 93 | $wgHooks['ParserFirstCallInit'][] = 'SurveyHooks::onParserFirstCallInit'; |
| 94 | +$wgHooks['ArticleViewHeader'][] = 'SurveyHooks::onArticleViewHeader'; |
94 | 95 | |
95 | 96 | $wgAvailableRights[] = 'surveyadmin'; |
96 | 97 | $wgAvailableRights[] = 'surveysubmit'; |
Index: trunk/extensions/Survey/Survey.hooks.php |
— | — | @@ -118,4 +118,66 @@ |
119 | 119 | return true; |
120 | 120 | } |
121 | 121 | |
| 122 | + /** |
| 123 | + * Hook to insert things into article headers. |
| 124 | + * |
| 125 | + * @since 0.1 |
| 126 | + * |
| 127 | + * @param Article &$article |
| 128 | + * @param boolean $outputDone |
| 129 | + * @param boolean $useParserCache |
| 130 | + * |
| 131 | + * @return true |
| 132 | + */ |
| 133 | + public static function onArticleViewHeader( Article &$article, &$outputDone, &$useParserCache ) { |
| 134 | + if ( !Survey::has( array( 'enabled' => 1 ) ) ) { |
| 135 | + return true; |
| 136 | + } |
| 137 | + |
| 138 | + global $wgUser; |
| 139 | + |
| 140 | + $userTypes = array( Survey::$USER_ALL ); |
| 141 | + |
| 142 | + $userTypes[] = $wgUser->isLoggedIn() ? Survey::$USER_LOGGEDIN : Survey::$USER_ANON; |
| 143 | + |
| 144 | + if ( $wgUser->isEmailConfirmed() ) { |
| 145 | + $userTypes[] = Survey::$USER_CONFIRMED; |
| 146 | + } |
| 147 | + |
| 148 | + if ( $wgUser->getEditCount() > 0 ) { |
| 149 | + $userTypes[] = Survey::$USER_EDITOR; |
| 150 | + } |
| 151 | + |
| 152 | + $surveys = Survey::select( |
| 153 | + array( |
| 154 | + 'id', 'namespaces' |
| 155 | + ), |
| 156 | + array( |
| 157 | + 'enabled' => 1, |
| 158 | + 'user_type' => $userTypes |
| 159 | + ) |
| 160 | + ); |
| 161 | + |
| 162 | + foreach ( $surveys as /* Survey */ $survey ) { |
| 163 | + |
| 164 | + if ( count( $survey->getField( 'namespaces' ) ) == 0 ) { |
| 165 | + $nsValid = true; |
| 166 | + } |
| 167 | + else { |
| 168 | + $nsValid = in_array( $article->getTitle()->getNamespace(), $survey->getField( 'namespaces' ) ); |
| 169 | + } |
| 170 | + |
| 171 | + if ( $nsValid ) { |
| 172 | + $GLOBALS['wgOut']->addWikiText( Xml::element( |
| 173 | + 'survey', |
| 174 | + array( |
| 175 | + 'id' => $survey->getId() |
| 176 | + ) |
| 177 | + ) ); |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + return true; |
| 182 | + } |
| 183 | + |
122 | 184 | } |