2015-04-05 79 views
1

嘗試爲Mediawiki創建新皮膚。 CSS文件正在加載,但不是JavaScript文件。在script.js文件中,我只有一個簡單的alert語句,但在頁面加載時沒有任何反應。Mediawiki皮膚創建 - Javascript未被加載

NewSkin.php文件:

<?php  
if(!defined('MEDIAWIKI')) { 
    die('This is a skin to the MediaWiki package and cannot be run standalone.'); 
}  
$wgExtensionCredits['skin'][] = array(
    'path'  => __FILE__, 
    'name'  => 'newskin', 
    'url'  => 'http://exmaple.com/', 
    'version' => '1.2-alpha', 
    'author'  => array(
     'Author Name',  
     ), 
    'descriptionmsg' => 'newskin-desc' 
);  
$wgValidSkinNames['newskin'] = 'NewSkin';  
$wgAutoloadClasses['SkinNewSkin'] = __DIR__ . '/NewSkin.skin.php';  
$wgMessagesDirs['SkinNewSkin'] = __DIR__ . '/i18n';  
$wgResourceModules['skins.newskin'] = array(
    'styles'   => array(
     'newskin/resources/bootstrap.css', 
     'newskin/resources/styles.css',  
    ), 
    'scripts' => array(
     'newskin/resources/jquery.js', 
     'newskin/resources/script.js',    
    ), 
    'remoteBasePath' => &$GLOBALS['wgStylePath'], 
    'localBasePath' => &$GLOBALS['wgStyleDirectory'] 
); 
?> 

NewSkin.skin.php文件:

<?php 
class SkinNewSkin extends SkinTemplate { 

    var $skinname = 'newskin', $stylename = 'newskin', 
     $template = 'NewSkinTemplate', $useHeadElement = true; 

    public function initPage(OutputPage $out) { 
     parent::initPage($out); 

     /* Assures mobile devices that the site doesn't assume traditional 
     * desktop dimensions, so they won't downscale and will instead respect 
     * things like CSS's @media rules */ 
     $out->addHeadItem('viewport', 
      '<meta name="viewport" content="width=device-width, initial-scale=1" />' 
     ); 
     $out->addModuleScripts('skins.newskin'); 
    } 

    /** 
    * @param $out OutputPage object 
    */ 
    function setupSkinUserCss(OutputPage $out) { 
     parent::setupSkinUserCss($out); 
     $out->addModuleStyles('skins.newskin');  
    } 
} 

class NewSkinTemplate extends BaseTemplate {  
    public function execute() { 
     $this->html('headelement'); 
     $this->html('bodytext'); 
    } 
} 
?> 
+0

jquery.js只是jQuery嗎?如果是這樣,刪除它(mediawiki有jQuery內置)。 – TiiJ7 2015-04-05 12:23:38

+0

是的,但是,除此之外,我還需要bootstrap.js和另一個custom.js。不知道我在這裏錯過了什麼。 – BCB 2015-04-06 13:38:14

+0

嗯,我沒有看到任何PHP代碼錯誤。 JavaScript控制檯中是否有錯誤? – TiiJ7 2015-04-06 13:53:15

回答

0

是否有一個地方,我們可以檢查JS錯誤的任何地方嗎?

如果您使用bootstrap構建Mediawiki皮膚,那麼您可以從其中一個現有的皮膚創建。我開發了皮膚MediaWikiBoostrap(https://github.com/nasirkhan/mediawiki-bootstrap),我希望這可以幫助你解決問題。