r45541 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45540‎ | r45541 | r45542 >
Date:02:48, 8 January 2009
Author:demon
Status:deferred
Tags:
Comment:
Quick and dirty little extension to remove all redlinks from page output. Returns the raw link text if the page doesn't exist.
Modified paths:
  • /trunk/extensions/RemoveRedlinks (added) (history)
  • /trunk/extensions/RemoveRedlinks/RemoveRedlinks.php (added) (history)

Diff [purge]

Index: trunk/extensions/RemoveRedlinks/RemoveRedlinks.php
@@ -0,0 +1,45 @@
 2+<?php
 3+
 4+/**
 5+ * Extension:RemoveRedlinks - Hide all redlinks and turn them into
 6+ * their static text.
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * @author Chad Horohoe <innocentkiller@gmail.com>
 14+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 15+ */
 16+
 17+$wgExtensionCredits['other'][] = array(
 18+ 'name' => 'RemoveRedlinks',
 19+ 'url' => 'http://mediawiki.org/wiki/Extension:RemoveRedlinks',
 20+ 'description' => 'Removes all redlinks from page output',
 21+ 'author' => '[mailto:innocentkiller@gmail.com Chad Horohoe]',
 22+);
 23+
 24+// Hook Registering
 25+$wgHooks['LinkBegin'][] = 'efRemoveRedlinks';
 26+
 27+// And the function
 28+function efRemoveRedlinks( $skin, $target, &$text, &$customAttribs, &$query, &$options, &$ret ) {
 29+ // return immediately if we know it's real
 30+ if ( in_array( 'known', $options ) ) {
 31+ return true;
 32+ }
 33+ // or if we know it's broken
 34+ if ( in_array( 'broken', $options ) ) {
 35+ $ret = $text;
 36+ return false;
 37+ }
 38+ // hopefully we don't have to do this, but here we'll check for existence.
 39+ // dupes a bit of the logic in Linker::link(), but we have to know here
 40+ if( $target->isKnown() ) {
 41+ return true;
 42+ } else {
 43+ $ret = $text;
 44+ return false;
 45+ }
 46+}

Status & tagging log