|
|
Line 134: |
Line 134: |
| padding: 5px; | | padding: 5px; |
| } | | } |
- |
| |
- | <?php
| |
- | /**
| |
- | * WikiSpeller - some folks can spel, smart peple use a speller checker
| |
- | *
| |
- | * More details at http://it.extension.org/wiki/WikiSpeller
| |
- | *
| |
- | * Developed with funding by the National eXtension Initiative.
| |
- | *
| |
- | * For the latest version, please see:
| |
- | * https://sourcecode.extension.org/MediaWiki/WikiSpeller/
| |
- | *
| |
- | * This is a MediaWiki Extension. To activate the extension,
| |
- | * include it from your LocalSettings.php with:
| |
- | * include_once("extensions/WikiSpeller/WikiSpeller.php");
| |
- | *
| |
- | * @package WikiSpeller
| |
- | * @version 1.2
| |
- | * @author James E. Robinson, III <james.robinson@extension.org>
| |
- | * @copyright North Carolina State University 2006
| |
- | */
| |
- | $gsVersion = "1.2";
| |
- |
| |
- | /*
| |
- |
| |
- | © Copyright 2006 North Carolina State University
| |
- |
| |
- | Redistribution and use in source and binary forms, with or without
| |
- | modification, are permitted provided that the following conditions are met:
| |
- |
| |
- | 1. Redistributions of source code must retain the above copyright notice,
| |
- | this list of conditions and the following disclaimer.
| |
- |
| |
- | 2. Redistributions in binary form must reproduce the above copyright notice,
| |
- | this list of conditions and the following disclaimer in the documentation
| |
- | and/or other materials provided with the distribution.
| |
- |
| |
- | 3. The name of the author may not be used to endorse or promote products
| |
- | derived from this software without specific prior written permission.
| |
- |
| |
- | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
| |
- | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
| |
- | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
| |
- | EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
| |
- | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
| |
- | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
| |
- | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
| |
- | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
| |
- | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
| |
- | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
| |
- | */
| |
- |
| |
- | /**
| |
- | * Your countries default Google domain.
| |
- | */
| |
- | define('GOOGLE_SITE', 'www.google.com');
| |
- |
| |
- | /**
| |
- | * Built-in XML proxy for Google
| |
- | * based on version written by Clem (http://labs.beffa.org/)
| |
- | */
| |
- | if ( ! defined('MEDIAWIKI') ) {
| |
- |
| |
- | $lang = urlencode($_GET['lang']);
| |
- | $url = 'http://' . GOOGLE_SITE . '/tbproxy/spell?lang=' . $lang;
| |
- |
| |
- | $data = file_get_contents('php://input');
| |
- |
| |
- | $curl_opts = array(
| |
- | CURLOPT_URL => $url,
| |
- | CURLOPT_POST => 1,
| |
- | CURLOPT_POSTFIELDS => $data,
| |
- | CURLOPT_RETURNTRANSFER => 1
| |
- | );
| |
- |
| |
- | $ch = curl_init();
| |
- | foreach ( $curl_opts as $opt => $val ) {
| |
- | curl_setopt($ch, $opt, $val);
| |
- | }
| |
- | $output = curl_exec ($ch);
| |
- | curl_close ($ch);
| |
- |
| |
- | print $output;
| |
- |
| |
- | exit(0);
| |
- | }
| |
- |
| |
- | /**
| |
- | * This should take care of typical MediaWiki installs.
| |
- | * If not, change it.
| |
- | * It should be the relative web path to the top-level WikiSpeller
| |
- | * directory.
| |
- | */
| |
- | $WikiSpellWebPath = $GLOBALS['wgScriptPath'] . '/extensions/WikiSpeller/';
| |
- |
| |
- | /**#@+
| |
- | * Extension entry points used by MW.
| |
- | *
| |
- | * @access public
| |
- | */
| |
- | function wfWikiSpeller() {
| |
- | WikiSpeller::addIncludes();
| |
- | return;
| |
- | }
| |
- | /**#@-*/
| |
- |
| |
- | /**
| |
- | * Class with functions that add the appropriate javascript and CSS
| |
- | * hooks to the MediaWiki output to allow googiespell to work.
| |
- | *
| |
- | * @package WikiSpeller
| |
- | * @author James E. Robinson, III <james.robinson@extension.org>
| |
- | * @version $Revision: 83 $
| |
- | * @copyright North Carolina State University 2006
| |
- | */
| |
- | class WikiSpeller {
| |
- |
| |
- | /**#@+
| |
- | * @access private
| |
- | */
| |
- | var $debug;
| |
- | /**#@-*/
| |
- |
| |
- | /**
| |
- | * Class constructor.
| |
- | *
| |
- | * @access public
| |
- | */
| |
- | function WikiSpeller() {
| |
- | $fname = __CLASS__ . '::' . __FUNCTION__;
| |
- | wfProfileIn($fname);
| |
- | $this->debug = False;
| |
- | wfProfileOut($fname);
| |
- | return;
| |
- | }
| |
- |
| |
- | /**
| |
- | * Includes the required spell-check files - css and js.
| |
- | *
| |
- | * @access private
| |
- | */
| |
- | function addIncludes() {
| |
- | $fname = __CLASS__ . '::' . __FUNCTION__;
| |
- | wfProfileIn($fname);
| |
- |
| |
- | $action = $GLOBALS['wgRequest']->getVal('action');
| |
- | $preview = $GLOBALS['wgRequest']->getCheck('wpPreview');
| |
- |
| |
- | if ( $action != 'edit' ) {
| |
- | if ( $preview && ($action == 'submit') ) {
| |
- | $action = 'edit';
| |
- | }
| |
- | }
| |
- |
| |
- | if ( $action == 'edit' ) {
| |
- |
| |
- | $uri = $GLOBALS['WikiSpellWebPath'];
| |
- | $goog = $uri . 'gs/googiespell/';
| |
- | $scr = '
| |
- | <script type="text/javascript"
| |
- | src="' . $goog . 'AmiJS.js"></script>
| |
- | <script type="text/javascript"
| |
- | src="'. $goog . 'googiespell.js"></script>
| |
- | <script type="text/javascript"
| |
- | src="' . $goog . 'cookiesupport.js"></script>
| |
- | <link href="' . $goog . 'googiespell.css"
| |
- | rel="stylesheet" type="text/css" media="all" />';
| |
- |
| |
- | // add JS - the std MW text edit box is name="wpTextbox1"
| |
- | $scr .= '
| |
- | <script type="text/javascript">
| |
- | if (typeof document.attachEvent!=\'undefined\') {
| |
- | window.attachEvent(\'onload\',Spellorate);
| |
- | } else {
| |
- | window.addEventListener(\'load\',Spellorate,false);
| |
- | }
| |
- |
| |
- | function getGoogleUrl() {
| |
- | return "' . $uri . 'WikiSpeller.php' . '?lang=" + CURRENT_LANG;
| |
- | }
| |
- |
| |
- | var GOOGIE_IMAGE_DIR = "' . $uri . 'gs/googiespell/";
| |
- | var CURRENT_LANG;
| |
- |
| |
- | function Spellorate(){
| |
- | var cookie_value;
| |
- |
| |
- | cookie_value = getCookie("language");
| |
- | if ( cookie_value != null ) {
| |
- | CURRENT_LANG = cookie_value;
| |
- | } else {
| |
- | CURRENT_LANG = "en";
| |
- | }
| |
- |
| |
- | document.editform.wpTextbox1.setAttribute("id", "wpTextbox1");
| |
- | googieDecorateTextarea("wpTextbox1");
| |
- | }
| |
- | </script>';
| |
- |
| |
- | // make the lang and spellcheck elements closer together to
| |
- | // give the lang drop-down some context
| |
- | $scr .= '<style> #editform table { width: 300px; } </style>';
| |
- |
| |
- | $GLOBALS['wgOut']->addScript($scr);
| |
- | }
| |
- |
| |
- | wfProfileOut($fname);
| |
- | return;
| |
- | }
| |
- |
| |
- | /**
| |
- | * Returns version string for module.
| |
- | *
| |
- | * @param string $version Primary version string.
| |
- | * @return string Module version with build number and date.
| |
- | * @access public
| |
- | */
| |
- | function getVersion($version) {
| |
- | $fname = __CLASS__ . '::' . __FUNCTION__;
| |
- |
| |
- | // svn propset svn:keywords "Date Revision"
| |
- | $revision = '$Revision: 83 $';
| |
- | $date = '$Date: 2006-03-28 09:01:07 -0500 (Tue, 28 Mar 2006) $';
| |
- | $build = '';
| |
- | $shortdate = '';
| |
- |
| |
- | // grab only the number
| |
- | $rc = preg_match('(\\d+)', $revision, $matches);
| |
- | if ( $rc ) {
| |
- | $build = $matches[0];
| |
- | }
| |
- |
| |
- | // just get the yr mo day string
| |
- | $rc = preg_match('(\\d+-\\d+-\\d+)', $date, $matches);
| |
- | if ( $rc ) {
| |
- | $shortdate = $matches[0];
| |
- | }
| |
- |
| |
- | return "v.$version($build) $shortdate";
| |
- | }
| |
- |
| |
- | /**
| |
- | * Output module debugging information.
| |
- | *
| |
- | * @param mixed $input Zero or more variables or strings to log.
| |
- | * @param string $more Additional text to output. Optional.
| |
- | * @access private
| |
- | * @see GlobalFunctions
| |
- | */
| |
- | function debug($input=False) {
| |
- | $fname = __CLASS__ . '::' . __FUNCTION__;
| |
- |
| |
- | if(! $this->debug ) return;
| |
- |
| |
- | wfProfileIn($fname);
| |
- |
| |
- | if ( func_num_args() > 1 || !is_array($input) ) {
| |
- | $input = func_get_args();
| |
- | }
| |
- |
| |
- | // use a buffer to capture output
| |
- | ob_start();
| |
- | var_dump($input);
| |
- | $output = ob_get_contents();
| |
- | ob_end_clean();
| |
- |
| |
- | wfDebug($output . "\
| |
- | ");
| |
- |
| |
- | wfProfileOut($fname);
| |
- | return;
| |
- | }
| |
- |
| |
- | }
| |
- |
| |
- | // Register extension functions
| |
- | $wgExtensionFunctions[] = 'wfWikiSpeller';
| |
- |
| |
- | $gsVersion = WikiSpeller::getVersion($gsVersion);
| |
- |
| |
- | $wgExtensionCredits['parserhook'][] = array
| |
- | (
| |
- | 'name' => "WikiSpeller $gsVersion",
| |
- | 'author' => 'James E. Robinson, III',
| |
- | 'url' => 'http://it.extension.org/wiki/WikiSpeller'
| |
- | );
| |
- |
| |
- | ?>
| |
| | | |
| /* | | /* |
| </pre> | | </pre> |
| */ | | */ |