r26501 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26500‎ | r26501 | r26502 >
Date:14:24, 8 October 2007
Author:catrope
Status:old
Tags:
Comment:
* (bug 11173) Allow limited wikicode rendering via api.php
* (bug 11572) API should provide interface for expanding templates

Patches by VasilevVV
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/api/ApiExpandTemplates.php (added) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)
  • /trunk/phase3/includes/api/ApiRender.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiRender.php
@@ -0,0 +1,94 @@
 2+<?php
 3+
 4+/*
 5+ * Created on Oct 06, 2007
 6+ *
 7+ * API for MediaWiki 1.8+
 8+ *
 9+ * Copyright (C) 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
 10+ *
 11+ * This program is free software; you can redistribute it and/or modify
 12+ * it under the terms of the GNU General Public License as published by
 13+ * the Free Software Foundation; either version 2 of the License, or
 14+ * (at your option) any later version.
 15+ *
 16+ * This program is distributed in the hope that it will be useful,
 17+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 19+ * GNU General Public License for more details.
 20+ *
 21+ * You should have received a copy of the GNU General Public License along
 22+ * with this program; if not, write to the Free Software Foundation, Inc.,
 23+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 24+ * http://www.gnu.org/copyleft/gpl.html
 25+ */
 26+
 27+if (!defined('MEDIAWIKI')) {
 28+ // Eclipse helper - will be ignored in production
 29+ require_once ("ApiBase.php");
 30+}
 31+
 32+/**
 33+ * @addtogroup API
 34+ */
 35+class ApiRender extends ApiBase {
 36+
 37+ public function __construct($main, $action) {
 38+ parent :: __construct($main, $action);
 39+ }
 40+
 41+ public function execute() {
 42+ // Get parameters
 43+ $params = $this->extractRequestParams();
 44+ $text = $params['text'];
 45+ $title = $params['title'];
 46+ $retval = '';
 47+
 48+ //Create title for parser
 49+ $title_obj = Title :: newFromText($params['title']);
 50+ if(!$title_obj)
 51+ $title_obj = Title :: newFromText("API"); // Default title is "API". For example, ExpandTemplates uses "ExpendTemplates" for it
 52+
 53+ // Parse text
 54+ global $wgParser;
 55+ $p_result = $wgParser->parse( $text, $title_obj, new ParserOptions() );
 56+ $retval = $p_result->getText();
 57+
 58+ // Return result
 59+ $result = $this->getResult();
 60+ $retval_array = array();
 61+ $result->setContent( $retval_array, $retval );
 62+ $result->addValue( null, 'render', $retval_array );
 63+ }
 64+
 65+ protected function getAllowedParams() {
 66+ return array (
 67+ 'title' => array(
 68+ ApiBase :: PARAM_DFLT => 'API',
 69+ ),
 70+ 'text' => null
 71+ );
 72+ }
 73+
 74+ protected function getParamDescription() {
 75+ return array (
 76+ 'text' => 'Wikitext to render',
 77+ 'title' => 'Title of page',
 78+ );
 79+ }
 80+
 81+ protected function getDescription() {
 82+ return 'This module allows to get rendered wikitext';
 83+ }
 84+
 85+ protected function getExamples() {
 86+ return array (
 87+ 'api.php?action=render&text={{Project:Sandbox}}'
 88+ );
 89+ }
 90+
 91+ public function getVersion() {
 92+ return __CLASS__ . ': $Id$';
 93+ }
 94+}
 95+
Index: trunk/phase3/includes/api/ApiMain.php
@@ -54,6 +54,8 @@
5555 private static $Modules = array (
5656 'login' => 'ApiLogin',
5757 'query' => 'ApiQuery',
 58+ 'expandtemplates' => 'ApiExpandTemplates',
 59+ 'render' => 'ApiRender',
5860 'opensearch' => 'ApiOpenSearch',
5961 'feedwatchlist' => 'ApiFeedWatchlist',
6062 'help' => 'ApiHelp',
@@ -539,3 +541,4 @@
540542 }
541543 }
542544
 545+
