r98536 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98535‎ | r98536 | r98537 >
Date:16:30, 30 September 2011
Author:petrb
Status:ok
Tags:
Comment:
removing old stuff
Modified paths:
  • /branches/petrb/api.php (deleted) (history)
  • /branches/petrb/includes (deleted) (history)

Diff [purge]

Index: branches/petrb/api.php
@@ -1,150 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * API for MediaWiki 1.8+
6 - *
7 - * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
8 - *
9 - * This program is free software; you can redistribute it and/or modify
10 - * it under the terms of the GNU General Public License as published by
11 - * the Free Software Foundation; either version 2 of the License, or
12 - * (at your option) any later version.
13 - *
14 - * This program is distributed in the hope that it will be useful,
15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 - * GNU General Public License for more details.
18 - *
19 - * You should have received a copy of the GNU General Public License along
20 - * with this program; if not, write to the Free Software Foundation, Inc.,
21 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 - * http://www.gnu.org/copyleft/gpl.html
23 - *
24 - * @file
25 - */
26 -
27 -/**
28 - * This file is the entry point for all API queries. It begins by checking
29 - * whether the API is enabled on this wiki; if not, it informs the user that
30 - * s/he should set $wgEnableAPI to true and exits. Otherwise, it constructs
31 - * a new ApiMain using the parameter passed to it as an argument in the URL
32 - * ('?action=') and with write-enabled set to the value of $wgEnableWriteAPI
33 - * as specified in LocalSettings.php. It then invokes "execute()" on the
34 - * ApiMain object instance, which produces output in the format sepecified
35 - * in the URL.
36 - */
37 -
38 -// So extensions (and other code) can check whether they're running in API mode
39 -define( 'MW_API', true );
40 -
41 -// Bail if PHP is too low
42 -if ( !function_exists( 'version_compare' ) || version_compare( phpversion(), '5.2.3' ) < 0 ) {
43 - require( dirname( __FILE__ ) . '/includes/PHPVersionError.php' );
44 - wfPHPVersionError( 'api.php' );
45 -}
46 -
47 -// Initialise common code.
48 -if ( isset( $_SERVER['MW_COMPILED'] ) ) {
49 - require ( 'phase3/includes/WebStart.php' );
50 -} else {
51 - require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
52 -}
53 -
54 -wfProfileIn( 'api.php' );
55 -$starttime = microtime( true );
56 -
57 -// URL safety checks
58 -if ( !$wgRequest->checkUrlExtension() ) {
59 - return;
60 -}
61 -
62 -// Verify that the API has not been disabled
63 -if ( !$wgEnableAPI ) {
64 - header( $_SERVER['SERVER_PROTOCOL'] . ' 500 MediaWiki configuration Error', true, 500 );
65 - echo( 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php'
66 - . '<pre><b>$wgEnableAPI=true;</b></pre>' );
67 - die(1);
68 -}
69 -
70 -// Selectively allow cross-site AJAX
71 -
72 -/**
73 - * Helper function to convert wildcard string into a regex
74 - * '*' => '.*?'
75 - * '?' => '.'
76 - *
77 - * @param $search string
78 - * @return string
79 - */
80 -function convertWildcard( $search ) {
81 - $search = preg_quote( $search, '/' );
82 - $search = str_replace(
83 - array( '\*', '\?' ),
84 - array( '.*?', '.' ),
85 - $search
86 - );
87 - return "/$search/";
88 -}
89 -
90 -if ( $wgCrossSiteAJAXdomains && isset( $_SERVER['HTTP_ORIGIN'] ) ) {
91 - $exceptions = array_map( 'convertWildcard', $wgCrossSiteAJAXdomainExceptions );
92 - $regexes = array_map( 'convertWildcard', $wgCrossSiteAJAXdomains );
93 - foreach ( $regexes as $regex ) {
94 - if ( preg_match( $regex, $_SERVER['HTTP_ORIGIN'] ) ) {
95 - foreach ( $exceptions as $exc ) { // Check against exceptions
96 - if ( preg_match( $exc, $_SERVER['HTTP_ORIGIN'] ) ) {
97 - break 2;
98 - }
99 - }
100 - header( "Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}" );
101 - header( 'Access-Control-Allow-Credentials: true' );
102 - break;
103 - }
104 - }
105 -}
106 -
107 -// Set a dummy $wgTitle, because $wgTitle == null breaks various things
108 -// In a perfect world this wouldn't be necessary
109 -$wgTitle = Title::makeTitle( NS_MAIN, 'API' );
110 -
111 -/* Construct an ApiMain with the arguments passed via the URL. What we get back
112 - * is some form of an ApiMain, possibly even one that produces an error message,
113 - * but we don't care here, as that is handled by the ctor.
114 - */
115 -$processor = new ApiMain( $wgRequest, $wgEnableWriteAPI );
116 -
117 -// Process data & print results
118 -$processor->execute();
119 -
120 -// Execute any deferred updates
121 -wfDoUpdates();
122 -
123 -// Log what the user did, for book-keeping purposes.
124 -$endtime = microtime( true );
125 -wfProfileOut( 'api.php' );
126 -wfLogProfilingData();
127 -
128 -// Log the request
129 -if ( $wgAPIRequestLog ) {
130 - $items = array(
131 - wfTimestamp( TS_MW ),
132 - $endtime - $starttime,
133 - $wgRequest->getIP(),
134 - $_SERVER['HTTP_USER_AGENT']
135 - );
136 - $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET';
137 - $module = $processor->getModule();
138 - if ( $module->mustBePosted() ) {
139 - $items[] = "action=" . $wgRequest->getVal( 'action' );
140 - } else {
141 - $items[] = wfArrayToCGI( $wgRequest->getValues() );
142 - }
143 - wfErrorLog( implode( ',', $items ) . "\n", $wgAPIRequestLog );
144 - wfDebug( "Logged API request to $wgAPIRequestLog\n" );
145 -}
146 -
147 -// Shut down the database. foo()->bar() syntax is not supported in PHP4: we won't ever actually
148 -// get here to worry about whether this should be = or =&, but the file has to parse properly.
149 -$lb = wfGetLBFactory();
150 -$lb->shutdown();
151 -

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98320inserted own branch as instructed by Tim for my changespetrb16:00, 28 September 2011

Status & tagging log