为什么在doctype之前加载代码

时间:2015-03-21 20:44:28

标签: mediawiki

<?php

# Alert the user that this is not a valid access point to MediaWiki if they try to access the special pages file directly.
if ( !defined( 'MEDIAWIKI' ) ) {
    echo <<<EOT
To install my extension, put the following line in LocalSettings.php:
require_once "$IP/extensions/Userprofile/Userprofile.php";
EOT;
    exit( 1 );
}


$wgExtensionCredits['specialpage'][] = array(
    'path' => __FILE__,
    'name' => 'Userprofile',
    'author' => 'matsuiny2004',
    'url' => 'http://localhost/mywiki/index.php/Extension:Userprofile',
    'descriptionmsg' => 'userprofile-desc',
    'version' => '0.0.0',
);

$wgAutoloadClasses['SpecialUserprofile'] = __DIR__ . '/SpecialUserprofile.php'; # Location of the SpecialMyExtension class (Tell MediaWiki to load this file)
$wgMessagesDirs['Userprofile'] = __DIR__ . "/i18n"; # Location of localisation files (Tell MediaWiki to load them)
$wgExtensionMessagesFiles['UserprofileAlias'] = __DIR__ . '/Userprofile.alias.php'; # Location of an aliases file (Tell MediaWiki to load it)
$wgSpecialPages['Userprofile'] = 'SpecialUserprofile'; # Tell MediaWiki about the new special page and its class name

function extensionFunction() {
    # Assume $title is the title object
    if( $title->isProtected( 'edit' ) ) {
       # Protected from editing, do things
    } else {
       # Not protected from editing
    }
 }

//test code here


echo '<div id="navigation">Navigation</div>';
?>

<?php
echo '<div id="account">account</div>';
?>

<?php
echo '<div id="editpage">edit page</div>';
?>

<div id='border-search'>
<img src="http://s6.postimage.org/z6ixulv6l/searchbox_border.png"></img>
</div>
?php>

<div class='rectangle-box'>
    <div class='rectangle-content'></div>
</div>

我从一个单独的文件中包含额外的php和html代码,我在mediawiki中加载它作为扩展来创建自定义布局。问题是代码在文件类型之前加载,使得页面在IE和Safari中以怪异模式呈现。如何在doctype标签后加载它?

1 个答案:

答案 0 :(得分:1)

问题在于您的代码中包含顶级echo语句(顶级我的意思是任何函数中未包含的语句)。这就是为什么PHP引擎一看到它就会执行它们,这是在MediaWiki本身开始运行之前。

MediaWiki有一些good documentation解释各种钩子。您应该做的是编写一些函数并将所有echo代码放在那里,并期望在发生相关事件时执行此函数。

我看到一个好的首页here。相关的例子是:

$wgHooks['ArticleSave'][] = 'wgAddStub';
function wgAddStub( &$article, &$user, &$text, &$summary, $minor, $watchthis, $sectionanchor, &$flags, &$status ) {
    $text = ( $article->exists() ? "" : "{{stub}}\n" ) . $text;
    return true;
}