MediaWiki Aktualisierte Extension Contribution Credits

Aus Laub-Home Wiki

Da wir hier für das Wiki nicht die Usernamen sondern unsere Signaturen als Contribution Credits haben wollten, haben wir die Extension dahingehend erweitert. Man hat dennoch die Möglichkeit mittels Parameter in der LocalSettings.php den normalen Username zu aktivieren.

Original Extension ist hier zu finden:

Installation und Konfiguration

mkdir extensions/ContributionCredits

dann das unten stehende PHP Skript in die Datei extensions/ContributionCredits/ContributionCredits.php einfügen. LocalSettings.php

# Enables ContributionCredits
require_once( "$IP/extensions/ContributionCredits/ContributionCredits.php" );
$wgContributionCreditsShowUserSignature = true;
# original configurations
$wgContributionCreditsUseRealNames = true;
$wgContributionCreditsHeader = true;

Extension Skript v3.1

https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/ContributionCredits/+/master/ContributionCredits.php

extensions/ContributionCredits/ContributionCredits.php

Source

<?php

/*
 * Configuration:
 *  LocalSettings.php => $wgContributionCreditsShowUserSignature = true;
 *                          Default: true
 *                          true:   shows user specific user signature (if configured and not empty; else just the username)
 *                          false:  shows only the username instead of the user signature
 */                                                                

class ContributionCredits {
	/**
	 * @param string &$data
	 * @param Skin $skin
	 */
	public static function onSkinAfterContent( &$data, Skin $skin ) {
		global $wgContentNamespaces,
			$wgContributionCreditsHeader,
			$wgContributionCreditsUseRealNames,
			
			// ---- CHANGES
			$wgContributionCreditsExcludedCategories,
			$wgContributionCreditsShowUserSignature;    // NEW
			// ---------------
			
		$title = $skin->getTitle();
		$namespace = $title->getNamespace();
		$request = $skin->getRequest();
		$action = $request->getVal( 'action', 'view' );
		if ( in_array( $namespace, $wgContentNamespaces ) && $action === 'view' ) {
			// If the page is in the list of excluded categories, don't show the credits
			$categories = $title->getParentCategories();
			foreach ( $categories as $key => $value ) {
				$category = str_ireplace( '_', ' ', $key );
				if ( in_array( $category, $wgContributionCreditsExcludedCategories ) ) {
					return;
				}
			}
			$database = wfGetDB( DB_REPLICA );
			$articleID = $title->getArticleID();
			$links = [];
			
			/* // --------------- original
			 * $result = $database->select(
			 * [ 'revision', 'user' ],
			 * [ 'distinct user.user_id', 'user.user_name', 'user.user_real_name' ],
			 * [ 'user.user_id = revision.rev_user', "rev_page = $articleID", 'rev_user > 0', 'rev_deleted = 0' ],
			 * __METHOD__,
			 * [ 'ORDER BY' => 'user.user_name ASC' ]
			 * );
			 */ // ---------------
			 
			// NEW 
			// perhaps sql a little too generic; check simplification
            $result = $database->select(
                [ 'revision', 'user', 'user_properties', 'revision_actor_temp' ],
                [ 'DISTINCT user.user_name', 'user.user_real_name', 'user_properties.up_value AS signature' ],
                [ 'revision.rev_page = ' . $articleID . ' AND revision.rev_user = user.user_id AND user_properties.up_user = revision.rev_user AND user_properties.up_property = "nickname") OR (revision.rev_page = ' . $articleID . ' AND revision_actor_temp.revactor_actor = user.user_id AND revision_actor_temp.revactor_page = ' . $articleID . ' AND user_properties.up_property = "nickname" AND user_properties.up_user = user.user_id' ],
                __METHOD__,
                [ 'ORDER BY' => 'user.user_name ASC' ]
            );

            /* // --------------- original
             *  foreach ( $result as $row ) {
             *      if ( $wgContributionCreditsUseRealNames && $row->user_real_name ) {
             *          $link = Linker::userLink( $row->user_id, $row->user_name, $row->user_real_name );
             *      } else {
             *          $link = Linker::userLink( $row->user_id, $row->user_name );
             *      }
             *      $links[] = $link;
             *  }
             */ // ---------------

            // NEW
            foreach ( $result as $row ) {
                if ( $wgContributionCreditsUseRealNames && $row->user_real_name ) {
                    $link = Linker::userLink( $row->user_id, $row->user_name, $row->user_real_name );
                } elseif ( $wgContributionCreditsShowUserSignature && $row->signature ) {
                    $parser = new Parser;
                    $parserOptions = new ParserOptions;
                    $parserOutput = $parser->parse( $row->signature, $skin->getTitle(), $parserOptions );
                    $link = $parserOutput->getText();
                } else {
                    $link = Linker::userLink( $row->user_id, $row->user_name );
                }
                $links[] = $link;
            }
			
			$header = wfMessage( 'contributioncredits-header' );
			if ( $wgContributionCreditsHeader ) {
				$data .= "<h2>$header</h2>";
				$data .= "<ul>";
				foreach ( $links as $link ) {
					$data .= "<li>$link</li>";
				}
				$data .= "</ul>";
			} else {
				$links = implode( ', ', $links );
				$data .= "<p>$header: $links</p>";
			}
		}
	}
}
?>

