r87365 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87364‎ | r87365 | r87366 >
Date:23:06, 3 May 2011
Author:ashley
Status:deferred (Comments)
Tags:
Comment:
commit some ShoutWiki extensions from MediaWiki.org because ^demon has Evil Plans™ for extension pages
Modified paths:
  • /trunk/extensions/EnhanceContactForm (added) (history)
  • /trunk/extensions/EnhanceContactForm/EnhanceContactForm.php (added) (history)
  • /trunk/extensions/GlobalNotice (added) (history)
  • /trunk/extensions/GlobalNotice/GlobalNotice.php (added) (history)
  • /trunk/extensions/Quantcast (added) (history)
  • /trunk/extensions/Quantcast/Quantcast.php (added) (history)
  • /trunk/extensions/SoftwareVersion (added) (history)
  • /trunk/extensions/SoftwareVersion/SoftwareVersion.php (added) (history)
  • /trunk/extensions/WhitelistPages (added) (history)
  • /trunk/extensions/WhitelistPages/WhitelistPages.php (added) (history)

Diff [purge]

Index: trunk/extensions/SoftwareVersion/SoftwareVersion.php
@@ -0,0 +1,70 @@
 2+<?php
 3+/**
 4+ * SoftwareVersion extension - customizes Special:Version for ShoutWiki
 5+ * by changing MediaWiki's version to $wgVersion and adding ShoutWiki component
 6+ *
 7+ * @file
 8+ * @ingroup Extensions
 9+ * @version 0.4
 10+ * @author Jack Phoenix <jack@shoutwiki.com>
 11+ * @copyright Copyright © 2009-2010 Jack Phoenix
 12+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 13+ */
 14+
 15+if ( !defined( 'MEDIAWIKI' ) ) {
 16+ die( "This is not a valid entry point.\n" );
 17+}
 18+
 19+// Extension credits that will show up on Special:Version
 20+$wgExtensionCredits['other'][] = array(
 21+ 'name' => 'SoftwareVersion',
 22+ 'author' => 'Jack Phoenix',
 23+ 'version' => '0.4',
 24+ 'url' => 'http://www.mediawiki.org/wiki/Extension:SoftwareVersion',
 25+ 'description' => 'Customizes [[Special:Version]] for ShoutWiki',
 26+);
 27+
 28+// Our hooked function
 29+$wgHooks['SoftwareInfo'][] = 'efAddShoutWikiInfo';
 30+
 31+/**
 32+ * Adds ShoutWiki component into Special:Version and sets MW's version to $wgVersion
 33+ *
 34+ * @param $software Array: array of software information
 35+ * @return Boolean: true
 36+ */
 37+function efAddShoutWikiInfo( &$software ) {
 38+ global $wgVersion, $IP;
 39+
 40+ // Set MW version to $wgVersion
 41+ $software['[http://www.mediawiki.org/ MediaWiki]'] = $wgVersion;
 42+
 43+ // Add ShoutWiki component (release branch name) and its revision number
 44+ $software['[http://www.shoutwiki.com/ ShoutWiki]'] = efGetSvnURL( $IP ) . ' (r' . SpecialVersion::getSvnRevision( $IP ) . ')';
 45+
 46+ return true;
 47+}
 48+
 49+// Gets the name of the release for Special:Version's "ShoutWiki" column
 50+// Copied from Wikia's SpecialVersion.php and modified
 51+function efGetSvnURL( $dir ) {
 52+ // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
 53+ $entries = $dir . '/.svn/entries';
 54+
 55+ if( !file_exists( $entries ) ) {
 56+ return false;
 57+ }
 58+
 59+ $content = file( $entries );
 60+
 61+ $ret = str_replace( rtrim( $content[5] ), '', rtrim( $content[4] ) );
 62+ // Convert /trunk to trunk
 63+ if ( strpos( $ret, '/trunk' ) !== false ) {
 64+ $ret = str_replace( '/', '', $ret );
 65+ // and /tags/weekly/<release date> to just plain <release date>
 66+ } elseif ( strpos( $ret, '/tags/weekly/' ) !== false ) {
 67+ $ret = str_replace( '/tags/weekly/', '', $ret );
 68+ }
 69+
 70+ return $ret;
 71+}
