r102143 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102142‎ | r102143 | r102144 >
Date:02:27, 6 November 2011
Author:danwe
Status:deferred
Tags:
Comment:
Version 0.4 of my extension 'SemanticUpdateOnPurge' moved from mediawiki.org
Modified paths:
  • /trunk/extensions/SemanticUpdateOnPurge (added) (history)
  • /trunk/extensions/SemanticUpdateOnPurge/COPYING (added) (history)
  • /trunk/extensions/SemanticUpdateOnPurge/README (added) (history)
  • /trunk/extensions/SemanticUpdateOnPurge/RELEASE-NOTES (added) (history)
  • /trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.i18n.php (added) (history)
  • /trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.php (added) (history)

Diff [purge]

Index: trunk/extensions/SemanticUpdateOnPurge/RELEASE-NOTES
@@ -0,0 +1,15 @@
 2+ Changelog:
 3+ ==========
 4+
 5+ * November 6, 2011 -- Version 0.4
 6+ - Language file for extension description added.
 7+ - Extension added into wikimedia.org svn repository and put under ISC License.
 8+
 9+ * September 28, 2011 -- Version 0.3.1.1: Minor update letting the extension appear as semantic extension on [[Special:Version]].
 10+ * September 23, 2011 -- Version 0.3.1: PHP notice will not appear anymore when purging pages without semantic data.
 11+ * September 20, 2011 -- Version 0.3: Internal extension structure redesigned, works with SMW 1.6.1 (probably 1.6 as well).
 12+
 13+ * February 14, 2011 -- Version 0.2.1: Minor code changes, added 'VERSION' constant into 'ExtSemanticUpdateOnPurge' class.
 14+ * March 10, 2010 -- Version 0.2: Redesign of how the update happens. Doesn't use an update job any longer.
 15+
 16+ * March 9, 2010 -- Version 0.1: First experimental release of 'SemanticUpdateOnPurge'.
Index: trunk/extensions/SemanticUpdateOnPurge/COPYING
@@ -0,0 +1,13 @@
 2+Copyright (c) 2010 - 2011 by Daniel Werner < danweetz@web.de >
 3+
 4+Permission to use, copy, modify, and/or distribute this software for any
 5+purpose with or without fee is hereby granted, provided that the above
 6+copyright notice and this permission notice appear in all copies.
 7+
 8+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 9+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 10+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 11+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 12+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 13+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 14+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
\ No newline at end of file
Index: trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.i18n.php
@@ -0,0 +1,28 @@
 2+<?php
 3+#coding: utf-8
 4+
 5+/**
 6+ * Internationalisation file of the 'SemanticUpdateOnPurge' extension
 7+ *
 8+ * @since 0.4
 9+ *
 10+ * @file SemanticUpdateOnPurge.i18n.php
 11+ * @ingroup SemanticUpdateOnPurge
 12+ * @author Daniel Werner < danweetz@web.de >
 13+ */
 14+
 15+$messages = array();
 16+
 17+/** English
 18+ * @author Daniel Werner
 19+ */
 20+$messages['en'] = array(
 21+ 'suop-desc' => 'Updates semantic attributes of a wiki page when purging the page.',
 22+);
 23+
 24+/** German (Deutsch)
 25+ * @author Daniel Werner
 26+ */
 27+$messages['de'] = array(
 28+ 'suop-desc' => 'Aktualisiert semantische Attribute wenn der Seitencache durch „purge“ geleert wird.',
 29+);
