/** * Check whether data should be loaded for the stylometric analysis namespace page */ private function StylometricanalysisDataShouldBeLoaded(Title $title, WebRequest $request, MediaWiki $wiki) { if ($wiki->getAction($request) !== 'view') { return false; } $namespace = $title->getNamespace(); if ($namespace !== NS_STYLOMETRICANALYSIS) { return false; } return true; }
/** * Purges the cache of a page */ public function execute() { global $wgUser; $params = $this->extractRequestParams(); if (!$wgUser->isAllowed('purge') && !$this->getMain()->isInternalMode() && !$this->getMain()->getRequest()->wasPosted()) { $this->dieUsageMsg(array('mustbeposted', $this->getModuleName())); } $result = array(); foreach ($params['titles'] as $t) { $r = array(); $title = Title::newFromText($t); if (!$title instanceof Title) { $r['title'] = $t; $r['invalid'] = ''; $result[] = $r; continue; } ApiQueryBase::addTitleInfo($r, $title); if (!$title->exists()) { $r['missing'] = ''; $result[] = $r; continue; } $article = MediaWiki::articleFromTitle($title); $article->doPurge(); // Directly purge and skip the UI part of purge(). $r['purged'] = ''; $result[] = $r; } $this->getResult()->setIndexedTagName($result, 'page'); $this->getResult()->addValue(null, $this->getModuleName(), $result); }
/** * MediaWikiPerformAction hook. Retrieve the collatex output stored in the database and render the table if the user is in NS_COLLATIONS */ public function onMediaWikiPerformAction(OutputPage $output, Article $article, Title $title, User $user, WebRequest $request, MediaWiki $wiki) { try { if ($wiki->getAction($request) !== 'view' || !$this->isCollationsNamespace($title)) { return true; } $wrapper = $this->wrapper; $partial_url = $title->getPrefixedUrl(); $this->signature = $wrapper->getSignatureWrapper()->getCollationsSignature($partial_url); if (!$this->userIsAllowedToViewThePage($user)) { return true; } $this->user_has_view_permission = true; $data = $wrapper->getCollationsData($partial_url); $viewer = new CollateViewer($output); $viewer->showCollateNamespacePage($data); } catch (Exception $e) { $this->page_exists = false; return true; } return true; }
/** * Really find the title match. */ private static function getNearMatchInternal($searchterm) { global $wgContLang; $allSearchTerms = array($searchterm); if ($wgContLang->hasVariants()) { $allSearchTerms = array_merge($allSearchTerms, $wgContLang->convertLinkToAllVariants($searchterm)); } if (!wfRunHooks('SearchGetNearMatchBefore', array($allSearchTerms, &$titleResult))) { return $titleResult; } foreach ($allSearchTerms as $term) { # Exact match? No need to look further. $title = Title::newFromText($term); if (is_null($title)) { return null; } if ($title->getNamespace() == NS_SPECIAL || $title->isExternal() || $title->exists()) { return $title; } # See if it still otherwise has content is some sane sense $article = MediaWiki::articleFromTitle($title); if ($article->hasViewableContent()) { return $title; } # Now try all lower case (i.e. first letter capitalized) # $title = Title::newFromText($wgContLang->lc($term)); if ($title && $title->exists()) { return $title; } # Now try capitalized string # $title = Title::newFromText($wgContLang->ucwords($term)); if ($title && $title->exists()) { return $title; } # Now try all upper case # $title = Title::newFromText($wgContLang->uc($term)); if ($title && $title->exists()) { return $title; } # Now try Word-Caps-Breaking-At-Word-Breaks, for hyphenated names etc $title = Title::newFromText($wgContLang->ucwordbreaks($term)); if ($title && $title->exists()) { return $title; } // Give hooks a chance at better match variants $title = null; if (!wfRunHooks('SearchGetNearMatch', array($term, &$title))) { return $title; } } $title = Title::newFromText($searchterm); # Entering an IP address goes to the contributions page if ($title->getNamespace() == NS_USER && User::isIP($title->getText()) || User::isIP(trim($searchterm))) { return SpecialPage::getTitleFor('Contributions', $title->getDBkey()); } # Entering a user goes to the user page whether it's there or not if ($title->getNamespace() == NS_USER) { return $title; } # Go to images that exist even if there's no local page. # There may have been a funny upload, or it may be on a shared # file repository such as Wikimedia Commons. if ($title->getNamespace() == NS_FILE) { $image = wfFindFile($title); if ($image) { return $title; } } # MediaWiki namespace? Page may be "implied" if not customized. # Just return it, with caps forced as the message system likes it. if ($title->getNamespace() == NS_MEDIAWIKI) { return Title::makeTitle(NS_MEDIAWIKI, $wgContLang->ucfirst($title->getText())); } # Quoted term? Try without the quotes... $matches = array(); if (preg_match('/^"([^"]+)"$/', $searchterm, $matches)) { return SearchEngine::getNearMatch($matches[1]); } return null; }
} // Process data & print results if ($processor) { $processor->execute(); } // Log what the user did, for book-keeping purposes. $endtime = microtime(true); // Log the request if ($wgAPIRequestLog) { $items = array(wfTimestamp(TS_MW), $endtime - $starttime, $wgRequest->getIP(), $wgRequest->getHeader('User-agent')); $items[] = $wgRequest->wasPosted() ? 'POST' : 'GET'; if ($processor) { try { $manager = $processor->getModuleManager(); $module = $manager->getModule($wgRequest->getVal('action'), 'action'); } catch (Exception $ex) { $module = null; } if (!$module || $module->mustBePosted()) { $items[] = "action=" . $wgRequest->getVal('action'); } else { $items[] = wfArrayToCgi($wgRequest->getValues()); } } else { $items[] = "failed in ApiBeforeMain"; } LegacyLogger::emit(implode(',', $items) . "\n", $wgAPIRequestLog); wfDebug("Logged API request to {$wgAPIRequestLog}\n"); } $mediawiki = new MediaWiki(); $mediawiki->doPostOutputShutdown('fast');
} // Check that required parameters are given if (!$error && (!isset($_GET['secret']) || !$_GET['secret'])) { $error = array("error" => "Bad request - Secret not given", "status" => 400); } if (!$error && (!isset($_GET['query']) || !$_GET['query'])) { $error = array("error" => "Bad request - Query not given", "status" => 400); } // check that secret matches config secret if (!$error && $WIKI_SLURP_CONFIG['SECRET'] != $_GET['secret']) { $error = array("error" => "Unauthorised - Secret is not valid", "status" => 401); } if ($error) { $obj = $error; } else { $wiki = new MediaWiki($WIKI_SLURP_CONFIG); $obj = $wiki->getArticle($_GET); } if (isset($obj['status']) && 200 != $obj['status']) { header("HTTP/1.0 {$obj['status']} {$obj['error']}"); } $output = isset($_GET['output']) ? $_GET['output'] : ''; switch ($output) { case 'json': header("Content-type: application/json"); echo json_encode($obj); break; default: // is this a suitable mimetype? header("Content-type: text/x-php"); echo serialize($obj);
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file */ # Initialise common code $preIP = dirname(__FILE__); require_once "{$preIP}/includes/WebStart.php"; # Initialize MediaWiki base class $mediaWiki = new MediaWiki(); wfProfileIn('main-misc-setup'); OutputPage::setEncodings(); # Not really used yet $maxLag = $wgRequest->getVal('maxlag'); if (!is_null($maxLag) && !$mediaWiki->checkMaxLag($maxLag)) { exit; } # Query string fields $action = $wgRequest->getVal('action', 'view'); $title = $wgRequest->getVal('title'); # Set title from request parameters $wgTitle = $mediaWiki->checkInitialQueries($title, $action); if ($wgTitle === null) { unset($wgTitle); }
* it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file */ # Bail on old versions of PHP. Pretty much every other file in the codebase # has structures (try/catch, foo()->bar(), etc etc) which throw parse errors in # PHP 4. Setup.php and ObjectCache.php have structures invalid in PHP 5.0 and # 5.1, respectively. if (!function_exists('version_compare') || version_compare(phpversion(), '5.3.2') < 0) { // We need to use dirname( __FILE__ ) here cause __DIR__ is PHP5.3+ require dirname(__FILE__) . '/includes/PHPVersionError.php'; wfPHPVersionError('index.php'); } # Initialise common code. This gives us access to GlobalFunctions, the # AutoLoader, and the globals $wgRequest, $wgOut, $wgUser, $wgLang and # $wgContLang, amongst others; it does *not* load $wgTitle require __DIR__ . '/includes/WebStart.php'; $mediaWiki = new MediaWiki(); $mediaWiki->run();
/** * Execute an action, and in case of an error, erase whatever partial results * have been accumulated, and replace it with an error message and a help screen. */ protected function executeActionWithErrorHandling() { // Verify the CORS header before executing the action if (!$this->handleCORS()) { // handleCORS() has sent a 403, abort return; } // Exit here if the request method was OPTIONS // (assume there will be a followup GET or POST) if ($this->getRequest()->getMethod() === 'OPTIONS') { return; } // In case an error occurs during data output, // clear the output buffer and print just the error information $obLevel = ob_get_level(); ob_start(); $t = microtime(true); try { $this->executeAction(); $isError = false; } catch (Exception $e) { $this->handleException($e); $isError = true; } // Log the request whether or not there was an error $this->logRequest(microtime(true) - $t); // Commit DBs and send any related cookies and headers MediaWiki::preOutputCommit($this->getContext()); // Send cache headers after any code which might generate an error, to // avoid sending public cache headers for errors. $this->sendCacheHeaders($isError); // Executing the action might have already messed with the output // buffers. while (ob_get_level() > $obLevel) { ob_end_flush(); } }
<?php # Initialise common code require_once './includes/WebStart.php'; # Initialize MediaWiki base class require_once "includes/Wiki.php"; $mediaWiki = new MediaWiki(); wfProfileIn('main-misc-setup'); OutputPage::setEncodings(); # Not really used yet # Query string fields $action = $wgRequest->getVal('action', 'view'); $title = $wgRequest->getVal('title'); # # Send Ajax requests to the Ajax dispatcher. # if ($wgUseAjax && $action == 'ajax') { require_once $IP . '/includes/AjaxDispatcher.php'; $dispatcher = new AjaxDispatcher(); $dispatcher->performAction(); $mediaWiki->restInPeace($wgLoadBalancer); exit; } $wgTitle = $mediaWiki->checkInitialQueries($title, $action, $wgOut, $wgRequest, $wgContLang); if ($wgTitle == NULL) { unset($wgTitle); } wfProfileOut('main-misc-setup'); # Setting global variables in mediaWiki $mediaWiki->setVal('Server', $wgServer); $mediaWiki->setVal('DisableInternalSearch', $wgDisableInternalSearch);
{ } function addJsConfigVars($name, $value) { global $lgScript; $value = is_array($value) ? str_replace('\\', '\\\\', json_encode($value)) : addslashes($value); $lgScript .= "window.mw.data.{$name}='{$value}';\n"; } // For wfMessage() function text() { return $this->msgKey; } } function wfMessage($msgkey) { return new MediaWiki($msgKey); } global $wgExtensionCredits, $wgExtensionMessagesFiles, $wgOut, $wgResourceModules, $wgExtensionAssetsPath, $lgScript, $wgDBname, $wgDBprefix; $lgScript = ''; $wgExtensionCredits = array('other' => array()); $wgExtensionMessagesFiles = array(); $wgOut = new MediaWiki(); $wgOut->addJsConfigVars('wgServer', 'http://' . $_SERVER['HTTP_HOST']); $wgResourceModules = array(); $wgExtensionAssetsPath = ''; // These are just used to form the WebSocket message prefix filter if (!isset($wgDBname)) { $wgDBname = 'Ligmincha'; $wgDBprefix = 'Global'; }
function cdbfPurgeMainSubpage($article, $user, $text, $summary, $isMinor, $isWatch, $section, $section, $flags, $revision, $baseRevId) { $title = $article->getTitle(); $main = cdbfGetMainSubpage($title); if ($main != '' && $main != $title->getText()) { $mainTitle = Title::newFromText($main); $mainArticle = MediaWiki::articleFromTitle($mainTitle); $mainArticle->doPurge(); } return true; }
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file * @author Aaron Schulz */ if (!in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1', '0:0:0:0:0:0:0:1', '::1'), true)) { die("Only loopback requests are allowed.\n"); } elseif ($_SERVER['REQUEST_METHOD'] !== 'POST') { die("Request must use POST.\n"); } require_once __DIR__ . '/../multiversion/MWVersion.php'; $wiki = isset($_GET['wiki']) ? $_GET['wiki'] : ''; require getMediaWiki('includes/WebStart.php', $wiki); error_reporting(E_ERROR); // fatals but not random I/O warnings ini_set('display_errors', 1); $wgShowExceptionDetails = true; if (method_exists('LBFactory', 'disableChronologyProtection')) { // This is not helpful here and will slow things down in some cases wfGetLBFactory()->disableChronologyProtection(); } try { $mediawiki = new MediaWiki(); $runner = new JobRunner(); $response = $runner->run(array('type' => isset($_GET['type']) ? $_GET['type'] : false, 'maxJobs' => isset($_GET['maxjobs']) ? $_GET['maxjobs'] : false, 'maxTime' => isset($_GET['maxtime']) ? $_GET['maxtime'] : 30)); print json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); $mediawiki->restInPeace(); } catch (Exception $e) { MWExceptionHandler::handleException($e); }
* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html */ # Initialise common code $preIP = dirname(__FILE__); require_once "{$preIP}/includes/WebStart.php"; # Initialize MediaWiki base class require_once "{$preIP}/includes/Wiki.php"; $mediaWiki = new MediaWiki(); wfProfileIn('main-misc-setup'); OutputPage::setEncodings(); # Not really used yet $maxLag = $wgRequest->getVal('maxlag'); if (!is_null($maxLag) && !$mediaWiki->checkMaxLag($maxLag)) { exit; } # Query string fields $action = $wgRequest->getVal('action', 'view'); $title = $wgRequest->getVal('title'); $wgTitle = $mediaWiki->checkInitialQueries($title, $action); if ($wgTitle === NULL) { unset($wgTitle); } wfProfileOut('main-misc-setup');
# Please don't move this line to includes/Defines.php. This line essentially # defines a valid entry point. If you put it in includes/Defines.php, then # any script that includes it becomes an entry point, thereby defeating # its purpose. define('MEDIAWIKI', true); # Load up some global defines. require_once '../../includes/Defines.php'; # Include this site setttings require_once './LocalSettings.php'; # Prepare MediaWiki require_once 'includes/Setup.php'; require_once 'extensions/CalendarClass.php'; require_once "extensions/WikiCalendarFormatIcal.php"; # Initialize MediaWiki base class require_once "includes/Wiki.php"; $mediaWiki = new MediaWiki(); # Setting global variables in mediaWiki $mediaWiki->setVal('Server', $wgServer); $mediaWiki->setVal('DisableInternalSearch', $wgDisableInternalSearch); $mediaWiki->setVal('action', $action); $mediaWiki->setVal('SquidMaxage', $wgSquidMaxage); $mediaWiki->setVal('EnableDublinCoreRdf', $wgEnableDublinCoreRdf); $mediaWiki->setVal('EnableCreativeCommonsRdf', $wgEnableCreativeCommonsRdf); $mediaWiki->setVal('CommandLineMode', $wgCommandLineMode); $mediaWiki->setVal('UseExternalEditor', $wgUseExternalEditor); $mediaWiki->setVal('DisabledActions', $wgDisabledActions); header("Content-Type: text/plain;charset=us-ascii"); $cal = new WikiCalendarClass(); $cal->weekformat = new WikiCalendarFormatIcal(); $cal->name = "krass"; $cal->format = "%day.%month.%year";
function GetWikiPage($page, $pID, $namespace = '', $memID = '') { global $wgOut, $wgRequest, $wgContLang, $wgUser, $rev_timestamp, $wgParser; #, $wgTitle, $wgTitle; #die(print_r($wgOut)); # name space # forum preview # adding wiki tabs across the top of the post #die("GetWikiPage <br />" . $page); $page = str_replace('<wiki>', '<wiki>', $page); $page = str_replace('</wiki>', '</wiki>', $page); $ns = null; if ($namespace != '') { $ns = $namespace; $namespace = " AND p.page_namespace={$namespace} "; } else { $namespace = " AND p.page_namespace=0 "; } $match = "#<wiki>(.*)<\\/wiki>#siU"; if (preg_match($match, $page, $found)) { $org_page = str_replace($found[0], '<_wiki_temp_page_holder_goes_here_for_replacing_>', $page); $title = str_replace(' ', '_', $found[1]); # die($found[1]); # $org_page = $wgOut->parse($org_page) ; # $org_page = Convert($org_page); $dbr = wfGetDB(DB_SLAVE); $table_page = $dbr->tableName('page'); $table_rev = $dbr->tableName('revision'); $table_text = $dbr->tableName('text'); $sql = "SELECT t.old_text, r.rev_timestamp\r\r\n FROM {$table_page} p\r\r\n JOIN {$table_rev} r\r\r\n ON p.page_id=r.rev_page\r\r\n JOIN {$table_text} t\r\r\n ON r.rev_text_id=t.old_id\r\r\n WHERE p.page_title = '" . $title . "' {$namespace} ORDER BY r.rev_timestamp DESC LIMIT 1"; $res = $dbr->query($sql); $r = $dbr->fetchRow($res); //die($r['rev_timestamp']); $rev_timestamp = $r['rev_timestamp']; $page = $r['old_text']; $dbr->freeResult($res); if ($ns == '8') { return $page; } // used for MediaWiki:Edittools #die($page); $mw = new MediaWiki(); $action = $wgRequest->getVal('action', 'view'); $wgTitle = $mw->checkInitialQueries($title, $action, $wgOut, $wgRequest, $wgContLang); # $p = new Parser(); # $p->clearState(); $options = new ParserOptions(); #$options->setTidy(false); # die($page); # $page = awc_wikipase($page, $wgOut); # $out = $wgParser->parse($page, $wgTitle, $options, false, false); # $mText = $out->mText; $mText = $page; #awc_wikipase # die(print_r($ns)); $link = str_replace('index.php/', '', awcsf_wiki_url); $link = str_replace('index.php?title=', '', $link); if ($ns == 0) { $link = $link . 'index.php?title=' . $title; $page = '<br /><br /><hr>' . get_awcsforum_word('word_wikipage') . ' <a href="' . $link . '&awc_redirect=' . $pID . '&action=edit">' . get_awcsforum_word('word_editwikipage') . '</a><hr> <br />' . $mText . '<hr><br />'; $page = str_replace('<_wiki_temp_page_holder_goes_here_for_replacing_>', $page, $org_page); $page = str_replace('&action=edit&section=', '&awc_redirect=' . $pID . '&action=edit&section=', $page); } else { $page = $mText; # die($page); # $page = str_replace('title=', 'title=User:'******'&action=edit&section=', '&awc_redirect='.$memID.'&action=edit&section=', $page); # $page = str_replace('&action=edit&section=', '&awc_mem_redirect='.$title.'&action=edit&section=', $page); } } return $page; }