\ No newline at end of file
Property changes on: trunk/extensions/SoftwareVersion/SoftwareVersion.php
___________________________________________________________________
Added: svn:eol-style
172 + native
Index: trunk/extensions/GlobalNotice/GlobalNotice.php
@@ -0,0 +1,151 @@
 2+<?php
 3+/**
 4+ * GlobalNotice -- global (undismissable) sitenotice for wiki farms
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ * @version 0.3
 9+ * @author Misza <misza@shoutwiki.com>
 10+ * @author Jack Phoenix <jack@shoutwiki.com>
 11+ * @copyright Copyright © 2010 Misza
 12+ * @copyright Copyright © 2010-2011 Jack Phoenix
 13+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 14+ * @link http://www.mediawiki.org/wiki/Extension:GlobalNotice Documentation
 15+ */
 16+
 17+if( !defined( 'MEDIAWIKI' ) ) {
 18+ die( "This is not a valid entry point.\n" );
 19+}
 20+
 21+// Extension credits that will show up on Special:Version
 22+$wgExtensionCredits['other'][] = array(
 23+ 'name' => 'GlobalNotice',
 24+ 'version' => '0.3',
 25+ 'author' => array( 'Misza', 'Jack Phoenix' ),
 26+ 'description' => 'Global sitenotice for wiki farms',
 27+ 'url' => 'http://www.mediawiki.org/wiki/Extension:GlobalNotice',
 28+);
 29+
 30+$wgHooks['SiteNoticeAfter'][] = 'wfGlobalNotice';
 31+/**
 32+ * @param $siteNotice String: existing site notice (if any) to manipulate or
 33+ * append to
 34+ * @return Boolean: true
 35+ */
 36+function wfGlobalNotice( &$siteNotice ) {
 37+ global $wgLang, $wgUser;
 38+
 39+ // It is possible that there is a global notice (for example, for all
 40+ // French-speaking users) *and* a forced global notice (for everyone,
 41+ // informing them of planned server maintenance etc.)
 42+ //
 43+ // We append whatever we have to this variable and if right before
 44+ // returning this variable is non-empty, we wrap the local site-notice in
 45+ // a div with id="localSiteNotice" because users may want to hide global
 46+ // notices (or forced global notices...that'd be quite dumb though)
 47+ //
 48+ // Come to think of it...on ShoutWiki, the $siteNotice variable will never
 49+ // be empty because SendToAFriend hooks into SiteNoticeAfter hook, too, and
 50+ // appends its HTML to it.
 51+ $ourSiteNotice = '';
 52+
 53+ // "Forced" globalnotice -- a site-wide notice shown for *all* users,
 54+ // no matter what their language is
 55+ // Used only for things like server migration notices etc.
 56+ //
 57+ // So, once again I find it that MediaWiki sucks. Adding 'parse' to the
 58+ // options array adds <p> tags around the message, EVEN IF THE MESSAGE IS
 59+ // EMPTY! This causes wfEmptyMsg() to think that the message has some
 60+ // content, when in fact it doesn't.
 61+ $forcedNotice = wfMsgExt(
 62+ 'forced-globalnotice',
 63+ array( 'language' => 'en' )
 64+ );
 65+ if ( !wfEmptyMsg( 'forced-globalnotice', $forcedNotice ) ) {
 66+ $ourSiteNotice .= '<div style="text-align: center;" id="forcedGlobalNotice">' .
 67+ wfMsgExt(
 68+ 'forced-globalnotice',
 69+ array( 'parse', 'language' => 'en' )
 70+ ) . '</div>';
 71+ }
 72+
 73+ // Global notice, depending on the user's language
 74+ // This can be used to show language-specific stuff to users with a certain
 75+ // interface language (i.e. "We need more French translators! Pouvez-vous nous aider ?")
 76+ $globalNotice = wfMsgExt(
 77+ 'globalnotice',
 78+ array( 'language' => $wgLang->getCode() )
 79+ );
 80+ if ( !wfEmptyMsg( 'globalnotice', $globalNotice ) ) {
 81+ // Give the global notice its own ID and center it
 82+ $ourSiteNotice .= '<div style="text-align: center;" id="globalNotice">' .
 83+ wfMsgExt(
 84+ 'globalnotice',
 85+ array( 'parse', 'language' => $wgLang->getCode() )
 86+ ) . '</div>';
 87+ }
 88+
 89+ // Group-specific global notices
 90+ foreach( array( 'sysop', 'bureaucrat', 'bot', 'rollback' ) as $group ) {
 91+ $messageName = 'globalnotice-' . $group;
 92+ $globalNoticeForGroup = wfMsgExt(
 93+ $messageName,
 94+ array( 'language' => $wgLang->getCode() )
 95+ );
 96+ $isMember = in_array( $group, $wgUser->getEffectiveGroups() );
 97+ if ( !wfEmptyMsg( $messageName, $globalNoticeForGroup ) && $isMember ) {
 98+ // Give the global notice its own ID and center it
 99+ $ourSiteNotice .= '<div style="text-align: center;" id="globalNoticeForGroup">' .
 100+ wfMsgExt(
 101+ $messageName,
 102+ array( 'parse', 'language' => $wgLang->getCode() )
 103+ ) . '</div>';
 104+ }
 105+ }
 106+
 107+ // If we have something to display, wrap the local sitenotice in a pretty
 108+ // div and copy $ourSiteNotice to $siteNotice
 109+ if ( !empty( $ourSiteNotice ) ) {
 110+ $ourSiteNotice .= '<!-- end GlobalNotice --><div id="localSiteNotice">' . $siteNotice . '</div>';
 111+ $siteNotice = $ourSiteNotice;
 112+ }
 113+
 114+ return true;
 115+}
 116+
 117+//$wgHooks['EditPage::showEditForm:initial'][] = 'wfGlobalNoticeOnEditPage';
 118+/**
 119+ * Show an annoying notice when editing MediaWiki:Forced-globalnotice because
 120+ * that message is Serious Business™.
 121+ * Disabled for production, might be too annoying -- but I just wanted to code
 122+ * this feature. :)
 123+ *
 124+ * @param $editPage Object: instance of EditPage class
 125+ * @return Boolean: true
 126+function wfGlobalNoticeOnEditPage( &$editPage ) {
 127+ // only initialize this when editing pages in MediaWiki namespace
 128+ if( $editPage->mTitle->getNamespace() != 8 ) {
 129+ return true;
 130+ }
 131+
 132+ // Show an annoying notice when editing MediaWiki:Forced-globalnotice
 133+ // I considered using confirm() JS but it doesn't allow CSS properties
 134+ // AFAIK and no CSS properties = less obtrusive notice = bad, so I ditched
 135+ // that idea.
 136+ if ( $editPage->mTitle->getDBkey() == 'Forced-globalnotice' ) {
 137+ $editPage->editFormPageTop .= '<span style="color: red;">Hey, hold it right there!</span><br />
 138+The value of this message is shown to <b>all users</b>, no matter what is their language. This can be <u>extremely</u> annoying.<br />
 139+<span style="text-transform: uppercase; font-size: 20px;">Only use this for really important things, like server maintenance notices!</span><br />
 140+Understood?
 141+<br /><br />
 142+
 143+<a href="#" onclick="document.getElementById( \'wpTextbox1\' ).style.display = \'block\'; return false;">Yes!</a>';
 144+ // JavaScript must be injected here, wpTextbox1 doesn't exist before...
 145+ $editPage->editFormTextAfterWarn .= '<script type="text/javascript">
 146+ document.getElementById( \'wpTextbox1\' ).style.display = \'none\';
 147+ </script>';
 148+ }
 149+
 150+ return true;
 151+}
 152+*/