Patch

Eine Anleitung zum Einspielen des Patches findet ihr hier:

Datei kann hier heruntergeladen werden:

ContributionCredits.patch

--- ContributionCredits.php.orig        2020-03-10 09:23:07.074100781 +0100
+++ ContributionCredits.php     2020-03-10 14:08:04.285585177 +0100
@@ -1,61 +1,214 @@
 <?php

+
+/*
+
+ * Configuration:
+
+ *  LocalSettings.php => $wgContributionCreditsShowUserSignature = true;
+
+ *                          Default: true
+
+ *                          true:   shows user specific user signature (if configured and not empty; else just the username)
+
+ *                          false:  shows only the username instead of the user signature
+
+ */
+
+
 class ContributionCredits {

+       /**
+
+        * @param string &$data
+
+        * @param Skin $skin
+
+        */
+
        public static function onSkinAfterContent( &$data, Skin $skin ) {
+
                global $wgContentNamespaces,
+
                        $wgContributionCreditsHeader,
+
                        $wgContributionCreditsUseRealNames,
-                       $wgContributionCreditsExcludedCategories;
+
+
+
+                       // ---- CHANGES
+
+                       $wgContributionCreditsExcludedCategories,
+
+                       $wgContributionCreditsShowUserSignature;    // NEW
+
+                       // ---------------
+
+

                $title = $skin->getTitle();
+
                $namespace = $title->getNamespace();
+
                $request = $skin->getRequest();
+
                $action = $request->getVal( 'action', 'view' );
-               if ( in_array( $namespace, $wgContentNamespaces ) and $action === 'view' ) {
+
+               if ( in_array( $namespace, $wgContentNamespaces ) && $action === 'view' ) {

                        // If the page is in the list of excluded categories, don't show the credits
+
                        $categories = $title->getParentCategories();
+
                        foreach ( $categories as $key => $value ) {
+
                                $category = str_ireplace( '_', ' ', $key );
+
                                if ( in_array( $category, $wgContributionCreditsExcludedCategories ) ) {
+
                                        return;
+
                                }
+
                        }

                        $database = wfGetDB( DB_REPLICA );
+
                        $articleID = $title->getArticleID();
-                       $authors = [];

-                       $result = $database->select(
-                               [ 'revision', 'user' ],
-                               [ 'distinct user.user_id', 'user.user_name', 'user.user_real_name' ],
-                               [ 'user.user_id = revision.rev_user', "rev_page = $articleID", 'rev_user > 0', 'rev_deleted = 0' ],
-                               __METHOD__,
-                               [ 'ORDER BY' => 'user.user_name ASC' ]
-                       );
-
-                       foreach ( $result as $row ) {
-                               if ( $wgContributionCreditsUseRealNames and $row->user_real_name ) {
-                                       $link = Linker::userLink( $row->user_id, $row->user_name, $row->user_real_name );
-                               } else {
-                                       $link = Linker::userLink( $row->user_id, $row->user_name );
-                               }
-                               $links[] = $link;
-                       }
+                       $links = [];
+
+
+
+                       /* // --------------- original
+
+                        * $result = $database->select(
+
+                        * [ 'revision', 'user' ],
+
+                        * [ 'distinct user.user_id', 'user.user_name', 'user.user_real_name' ],
+
+                        * [ 'user.user_id = revision.rev_user', "rev_page = $articleID", 'rev_user > 0', 'rev_deleted = 0' ],
+
+                        * __METHOD__,
+
+                        * [ 'ORDER BY' => 'user.user_name ASC' ]
+
+                        * );
+
+                        */ // ---------------
+
+
+
+                       // NEW
+
+                       // perhaps sql a little too generic; check simplification
+/*
+            $result = $database->select(
+
+                [ 'revision', 'user', 'user_properties' ],
+
+                [ 'DISTINCT user.user_name', 'user.user_real_name', 'user_properties.up_value AS signature' ],
+
+                [ 'revision.rev_id = ' . $articleID, 'revision.rev_user = user.user_id', 'user_properties.up_user = revision.rev_user', 'user_properties.up_property = "nickname"' ],
+
+                __METHOD__,
+
+                [ 'ORDER BY' => 'user.user_name ASC' ]
+
+            );
+*/
+
+
+$result = $database->select(
+        [ 'revision', 'user', 'user_properties', 'revision_actor_temp' ],
+        [ 'DISTINCT user.user_name', 'user.user_real_name', 'user_properties.up_value AS signature' ],
+        [ 'revision.rev_page = ' . $articleID . ' AND revision.rev_user = user.user_id AND user_properties.up_user = revision.rev_user AND user_properties.up_property = "nickname") OR (revision.rev_page = ' . $articleID . ' AND revision_actor_temp.revactor_actor = user.user_id AND revision_actor_temp.revactor_page = ' . $articleID . ' AND user_properties.up_property = "nickname" AND user_properties.up_user = user.user_id' ],
+        __METHOD__,
+        [ 'ORDER BY' => 'user.user_name ASC' ]
+);
+
+
+
+            /* // --------------- original
+
+             *  foreach ( $result as $row ) {
+
+             *      if ( $wgContributionCreditsUseRealNames && $row->user_real_name ) {
+
+             *          $link = Linker::userLink( $row->user_id, $row->user_name, $row->user_real_name );
+
+             *      } else {
+
+             *          $link = Linker::userLink( $row->user_id, $row->user_name );
+
+             *      }
+
+             *      $links[] = $link;
+
+             *  }
+
+             */ // ---------------
+
+
+            // NEW
+
+            foreach ( $result as $row ) {
+
+                if ( $wgContributionCreditsUseRealNames && $row->user_real_name ) {
+
+                    $link = Linker::userLink( $row->user_id, $row->user_name, $row->user_real_name );
+
+                } elseif ( $wgContributionCreditsShowUserSignature && $row->signature ) {
+
+                    $parser = new Parser;
+
+                    $parserOptions = new ParserOptions;
+
+                    $parserOutput = $parser->parse( $row->signature, $skin->getTitle(), $parserOptions );
+
+                    $link = $parserOutput->getText();
+
+                } else {
+
+                    $link = Linker::userLink( $row->user_id, $row->user_name );
+
+                }
+
+                $links[] = $link;
+
+            }
+
+

                        $header = wfMessage( 'contributioncredits-header' );
+
                        if ( $wgContributionCreditsHeader ) {
+
                                $data .= "<h2>$header</h2>";
+
                                $data .= "<ul>";
+
                                foreach ( $links as $link ) {
+
                                        $data .= "<li>$link</li>";
+
                                }
+
                                $data .= "</ul>";
+
                        } else {
+
                                $links = implode( ', ', $links );
+
                                $data .= "<p>$header: $links</p>";
+
                        }
+
                }
+
        }
-}
\ No newline at end of file
+
+}
+
+?>