Index: trunk/phase3/includes/api/ApiExpandTemplates.php
@@ -0,0 +1,93 @@
 2+<?php
 3+
 4+/*
 5+ * Created on Oct 05, 2007
 6+ *
 7+ * API for MediaWiki 1.8+
 8+ *
 9+ * Copyright (C) 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
 10+ *
 11+ * This program is free software; you can redistribute it and/or modify
 12+ * it under the terms of the GNU General Public License as published by
 13+ * the Free Software Foundation; either version 2 of the License, or
 14+ * (at your option) any later version.
 15+ *
 16+ * This program is distributed in the hope that it will be useful,
 17+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 19+ * GNU General Public License for more details.
 20+ *
 21+ * You should have received a copy of the GNU General Public License along
 22+ * with this program; if not, write to the Free Software Foundation, Inc.,
 23+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 24+ * http://www.gnu.org/copyleft/gpl.html
 25+ */
 26+
 27+if (!defined('MEDIAWIKI')) {
 28+ // Eclipse helper - will be ignored in production
 29+ require_once ("ApiBase.php");
 30+}
 31+
 32+/**
 33+ * @addtogroup API
 34+ */
 35+class ApiExpandTemplates extends ApiBase {
 36+
 37+ public function __construct($main, $action) {
 38+ parent :: __construct($main, $action);
 39+ }
 40+
 41+ public function execute() {
 42+ // Get parameters
 43+ $params = $this->extractRequestParams();
 44+ $text = $params['text'];
 45+ $title = $params['title'];
 46+ $retval = '';
 47+
 48+ //Create title for parser
 49+ $title_obj = Title :: newFromText($params['title']);
 50+ if(!$title_obj)
 51+ $title_obj = Title :: newFromText("API"); // Default title is "API". For example, ExpandTemplates uses "ExpendTemplates" for it
 52+
 53+ // Parse text
 54+ global $wgParser;
 55+ $retval = $wgParser->preprocess( $text, $title_obj, new ParserOptions() );
 56+
 57+ // Return result
 58+ $result = $this->getResult();
 59+ $retval_array = array();
 60+ $result->setContent( $retval_array, $retval );
 61+ $result->addValue( null, 'expandtemplates', $retval_array );
 62+ }
 63+
 64+ protected function getAllowedParams() {
 65+ return array (
 66+ 'title' => array(
 67+ ApiBase :: PARAM_DFLT => 'API',
 68+ ),
 69+ 'text' => null
 70+ );
 71+ }
 72+
 73+ protected function getParamDescription() {
 74+ return array (
 75+ 'text' => 'Wikitext to convert',
 76+ 'title' => 'Title of page',
 77+ );
 78+ }
 79+
 80+ protected function getDescription() {
 81+ return 'This module expand all templates in wikitext';
 82+ }
 83+
 84+ protected function getExamples() {
 85+ return array (
 86+ 'api.php?action=expandtemplates&text={{Project:Sandbox}}'
 87+ );
 88+ }
 89+
 90+ public function getVersion() {
 91+ return __CLASS__ . ': $Id$';
 92+ }
 93+}
 94+
Index: trunk/phase3/includes/AutoLoader.php
@@ -308,6 +308,7 @@
309309 'ApiLogin' => 'includes/api/ApiLogin.php',
310310 'ApiMain' => 'includes/api/ApiMain.php',
311311 'ApiOpenSearch' => 'includes/api/ApiOpenSearch.php',
 312+ 'ApiExpandTemplates' => 'includes/api/ApiExpandTemplates.php',
312313 'ApiPageSet' => 'includes/api/ApiPageSet.php',
313314 'ApiQuery' => 'includes/api/ApiQuery.php',
314315 'ApiQueryAllpages' => 'includes/api/ApiQueryAllpages.php',
@@ -333,6 +334,7 @@
334335 'ApiQuerySiteinfo' => 'includes/api/ApiQuerySiteinfo.php',
335336 'ApiQueryUserInfo' => 'includes/api/ApiQueryUserInfo.php',
336337 'ApiQueryWatchlist' => 'includes/api/ApiQueryWatchlist.php',
 338+ 'ApiRender' => 'includes/api/ApiRender.php',
337339 'ApiResult' => 'includes/api/ApiResult.php',
338340 );
339341
Index: trunk/phase3/RELEASE-NOTES
@@ -108,6 +108,8 @@
109109 * Fixed rvlimit of the revisions query to only enforce the lower query limit if
110110 revision content is requested.
111111 * Include svn revision number (if install is checked-out from svn) in siteinfo query.
 112+* (bug 11173) Allow limited wikicode rendering via api.php
 113+* (bug 11572) API should provide interface for expanding templates
112114
113115 === Languages updated in 1.12 ===
114116

Follow-up revisions

RevisionCommit summaryAuthorDate
r26512Merged revisions 26465-26511 via svnmerge from...david21:07, 8 October 2007

Status & tagging log