Extension:BypassSearch/1.0.1
From MediaWiki.org
< Extension:BypassSearch(Redirected from Extension:BypassSearch/stable)
<?php /** BypassSearch - http://www.mediawiki.org/wiki/Extension:BypassSearch Some notes: -UserToggles requires 1.8.0. If you're old school (i.e., you don't meet that version), you're gonna have to get down and dirty. -SpecialSearchNogomatch requires 1.6.0, and if you're running on that old of mw, you really should upgrade anyway. -You don't need this extension if you enable $wgGoToEdit globally. -Set $wgDefaultUserOptions['bypasssearch'] to 1 in LocalSettings.php to enable the toggle by default; 0 to disable by default. */ if (!defined('MEDIAWIKI')) { echo "This is an extension and has no bells and whistles you can play with by accessing it directly.\n"; die(); } // make it... $bypassSearch = new BypassSearch; // ... then add it ... $wgExtensionFunctions[] = array($bypassSearch, 'init'); // ... and finally make the preference to enable it. $wgHooks['UserToggles'][] = array($bypassSearch, 'togglify'); $wgExtensionCredits['other'][] = array( 'name' => 'BypassSearch', 'version' => '1.0.0', 'author' => '[http://en.wikipedia.org/wiki/User:Slakr/BypassSearch slakr]', 'url' => 'http://www.mediawiki.org/wiki/Extension:BypassSearch', 'description' => 'Adds a user preference to go directly to creating a new page when the Go button is used and the target page doesn\'t exist', ); // zee class class BypassSearch { /** Say hi, offer coffee/tea. * @public */ function init() { global $wgUser, $wgHooks; // is it enabled? more importantly, do they have enough 's'es to sound like a snake? if ( ! $wgUser->getOption('bypasssearch') ) { return; } // add actual handling for us. $wgHooks['SpecialSearchNogomatch'][] = array($this, 'run'); } /** Add our toggle * @param array &$toggles * @public */ function togglify(&$toggles) { global $wgMessageCache; // insert the actual toggle $toggles[] = 'bypasssearch'; // ... and add the appropriate language entry for it. // TODO: Find someone who speaks every language on planet. // TODO-ALTERNATE: ... ask really nicely for translations. :P $wgMessageCache->addMessage('tog-bypasssearch', 'Bypass automatic searches when using the "Go" button and the target page does not exist'); return true; } /** Apparently we're enabled, so let's kick the tires and light the fires. * @param object &$titleObj * @public */ function run(&$titleObj) { global $wgGoToEdit; // drumroll please ... $wgGoToEdit = true; // ... and I'm spent. The rest is out of our hands. return true; } } // end class BypassSearch