Property changes on: trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.i18n.php
___________________________________________________________________
Added: svn:eol-style
130 + native
Index: trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.php
@@ -0,0 +1,125 @@
 2+<?php
 3+
 4+/**
 5+ * Updates Semantic MediaWikis properties of an article when the article is purged.
 6+ * SMW standard behavior is to update properties only on page save (as of SMW 1.6)
 7+ *
 8+ * Documentation: http://www.mediawiki.org/wiki/Extension:SemanticUpdateOnPurge
 9+ * Support: http://www.mediawiki.org/wiki/Extension_talk:SemanticUpdateOnPurge
 10+ * Source code: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SemanticUpdateOnPurge
 11+ *
 12+ * @version: 0.4
 13+ * @license: ISC license
 14+ * @author: Daniel Werner < danweetz@web.de >
 15+ *
 16+ * @file SemanticUpdateOnPurge.php
 17+ * @ingroup SemanticUpdateOnPurge
 18+ */
 19+
 20+if ( !defined( 'MEDIAWIKI' ) ) { die(); }
 21+
 22+# Credits
 23+$wgExtensionCredits[ defined( 'SEMANTIC_EXTENSION_TYPE' ) ? 'semantic' : 'other' ][] = array(
 24+ 'path' => __FILE__,
 25+ 'name' => 'SemanticUpdateOnPurge',
 26+ 'descriptionmsg' => 'suop-desc',
 27+ 'version' => ExtSemanticUpdateOnPurge::VERSION,
 28+ 'author' => '[http://www.mediawiki.org/wiki/User:Danwe Daniel Werner]',
 29+ 'url' => 'http://www.mediawiki.org/wiki/Extension:SemanticUpdateOnPurge',
 30+);
 31+
 32+// language file:
 33+$wgExtensionMessagesFiles['SemanticUpdateOnPurge'] = ExtSemanticUpdateOnPurge::getDir() . '/SemanticUpdateOnPurge.i18n.php';
 34+
 35+// hooks registration:
 36+$wgHooks[ 'ArticlePurge' ][] = 'ExtSemanticUpdateOnPurge::onArticlePurge';
 37+$wgHooks[ 'ParserAfterTidy' ][] = 'ExtSemanticUpdateOnPurge::onParserAfterTidy';
 38+
 39+
 40+/**
 41+ * Extension class with all the extension functionality
 42+ */
 43+class ExtSemanticUpdateOnPurge {
 44+
 45+ /**
 46+ * Version of the RegexFun extension.
 47+ *
 48+ * @since 0.2.1
 49+ *
 50+ * @var string
 51+ */
 52+ const VERSION = '0.4';
 53+
 54+ /**
 55+ * contains Title::getPrefixedDBkey() values as keys, and 'true' as value
 56+ * if the titles semantics should be updated. Usually only one title, just make sure
 57+ * this will also work if there are some weird internal purge processing is going on
 58+ * or several parser processes running recursivelly
 59+ *
 60+ * @since 0.3
 61+ *
 62+ * @var Array
 63+ */
 64+ private static $mUpdateTitles = array();
 65+
 66+ /**
 67+ * Returns the extensions base installation directory.
 68+ *
 69+ * @since 0.4
 70+ *
 71+ * @return string
 72+ */
 73+ public static function getDir() {
 74+ static $dir = null;
 75+
 76+ if( $dir === null ) {
 77+ $dir = dirname( __FILE__ );
 78+ }
 79+ return $dir;
 80+ }
 81+
 82+ public static function onArticlePurge( &$article ) {
 83+ self::addUpdateTitle( $article->getTitle() );
 84+ return true;
 85+ }
 86+
 87+ /* Note: SMW uses the hook "LinksUpdateConstructed" for this which apparently won't get
 88+ * called when purging the article. So we have to stick with this one here.
 89+ */
 90+ public static function onParserAfterTidy( &$parser, &$text ) {
 91+ $title = $parser->getTitle();
 92+ // make sure this isn't some title we didn't wanted to purge in the first place:
 93+ if( self::hasUpdateTitle( $title ) ) {
 94+ /*
 95+ * Note: don't use SMWUpdateJob here because it would parse the whole article again and
 96+ * could cause some problems with very dynamic extensions like Extension:Variables.
 97+ */
 98+ $output = $parser->getOutput();
 99+
 100+ // only update if the page contains semantic data:
 101+ if( isset( $output->mSMWData ) ) {
 102+ SMWParseData::storeData( $output, $title, true );
 103+ }
 104+ self::removeUpdateTitle( $title );
 105+ }
 106+ return true;
 107+ }
 108+
 109+ private static function addUpdateTitle( Title $title ) {
 110+ self::$mUpdateTitles[ $title->getPrefixedDBkey() ] = true;
 111+ }
 112+
 113+ private static function removeUpdateTitle( Title $title ) {
 114+ if( self::hasUpdateTitle( $title ) ) {
 115+ unset( self::$mUpdateTitles[ $title->getPrefixedDBkey() ] );
 116+ return true;
 117+ }
 118+ return false;
 119+ }
 120+
 121+ private static function hasUpdateTitle( Title $title ) {
 122+ $key = $title->getPrefixedDBkey();
 123+ return ( isset( self::$mUpdateTitles[ $key ] ) && self::$mUpdateTitles[ $key ] === true );
 124+ }
 125+
 126+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.php
___________________________________________________________________
Added: svn:eol-style
1127 + native
Index: trunk/extensions/SemanticUpdateOnPurge/README
@@ -0,0 +1,28 @@
 2+== About ==
 3+
 4+''SemanticUpdateOnPurge'' is a MediaWiki extension by Daniel Werner which updates Semantic MediaWikis properties
 5+of an article whenever the article is purged.
 6+SMW standard behavior is to update properties only on page save (as of SMW 1.6)
 7+
 8+
 9+== Installation ==
 10+
 11+Once you have downloaded the code, place the 'SemanticUpdateOnPurge' directory within your MediaWiki 'extensions'
 12+directory. Then add the following code to your [[Manual:LocalSettings.php|LocalSettings.php]] file:
 13+
 14+ # SemanticUpdateOnPurge
 15+ require_once( "$IP/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.php" );
 16+
 17+
 18+== Compatibility ==
 19+
 20+Version 0.2.1 to 0.4 are tested on SMW 1.6.1 and 1.6.2 (propably working with 1.6 too) There have been some issues
 21+with some versions of the SMW 1.5.x branch, where in early versions the extension seemed to work, then it didn't.
 22+
 23+
 24+== Contributing ==
 25+
 26+If you have bug reports or requests, please add them to the ''SemanticUpdateOnPurge'' Talk page [0].
 27+You can also send them to Daniel Werner < danweetz@web.de >
 28+
 29+[0] http://www.mediawiki.org/w/index.php?title=Extension_talk:SemanticUpdateOnPurge
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r102189r102143: Consistency tweaks in preparation for adding extension to translatew...raymond20:03, 6 November 2011
r102190r102143: Adding extension to translatewiki.netraymond20:05, 6 November 2011