public static function onUploadCompleteHook( &$file ) { global $wgExIndexMIMETypes; $localFile = $file->getLocalFile(); if ( $localFile != null && in_array( $localFile->getMimeType(), $wgExIndexMIMETypes ) ) { wfDebugLog( 'OracleTextSearch', 'Touching file page to force indexing'); $article = new Article( $localFile->getTitle() ); $article->loadContent(); $article->doEdit( $article->mContent, $article->mComment ); } return true; }
public function hUnknownAction($action, &$article) { // check if request 'action=formsubmit' if ($action != 'formsubmit') { return true; } // continue hook-chain. $article->loadContent(); // follow redirects if ($article->mIsRedirect == true) { $title = Title::newFromRedirect($article->getContent()); $article = new Article($title); $article->loadContent(); } // Extract the code // Use our runphpClass helper $runphp = new runphpClass(); $runphp->initFromContent($article->getContent()); // Execute Code $code = $runphp->getCode(true); if (!empty($code)) { $callback = eval($code); } // we might implement functionality around a callback method in the future // Was there an expected class defined? $name = $article->mTitle->getDBkey(); // the page name might actually be a sub-page; extract the basename without the full path. $pn = explode('/', $name); if (!empty($pn)) { $rn = array_reverse($pn); $name = $rn[0]; } $name .= 'Class'; if (class_exists($name)) { $class = new $name(); if (is_object($class)) { if (method_exists($class, 'submit')) { $class->submit(); } } } // ... then it was a page built from ground up; nothing more to do here. return false; }
protected function fetchArticleHtml($title, $revid) { if (!$revid) { $good = GoodRevision::newFromTitle($title, $title->getArticleID()); if ($good) { $revid = $good->latestGood(); } } $article = new Article($title, $revid); if (!$article) { return false; } $article->loadContent(); $rev = $article->mRevision; if (!$rev) { return false; } $this->getNonMobileHtml($title, $rev); $builder = new MobileAppArticleBuilder(); $this->html = $builder->createByHtml($title, $this->html); return true; }
public static function onArticleFromTitle_New(&$title, &$article) { global $wgScriptPath; global $wgArticlePath, $wgTitle, $wgOut, $wgHooks; $dbr = wfGetDB(DB_SLAVE); /** * We only care about Documentation namespace for rewrites and they must contain a slash, so scan for it. * $matches[1] = product * $matches[2] = latest|version * $matches[3] = manual * $matches[4] = topic */ if (!preg_match('/^' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . '\\/([' . PONYDOCS_PRODUCT_LEGALCHARS . ']*)\\/(.*)\\/(.*)\\/(.*)$/i', $title->__toString(), $matches)) { return false; } $defaultRedirect = PonyDocsExtension::getDefaultUrl(); /** * At this point $matches contains: * 0= Full title. * 1= Product name * 2= Version OR 'latest' as a string. * 3= Manual name (short name). * 4= Wiki topic name. */ $productName = $matches[1]; $versionName = $matches[2]; $manualName = $matches[3]; $topicName = $matches[4]; $product = PonyDocsProduct::GetProductByShortName($productName); // If we don't have a valid product, display 404 if (!$product instanceof PonyDocsProduct) { $wgHooks['BeforePageDisplay'][] = "PonyDocsExtension::handle404"; return false; } // If this article doesn't have a valid manual, don't display the article if (!PonyDocsProductManual::IsManual($productName, $manualName)) { $wgHooks['BeforePageDisplay'][] = "PonyDocsExtension::handle404"; return false; } // If this is a static product return because that should be handled by another function if ($product->isStatic()) { return true; } $versionSelectedName = PonyDocsProductVersion::GetSelectedVersion($productName); $version = ''; PonyDocsProductVersion::LoadVersionsForProduct($productName); if (!strcasecmp('latest', $versionName)) { /** * This will be a DESCENDING mapping of version name to PonyDocsVersion object and will ONLY contain the * versions available to the current user (i.e. LoadVersions() only loads the ones permitted). */ $releasedVersions = PonyDocsProductVersion::GetReleasedVersions($productName, true); if (empty($releasedVersions)) { return false; } $versionList = array_reverse($releasedVersions); $versionNameList = array(); foreach ($versionList as $pV) { $versionNameList[] = $pV->getVersionName(); } /** * Now get a list of version names to which the current topic is mapped in DESCENDING order as well * from the 'categorylinks' table. * * DB can't do descending order here, it depends on the order defined in versions page! So we have to * do some magic sorting below. */ $res = $dbr->select('categorylinks', 'cl_to', array('cl_to LIKE "V:%:%"', 'cl_type = "page"', "cl_sortkey LIKE '" . $dbr->strencode(strtoupper("{$productName}:{$manualName}:{$topicName}")) . ":%'"), __METHOD__); if (!$res->numRows()) { /** * What happened here is we requested a topic that does not exist or is not linked to any version. * Perhaps setup a default redirect, Main_Page or something? */ if (PONYDOCS_DEBUG) { error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] redirecting to {$defaultRedirect}"); } header("Location: " . $defaultRedirect); exit(0); } /** * Based on our list, get the PonyDocsVersion for each version tag and store in an array. Then pass this array * to our custom sort function via usort() -- the ending result is a sorted list in $existingVersions, with the * LATEST version at the front. * * @FIXME: GetVersionByName is missing some versions? */ $existingVersions = array(); while ($row = $dbr->fetchObject($res)) { if (preg_match('/^V:(.*):(.*)/i', $row->cl_to, $vmatch)) { $pVersion = PonyDocsProductVersion::GetVersionByName($vmatch[1], $vmatch[2]); if ($pVersion && !in_array($pVersion, $existingVersions)) { $existingVersions[] = $pVersion; } } } usort($existingVersions, "PonyDocs_ProductVersionCmp"); $existingVersions = array_reverse($existingVersions); // Okay, iterate through existingVersions. If we can't see that // any of them belong to our latest released version, redirect to // our latest handler. $latestReleasedVersion = PonyDocsProductVersion::GetLatestReleasedVersion($productName)->getVersionName(); $found = false; foreach ($existingVersions as $docVersion) { if ($docVersion->getVersionName() == $latestReleasedVersion) { $found = true; break; } } if (!$found) { if (PONYDOCS_DEBUG) { error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] redirecting to {$wgScriptPath}/Special:PonyDocsLatestDoc?t={$title}"); } header("Location: " . $wgScriptPath . "/Special:SpecialLatestDoc?t={$title}", true, 302); exit(0); } /** * Now we need to filter out any versions which this user has no access to. The easiest way is to loop through * our resulting $existingVersions and see if each is in_array( $versionNameList ); if its NOT, continue looping. * Once we hit one, redirect. if we exhaust our list, go to the main page or something. */ foreach ($existingVersions as $pV) { if (in_array($pV->getVersionName(), $versionNameList)) { /** * Look up topic name and redirect to URL. */ $res = $dbr->select(array('categorylinks', 'page'), 'page_title', array('cl_from = page_id', 'page_namespace = "' . NS_PONYDOCS . '"', "cl_to = 'V:" . $dbr->strencode($pV->getProductName() . ':' . $pV->getVersionName()) . "'", 'cl_type = "page"', "cl_sortkey LIKE '" . $dbr->strencode(strtoupper("{$productName}:{$manualName}:{$topicName}")) . ":%'"), __METHOD__); if (!$res->numRows()) { if (PONYDOCS_DEBUG) { error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] redirecting to {$defaultRedirect}"); } header("Location: " . $defaultRedirect); exit(0); } $row = $dbr->fetchObject($res); $title = Title::newFromText(PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ":{$row->page_title}"); $article = new Article($title); $article->loadContent(); PonyDocsProductVersion::SetSelectedVersion($pV->getProductName(), $pV->getVersionName()); if (!$article->exists()) { $article = NULL; } else { // Without this we lose SplunkComments and version switcher. // Probably we can replace with a RequestContext in the future... $wgTitle = $title; } return TRUE; } } /** * Invalid redirect -- go to Main_Page or something. */ if (PONYDOCS_DEBUG) { error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] redirecting to {$defaultRedirect}"); } header("Location: " . $defaultRedirect); exit(0); } else { /** * Ensure version specified in aliased URL is a valid version -- if it is not we just need to do our default * redirect here. */ $version = PonyDocsProductVersion::GetVersionByName($productName, $versionName); if (!$version) { if (PONYDOCS_DEBUG) { error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] unable to retrieve version ({$versionName}) for product ({$productName}); redirecting to {$defaultRedirect}"); } header("Location: " . $defaultRedirect); exit(0); } /** * Look up the TOPIC in the categorylinks and find the one which is tagged with the version supplied. This * is the URL to redirect to. */ $res = $dbr->select(array('categorylinks', 'page'), 'page_title', array('cl_from = page_id', 'page_namespace = "' . NS_PONYDOCS . '"', "cl_to = 'V:" . $dbr->strencode($productName . ':' . $versionSelectedName) . "'", 'cl_type = "page"', "cl_sortkey LIKE '" . $dbr->strencode(strtoupper("{$productName}:{$manualName}:{$topicName}")) . ":%'"), __METHOD__); if (!$res->numRows()) { /** * Handle invalid redirects? */ $wgHooks['BeforePageDisplay'][] = "PonyDocsExtension::handle404"; return false; } $row = $dbr->fetchObject($res); $title = Title::newFromText(PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ":{$row->page_title}"); /// FIXME this shouldn't be necessary because selected version already comes from here PonyDocsProductVersion::SetSelectedVersion($productName, $versionSelectedName); $article = new Article($title); $article->loadContent(); if (!$article->exists()) { $article = NULL; } else { // Without this we lose SplunkComments and version switcher. // Probably we can replace with a RequestContext in the future... $wgTitle = $title; } return TRUE; } return FALSE; }
function runTests() { global $wgOut, $wgTitle; $wgOut->wrapWikiMsg('<h1>$1</h1>', 'offline_heading_status'); $wgOut->addHTML('<ul>'); // lookup a real article in the index can be searched $results = DumpReader::index_search(wfMsg('offline_test_article')); if (count($results) > 0) list ($bz_file, $offset, $entry_title) = $results[0]; $test_index = isset($bz_file); $this->printTest($test_index, 'offline_index_test'); if (!$test_index) { $this->diagnoseIndex(); return; } // tests that bz2 dumpfiles can be opened and read $xml = DumpReader::load_bz($bz_file, $entry_title); $test_bz = isset($xml); $this->printTest($test_bz, 'offline_bzload_test'); if (!$test_bz) { $this->diagnoseBzload($bz_file); return; } //report subdirectory setting // if (substr($bz_file, 0, 1) == 'x') { // $subdir = dirname($bz_file); //TODO strip absolute components if needed // $wgOut->addWikiMsg('offline_subdir-status', $subdir); // $wgOut->addHTML( // '<label>' . wfMsg('offline_change-subdir') . // '<input type=text size=20 name="subdir" value="'.$subdir.'"> // <input type=submit name="subdir" value="Change"> // </label/>' // ); // } // TODO report language settings and availabilities //test that a specific article can be loaded $article_wml = DumpReader::load_article($entry_title); $test_article = isset($article_wml); $this->printTest($test_article, 'offline_article_test'); if (!$test_article) { //TODO diagnose return; } //TODO test that the wml has not been padded or truncated //test that our handler is still hooked in $mw_api_article = new Article(Title::newFromText($entry_title)); $mw_api_article->loadContent(); $content = $mw_api_article->getContent(); //wfDebug('got '.strlen($mw_api_article->mContent).' bytes of wml from cache'); $test_hooks = $mw_api_article->mContentLoaded; // TODO false positive $this->printTest($test_hooks, 'offline_hooks_test'); if (!$test_hooks) { $this->diagnoseHooks(); return; } //TODO test Templates $wgOut->addHTML('</ul>'); $wgOut->wrapWikiMsg('<i>$1</i>', 'offline_all_tests_pass'); //TODO div collapse or load on demand //$wgOut->addWikiText($content); }
<?php require_once '/classes/Article.php'; $path = ''; if (isset($_POST['articleTitle'])) { $obj = new Article($_POST['articleTitle']); } if (isset($_POST['language'])) { $path = $obj->loadContent($_POST['language']); } return $path;
function doRedirect($form_name, $page_name, $params) { global $wgOut; $page_title = Title::newFromText($page_name); if ($page_title->exists()) { // It exists - see if page is a redirect; if // it is, edit the target page instead. $article = new Article($page_title, 0); $article->loadContent(); $redirect_title = Title::newFromRedirect($article->fetchContent()); if ($redirect_title != null) { $page_title = $redirect_title; $page_name = SFUtils::titleURLString($redirect_title); } // HACK - if this is the default form for // this page, send to the regular 'formedit' // tab page; otherwise, send to the 'Special:FormEdit' // page, with the form name hardcoded. // Is this logic necessary? Or should we just // out-guess the user and always send to the // standard form-edit page, with the 'correct' form? $default_forms = SFFormLinker::getDefaultFormsForPage($page_title); if (count($default_forms) > 0) { $default_form_name = $default_forms[0]; } else { $default_form_name = null; } if ($form_name == $default_form_name) { $redirect_url = $page_title->getLocalURL('action=formedit'); } else { $redirect_url = self::getFormEditURL($form_name, $page_name); } } else { $redirect_url = self::getFormEditURL($form_name, $page_name); // Of all the request values, send on to 'FormEdit' // only 'preload' and specific form fields - we can // identify the latter because they show up as arrays. foreach ($_REQUEST as $key => $val) { if (is_array($val)) { $template_name = urlencode($key); foreach ($val as $field_name => $value) { $field_name = urlencode($field_name); $value = urlencode($value); $redirect_url .= strpos($redirect_url, '?') > -1 ? '&' : '?'; $redirect_url .= $template_name . '[' . $field_name . ']=' . $value; } } elseif ($key == 'preload') { $redirect_url .= strpos($redirect_url, '?') > -1 ? '&' : '?'; $redirect_url .= "{$key}={$val}"; } } } if (!is_null($params) && $params !== '') { $redirect_url .= strpos($redirect_url, '?') > -1 ? '&' : '?'; $redirect_url .= $params; } $wgOut->setArticleBodyOnly(true); // Show "loading" animated image while people wait for the // redirect. global $sfgScriptPath; $text = "<p style=\"position: absolute; left: 45%; top: 45%;\"><img src=\"{$sfgScriptPath}/skins/loading.gif\" /></p>\n"; $text .= <<<END \t\t<script type="text/javascript"> \t\twindow.onload = function() { \t\t\twindow.location="{$redirect_url}"; \t\t} \t\t</script> END; $wgOut->addHTML($text); return; }
function doRedirect($form_name, $page_name, $params) { global $wgOut; $page_title = Title::newFromText($page_name); if ($page_title->exists()) { // It exists - see if page is a redirect; if // it is, edit the target page instead. $article = new Article($page_title, 0); $article->loadContent(); $redirect_title = Title::newFromRedirect($article->fetchContent()); if ($redirect_title != null) { $page_title = $redirect_title; $page_name = SFUtils::titleURLString($redirect_title); } // HACK - if this is the default form for // this page, send to the regular 'formedit' // tab page; otherwise, send to the 'Special:FormEdit' // page, with the form name hardcoded. // Is this logic necessary? Or should we just // out-guess the user and always send to the // standard form-edit page, with the 'correct' form? $default_forms = SFFormLinker::getDefaultFormsForPage($page_title); if (count($default_forms) > 0) { $default_form_name = $default_forms[0]; } else { $default_form_name = null; } if ($form_name == $default_form_name) { $redirect_url = $page_title->getLocalURL('action=formedit'); } else { $redirect_url = self::getFormEditURL($form_name, $page_name); } } else { $redirect_url = self::getFormEditURL($form_name, $page_name); // Of all the request values, send on to 'FormEdit' // only 'preload' and specific form fields - we can // identify the latter because they show up as arrays. foreach ($_REQUEST as $key => $val) { if (is_array($val)) { $redirect_url .= strpos($redirect_url, '?') > -1 ? '&' : '?'; // Re-add the key (i.e. the template // name), so we can make a nice query // string snippet out of the whole // thing. $wrapperArray = array($key => $val); $redirect_url .= urldecode(http_build_query($wrapperArray)); } elseif ($key == 'preload') { $redirect_url .= strpos($redirect_url, '?') > -1 ? '&' : '?'; $redirect_url .= "{$key}={$val}"; } } } if (!is_null($params) && $params !== '') { $redirect_url .= strpos($redirect_url, '?') > -1 ? '&' : '?'; $redirect_url .= $params; } $wgOut->setArticleBodyOnly(true); // Show "loading" animated image while people wait for the // redirect. global $sfgScriptPath; $text = <<<END \t<p style="position: absolute; left: 45%; top: 45%;"> \t<img src="{$sfgScriptPath}/skins/loading.gif" /> \t</p> \t<meta http-equiv="refresh" content="0; url={$redirect_url}" /> END; $wgOut->addHTML($text); return; }
static function loadTitleRevision($title, $revid = 0) { if (!$revid) { $good = GoodRevision::newFromTitle($title, $title->getArticleId()); if ($good) { $revid = $good->latestGood(); } } // TODO these two are to be uncommented only for debugging //$revision = Revision::newFromTitle($title); //$revid = $revision->getId(); $article = new Article($title, $revid); if (!$article) { return null; } $article->loadContent(); $rev = $article->mRevision; return $rev ? $rev : null; }
/** * CHANGE THIS TO CACHE THESE IN MEMCACHE OR WHATEVER. * * This takes a title (text form) and extracts the H1 content for the title and returns it. * This is used in display (heading and TOC). * * @static * @param string $title The text form of the title to get the H1 content for. * @return string The resulting H1 content; or boolean false if title not found. */ public static function FindH1ForTitle($title) { $article = new Article(Title::newFromText($title), 0); $content = $article->loadContent(); if (!preg_match('/^\\s*=(.*)=/D', $article->getContent(), $matches)) { return false; } return $matches[1]; }
function execute($par) { global $wgOut; include "Parse_Entries.php"; #Don't want to output standard Wiki stuff, just want blank page. $wgOut->disable(); # If just Special:BibtexExport , explain what it is and die. if ($par == "") { echo "<h3>You haven't specified which wiki page you would like the BibTeX from.</h3>"; echo "<div style=\"width:33em\">"; echo "To grab the BibTeX between the <bibtex> and </bibtex> tags "; echo "in an article, simply visit Special:BibtexExport/Article_Name."; echo "<p>"; echo "To narrow it down you can append a query to the URL. For example, if you "; echo "wanted to get the bibtex for all the Haystack publications by David Huynh "; echo "in the year 2005, simply visit: <p>"; echo "<a href=\"http://simile.mit.edu/exhibited-wiki/Special:BibtexExport/Haystack?field:author=David%20Huynh&field:year=2005\">"; echo "http://simile.mit.edu/exhibited-wiki/Special:BibtexExport/Haystack?field:author=David%20Huynh&field:year=2005</a>"; echo "</div>"; die; } # Grab the article associated with the text past Special:BibtexExport. # e.g. Special:BibtexExport/Some_Article will grab all the data in the # Some_Article page. $title = Title::newFromURL($par); $article = new Article($title); $article->loadContent(); $text = $article->getContent(); # Try to get just the stuff in <bibtex> </bibtex> tags. $bibtexmatches = array(); $anything = Parser::extractTagsAndParams(array('bibtex'), $text, $bibtexmatches); # info stored in $bibtexmatches array, but key is randomly generated, so must # iterate through the *one* element in the array. # that in turn is an array, with the second key being the content foreach ($bibtexmatches as $match) { $bibtex = $match[1]; } # If there's a query string (e.g. Special:BibtexExport/Article?author=name) # we have more work to do. Otherwise, we're done. if (!$_SERVER['QUERY_STRING']) { echo "{$bibtex}"; } else { #Parse Bibtex $parse = new PARSEENTRIES(); $parse->loadBibtexString($bibtex); $parse->extractEntries(); list($preamble, $strings, $entries, $undefinedStrings) = $parse->returnArrays(); #filter by queries of form, e.g., ?field:author=Charles%20Darwin $queries = explode("&", $_SERVER['QUERY_STRING']); foreach ($queries as $query) { $survivingentries = array(); list($attr, $val) = explode("=", $query); $val = rawurldecode($val); $explodedattr = explode(":", $attr); if ($explodedattr[0] == "field") { # filter by some field $filterby = $explodedattr[1]; #Now we know what to filter by, let's go through the bibtex. foreach ($entries as $entry) { if ($filterby == "author") { $authorarray = explode(" and ", $entry['author']); if (in_array($val, $authorarray)) { $survivingentries[] = $entry; } } elseif ($entry[$filterby] == $val) { $survivingentries[] = $entry; } } } unset($entries); $entries = $survivingentries; unset($survivingentries); } #Surviving entries should now be in $entries. echo self::parsedEntriesToBibtex($entries); } exit; }
function wfFiAddCheckboxToUploadForm(&$oUploadForm) { global $wgRequest, $wgFiCreateOnUploadByDefault, $wgFiArticleNamespace; /* * Formular abeschickt? * Ja => Harken setzen, wie vor dem Abschicken * Nein => Artikel zur Datei aus dem Namensraum $wgFiArticleNamespace existiert? * Ja => Harken setzen, wenn darin Index gefunden wird * Nein => Harken nach globalen $wgFiCreateOnUploadByDefault setzen */ $bCheckboxChecked = true; if (!is_null($wgRequest->getVal('wpUpload'))) { $bCheckboxChecked = !is_null($wgRequest->getVal('wpProcessIndex')) && $wgRequest->getVal('wpProcessIndex') == "true"; } else { $iIndexArticleNamespace = $wgFiArticleNamespace > -1 ? $wgFiArticleNamespace : NS_IMAGE; if ($oUploadForm->mDesiredDestName != "") { $oTitle = Title::makeTitleSafe($iIndexArticleNamespace, $oUploadForm->mDesiredDestName); $oArticle = new Article($oTitle); if ($oArticle->exists()) { $oArticle->loadContent(); $bCheckboxChecked = !(wfFiGetIndexFragments($oArticle->mContent) === false); } else { $bCheckboxChecked = $wgFiCreateOnUploadByDefault; } } else { $bCheckboxChecked = $wgFiCreateOnUploadByDefault; } } $oUploadForm->uploadFormTextAfterSummary .= "</td></tr><tr><td align=right>FileIndexer:</td><td><input type='checkbox' name='wpProcessIndex' value='true' " . ($bCheckboxChecked ? "checked" : "") . "> " . wfMsg('fileindexer_form_label_create_index') . "\n"; return true; }