Extension Skript v2.3

Angepasste Version 2.3 der Extension Contribution Credits
extensions/ContributionCredits/ContributionCredits.php

<?php
        /**
        * Contribution Credits extension - Adds contribution credits to the footer
        * @version 2.3 - 2012/05/09
        *
        * @link http://www.mediawiki.org/wiki/Extension:Contribution_Credits Documentation
        *
        * @file ContributionCredits.php
        * @ingroup Extensions
        * @package MediaWiki
        * @author Jaime Prilusky
        * @author Al Maghi
        * @author Manuel Wendel
        * @copyright © 2008 Jaime Prilusky
        * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
        *
        * Configuration:
        *       LocalSettings.php => $wgContributionCreditsShowUserSignature = true;
        *                                                       Default: true
        *                                                       true:   shows user specific user signature (if configured and not empty; else just the username)
                                                                false:  shows only the username instead of the user signature
        */

        if( !defined( 'MEDIAWIKI' ) ) {
                echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
                die( 1 );
        }

        define ('CONTRIBUTIONCREDITS_VERSION','2.3, 2012-05-09');

        $wgHooks['OutputPageBeforeHTML'][] = 'addFooter';

        $wgExtensionCredits['other'][] = array(
                'name' => 'Contribution Credits',
                'version' => CONTRIBUTIONCREDITS_VERSION,
                'author' => array( 'Jaime Prilusky', 'Al Maghi' ),
                'description' => 'Adds contribution credits to the footer',
                'url' => 'https://www.mediawiki.org/wiki/Extension:Contribution_Credits'
        );

        function addFooter (&$articleTitle, &$text) {
                global $wgTitle,$wgOut,$wgRequest;
                global $wgContributionCreditsHeader;
//      -- DIFFERENCE
                global $wgContributionCreditsShowUserSignature;
                if (is_null($wgContributionCreditsShowUserSignature)) {$wgContributionCreditsShowUserSignature = true;}
//      -------------

                $NS = $wgTitle->getNamespace();
                $action = $wgRequest->getVal('action');

                if (($NS==0 or $NS==1) and ($action != 'edit')) {
                        $dbr =& wfGetDB( DB_SLAVE );
                        $page_id = $wgTitle->getArticleID(); $list= '';

                        $res = $dbr->select(
//      -- DIFFERENCE
                        //      'revision',
                        //      array('distinct rev_user_text'),
                        //      array("rev_page = $page_id","rev_user >= 1"),
                        //      __METHOD__,
                        //      array('ORDER BY' => 'rev_user_text ASC',));
                        array('revision', 'user', 'user_properties'),
                        array('distinct user.user_id', 'user.user_real_name', 'user.user_name', 'revision.rev_user_text', 'user_properties.up_value AS signature'),
                        array("user.user_name = revision.rev_user_text", "user_properties.up_user = user.user_id", "user_properties.up_property = 'nickname'", "rev_page = $page_id","rev_user >= 1"),
                        __METHOD__,
                        array('ORDER BY' => 'user.user_name ASC',));
//      -------------
                                if( $res && $dbr->numRows( $res ) > 0 ) {
                                        while( $row = $dbr->fetchObject( $res ) ) {
                                                $deletedUser = preg_match("/ZDelete/",$row->rev_user_text); # deleted users are renamed as ZDelete####
                                                if (!$deletedUser) {
//      -- DIFFERENCE
                                                //      $list .= "[[User:".$row->rev_user_text."|".$row->rev_user_text."]], ";
                                                        if($row->signature != "" && $wgContributionCreditsShowUserSignature == true ) {
                                                                $list .= "<p>&raquo; " . $row->signature . "</p>";
                                                        } else {
                                                                $list .= "<p>&raquo; [[User:" .  $row->user_name . "|" . $row->user_name . "]]</p>";
                                                        }
//      -------------
                                                }
                                        }
                                }
                        $dbr->freeResult( $res );
//      -- DIFFERENCE
                //      $list = preg_replace('/\,\s*$/','',$list);
//      -------------
                        $contributorsBlock = '';
                        if (!empty($list)) {
                                if (!$wgContributionCreditsHeader) {$wgContributionCreditsHeader = "==Contributors==\n";}
                                $contributorsBlock = $wgOut->parse("__NOEDITSECTION__\n" . $wgContributionCreditsHeader . $list);
                        }
                        $text = $text."\n<div id=\"ContributionCredits\">$contributorsBlock</div>";
                }
                return true;
        }
?>

Download