【问题标题】:Wiki - table content from an external sourceWiki - 来自外部来源的表格内容
【发布时间】:2013-09-05 06:32:19
【问题描述】:

是否可以有一个 wiki 页面,其中包含两个表,反映来自两个不同的 3rd 方站点的数据?

如果是这样,如何完成?页面模板在这里会有所帮助吗?

【问题讨论】:

    标签: html mediawiki wiki


    【解决方案1】:

    简短的回答是否定的,没有简单的内置方法可以将外部内容拉入 MediaWiki 站点。允许第三方注入任意内容将带来巨大的安全风险。

    长答案是,任何事情都可以通过扩展来实现,无论是现有的还是您自己编写的。 MediaWiki 站点有一整类“Remote content extensions”列表,它们以一种或另一种形式执行此类操作,External Data 看起来特别有用。您需要管理员权限才能安装其中任何一个,并且您需要信任扩展代码和您提取的数据。

    【讨论】:

      【解决方案2】:

      我已经完全按照你的描述写了。可能对你有帮助。

      # Define a setup function
      $wgHooks['ParserFirstCallInit'][] = 'efStackOverflow_Setup';
      # Add a hook to initialise the magic word
      $wgHooks['LanguageGetMagic'][]       = 'efStackOverflow_Magic';
      
      function efStackOverflow_Setup( &$parser ) {
              # Set a function hook associating the "example" magic word with our function
       $parser->setFunctionHook( 'stag', 'efStackOverflow_Render' );
              return true;
      }
      
      function efStackOverflow_Magic( &$magicWords, $langCode ) {
              # Add the magic word
              # The first array element is whether to be case sensitive, in this case (0) it is not case sensitive, 1 would be sensitive
              # All remaining elements are synonyms for our parser function
              $magicWords['stag'] = array(1, 'stag');
              # unless we return true, other parser functions extensions won't get loaded.
              return true;
      }
      
      function efStackOverflow_Render( $parser, $param1 = '', $param2 = '' ) {
        // there was filtering
        $modif = 0;
      
        $cache_file_path = "cache/".$param1."_".$param2;
      
        if (file_exists($cache_file_path))
        $modif = time() - @filemtime ($cache_file_path);
      
        if (file_exists($cache_file_path) and $modif < 60*60*24) {
      
          return file_get_contents($cache_file_path);
      
        }
      
        $page = file_get_contents("http://www.google.com/rss/".$param1);
      
        $xml = new SimpleXMLElement($page);
      
        foreach ($xml as $key => $value) {
      // do some
        }
      
        if (!empty($output))
        file_put_contents($cache_file_path, $output);
      
        return $output;
      
      }
      

      Mediawiki 版本是 1.16。

      【讨论】:

      • 这是一个完美的例子,说明为什么你不应该自己做这种事情:因为你对 $param1 进行了零过滤,用户可以按照 {{stag|.. /../etc/passwd#&0;}} 并获取您的密码文件的转储!
      • @jpatokal 我切断了过滤。如果您有兴趣 - 第一个参数是预定义的字符串,第二个参数是数字。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多