\ No newline at end of file
Property changes on: trunk/extensions/GlobalNotice/GlobalNotice.php
___________________________________________________________________
Added: svn:eol-style
1153 + native
Index: trunk/extensions/EnhanceContactForm/EnhanceContactForm.php
@@ -0,0 +1,92 @@
 2+<?php
 3+/**
 4+ * EnhanceContactForm -- improves Special:Contact by adding new fields for:
 5+ * -wiki URL ($wgServer; this is the only visible field)
 6+ * -wiki database name ($wgDBname)
 7+ * -reporter's IP address
 8+ * -reporter's browser
 9+ * -reporter's operating system
 10+ * -reporter's User-Agent string
 11+ * MyInfo extension is required for the browser/OS/UA detection.
 12+ *
 13+ * @file
 14+ * @ingroup Extensions
 15+ * @author Jack Phoenix <jack@shoutwiki.com>
 16+ * @copyright Copyright © 2009-2011 Jack Phoenix
 17+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 18+ */
 19+
 20+if( !defined( 'MEDIAWIKI' ) ) {
 21+ die();
 22+}
 23+
 24+// Extension credits that will show up on Special:Version
 25+$wgExtensionCredits['other'][] = array(
 26+ 'name' => 'EnhanceContactForm',
 27+ 'version' => '0.5',
 28+ 'author' => 'Jack Phoenix',
 29+ 'url' => 'http://www.mediawiki.org/wiki/Extension:EnhanceContactForm',
 30+ 'description' => 'Enhances [[Special:Contact]] by sending more info',
 31+);
 32+
 33+$wgHooks['ContactForm'][] = 'enhanceContactForm';
 34+$wgHooks['ContactFormBeforeMessage'][] = 'addContactFormFields';
 35+
 36+/**
 37+ * Add extra info to the e-mail which gets sent to the staff.
 38+ * @return Boolean: true
 39+ */
 40+function enhanceContactForm( &$to, &$replyto, &$subject, &$text ) {
 41+ global $wgRequest;
 42+ $text = 'Contact message by the user: ' . $wgRequest->getText( 'wpText' ) . "\n";
 43+ // Now add the custom stuff
 44+ $text .= 'URL of the wiki: ' . $wgRequest->getText( 'wpWikiURL' ) . "\n";
 45+ $text .= 'Database name: ' . $wgRequest->getText( 'wpDBname' ) . "\n";
 46+ $text .= 'IP address of the reporter: ' . wfGetIP() . "\n";
 47+ $text .= 'Browser: ' . $wgRequest->getText( 'wpBrowser' ) . "\n";
 48+ $text .= 'Operating system: ' . $wgRequest->getText( 'wpOperatingSystem' ) . "\n";
 49+ $text .= 'User-Agent string: ' . $wgRequest->getText( 'wpUserAgent' ) . "\n";
 50+ return true;
 51+}
 52+
 53+/**
 54+ * Add new fields (1 shown + 1-5 hidden ones) to Special:Contact.
 55+ *
 56+ * @param $contactForm Object: instance of EmailContactForm class
 57+ * @param $form Sringt: HTML
 58+ * @return Boolean: true
 59+ */
 60+function addContactFormFields( $contactForm, $form ) {
 61+ global $wgServer, $wgDBname;
 62+
 63+ $form .= '<tr>
 64+ <td class="mw-label">' .
 65+ Xml::label( wfMsg( 'contactpage-wikiurl' ), 'wpWikiURL' ) .
 66+ '</td>
 67+ <td class="mw-input" id="mw-contactpage-address">' .
 68+ Xml::input( 'wpWikiURL', 60, $wgServer, array( 'type' => 'text', 'maxlength' => 200 ) ) .
 69+ '</td>
 70+ </tr>
 71+ <tr>' .
 72+ Xml::hidden( 'wpDBname', $wgDBname, array( 'maxlength' => 100 ) ) .
 73+ "</tr>\n\t\t\t";
 74+ if( class_exists( 'MyInfo' ) ) {
 75+ $myinfo = new MyInfo();
 76+ $myinfo->browser = get_browser( null, true );
 77+ $myinfo->info = browser_detection( 'full' );
 78+ $myinfo->info[] = browser_detection( 'moz_version' );
 79+ $form .= '<tr>' .
 80+ Xml::hidden( 'wpBrowser', $myinfo->getBrowser(), array( 'maxlength' => 255 ) ) .
 81+ '</tr>
 82+ <tr>' .
 83+ Xml::hidden( 'wpOperatingSystem', $myinfo->getOs(), array( 'maxlength' => 255 ) ) .
 84+ '</tr>
 85+ <tr>' .
 86+ Xml::hidden( 'wpSkinName', $myinfo->getSkin(), array( 'maxlength' => 35 ) ) .
 87+ '</tr>
 88+ <tr>' .
 89+ Xml::hidden( 'wpUserAgent', $myinfo->getUAgent(), array( 'maxlength' => 500 ) ) .
 90+ '</tr>';
 91+ }
 92+ return true;
 93+}
