https://www.mediawiki.org/wiki/Special:Code/MediaWiki/102143

Revision: 102143
Author:   danwe
Date:     2011-11-06 02:27:13 +0000 (Sun, 06 Nov 2011)
Log Message:
-----------
Version 0.4 of my extension 'SemanticUpdateOnPurge' moved from mediawiki.org

Added Paths:
-----------
    trunk/extensions/SemanticUpdateOnPurge/
    trunk/extensions/SemanticUpdateOnPurge/COPYING
    trunk/extensions/SemanticUpdateOnPurge/README
    trunk/extensions/SemanticUpdateOnPurge/RELEASE-NOTES
    trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.i18n.php
    trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.php

Added: trunk/extensions/SemanticUpdateOnPurge/COPYING
===================================================================
--- trunk/extensions/SemanticUpdateOnPurge/COPYING                              
(rev 0)
+++ trunk/extensions/SemanticUpdateOnPurge/COPYING      2011-11-06 02:27:13 UTC 
(rev 102143)
@@ -0,0 +1,13 @@
+Copyright (c) 2010 - 2011 by Daniel Werner < [email protected] >
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
\ No newline at end of file

Added: trunk/extensions/SemanticUpdateOnPurge/README
===================================================================
--- trunk/extensions/SemanticUpdateOnPurge/README                               
(rev 0)
+++ trunk/extensions/SemanticUpdateOnPurge/README       2011-11-06 02:27:13 UTC 
(rev 102143)
@@ -0,0 +1,28 @@
+== About ==
+
+''SemanticUpdateOnPurge'' is a MediaWiki extension by Daniel Werner which 
updates Semantic MediaWikis properties
+of an article whenever the article is purged.
+SMW standard behavior is to update properties only on page save (as of SMW 1.6)
+
+
+== Installation ==
+
+Once you have downloaded the code, place the 'SemanticUpdateOnPurge' directory 
within your MediaWiki 'extensions'
+directory. Then add the following code to your 
[[Manual:LocalSettings.php|LocalSettings.php]] file:
+
+ # SemanticUpdateOnPurge
+ require_once( 
"$IP/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.php" );
+
+
+== Compatibility ==
+
+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
+with some versions of the SMW 1.5.x branch, where in early versions the 
extension seemed to work, then it didn't.
+
+
+== Contributing ==
+
+If you have bug reports or requests, please add them to the 
''SemanticUpdateOnPurge'' Talk page [0].
+You can also send them to Daniel Werner < [email protected] >
+
+[0] 
http://www.mediawiki.org/w/index.php?title=Extension_talk:SemanticUpdateOnPurge
\ No newline at end of file

Added: trunk/extensions/SemanticUpdateOnPurge/RELEASE-NOTES
===================================================================
--- trunk/extensions/SemanticUpdateOnPurge/RELEASE-NOTES                        
        (rev 0)
+++ trunk/extensions/SemanticUpdateOnPurge/RELEASE-NOTES        2011-11-06 
02:27:13 UTC (rev 102143)
@@ -0,0 +1,15 @@
+ Changelog:
+ ==========
+
+ * November 6, 2011 -- Version 0.4
+   - Language file for extension description added.
+   - Extension added into wikimedia.org svn repository and put under ISC 
License.
+   
+ * September 28, 2011 -- Version 0.3.1.1: Minor update letting the extension 
appear as semantic extension on [[Special:Version]].
+ * September 23, 2011 -- Version 0.3.1:   PHP notice will not appear anymore 
when purging pages without semantic data.
+ * September 20, 2011 -- Version 0.3:     Internal extension structure 
redesigned, works with SMW 1.6.1 (probably 1.6 as well).
+ 
+ * February 14, 2011 -- Version 0.2.1: Minor code changes, added 'VERSION' 
constant into 'ExtSemanticUpdateOnPurge' class.
+ * March 10, 2010    -- Version 0.2:   Redesign of how the update happens. 
Doesn't use an update job any longer.
+ 
+ * March 9, 2010 -- Version 0.1: First experimental release of 
'SemanticUpdateOnPurge'.

Added: trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.i18n.php
===================================================================
--- trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.i18n.php       
                        (rev 0)
+++ trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.i18n.php       
2011-11-06 02:27:13 UTC (rev 102143)
@@ -0,0 +1,28 @@
+<?php
+#coding: utf-8
+
+/**
+ * Internationalisation file of the 'SemanticUpdateOnPurge' extension
+ *
+ * @since 0.4
+ * 
+ * @file SemanticUpdateOnPurge.i18n.php
+ * @ingroup SemanticUpdateOnPurge
+ * @author Daniel Werner < [email protected] >
+ */
+
+$messages = array();
+
+/** English
+ * @author Daniel Werner
+ */
+$messages['en'] = array(
+       'suop-desc' => 'Updates semantic attributes of a wiki page when purging 
the page.',
+);
+
+/** German (Deutsch)
+ * @author Daniel Werner
+ */
+$messages['de'] = array(
+       'suop-desc' => 'Aktualisiert semantische Attribute wenn der Seitencache 
durch „purge“ geleert wird.',
+);


