r96795 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96794‎ | r96795 | r96796 >
Date:16:28, 11 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
add survey via ArticleViewHeader
Modified paths:
  • /trunk/extensions/Survey/Survey.hooks.php (modified) (history)
  • /trunk/extensions/Survey/Survey.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Survey/Survey.php
@@ -90,6 +90,7 @@
9191 $wgHooks['LoadExtensionSchemaUpdates'][] = 'SurveyHooks::onSchemaUpdate';
9292 $wgHooks['UnitTestsList'][] = 'SurveyHooks::registerUnitTests';
9393 $wgHooks['ParserFirstCallInit'][] = 'SurveyHooks::onParserFirstCallInit';
 94+$wgHooks['ArticleViewHeader'][] = 'SurveyHooks::onArticleViewHeader';
9495
9596 $wgAvailableRights[] = 'surveyadmin';
9697 $wgAvailableRights[] = 'surveysubmit';
Index: trunk/extensions/Survey/Survey.hooks.php
@@ -118,4 +118,66 @@
119119 return true;
120120 }
121121
 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+
122184 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r96796Follow up to r96795;jeroendedauw16:48, 11 September 2011

Status & tagging log