\ No newline at end of file
Property changes on: trunk/extensions/EnhanceContactForm/EnhanceContactForm.php
___________________________________________________________________
Added: svn:eol-style
194 + native
Index: trunk/extensions/Quantcast/Quantcast.php
@@ -0,0 +1,69 @@
 2+<?php
 3+/**
 4+ * Quantcast tracking extension -- adds Quantcast tracking JS code to all pages
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ * @version 0.1
 9+ * @date 12 December 2010
 10+ * @author Jack Phoenix <jack@shoutwiki.com> (forgive me)
 11+ * @license http://en.wikipedia.org/wiki/Public_domain Public domain
 12+ * @link http://www.mediawiki.org/wiki/Extension:Quantcast Documentation
 13+ * @see http://bugzilla.shoutwiki.com/show_bug.cgi?id=108
 14+ */
 15+
 16+if ( !defined( 'MEDIAWIKI' ) ) {
 17+ die( 'This is not a valid entry point to MediaWiki.' );
 18+}
 19+
 20+// Extension credits that will show up on Special:Version
 21+$wgExtensionCredits['other'][] = array(
 22+ 'name' => 'Quantcast Tracking',
 23+ 'version' => '0.1',
 24+ 'author' => 'Jack Phoenix',
 25+ 'description' => 'Adds [http://www.quantcast.com/ Quantcast] tracking code to pages',
 26+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Quantcast',
 27+);
 28+
 29+// Groups that are excluded from Quantcast statistics
 30+$wgQuantcastTrackingExcludedGroups = array( 'staff' );
 31+
 32+// Hook it up!
 33+$wgHooks['SkinAfterBottomScripts'][] = 'wfAddQuantcastTrackingCode';
 34+
 35+/**
 36+ * Add tracking JS to all pages for all users that are not members of excluded
 37+ * groups (the group listed in $wgQuantcastTrackingExcludedGroups).
 38+ *
 39+ * @param $skin Object: Skin object
 40+ * @param $text String: bottomScripts text
 41+ * @return Boolean: true
 42+ */
 43+function wfAddQuantcastTrackingCode( $skin, &$text ) {
 44+ global $wgUser, $wgQuantcastTrackingExcludedGroups;
 45+
 46+ $groups = $wgUser->getEffectiveGroups();
 47+ if ( !in_array( $wgQuantcastTrackingExcludedGroups, $groups ) ) {
 48+ $message = trim( wfMsgForContent( 'quantcast-tracking-number' ) );
 49+ // We have a custom tracking code, use it!
 50+ if( !wfEmptyMsg( 'quantcast-tracking-number', $message ) ) {
 51+ $trackingCode = $message;
 52+ } else { // use ShoutWiki's default code
 53+ $trackingCode = wfMsgForContent( 'shoutwiki-quantcast-tracking-number' );
 54+ }
 55+ $safeCode = htmlspecialchars( $trackingCode, ENT_QUOTES );
 56+ $text .= "\t\t" . '<!-- Start Quantcast tag -->
 57+ <script type="text/javascript">/*<![CDATA[*/
 58+ _qoptions = {
 59+ qacct: "' . $safeCode . '"
 60+ };
 61+ /*]]>*/</script>
 62+ <script type="text/javascript" src="http://edge.quantserve.com/quant.js"></script>
 63+ <noscript>
 64+ <img src="http://pixel.quantserve.com/pixel/' . $safeCode . '.gif" style="display: none;" border="0" height="1" width="1" alt="Quantcast" />
 65+ </noscript>
 66+ <!-- End Quantcast tag -->' . "\n\n";
 67+ }
 68+
 69+ return true;
 70+}
