Index: trunk/extensions/ArticleEmblems/ArticleEmblems.hooks.php |
— | — | @@ -0,0 +1,102 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Hooks for ArticleEmblems extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +class ArticleEmblemsHooks { |
| 11 | + |
| 12 | + /* Protected Static Members */ |
| 13 | + |
| 14 | + protected static $emblems = array(); |
| 15 | + |
| 16 | + /* Static Methods */ |
| 17 | + |
| 18 | + /** |
| 19 | + * LoadExtensionSchemaUpdates hook |
| 20 | + * |
| 21 | + * @param $updater DatabaseUpdater |
| 22 | + */ |
| 23 | + public static function loadExtensionSchemaUpdates( $updater = null ) { |
| 24 | + if ( $updater === null ) { |
| 25 | + global $wgExtNewTables; |
| 26 | + $wgExtNewTables[] = array( 'articleemblems', dirname( __FILE__ ) . '/patches/ArticleEmblems.sql' ); |
| 27 | + } else { |
| 28 | + $updater->addExtensionUpdate( array( 'addTable', 'articleemblems', dirname( __FILE__ ) . '/patches/ArticleEmblems.sql', true ) ); |
| 29 | + } |
| 30 | + return true; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * ParserTestTables hook |
| 35 | + */ |
| 36 | + public static function parserTestTables( &$tables ) { |
| 37 | + $tables[] = 'articleemblems'; |
| 38 | + return true; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * ParserInit hook |
| 43 | + * |
| 44 | + * @param $parser Parser |
| 45 | + */ |
| 46 | + public static function parserInit( &$parser ) { |
| 47 | + $parser->setHook( 'emblem', 'ArticleEmblemsHooks::render' ); |
| 48 | + return true; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Renderer for <emblem> parser tag hook |
| 53 | + * |
| 54 | + * @param $input |
| 55 | + * @param $args Array |
| 56 | + * @param $parser Parser |
| 57 | + * @param $frame |
| 58 | + */ |
| 59 | + public static function render( $input, $args, $parser, $frame ) { |
| 60 | + self::$emblems[] = $parser->recursiveTagParse( $input, $frame ); |
| 61 | + return null; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * ArticleSaveComplete hook |
| 66 | + * |
| 67 | + * @param $article Article |
| 68 | + */ |
| 69 | + public static function articleSaveComplete( &$article ) { |
| 70 | + $articleId = $article->getId(); |
| 71 | + $dbw = wfGetDB( DB_MASTER ); |
| 72 | + $dbw->delete( 'articleemblems', array( 'ae_article' => $articleId ), __METHOD__ ); |
| 73 | + $emblems = array(); |
| 74 | + foreach ( self::$emblems as $emblem ) { |
| 75 | + $emblems[] = array( 'ae_article' => $articleId, 'ae_value' => $emblem ); |
| 76 | + } |
| 77 | + $dbw->insert( 'articleemblems', array_reverse( $emblems ), __METHOD__ ); |
| 78 | + return true; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * ArticleViewHeader hook |
| 83 | + * |
| 84 | + * @param $article Article |
| 85 | + * @param $outputDone |
| 86 | + * @param $pcache |
| 87 | + */ |
| 88 | + public static function articleViewHeader( &$article, &$outputDone, &$pcache ) { |
| 89 | + global $wgOut; |
| 90 | + |
| 91 | + $wgOut->addModuleStyles( 'ext.articleEmblems' ); |
| 92 | + |
| 93 | + $articleId = $article->getId(); |
| 94 | + $dbr = wfGetDB( DB_SLAVE ); |
| 95 | + $results = $dbr->select( 'articleemblems', 'ae_value', array( 'ae_article' => $articleId ), __METHOD__ ); |
| 96 | + $emblems = array(); |
| 97 | + foreach ( $results as $emblem ) { |
| 98 | + $emblems[] = '<li class="articleEmblem">' . $emblem['ae_value'] . '</li>'; |
| 99 | + } |
| 100 | + $wgOut->addHtml( '<ul id="articleEmblems">' . implode( $emblems ) . '</ul>' ); |
| 101 | + return true; |
| 102 | + } |
| 103 | +} |
Property changes on: trunk/extensions/ArticleEmblems/ArticleEmblems.hooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 104 | + native |
Index: trunk/extensions/ArticleEmblems/patches/ArticleEmblems.sql |
— | — | @@ -0,0 +1,12 @@ |
| 2 | +-- |
| 3 | +-- Schema for ArticleEmblems |
| 4 | +-- |
| 5 | + |
| 6 | +CREATE TABLE IF NOT EXISTS /*_*/articleemblems ( |
| 7 | + -- Article ID |
| 8 | + ae_article int NOT NULL, |
| 9 | + -- Emblem value |
| 10 | + ae_value blob NOT NULL |
| 11 | +) /*$wgDBTableOptions*/; |
| 12 | + |
| 13 | +CREATE INDEX /*i*/ae_article ON /*_*/articleemblems (ae_article); |
Property changes on: trunk/extensions/ArticleEmblems/patches/ArticleEmblems.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 14 | + native |
Index: trunk/extensions/ArticleEmblems/modules/ext.articleEmblems.css |
— | — | @@ -0,0 +1,18 @@ |
| 2 | +/* |
| 3 | + * CSS for ArticleEmblems extension |
| 4 | + */ |
| 5 | + |
| 6 | +#articleEmblems { |
| 7 | + float: right; |
| 8 | + list-style: none; |
| 9 | + margin-top: 0; |
| 10 | +} |
| 11 | +/* IGNORED BY IE6 */ |
| 12 | +html > body #articleEmblems { |
| 13 | + margin-top: -1em; |
| 14 | +} |
| 15 | +#articleEmblems li { |
| 16 | + float: right; |
| 17 | + list-style: none; |
| 18 | + margin-left: 0.5em; |
| 19 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/ArticleEmblems/modules/ext.articleEmblems.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 20 | + native |
Index: trunk/extensions/ArticleEmblems/ArticleEmblems.i18n.php |
— | — | @@ -0,0 +1,17 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation for ArticleEmblems extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$messages = array(); |
| 11 | + |
| 12 | +/** English |
| 13 | + * @author Trevor Parscal |
| 14 | + */ |
| 15 | +$messages['en'] = array( |
| 16 | + 'articleEmblems' => 'Article Emblems', |
| 17 | + 'articleEmblems-desc' => 'Parser hook that collects and renders extra information about an article', |
| 18 | +); |
Property changes on: trunk/extensions/ArticleEmblems/ArticleEmblems.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 19 | + native |
Index: trunk/extensions/ArticleEmblems/README |
— | — | @@ -0,0 +1,10 @@ |
| 2 | +# ArticleEmblems provides a parser hook that collects and renders extra information about an article |
| 3 | + |
| 4 | +# This extension requires MediaWiki 1.17+ because it makes use of ResourceLoader. |
| 5 | + |
| 6 | +# Example LocalSettings.php additions |
| 7 | + |
| 8 | +require_once( "$IP/extensions/ArticleEmblems/ArticleEmblems.php" ); |
| 9 | + |
| 10 | +# To use this extension, add <emblem>any wiki-text you want</emblem> to an article. The wikitext will appear in the top |
| 11 | +# right (or left when $wgContLang is an RTL language). Emblems will appear in the order they are found in the article. |
\ No newline at end of file |
Property changes on: trunk/extensions/ArticleEmblems/README |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 12 | + native |
Index: trunk/extensions/ArticleEmblems/ArticleEmblems.php |
— | — | @@ -0,0 +1,34 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * ArticleEmblems extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * |
| 9 | + * @author Trevor Parscal <trevor@wikimedia.org> |
| 10 | + * @license GPL v2 or later |
| 11 | + * @version 0.1.0 |
| 12 | + */ |
| 13 | + |
| 14 | +/* Setup */ |
| 15 | + |
| 16 | +$wgExtensionCredits['parserhook'][] = array( |
| 17 | + 'path' => __FILE__, |
| 18 | + 'name' => 'ArticleEmblems', |
| 19 | + 'author' => array( 'Trevor Parscal' ), |
| 20 | + 'version' => '0.1.0', |
| 21 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:ArticleEmblems', |
| 22 | + 'descriptionmsg' => 'articleEmblems-desc', |
| 23 | +); |
| 24 | +$wgAutoloadClasses['ArticleEmblemsHooks'] = dirname( __FILE__ ) . '/ArticleEmblems.hooks.php'; |
| 25 | +$wgExtensionMessagesFiles['ArticleEmblems'] = dirname( __FILE__ ) . '/ArticleEmblems.i18n.php'; |
| 26 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'ArticleEmblemsHooks::loadExtensionSchemaUpdates'; |
| 27 | +$wgHooks['ParserFirstCallInit'][] = 'ArticleEmblemsHooks::parserInit'; |
| 28 | +$wgHooks['ParserTestTables'][] = 'ArticleEmblemsHooks::parserTestTables'; |
| 29 | +$wgHooks['ArticleViewHeader'][] = 'ArticleEmblemsHooks::articleViewHeader'; |
| 30 | +$wgHooks['ArticleSaveComplete'][] = 'ArticleEmblemsHooks::articleSaveComplete'; |
| 31 | +$wgResourceModules['ext.articleEmblems'] = array( |
| 32 | + 'styles' => 'ext.articleEmblems.css', |
| 33 | + 'localBasePath' => dirname( __FILE__ ) . '/modules', |
| 34 | + 'remoteExtPath' => 'ArticleEmblems/modules', |
| 35 | +); |
Property changes on: trunk/extensions/ArticleEmblems/ArticleEmblems.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 36 | + native |