MediaWiki Aktualisierte Extension Contribution Credits

Aus Laub-Home.de Wiki
Zur Navigation springen Zur Suche springen

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

  1 <?php
  2 
  3 /*
  4  * Configuration:
  5  *  LocalSettings.php => $wgContributionCreditsShowUserSignature = true;
  6  *                          Default: true
  7  *                          true:   shows user specific user signature (if configured and not empty; else just the username)
  8  *                          false:  shows only the username instead of the user signature
  9  */                                                                
 10 
 11 class ContributionCredits {
 12 	/**
 13 	 * @param string &$data
 14 	 * @param Skin $skin
 15 	 */
 16 	public static function onSkinAfterContent( &$data, Skin $skin ) {
 17 		global $wgContentNamespaces,
 18 			$wgContributionCreditsHeader,
 19 			$wgContributionCreditsUseRealNames,
 20 			
 21 			// ---- CHANGES
 22 			$wgContributionCreditsExcludedCategories,
 23 			$wgContributionCreditsShowUserSignature;    // NEW
 24 			// ---------------
 25 			
 26 		$title = $skin->getTitle();
 27 		$namespace = $title->getNamespace();
 28 		$request = $skin->getRequest();
 29 		$action = $request->getVal( 'action', 'view' );
 30 		if ( in_array( $namespace, $wgContentNamespaces ) && $action === 'view' ) {
 31 			// If the page is in the list of excluded categories, don't show the credits
 32 			$categories = $title->getParentCategories();
 33 			foreach ( $categories as $key => $value ) {
 34 				$category = str_ireplace( '_', ' ', $key );
 35 				if ( in_array( $category, $wgContributionCreditsExcludedCategories ) ) {
 36 					return;
 37 				}
 38 			}
 39 			$database = wfGetDB( DB_REPLICA );
 40 			$articleID = $title->getArticleID();
 41 			$links = [];
 42 			
 43 			/* // --------------- original
 44 			 * $result = $database->select(
 45 			 * [ 'revision', 'user' ],
 46 			 * [ 'distinct user.user_id', 'user.user_name', 'user.user_real_name' ],
 47 			 * [ 'user.user_id = revision.rev_user', "rev_page = $articleID", 'rev_user > 0', 'rev_deleted = 0' ],
 48 			 * __METHOD__,
 49 			 * [ 'ORDER BY' => 'user.user_name ASC' ]
 50 			 * );
 51 			 */ // ---------------
 52 			 
 53 			// NEW 
 54 			// perhaps sql a little too generic; check simplification
 55             $result = $database->select(
 56                 [ 'revision', 'user', 'user_properties', 'revision_actor_temp' ],
 57                 [ 'DISTINCT user.user_name', 'user.user_real_name', 'user_properties.up_value AS signature' ],
 58                 [ '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' ],
 59                 __METHOD__,
 60                 [ 'ORDER BY' => 'user.user_name ASC' ]
 61             );
 62 
 63             /* // --------------- original
 64              *  foreach ( $result as $row ) {
 65              *      if ( $wgContributionCreditsUseRealNames && $row->user_real_name ) {
 66              *          $link = Linker::userLink( $row->user_id, $row->user_name, $row->user_real_name );
 67              *      } else {
 68              *          $link = Linker::userLink( $row->user_id, $row->user_name );
 69              *      }
 70              *      $links[] = $link;
 71              *  }
 72              */ // ---------------
 73 
 74             // NEW
 75             foreach ( $result as $row ) {
 76                 if ( $wgContributionCreditsUseRealNames && $row->user_real_name ) {
 77                     $link = Linker::userLink( $row->user_id, $row->user_name, $row->user_real_name );
 78                 } elseif ( $wgContributionCreditsShowUserSignature && $row->signature ) {
 79                     $parser = new Parser;
 80                     $parserOptions = new ParserOptions;
 81                     $parserOutput = $parser->parse( $row->signature, $skin->getTitle(), $parserOptions );
 82                     $link = $parserOutput->getText();
 83                 } else {
 84                     $link = Linker::userLink( $row->user_id, $row->user_name );
 85                 }
 86                 $links[] = $link;
 87             }
 88 			
 89 			$header = wfMessage( 'contributioncredits-header' );
 90 			if ( $wgContributionCreditsHeader ) {
 91 				$data .= "<h2>$header</h2>";
 92 				$data .= "<ul>";
 93 				foreach ( $links as $link ) {
 94 					$data .= "<li>$link</li>";
 95 				}
 96 				$data .= "</ul>";
 97 			} else {
 98 				$links = implode( ', ', $links );
 99 				$data .= "<p>$header: $links</p>";
100 			}
101 		}
102 	}
103 }
104 ?>

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

 1 <?php
 2         /**
 3         * Contribution Credits extension - Adds contribution credits to the footer
 4         * @version 2.3 - 2012/05/09
 5         *
 6         * @link http://www.mediawiki.org/wiki/Extension:Contribution_Credits Documentation
 7         *
 8         * @file ContributionCredits.php
 9         * @ingroup Extensions
10         * @package MediaWiki
11         * @author Jaime Prilusky
12         * @author Al Maghi
13         * @author Manuel Wendel
14         * @copyright © 2008 Jaime Prilusky
15         * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
16         *
17         * Configuration:
18         *       LocalSettings.php => $wgContributionCreditsShowUserSignature = true;
19         *                                                       Default: true
20         *                                                       true:   shows user specific user signature (if configured and not empty; else just the username)
21                                                                 false:  shows only the username instead of the user signature
22         */
23 
24         if( !defined( 'MEDIAWIKI' ) ) {
25                 echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
26                 die( 1 );
27         }
28 
29         define ('CONTRIBUTIONCREDITS_VERSION','2.3, 2012-05-09');
30 
31         $wgHooks['OutputPageBeforeHTML'][] = 'addFooter';
32 
33         $wgExtensionCredits['other'][] = array(
34                 'name' => 'Contribution Credits',
35                 'version' => CONTRIBUTIONCREDITS_VERSION,
36                 'author' => array( 'Jaime Prilusky', 'Al Maghi' ),
37                 'description' => 'Adds contribution credits to the footer',
38                 'url' => 'https://www.mediawiki.org/wiki/Extension:Contribution_Credits'
39         );
40 
41         function addFooter (&$articleTitle, &$text) {
42                 global $wgTitle,$wgOut,$wgRequest;
43                 global $wgContributionCreditsHeader;
44 //      -- DIFFERENCE
45                 global $wgContributionCreditsShowUserSignature;
46                 if (is_null($wgContributionCreditsShowUserSignature)) {$wgContributionCreditsShowUserSignature = true;}
47 //      -------------
48 
49                 $NS = $wgTitle->getNamespace();
50                 $action = $wgRequest->getVal('action');
51 
52                 if (($NS==0 or $NS==1) and ($action != 'edit')) {
53                         $dbr =& wfGetDB( DB_SLAVE );
54                         $page_id = $wgTitle->getArticleID(); $list= '';
55 
56                         $res = $dbr->select(
57 //      -- DIFFERENCE
58                         //      'revision',
59                         //      array('distinct rev_user_text'),
60                         //      array("rev_page = $page_id","rev_user >= 1"),
61                         //      __METHOD__,
62                         //      array('ORDER BY' => 'rev_user_text ASC',));
63                         array('revision', 'user', 'user_properties'),
64                         array('distinct user.user_id', 'user.user_real_name', 'user.user_name', 'revision.rev_user_text', 'user_properties.up_value AS signature'),
65                         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"),
66                         __METHOD__,
67                         array('ORDER BY' => 'user.user_name ASC',));
68 //      -------------
69                                 if( $res && $dbr->numRows( $res ) > 0 ) {
70                                         while( $row = $dbr->fetchObject( $res ) ) {
71                                                 $deletedUser = preg_match("/ZDelete/",$row->rev_user_text); # deleted users are renamed as ZDelete####
72                                                 if (!$deletedUser) {
73 //      -- DIFFERENCE
74                                                 //      $list .= "[[User:".$row->rev_user_text."|".$row->rev_user_text."]], ";
75                                                         if($row->signature != "" && $wgContributionCreditsShowUserSignature == true ) {
76                                                                 $list .= "<p>&raquo; " . $row->signature . "</p>";
77                                                         } else {
78                                                                 $list .= "<p>&raquo; [[User:" .  $row->user_name . "|" . $row->user_name . "]]</p>";
79                                                         }
80 //      -------------
81                                                 }
82                                         }
83                                 }
84                         $dbr->freeResult( $res );
85 //      -- DIFFERENCE
86                 //      $list = preg_replace('/\,\s*$/','',$list);
87 //      -------------
88                         $contributorsBlock = '';
89                         if (!empty($list)) {
90                                 if (!$wgContributionCreditsHeader) {$wgContributionCreditsHeader = "==Contributors==\n";}
91                                 $contributorsBlock = $wgOut->parse("__NOEDITSECTION__\n" . $wgContributionCreditsHeader . $list);
92                         }
93                         $text = $text."\n<div id=\"ContributionCredits\">$contributorsBlock</div>";
94                 }
95                 return true;
96         }
97 ?>

Download