\ No newline at end of file
Property changes on: trunk/extensions/Quantcast/Quantcast.php
___________________________________________________________________
Added: svn:eol-style
171 + native
Index: trunk/extensions/WhitelistPages/WhitelistPages.php
@@ -0,0 +1,55 @@
 2+<?php
 3+/**
 4+ * A quick hack to make $wgWhitelistRead an admin-editable system message.
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ * @version 0.2
 9+ * @author Jack Phoenix <jack@shoutwiki.com>
 10+ * @author Misza <misza@shoutwiki.com>
 11+ * @date 26 January 2011
 12+ * @see http://en.gwo.shoutwiki.com/w/index.php?title=User_talk%3AJack_Phoenix&diff=302&oldid=83
 13+ * @license http://en.wikipedia.org/wiki/Public_domain Public domain
 14+ */
 15+
 16+if ( !defined( 'MEDIAWIKI' ) ) {
 17+ die( 'This is not a valid entry point to MediaWiki.' );
 18+}
 19+
 20+// Extension credits that will show up on Special:Version
 21+$wgExtensionCredits['other'][] = array(
 22+ 'name' => 'Whitelist Pages',
 23+ 'author' => array( 'Jack Phoenix', 'Misza' ),
 24+ 'version' => '0.2',
 25+ 'description' => 'Allows [[MediaWiki:Public read whitelist|whitelisting]] pages on a private wiki so that anonymous users can read said pages',
 26+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Whitelist_Pages',
 27+);
 28+
 29+$wgExtensionFunctions[] = 'wfWhitelistPages';
 30+function wfWhitelistPages() {
 31+ global $wgWhitelistRead, $wgGroupPermissions;
 32+
 33+ $message = wfMsgForContent( 'public read whitelist' );
 34+
 35+ // If MediaWiki:Public read whitelist is empty, bail out
 36+ if ( wfEmptyMsg( 'public read whitelist', $message ) ) {
 37+ return;
 38+ }
 39+
 40+ // If anonymous users can read the wiki, then it's not a private one
 41+ // and we don't need this feature for non-private wikis
 42+ if ( $wgGroupPermissions['*']['read'] ) {
 43+ return;
 44+ }
 45+
 46+ // $wgWhitelistRead is *false* by default instead of being an empty array
 47+ if ( $wgWhitelistRead === false ) {
 48+ $wgWhitelistRead = array();
 49+ }
 50+
 51+ // Explode along newlines
 52+ $whitelistedPages = explode( "\n", trim( $message ) );
 53+
 54+ // Merge with current list
 55+ $wgWhitelistRead = array_merge( $wgWhitelistRead, $whitelistedPages );
 56+}
\ No newline at end of file
Property changes on: trunk/extensions/WhitelistPages/WhitelistPages.php
___________________________________________________________________
Added: svn:eol-style
157 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r87412Add i18n file for r87365...raymond17:20, 4 May 2011

Comments

#Comment by Nikerabbit (talk | contribs)   07:39, 4 May 2011

demon: ?

#Comment by P858snake (talk | contribs)   08:43, 4 May 2011

pointless reply so i get follow up emails

#Comment by Dantman (talk | contribs)   22:42, 9 March 2012

"SoftwareVersion"

What is blatant ShoutWiki specific (absolutely worthless to everyone else) code doing in our generic extensions repo occupying a very generic extension name?

Status & tagging log