Property changes on: 
trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.i18n.php
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.php
===================================================================
--- trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.php            
                (rev 0)
+++ trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.php    
2011-11-06 02:27:13 UTC (rev 102143)
@@ -0,0 +1,125 @@
+<?php
+ 
+/**
+ * Updates Semantic MediaWikis properties of an article when the article is 
purged.
+ * SMW standard behavior is to update properties only on page save (as of SMW 
1.6)
+ * 
+ * Documentation: http://www.mediawiki.org/wiki/Extension:SemanticUpdateOnPurge
+ * Support:       
http://www.mediawiki.org/wiki/Extension_talk:SemanticUpdateOnPurge
+ * Source code:   
http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SemanticUpdateOnPurge
+ *
+ * @version: 0.4
+ * @license: ISC license
+ * @author:  Daniel Werner < [email protected] >
+ * 
+ * @file SemanticUpdateOnPurge.php
+ * @ingroup SemanticUpdateOnPurge
+ */
+ 
+if ( !defined( 'MEDIAWIKI' ) ) { die(); }
+ 
+# Credits
+$wgExtensionCredits[ defined( 'SEMANTIC_EXTENSION_TYPE' ) ? 'semantic' : 
'other' ][] = array(
+       'path'           => __FILE__,
+       'name'           => 'SemanticUpdateOnPurge',
+       'descriptionmsg' => 'suop-desc',
+       'version'        => ExtSemanticUpdateOnPurge::VERSION,
+       'author'         => '[http://www.mediawiki.org/wiki/User:Danwe Daniel 
Werner]',
+       'url'            => 
'http://www.mediawiki.org/wiki/Extension:SemanticUpdateOnPurge',
+);
+
+// language file:
+$wgExtensionMessagesFiles['SemanticUpdateOnPurge'] = 
ExtSemanticUpdateOnPurge::getDir() . '/SemanticUpdateOnPurge.i18n.php';
+ 
+// hooks registration:
+$wgHooks[ 'ArticlePurge'    ][] = 'ExtSemanticUpdateOnPurge::onArticlePurge';
+$wgHooks[ 'ParserAfterTidy' ][] = 
'ExtSemanticUpdateOnPurge::onParserAfterTidy';
+
+
+/**
+ * Extension class with all the extension functionality
+ */
+class ExtSemanticUpdateOnPurge {
+       
+       /**
+        * Version of the RegexFun extension.
+        * 
+        * @since 0.2.1
+        * 
+        * @var string
+        */
+       const VERSION = '0.4';
+       
+       /**
+        * contains Title::getPrefixedDBkey() values as keys, and 'true' as 
value
+        * if the titles semantics should be updated. Usually only one title, 
just make sure
+        * this will also work if there are some weird internal purge 
processing is going on
+        * or several parser processes running recursivelly
+        * 
+        * @since 0.3
+        * 
+        * @var Array
+        */
+       private static $mUpdateTitles = array();
+       
+       /**
+        * Returns the extensions base installation directory.
+        *
+        * @since 0.4
+        * 
+        * @return string
+        */
+       public static function getDir() {               
+               static $dir = null;
+               
+               if( $dir === null ) {
+                       $dir = dirname( __FILE__ );
+               }
+               return $dir;
+       }
+
+       public static function onArticlePurge( &$article ) {
+               self::addUpdateTitle( $article->getTitle() );
+               return true;
+       }
+
+       /* Note: SMW uses the hook "LinksUpdateConstructed" for this which 
apparently won't get
+        * called when purging the article. So we have to stick with this one 
here.
+        */
+       public static function onParserAfterTidy( &$parser, &$text ) {
+               $title = $parser->getTitle();
+               // make sure this isn't some title we didn't wanted to purge in 
the first place:              
+               if( self::hasUpdateTitle( $title ) ) {
+                       /* 
+                        * Note: don't use SMWUpdateJob here because it would 
parse the whole article again and 
+                        * could cause some problems with very dynamic 
extensions like Extension:Variables.
+                        */
+                       $output = $parser->getOutput();
+                       
+                       // only update if the page contains semantic data:
+                       if( isset( $output->mSMWData ) ) {
+                               SMWParseData::storeData( $output, $title, true 
);
+                       }
+                       self::removeUpdateTitle( $title );
+               }
+               return true;
+       }
+       
+       private static function addUpdateTitle( Title $title ) {
+               self::$mUpdateTitles[ $title->getPrefixedDBkey() ] = true;
+       }
+       
+       private static function removeUpdateTitle( Title $title ) {
+               if( self::hasUpdateTitle( $title ) ) {
+                       unset( self::$mUpdateTitles[ $title->getPrefixedDBkey() 
] );
+                       return true;
+               }
+               return false;
+       }
+       
+       private static function hasUpdateTitle( Title $title ) {
+               $key = $title->getPrefixedDBkey();
+               return ( isset( self::$mUpdateTitles[ $key ] ) && 
self::$mUpdateTitles[ $key ] === true );
+       }
+       
+}
\ No newline at end of file


Property changes on: 
trunk/extensions/SemanticUpdateOnPurge/SemanticUpdateOnPurge.php
___________________________________________________________________
Added: svn:eol-style
   + native


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to