Index: trunk/extensions/TemplateInfo/TemplateInfo.API.php |
— | — | @@ -1,109 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Adds the 'templateinfo' action to the MediaWiki API. |
5 | | - * |
6 | | - * @author Yaron Koren |
7 | | - */ |
8 | | - |
9 | | -/** |
10 | | - * Protect against register_globals vulnerabilities. |
11 | | - * This line must be present before any global variable is referenced. |
12 | | - */ |
13 | | -if (!defined('MEDIAWIKI')) die(); |
14 | | - |
15 | | -/** |
16 | | - * @addtogroup API |
17 | | - */ |
18 | | -class TemplateInfoAPI extends ApiBase { |
19 | | - |
20 | | - public function __construct($query, $moduleName) { |
21 | | - parent :: __construct($query, $moduleName); |
22 | | - } |
23 | | - |
24 | | - public function execute() { |
25 | | - global $wgContLang, $wgParser, $egTemplateInfoXML; |
26 | | - |
27 | | - $params = $this->extractRequestParams(); |
28 | | - $template_name = $params['template']; |
29 | | - |
30 | | - if (strlen($template_name) == 0) { |
31 | | - $this->dieUsage("A template name must be specified", 'param_substr'); |
32 | | - } |
33 | | - |
34 | | - $template_title = Title::makeTitleSafe(NS_TEMPLATE, $template_name); |
35 | | - if (! $template_title->exists()) { |
36 | | - $this->dieUsage("A template does not exist by this name", 'param_substr'); |
37 | | - } |
38 | | - $parser_options = new ParserOptions(); |
39 | | - $article = new Article($template_title); |
40 | | - $text = $wgParser->parse($article->getContent(), $template_title, $parser_options); |
41 | | - if (empty($egTemplateInfoXML)) { |
42 | | - $this->dieUsage("This template does not contain an XML definition.", 'param_substr'); |
43 | | - } |
44 | | - |
45 | | - $data = array($egTemplateInfoXML); |
46 | | - |
47 | | - $xmlDTD =<<<END |
48 | | -<?xml version="1.0" encoding="utf-8"?> |
49 | | -<!DOCTYPE template [ |
50 | | -<!ELEMENT template (description?,params?,data*)> |
51 | | -<!ELEMENT params (param|group)*> |
52 | | -<!ELEMENT param (label?,description?,options?,type?,data*)> |
53 | | -<!ATTLIST param id ID #REQUIRED> |
54 | | -<!ELEMENT group (label?,description?,param*,data*)> |
55 | | -<!ELEMENT label (#PCDATA|msg)*> |
56 | | -<!ELEMENT description (#PCDATA|msg)*> |
57 | | -<!ELEMENT options (option*)> |
58 | | -<!ELEMENT option (#PCDATA|msg)*> |
59 | | -<!ELEMENT type (field*)> |
60 | | -<!ATTLIST type name CDATA #REQUIRED> |
61 | | -<!ELEMENT field EMPTY> |
62 | | -<!ATTLIST field name CDATA #REQUIRED> |
63 | | -<!ATTLIST field value CDATA #REQUIRED> |
64 | | -<!ELEMENT msg (#PCDATA)> |
65 | | -<!ATTLIST msg lang CDATA #REQUIRED> |
66 | | -<!ELEMENT data (field*)> |
67 | | -<!ATTLIST data app CDATA #REQUIRED> |
68 | | -]> |
69 | | - |
70 | | -END; |
71 | | - // hide parsing warnings |
72 | | - libxml_use_internal_errors(true); |
73 | | - $xml_success = simplexml_load_string($xmlDTD . $egTemplateInfoXML); |
74 | | - if (! $xml_success) { |
75 | | - $this->dieUsage("Template contains invalid XML", 'badxml'); |
76 | | - } |
77 | | - |
78 | | - // Set top-level elements |
79 | | - $result = $this->getResult(); |
80 | | - $result->setIndexedTagName($data, 'p'); |
81 | | - $result->addValue(null, $this->getModuleName(), $data); |
82 | | - } |
83 | | - |
84 | | - protected function getAllowedParams() { |
85 | | - return array ( |
86 | | - 'template' => null, |
87 | | - ); |
88 | | - } |
89 | | - |
90 | | - protected function getParamDescription() { |
91 | | - return array ( |
92 | | - 'template' => 'The name of the template to retrieve information for', |
93 | | - ); |
94 | | - } |
95 | | - |
96 | | - protected function getDescription() { |
97 | | - return 'Template information, defined by the Templat Info extension (http://www.mediawiki.org/Extension:Template_Info)'; |
98 | | - } |
99 | | - |
100 | | - protected function getExamples() { |
101 | | - return array ( |
102 | | - 'api.php?action=templateinfo&template=My_template', |
103 | | - ); |
104 | | - } |
105 | | - |
106 | | - public function getVersion() { |
107 | | - return __CLASS__ . ': $Id$'; |
108 | | - } |
109 | | - |
110 | | -} |
Index: trunk/extensions/TemplateInfo/TemplateInfo.classes.php |
— | — | @@ -1,20 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Classes for TemplateInfo extension |
5 | | - * |
6 | | - * @file |
7 | | - * @ingroup Extensions |
8 | | - */ |
9 | | - |
10 | | -// TemplateInfo class |
11 | | -class TemplateInfo { |
12 | | - |
13 | | - /** |
14 | | - * Display the contents of <templateinfo> in a nicely-formatted way. |
15 | | - */ |
16 | | - public function render( $input ) { |
17 | | - $text = "<p>" . wfMsg('templateinfo-header') . "</p>\n"; |
18 | | - $text .= htmlentities($input); |
19 | | - return $text; |
20 | | - } |
21 | | -} |
Index: trunk/extensions/TemplateInfo/TemplateInfo.hooks.php |
— | — | @@ -22,19 +22,17 @@ |
23 | 23 | // Render the displayed XML, if any |
24 | 24 | public static function render( $input, $args, $parser, $frame ) { |
25 | 25 | // if this call is contained in a transcluded page or template, |
26 | | - // display nothing |
27 | | - if ($frame->title->getFullText() != $parser->getTitle()->getFullText()) |
| 26 | + // or if the inpur is empty, display nothing |
| 27 | + if ( !$frame->title->equals( $parser->getTitle() ) || $input == '' ) |
28 | 28 | return; |
| 29 | + |
| 30 | + // Store XML in the page_props table |
| 31 | + // TODO: Do processing here, like parse to an array |
| 32 | + $parser->getOutput()->setProperty( 'templateinfo', $input ); |
29 | 33 | |
30 | | - // also display nothing if there are no contents |
31 | | - if (empty($input)) { |
32 | | - return; |
33 | | - } |
34 | | - |
35 | 34 | // Return output |
36 | | - global $egTemplateInfoXML; |
37 | | - $egTemplateInfoXML = $input; |
38 | | - $templateInfo = new TemplateInfo( $parser ); |
39 | | - return $templateInfo->render($input); |
| 35 | + $text = "<p>" . wfMsg( 'templateinfo-header' ) . "</p>\n"; |
| 36 | + $text .= htmlspecialchars( $input, ENT_QUOTES ); |
| 37 | + return $text; |
40 | 38 | } |
41 | 39 | } |
Index: trunk/extensions/TemplateInfo/ApiQueryTemplateInfo.php |
— | — | @@ -0,0 +1,74 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Adds the 'templateinfo' action to the MediaWiki API. |
| 5 | + * |
| 6 | + * @author Yaron Koren |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * Protect against register_globals vulnerabilities. |
| 11 | + * This line must be present before any global variable is referenced. |
| 12 | + */ |
| 13 | +if (!defined('MEDIAWIKI')) die(); |
| 14 | + |
| 15 | +/** |
| 16 | + * @addtogroup API |
| 17 | + */ |
| 18 | +class APIQueryTemplateInfo extends ApiQueryBase { |
| 19 | + |
| 20 | + public function __construct( $query, $moduleName ) { |
| 21 | + parent :: __construct( $query, $moduleName, 'ti' ); |
| 22 | + } |
| 23 | + |
| 24 | + public function execute() { |
| 25 | + $params = $this->extractRequestParams(); |
| 26 | + $titles = $this->getPageSet()->getGoodTitles(); |
| 27 | + $this->addTables( 'page_props' ); |
| 28 | + $this->addFields( array( 'pp_page', 'pp_value' ) ); |
| 29 | + $this->addWhere( array( 'pp_propname' => 'templateinfo' ) ); |
| 30 | + if ( !is_null( $params['continue'] ) ) |
| 31 | + { |
| 32 | + $fromid = intval( $params['continue'] ); |
| 33 | + $this->addWhere( "pp_page >= $fromid" ); |
| 34 | + } |
| 35 | + $this->addOption( 'ORDER BY', 'pp_page' ); |
| 36 | + |
| 37 | + $res = $this->select(__METHOD__); |
| 38 | + while ( $row = $this->getDB()->fetchObject( $res ) ) { |
| 39 | + $vals = array( ); |
| 40 | + ApiResult::setContent( $vals, $row->pp_value ); |
| 41 | + $fit = $this->addPageSubItems( $row->pp_page, $vals ); |
| 42 | + if( !$fit ) { |
| 43 | + $this->setContinueEnumParameter( 'continue', $row->pp_page ); |
| 44 | + break; |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + public function getAllowedParams() { |
| 50 | + return array ( |
| 51 | + 'continue' => null, |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + public function getParamDescription() { |
| 56 | + return array ( |
| 57 | + 'continue' => 'When more results are available, use this to continue', |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + public function getDescription() { |
| 62 | + return 'Template information, defined by the Template Info extension (http://www.mediawiki.org/Extension:Template_Info)'; |
| 63 | + } |
| 64 | + |
| 65 | + protected function getExamples() { |
| 66 | + return array ( |
| 67 | + 'api.php?action=query&prop=templateinfo&titles=Template:Foo|Template:Bar', |
| 68 | + ); |
| 69 | + } |
| 70 | + |
| 71 | + public function getVersion() { |
| 72 | + return __CLASS__ . ': $Id$'; |
| 73 | + } |
| 74 | + |
| 75 | +} |
Property changes on: trunk/extensions/TemplateInfo/ApiQueryTemplateInfo.php |
___________________________________________________________________ |
Name: svn:mergeinfo |
1 | 76 | + |
Index: trunk/extensions/TemplateInfo/TemplateInfo.php |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | $wgExtensionCredits['parserhook'][] = array( |
28 | 28 | 'path' => __FILE__, |
29 | 29 | 'name' => 'TemplateInfo', |
30 | | - 'author' => 'Yaron Koren', |
| 30 | + 'author' => array( 'Yaron Koren', 'Roan Kattouw' ), |
31 | 31 | 'url' => 'http://www.mediawiki.org/wiki/Extension:TemplateInfo', |
32 | 32 | 'description' => 'Supports templates defining their data structure via XML markup.', |
33 | 33 | 'descriptionmsg' => 'templateinfo-desc', |
— | — | @@ -40,11 +40,10 @@ |
41 | 41 | |
42 | 42 | // Register auto load for the special page class |
43 | 43 | $wgAutoloadClasses['TemplateInfoHooks'] = $dir . 'TemplateInfo.hooks.php'; |
44 | | -$wgAutoloadClasses['TemplateInfo'] = $dir . 'TemplateInfo.classes.php'; |
45 | | -$wgAutoloadClasses['TemplateInfoAPI'] = $dir . 'TemplateInfo.API.php'; |
| 44 | +$wgAutoloadClasses['ApiQueryTemplateInfo'] = $dir . 'ApiQueryTemplateInfo.php'; |
46 | 45 | |
47 | 46 | // Register parser hook |
48 | 47 | $wgHooks['ParserFirstCallInit'][] = 'TemplateInfoHooks::register'; |
49 | 48 | |
50 | 49 | // Register API action |
51 | | -$wgAPIModules['templateinfo'] = 'TemplateInfoAPI'; |
| 50 | +$wgAPIPropModules['templateinfo'] = 'ApiQueryTemplateInfo'; |