r45870 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45869‎ | r45870 | r45871 >
Date:10:44, 18 January 2009
Author:dantman
Status:deferred
Tags:
Comment:
Committing negref extension (Negotiate References).
Allows the location of references to be negociated to avoid issues in
templates where you want to use something like [[{{{1}}}]] but don't
want the link to break if the user inputs a ref tag.
Modified paths:
  • /trunk/extensions/Negref (added) (history)
  • /trunk/extensions/Negref/Negref.php (added) (history)

Diff [purge]

Index: trunk/extensions/Negref/Negref.php
@@ -0,0 +1,76 @@
 2+<?php
 3+/**
 4+ * WikiRuby
 5+ * @package WikiRuby
 6+ * @author Daniel Friesen (http://wiki-tools.com/wiki/User:Dantman) <dan_the_man@telus.net>
 7+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 8+ *
 9+ * This program is free software; you can redistribute it and/or
 10+ * modify it under the terms of the GNU General Public License
 11+ * as published by the Free Software Foundation; either version 2
 12+ * of the License, or (at your option) any later version.
 13+ *
 14+ * This program is distributed in the hope that it will be useful,
 15+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 17+ * GNU General Public License for more details.
 18+ *
 19+ * You should have received a copy of the GNU General Public License
 20+ * along with this program; if not, write to the Free Software
 21+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 22+ */
 23+
 24+if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." );
 25+
 26+$wgExtensionCredits['parserhook'][] = array (
 27+ "name" => "Negref",
 28+ "author" => "[http://mediawiki.org/wiki/User:Dantman Daniel Friesen]",
 29+ "description" => "Provides a tag to negotiate the location of any <nowiki><ref/></nowiki> tags inside of input text to fix some template use cases."
 30+);
 31+
 32+$wgExtensionFunctions[] = 'efNegrefSetup';
 33+$wgHooks['LanguageGetMagic'][] = 'efNegrefSetupLanguageMagic';
 34+$wgExtensionMessagesFiles['Negref'] = dirname(__FILE__).'/Negref.i18n.php';
 35+
 36+function efNegrefSetup() {
 37+ global $wgParser, $wgHooks;
 38+
 39+ // Check for SFH_OBJECT_ARGS capability
 40+ if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
 41+ $wgHooks['ParserFirstCallInit'][] = 'efNegrefRegisterParser';
 42+ } else {
 43+ if ( class_exists( 'StubObject' ) && !StubObject::isRealObject( $wgParser ) ) {
 44+ $wgParser->_unstub();
 45+ }
 46+ efNegrefRegisterParser( $wgParser );
 47+ }
 48+
 49+ return true;
 50+}
 51+
 52+function efNegrefRegisterParser( &$parser ) {
 53+ $parser->setFunctionHook( 'negref', 'efNegrefHook' );
 54+ return true;
 55+}
 56+
 57+function efNegrefSetupLanguageMagic( &$magicWords, $langCode ) {
 58+ $magicWords['negref'] = array( 0, 'negref' );
 59+ return true;
 60+}
 61+
 62+function efNegrefHook( $parser, $input, $replaceData, $replaceRef, $pattern ) {
 63+ $data = $input;
 64+ $ref = '';
 65+
 66+ $keys = array_keys($parser->mStripState->general->getArray());
 67+ foreach($keys as $key) {
 68+ if(preg_match('/^'.preg_quote($parser->uniqPrefix(), '/').'-(ref)-.*$/', $key)) {
 69+ if(substr_count($input, $key) > 0) {
 70+ $data = str_replace($key, '', $data);
 71+ $ref .= $key;
 72+ }
 73+ }
 74+ }
 75+
 76+ return str_replace($replaceRef, $ref, str_replace($replaceData, $data, $pattern));
 77+}
Property changes on: trunk/extensions/Negref/Negref.php
___________________________________________________________________
Name: svn:eol-style
178 + native

Status & tagging log